/* ====================================
   CAWANG FINANCE — Global Stylesheet
   ==================================== */

:root {
    --bg-dark:       #0D0F1A;
    --bg-surface:    #131625;
    --bg-elevated:   #1A1D2E;
    --card-bg:       rgba(26, 29, 46, 0.8);
    --border:        rgba(255, 255, 255, 0.08);
    --border-hover:  rgba(255, 255, 255, 0.15);
    --text:          #F0F2FF;
    --text-muted:    #8B8FA8;
    --text-subtle:   #5C607A;
    --accent:        #6C63FF;
    --accent-hover:  #7B73FF;
    --accent-light:  #A5A1FF;
    --accent-purple: #8B5CF6;
    --green:         #10B981;
    --green-light:   #34D399;
    --red:           #EF4444;
    --red-light:     #F87171;
    --amber:         #F59E0B;
    --sky:           #06B6D4;
    --shadow:        0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg:     0 8px 40px rgba(0, 0, 0, 0.4);
    --radius:        12px;
    --radius-lg:     16px;
    --radius-xl:     24px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    line-height: 1.6;
    font-size: 15px;
}

/* ── Typography ── */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.3; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
p  { color: var(--text-muted); }
a  { color: var(--accent-light); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--text); }

/* ── Layout ── */
.container { max-width: 1280px; margin: 0 auto; padding: 0 24px; }

/* ── Sidebar Layout ── */
.app-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-logo {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo .logo-icon {
    font-size: 28px;
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent), var(--accent-purple));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-logo h2 {
    font-size: 17px;
    font-weight: 800;
    color: var(--text);
    margin: 0;
}

.sidebar-logo span {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    font-weight: 400;
}

.sidebar-user {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--green));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}

.user-info .user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.user-info .user-tg {
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 12px;
}

.nav-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 16px 8px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    margin-bottom: 2px;
    cursor: pointer;
    text-decoration: none;
}

.nav-item:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

.nav-item.active {
    background: rgba(108, 99, 255, 0.15);
    color: var(--accent-light);
}

.nav-item .nav-icon { font-size: 16px; min-width: 20px; text-align: center; }

.sidebar-bottom {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
}

/* ── Main Content ── */
.main-content {
    background: var(--bg-dark);
    overflow-y: auto;
    min-height: 100vh;
}

.page-header {
    padding: 32px 32px 0;
    margin-bottom: 24px;
}

.page-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    margin: 0 0 4px;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0;
}

.page-content {
    padding: 0 32px 48px;
}

/* ── Cards ── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    backdrop-filter: blur(10px);
    transition: border-color 0.2s;
}

.card:hover { border-color: var(--border-hover); }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card.income::before  { background: var(--green); }
.stat-card.expense::before { background: var(--red); }
.stat-card.balance::before { background: var(--accent); }
.stat-card.count::before   { background: var(--amber); }

.stat-icon {
    font-size: 28px;
    margin-bottom: 12px;
}

.stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

.stat-change {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-purple));
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(108, 99, 255, 0.35);
    color: #fff;
}

.btn-secondary {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.1);
    border-color: var(--border-hover);
}

.btn-success {
    background: linear-gradient(135deg, var(--green), #059669);
    color: #fff;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--red-light);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover { background: rgba(239, 68, 68, 0.2); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 24px; font-size: 16px; }

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
    justify-content: center;
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: var(--text);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-income  { background: rgba(16, 185, 129, 0.12); color: var(--green-light); }
.badge-expense { background: rgba(239, 68, 68, 0.12);  color: var(--red-light); }
.badge-default { background: rgba(108, 99, 255, 0.12); color: var(--accent-light); }

/* ── Forms ── */
.form-group { margin-bottom: 20px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.form-control {
    width: 100%;
    background: var(--bg-dark);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 11px 14px;
    color: var(--text);
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}

.form-control::placeholder { color: var(--text-subtle); }

select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238B8FA8' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 32px;
    width: 100%;
    max-width: 480px;
    transform: scale(0.95);
    transition: transform 0.2s;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-overlay.active .modal { transform: scale(1); }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.modal-title { font-size: 18px; font-weight: 700; color: var(--text); }

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.modal-close:hover { background: rgba(255,255,255,0.1); }

/* ── Chart Wrapper ── */
.chart-container {
    position: relative;
    height: 280px;
}

/* ── Alert / Toast ── */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success { background: rgba(16, 185, 129, 0.1); border: 1px solid rgba(16, 185, 129, 0.25); color: var(--green-light); }
.alert-error   { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.25); color: var(--red-light); }
.alert-info    { background: rgba(108, 99, 255, 0.1); border: 1px solid rgba(108, 99, 255, 0.25); color: var(--accent-light); }

/* ── Toast notification ── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    min-width: 280px;
}

.toast.show { transform: translateX(0); }
.toast.success { border-left: 4px solid var(--green); }
.toast.error   { border-left: 4px solid var(--red); }
.toast.info    { border-left: 4px solid var(--accent); }

/* ── Toggle switch ── */
.toggle-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle {
    width: 44px;
    height: 24px;
    background: var(--border);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle.on { background: var(--accent); }

.toggle::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.toggle.on::after { transform: translateX(20px); }

/* ── Progress bar ── */
.progress-bar {
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.8s ease;
    background: linear-gradient(90deg, var(--accent), var(--accent-purple));
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ── Responsive ── */
@media (max-width: 1024px) {
    .app-layout { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -280px; top: 0; height: 100vh; width: 260px; transition: left 0.3s; }
    .sidebar.open { left: 0; box-shadow: var(--shadow-lg); }
    .mobile-header { 
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: 90;
    }
    .page-header { padding: 20px 20px 0; }
    .page-content { padding: 0 20px 32px; }
}

@media (min-width: 1025px) {
    .mobile-header { display: none; }
}

@media (max-width: 640px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
}

/* ── Loading skeletons ── */
.skeleton {
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-surface) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 8px;
}

@keyframes shimmer {
    from { background-position: -200% 0; }
    to   { background-position:  200% 0; }
}

/* ── Amount type toggle ── */
.type-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--bg-dark);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    gap: 4px;
}

.type-toggle label {
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.type-toggle input[type="radio"] { display: none; }

.type-toggle input[value="income"]:checked + label {
    background: rgba(16, 185, 129, 0.15);
    color: var(--green-light);
}

.type-toggle input[value="expense"]:checked + label {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red-light);
}

/* ── Date filter pills ── */
.filter-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-pill {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    background: rgba(255,255,255,0.05);
    color: var(--text-muted);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
}

.filter-pill:hover, .filter-pill.active {
    background: rgba(108, 99, 255, 0.15);
    color: var(--accent-light);
    border-color: rgba(108, 99, 255, 0.3);
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-state .empty-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 15px;
    color: var(--text-muted);
    margin-bottom: 20px;
}
