:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1d2430;
  --muted: #5a6474;
  --line: #dde2ea;
  --brand: #1f5f8b;
  --brand-ink: #ffffff;
  --gov: #1f5f8b;
  --pvt: #6b3fa0;
  --ok: #17663a;
  --warn: #9a6100;
  --bad: #b42318;
  --active: #fff6d6;
  --rec: #d92d20;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, monospace; word-break: break-all; }

/* layout */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--brand); text-decoration: none; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); }
.nav a.on { background: #e8f0f7; color: var(--brand); font-weight: 600; }
.spacer { flex: 1; }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* controls */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: #b8c1ce; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label.f { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; }
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3e3; border-color: var(--brand); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 14px; cursor: pointer; color: var(--muted); }
.seg button.on.state { background: var(--gov); color: #fff; }
.seg button.on.private { background: var(--pvt); color: #fff; }

.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.chip.draft { background: #fff3d6; color: var(--warn); }
.chip.final { background: #e1f2e8; color: var(--ok); }
.chip.submitted { background: #e3ecfa; color: var(--brand); }
.chip.state { background: #e3ecfa; color: var(--gov); }
.chip.private { background: #efe7f8; color: var(--pvt); }

table.list { width: 100%; border-collapse: collapse; background: var(--panel); }
table.list th, table.list td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); }
table.list th { font-size: .8rem; color: var(--muted); font-weight: 600; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: #f8fafc; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }

/* login */
.login { max-width: 360px; margin: 10vh auto; }

/* editor */
.editor { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
.dictation { position: sticky; top: 70px; display: grid; gap: 12px; }
.mic { width: 100%; padding: 18px; border-radius: 14px; border: 0; font-size: 1.1rem; font-weight: 700; cursor: pointer; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; gap: 10px; }
.mic.rec { background: var(--rec); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(217,45,32,.15); } }
.dot { width: 12px; height: 12px; border-radius: 50%; background: currentColor; }
.interim { min-height: 1.4em; font-style: italic; color: var(--muted); }
.active-field { font-weight: 600; color: var(--brand); }
.transcript { max-height: 30vh; overflow: auto; font-size: .85rem; white-space: pre-wrap; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.help { font-size: .82rem; color: var(--muted); }
.help code { background: #eef2f6; padding: 1px 5px; border-radius: 4px; }
.section { margin-bottom: 14px; }
.section h3 { margin: 0 0 10px; font-size: .95rem; padding: 8px 10px; background: #eef2f6; border-radius: 8px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.field.wide { grid-column: 1 / -1; }
.field.on input, .field.on textarea, .field.on select { background: var(--active); border-color: #e0b100; }
.field.flash input, .field.flash textarea, .field.flash select { transition: background .1s; background: #dff5e6; }
.alias { font-size: .72rem; color: #8a93a2; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.thumbs figure { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.thumbs img { width: 100%; height: 110px; object-fit: cover; display: block; }
.thumbs figcaption { padding: 6px; display: grid; gap: 4px; }

/* dialogs */
dialog { border: 0; border-radius: 12px; padding: 20px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 28, 40, .45); }
.sigpad { border: 1px dashed #9aa5b5; border-radius: 8px; background: #fff; touch-action: none; width: 100%; height: 180px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2430; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); z-index: 100; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-color: var(--brand); font-weight: 600; }
.json { font-family: ui-monospace, monospace; font-size: .8rem; min-height: 420px; }
.banner { padding: 10px 12px; border-radius: 8px; background: #fff3d6; color: #6b4700; font-size: .88rem; }
.banner.info { background: #e8f0f7; color: #1b4a6b; }

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
  .dictation { position: static; }
  main { padding: 12px 16px; }
}
.seg form { display: contents; }
.topbar form { margin: 0; }
.filters { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.banner { margin-bottom: 12px; }
.case-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.case-head h1 { margin: 0; }
.photo-form { display: grid; gap: 8px; }

a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
