/* taxcite — the visual language is the accounting workpaper: columnar ledger
   paper, hairline rules, and the two pencils a reviewer actually holds. Blue
   pencil marks work that stands. Red pencil marks an exception. Every
   verification verdict is a tick mark in the margin, with a legend, exactly as
   it would be on paper. */

:root {
  --paper:        #faf9f6;
  --surface:      #ffffff;
  --surface-sunk: #f3f2ed;
  --greenbar:     #e6efe4;
  --ink:          #15181b;
  --ink-soft:     #545b62;
  --ink-faint:    #878d93;
  --rule:         #dcd9d1;
  --rule-strong:  #b9b5aa;
  --pencil-blue:  #2d5c8a;
  --pencil-blue-wash: #dce8f3;
  --pencil-red:   #b3271e;
  --pencil-red-wash:  #f6e0de;
  --pencil-amber: #9a6208;
  --pencil-amber-wash:#f7e9d2;
  --highlight:    #fff2a8;
  --shadow:       0 1px 2px rgba(20, 24, 27, .06), 0 8px 24px -12px rgba(20, 24, 27, .18);

  --sans:  "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  --serif: "IBM Plex Serif", ui-serif, Georgia, "Times New Roman", serif;
  --mono:  "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --rail: 232px;
  --pad: clamp(18px, 3vw, 40px);
}

:root[data-theme="dark"] {
  --paper:        #14171a;
  --surface:      #1a1e22;
  --surface-sunk: #202529;
  --greenbar:     #1c2621;
  --ink:          #e9eae7;
  --ink-soft:     #a6adb4;
  --ink-faint:    #7b838a;
  --rule:         #2b3137;
  --rule-strong:  #3d454c;
  --pencil-blue:  #86b4de;
  --pencil-blue-wash: #1c2c3b;
  --pencil-red:   #ea7167;
  --pencil-red-wash:  #35201e;
  --pencil-amber: #d9a04a;
  --pencil-amber-wash:#332715;
  --highlight:    #5c5320;
  --shadow:       0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--pencil-blue); }

/* ---------------------------------------------------------- masthead ---- */
.masthead {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px var(--pad);
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 40;
}
.mark { display: flex; align-items: center; gap: 14px; }
.pilcrow {
  font-family: var(--serif); font-size: 30px; line-height: 1;
  width: 42px; height: 42px; display: grid; place-items: center;
  color: var(--surface); background: var(--ink); border-radius: 3px;
}
.masthead h1 {
  margin: 0; font-family: var(--mono); font-size: 17px; font-weight: 600;
  letter-spacing: .06em; text-transform: lowercase;
}
.masthead p { margin: 0; font-size: 12.5px; color: var(--ink-soft); }
.masthead-right { display: flex; align-items: center; gap: 14px; }

.corpus-badge {
  margin: 0; display: flex; align-items: baseline; gap: 8px;
  font-family: var(--mono); font-size: 12px;
}
.corpus-badge dt { color: var(--ink-faint); text-transform: uppercase; letter-spacing: .07em; }
.corpus-badge dd { margin: 0; font-weight: 600; }

.ghost {
  background: transparent; border: 1px solid var(--rule-strong); border-radius: 3px;
  padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--ink-soft);
}
.ghost:hover { border-color: var(--ink); color: var(--ink); }

/* ------------------------------------------------------------- shell ---- */
.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); align-items: start; }

.index-rail {
  position: sticky; top: 71px; align-self: start;
  border-right: 1px solid var(--rule);
  padding: 22px 0 22px var(--pad);
  min-height: calc(100vh - 71px);
}
.index-rail ol { list-style: none; margin: 0; padding: 0; }
.index-rail li { border-bottom: 1px solid var(--rule); }
.tab {
  width: 100%; display: flex; align-items: center; gap: 12px;
  background: none; border: 0; padding: 11px 14px 11px 0; cursor: pointer;
  text-align: left; font-size: 14px; color: var(--ink-soft);
}
.tab span {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  width: 20px; height: 20px; display: grid; place-items: center;
  border: 1px solid var(--rule-strong); border-radius: 2px; color: var(--ink-faint);
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); font-weight: 600; }
.tab.active span { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.tab em {
  margin-left: auto; font-style: normal; font-family: var(--mono); font-size: 11px;
  background: var(--pencil-red); color: #fff; border-radius: 2px; padding: 1px 5px;
}
.tab em:empty { display: none; }
.rail-note {
  margin-top: 22px; padding-right: 18px;
  font-size: 12.5px; line-height: 1.5; color: var(--ink-faint);
  border-left: 2px solid var(--pencil-blue); padding-left: 12px;
}
.rail-note p { margin: 0; }

main { padding: 26px var(--pad) 90px; max-width: 1080px; }
.view { display: none; }
.view.active { display: block; }

/* -------------------------------------------------------- workpaper ---- */
.workpaper-head { margin-bottom: 22px; }
.eyebrow {
  margin: 0 0 6px; font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint);
}
.workpaper-head h2 {
  margin: 0 0 8px; font-family: var(--serif); font-weight: 600;
  font-size: clamp(24px, 3vw, 31px); line-height: 1.2; letter-spacing: -.01em;
}
.lede { margin: 0; max-width: 68ch; color: var(--ink-soft); font-size: 14.5px; }

.entry {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 3px;
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.field { display: block; }
.field > span {
  display: block; font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 7px;
}
textarea {
  width: 100%; background: var(--paper); border: 1px solid var(--rule);
  border-radius: 2px; padding: 11px 12px; resize: vertical; line-height: 1.5;
}
textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--pencil-blue); outline-offset: 2px;
}
#engagementJson { font-family: var(--mono); font-size: 12.5px; }

.entry-actions { display: flex; align-items: center; gap: 14px; margin-top: 13px; flex-wrap: wrap; }
.primary {
  background: var(--ink); color: var(--paper); border: 1px solid var(--ink);
  border-radius: 2px; padding: 9px 20px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.primary:hover { background: var(--pencil-blue); border-color: var(--pencil-blue); color: #fff; }
.primary[disabled] { opacity: .5; cursor: progress; }
.hint { font-size: 12.5px; color: var(--ink-faint); font-family: var(--mono); }

.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.examples button {
  background: var(--surface-sunk); border: 1px solid var(--rule); border-radius: 2px;
  padding: 7px 11px; font-size: 12.5px; cursor: pointer; color: var(--ink-soft); text-align: left;
}
.examples button:hover { border-color: var(--pencil-blue); color: var(--ink); }

.sample-picker { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.sample-card {
  flex: 1 1 240px; text-align: left; cursor: pointer;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 3px; padding: 12px 14px;
}
.sample-card.active { border-color: var(--pencil-blue); background: var(--pencil-blue-wash); }
.sample-card strong { display: block; font-size: 14px; }
.sample-card span { font-size: 12.5px; color: var(--ink-soft); font-family: var(--mono); }
.paste { margin-top: 4px; }
.paste summary { cursor: pointer; font-size: 13px; color: var(--ink-soft); }
.paste textarea { margin-top: 10px; }

/* ------------------------------------------------------------ output ---- */
.card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 3px;
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.card > header {
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
  padding: 13px 18px; border-bottom: 1px solid var(--rule); background: var(--surface-sunk);
  flex-wrap: wrap;
}
.card > header h3 { margin: 0; font-family: var(--serif); font-size: 18px; font-weight: 600; }
.card-body { padding: 18px; }

.answer { font-family: var(--serif); font-size: 17px; line-height: 1.62; margin: 0 0 4px; }

/* the tick-mark margin — the signature device */
.claim { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 0 14px; padding: 15px 0; border-top: 1px solid var(--rule); }
.claim:first-of-type { border-top: 0; }
.claim-tick { padding-top: 2px; }
.tick {
  display: inline-grid; place-items: center; width: 22px; height: 22px;
  font-family: var(--mono); font-size: 13px; font-weight: 600; border-radius: 2px;
  border: 1px solid currentColor;
}
.tick.verified    { color: var(--pencil-blue);  background: var(--pencil-blue-wash); }
.tick.miscited    { color: var(--pencil-amber); background: var(--pencil-amber-wash); }
.tick.unsupported,
.tick.malformed   { color: var(--pencil-red);   background: var(--pencil-red-wash); }

.claim h4 { margin: 0 0 5px; font-size: 13px; font-family: var(--mono); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-faint); }
.claim p  { margin: 0 0 9px; }
.cites { display: flex; flex-wrap: wrap; gap: 7px; }
.cite {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  background: var(--paper); border: 1px solid var(--rule); border-left: 3px solid var(--pencil-blue);
  border-radius: 2px; padding: 5px 10px; font-family: var(--mono); font-size: 12px; color: var(--ink);
}
.cite:hover { border-color: var(--pencil-blue); background: var(--pencil-blue-wash); }
.cite.miscited { border-left-color: var(--pencil-amber); }
.cite.unsupported, .cite.malformed { border-left-color: var(--pencil-red); text-decoration: line-through; }
.cite-note { display: block; margin-top: 6px; font-size: 12px; color: var(--pencil-amber); }

.quote {
  font-family: var(--serif); font-style: italic; color: var(--ink-soft);
  border-left: 2px solid var(--rule-strong); padding-left: 12px; margin: 8px 0 0; font-size: 14px;
}
.quote cite {
  display: block; font-family: var(--mono); font-style: normal; font-size: 11px;
  letter-spacing: .04em; color: var(--ink-faint); margin-top: 3px;
}

/* verification strip */
.verification {
  display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--rule); border-radius: 3px;
  overflow: hidden; margin-bottom: 18px; background: var(--surface);
}
.vstat { flex: 1 1 120px; padding: 12px 16px; border-right: 1px solid var(--rule); }
.vstat:last-child { border-right: 0; }
.vstat dt { font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.vstat dd { margin: 3px 0 0; font-family: var(--mono); font-size: 21px; font-weight: 600; }
.vstat.bad dd  { color: var(--pencil-red); }
.vstat.warn dd { color: var(--pencil-amber); }
.vstat.good dd { color: var(--pencil-blue); }

.flags { list-style: none; margin: 0 0 18px; padding: 0; }
.flags li {
  border-left: 3px solid var(--pencil-red); background: var(--pencil-red-wash);
  padding: 9px 13px; margin-bottom: 6px; font-size: 13.5px; border-radius: 0 2px 2px 0;
}
.flags li.clean { border-left-color: var(--pencil-blue); background: var(--pencil-blue-wash); }

.meters { display: grid; gap: 9px; }
.meter { display: grid; grid-template-columns: 190px 1fr 52px; gap: 12px; align-items: center; font-size: 13px; }
.meter-track { height: 7px; background: var(--surface-sunk); border-radius: 4px; overflow: hidden; border: 1px solid var(--rule); }
.meter-fill { height: 100%; background: var(--pencil-blue); }
.meter-fill.penalty { background: var(--pencil-red); }
.meter b { font-family: var(--mono); font-weight: 600; text-align: right; }
.meter small { display: block; color: var(--ink-faint); font-size: 11.5px; }

/* greenbar ledger table */
table.ledger { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.ledger th {
  text-align: left; font-family: var(--mono); font-size: 10.5px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--ink-faint); padding: 9px 12px;
  border-bottom: 1px solid var(--rule-strong); white-space: nowrap;
}
table.ledger td { padding: 8px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.ledger tbody tr:nth-child(even) { background: var(--greenbar); }
table.ledger .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.ledger .up   { color: var(--pencil-blue); }
table.ledger .down { color: var(--pencil-red); }
table.ledger .unmapped td:first-child::after {
  content: "unmapped"; margin-left: 8px; font-family: var(--mono); font-size: 10px;
  color: var(--pencil-amber); border: 1px solid currentColor; padding: 0 4px; border-radius: 2px;
}
.table-wrap { overflow-x: auto; }

/* findings */
.finding { border-top: 1px solid var(--rule); padding: 15px 0; }
.finding:first-child { border-top: 0; }
.finding-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 5px; }
.finding-head h4 { margin: 0; font-size: 15px; font-weight: 600; }
.pill {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  border: 1px solid var(--rule-strong); border-radius: 2px; padding: 1px 6px; color: var(--ink-faint);
}
.pill.high { color: var(--pencil-red); border-color: currentColor; background: var(--pencil-red-wash); }
.pill.medium { color: var(--pencil-amber); border-color: currentColor; background: var(--pencil-amber-wash); }
.pill.rule { color: var(--pencil-blue); border-color: currentColor; background: var(--pencil-blue-wash); }
.observation { margin: 0 0 6px; }
.consideration { margin: 0 0 9px; color: var(--ink-soft); }

/* review queue */
.queue-item { border-top: 1px solid var(--rule); padding: 16px 0; }
.queue-item:first-child { border-top: 0; }
.queue-actions { display: flex; gap: 9px; margin-top: 11px; align-items: center; flex-wrap: wrap; }
.queue-actions input {
  flex: 1 1 240px; background: var(--paper); border: 1px solid var(--rule);
  border-radius: 2px; padding: 7px 10px; font-size: 13px;
}
.approve { background: var(--pencil-blue); border-color: var(--pencil-blue); color: #fff; }
.approve:hover { filter: brightness(1.08); }
.reject { border-color: var(--pencil-red); color: var(--pencil-red); background: transparent; }
.reject:hover { background: var(--pencil-red-wash); }
.btn { border: 1px solid var(--rule-strong); border-radius: 2px; padding: 7px 15px; cursor: pointer; font-size: 13px; font-weight: 600; }
.decided { font-family: var(--mono); font-size: 12px; color: var(--ink-faint); margin-top: 8px; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 2px;
  padding: 6px 13px; font-size: 13px; cursor: pointer; color: var(--ink-soft);
}
.chip.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }

details.raw { margin-top: 16px; border-top: 1px solid var(--rule); padding-top: 13px; }
details.raw summary { cursor: pointer; font-size: 13px; color: var(--ink-soft); font-family: var(--mono); }
details.raw pre {
  margin: 11px 0 0; background: var(--surface-sunk); border: 1px solid var(--rule);
  border-radius: 2px; padding: 13px; overflow: auto; max-height: 380px;
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
}

.empty { color: var(--ink-faint); font-size: 14px; padding: 22px 0; }
.telemetry { font-family: var(--mono); font-size: 11.5px; color: var(--ink-faint); }

/* ------------------------------------------------------------ drawer ---- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(620px, 92vw);
  background: var(--surface); border-left: 1px solid var(--rule-strong);
  transform: translateX(102%); transition: transform .24s ease; z-index: 60;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer.open { transform: none; }
.drawer > header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 16px 20px; border-bottom: 1px solid var(--rule);
}
.drawer h3 { margin: 0; font-family: var(--serif); font-size: 18px; }
.drawer-body { overflow: auto; padding: 18px 20px; flex: 1; }
.drawer pre {
  margin: 0; white-space: pre-wrap; font-family: var(--serif); font-size: 14.5px; line-height: 1.66;
}
.drawer mark { background: var(--highlight); color: inherit; padding: 1px 0; }
.drawer > footer {
  padding: 12px 20px; border-top: 1px solid var(--rule); font-size: 12px; color: var(--ink-faint);
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.scrim {
  position: fixed; inset: 0; background: rgba(10, 12, 14, .38); opacity: 0; pointer-events: none;
  transition: opacity .24s ease; z-index: 50;
}
.scrim.open { opacity: 1; pointer-events: auto; }

/* ------------------------------------------------------------ legend ---- */
.legend {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px var(--pad); background: var(--surface); border-top: 1px solid var(--rule);
  font-size: 12px; color: var(--ink-soft);
}
.legend .tick { width: 19px; height: 19px; font-size: 11.5px; margin-left: 10px; }
.legend .tick:first-of-type { margin-left: 0; }
.legend-title {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint); margin-right: 4px;
}
.legend-spacer { flex: 1; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .index-rail {
    position: static; min-height: 0; border-right: 0; border-bottom: 1px solid var(--rule);
    padding: 10px var(--pad);
  }
  .index-rail ol { display: flex; gap: 4px; overflow-x: auto; }
  .index-rail li { border-bottom: 0; }
  .tab { padding: 8px 12px; white-space: nowrap; }
  .rail-note { display: none; }
  .meter { grid-template-columns: 1fr; gap: 4px; }
  .legend { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
