/* ═══════════════════════════════════════════════
   MD3 LIGHT THEME
═══════════════════════════════════════════════ */
:root {
    --md-sys-color-background: #f9faef;
    --md-sys-color-on-background: #1a1d16;
    --md-sys-color-surface: #f9faef;
    --md-sys-color-surface-dim: #d9dbd0;
    --md-sys-color-surface-bright: #f9faef;
    --md-sys-color-surface-container-lowest: #ffffff;
    --md-sys-color-surface-container-low: #f3f5e9;
    --md-sys-color-surface-container: #edefe4;
    --md-sys-color-surface-container-high: #e7e9de;
    --md-sys-color-surface-container-highest: #e2e3d9;
    --md-sys-color-on-surface: #1a1d16;
    --md-sys-color-surface-variant: #dfe5d2;
    --md-sys-color-on-surface-variant: #43493b;
    --md-sys-color-inverse-surface: #2e312a;
    --md-sys-color-inverse-on-surface: #f0f2e7;
    --md-sys-color-outline: #73796a;
    --md-sys-color-outline-variant: #c3c9b7;
    --md-sys-color-shadow: #000000;
    --md-sys-color-scrim: #000000;
    --md-sys-color-surface-tint: #3f6918;
    --md-sys-color-primary: #1f3e00;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #3a6312;
    --md-sys-color-on-primary-container: #ffffff;
    --md-sys-color-inverse-primary: #a4d576;
    --md-sys-color-secondary: #51643f;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #d8eebf;
    --md-sys-color-on-secondary-container: #3e502d;
    --md-sys-color-tertiary: #003e34;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #1c6356;
    --md-sys-color-on-tertiary-container: #ffffff;
    --md-sys-color-error: #ba1a1a;
    --md-sys-color-on-error: #ffffff;
    --md-sys-color-error-container: #ffdad6;
    --md-sys-color-on-error-container: #410002;

    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --md-sys-shape-corner-large: 16px;
    --md-sys-shape-corner-medium: 12px;
    --md-sys-shape-corner-small: 8px;
    --md-sys-shape-corner-full: 50px;

    /* Elevation shadows */
    --md-elevation-1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
    --md-elevation-2: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px 2px rgba(0,0,0,.15);
    --md-elevation-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.3);
}

/* ═══════════════════════════════════════════════
   MD3 DARK THEME
═══════════════════════════════════════════════ */
[data-theme="dark"] {
    --md-sys-color-background: #11140e;
    --md-sys-color-on-background: #e2e3d9;
    --md-sys-color-surface: #11140e;
    --md-sys-color-surface-dim: #11140e;
    --md-sys-color-surface-bright: #373a33;
    --md-sys-color-surface-container-lowest: #0c0f09;
    --md-sys-color-surface-container-low: #1a1d16;
    --md-sys-color-surface-container: #1e211a;
    --md-sys-color-surface-container-high: #282b24;
    --md-sys-color-surface-container-highest: #33362e;
    --md-sys-color-on-surface: #e2e3d9;
    --md-sys-color-surface-variant: #43493b;
    --md-sys-color-on-surface-variant: #c3c9b7;
    --md-sys-color-inverse-surface: #e2e3d9;
    --md-sys-color-inverse-on-surface: #2e312a;
    --md-sys-color-outline: #8d9383;
    --md-sys-color-outline-variant: #43493b;
    --md-sys-color-shadow: #000000;
    --md-sys-color-scrim: #000000;
    --md-sys-color-surface-tint: #a4d576;
    --md-sys-color-primary: #a4d576;
    --md-sys-color-on-primary: #1b3700;
    --md-sys-color-primary-container: #254800;
    --md-sys-color-on-primary-container: #b2e483;
    --md-sys-color-inverse-primary: #3f6918;
    --md-sys-color-secondary: #b8cea0;
    --md-sys-color-on-secondary: #243515;
    --md-sys-color-secondary-container: #314220;
    --md-sys-color-on-secondary-container: #c2d7aa;
    --md-sys-color-tertiary: #90d3c3;
    --md-sys-color-on-tertiary: #00382f;
    --md-sys-color-tertiary-container: #00483d;
    --md-sys-color-on-tertiary-container: #9ee1d1;
    --md-sys-color-error: #ffb4ab;
    --md-sys-color-on-error: #690005;
    --md-sys-color-error-container: #93000a;
    --md-sys-color-on-error-container: #ffdad6;

    --md-elevation-1: 0 1px 2px rgba(0,0,0,.5), 0 1px 3px 1px rgba(0,0,0,.35);
    --md-elevation-2: 0 1px 2px rgba(0,0,0,.5), 0 2px 6px 2px rgba(0,0,0,.35);
    --md-elevation-3: 0 4px 8px 3px rgba(0,0,0,.35), 0 1px 3px rgba(0,0,0,.5);
}

/* ═══════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    display: flex;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════
   SIDEBAR — MD3 Navigation Drawer
═══════════════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--md-sys-color-surface-container-low);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0; top: 0;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    transition: background-color 0.3s ease;
    border-right: 1px solid var(--md-sys-color-outline-variant);
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline-variant);
    border-radius: 4px;
}

.sidebar-header {
    padding: 20px 16px 12px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--md-sys-color-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 64px;
}

.sidebar-header::before {
    content: '';
    display: inline-block;
    width: 28px; height: 28px;
    background: var(--md-sys-color-primary);
    border-radius: 8px;
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 8px 0 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* MD3 Navigation Item */
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 56px;
    color: var(--md-sys-color-on-surface-variant);
    text-decoration: none;
    border-radius: var(--md-sys-shape-corner-full);
    margin: 0 12px;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.006em;
    transition: background-color 0.2s ease, color 0.2s ease;
    position: relative;
    cursor: pointer;
    border: none;
    background: none;
    width: calc(100% - 24px);
    text-align: left;
}

.nav-item i {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.nav-item:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface-variant) 8%, transparent);
    color: var(--md-sys-color-on-surface);
}

.nav-item.active {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    font-weight: 700;
}

.nav-item.active i { color: var(--md-sys-color-on-secondary-container); }

.nav-item.sub {
    height: 48px;
    padding-left: 56px;
    font-size: 0.84rem;
    font-weight: 400;
}

/* Nav Group */
.nav-group { width: 100%; }

.nav-group-header {
    width: calc(100% - 24px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 48px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    border-radius: var(--md-sys-shape-corner-full);
    margin: 4px 12px 0;
    transition: background-color 0.2s, color 0.2s;
}

.nav-group-header:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
    color: var(--md-sys-color-primary);
}

.nav-group-header span { display: flex; align-items: center; gap: 8px; }

.nav-chevron {
    font-size: 0.65rem;
    transition: transform 0.25s ease;
}
.nav-group.open .nav-chevron { transform: rotate(180deg); }

.nav-group-items {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease, opacity 0.25s ease;
    opacity: 0;
}
.nav-group.open .nav-group-items { max-height: 600px; opacity: 1; }

/* ═══════════════════════════════════════════════
   MAIN WRAPPER
═══════════════════════════════════════════════ */
.main-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ═══════════════════════════════════════════════
   TOPBAR — MD3 Top App Bar
═══════════════════════════════════════════════ */
.topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 90;
    background-color: var(--md-sys-color-surface-container);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    transition: background-color 0.3s ease;
}

.topbar-left h1 {
    font-size: 1.375rem;
    font-weight: 400;
    color: var(--md-sys-color-on-surface);
    letter-spacing: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ═══════════════════════════════════════════════
   CONTENT
═══════════════════════════════════════════════ */
.content {
    padding: 24px;
    flex: 1;
}

/* ═══════════════════════════════════════════════
   MD3 CARDS
═══════════════════════════════════════════════ */
.card {
    background-color: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-sys-shape-corner-large);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--md-sys-color-outline-variant);
    transition: background-color 0.3s ease, box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--md-elevation-1);
}

/* ═══════════════════════════════════════════════
   MD3 BUTTONS
═══════════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 24px;
    height: 40px;
    border-radius: var(--md-sys-shape-corner-full);
    font-family: 'Roboto', sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.006em;
    border: none;
    cursor: pointer;
    transition: box-shadow 0.2s ease, background-color 0.2s ease;
    text-decoration: none;
}

/* Filled button */
.btn-primary {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}
.btn-primary:hover {
    box-shadow: var(--md-elevation-1);
    background-color: color-mix(in srgb, var(--md-sys-color-on-primary) 8%, var(--md-sys-color-primary));
}

/* Tonal button */
.btn-secondary {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}
.btn-secondary:hover {
    box-shadow: var(--md-elevation-1);
}

/* Outlined / danger */
.btn-danger {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}
.btn-danger:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-error-container) 8%, var(--md-sys-color-error-container));
    box-shadow: var(--md-elevation-1);
}

/* ═══════════════════════════════════════════════
   MD3 ICON BUTTON (for theme toggle & notifications)
═══════════════════════════════════════════════ */
.md-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px; height: 48px;
    border-radius: 50%;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 1.25rem;
    transition: background-color 0.2s ease, color 0.2s ease;
    position: relative;
    text-decoration: none;
}

.md-icon-btn:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface-variant) 12%, transparent);
    color: var(--md-sys-color-on-surface);
}

/* ═══════════════════════════════════════════════
   NOTIFICATION BADGE
═══════════════════════════════════════════════ */
.notification-icon-wrapper {
    position: relative;
    display: inline-flex;
}

.notification-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background-color: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
    border-radius: var(--md-sys-shape-corner-full);
    padding: 1px 4px;
    font-size: 0.6rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════
   THEME TOGGLE BUTTON
═══════════════════════════════════════════════ */
#theme-toggle {
    position: relative;
    overflow: hidden;
}

#theme-toggle .icon-sun,
#theme-toggle .icon-moon {
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

[data-theme="dark"] #theme-toggle .icon-sun  { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="dark"] #theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(0.5); }

:root:not([data-theme="dark"]) #theme-toggle .icon-sun  { opacity: 0; transform: rotate(-90deg) scale(0.5); }
:root:not([data-theme="dark"]) #theme-toggle .icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }

/* ═══════════════════════════════════════════════
   USER CHIP (topbar)
═══════════════════════════════════════════════ */
#user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    padding: 6px 12px;
    border-radius: var(--md-sys-shape-corner-full);
    background-color: var(--md-sys-color-surface-container-high);
    letter-spacing: 0.006em;
}

/* ═══════════════════════════════════════════════
   UTILITIES
═══════════════════════════════════════════════ */
.text-muted { color: var(--md-sys-color-on-surface-variant); }

.grid-4 {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

/* MD3 Divider */
.md-divider {
    height: 1px;
    background-color: var(--md-sys-color-outline-variant);
    margin: 8px 0;
}

/* MD3 Badge / Chip */
.md-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border-radius: var(--md-sys-shape-corner-full);
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid var(--md-sys-color-outline);
    cursor: pointer;
    transition: background-color 0.2s;
}
.md-chip:hover { background-color: var(--md-sys-color-surface-container-highest); }
.md-chip.selected {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    border-color: transparent;
}

/* MD3 Text field */
.md-field {
    position: relative;
    width: 100%;
}
.md-field input, .md-field select, .md-field textarea {
    width: 100%;
    padding: 16px;
    background-color: var(--md-sys-color-surface-container-highest);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-small);
    color: var(--md-sys-color-on-surface);
    font-family: 'Roboto', sans-serif;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s, background-color 0.2s;
}
.md-field input:focus, .md-field select:focus, .md-field textarea:focus {
    border-color: var(--md-sys-color-primary);
    border-width: 2px;
    background-color: var(--md-sys-color-surface-container-low);
}

/* MD3 Table */
.md-table { width: 100%; border-collapse: collapse; }
.md-table th {
    text-align: left;
    padding: 14px 16px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--md-sys-color-on-surface-variant);
    border-bottom: 2px solid var(--md-sys-color-outline-variant);
}
.md-table td {
    padding: 14px 16px;
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    transition: background-color 0.15s;
}
.md-table tr:hover td {
    background-color: color-mix(in srgb, var(--md-sys-color-primary) 4%, transparent);
}

/* MD3 Alert / Banner */
.md-alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    border-radius: var(--md-sys-shape-corner-medium);
    font-size: 0.875rem;
    margin-bottom: 16px;
}
.md-alert-error {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}
.md-alert-success {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}
.md-alert-info {
    background-color: var(--md-sys-color-tertiary-container);
    color: var(--md-sys-color-on-tertiary-container);
}

/* Scrollbar global */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline-variant);
    border-radius: 6px;
}
