/* Searcher 2 — application styles.
 *
 * This is a working tool that analysts sit in front of for hours, so the
 * priorities are legibility at density, a stable layout that does not move
 * under the cursor, and status that reads at a glance. No animation beyond
 * what communicates state.
 *
 * One system font stack, no web fonts: the app runs on a single VPS and a font
 * host is a dependency it does not need.
 */

:root {
  --ink: #16211c;
  --ink-soft: #4a5a53;
  --ink-faint: #7b8a83;
  --ground: #ffffff;
  --surface: #f4f6f5;
  --surface-2: #e9edeb;
  --rule: #d3dad7;
  --accent: #0c4b33;
  --accent-soft: #e6f0ea;
  --ok: #1a7f4b;
  --warn: #8a5a00;
  --warn-soft: #fdf3e0;
  --crit: #a32020;
  --crit-soft: #fbeceb;
  --focus: #0c4b33;

  --step: 0.25rem;
  --radius: 4px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e4eae7;
    --ink-soft: #a9b7b1;
    --ink-faint: #7d8c86;
    --ground: #121714;
    --surface: #1a211d;
    --surface-2: #232b27;
    --rule: #303a35;
    --accent: #63c79e;
    --accent-soft: #1a2b23;
    --ok: #63c79e;
    --warn: #d9a441;
    --warn-soft: #2a2314;
    --crit: #e58b83;
    --crit-soft: #2c1a19;
    --focus: #63c79e;
  }
}

:root[data-theme="dark"] {
  --ink: #e4eae7;
  --ink-soft: #a9b7b1;
  --ink-faint: #7d8c86;
  --ground: #121714;
  --surface: #1a211d;
  --surface-2: #232b27;
  --rule: #303a35;
  --accent: #63c79e;
  --accent-soft: #1a2b23;
  --ok: #63c79e;
  --warn: #d9a441;
  --warn-soft: #2a2314;
  --crit: #e58b83;
  --crit-soft: #2c1a19;
  --focus: #63c79e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 8px;
  top: 8px;
  z-index: 100;
  background: var(--ground);
  padding: 8px 12px;
  border: 1px solid var(--rule);
}

/* Screen-reader-only text uses `.sr-only`, defined further down with the other
 * utilities and already used across a dozen templates. A second class doing the
 * same thing under a different name was added here and removed: two names for
 * one utility is how a stylesheet ends up with both half-maintained. */

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.crumb-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 32ch;
}
.crumb-client { color: var(--ink-faint); font-size: 0.88rem; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
  font-size: 0.9rem;
}
.topbar-link { color: var(--ink-soft); text-decoration: none; }
.topbar-link:hover { color: var(--ink); text-decoration: underline; }

/* Spend: a magnitude, never hidden. Colour carries the band, the number
   carries the fact — colour alone would not survive a greyscale print or a
   colour-blind reader. */
.spend {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  text-decoration: none;
  border: 1px solid var(--rule);
  background: var(--ground);
  font-variant-numeric: tabular-nums;
}
.spend-amount { font-weight: 700; color: var(--ink); }
.spend-of, .spend-team { color: var(--ink-faint); font-size: 0.82rem; }
.spend-near { border-color: var(--warn); background: var(--warn-soft); }
.spend-near .spend-amount { color: var(--warn); }
.spend-over { border-color: var(--crit); background: var(--crit-soft); }
.spend-over .spend-amount { color: var(--crit); }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.shell { max-width: 1400px; margin: 0 auto; padding: 0 20px; }
.shell-with-rail {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
:root { --rail-w: 232px; }
:root.rail-collapsed { --rail-w: 52px; }

/* Below this the grid becomes one column and the rail sits above the content
   rather than beside it. Collapsing is then meaningless — there is no width to
   reclaim — so the toggle goes and the rail is always open. */
@media (max-width: 880px) {
  .shell-with-rail { grid-template-columns: 1fr; gap: 0; }
  .rail-toggle { display: none; }
  :root.rail-collapsed .rail-text,
  :root.rail-collapsed .rail-heading,
  :root.rail-collapsed .rail-project-name { position: static; width: auto; height: auto; clip-path: none; }
}

/* ── The rail ────────────────────────────────────────────────────────────── */

.rail { position: sticky; top: 16px; padding-top: 20px; min-width: 0; }
.rail-group { margin-bottom: 22px; }
.rail-heading {
  margin: 0 0 6px 10px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.rail-project-name {
  margin: 0 0 6px 10px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}
.rail-list { list-style: none; margin: 0; padding: 0; }

.rail-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 6px 10px;
  text-decoration: none;
  color: var(--ink-soft);
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.rail-item:hover { color: var(--ink); background: var(--surface); }
.rail-item-current,
.rail-item[aria-current="page"] {
  color: var(--ink);
  background: var(--surface);
  border-left-color: var(--accent);
  font-weight: 600;
}
.rail-mark {
  flex: 0 0 auto;
  width: 18px;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--ink-faint);
}
.rail-item:hover .rail-mark,
.rail-item-current .rail-mark { color: var(--accent); }
.rail-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.rail-label { font-size: 0.86rem; line-height: 1.4; }
/* The question the analysis answers. Two nouns do not tell an analyst which of
   Invalidity and Patentability they want; two questions do. */
.rail-blurb { font-size: 0.72rem; line-height: 1.35; color: var(--ink-faint); }

.rail-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 10px;
  margin-bottom: 14px;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--ink-faint);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  text-align: left;
}
.rail-toggle:hover { color: var(--ink); background: var(--surface); }
.rail-toggle-mark { width: 18px; text-align: center; font-family: var(--mono); }

/* Collapsed: the marks stay, the words go to the accessibility tree only. Not
   `display:none` — a rail whose labels are unreachable to a screen reader is a
   rail with no navigation in it, and `title` on each link keeps the pointer
   answer too. */
:root.rail-collapsed .rail-text,
:root.rail-collapsed .rail-heading,
:root.rail-collapsed .rail-project-name,
:root.rail-collapsed .rail-toggle-text {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
:root.rail-collapsed .rail-group { margin-bottom: 14px; }
:root.rail-collapsed .rail-item { padding: 7px 0; justify-content: center; border-left-width: 0; }
:root.rail-collapsed .rail-item-current,
:root.rail-collapsed .rail-item[aria-current="page"] { border-radius: var(--radius); }

.main { padding: 24px 0 64px; min-width: 0; }

/* ── Stage stepper ───────────────────────────────────────────────────────── */

.steps { position: sticky; top: 16px; padding-top: 24px; }
.steps ol { list-style: none; margin: 0; padding: 0; }
.step a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  text-decoration: none;
  color: var(--ink-soft);
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.step a:hover { background: var(--surface); color: var(--ink); }
.step-current a {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 600;
}
.step-n {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
  min-width: 1.2em;
}
.step-current .step-n { color: var(--accent); }
/* Takes the slack so the state mark sits at the end of the row. `.step a` is a
 * single flex line with no room for a second, so the mark goes beside the label
 * rather than under it. */
.step-label { flex: 1 1 auto; min-width: 0; }

/* State is the mark, and the mark carries a word for a screen reader. The left
 * border stays the "you are here" channel alone — sharing it would make a
 * current step that also needs attention pick one of the two to show. */
.step-mark {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1;
  color: var(--ink-faint);
}
.step-done .step-mark { color: var(--ok); }
.step-running .step-mark { color: var(--accent); }
.step-attention .step-mark { color: var(--crit); font-weight: 700; }

@media (max-width: 880px) {
  .steps { position: static; padding-top: 12px; overflow-x: auto; }
  .steps ol { display: flex; gap: 4px; }
  .step a { border-left: 0; border-bottom: 2px solid transparent; white-space: nowrap; }
  .step-current a { border-left: 0; border-bottom-color: var(--accent); }
  /* The rail is a horizontal scroller here, so the label must not stretch. */
  .step-label { flex: 0 0 auto; }
}

/* ── Workbench ───────────────────────────────────────────────────────────── */

/* `.spacenav` — the workbench's own strip of section links — was removed with
 * the markup that used it. The rail carries those sections now, and rendering
 * both put two `aria-current="page"` marks on one page. */

/* ── Typography ──────────────────────────────────────────────────────────── */

h1 { font-size: 1.6rem; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.015em; text-wrap: balance; }
h2 { font-size: 1.15rem; font-weight: 700; margin: 32px 0 10px; }
h3 { font-size: 0.98rem; font-weight: 700; margin: 22px 0 8px; }
.lede { color: var(--ink-soft); margin: 0 0 20px; max-width: 68ch; }
.hint { color: var(--ink-faint); font-size: 0.86rem; }
code, .mono { font-family: var(--mono); font-size: 0.88em; }

/* ── Pills and badges ────────────────────────────────────────────────────── */

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  border: 1px solid var(--rule);
  background: var(--surface-2);
  color: var(--ink-soft);
  white-space: nowrap;
}
.pill-muted { color: var(--ink-faint); }
.pill-ok { border-color: var(--ok); color: var(--ok); background: var(--accent-soft); }
.pill-warn { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.pill-crit { border-color: var(--crit); color: var(--crit); background: var(--crit-soft); }

/* ── Tables ──────────────────────────────────────────────────────────────── */

.tablewrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  padding: 9px 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
  white-space: nowrap;
}
td { padding: 10px 12px; border-top: 1px solid var(--rule); vertical-align: top; }
tbody tr:hover { background: var(--surface); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Forms and controls ──────────────────────────────────────────────────── */

input[type="text"], input[type="email"], input[type="search"],
input[type="number"], select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 7px 10px;
  width: 100%;
  max-width: 100%;
}
textarea { min-height: 8rem; resize: vertical; }
label { display: block; font-size: 0.84rem; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 16px; }
.field-error input, .field-error select { border-color: var(--crit); }
.error-text { color: var(--crit); font-size: 0.84rem; margin-top: 4px; }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--ground);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: var(--surface); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); background: var(--accent); }
.btn-danger { color: var(--crit); border-color: var(--crit); background: var(--ground); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.linkish {
  font: inherit; background: none; border: 0; padding: 0;
  color: var(--ink-soft); cursor: pointer; text-decoration: underline;
}
.linkish:hover { color: var(--ink); }
.inline { display: inline; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; min-width: 180px; }

/* Inputs default to width:100% so they fill a form field. Inside a flex row
   that reads as a 100% flex-basis and every control wraps onto its own line,
   so here the row does the sizing instead. */
.toolbar input, .toolbar select, .row > input, .row > select { width: auto; }
.toolbar form.row { flex: 1; min-width: 320px; flex-wrap: nowrap; }
.toolbar form.row input[type="search"] { flex: 1; min-width: 140px; }
.toolbar form.row select { flex: 0 0 auto; max-width: 15rem; }

@media (max-width: 700px) {
  .toolbar form.row { flex-wrap: wrap; }
}

/* ── Cards and panels ────────────────────────────────────────────────────── */

.card {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--ground);
  padding: 18px 20px;
}
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; }
/* A panel that carries a problem rather than an explanation. The border and
   ground shift; the words still have to say what is wrong on their own, since
   colour is not read by everyone. */
.panel-crit { border-color: var(--crit); background: var(--crit-soft); }

.empty {
  text-align: center;
  padding: 56px 20px;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  color: var(--ink-soft);
}
/* An empty state under a section heading uses h3, so the page's heading order
   still reads top to bottom; both sit flush with the top of the box. */
.empty h2, .empty h3 { margin-top: 0; }

/* ── Messages ────────────────────────────────────────────────────────────── */

.messages { list-style: none; margin: 0; padding: 10px 20px; }
.message {
  padding: 9px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--surface);
  margin-bottom: 6px;
  max-width: 1400px;
}
.message-success { border-color: var(--ok); background: var(--accent-soft); }
.message-error { border-color: var(--crit); background: var(--crit-soft); }
.message-warning { border-color: var(--warn); background: var(--warn-soft); }

.error-banner {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--crit-soft);
  border: 1px solid var(--crit);
  color: var(--crit);
  padding: 10px 16px;
  border-radius: var(--radius);
  z-index: 50;
  max-width: 90vw;
}

/* ── Progress ────────────────────────────────────────────────────────────── */

.bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}
@media (prefers-reduced-motion: reduce) {
  .bar > span { transition: none; }
  * { scroll-behavior: auto !important; }
}

/* ── htmx feedback ───────────────────────────────────────────────────────── */

/* Only shown while a request is genuinely in flight; htmx adds the class. */
.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }
.htmx-swapping { opacity: 0.55; }

/* ── Login ───────────────────────────────────────────────────────────────── */

.auth {
  max-width: 380px;
  margin: 10vh auto;
  padding: 0 20px;
}
.auth h1 { margin-bottom: 6px; }
.auth .card { margin-top: 22px; }

/* ── Utilities ───────────────────────────────────────────────────────────── */

.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
.muted { color: var(--ink-faint); }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── Start an analysis ───────────────────────────────────────────────────── */

/* auto-fit rather than a fixed count: seven cards do not divide evenly into
   any column count, and a widow on its own row reads as a mistake. */
.analysis-grid {
  list-style: none;
  margin: 0 0 32px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}
.analysis-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--ground);
}
.analysis-card h2 { margin: 0; font-size: 0.98rem; }
/* The question is the reason this page exists, so it carries the emphasis the
   name would normally take. */
.analysis-question { margin: 0; color: var(--ink); font-size: 0.9rem; }
.analysis-card .btn { margin-top: auto; align-self: flex-start; }
.analysis-card-chosen { border-color: var(--accent); background: var(--accent-soft); }
