@import url("fonts.css");

:root {
  --bg: #f2f3ef;
  --surface: #ffffff;
  --surface-2: #f7f8f5;
  --ink: #1b2421;
  --muted: #56635e;
  --line: #d6dbd5;
  --line-strong: #b5bdb6;
  --primary: #0e5a52;
  --primary-ink: #ffffff;
  --primary-soft: #e3efec;
  --marker: #ffe16b;
  --marker-soft: #fff4c2;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #2e6b30;
  --ok-soft: #e6f2e4;
  --focus: #1d6fd6;

  --ui: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --letter: "Literata", Georgia, "Times New Roman", serif;

  /* modular scale 1.2 on 16px */
  --fs-sm: 0.833rem;
  --fs-base: 1rem;
  --fs-md: 1.2rem;
  --fs-lg: 1.44rem;
  --fs-xl: 1.728rem;

  --r-sm: 4px;
  --r-md: 8px;
  --shadow-panel: 0 1px 0 rgba(27, 36, 33, 0.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs-base)/1.5 var(--ui);
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; font-weight: 700; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
h4 { font-size: var(--fs-base); }
p { margin: 0 0 0.75em; }
a { color: var(--primary); }
small, .small { font-size: var(--fs-sm); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------ controls */

button, .btn {
  font: 700 var(--fs-base)/1.2 var(--ui);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  padding: 0.6rem 1rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--ink); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
button.primary:hover:not(:disabled) { background: #0a4741; }
button.quiet { border-color: transparent; background: transparent; color: var(--primary); padding: 0.4rem 0.5rem; }
button.quiet:hover:not(:disabled) { border-color: transparent; text-decoration: underline; }
button.danger { color: var(--danger); border-color: #e3b8b4; }
button.small, .btn.small { font-size: var(--fs-sm); padding: 0.35rem 0.6rem; }

label { display: block; font-weight: 700; margin: 0 0 0.3rem; }
label .hint, .hint { font-weight: 400; color: var(--muted); font-size: var(--fs-sm); display: block; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=datetime-local], input:not([type]), select, textarea {
  font: 400 var(--fs-base)/1.45 var(--ui);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 0.55rem 0.65rem;
  width: 100%;
}
textarea { resize: vertical; min-height: 5.5rem; }
textarea.letter { font-family: var(--letter); font-size: 1.05rem; line-height: 1.7; min-height: 22rem; padding: 1rem 1.1rem; }
.field { margin-bottom: 1rem; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.spread { justify-content: space-between; }
.check { display: flex; gap: 0.5rem; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 0.3rem; }
fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
legend { font-weight: 700; margin-bottom: 0.3rem; padding: 0; }
.scale { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.scale label { font-weight: 400; display: inline-flex; align-items: center; gap: 0.25rem; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.3rem 0.6rem; margin: 0; cursor: pointer; background: var(--surface); }
.scale label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.scale input { margin: 0; }

/* ------------------------------------------------------------ marks */

mark, .marker { background: var(--marker); color: var(--ink); padding: 0 0.15em; border-radius: 2px; }
.ref {
  font: 700 0.72em/1 var(--ui);
  border: 1px solid var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 3px;
  padding: 0.12em 0.32em;
  margin: 0 0.1em;
  vertical-align: 0.15em;
  cursor: pointer;
}
.ref.web { border-style: dashed; }
.ref.unknown { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); cursor: help; }
.ak { background: var(--marker); font: 700 0.72em/1 var(--ui); padding: 0.12em 0.32em; border-radius: 3px; vertical-align: 0.15em; cursor: help; }

.notice { border-left: 4px solid var(--line-strong); background: var(--surface-2); padding: 0.75rem 1rem; margin: 0 0 1rem; border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.notice.warn { border-color: #c79a00; background: var(--marker-soft); }
.notice.error { border-color: var(--danger); background: var(--danger-soft); }
.notice.ok { border-color: var(--ok); background: var(--ok-soft); }
.notice > :last-child { margin-bottom: 0; }

.tag { display: inline-block; font-size: var(--fs-sm); border: 1px solid var(--line); border-radius: 3px; padding: 0.05rem 0.4rem; color: var(--muted); background: var(--surface); }
.tag.ok { color: var(--ok); border-color: #b8d6b4; }
.tag.warn { color: #7a5d00; border-color: #e7cf6d; background: var(--marker-soft); }
.tag.err { color: var(--danger); border-color: #e3b8b4; }

/* ------------------------------------------------------------ advisor shell */

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .timer { font-variant-numeric: tabular-nums; color: var(--muted); }

.workbench { display: grid; grid-template-columns: 220px minmax(0, 1fr) 360px; min-height: calc(100vh - 54px); }
.workbench.no-side { grid-template-columns: 220px minmax(0, 1fr); }

.steps { list-style: none; margin: 0; padding: 1.25rem 0.75rem; border-right: 1px solid var(--line); counter-reset: step; }
.steps li { counter-increment: step; }
.steps button {
  width: 100%; text-align: left; border: 0; background: transparent; padding: 0.6rem 0.6rem; border-radius: var(--r-sm);
  font-weight: 400; color: var(--muted); display: grid; grid-template-columns: 1.8rem 1fr; align-items: center;
}
.steps button::before {
  content: counter(step);
  width: 1.5rem; height: 1.5rem; border-radius: 50%; border: 1.5px solid var(--line-strong);
  display: inline-grid; place-items: center; font-size: var(--fs-sm); font-weight: 700;
}
.steps button.done { color: var(--ink); }
.steps button.done::before { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.steps button.current { color: var(--ink); font-weight: 700; background: var(--surface); box-shadow: inset 3px 0 0 var(--primary); }
.steps button.current::before { background: var(--primary); border-color: var(--primary); color: #fff; }
.steps button:disabled { opacity: 0.45; }
.steps .busy-dot { grid-column: 2; font-size: var(--fs-sm); color: var(--primary); font-weight: 700; }

.main { padding: 1.75rem 2rem 4rem; min-width: 0; }
.column { max-width: 720px; }
.main h1 { margin-bottom: 0.25rem; }
.lede { color: var(--muted); margin-bottom: 1.5rem; max-width: 62ch; }

.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.block > h3:first-child, .block > h4:first-child { margin-top: 0; }
.block.quiet { background: transparent; border-style: dashed; }
.question-quote { font-family: var(--letter); font-size: 1.05rem; line-height: 1.65; border-left: 3px solid var(--line-strong); padding: 0.1rem 0 0.1rem 1rem; margin: 0 0 1rem; white-space: pre-wrap; }

.kv { display: grid; grid-template-columns: 11rem 1fr; gap: 0.35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
ul.plain { margin: 0.25rem 0 0.75rem; padding-left: 1.2rem; }
ul.plain li { margin-bottom: 0.25rem; }

.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; margin-top: 1.25rem; }
.instruction { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.instruction input { flex: 1; }

/* live log */
.livelog { font-size: var(--fs-sm); color: var(--muted); border-left: 2px solid var(--primary); padding-left: 0.75rem; margin: 0 0 1rem; }
.livelog div { padding: 0.1rem 0; }
.livelog .now { color: var(--ink); }
.spinner { display: inline-block; width: 0.9em; height: 0.9em; border: 2px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -0.1em; }
@keyframes spin { to { transform: rotate(360deg); } }

/* findings */
.finding { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); padding: 0.85rem 1rem; margin-bottom: 0.6rem; }
.finding.fb-useful { border-color: #a9cfa4; }
.finding.fb-incorrect { border-color: var(--danger); background: #fffafa; }
.finding.fb-incorrect .statement { text-decoration: line-through; text-decoration-color: var(--danger); }
.finding.fb-irrelevant { opacity: 0.6; }
.finding .statement { margin: 0 0 0.3rem; }
.finding .meta { font-size: var(--fs-sm); color: var(--muted); margin-bottom: 0.5rem; }
.finding .fb { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.finding .fb button { font-size: var(--fs-sm); padding: 0.3rem 0.55rem; font-weight: 400; }
.finding .fb button[aria-pressed=true] { border-color: var(--ink); font-weight: 700; background: var(--surface-2); }
.finding .fb-note { margin-top: 0.5rem; }

/* the letter (draft / final) */
.letter-doc {
  font-family: var(--letter); font-size: 1.05rem; line-height: 1.75;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 1.5rem 1.75rem; max-width: 68ch;
}
.letter-doc h2, .letter-doc h3 { font-family: var(--ui); font-size: var(--fs-md); margin: 1.2em 0 0.4em; }
.letter-doc h2:first-child, .letter-doc h3:first-child { margin-top: 0; }
.letter-doc ul, .letter-doc ol { padding-left: 1.3rem; }
.letter-doc li { margin-bottom: 0.3rem; }
.letter-doc .caret::after { content: "▍"; color: var(--primary); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.checks { border-top: 1px dashed var(--line-strong); margin-top: 1rem; padding-top: 0.75rem; }

/* side panel */
.side { border-left: 1px solid var(--line); background: var(--surface-2); display: flex; flex-direction: column; min-height: 0; position: sticky; top: 54px; height: calc(100vh - 54px); }
.side .tabs { display: flex; border-bottom: 1px solid var(--line); }
.side .tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 0.75rem; font-weight: 400; color: var(--muted); border-bottom: 3px solid transparent; }
.side .tabs button[aria-selected=true] { color: var(--ink); font-weight: 700; border-bottom-color: var(--primary); }
.side .pane { padding: 1rem 1.1rem; overflow-y: auto; flex: 1; }
.source-view h4 { margin-bottom: 0.15rem; }
.source-view .src-text { font-family: var(--letter); font-size: 0.95rem; line-height: 1.65; white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.75rem 0.85rem; margin-top: 0.6rem; }
.chat { display: flex; flex-direction: column; height: 100%; }
.chat .msgs { flex: 1; overflow-y: auto; padding: 1rem 1.1rem; }
.chat .msg { margin-bottom: 0.9rem; }
.chat .msg.user { background: var(--primary-soft); border-radius: var(--r-md); padding: 0.55rem 0.75rem; margin-left: 1.5rem; }
.chat .msg.assistant { font-family: var(--letter); line-height: 1.65; }
.chat form { border-top: 1px solid var(--line); padding: 0.75rem; display: flex; gap: 0.5rem; }
.chat textarea { min-height: 2.6rem; height: 2.6rem; }

/* pause overlay */
.overlay { position: fixed; inset: 0; background: rgba(242, 243, 239, 0.94); z-index: 50; display: grid; place-items: center; text-align: center; padding: 1rem; }
.overlay .box { max-width: 28rem; }

dialog { border: 1px solid var(--line-strong); border-radius: var(--r-md); padding: 1.5rem; max-width: min(36rem, calc(100vw - 2rem)); color: var(--ink); }
dialog::backdrop { background: rgba(27, 36, 33, 0.35); }

.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 0.6rem 1rem; border-radius: var(--r-sm); z-index: 60; max-width: calc(100vw - 2rem); }
.toast.error { background: var(--danger); }

.save-state { font-size: var(--fs-sm); color: var(--muted); }

/* home */
.home { max-width: 760px; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }
.case-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.case-list li { border-bottom: 1px solid var(--line); }
.case-list a { display: flex; gap: 1rem; justify-content: space-between; padding: 0.8rem 0.25rem; color: var(--ink); text-decoration: none; }
.case-list a:hover .q { text-decoration: underline; }
.case-list .q { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mobile-only { display: none; }

@media (max-width: 1100px) {
  .workbench, .workbench.no-side { grid-template-columns: 190px minmax(0, 1fr); }
  .side { position: fixed; right: 0; top: 54px; width: min(380px, 100vw); z-index: 30; box-shadow: -8px 0 24px rgba(27, 36, 33, 0.12); transform: translateX(100%); transition: transform 0.2s; }
  .side.open { transform: none; }
  .mobile-only { display: inline-flex; }
}
@media (max-width: 760px) {
  .workbench, .workbench.no-side { display: block; }
  .steps { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 0.5rem; gap: 0.25rem; }
  .steps li { flex: 0 0 auto; }
  .steps button { grid-template-columns: 1.7rem auto; white-space: nowrap; }
  .steps button.current { box-shadow: inset 0 -3px 0 var(--primary); }
  .main { padding: 1.25rem 1rem 3rem; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 0.4rem; }
  .letter-doc { padding: 1rem; }
  .topbar { padding: 0.5rem 1rem; gap: 0.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ------------------------------------------------------------ admin */

.admin-shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; }
.admin-nav { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem 0.6rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.admin-nav .brand { font-weight: 700; padding: 0.25rem 0.6rem 1rem; }
.admin-nav a { display: block; padding: 0.45rem 0.6rem; border-radius: var(--r-sm); color: var(--ink); text-decoration: none; }
.admin-nav a:hover { background: var(--surface-2); }
.admin-nav a[aria-current=page] { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.admin-nav .group { color: var(--muted); font-size: var(--fs-sm); padding: 0.9rem 0.6rem 0.25rem; }
.admin-main { padding: 1.5rem 2rem 4rem; min-width: 0; }
.admin-main > h1 { margin-bottom: 1rem; }

table.data { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); font-size: 0.95rem; }
table.data th, table.data td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: var(--fs-sm); color: var(--muted); font-weight: 700; background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; margin-bottom: 1.25rem; }
.trunc { max-width: 28rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 0.75rem 0.9rem; }
.stat .v { font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: var(--fs-sm); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
pre.code { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.75rem; overflow-x: auto; font-size: 0.82rem; white-space: pre-wrap; word-break: break-word; max-height: 32rem; }
.diff ins { background: var(--ok-soft); text-decoration: none; color: var(--ok); }
.diff del { background: var(--danger-soft); color: var(--danger); }
.diff { font-family: var(--letter); line-height: 1.7; white-space: pre-wrap; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 0.92rem; }
.timeline li { display: grid; grid-template-columns: 6.5rem 9rem 1fr; gap: 0.75rem; padding: 0.3rem 0; border-bottom: 1px solid var(--line); }
.timeline .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.progress { height: 0.5rem; background: var(--line); border-radius: 999px; overflow: hidden; min-width: 6rem; }
.progress > div { height: 100%; background: var(--primary); }
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
details > summary { cursor: pointer; font-weight: 700; padding: 0.4rem 0; }
.login { max-width: 22rem; margin: 15vh auto; padding: 0 1rem; }

@media (max-width: 900px) {
  .admin-shell { display: block; }
  .admin-nav { position: static; height: auto; display: flex; flex-wrap: wrap; gap: 0.25rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .admin-nav .group, .admin-nav .brand { display: none; }
  .admin-main { padding: 1rem; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .timeline li { grid-template-columns: 1fr; gap: 0; }
}
