:root {
  /* Backup Investigations. Palette taken from the agency mark: gold rule and
     lettering, cream, and a true black ground. Gold carries two values because
     the bright one is illegible on paper and the deep one disappears on black. */
  --ink: #0f1114; --noir: #000000; --noir-soft: #1a1c20;
  --muted: #5d6472; --faint: #8b929e;
  --rule: #e2ddd3; --bg: #f6f3ec; --panel: #fffdf9; --soft: #efeae0;
  --gold: #8f6414; --gold-bright: #e0b054; --gold-soft: #f7edd7;
  --amber: #8f6414; --amber-bright: #e0b054; --amber-soft: #f7edd7;
  --accent: #8f6414; --accent-soft: #f7edd7;
  --cream: #f5f0e6;
  --warn-bg: #fdf4e3; --warn-rule: #e3c68d; --warn-ink: #7a5210;
  --danger: #9d2b22; --ok: #3d6b46;
  --radius: 5px;
  --shadow: 0 1px 2px rgba(15,17,20,.05), 0 6px 18px rgba(15,17,20,.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.011em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.08rem; }
p { margin: 0 0 .9rem; }
a { color: var(--accent); }
small, .small { font-size: .84rem; color: var(--muted); }

.wrap { max-width: 46rem; margin: 0 auto; padding: 2.5rem 1.25rem 5rem; }

.masthead { display: flex; align-items: center; gap: 1.1rem; margin-bottom: .7rem; }
/* Full lockup, used where there is room for it: login, report cover. */
.lockup { display: block; width: 100%; max-width: 20rem; height: auto; margin: 0 auto 1rem; }
/* Compact head-only mark for the page header. */
/* The mark is transparent artwork with its own black roundel and banner, so
   it sits directly on the page - no tile behind it. */
.mark {
  /* Backup gets to be the header. Clamped rather than fixed: at the full 9rem
     the lockup is wider than the 46rem column on a phone, and a hard size
     would either overflow or force the wordmark to wrap mid-word. */
  width: clamp(4rem, 13vw, 9rem);
  height: clamp(4rem, 13vw, 9rem);
  flex: 0 0 auto; display: block; object-fit: contain;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name {
  /* Tracks the mark so the lockup stays balanced at every width. */
  font-size: clamp(1.4rem, 5vw, 3rem);
  font-weight: 700; letter-spacing: -.025em; color: var(--ink);
  line-height: 1.05;
}
.brand-name em { font-style: normal; color: var(--amber); }
.brand-tag {
  font-size: clamp(.72rem, 1.7vw, 1.05rem);
  color: var(--muted); letter-spacing: .08em; text-transform: uppercase;
  margin-top: .35rem;
}
/* A hairline of amber under the masthead - the one flourish. */
.masthead + .lede { padding-top: .8rem; border-top: 3px solid var(--amber); margin-top: .2rem; }
.lede { color: var(--muted); margin-bottom: 1.6rem; }

.panel {
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 1.4rem 1.5rem; box-shadow: var(--shadow); margin-bottom: 1.2rem;
}
.panel > h2 { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.step {
  width: 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); font-size: .78rem; font-weight: 700; display: grid; place-items: center;
  flex: 0 0 auto;
}

.notice {
  background: var(--warn-bg); border: 1px solid var(--warn-rule); border-left-width: 3px;
  border-radius: var(--radius); padding: .85rem 1rem; font-size: .87rem; color: var(--warn-ink);
  margin-bottom: 1.4rem;
}
.notice b { color: #5c3a04; }

.grid { display: grid; gap: .9rem 1rem; grid-template-columns: 1fr 1fr; }
.grid .full { grid-column: 1 / -1; }
@media (max-width: 34rem) { .grid { grid-template-columns: 1fr; } }

label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .28rem; }
label .opt { font-weight: 400; color: var(--faint); }
input[type=text], textarea, select {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--rule); border-radius: 5px;
  background: #fff; font: inherit; font-size: .92rem; color: var(--ink);
}
input[type=text]:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent-soft); outline-offset: 0; border-color: var(--accent);
}
textarea { resize: vertical; min-height: 4.5rem; }
.hint { font-size: .78rem; color: var(--faint); margin-top: .25rem; }

.bundle {
  border: 1px solid var(--rule); border-radius: 5px; padding: .85rem .9rem;
  margin-bottom: .7rem; background: #fcfcfd; position: relative;
}
.bundle .row { display: grid; grid-template-columns: 1fr 12rem; gap: .7rem; }
@media (max-width: 34rem) { .bundle .row { grid-template-columns: 1fr; } }
.bundle .drop {
  border: 1.5px dashed var(--rule); border-radius: 5px; padding: .8rem; text-align: center;
  font-size: .85rem; color: var(--muted); cursor: pointer; background: #fff;
}
.bundle .drop.has-file { border-style: solid; border-color: var(--ok); color: var(--ink); background: #f4faf5; }
.bundle .drop input { display: none; }
.bundle .remove {
  position: absolute; top: .5rem; right: .55rem; border: 0; background: none;
  color: var(--faint); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: .1rem .3rem;
}
.bundle .remove:hover { color: var(--danger); }

button, .btn {
  font: inherit; font-weight: 600; font-size: .9rem; border-radius: 5px; cursor: pointer;
  padding: .55rem 1.1rem; border: 1px solid var(--rule); background: #fff; color: var(--ink);
  text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--faint); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #000; border-color: #000; }
.btn-primary[disabled] { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: none; border-style: dashed; color: var(--muted); width: 100%; }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: 1.2rem; }

.err { color: var(--danger); font-size: .87rem; margin-top: .8rem; }
.err:empty { display: none; }

/* ---- job page ---- */
.bar { height: 7px; background: var(--rule); border-radius: 4px; overflow: hidden; margin: .9rem 0 .5rem; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .6s ease; }
.bar.done i { background: var(--ok); }
.bar.failed i { background: var(--danger); width: 100% !important; }

.stages { list-style: none; padding: 0; margin: 1.2rem 0 0; font-size: .88rem; }
.stages li { display: flex; align-items: center; gap: .6rem; padding: .3rem 0; color: var(--faint); }
.stages li .dot {
  width: .7rem; height: .7rem; border-radius: 50%; border: 2px solid var(--rule);
  flex: 0 0 auto; background: #fff;
}
.stages li.active { color: var(--ink); font-weight: 600; }
.stages li.active .dot { border-color: var(--accent); background: var(--accent); animation: pulse 1.6s infinite; }
.stages li.done { color: var(--muted); }
.stages li.done .dot { border-color: var(--ok); background: var(--ok); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(44,74,124,.35); } 50% { box-shadow: 0 0 0 5px rgba(44,74,124,0); } }

.status-msg { font-size: .9rem; color: var(--muted); min-height: 1.3em; }
.meta { display: flex; flex-wrap: wrap; gap: .3rem 1.4rem; font-size: .82rem; color: var(--muted); margin-top: 1rem; padding-top: .9rem; border-top: 1px solid var(--rule); }
.meta b { color: var(--ink); font-weight: 600; }

.downloads { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.badge-ok { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; color: var(--ok); font-weight: 600; }
.spin { display: inline-block; width: .8rem; height: .8rem; border: 2px solid var(--rule); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

footer.foot { text-align: center; font-size: .8rem; color: var(--faint); margin-top: 2rem; }

/* ---- reports index ---- */
.wrap.wide { max-width: 64rem; }

.tallies { display: flex; align-items: center; gap: 1.4rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.tally { font-size: .85rem; color: var(--muted); }
.tally b { color: var(--ink); font-size: 1.05rem; font-weight: 700; }
.tally.muted b { color: var(--faint); }
.tally-action { margin-left: auto; }

table.reports { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.reports th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 0 .7rem .5rem; border-bottom: 2px solid var(--rule);
}
table.reports td { padding: .8rem .7rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.reports tr:last-child td { border-bottom: 0; }
table.reports tr.state-gone { opacity: .62; }
table.reports .right { text-align: right; }
table.reports .nowrap { white-space: nowrap; }

.parties { font-weight: 600; color: var(--ink); text-decoration: none; }
.parties:hover { color: var(--accent); text-decoration: underline; }
.sub { font-size: .78rem; color: var(--muted); margin-top: .18rem; line-height: 1.4; }
.sub.mono, .mono { font-family: "DejaVu Sans Mono", Menlo, Consolas, monospace; font-size: .72rem; color: var(--faint); }
.err-text { color: var(--danger); }
.expiring { color: var(--danger); font-weight: 600; }

.badge {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; padding: .15rem .5rem; border-radius: 3px;
  border: 1px solid currentColor; white-space: nowrap;
}
.badge.ready   { color: var(--ok); background: #f2f9f3; }
.badge.running { color: var(--accent); background: var(--accent-soft); }
.badge.gone    { color: var(--faint); background: #f5f6f7; }

.mini-bar { height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; margin: .4rem 0 .1rem; max-width: 9rem; }
.mini-bar i { display: block; height: 100%; background: var(--accent); transition: width .6s ease; }

.btn-sm { padding: .28rem .6rem; font-size: .78rem; }
.panel.empty { text-align: center; padding: 3rem 1.5rem; }
.panel.empty h2 { justify-content: center; }
.panel.empty .btn { margin-top: .5rem; }

/* ---- cost panel ---- */
.panel.spend { padding-bottom: 1.1rem; }
.spend-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
@media (max-width: 44rem) { .spend-grid { grid-template-columns: repeat(2, 1fr); } }
.figure { border-left: 3px solid var(--rule); padding-left: .8rem; }
.figure .n { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.figure .n.muted { color: var(--faint); font-weight: 400; }
.figure .lbl { font-size: .78rem; color: var(--muted); margin-top: .1rem; }
.figure .sub { margin-top: .15rem; }
b.cost { color: var(--ink); font-weight: 600; }

.budget { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.budget-head { font-size: .92rem; }
.budget-head b { font-size: 1.15rem; }
.budget .bar { height: 8px; background: var(--rule); border-radius: 4px; overflow: hidden; margin: .5rem 0 .4rem; }
.budget .bar i { display: block; height: 100%; background: var(--accent); transition: width .6s ease; }
.budget.over .bar i { background: var(--danger); }
.budget.over .budget-head b { color: var(--danger); }
.budget-hint { margin-top: 1rem; padding-top: .9rem; border-top: 1px solid var(--rule); }
.budget-hint code { background: var(--soft); padding: .1rem .3rem; border-radius: 3px; font-size: .9em; }

/* ---- per-phase cost on the job page ---- */
.cost-h { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.4rem 0 .4rem; }
table.phases { width: 100%; max-width: 26rem; border-collapse: collapse; font-size: .85rem; }
table.phases td { padding: .3rem .5rem; border-bottom: 1px solid var(--rule); }
table.phases td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.phases tr.total td { border-bottom: 0; border-top: 2px solid var(--ink); font-weight: 700; }

/* ---- date range ---- */
input[type=date] {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--rule); border-radius: 5px;
  background: #fff; font: inherit; font-size: .92rem; color: var(--ink);
}
input[type=date]:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.opt-h { font-weight: 400; font-size: .85rem; color: var(--faint); }
#range-hint { margin-top: .5rem; font-weight: 500; color: var(--muted); }

/* ---- user bar ---- */
.userbar {
  display: flex; align-items: center; gap: 1rem; font-size: .85rem;
  padding: .55rem .9rem; margin-bottom: 1.2rem; border-radius: var(--radius);
  background: #fff; border: 1px solid var(--rule); box-shadow: var(--shadow);
}
.userbar a { color: var(--muted); text-decoration: none; }
.userbar a:hover { color: var(--accent); text-decoration: underline; }
.userbar .who { font-weight: 600; color: var(--ink); margin-right: auto; display: flex; align-items: center; gap: .4rem; }
.role-chip {
  font-size: .64rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  background: var(--accent-soft); color: var(--accent); padding: .1rem .35rem; border-radius: 3px;
}
.userbar.open-warning { background: #fdecea; border-color: #f0b4ae; color: #7a1108; display: block; }
.userbar.open-warning b { color: #5c0d06; }
.badge { background: #f5f6f7; color: var(--muted); }

/* ---- investigation detail ---- */
.add-evidence { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.panel.danger-zone { border-color: #e8c4c0; background: #fffaf9; }
.panel.danger-zone h2 { border: 0; color: var(--danger); font-size: 1rem; margin-bottom: .3rem; }
.panel.danger-zone .btn { border-color: var(--danger); color: var(--danger); }
.panel.danger-zone .btn:hover { background: var(--danger); color: #fff; }

/* ---- investigation type ---- */
.kind-choice { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 38rem) { .kind-choice { grid-template-columns: 1fr; } }
.kind { display: flex; gap: .6rem; align-items: flex-start; padding: .8rem .9rem;
        border: 1px solid var(--rule); border-radius: 5px; cursor: pointer; background: #fcfcfa; }
.kind:hover { border-color: var(--faint); }
.kind input { margin-top: .25rem; }
.kind:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.kind-body { display: flex; flex-direction: column; }
.kind-body b { font-size: .95rem; }
.kind-body .sub { margin-top: .2rem; }
.kind-chip { display: inline-block; font-size: .64rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; padding: .08rem .35rem; border-radius: 3px;
  background: var(--soft); color: var(--muted); margin-right: .3rem; }
.evidence-context { border-left: 2px solid var(--rule); padding-left: .55rem; margin-top: .35rem;
  font-style: italic; color: var(--muted); max-width: 42rem; }
textarea.note-input { width: 100%; padding: .5rem .6rem; border: 1px solid var(--rule);
  border-radius: 5px; font: inherit; font-size: .9rem; resize: vertical; }
.userbar .sub-link { font-size: .74rem; color: var(--faint); }

/* ---- investigation header ---- */
.facts-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: .9rem 1.6rem; margin: 0 0 1.2rem; padding: 1rem 1.2rem;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius);
  border-left: 3px solid var(--gold);
}
.facts-grid > div { min-width: 0; }
.facts-grid dt {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--faint); font-weight: 600; margin-bottom: .2rem;
}
.facts-grid dd {
  margin: 0; font-size: .95rem; color: var(--ink); font-weight: 500;
  overflow-wrap: anywhere;
}
.facts-grid .unset { color: var(--faint); font-weight: 400; font-style: italic; }

.background {
  margin-bottom: 1.4rem; padding: .85rem 1.1rem; background: var(--soft);
  border-radius: var(--radius); border: 1px solid var(--rule);
}
.background b {
  display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin-bottom: .3rem;
}
.background p { margin: 0; font-size: .92rem; line-height: 1.6; color: var(--ink); }

/* ---- investigation workspace ---- */
/* Evidence on the left is what goes in; dossiers on the right are what comes
   out. Side by side because the relationship between them is the page: adding
   evidence is what makes a dossier stale. */
.workspace {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.2rem; align-items: start;
}
@media (max-width: 62rem) { .workspace { grid-template-columns: 1fr; } }
.workspace .panel { margin-bottom: 0; }
/* Tables in a narrower column need to scroll rather than push the layout. */
.workspace table.reports { display: block; overflow-x: auto; white-space: normal; }
.workspace table.reports tbody, .workspace table.reports thead { display: table; width: 100%; }
.workspace .bundle .row { grid-template-columns: 1fr; }

/* ---- dossier list ---- */
.dossier-list { list-style: none; padding: 0; margin: 1rem 0 0; }
.dossier-list li { padding: .75rem 0; border-bottom: 1px solid var(--rule); }
.dossier-list li:last-child { border-bottom: 0; }
.dossier-list li.state-gone { opacity: .62; }
.dossier-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .7rem; }
.dossier-line b { font-size: .95rem; }
.dossier-line .sub { margin-top: 0; }
.dossier-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-top: .5rem; }

/* ---- dossier chat ---- */
.chat-panel.disabled { opacity: .7; }
.transcript {
  max-height: 26rem; overflow-y: auto; margin: 1rem 0 0;
  padding: .2rem .1rem; display: flex; flex-direction: column; gap: .9rem;
}
.turn { display: flex; flex-direction: column; gap: .25rem; }
.turn .who {
  font-size: .66rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--faint); font-weight: 600;
}
.turn .said {
  font-size: .93rem; line-height: 1.62; white-space: pre-wrap; overflow-wrap: anywhere;
  padding: .6rem .85rem; border-radius: var(--radius);
}
.turn.user .said { background: var(--accent-soft); border: 1px solid #e7dcc2; }
.turn.assistant .said { background: var(--soft); border: 1px solid var(--rule); }
.turn.empty .said { background: none; border: 0; color: var(--muted); padding-left: 0; }
.turn.pending .said { color: var(--muted); font-style: italic; }
.chat-form { margin-top: 1rem; padding-top: .9rem; border-top: 1px solid var(--rule); }
.chat-form textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--rule); border-radius: 5px;
  font: inherit; font-size: .93rem; resize: vertical;
}
.chat-form textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---- chat: speaker, thinking, markdown ---- */
.turn .who { display: flex; align-items: center; gap: .4rem; }
.who-mark { width: 1.4rem; height: 1.4rem; object-fit: contain; flex: 0 0 auto; }

/* Three dots that actually breathe, rather than a static ellipsis that looks
   like the page has stopped. */
.said.thinking { display: flex; align-items: center; gap: .3rem; min-height: 2.2rem; }
.said.thinking .dot {
  width: .38rem; height: .38rem; border-radius: 50%; background: var(--muted);
  animation: chat-blink 1.25s infinite ease-in-out both;
}
.said.thinking .dot:nth-child(2) { animation-delay: .18s; }
.said.thinking .dot:nth-child(3) { animation-delay: .36s; }
@keyframes chat-blink {
  0%, 75%, 100% { opacity: .22; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-.16rem); }
}
@media (prefers-reduced-motion: reduce) {
  .said.thinking .dot { animation: none; opacity: .5; }
}

/* Rendered answers: markdown, kept tight so a list does not sprawl. */
.said.markdown { white-space: normal; }
.said.markdown > :first-child { margin-top: 0; }
.said.markdown > :last-child { margin-bottom: 0; }
.said.markdown p { margin: 0 0 .6rem; }
.said.markdown ul, .said.markdown ol { margin: .4rem 0 .6rem; padding-left: 1.3rem; }
.said.markdown li { margin-bottom: .25rem; }
.said.markdown code {
  font-family: "DejaVu Sans Mono", Menlo, Consolas, monospace; font-size: .86em;
  background: rgba(15,17,20,.06); padding: .05rem .3rem; border-radius: 3px;
}
.said.markdown pre { background: rgba(15,17,20,.06); padding: .6rem .75rem;
  border-radius: 4px; overflow-x: auto; }
.said.markdown pre code { background: none; padding: 0; }
.said.markdown blockquote {
  margin: .5rem 0; padding-left: .75rem; border-left: 3px solid var(--rule);
  color: var(--muted);
}
.said.markdown h1, .said.markdown h2, .said.markdown h3 {
  font-size: .96rem; margin: .7rem 0 .3rem;
}
.said.markdown table { width: 100%; border-collapse: collapse; font-size: .88em; margin: .5rem 0; }
.said.markdown th, .said.markdown td { text-align: left; padding: .3rem .5rem;
  border-bottom: 1px solid var(--rule); }
