:root {
    --surface: #f8f9fa;
    --surface-low: #f3f4f5;
    --surface-container: #ffffff;
    --surface-high: #e7e8e9;
    --on-surface: #191c1d;
    --on-surface-variant: #434652;
    --outline: #737783;
    --outline-variant: #c3c6d4;
    --primary: #0d47a1;
    --primary-dark: #003178;
    --primary-soft: #d9e2ff;
    --secondary-dark: #1b2b48;
    --success: #1b7f4c;
    --success-soft: #dff4e9;
    --warning: #9a6400;
    --warning-soft: #fff1cc;
    --danger: #ba1a1a;
    --danger-soft: #ffdad6;
    --info-soft: #e8eefc;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-soft: 0 2px 10px rgba(15, 23, 42, 0.06);
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
    --surface: #111827;
    --surface-low: #182235;
    --surface-container: #1f2937;
    --surface-high: #2b3648;
    --on-surface: #f8fafc;
    --on-surface-variant: #cbd5e1;
    --outline: #94a3b8;
    --outline-variant: #334155;
    --primary: #b0c6ff;
    --primary-dark: #d9e2ff;
    --primary-soft: #203d75;
    --secondary-dark: #0b1220;
    --success-soft: #123527;
    --warning-soft: #3b2d0b;
    --danger-soft: #411818;
    --info-soft: #182a4b;
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--surface);
    color: var(--on-surface);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { border: 0; }
a { color: var(--primary-dark); }

.material-symbols-outlined {
    font-family: "Material Symbols Outlined";
    font-weight: normal;
    font-style: normal;
    font-size: 20px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    direction: ltr;
    font-feature-settings: "liga";
    -webkit-font-feature-settings: "liga";
    -webkit-font-smoothing: antialiased;
    vertical-align: -4px;
}

.icon-fill { font-variation-settings: "FILL" 1, "wght" 600, "GRAD" 0, "opsz" 24; }
.app-shell { min-height: 100vh; }

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 12% 18%, rgba(13, 71, 161, 0.12), transparent 28%),
        linear-gradient(135deg, var(--surface), var(--surface-low));
}

.login-card {
    width: min(440px, 100%);
    padding: 32px;
    background: var(--surface-container);
    border: 1px solid var(--outline-variant);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

h1, h2 { margin: 0; letter-spacing: 0; }
.login-card h1, .page-title h1 { font-size: 24px; line-height: 32px; }
.login-subtitle, .muted { color: var(--on-surface-variant); }
.login-note { padding: 12px; border-radius: 8px; background: var(--info-soft); color: var(--on-surface-variant); font-size: 13px; }

.login-form, .stack, .panel, .field { display: flex; flex-direction: column; }
.login-form, .stack { gap: 14px; }
.field { gap: 6px; position: relative; }
.field.floating { margin-top: 8px; }
.field label {
    color: var(--on-surface-variant);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    pointer-events: none;
    transition: all 0.2s ease;
}

.field.floating label {
    position: absolute;
    left: 10px;
    top: -8px;
    padding: 0 6px;
    background: var(--surface-container);
    z-index: 2;
    color: var(--primary);
}

.login-card .field.floating label {
    background: var(--surface-container);
}

.login-card .input, .login-card .select {
    border-width: 1.5px;
    background: var(--surface);
}

.input, .select, .textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--outline-variant);
    border-radius: 6px;
    background: var(--surface-container);
    color: var(--on-surface);
    padding: 11px 12px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.btn {
    min-height: 40px;
    border-radius: 6px;
    padding: 8px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 800;
    color: var(--on-surface);
    background: var(--surface-low);
    border: 1px solid var(--outline-variant);
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover { background: var(--surface-high); transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-ghost { background: transparent; border-color: transparent; }

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    border: 0;
}

.layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
}

.sidebar {
    background: var(--secondary-dark);
    color: #f0f1f2;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: sticky;
    top: 0;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    gap: 12px;
    align-items: center;
}

.sidebar-header .brand-mark { background: #fff; color: #003178; }
.sidebar-title { font-weight: 900; }
.sidebar-subtitle { color: #b7c7eb; font-size: 12px; }

.nav {
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-button {
    width: 100%;
    min-height: 42px;
    color: #d7e2ff;
    background: transparent;
    border-radius: 6px;
    padding: 10px 12px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    border-left: 4px solid transparent;
}

.nav-button:hover, .nav-button.active {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.nav-button.active { border-left-color: #b0c6ff; }
.nav-count { margin-left: auto; min-width: 24px; height: 22px; border-radius: 999px; display: grid; place-items: center; background: #ffdad6; color: #93000a; font-size: 12px; font-weight: 900; }
.sidebar-footer { margin-top: auto; padding: 16px; border-top: 1px solid rgba(255,255,255,0.1); display: flex; flex-direction: column; gap: 10px; }
.logout-button { background: rgba(255,255,255,0.06); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
    min-height: 72px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--surface-container);
    border-bottom: 1px solid var(--outline-variant);
}

.mobile-menu { display: none; }
.page { padding: 32px; display: flex; flex-direction: column; gap: 24px; }
.page-title { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.panel {
    background: var(--surface-container);
    border: 1px solid var(--outline-variant);
    border-radius: 8px;
    overflow: visible;
    box-shadow: var(--shadow-soft);
}

.panel-header {
    padding: 16px;
    border-bottom: 1px solid var(--outline-variant);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.panel-body { padding: 16px; }
.form-panel { overflow: visible; }
.form-section { padding: 20px; border-bottom: 1px solid var(--outline-variant); }
.form-section h2 { margin: 0 0 18px; font-size: 16px; line-height: 24px; display: flex; align-items: center; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.full { grid-column: 1 / -1; }

.stat {
    padding: 18px;
    background: var(--surface-container);
    border: 1px solid var(--outline-variant);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
    display: flex;
    gap: 14px;
    align-items: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon { width: 44px; height: 44px; border-radius: 8px; display: grid; place-items: center; background: var(--info-soft); color: var(--primary-dark); }
.stat-value { font-size: 28px; line-height: 34px; font-weight: 900; color: var(--primary-dark); }
.stat-label { color: var(--on-surface-variant); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-blue .stat-icon { background: var(--info-soft); color: var(--primary-dark); }
.stat-yellow .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat-red .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat-green .stat-icon { background: var(--success-soft); color: var(--success); }
.stat-gray .stat-icon { background: var(--surface-high); color: var(--on-surface-variant); }

.table-wrap { overflow: auto; border-radius: 0 0 8px 8px; }
.table { width: 100%; border-collapse: collapse; min-width: 980px; font-size: 14px; }
.table th, .table td { padding: 12px; border-bottom: 1px solid var(--outline-variant); text-align: left; vertical-align: top; }
.table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-low);
    color: var(--on-surface-variant);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.table tr:hover td { background: color-mix(in srgb, var(--primary-soft) 24%, transparent); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
}
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-yellow { background: var(--warning-soft); color: var(--warning); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-blue { background: var(--info-soft); color: var(--primary-dark); }
.badge-gray { background: var(--surface-high); color: var(--on-surface-variant); }
.status-dot { width: 8px; height: 8px; border-radius: 999px; background: currentColor; }

.suggestion-wrap { position: relative; }
.suggestions.overlay {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    z-index: 10;
    max-height: 220px;
    overflow: auto;
    border: 1px solid var(--outline-variant);
    border-radius: 8px;
    background: var(--surface-container);
    box-shadow: var(--shadow);
}
.suggestion { width: 100%; padding: 10px 12px; text-align: left; cursor: pointer; background: transparent; color: var(--on-surface); border-bottom: 1px solid var(--outline-variant); }
.suggestion:hover { background: var(--primary-soft); }

.dropzone {
    border: 1.5px dashed var(--outline);
    border-radius: 8px;
    background: var(--surface-low);
    min-height: 160px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-align: center;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone.dragging { border-color: var(--primary); background: var(--primary-soft); }
.file-list, .card-list { display: flex; flex-direction: column; gap: 10px; }
.file-row, .notification-row {
    padding: 10px 12px;
    border: 1px solid var(--outline-variant);
    border-radius: 6px;
    background: var(--surface-low);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.alert-panel { border-left: 4px solid var(--warning); }
.alert-card {
    border: 1px solid var(--outline-variant);
    border-radius: 8px;
    background: var(--surface-low);
    overflow: hidden;
}
.alert-card summary {
    cursor: pointer;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}
.alert-details { padding: 0 12px 12px; color: var(--on-surface-variant); }
.detail-card { gap: 10px; padding: 14px; border: 1px solid var(--outline-variant); border-radius: 8px; background: var(--surface-low); }
.folder-link { font-weight: 800; text-decoration: none; }
.notice { padding: 14px; border-radius: 8px; background: var(--warning-soft); color: var(--warning); font-weight: 800; display: flex; gap: 8px; align-items: center; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    padding: 20px;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, 0.54);
}
.modal {
    width: min(1020px, 100%);
    max-height: min(92vh, 920px);
    overflow: auto;
    background: var(--surface-container);
    border: 1px solid var(--outline-variant);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.modal-small { width: min(540px, 100%); }
.empty { padding: 32px; text-align: center; color: var(--on-surface-variant); }
.empty.compact { padding: 14px; }
.ai-offline { border-left: 4px solid var(--warning); }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 920px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .sidebar.open {
        display: flex;
        position: fixed;
        inset: 0 auto 0 0;
        width: min(320px, 88vw);
        z-index: 40;
        box-shadow: var(--shadow);
    }
    .mobile-menu { display: inline-flex; }
    .topbar { padding: 12px 16px; align-items: stretch; flex-direction: column; }
    .page { padding: 16px; }
    .page-title { flex-direction: column; }
    .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
    .full { grid-column: auto; }
}
