/* Nadi Personal Life OS — Stylesheet v2.0 (Mobile-First) */
:root {
    --primary:       #6366f1;
    --primary-dark:  #4f46e5;
    --primary-light: #eef2ff;
    --success:       #22c55e;
    --success-light: #f0fdf4;
    --danger:        #ef4444;
    --danger-light:  #fef2f2;
    --warning:       #f59e0b;
    --warning-light: #fffbeb;
    --info:          #3b82f6;
    --info-light:    #eff6ff;
    --bg:            #f8fafc;
    --surface:       #ffffff;
    --surface2:      #f1f5f9;
    --border:        #e2e8f0;
    --border-dark:   #cbd5e1;
    --text:          #0f172a;
    --text-muted:    #64748b;
    --text-light:    #94a3b8;
    --sidebar-w:     220px;
    --nav-h:         56px;
    --bottom-nav-h:  64px;
    --radius:        10px;
    --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:     0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   TOP NAV
   ============================================================ */
.topnav {
    position: fixed; top: 0; left: 0; right: 0; height: var(--nav-h);
    background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 1.25rem;
    z-index: 200; gap: 1rem;
}
.topnav-brand { font-weight: 800; font-size: 1.15rem; color: var(--primary); letter-spacing: -.5px; flex-shrink: 0; }
.topnav-brand span { color: var(--text-muted); font-weight: 400; font-size: .8rem; margin-left: .25rem; }
.topnav-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.topnav-user { font-size: .85rem; color: var(--text-muted); }
.topnav-user strong { color: var(--text); }

/* ============================================================
   SIDEBAR (desktop only)
   ============================================================ */
.sidebar {
    position: fixed; top: var(--nav-h); left: 0; bottom: 0;
    width: var(--sidebar-w); background: var(--surface);
    border-right: 1px solid var(--border); overflow-y: auto;
    padding: 1rem 0; z-index: 100;
}
.sidebar-section { padding: 0 .75rem; margin-bottom: 1.5rem; }
.sidebar-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-light); padding: 0 .5rem; margin-bottom: .4rem; }
.sidebar-item {
    display: flex; align-items: center; gap: .6rem;
    padding: .5rem .75rem; border-radius: 7px;
    color: var(--text-muted); font-size: .875rem;
    cursor: pointer; transition: background .12s, color .12s;
    text-decoration: none;
}
.sidebar-item:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.sidebar-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sidebar-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }

/* ============================================================
   BOTTOM NAV (mobile only)
   ============================================================ */
.bottom-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-items {
    display: flex; height: 100%;
}
.bottom-nav-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px; text-decoration: none;
    color: var(--text-muted); font-size: .65rem;
    font-weight: 500; padding: .5rem .25rem;
    transition: color .15s; cursor: pointer;
    border: none; background: none;
}
.bottom-nav-item:hover, .bottom-nav-item.active { color: var(--primary); text-decoration: none; }
.bottom-nav-item .nav-icon { font-size: 1.3rem; line-height: 1; }
.bottom-nav-item.active .nav-icon { transform: scale(1.1); }

/* More drawer */
.more-drawer {
    display: none;
    position: fixed; bottom: var(--bottom-nav-h); left: 0; right: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    z-index: 199; padding: .75rem;
    box-shadow: 0 -4px 12px rgba(0,0,0,.08);
    border-radius: 16px 16px 0 0;
}
.more-drawer.open { display: block; }
.more-drawer-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
}
.more-drawer-item {
    display: flex; flex-direction: column; align-items: center;
    gap: .35rem; padding: .75rem .5rem; border-radius: 10px;
    text-decoration: none; color: var(--text); font-size: .72rem;
    font-weight: 500; background: var(--bg);
}
.more-drawer-item:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.more-drawer-item .drawer-icon { font-size: 1.4rem; }
.drawer-overlay {
    display: none; position: fixed; inset: 0; z-index: 198;
    background: rgba(0,0,0,.3);
}
.drawer-overlay.open { display: block; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main { margin-left: var(--sidebar-w); padding-top: var(--nav-h); min-height: 100vh; }
.page { padding: 1.5rem; max-width: 1200px; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.page-title { font-size: 1.3rem; font-weight: 700; }
.page-subtitle { font-size: .85rem; color: var(--text-muted); margin-top: .2rem; }

/* ============================================================
   CARDS
   ============================================================ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 1.25rem; }
.card-header { padding: .875rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.card-title { font-weight: 600; font-size: .95rem; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.stat-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .3rem; }
.stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.stat-sub { font-size: .75rem; color: var(--text-muted); margin-top: .3rem; }
.stat-value.green  { color: var(--success); }
.stat-value.red    { color: var(--danger); }
.stat-value.orange { color: var(--warning); }
.stat-value.purple { color: var(--primary); }

/* ============================================================
   DASHBOARD GRID
   ============================================================ */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.dash-grid .full { grid-column: 1 / -1; }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead th { background: var(--surface2); padding: .65rem 1rem; text-align: left; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); border-bottom: 1px solid var(--border); }
tbody td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tbody tr.paid td { color: var(--text-muted); }
tbody tr.paid .payee-name { text-decoration: line-through; }
tbody tr.overdue { background: var(--danger-light); }

/* ============================================================
   BADGES
   ============================================================ */
.badge { display: inline-flex; align-items: center; padding: .2rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.badge-green  { background: var(--success-light); color: #15803d; }
.badge-red    { background: var(--danger-light);  color: #b91c1c; }
.badge-orange { background: var(--warning-light); color: #b45309; }
.badge-blue   { background: var(--info-light);    color: #1d4ed8; }
.badge-purple { background: var(--primary-light); color: var(--primary-dark); }
.badge-gray   { background: var(--surface2);      color: var(--text-muted); }
.priority-urgent { background: #fef2f2; color: #b91c1c; }
.priority-high   { background: #fff7ed; color: #c2410c; }
.priority-medium { background: #eff6ff; color: #1d4ed8; }
.priority-low    { background: var(--surface2); color: var(--text-muted); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: 7px; border: none; cursor: pointer; font-size: .875rem; font-weight: 500; text-decoration: none; transition: opacity .15s; white-space: nowrap; }
.btn:hover { opacity: .88; text-decoration: none; }
.btn-primary   { background: var(--primary); color: white; }
.btn-danger    { background: var(--danger);  color: white; }
.btn-success   { background: var(--success); color: white; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-ghost     { background: transparent; color: var(--text-muted); border: 1px solid transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-sm  { padding: .3rem .65rem; font-size: .8rem; }
.btn-xs  { padding: .2rem .5rem; font-size: .75rem; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .82rem; font-weight: 500; color: var(--text-muted); margin-bottom: .3rem; }
.form-control { width: 100%; padding: .5rem .75rem; border: 1px solid var(--border); border-radius: 7px; font-size: .9rem; background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
select.form-control { cursor: pointer; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-check { display: flex; align-items: center; gap: .5rem; font-size: .875rem; cursor: pointer; }
.form-check input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }
.form-hint { font-size: .78rem; color: var(--text-light); margin-top: .25rem; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal-header { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: .875rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.3rem; color: var(--text-muted); padding: 0 .25rem; line-height: 1; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .875rem; }
.alert-success { background: var(--success-light); color: #15803d; border: 1px solid #bbf7d0; }
.alert-error   { background: var(--danger-light);  color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: var(--info-light);    color: #1e40af; border: 1px solid #bfdbfe; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2.25rem; width: 100%; max-width: 400px; box-shadow: var(--shadow-md); }
.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-brand h1 { font-size: 1.6rem; font-weight: 800; color: var(--primary); letter-spacing: -1px; }
.login-brand p { font-size: .85rem; color: var(--text-muted); margin-top: .25rem; }

/* ============================================================
   WIDGET LISTS
   ============================================================ */
.widget-list { display: flex; flex-direction: column; gap: .5rem; }
.widget-item { display: flex; justify-content: space-between; align-items: center; padding: .6rem .875rem; border-radius: 8px; border-left: 3px solid var(--border); background: var(--bg); font-size: .875rem; }
.widget-item.urgent  { border-color: var(--danger);  background: var(--danger-light); }
.widget-item.warning { border-color: var(--warning); background: var(--warning-light); }
.widget-item.info    { border-color: var(--info);    background: var(--info-light); }
.widget-item.ok      { border-color: var(--success); background: var(--success-light); }
.widget-item-left  { display: flex; flex-direction: column; gap: .15rem; }
.widget-item-right { font-weight: 600; font-size: .82rem; text-align: right; flex-shrink: 0; }
.widget-empty { text-align: center; padding: 1.5rem; color: var(--text-light); font-size: .875rem; }

/* ============================================================
   MONTH NAV
   ============================================================ */
.month-nav { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.5rem; }
.month-nav h2 { font-size: 1.1rem; font-weight: 700; }

/* ============================================================
   MISC
   ============================================================ */
.paid-toggle { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.app-footer { margin-left: var(--sidebar-w); padding: 1.25rem 1.5rem; border-top: 1px solid var(--border); font-size: .78rem; color: var(--text-light); text-align: center; }

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

/* ============================================================
   MOBILE RESPONSIVE (≤768px)
   ============================================================ */
@media (max-width: 768px) {

    /* Hide desktop sidebar */
    .sidebar { display: none; }

    /* Show bottom nav */
    .bottom-nav { display: block; }

    /* Main content — full width, extra bottom padding for bottom nav */
    .main {
        margin-left: 0;
        padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + .5rem);
    }

    /* Page padding */
    .page { padding: 1rem; }

    /* Top nav — hide desktop elements, show just brand */
    .topnav-user { display: none; }
    .topnav-right .btn-ghost { display: none; }
    .topnav-brand span { display: none; }

    /* Footer */
    .app-footer { margin-left: 0; margin-bottom: var(--bottom-nav-h); }

    /* Stack grids to single column */
    .dash-grid { grid-template-columns: 1fr; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: 1fr 1fr; }

    /* Stat values slightly smaller */
    .stat-value { font-size: 1.3rem; }

    /* Page header stack on small screens */
    .page-header { flex-wrap: wrap; gap: .5rem; }
    .page-title { font-size: 1.1rem; }

    /* Tables — horizontal scroll */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Modal full width on mobile */
    .modal-overlay { padding: .5rem; align-items: flex-end; }
    .modal { border-radius: 16px 16px 0 0; max-height: 85vh; }

    /* Hide less important table columns on mobile */
    .hide-mobile { display: none !important; }

    /* Buttons full width in login */
    .login-box { padding: 1.5rem 1.25rem; margin: 1rem; border-radius: 12px; }

    /* Month nav compact */
    .month-nav { gap: .5rem; }
    .month-nav h2 { font-size: 1rem; }

    /* Cards */
    .card-body { padding: 1rem; }
    .card-header { padding: .75rem 1rem; }
}

/* Extra small phones */
@media (max-width: 380px) {
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 1.1rem; }
    .bottom-nav-item { font-size: .6rem; }
    .bottom-nav-item .nav-icon { font-size: 1.2rem; }
}
