:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #d9dde8;
  --text: #1b2033;
  --muted: #5b6380;
  --brand: #2f3e8f;
  --brand-ink: #ffffff;
  --brand-soft: #e6e9f7;
  --focus: #f0b400;
  --ok: #1d6b43; --ok-bg: #e2f3ea;
  --warn: #8a5300; --warn-bg: #fdf0d8;
  --bad: #a1262a; --bad-bg: #fbe4e4;
  --info: #1f5aa6; --info-bg: #e3edfa;
  --mark: #fff0a8; --mark-strong: #ffd84d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 25, 50, .06), 0 4px 16px rgba(20, 25, 50, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131c; --surface: #191c28; --surface-2: #212536; --border: #333a52;
    --text: #e8eaf3; --muted: #a2a9c4; --brand: #8f9cf0; --brand-ink: #11131c; --brand-soft: #262c4a;
    --ok: #7fd8a6; --ok-bg: #173526; --warn: #ffc56b; --warn-bg: #3a2c12; --bad: #ff9a9a; --bad-bg: #3d1a1c;
    --info: #9cc3ff; --info-bg: #182a44; --mark: #5a4d10; --mark-strong: #806a00;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
.loading, .noscript { padding: 48px; text-align: center; color: var(--muted); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: var(--mono); font-size: .85em; overflow-wrap: anywhere; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }

/* ── top bar ── */
#topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand .otto-mark { color: var(--brand); }
.brand small { font-weight: 500; color: var(--muted); font-size: .8rem; }
nav.main-nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav.main-nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
nav.main-nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
nav.main-nav a:hover { color: var(--text); }
.user-menu { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: var(--muted); }

main { max-width: 1280px; margin: 0 auto; padding: 24px 16px 64px; outline: none; }

/* ── controls ── */
.btn { font: inherit; font-weight: 500; font-size: .93rem; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; line-height: 1.3; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.08); background: var(--brand); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-otto { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
.btn-otto .otto-mark { color: var(--brand); }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn.is-busy::after { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { border: 0; background: transparent; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }
.linkish { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font: inherit; text-decoration: underline; }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=url], input[type=number], input:not([type]), select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
textarea { resize: vertical; min-height: 90px; }
textarea.body-editor { min-height: 340px; font-family: inherit; line-height: 1.55; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.field .hint { font-size: .82rem; color: var(--muted); margin: 4px 0 0; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.check input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 16px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 16px; }
legend { font-weight: 600; padding: 0 6px; }

/* ── cards / tables ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-warn { background: var(--warn-bg); color: var(--warn); }
.chip-bad { background: var(--bad-bg); color: var(--bad); }
.chip-info { background: var(--info-bg); color: var(--info); }
.chip-muted { background: var(--surface-2); color: var(--muted); }
.chip-neutral { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; border: 1px solid; display: flex; gap: 12px; align-items: flex-start; }
.banner-warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--text); }
.banner-info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.banner-bad { background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.notice-ai { font-size: .8rem; font-weight: 600; color: var(--warn); background: var(--warn-bg); padding: 2px 8px; border-radius: 6px; display: inline-block; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { color: var(--text); }

/* ── page head / tabs ── */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.case-meta { display: flex; gap: 8px 16px; flex-wrap: wrap; color: var(--muted); font-size: .92rem; margin-top: 6px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count { font-size: .75rem; background: var(--surface-2); border-radius: 999px; padding: 0 7px; margin-left: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }

/* ── evidence ── */
.split { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.split > * { min-width: 0; }
.split-even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.split-aside-right { grid-template-columns: minmax(0, 1fr) minmax(300px, 420px); }
.split-aside-left { grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); }
@media (max-width: 860px) { .split, .split-even, .split-aside-right, .split-aside-left { grid-template-columns: minmax(0, 1fr); } }
.ev-list { list-style: none; margin: 0; padding: 0; }
.ev-list li { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); margin-bottom: 8px; }
.ev-list li.child { margin-left: 18px; }
.ev-list button { all: unset; display: block; padding: 10px 12px; cursor: pointer; width: 100%; box-sizing: border-box; }
.ev-list li[aria-current="true"] { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.ev-list .t { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-list .s { font-size: .82rem; color: var(--muted); display: block; }
.source-text { white-space: pre-wrap; word-wrap: break-word; font-size: .95rem; line-height: 1.6; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; max-height: 70vh; overflow: auto; }
.source-text mark { background: var(--mark); color: inherit; border-radius: 2px; cursor: pointer; }
.source-text mark.focus { background: var(--mark-strong); outline: 2px solid var(--warn); }
.email-head { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; font-size: .9rem; margin-bottom: 10px; }
.email-head dt { color: var(--muted); }
.email-head dd { margin: 0; overflow-wrap: anywhere; }
.selection-bar { position: fixed; z-index: 40; display: flex; gap: 6px; background: var(--text); color: var(--bg); padding: 6px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.selection-bar .btn { background: transparent; color: inherit; border-color: transparent; }
.selection-bar .btn:hover { background: rgba(127,127,127,.25); }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); background: var(--surface); }
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); }

/* ── timeline ── */
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 118px; top: 0; bottom: 0; width: 2px; background: var(--border); }
@media (max-width: 700px) { .timeline::before { display: none; } }
.tl-item { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 20px; margin-bottom: 14px; position: relative; }
@media (max-width: 700px) { .tl-item { grid-template-columns: minmax(0, 1fr); gap: 4px; } }
.tl-date { text-align: right; font-weight: 600; font-size: .88rem; padding-top: 14px; }
@media (max-width: 700px) { .tl-date { text-align: left; padding-top: 0; } }
.tl-date small { display: block; font-weight: 400; color: var(--muted); }
.tl-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; position: relative; }
.tl-card::before { content: ""; position: absolute; left: -15px; top: 18px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }
@media (max-width: 700px) { .tl-card::before { display: none; } }
.tl-item.st-accepted .tl-card { border-left: 4px solid var(--ok); }
.tl-item.st-candidate .tl-card { border-left: 4px dashed var(--info); }
.tl-item.st-needs_clarification .tl-card { border-left: 4px dashed var(--warn); }
.tl-item.st-rejected .tl-card { opacity: .6; }
.tl-summary { font-weight: 600; margin-bottom: 6px; }
.tl-quote { border-left: 3px solid var(--border); padding: 2px 10px; color: var(--muted); font-size: .9rem; margin: 6px 0; white-space: pre-wrap; }
.tl-flag { font-size: .85rem; color: var(--warn); margin: 4px 0; }
.tl-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters select, .filters input { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; font: inherit; font-size: .88rem; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ── policy / assessments ── */
.claim { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; background: var(--surface); }
.claim h4 { margin: 0 0 8px; font-size: 1rem; }
.claim .cite { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; margin: 6px 0; font-size: .9rem; }
.claim .cite b { display: block; font-size: .8rem; color: var(--muted); }
.claim ul { margin: 4px 0 8px; padding-left: 20px; }
.passage { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface); font-size: .92rem; white-space: pre-wrap; }
.passage b { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.diff-del { background: var(--bad-bg); text-decoration: line-through; }
.diff-add { background: var(--ok-bg); }

/* ── drafts ── */
.draft-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .draft-layout { grid-template-columns: minmax(0, 1fr); } }
.draft-layout > * { min-width: 0; }
.ingredient { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: .88rem; background: var(--surface); }
.ingredient b { display: block; font-size: .78rem; color: var(--muted); }
.ingredient .q { white-space: pre-wrap; max-height: 7.5em; overflow: hidden; }
.otto-panel { border: 2px solid var(--brand-soft); border-radius: var(--radius); padding: 14px; background: var(--surface); }
.otto-panel h3 { display: flex; gap: 8px; align-items: center; color: var(--brand); }
.presend dl { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 6px 12px; margin: 0 0 12px; }
.presend dt { color: var(--muted); font-weight: 600; font-size: .9rem; }
.presend dd { margin: 0; overflow-wrap: anywhere; }
.presend pre { white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 8px; max-height: 260px; overflow: auto; font-family: inherit; }

/* ── modal ── */
dialog.modal { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog.modal-wide { width: min(900px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 12, 25, .5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 12px 20px; overflow: auto; max-height: calc(100vh - 200px); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-error { color: var(--bad); font-weight: 500; margin-top: 8px; }
.modal-error:empty { display: none; }

/* ── toasts ── */
#toasts { position: fixed; bottom: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgba(0,0,0,.2); transition: opacity .5s; }
.toast-bad { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; }

/* ── login ── */
.auth-wrap { min-height: 80vh; display: grid; place-items: center; }
.auth-card { width: min(420px, 100%); }
.auth-card .brand { justify-content: center; font-size: 1.3rem; margin-bottom: 6px; }
.auth-card .tag { text-align: center; color: var(--muted); margin-bottom: 20px; }

/* ── settings ── */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 800px) { .settings-layout { grid-template-columns: minmax(0, 1fr); } }
.side-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 80px; }
@media (max-width: 800px) { .side-nav { position: static; flex-direction: row; flex-wrap: wrap; } }
.side-nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; }
.side-nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.secret-hint { font-family: var(--mono); font-size: .85rem; color: var(--muted); }
.kv { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 4px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.audit-meta { font-family: var(--mono); font-size: .78rem; color: var(--muted); max-width: 420px; overflow-wrap: anywhere; }

@media (max-width: 520px) { .presend dl { grid-template-columns: minmax(0, 1fr); } .kv { grid-template-columns: minmax(0, 1fr); } .kv dt { margin-top: 6px; } }
main:focus, main:focus-visible { outline: none; }
@media (max-width: 640px) {
  .topbar-inner { gap: 8px 12px; }
  nav.main-nav { order: 3; flex-basis: 100%; }
  .user-menu { margin-left: auto; }
}

/* ── feedback ── */
.feedback-box { border: 1px dashed var(--border); border-radius: var(--radius); padding: 10px 14px; margin: 14px 0; background: var(--surface); }
.feedback-box .field { margin-bottom: 8px; }
.feedback-box textarea { min-height: 54px; }
.stars { display: inline-flex; gap: 2px; }
.star { cursor: pointer; font-size: 1.35rem; line-height: 1; color: var(--border); position: relative; }
.star input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.star:has(input:focus-visible) { outline: 3px solid var(--focus); border-radius: 4px; }
.stars:has(.star:nth-child(1) input:checked) .star:nth-child(-n+1),
.stars:has(.star:nth-child(2) input:checked) .star:nth-child(-n+2),
.stars:has(.star:nth-child(3) input:checked) .star:nth-child(-n+3),
.stars:has(.star:nth-child(4) input:checked) .star:nth-child(-n+4),
.stars:has(.star:nth-child(5) input:checked) .star:nth-child(-n+5) { color: #e0a000; }
.stars:hover .star { color: #e0a000; }
.stars .star:hover ~ .star { color: var(--border); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── chips ── */
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip .x { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 4px; font: inherit; opacity: .7; }
.chip .x:hover { opacity: 1; }
.chip-otto::before { content: "◉ "; font-size: .7em; vertical-align: 1px; }
.nav-count { font-size: .72rem; background: var(--bad); color: #fff; border-radius: 999px; padding: 0 6px; margin-left: 4px; vertical-align: 1px; }

/* ── inbox ── */
.proposal { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface); }
.proposal.off { opacity: .6; }
.proposal .why { font-size: .82rem; color: var(--muted); margin: 4px 0 0; }
.proposal .edit { margin-top: 8px; }
.decision { border: 2px solid var(--brand-soft); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.decision label.opt { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; margin: 6px 0; }
.meter { display: inline-block; width: 80px; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.meter > span { display: block; height: 100%; background: var(--brand); }
.bar-row { display: grid; grid-template-columns: 140px minmax(0, 1fr) 60px; gap: 8px; align-items: center; font-size: .88rem; margin: 3px 0; }
.bar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.split > .card + .card, .split > * + .card { margin-top: 0; }
