/* Quarry — "Quiet Terminal" design system (see /DESIGN.md). Dark-first,
   token-driven. Machine output = mono; human judgment = serif italic; UI
   chrome = Geist. Zero border-radius on data surfaces. No pills, no shadows. */

:root[data-theme="dark"], body[data-theme="dark"] {
  --bg:#0B0D10; --surface:#14171C; --surface-2:#1C2027; --rule:#262B33;
  --text:#E9E6DF; --muted:#8B929D; --accent:#FFB020; --accent-dim:#7A5A1E;
  --score-high:#3FE0A0; --score-mid:#E5C069; --score-low:#E06C4F; --score-null:#4A515B;
}
:root[data-theme="light"], body[data-theme="light"] {
  --bg:#F4F2EC; --surface:#FDFCF9; --surface-2:#ECE9E1; --rule:#DCD8CD;
  --text:#1B1E22; --muted:#6E7480; --accent:#B87A00; --accent-dim:#D9B36A;
  --score-high:#0E8A5F; --score-mid:#9A7A1A; --score-low:#B54A2E; --score-null:#9AA0A8;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Geist", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

a { color: inherit; }

.shell {
  display: flex;
  min-height: 100vh;
}

/* --- Left nav --------------------------------------------------------- */

.sidenav {
  width: 168px;
  flex: 0 0 168px;
  background: var(--surface);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidenav .brand {
  font-family: "Instrument Serif", serif;
  font-size: 20px;
  padding: 0 16px 16px;
  letter-spacing: 0.02em;
}
.sidenav a {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--muted);
  padding: 8px 16px;
  border-left: 2px solid transparent;
}
.sidenav a:hover { color: var(--text); }
.sidenav a.active {
  color: var(--text);
  border-left-color: var(--accent);
  background: var(--surface-2);
}
.side-footer {
  margin-top: auto;
  padding: 12px 16px 0;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#theme-toggle {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.06em;
  background: none;
  border: 1px solid var(--rule);
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 2px;
  cursor: pointer;
}
#theme-toggle:hover { color: var(--text); border-color: var(--accent-dim); }
.api-config {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.api-config input {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--rule);
  padding: 4px 6px;
  border-radius: 2px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
}

main {
  flex: 1;
  padding: 24px 28px;
  min-width: 0;
}

.loading, .muted { color: var(--muted); }
.error { color: var(--score-low); font-family: "IBM Plex Mono", monospace; }

/* --- Titles / headings -------------------------------------------------- */

h1, h2, h3 {
  font-family: "Instrument Serif", serif;
  font-weight: 400;
  margin: 0 0 12px;
}
h2 { font-size: 26px; }
h3 { font-size: 18px; }

/* --- Filters / forms ----------------------------------------------------- */

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
  margin-bottom: 12px; padding: 12px; background: var(--surface);
  border: 1px solid var(--rule);
}
.filters label {
  display: flex; flex-direction: column; gap: 4px;
  font-family: "Geist", sans-serif; font-size: 12px; color: var(--muted);
}
.filters input, .filters select {
  padding: 5px 6px; border: 1px solid var(--rule); border-radius: 2px;
  font-size: 13px; background: var(--surface-2); color: var(--text);
  font-family: "IBM Plex Mono", monospace;
}
.filters button, button.btn, .btn {
  padding: 6px 14px; border: none; background: var(--accent); color: #0B0D10;
  border-radius: 2px; cursor: pointer; font-size: 13px; font-family: "Geist", sans-serif;
  font-weight: 500;
}
.filters button:hover, .btn:hover { filter: brightness(1.08); }
.btn:disabled { background: var(--score-null); color: var(--surface); cursor: not-allowed; }
.btn.secondary {
  background: none; color: var(--text); border: 1px solid var(--rule);
}
.btn.secondary:hover { border-color: var(--accent-dim); }
.btn.ghost {
  background: none; color: var(--muted); border: none;
}
.btn.ghost:hover { color: var(--accent); }

/* --- Tables --------------------------------------------------------------
   Data surfaces: 0 border-radius, hairline rules, 28px rows, mono + tabular
   numerals, right-aligned numeric columns. */

table {
  width: 100%;
  background: var(--surface);
  border-collapse: collapse;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--rule);
}
th, td {
  padding: 0 10px;
  height: 28px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  white-space: nowrap;
}
th {
  background: var(--surface-2);
  font-family: "Geist", sans-serif;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
td.num, th.num { text-align: right; }
tbody tr:hover { background: var(--surface-2); cursor: pointer; }
td .company-name {
  font-family: "Geist", sans-serif;
  color: var(--text);
}

/* --- Score idiom: tick + tabular numeral (replaces pills) ----------------- */

.tick {
  display: inline-block;
  width: 3px;
  height: 13px;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--score-null);
}
.tick.t-high { background: var(--score-high); }
.tick.t-mid  { background: var(--score-mid); }
.tick.t-low  { background: var(--score-low); }
.tick.t-null { background: var(--score-null); }

.score {
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.score .num { color: var(--text); }
.score.is-null .num { color: var(--muted); }

/* Confidence tick-stack glyph, e.g. ▮▮▮▯ — 1-4 lit ticks. */
.tickstack { font-family: "IBM Plex Mono", monospace; letter-spacing: 1px; }
.tickstack .lit { color: var(--accent); }
.tickstack .unlit { color: var(--score-null); }

/* --- Human-judgment layer: serif italic + amber left rule ----------------- */

.annotation {
  font-family: "Instrument Serif", serif;
  font-style: italic;
  font-size: 17px;
  border-left: 2px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text);
  max-width: 640px;
}

/* --- Sub-row: rank-row expansion (subscores audit) ------------------------ */

tr.sub-row td {
  background: var(--surface-2);
  cursor: default;
  white-space: normal;
  padding: 8px 10px 12px 10px;
}
tr.sub-row:hover { background: var(--surface-2); }
.subscore-line {
  display: flex; justify-content: space-between; gap: 12px; max-width: 420px;
  padding: 2px 0; font-size: 12px; color: var(--muted);
}
.subscore-line .dim { color: var(--text); }
.subscore-line .vals { font-variant-numeric: tabular-nums; }

/* --- Contact cards --------------------------------------------------------- */

.contact-card {
  background: var(--surface); border: 1px solid var(--rule);
  padding: 10px 12px; margin-bottom: 8px;
}
.contact-card > div { margin-bottom: 5px; }
.contact-card .seq-actions { margin-bottom: 0; }
.contact-card .succession {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.contact-card .tenure {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  color: var(--muted);
}

/* Add/edit contact form (ADR-0058) */
.contact-form { display: flex; flex-direction: column; gap: 10px; }
.contact-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.contact-form label.chk { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.contact-form input, .contact-form select, .contact-form textarea {
  padding: 6px 8px; border: 1px solid var(--rule); border-radius: 2px;
  font-family: inherit; font-size: 13px; background: var(--surface-2); color: var(--text);
}
.contact-form label.chk input { width: auto; }
.contact-form button[type="submit"] { align-self: flex-start; margin-top: 4px; }

.detail { background: var(--surface); padding: 16px; border: 1px solid var(--rule); }
.detail .row { display: flex; flex-wrap: wrap; gap: 24px; padding: 6px 0; border-bottom: 1px solid var(--rule); }
.detail .row span:first-child {
  color: var(--muted); min-width: 11rem; font-size: 11px;
  font-family: "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.03em;
}
.detail h2 { margin: 20px 0 8px; font-size: 18px; }

.dossier-name {
  font-family: "Instrument Serif", serif;
  font-size: 34px;
  margin: 0;
}

.gbrain-badge {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--rule);
  padding: 3px 8px;
  border-radius: 2px;
  cursor: pointer;
  background: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.gbrain-badge:hover { border-color: var(--accent-dim); color: var(--text); }

.stat-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px; background: var(--rule); border: 1px solid var(--rule); margin: 16px 0;
}
.stat-strip .stat-card { background: var(--surface); padding: 10px 12px; }
.stat-strip .stat-card .label {
  font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
  font-family: "IBM Plex Mono", monospace;
}
.stat-strip .stat-card .value {
  font-size: 20px; margin-top: 4px; font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.dedup-pair {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px;
  background: var(--surface); padding: 12px; border: 1px solid var(--rule); margin-bottom: 12px;
}
.dedup-pair .actions button { margin-right: 4px; }
#map { width: 100%; height: 70vh; border: 1px solid var(--rule); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); margin-bottom: 16px; }
.stat-card { background: var(--surface); padding: 12px; }
.stat-card .label { font-size: 11px; color: var(--muted); text-transform: uppercase; font-family: "IBM Plex Mono", monospace; }
.stat-card .value { font-size: 22px; font-family: "IBM Plex Mono", monospace; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* --- Today dashboard (#/today, issue #26) ---------------------------------
   Three stat-card groups (Research / Outreach / Hygiene). Cards are clickable
   deep links, styled with the same .stats grid used elsewhere. An actionable
   card (count > 0 on a queue that needs Jim) gets the amber left rule and
   amber value -- DESIGN.md's "amber means needs Jim" rule; a zero-count card
   stays muted, never amber, so an empty dashboard reads calm, not alarming. */
.today-group { margin-bottom: 28px; }
.today-group h2 {
  font-family: "Geist", sans-serif; font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  margin: 0 0 8px;
}
.stats a.stat-card {
  display: block; text-decoration: none; color: inherit;
  border-left: 3px solid transparent; transition: border-color 150ms ease-out;
}
.stats a.stat-card:hover { background: var(--surface-2); }
.stats .stat-card.actionable { border-left-color: var(--accent); }
.stats .stat-card.actionable .value { color: var(--accent); }
.stats .stat-card.muted .value { color: var(--muted); }

.tabs { display: flex; gap: 16px; margin-bottom: 12px; border-bottom: 1px solid var(--rule); }
.tabs button {
  background: none; border: none; padding: 8px 2px; cursor: pointer;
  color: var(--muted); font-size: 13px; font-family: "Geist", sans-serif;
}
.tabs button.active { color: var(--accent); border-bottom: 2px solid var(--accent); }

/* Detail-page actions row + buttons. */
.detail .actions { margin: 12px 0 16px; display: flex; gap: 8px; }

/* Draft Email side panel — same shape as Atlas. */
.draft-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(40rem, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--rule); padding: 16px 20px; overflow: auto;
  display: flex; flex-direction: column; gap: 8px; z-index: 50;
}
.draft-panel header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid var(--rule); padding-bottom: 8px; margin-bottom: 4px;
}
.draft-panel header h2 { margin: 0; font-size: 18px; }
.draft-panel .subject {
  font-weight: 600; font-size: 14px; padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--rule); border-radius: 2px;
  font-family: "Geist", sans-serif;
}
.draft-panel textarea {
  width: 100%; min-height: 22rem; resize: vertical;
  padding: 10px 12px; border: 1px solid var(--rule); border-radius: 2px;
  font-family: inherit; font-size: 14px; line-height: 1.4;
  background: var(--surface-2); color: var(--text);
}
.draft-panel .footer-actions {
  display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap;
  border-top: 1px solid var(--rule); padding-top: 8px; margin-top: 4px;
}
.draft-panel .footer-actions .left, .draft-panel .footer-actions .right {
  display: flex; gap: 8px;
}
.draft-panel .status { font-size: 12px; color: var(--muted); }
.draft-panel .status.success { color: var(--score-high); }
.draft-panel .status.error { color: var(--score-low); }
.scrim {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 40;
}

/* --- Alerts / status lines (design system component notes) ---------------- */

.status-line {
  background: var(--surface); border-left: 3px solid var(--accent);
  padding: 8px 12px; font-family: "IBM Plex Mono", monospace; font-size: 12px;
}
.status-line .tag { color: var(--accent); margin-right: 8px; letter-spacing: 0.04em; }

/* --- Communications timeline (issue #24) ---------------------------------- */

.timeline { display: flex; flex-direction: column; }

.tl-row {
  display: grid;
  grid-template-columns: 6px 132px 56px auto;
  align-items: baseline;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--rule);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12.5px;
}
/* Global view adds a company column between the tag and the body. */
#view .timeline .tl-row:has(.tl-company) {
  grid-template-columns: 6px 132px 56px 200px auto;
}
.tl-row.tl-clickable { cursor: pointer; }
.tl-row.tl-clickable:hover { background: var(--surface-2); }

.tl-tick { align-self: center; margin-right: 0; }
.tl-ts { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-tag { letter-spacing: 0.04em; font-size: 11px; white-space: nowrap; }
.tl-company {
  font-family: "Instrument Serif", serif; font-size: 15px;
  color: var(--text); text-decoration: none; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.tl-company:hover { color: var(--accent); }
.tl-body { min-width: 0; }
.tl-title { color: var(--text); }
.tl-snippet { color: var(--muted); margin-left: 8px; }

/* Notes render in the human-judgment register: serif italic, amber left rule. */
.tl-note {
  font-family: "Instrument Serif", serif; font-style: italic; font-size: 16px;
  color: var(--text); border-left: 2px solid var(--accent); padding-left: 10px;
}

.tl-expand { padding: 4px 4px 12px 146px; }
.tl-email-body {
  font-family: "IBM Plex Mono", monospace; font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; color: var(--text);
  background: var(--surface); border-left: 3px solid var(--rule);
  padding: 12px; margin: 0; max-width: 720px;
}
.tl-nosync {
  font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--score-mid);
  background: var(--surface); border-left: 3px solid var(--score-mid);
  padding: 10px 12px; max-width: 720px;
}

/* --- Contact reports (issue #25) -------------------------------------------
   DNC/opted-out rows are only ever visible when include_dnc is toggled on
   (the API excludes them by default); when shown, they render muted with a
   strikethrough on the human-facing cells so they read as "on file, but off
   limits" rather than a normal active row. */
tr.dnc-row td { color: var(--muted); }
tr.dnc-row .company-name, tr.dnc-row td:nth-child(4), tr.dnc-row td:nth-child(6) {
  text-decoration: line-through;
}

/* Filter chips (global timeline). Hairline outline, amber when active. */
.filter-chips { display: flex; gap: 6px; }
.chip {
  font-family: "IBM Plex Mono", monospace; font-size: 12px; letter-spacing: 0.03em;
  text-transform: uppercase; background: transparent; color: var(--muted);
  border: 1px solid var(--rule); border-radius: 2px; padding: 4px 10px; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }

/* Login overlay (auth) — same tokens as the shell, mono form controls. */
#login-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
#login-form {
  background: var(--surface);
  border: 1px solid var(--rule);
  padding: 32px 36px;
  display: flex; flex-direction: column; gap: 12px;
  min-width: 320px;
}
#login-form h1 {
  font-family: "IBM Plex Mono", monospace;
  font-size: 14px; letter-spacing: 0.2em; color: var(--accent);
  margin: 0;
}
#login-form p { color: var(--muted); font-size: 13px; margin: 0; }
#login-form input {
  font-family: "IBM Plex Mono", monospace;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--rule); padding: 8px 10px;
}
#login-form input:focus { outline: none; border-color: var(--accent-dim); }
#login-form button {
  font-family: "IBM Plex Mono", monospace;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--rule); padding: 8px 10px;
  cursor: pointer; letter-spacing: 0.1em;
}
#login-form button:hover { border-color: var(--accent); color: var(--accent); }
