:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #fff;
  --surface-muted: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #cbd5e1;
  --primary: #2563eb;
  --primary-muted: #eff6ff;
  --success: #047857;
  --danger: #b91c1c;
  --warning: #92400e;
  --focus: #2563eb;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1,h2,h3,p { margin-top: 0; }
h1 { font-size: 1.55rem; line-height: 1.2; }
h2 { font-size: 1.18rem; line-height: 1.3; }
h3 { font-size: 1rem; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.boot { display: grid; min-height: 100vh; place-items: center; color: var(--text-muted); }
.btn { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font-weight: 600; text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--surface-muted); }
.btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn.primary:hover:not(:disabled) { background: #1d4ed8; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 32px; padding: 4px 8px; }
.field { display: grid; gap: 5px; margin-bottom: 14px; }
.field label, label.field { font-weight: 600; }
.field input,.field select,.field textarea, input.search { width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: white; color: var(--text); }
textarea { resize: vertical; }
.field textarea { min-height: 78px; }
.field small { color: var(--text-muted); font-weight: 400; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(100%, 430px); }
.brand { font-weight: 850; letter-spacing: -.045em; font-size: 1.35rem; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; margin-right: 6px; border-radius: 8px; background: var(--primary); color: white; font-size: .95rem; letter-spacing: 0; }
.auth-card .brand { display: block; margin-bottom: 30px; }
.auth-card .btn.primary { width: 100%; }
.auth-switch { margin: 18px 0 0; text-align: center; }
.link { padding: 0; border: none; background: transparent; color: #1d4ed8; text-decoration: underline; }
.shell { height: 100dvh; min-height: 550px; display: grid; grid-template-columns: 210px minmax(0,1fr); }
.sidebar { display: flex; flex-direction: column; gap: 6px; background: var(--surface); border-right: 1px solid var(--border); padding: 20px 12px; }
.sidebar .brand { padding: 2px 10px 22px; }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; background: transparent; border: 0; border-radius: var(--radius); color: var(--text-muted); text-align: left; font-weight: 600; }
.nav-btn:hover,.nav-btn.active { background: var(--primary-muted); color: #1e40af; }
.nav-icon { width: 22px; font-size: 1.15rem; text-align: center; }
.identity { padding: 12px 8px 0; margin-top: auto; border-top: 1px solid var(--border); }
.identity strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.identity .small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace { min-width: 0; min-height: 0; }
.inbox { height: 100%; display: grid; grid-template-columns: 330px minmax(400px,1fr) 285px; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); }
.pane:last-child { border-right: 0; }
.pane-head { flex: none; padding: 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.pane-head h1,.pane-head h2 { margin-bottom: 3px; }
.pane-scroll { flex: 1; min-height: 0; overflow: auto; }
.list-controls { padding: 12px 16px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.segmented { display: flex; flex-wrap: wrap; gap: 4px; }
.segmented button { padding: 5px 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--text-muted); font-weight: 600; }
.segmented button.active { color: #1e40af; border-color: #bfdbfe; background: var(--primary-muted); }
.chat-item { width: 100%; display: grid; grid-template-columns: 38px minmax(0,1fr); gap: 10px; padding: 12px 16px; text-align: left; border: 0; border-bottom: 1px solid #e2e8f0; background: white; color: var(--text); }
.chat-item:hover,.chat-item.active { background: var(--primary-muted); }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: #dbeafe; color: #1e3a8a; font-weight: 800; }
.chat-item.group .avatar { background: #dcfce7; color: #166534; }
.chat-item .title-row { display: flex; gap: 6px; align-items: baseline; }
.chat-item .title { font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { margin-left: auto; color: var(--text-muted); font-size: .78rem; white-space: nowrap; }
.chat-item .preview { display: block; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.badge { display: inline-flex; align-items: center; border-radius: 100px; padding: 1px 7px; background: var(--surface-muted); color: var(--text-muted); font-size: .75rem; font-weight: 700; }
.badge.blue { color: #1e40af; background: #dbeafe; }
.badge.green { color: #065f46; background: #d1fae5; }
.badge.amber { color: #92400e; background: #fef3c7; }
.badge.red { color: #991b1b; background: #fee2e2; }
.thread { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.message { align-self: flex-start; width: fit-content; max-width: min(85%, 580px); padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px 10px 10px 2px; background: var(--surface); overflow-wrap: anywhere; }
.message.outbound { align-self: flex-end; background: #dbeafe; border-color: #bfdbfe; border-radius: 10px 10px 2px 10px; }
.message.evidence-highlight { outline: 3px solid var(--focus); outline-offset: 3px; }
.message .author { display: block; font-size: .78rem; font-weight: 700; color: #1d4ed8; margin-bottom: 2px; }
.message .body { white-space: pre-wrap; }
.message .meta { display: block; margin-top: 4px; color: var(--text-muted); font-size: .75rem; text-align: right; }
.review-strip { flex: none; padding: 8px 16px; background: #f0fdf4; border-bottom: 1px solid #bbf7d0; color: #166534; }
.review-strip p { margin: 5px 0; }
.review-strip details { margin-top: 5px; }
.review-info > summary { cursor: pointer; font-weight: 600; }
.read-toolbar { flex: none; padding: 7px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.load-more { display: block; width: calc(100% - 24px); margin: 12px; }
.review-actions { display: block; margin-top: 4px; text-align: right; }
.review-actions .link { min-height: 26px; }
.message.review-boundary { border-color: #16a34a; box-shadow: inset 3px 0 #16a34a; }
.chat-media { display: block; max-width: min(100%, 420px); max-height: 420px; border-radius: 8px; margin: 4px 0 6px; }
.message audio.chat-media { width: min(100%, 320px); }
.thread-search { flex: none; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.thread-results { flex: none; max-height: 150px; overflow: auto; display: grid; gap: 3px; padding: 6px 16px; border-bottom: 1px solid var(--border); }
.thread-result { text-align: left; border: 0; background: transparent; color: var(--text); padding: 5px; cursor: pointer; border-radius: 4px; }
.thread-result:hover,.thread-result:focus-visible { background: #eff6ff; }
.composer select { min-width: 180px; max-width: 260px; min-height: 34px; }
.composer { flex: none; display: grid; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: white; }
.mobile-compose-toggle { display: none; }
.composer textarea { width: 100%; min-height: 70px; max-height: 180px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); resize: vertical; }
.offline { padding: 8px 10px; color: var(--warning); background: #fffbeb; border: 1px solid #fde68a; border-radius: 7px; }
.case-content { padding: 16px; }
.case-content .field { margin-bottom: 10px; }
.case-actions { display: grid; gap: 7px; margin: 14px 0; }
.section-divider { border-top: 1px solid var(--border); margin: 18px 0; }
.timeline-item { border-left: 2px solid var(--border); padding: 0 0 12px 10px; margin-left: 4px; }
.timeline-item p { margin: 2px 0; }
.empty { display: grid; place-content: center; gap: 8px; padding: 40px 24px; text-align: center; color: var(--text-muted); min-height: 170px; }
.empty strong { color: var(--text); }
.screen { height: 100%; overflow: auto; padding: 28px; }
.screen-inner { max-width: 1000px; margin: 0 auto; }
.screen-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.kpis { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; margin: 18px 0 24px; }
.kpi { text-align: left; cursor: pointer; }
.kpi:hover { border-color: var(--primary); }
.kpi.static { cursor: default; }
.kpi.static:hover { border-color: var(--border); }
.kpi .value { font-size: 2rem; font-weight: 850; line-height: 1.15; }
.kpi .label { color: var(--text-muted); font-weight: 650; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th,td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-size: .82rem; }
tr:hover td { background: var(--surface-muted); }
.settings-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.qr { display: block; width: min(100%,260px); margin: 15px auto; }
#toast { position: fixed; z-index: 100; right: 18px; bottom: 18px; max-width: 360px; pointer-events: none; }
#toast:not(:empty) { padding: 12px 16px; border-radius: var(--radius); background: var(--text); color: white; box-shadow: 0 10px 30px #0f172a30; }
#toast.error { background: #991b1b; }
dialog { width: min(95vw, 520px); padding: 0; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 20px 60px #0f172a33; }
dialog::backdrop { background: #0f172a80; }
.modal-body { padding: 22px; }
.review-history { max-height: 85dvh; overflow: auto; }
.review-history-list { display: grid; gap: 8px; padding-left: 22px; }
.review-history-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 12px; }
.mobile-back { display: none; }
.case-scrim { display: none; }
@media (min-width: 1200px) { [data-close-case] { display: none; } }
@media (max-width: 1199px) {
  .shell { grid-template-columns: 64px minmax(0,1fr); }
  .sidebar { padding: 16px 6px; align-items: center; }
  .sidebar .brand { padding: 2px 0 20px; font-size: 0; }
  .sidebar .brand-mark { font-size: .95rem; margin: 0; }
  .nav-btn { justify-content: center; padding: 10px 5px; }
  .nav-label,.identity strong,.identity .small,.identity .btn { display: none; }
  .identity { width: 100%; min-height: 20px; }
  .inbox { grid-template-columns: 300px minmax(0,1fr); }
  .case-pane { position: fixed; z-index: 20; top: 0; bottom: 0; right: 0; width: min(360px,100vw); box-shadow: -12px 0 40px #0f172a22; transform: translateX(105%); transition: transform .2s; }
  .case-pane.open { transform: translateX(0); }
  .case-scrim.open { display: block; position: fixed; inset: 0; z-index: 19; background: #0f172a88; }
}
@media (max-width: 767px) {
  .shell { display: flex; flex-direction: column; min-height: 0; }
  .sidebar { order: 2; flex-direction: row; width: 100%; height: 60px; border-right: 0; border-top: 1px solid var(--border); padding: 4px 8px; }
  .sidebar .brand,.identity { display: none; }
  .sidebar .nav-btn { flex: 1; min-width: 0; }
  .nav-label { display: block; font-size: .75rem; }
  .sidebar .nav-btn { font-size: .72rem; }
  .nav-btn { flex-direction: column; gap: 0; }
  .workspace { order: 1; flex: 1; height: calc(100dvh - 60px); }
  .inbox { display: block; position: relative; }
  .inbox .list-pane,.inbox .thread-pane { position: absolute; inset: 0; }
  .inbox[data-mobile-view="list"] .thread-pane,.inbox[data-mobile-view="thread"] .list-pane { display: none; }
  .case-pane { width: 100%; }
  .mobile-back { display: inline-flex; }
  .read-toolbar .small.muted { display: none; }
  .review-strip { padding: 6px 10px; }
  .review-strip .row { gap: 4px; }
  .review-strip strong { font-size: .82rem; }
  .review-info > summary { font-size: .8rem; }
  .mobile-compose-toggle { display: inline-flex; flex: none; min-height: 38px; width: 100%; border-radius: 0; }
  .composer:not(.compose-open) { display: none; }
  .thread { padding: 14px 12px; }
  .message { max-width: 92%; }
  .screen { padding: 18px 12px; }
  .screen-header { flex-direction: column; }
  .kpis { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 390px) { .kpis { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *,*::before,*::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; } }
