:root {
    color-scheme: light;

    /* ----- Rauda brand palette (rauda.ai) ----- */
    --brand-volt: #3c5fff;     /* voltblue — primary accent */
    --brand-pulse: #002eff;    /* pulse — hover / emphasis */
    --brand-naval: #0e1f40;    /* naval — headings / text */
    --brand-slate: #5a6b88;    /* slatelight — muted text */
    --brand-frost: #eaf0f8;    /* frost — light tint */
    --brand-mist: #d3ddea;     /* mist — light blue-grey */

    /* ----- Semantic tokens (light theme) ----- */
    --bg: #f4f7fc;             /* app canvas */
    --surface: #ffffff;        /* cards / sidebar / panels */
    --surface-2: #eef2f9;      /* nested fills / hover / code */
    --border: #dde5f0;         /* hairline borders */
    --text: #0e1f40;           /* primary text (~14:1 on white) */
    --muted: #5a6b88;          /* secondary text (AA on white) */
    --accent: #3c5fff;         /* active states, links, focus, chart series 1 */
    --accent-strong: #2d40ea;  /* fills carrying white text (AA) */
    --accent-text: #002eff;    /* accent used AS text on white (AA) */
    --accent-soft: #e8ecff;    /* active nav / assistant bubble */
    --danger: #d11f3a;
    --danger-soft: #fdecef;
    --ok: #136d58;
    --ok-soft: #e7f6f0;
    --warning: #b45309;
    --warning-soft: #fdf3e7;
    --focus-ring: 0 0 0 3px rgba(60, 95, 255, .30);
    --shadow-sm: 0 1px 2px rgba(14, 31, 64, .05), 0 1px 3px rgba(14, 31, 64, .07);
    --shadow-md: 0 4px 12px rgba(14, 31, 64, .07), 0 2px 4px rgba(14, 31, 64, .05);
    --font-main: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ----- Vendored fonts (IBM Plex) ----- */
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("../vendor/fonts/plex-sans-400.77bc02670657.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("../vendor/fonts/plex-sans-500.f7016cd446d2.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("../vendor/fonts/plex-sans-600.196e3cbc5fee.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 700; font-display: swap; src: url("../vendor/fonts/plex-sans-700.c277d7b83f8a.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("../vendor/fonts/plex-mono-400.79936b18df9f.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("../vendor/fonts/plex-mono-500.b1c8a895f5fd.woff2") format("woff2"); }

* { box-sizing: border-box; }

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

code, kbd, samp, pre { font-family: var(--font-mono); }

/* Visible keyboard focus (WCAG 2.4.7) */
a:focus-visible, button:focus-visible, summary:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible, .chip:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: 6px;
}

/* ----- App layout ----- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1rem 0.75rem;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: -0.01em;
    padding: 0.5rem 0.75rem 1rem;
}

.sidebar-nav { flex: 1; }
.nav-section { margin-bottom: 1.5rem; }
.nav-section-title {
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin: 0 0.75rem 0.4rem;
}
.nav-section ul { list-style: none; margin: 0; padding: 0; }

.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 8px;
    margin-bottom: 2px;
}
.nav-item a, .nav-item > span {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    color: var(--text);
    text-decoration: none;
    border-radius: 8px;
}
.nav-item a:hover { background: var(--surface-2); }
.nav-item.active a {
    background: var(--accent-soft);
    color: var(--accent-text);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--accent);
}
.nav-item.disabled { color: var(--muted); }
.nav-item.disabled > span:first-child { color: var(--muted); cursor: default; }
.nav-tag {
    font-size: 0.6rem;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1px 6px;
    margin-right: 0.5rem;
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 0.75rem;
    font-size: 0.8rem;
}
.user-email { color: var(--muted); margin: 0 0 0.5rem; word-break: break-all; }
.logout-link { color: var(--accent-text); text-decoration: none; }
.logout-link:hover { text-decoration: underline; }

/* ----- Content ----- */
.content { flex: 1; padding: 1.5rem 2rem; min-width: 0; }
.page-header h1 { margin: 0 0 1rem; font-size: 1.5rem; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.placeholder {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow-sm);
}

/* ----- Messages ----- */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.message { padding: 0.6rem 0.9rem; border-radius: 8px; margin-bottom: 0.5rem; }
.message.error { background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger); }
.message.success { background: var(--ok-soft); border: 1px solid var(--ok); color: var(--ok); }
.message.info { background: var(--surface-2); border: 1px solid var(--border); }

/* ----- Login ----- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 2rem;
    width: 360px;
    max-width: 90vw;
    box-shadow: var(--shadow-md);
}
.login-brand { font-size: 1.4rem; font-weight: 700; margin-bottom: 1.5rem; letter-spacing: -0.01em; }
.login-card h1 { font-size: 1.2rem; margin: 0 0 1rem; }
.login-card label { display: block; margin: 0.75rem 0 0.25rem; color: var(--muted); }
.login-card input {
    width: 100%;
    padding: 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}
.login-card button, .content button {
    margin-top: 1rem;
    width: 100%;
    padding: 0.6rem;
    border: none;
    border-radius: 8px;
    background: var(--accent-strong);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
.login-card button:hover, .content button:hover { background: var(--accent-text); }

/* ----- Metrics ----- */
.metrics { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.metric {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    box-shadow: var(--shadow-sm);
}
.metric-value { font-size: 1.5rem; font-weight: 700; }
.metric-label { font-size: 0.75rem; color: var(--muted); }

/* ----- Collapsible panels & forms ----- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.5rem 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
}
.panel > summary { cursor: pointer; font-weight: 600; padding: 0.25rem 0; }
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 1rem;
    padding: 0.75rem 0;
}
.form-grid label { display: flex; flex-direction: column; gap: 0.25rem; color: var(--muted); font-size: 0.85rem; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid label.checkbox { flex-direction: row; align-items: center; gap: 0.4rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}
.form-grid button { width: auto; padding: 0.55rem 1.2rem; }

/* ----- Scope filter chips ----- */
.scope-filter { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip {
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }

/* ----- Table + detail layout ----- */
.table-detail { display: grid; grid-template-columns: 3fr 2fr; gap: 1.25rem; align-items: start; }
.grid { height: 620px; width: 100%; }
.detail-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
}
.empty { color: var(--muted); padding: 2rem; text-align: center; }

/* ----- Detail card ----- */
.detail-card h2 { font-size: 1.05rem; margin: 0; }
.detail-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 6px; }
.badge.danger { background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger); }
.btn-link { color: var(--accent-text); text-decoration: none; }
.btn-link:hover { text-decoration: underline; }
.detail-card code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-family: var(--font-mono); }

/* ----- Conversation ----- */
.conversation { display: flex; flex-direction: column; gap: 0.4rem; }
.msg { display: flex; }
.msg-user { justify-content: flex-start; }
.msg-assistant { justify-content: flex-end; }
.bubble {
    max-width: 85%;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.msg-assistant .bubble { background: var(--accent-soft); }
.msg-warning { color: var(--warning); font-size: 0.85rem; }
.msg-time { font-size: 0.7rem; color: var(--muted); margin: 0 0 0.4rem; }
.msg-details { font-size: 0.8rem; color: var(--muted); }
.msg-details .details-title { font-weight: 600; margin: 0.4rem 0 0.2rem; color: var(--text); }
.msg-details ul { margin: 0; padding-left: 1.2rem; }

@media (max-width: 1100px) {
    .table-detail { grid-template-columns: 1fr; }
}

/* ----- Analytics ----- */
.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.9rem 1rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.filter-bar label { display: flex; flex-direction: column; gap: 0.25rem; color: var(--muted); font-size: 0.8rem; }
.filter-bar input, .filter-bar select {
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}
.filter-bar input:focus, .filter-bar select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}
.filter-bar button { margin-top: 0; width: auto; padding: 0.55rem 1.2rem; }

.analytics-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.analytics-section h2 { font-size: 1.1rem; margin: 0 0 1rem; }

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow-sm);
}
.metric-card .metric-value { font-size: 1.5rem; font-weight: 700; }
.metric-card .metric-label { font-size: 0.75rem; color: var(--muted); }
.metric-card .metric-delta { font-size: 0.75rem; color: var(--accent-text); margin: 0.2rem 0 0; }

.chart-block { margin-top: 1rem; }
.chart-title { font-weight: 600; margin: 0 0 0.2rem; }
.chart-caption { font-size: 0.8rem; margin: 0 0 0.4rem; color: var(--muted); }
.plotly-chart { width: 100%; min-height: 60px; }

@media (max-width: 900px) {
    .metric-grid { grid-template-columns: 1fr 1fr; }
}

/* ----- Escalation analysis ----- */
.metric-grid-6 { grid-template-columns: repeat(6, 1fr); }
.bordered-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
}
.bordered-card p { margin: 0.25rem 0; }
.bordered-card code, .group-title + .bordered-card code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-family: var(--font-mono); }
.group-title { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
.chart-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.case-layout { grid-template-columns: 1fr 2fr; margin-top: 1rem; }
.btn-download {
    display: inline-block;
    padding: 0.55rem 1.2rem;
    border-radius: 8px;
    background: var(--accent-strong);
    color: #fff;
    text-decoration: none;
    font-weight: 600;
}
.btn-download:hover { background: var(--accent-text); }

@media (max-width: 1100px) {
    .chart-pair { grid-template-columns: 1fr; }
    .metric-grid-6 { grid-template-columns: repeat(3, 1fr); }
}

/* ----- AG Grid (light quartz, aligned to brand) ----- */
.ag-theme-quartz {
    --ag-active-color: var(--accent);
    --ag-selected-row-background-color: var(--accent-soft);
    --ag-row-hover-color: var(--surface-2);
    --ag-border-color: var(--border);
    --ag-header-background-color: var(--brand-frost);
    --ag-background-color: var(--surface);
    --ag-odd-row-background-color: var(--surface);
    --ag-font-family: var(--font-main);
    --ag-foreground-color: var(--text);
    --ag-secondary-foreground-color: var(--muted);
    --ag-wrapper-border-radius: 12px;
    --ag-border-radius: 8px;
}
