/* ── Design tokens ────────────────────────────────────── */
:root {
    /* Content area (light) */
    --bg-main:       #f1f5f9;
    --bg-card:       #ffffff;
    --bg-card-soft:  #f8fafc;
    --text-main:     #0f172a;
    --text-muted:    #64748b;
    --border:        rgba(15, 23, 42, 0.08);
    --shadow-card:   0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.05);

    /* Sidebar (dark) */
    --sb-bg:         #0d1526;
    --sb-text:       #94a3b8;
    --sb-text-hover: #e2e8f0;
    --sb-active:     #38bdf8;
    --sb-active-bg:  rgba(56, 189, 248, 0.10);
    --sb-hover-bg:   rgba(255, 255, 255, 0.05);
    --sb-border:     rgba(255, 255, 255, 0.07);
    --sb-label:      #475569;

    /* Accent */
    --blue:          #2563eb;
    --blue-dark:     #1d4ed8;
    --blue-light:    #38bdf8;
    --green:         #16a34a;
    --yellow:        #d97706;
    --purple:        #7c3aed;
    --red:           #dc2626;

    --font:          'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --transition:    0.15s ease;
}

/* ── Reset / base ─────────────────────────────────────── */
* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── App shell ────────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    width: 256px;
    flex-shrink: 0;
    background: var(--sb-bg);
    border-right: 1px solid var(--sb-border);
    padding: 22px 14px 32px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    margin-bottom: 28px;
    padding: 0 4px;
}

.brand-icon {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--blue-dark), var(--blue-light));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.brand h1 {
    margin: 0;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: #f0f6ff;
}

.brand p {
    margin: 2px 0 0;
    color: var(--sb-label);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.3;
}

/* Nav sections */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.nav-section {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-bottom: 6px;
}

.nav-section-label {
    display: block;
    padding: 10px 8px 5px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sb-label);
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--sb-text);
    text-decoration: none;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    border-left: 2px solid transparent;
}

.sidebar-nav a svg {
    flex-shrink: 0;
    opacity: 0.65;
    transition: opacity var(--transition);
}

.sidebar-nav a:hover {
    background: var(--sb-hover-bg);
    color: var(--sb-text-hover);
    text-decoration: none;
    border-left-color: rgba(56, 189, 248, 0.25);
}

.sidebar-nav a:hover svg { opacity: 0.9; }

.sidebar-nav a.nav-active {
    background: var(--sb-active-bg);
    color: var(--sb-active);
    border-left-color: var(--sb-active);
    font-weight: 600;
}

.sidebar-nav a.nav-active svg {
    opacity: 1;
    stroke: var(--sb-active);
}

/* ── Main content ─────────────────────────────────────── */
.main-content {
    flex: 1;
    min-width: 0;
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
}

/* ── Topbar ───────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    gap: 16px;
}

.topbar-title h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.4px;
    color: var(--text-main);
}

.topbar-title p {
    margin: 3px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.topbar-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.2);
    color: var(--blue);
    padding: 6px 13px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
}

.btn-logout {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 13px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font);
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.btn-logout:hover {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.25);
    color: var(--red);
    opacity: 1;
}

/* ── Content card ─────────────────────────────────────── */
.content-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px 32px;
    box-shadow: var(--shadow-card);
    flex: 1;
}

/* ── Flash messages ───────────────────────────────────── */
.flash-messages {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 22px;
}

.flash {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 15px;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 500;
    border: 1px solid;
}

.flash svg { flex-shrink: 0; margin-top: 1px; }

.flash-error   { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.flash-success { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }
.flash-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash-info    { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }

/* ── Auth page ────────────────────────────────────────── */
.auth-page-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    background: var(--bg-main);
}

.auth-page-brandmark {
    position: absolute;
    top: 24px;
    left: 24px;
}

.auth-page-brandmark img {
    width: min(270px, 42vw);
    height: auto;
    display: block;
}

.auth-login-card {
    width: min(420px, 92vw);
}

/* ── Typography ───────────────────────────────────────── */
h2, h3, h4 { color: var(--text-main); letter-spacing: -0.2px; }
h2 { font-weight: 700; }
h3 { font-weight: 700; }
h4 { font-weight: 600; }

.small { color: var(--text-muted); font-size: 13px; }

code {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 13px;
    color: var(--blue);
}

/* ── Form elements ────────────────────────────────────── */
.field { margin-bottom: 18px; }

.field-hint { margin-top: 5px; color: var(--text-muted); font-size: 13px; }

label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-main);
    font-weight: 600;
    font-size: 14px;
}

input, select {
    width: 100%;
    padding: 9px 13px;
    border-radius: 9px;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: var(--text-main);
    font-size: 14px;
    font-family: var(--font);
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input::placeholder { color: #94a3b8; }

select option { background: #fff; color: var(--text-main); }

/* ── Buttons ──────────────────────────────────────────── */
.btn, button[type="submit"] {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: linear-gradient(135deg, var(--blue-dark), var(--blue));
    color: #fff;
    border: none;
    padding: 9px 20px;
    border-radius: 9px;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    font-family: var(--font);
    transition: opacity var(--transition), box-shadow var(--transition);
    box-shadow: 0 1px 4px rgba(37, 99, 235, 0.3);
}

.btn:hover, button[type="submit"]:hover {
    opacity: 0.9;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.35);
}

.btn-secondary, button.btn-secondary {
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text-muted);
    box-shadow: none;
}

.btn-secondary:hover, button.btn-secondary:hover {
    background: var(--bg-card-soft);
    color: var(--text-main);
    box-shadow: none;
}

.btn-danger, button.btn-danger {
    background: linear-gradient(135deg, #b91c1c, var(--red));
    box-shadow: 0 1px 4px rgba(220, 38, 38, 0.3);
}

/* ── Links ────────────────────────────────────────────── */
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Choice grid ──────────────────────────────────────── */
.choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px;
    margin-top: 4px;
}

.choice-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.choice-card {
    display: block;
    padding: 9px 13px;
    border-radius: 9px;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.choice-card:hover { border-color: #93c5fd; color: var(--text-main); }

.choice-input:focus + .choice-card {
    outline: 2px solid rgba(37, 99, 235, 0.3);
    outline-offset: 2px;
}

.choice-input:checked + .choice-card {
    border-color: #93c5fd;
    background: #eff6ff;
    color: var(--blue);
    font-weight: 600;
}

/* ── Tables ───────────────────────────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 14px;
}

th {
    background: var(--bg-card-soft);
    color: var(--text-muted);
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

th:first-child { border-radius: 8px 0 0 0; }
th:last-child  { border-radius: 0 8px 0 0; }

td {
    padding: 11px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-main);
    font-size: 13.5px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.rank-one td { background: #f0fdf4; }

/* ── Score & badges ───────────────────────────────────── */
.score { font-weight: 800; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    border: 1px solid;
}

.badge-ml    { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.badge-model { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
.badge-final { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }

.badge-role-admin      { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.badge-role-tech       { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.badge-role-commercial { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.badge-role-marketing  { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
.badge-role-legacy     { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.badge-role-neutral    { background: #f8fafc; color: #475569; border-color: #e2e8f0; }

.badge-status-active   { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.badge-status-inactive,
.badge-status-rejected { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.badge-status-pending  { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.badge-status-approved { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }

.badge-event-access        { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.badge-event-company       { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
.badge-event-configuration { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.badge-event-generic       { background: #f8fafc; color: #475569; border-color: #e2e8f0; }

/* ── Filter chips ─────────────────────────────────────── */
.filter-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 10px 0 16px;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    border-radius: 999px;
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 600;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: var(--text-muted);
    transition: border-color var(--transition), color var(--transition), background var(--transition);
}

.filter-chip:hover {
    border-color: #93c5fd;
    color: var(--blue);
    text-decoration: none;
}

.filter-chip-active {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: var(--blue);
}

/* ── Metric grid ──────────────────────────────────────── */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 14px;
    margin: 18px 0;
}

/* .card and .metric-card: both supported */
.metric-card, .card {
    background: var(--bg-card-soft);
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 18px;
    transition: border-color var(--transition);
}

.metric-card:hover, .card:hover { border-color: #bfdbfe; }

.metric-card h3, .card h3 {
    margin: 0 0 7px;
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.metric-card p, .card p {
    margin: 0;
    font-size: 24px;
    font-weight: 800;
    color: var(--blue);
    letter-spacing: -0.5px;
}

/* ── Insight box ──────────────────────────────────────── */
.insight-box {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    padding: 14px 18px;
    margin: 16px 0;
    color: var(--text-main);
}

.insight-box ul {
    margin: 6px 0 0;
    padding-left: 18px;
}

.insight-box li { font-size: 13.5px; color: var(--text-muted); margin-bottom: 3px; }

/* ── Scrollbar ────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 900px) {
    .app-shell { flex-direction: column; }

    .sidebar {
        width: 100%;
        padding: 14px;
        background: var(--sb-bg);
    }

    .nav-section-label { display: none; }

    .sidebar-nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
    .nav-section  { flex-direction: row; flex-wrap: wrap; gap: 3px; margin-bottom: 0; }

    .sidebar-nav a {
        border-left: none;
        border-bottom: 2px solid transparent;
        padding: 6px 10px;
        font-size: 13px;
        border-radius: 6px;
    }

    .sidebar-nav a.nav-active { border-bottom-color: var(--sb-active); }

    .main-content { padding: 18px 16px; }
    .content-card { padding: 18px 16px; }
    .metric-grid  { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .auth-page-shell { align-items: flex-start; padding-top: 104px; }
    .auth-page-brandmark { top: 18px; left: 18px; }
    .auth-page-brandmark img { width: min(220px, 58vw); }
    .metric-grid { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
}
