:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
  --bg: #080d0b;
  --bg-soft: #0c1411;
  --surface: #101c17;
  --surface-strong: #14241d;
  --surface-hover: #172a22;
  --line: #294137;
  --line-soft: #1d3028;
  --text: #edf6f0;
  --muted: #91a79b;
  --muted-strong: #b8c9bf;
  --accent: #79d4a5;
  --accent-strong: #9aebbe;
  --accent-deep: #2e9a67;
  --accent-soft: #102a1e;
  --ra-bg: #302719;
  --ra-line: #80643d;
  --ra-text: #efc37c;
  --danger: #ff9c9c;
  --shadow: 0 18px 50px rgba(0, 0, 0, .24);
  --radius: 11px;
  line-height: 1.45;
  font-synthesis: none;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f8f5;
  --bg-soft: #eef5f0;
  --surface: #ffffff;
  --surface-strong: #eff8f2;
  --surface-hover: #e7f4ec;
  --line: #c9ddd0;
  --line-soft: #dcebe1;
  --text: #14251d;
  --muted: #667d70;
  --muted-strong: #3f5e4e;
  --accent: #2b9862;
  --accent-strong: #17633e;
  --accent-deep: #1f8050;
  --accent-soft: #e9f8ef;
  --ra-bg: #e6f7ec;
  --ra-line: #5eb67b;
  --ra-text: #1d7548;
  --shadow: 0 18px 50px rgba(25, 76, 48, .10);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 48% -24%, rgba(54, 135, 94, .11), transparent 37%), var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 0; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; }
.auth-view { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 16px; padding: 28px 18px; }
.auth-brand img { width: 116px; display: block; }
.auth-card { width: min(440px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 10px; font-size: 2rem; line-height: 1.08; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: .68rem; letter-spacing: .14em; font-weight: 850; }
.muted { color: var(--muted); font-size: .78rem; }
.stack-form { display: grid; gap: 13px; margin-top: 20px; }
.stack-form label, .filter-grid label { display: grid; gap: 6px; color: var(--muted-strong); font-size: .76rem; font-weight: 700; }
input, select { width: 100%; min-height: 38px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg-soft); color: var(--text); outline: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(121, 212, 165, .12); }
.primary, .secondary { min-height: 38px; border-radius: 8px; padding: 9px 14px; font-weight: 800; transition: transform .16s ease, background .16s ease, border-color .16s ease; }
.primary { background: var(--accent-deep); color: #fff; }
.primary:hover { background: var(--accent); color: #082014; }
.secondary { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.secondary:hover { border-color: var(--accent); }
.link-button { margin-top: 12px; padding: 8px 0; background: transparent; color: var(--accent); font-weight: 800; }
.feedback { min-height: 20px; margin: 13px 0 0; color: var(--muted); font-size: .82rem; }
.feedback.error { color: var(--danger); }
.feedback.success { color: var(--accent); }
.build-label, .staging-note { color: var(--muted); font-size: .68rem; text-align: center; }

.topbar { position: sticky; top: 0; z-index: 10; min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 10px clamp(18px, 4vw, 58px); border-bottom: 1px solid var(--line-soft); background: rgba(8, 13, 11, .94); backdrop-filter: blur(14px); }
[data-theme="light"] .topbar { background: rgba(255, 255, 255, .94); }
.topbar-left, .top-actions, .brand-lockup, .session-state { display: flex; align-items: center; }
.topbar-left { min-width: 0; gap: 13px; }
.brand-lockup { min-width: 174px; gap: 9px; }
.brand-lockup img { width: 49px; height: 38px; object-fit: contain; }
.brand-lockup strong, .brand-lockup span { display: block; white-space: nowrap; }
.brand-lockup strong { font-size: .76rem; letter-spacing: .01em; }
.brand-lockup span { margin-top: 2px; color: var(--muted); font-size: .6rem; }
.menu-button { width: 22px; display: grid; gap: 4px; padding: 3px 0; background: transparent; }
.menu-button span { display: block; height: 1px; width: 15px; background: var(--muted-strong); }
.session-state { gap: 5px; color: var(--muted); font-size: .65rem; white-space: nowrap; }
.session-state i, .migration-badge i { width: 7px; height: 7px; display: inline-block; border-radius: 50%; background: #d3a84b; box-shadow: 0 0 0 3px rgba(211, 168, 75, .11); }
.top-actions { justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
.top-action { min-height: 34px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted-strong); font-size: .66rem; font-weight: 750; text-decoration: none; transition: transform .16s ease, border-color .16s ease, color .16s ease, background .16s ease; }
.top-action:hover { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }
.user-name { max-width: 104px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .66rem; }
.theme-action { color: var(--text); }
.new-case-button { min-height: 40px; padding: 7px 14px; border-radius: 8px; background: var(--accent); color: #092015; font-size: .7rem; font-weight: 900; line-height: 1.1; }
.new-case-button b { margin-right: 4px; font-size: 1rem; }
.coming-soon { }

.dashboard-wrap { width: min(1180px, calc(100% - 36px)); margin: 0 auto; padding: 20px 0 42px; }
.view-tabs { display: flex; gap: 26px; border-bottom: 1px solid var(--line); }
.view-tab { position: relative; padding: 0 0 12px; background: transparent; color: var(--muted); font-size: .72rem; font-weight: 800; }
.view-tab.active { color: var(--text); }
.view-tab.active::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; content: ""; background: var(--accent); }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 25px 0 23px; }
.page-heading h1 { max-width: 600px; margin: 0 0 8px; font-size: clamp(1.62rem, 2.7vw, 2.1rem); line-height: 1.07; letter-spacing: -.02em; }
.page-heading .muted { margin: 0; font-size: .68rem; }
.migration-badge { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; border: 1px solid var(--ra-line); border-radius: 999px; color: var(--ra-text); background: var(--ra-bg); font-size: .61rem; font-weight: 850; white-space: nowrap; }
.migration-badge i { width: 5px; height: 5px; background: var(--ra-text); box-shadow: none; }

.stats-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 9px; margin-bottom: 15px; }
.stat-card { min-width: 0; min-height: 111px; padding: 17px 13px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--text); text-align: left; box-shadow: 0 8px 22px rgba(0, 0, 0, .08); transition: transform .16s ease, border-color .16s ease, background .16s ease; }
.stat-card:hover { transform: translateY(-1px); border-color: var(--accent); background: var(--surface-hover); }
.stat-card.is-ra { border-color: var(--ra-line); background: var(--ra-bg); }
.stat-card.is-ra:hover { border-color: var(--ra-text); }
.stat-label { display: block; min-height: 25px; color: var(--muted-strong); font-size: .61rem; font-weight: 850; line-height: 1.15; }
.stat-value { display: block; margin: 9px 0 3px; color: var(--text); font-size: 1.35rem; line-height: 1; }
.stat-meta { display: block; color: var(--muted); font-size: .59rem; line-height: 1.25; }
.stat-card.is-ra .stat-label, .stat-card.is-ra .stat-value { color: var(--ra-text); }
.stat-card.is-ra .stat-meta { color: color-mix(in srgb, var(--ra-text) 72%, var(--muted)); }

.queue-toolbar { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(150px, .9fr) minmax(160px, .95fr) auto; gap: 8px; align-items: center; margin: 0 0 12px; }
.search-box { position: relative; }
.search-box span { position: absolute; top: 7px; left: 11px; color: var(--muted); font-size: 1.1rem; line-height: 1; pointer-events: none; }
.search-box input { min-height: 35px; padding-left: 30px; border-color: var(--line); border-radius: 8px; background: var(--surface); font-size: .7rem; }
.queue-toolbar select { min-height: 35px; border-radius: 8px; background: var(--surface); font-size: .69rem; }
.clear-button { min-height: 35px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--text); font-size: .66rem; font-weight: 800; white-space: nowrap; }
.clear-button:hover { border-color: var(--accent); color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.queue-card { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 10px 30px rgba(0, 0, 0, .08); }
.queue-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 18px 18px 13px; }
.queue-head .eyebrow { margin-bottom: 4px; }
.queue-head h2 { margin: 0; font-size: 1.02rem; letter-spacing: -.01em; }
.queue-count { color: var(--muted); font-size: .63rem; white-space: nowrap; }
.table-scroll { max-height: 505px; overflow: auto; scrollbar-color: var(--accent-deep) var(--surface-strong); }
.case-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.case-table th { position: sticky; top: 0; z-index: 1; padding: 10px 17px; border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line); background: var(--surface-strong); color: var(--muted); font-size: .59rem; font-weight: 850; letter-spacing: .07em; text-align: left; }
.case-table th:nth-child(1) { width: 19%; }
.case-table th:nth-child(2) { width: 24%; }
.case-table th:nth-child(3) { width: 18%; }
.case-table th:nth-child(4) { width: 24%; }
.case-table th:nth-child(5) { width: 15%; }
.case-table td { padding: 12px 17px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.case-row-button { width: 100%; display: table-row; cursor: pointer; }
.case-row-button:hover td { background: var(--surface-hover); }
.case-row-button.ra td { background: color-mix(in srgb, var(--accent-soft) 88%, var(--surface)); }
.case-row-button.ra:hover td { background: var(--surface-hover); }
.cell-protocol strong, .cell-client strong, .cell-category strong, .cell-complaint strong { display: block; overflow: hidden; color: var(--text); font-size: .68rem; font-weight: 850; text-overflow: ellipsis; white-space: nowrap; }
.cell-protocol strong { color: var(--accent); letter-spacing: .03em; }
.cell-protocol small, .cell-client small, .cell-category small, .cell-complaint small { display: block; overflow: hidden; margin-top: 3px; color: var(--muted); font-size: .58rem; text-overflow: ellipsis; white-space: nowrap; }
.cell-client strong { text-transform: uppercase; }
.cell-status { text-align: left; }
.status-pill { display: inline-flex; max-width: 100%; padding: 5px 8px; overflow: hidden; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .58rem; font-weight: 850; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
.case-row-button.ra .status-pill { background: var(--ra-bg); color: var(--ra-text); }
.empty-state { padding: 34px 18px; color: var(--muted); font-size: .8rem; text-align: center; }
.staging-note { margin: 13px 0 0; }

.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 21px 22px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 1.22rem; }
.dialog-close { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-strong); color: var(--text); font-size: 1.3rem; line-height: 1; }
.dialog-body { display: grid; gap: 16px; padding: 21px 22px 24px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.detail-item { min-width: 0; padding: 11px; border: 1px solid var(--line-soft); border-radius: 8px; background: var(--surface-strong); }
.detail-item small { display: block; margin-bottom: 3px; color: var(--muted); font-size: .64rem; font-weight: 800; }
.detail-item strong { display: block; overflow-wrap: anywhere; font-size: .78rem; }
.detail-wide { grid-column: 1 / -1; }
.detail-history { padding-top: 13px; border-top: 1px solid var(--line); }
.detail-history h3 { margin: 0 0 10px; font-size: .86rem; }
.history-line { margin: 0 0 8px; padding: 0 0 9px 11px; border-left: 2px solid var(--accent); }
.history-line small { color: var(--muted); font-size: .64rem; }
.history-line p { margin: 3px 0 0; font-size: .76rem; }
dialog { width: min(720px, calc(100% - 24px)); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(2, 6, 4, .72); backdrop-filter: blur(3px); }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 30; max-width: min(360px, calc(100% - 36px)); padding: 10px 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-strong); color: var(--text); font-size: .74rem; opacity: 0; pointer-events: none; transform: translateY(7px); transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
button:active { transform: scale(.97); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
@media (max-width: 1180px) { .topbar { align-items: flex-start; } .topbar-left { padding-top: 7px; } .session-state { display: none; } .top-actions { max-width: 690px; } }
@media (max-width: 920px) { .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } .queue-toolbar { grid-template-columns: 1fr 1fr; } .search-box { grid-column: 1 / -1; } .clear-button { width: 100%; } .case-table { min-width: 790px; } .table-scroll { overflow-x: auto; } }
@media (max-width: 640px) { .topbar { display: block; padding: 10px 14px; } .topbar-left { justify-content: space-between; } .top-actions { justify-content: flex-start; max-width: none; margin-top: 9px; } .user-name { display: none; } .new-case-button { margin-left: auto; } .dashboard-wrap { width: min(100% - 24px, 1180px); padding-top: 14px; } .page-heading { display: block; padding-top: 20px; } .migration-badge { margin-top: 14px; } .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; } .stat-card { min-height: 99px; padding: 13px 10px; } .stat-value { font-size: 1.2rem; } .view-tabs { gap: 17px; overflow-x: auto; } .view-tab { flex: 0 0 auto; } .queue-toolbar { grid-template-columns: 1fr; } .search-box { grid-column: auto; } .detail-grid { grid-template-columns: 1fr; } .detail-wide { grid-column: auto; } }
