/* ─── CSS Custom Properties — Light Theme ─────────────────────────────────── */
:root {
    /* Colours */
    --color-bg:           #FAFAFA;
    --color-surface:      #FFFFFF;
    --color-surface-alt:  #F3F4F6;
    --color-border:       #E5E7EB;
    --color-border-focus: #6C63FF;
    --color-text:         #1A1A2E;
    --color-text-muted:   #6B7280;
    --color-text-light:   #9CA3AF;

    /* Accent */
    --color-accent:       #6C63FF;
    --color-accent-hover: #5A52E0;
    --color-accent-light: #EEF0FF;

    /* Status */
    --color-success:      #10B981;
    --color-success-bg:   #D1FAE5;
    --color-warning:      #F59E0B;
    --color-warning-bg:   #FEF3C7;
    --color-danger:       #EF4444;
    --color-danger-bg:    #FEE2E2;
    --color-info:         #3B82F6;
    --color-info-bg:      #DBEAFE;

    /* Shadows */
    --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
    --shadow-lg:  0 10px 25px rgba(0,0,0,.10), 0 4px 10px rgba(0,0,0,.06);
    --shadow-card:0 2px 8px rgba(0,0,0,.08);

    /* Typography */
    --font-family:  'Nunito', 'Segoe UI', system-ui, sans-serif;
    --font-size-xs: .75rem;
    --font-size-sm: .875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl:1.5rem;
    --font-size-3xl:1.875rem;

    /* Layout */
    --radius-sm:   6px;
    --radius-md:   12px;
    --radius-lg:   20px;
    --radius-pill: 9999px;
    --max-width:   1200px;
    --header-h:    64px;

    /* Transitions */
    --transition: 150ms ease;
    --transition-md: 200ms ease;
}

/* ─── Dark Theme ──────────────────────────────────────────────────────────── */
[data-theme="dark"] {
    --color-bg:           #0F0F1A;
    --color-surface:      #1E1E2E;
    --color-surface-alt:  #252535;
    --color-border:       #2D2D42;
    --color-border-focus: #7C74FF;
    --color-text:         #E2E8F0;
    --color-text-muted:   #94A3B8;
    --color-text-light:   #64748B;

    --color-accent:       #7C74FF;
    --color-accent-hover: #8B85FF;
    --color-accent-light: #1E1B4B;

    --color-success:      #34D399;
    --color-success-bg:   #064E3B;
    --color-warning:      #FBBF24;
    --color-warning-bg:   #451A03;
    --color-danger:       #F87171;
    --color-danger-bg:    #450A0A;
    --color-info:         #60A5FA;
    --color-info-bg:      #1E3A5F;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
    --shadow-md:  0 4px 6px rgba(0,0,0,.3);
    --shadow-lg:  0 10px 25px rgba(0,0,0,.4);
    --shadow-card:0 2px 8px rgba(0,0,0,.3);
}

/* ─── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    color: var(--color-text);
    background-color: var(--color-bg);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color var(--transition-md), color var(--transition-md);
}

a {
    color: var(--color-accent);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover { color: var(--color-accent-hover); }

img, svg { display: block; max-width: 100%; }

button { font-family: inherit; cursor: pointer; }

input, textarea, select {
    font-family: inherit;
    font-size: var(--font-size-md);
}

/* ─── App Shell ───────────────────────────────────────────────────────────── */
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-main {
    flex: 1;
    padding-top: var(--header-h);
}

/* ─── Header ──────────────────────────────────────────────────────────────── */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    z-index: 100;
    transition: background var(--transition-md), border-color var(--transition-md);
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.header-logo {
    font-size: var(--font-size-xl);
    font-weight: 800;
    color: var(--color-text);
    letter-spacing: -.03em;
    white-space: nowrap;
}
.header-logo span { color: var(--color-accent); }

.header-nav {
    display: flex;
    align-items: center;
    gap: .25rem;
    flex: 1;
}

.nav-link {
    padding: .4rem .75rem;
    border-radius: var(--radius-pill);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-muted);
    transition: background var(--transition), color var(--transition);
}
.nav-link:hover, .nav-link.active {
    background: var(--color-accent-light);
    color: var(--color-accent);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-left: auto;
}

.header-user {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-muted);
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--color-surface-alt);
    border-radius: var(--radius-pill);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background var(--transition);
}
.theme-toggle:hover { background: var(--color-border); }

/* ─── Page Container ──────────────────────────────────────────────────────── */
.page {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-title {
    font-size: var(--font-size-2xl);
    font-weight: 800;
    letter-spacing: -.02em;
    color: var(--color-text);
}

.page-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-top: .25rem;
}

/* ─── Typography ──────────────────────────────────────────────────────────── */
h1 { font-size: var(--font-size-3xl); font-weight: 800; letter-spacing: -.03em; }
h2 { font-size: var(--font-size-2xl); font-weight: 700; letter-spacing: -.02em; }
h3 { font-size: var(--font-size-xl);  font-weight: 700; }
h4 { font-size: var(--font-size-lg);  font-weight: 600; }

/* ─── Loading Screen ──────────────────────────────────────────────────────── */
.loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--header-h));
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Utility Classes ─────────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.sr-only  { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.text-muted   { color: var(--color-text-muted); }
.text-accent  { color: var(--color-accent); }
.text-sm      { font-size: var(--font-size-sm); }
.text-xs      { font-size: var(--font-size-xs); }
.font-bold    { font-weight: 700; }
.font-medium  { font-weight: 600; }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.gap-sm       { gap: .5rem; }
.gap-md       { gap: 1rem; }
.gap-lg       { gap: 1.5rem; }
.mt-1  { margin-top: .25rem; }
.mt-2  { margin-top: .5rem; }
.mt-4  { margin-top: 1rem; }
.mt-6  { margin-top: 1.5rem; }
.mb-4  { margin-bottom: 1rem; }
.mb-6  { margin-bottom: 1.5rem; }
.w-full { width: 100%; }

/* ─── Mobile Header ───────────────────────────────────────────────────────── */
.header-mobile-right {
    display: none;
    align-items: center;
    gap: .5rem;
    margin-left: auto;
}

.hamburger-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--color-surface-alt);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    padding: 0;
    transition: background var(--transition);
    flex-shrink: 0;
}
.hamburger-btn:hover { background: var(--color-border); }
.hamburger-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--color-text);
    border-radius: 2px;
}

/* ─── Mobile Nav Drawer ───────────────────────────────────────────────────── */
.mobile-nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 300;
    animation: fade-in .15s ease;
}
.mobile-nav-panel {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: min(300px, 85vw);
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slide-in-right .2s ease;
}
@keyframes slide-in-right {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}
.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    height: var(--header-h);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.mobile-nav-user {
    font-weight: 700;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mobile-nav-close {
    width: 34px; height: 34px;
    border: none;
    background: var(--color-surface-alt);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text);
    transition: background var(--transition);
    flex-shrink: 0;
}
.mobile-nav-close:hover { background: var(--color-border); }
.mobile-nav-links {
    display: flex;
    flex-direction: column;
    padding: .5rem 0;
    flex: 1;
    overflow-y: auto;
}
.mobile-nav-link {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .9rem 1.25rem;
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    font-family: inherit;
}
.mobile-nav-link:hover  { background: var(--color-surface-alt); }
.mobile-nav-link.active { color: var(--color-accent); background: var(--color-accent-light); }
.mobile-nav-logout      { color: var(--color-danger); }
.mobile-nav-logout:hover { background: var(--color-danger-bg); }
.mobile-nav-footer {
    border-top: 1px solid var(--color-border);
    padding: .5rem 0;
    flex-shrink: 0;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Header: show hamburger, hide desktop nav/actions */
    .header-inner { padding: 0 1rem; gap: .75rem; }
    .header-nav, .header-actions { display: none; }
    .header-mobile-right { display: flex; }

    /* Page */
    .page { padding: 1.5rem 1rem; }
    .page-title { font-size: var(--font-size-xl); }

    /* Tabs: full-width, scrollable */
    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tab-btn { flex: 1; justify-content: center; white-space: nowrap; }

    /* Toast: full width at bottom */
    .toast-container { right: 1rem; left: 1rem; }
    .toast { max-width: 100%; min-width: 0; }
}
