/* Palette roles. Light values on :root; the dark block redefines only the
   tokens, so every rule below is written against roles rather than raw hex. */
:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --critical: #d03b3b;
  --good: #006300;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --critical: #e66767;
    --good: #0ca30c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --series-2: #d95926;
  --critical: #e66767;
  --good: #0ca30c;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 0.95rem; margin: 0 0 0.75rem; font-weight: 600; }
.muted { color: var(--text-muted); margin: 0.15rem 0 0; font-size: 0.85rem; }
.error { color: var(--critical); font-size: 0.85rem; margin: 0.5rem 0 0; }
[hidden] { display: none !important; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

/* ---- Sign in ------------------------------------------------------------ */
.gate { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.gate-card { width: min(360px, 100%); display: grid; gap: 0.75rem; }

/* ---- Chrome ------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center;
  gap: 1rem; flex-wrap: wrap;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
.badge {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-secondary); border: 1px solid var(--border);
  border-radius: 999px; padding: 0.15rem 0.6rem;
}
.wrap {
  max-width: 1200px; margin: 0 auto;
  padding: clamp(1rem, 3vw, 1.5rem) clamp(1rem, 4vw, 2rem) 4rem;
  display: grid; gap: 1rem;
}
/* Grid and flex children default to min-width:auto, which lets a wide table
   push the whole page sideways. Wide content scrolls inside its own box. */
.wrap > *, .charts > *, .tiles > * { min-width: 0; }

/* ---- Controls ----------------------------------------------------------- */
.field { display: grid; gap: 0.25rem; font-size: 0.8rem; color: var(--text-secondary); }
.field.inline { min-width: 8.5rem; }
.field.grow { flex: 1 1 12rem; }
input, select, button { font: inherit; }
input, select {
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--baseline); border-radius: 6px;
  padding: 0.4rem 0.55rem; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 1px;
}

.btn {
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--baseline); border-radius: 6px;
  padding: 0.45rem 0.8rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--text-muted); }
.btn.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn.ghost { border-color: transparent; color: var(--text-secondary); }
.btn.link {
  border: none; background: none; color: var(--text-secondary);
  padding: 0.2rem 0.35rem; cursor: pointer; text-decoration: underline;
}
.btn.link:hover { color: var(--critical); }

.filters { display: grid; gap: 0.75rem; }
.presets { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  background: none; border: 1px solid var(--baseline); border-radius: 999px;
  padding: 0.3rem 0.75rem; cursor: pointer; color: var(--text-secondary);
}
.chip[aria-pressed="true"] {
  background: var(--series-1); border-color: var(--series-1); color: #fff;
}
.filter-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }

/* ---- Stat tiles --------------------------------------------------------- */
.tiles { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.tile { display: grid; gap: 0.15rem; }
.tile-label { font-size: 0.8rem; color: var(--text-secondary); }
.tile-value { font-size: 1.9rem; font-weight: 650; line-height: 1.1; }

/* ---- Bar charts --------------------------------------------------------- */
.charts { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.chart { margin: 0; }
.chart figcaption { margin: 0; }
.bars { display: grid; gap: 0.4rem; }

.bar-row {
  display: grid; grid-template-columns: minmax(6rem, 8rem) 1fr auto;
  align-items: center; gap: 0.6rem;
  padding: 0.1rem 0.25rem; border-radius: 4px;
}
.bar-row:hover { background: var(--gridline); }
.bar-label { color: var(--text-secondary); font-size: 0.82rem; }
.bar-track { background: var(--gridline); border-radius: 4px; height: 14px; }
.bar-fill {
  height: 100%;
  /* Square at the baseline, rounded at the data end. */
  border-radius: 0 4px 4px 0;
  background: var(--series-1);
  min-width: 2px;
}
[data-series="2"] .bar-fill { background: var(--series-2); }
/* Direct value labels: identity and magnitude never rest on color alone. */
.bar-value { font-variant-numeric: tabular-nums; color: var(--text-primary); font-size: 0.82rem; }
.bars-empty { color: var(--text-muted); font-size: 0.85rem; }

/* ---- Table -------------------------------------------------------------- */
.table-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem;
}
.table-head h2 { margin: 0; }
.exports { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.checkbox { display: flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; color: var(--text-secondary); }
.checkbox input { width: auto; }

.table-scroll { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--gridline); vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
td.date { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.notes { color: var(--text-secondary); max-width: 22rem; }
tbody tr:hover { background: var(--gridline); }
.empty { text-align: center; padding: 1.5rem 0; }

.pill {
  display: inline-block; border: 1px solid var(--border); border-radius: 999px;
  padding: 0.05rem 0.5rem; font-size: 0.75rem; color: var(--text-secondary);
  white-space: nowrap;
}
.pill.booked { color: var(--good); border-color: currentColor; }

/* ---- Tooltip ------------------------------------------------------------ */
.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 0.35rem 0.55rem; font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(11, 11, 11, 0.15);
}

.add-grid { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }
.add-grid .field { min-width: 9rem; }

@media (max-width: 620px) {
  .bar-row { grid-template-columns: minmax(5rem, 6rem) 1fr auto; }
  td.notes { max-width: 12rem; }
}

/* ---- Touch-history grid -------------------------------------------------- */
.view-switch { display: flex; gap: 0.4rem; }
.grid-controls {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem;
}

#grid { font-size: 0.85rem; }
#grid th.lead-col, #grid td.lead-col {
  position: sticky; left: 0; z-index: 1;
  background: var(--surface-1);
  min-width: 12rem;
  border-right: 1px solid var(--gridline);
}
#grid td.lead-col { font-size: 0.85rem; }
.lead-company { font-weight: 600; }
.lead-contact { color: var(--text-muted); font-size: 0.78rem; }
#grid th { text-align: center; white-space: nowrap; }
#grid th.lead-col { text-align: left; }
#grid td.cell { text-align: center; padding: 0.3rem 0.25rem; min-width: 3.1rem; }

/* The four summary columns: right-aligned head and body so the numbers line up
   under their labels, and shrunk to their content (width:1% collapses a column
   to its minimum) so the touch history keeps the room instead. */
#grid th.count, #grid td.count {
  text-align: right;
  white-space: nowrap;
  width: 1%;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  font-variant-numeric: tabular-nums;
}
#grid th.summary-start, #grid td.summary-start {
  border-left: 1px solid var(--gridline);
  padding-left: 0.8rem;
}

/* A touch is identified by its abbreviation, never by colour alone. Colour is
   reserved for the one distinction that matters in prospecting: whether the
   attempt reached a person. */
.touch {
  display: inline-block; min-width: 2.3rem;
  border: 1px solid var(--baseline); border-radius: 4px;
  padding: 0.1rem 0.3rem; font-size: 0.72rem; font-weight: 600;
  color: var(--text-secondary); background: var(--surface-1);
  cursor: default;
}
.touch + .touch { margin-left: 2px; }
.touch.connected {
  border-color: var(--series-1); color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 10%, transparent);
}
.touch-date { display: block; font-size: 0.65rem; font-weight: 400; color: var(--text-muted); }
.cell-empty { color: var(--gridline); }

.legend {
  display: flex; flex-wrap: wrap; gap: 0.35rem 1rem;
  margin: 0.9rem 0 0; padding-top: 0.75rem;
  border-top: 1px solid var(--gridline);
  font-size: 0.78rem; color: var(--text-secondary);
}
.legend div { display: flex; align-items: baseline; gap: 0.35rem; }
.legend dt { font-weight: 600; }
.legend dd { margin: 0; color: var(--text-muted); }

/* ---- Import panel -------------------------------------------------------- */
#import-card summary { cursor: pointer; list-style: none; }
#import-card summary::-webkit-details-marker { display: none; }
#import-card summary h2 { display: inline; }
#import-card summary::before { content: "▸ "; color: var(--text-muted); }
#import-card details[open] summary::before { content: "▾ "; }
.import-help { margin-top: 0.6rem; }
.import-controls { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin: 0.75rem 0; }
#import-text {
  width: 100%; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--baseline); border-radius: 6px; padding: 0.6rem;
  resize: vertical;
}
.import-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }
.import-result { margin-top: 1rem; font-size: 0.85rem; }
.import-result h3 { font-size: 0.85rem; margin: 0.9rem 0 0.35rem; }
.import-result table { width: 100%; border-collapse: collapse; margin-top: 0.35rem; }
.import-result th, .import-result td {
  text-align: left; padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--gridline); font-size: 0.8rem;
}
.problem { color: var(--critical); }
.problem-list { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.problem-list li { margin-bottom: 0.15rem; }
.tally { display: flex; flex-wrap: wrap; gap: 0.35rem 1.25rem; margin: 0; }
.tally div { display: flex; gap: 0.35rem; align-items: baseline; }
.tally dt { color: var(--text-secondary); }
.tally dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.banner {
  margin: 0; padding: 0.7rem 0.9rem; border-radius: 8px;
  border: 1px solid var(--critical); color: var(--critical);
  background: color-mix(in srgb, var(--critical) 8%, transparent);
  font-size: 0.85rem;
}

/* Saved, but not visible in the current range — an explanation, not an error. */
.notice {
  margin: 0.6rem 0 0; padding: 0.5rem 0.7rem; border-radius: 6px;
  border: 1px solid var(--baseline); color: var(--text-secondary);
  font-size: 0.85rem;
}
.notice .btn.link { color: var(--series-1); }

.col-label { align-self: center; margin: 0 0.15rem 0 0; }

/* ---- Forward-looking pipeline -------------------------------------------- */
.ahead { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.ahead-col { min-width: 0; }
.ahead-note { margin: -0.4rem 0 0.6rem; font-size: 0.8rem; }
.ahead-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.1rem; }
.ahead-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 0.6rem;
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--gridline);
  align-items: baseline;
}
.ahead-list li:last-child { border-bottom: none; }
.ahead-when {
  grid-column: 1 / -1; order: -1;
  font-size: 0.75rem; color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.ahead-who { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.ahead-sub { grid-column: 1; color: var(--text-muted); font-size: 0.8rem; overflow-wrap: anywhere; }
.ahead-rel {
  grid-row: 2; grid-column: 2;
  font-size: 0.75rem; color: var(--series-1); white-space: nowrap;
}
.ahead-empty { padding: 0.5rem 0; }

/* Targets carry no date, so company and contact fit on one line. Meetings keep
   the stacked grid above, where the time and relative-day need a row of their
   own. */
.ahead-list-inline li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.45rem;
}
.ahead-list-inline .ahead-sub::before {
  content: "·";
  margin-right: 0.45rem;
  color: var(--text-muted);
}

/* ---- Manage outcomes ----------------------------------------------------- */
#outcomes-card summary { cursor: pointer; list-style: none; }
#outcomes-card summary::-webkit-details-marker { display: none; }
#outcomes-card summary h2 { display: inline; }
#outcomes-card summary::before { content: "▸ "; color: var(--text-muted); }
#outcomes-card details[open] summary::before { content: "▾ "; }
.outcome-add { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin: 0.75rem 0 1rem; }
.outcome-list { display: grid; gap: 0.1rem; }
.outcome-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.3rem;
  border-bottom: 1px solid var(--gridline);
}
.outcome-row:last-child { border-bottom: none; }
.outcome-row.is-archived .outcome-name { color: var(--text-muted); text-decoration: line-through; }
.outcome-move { display: flex; flex-direction: column; gap: 1px; }
.outcome-move button {
  border: none; background: none; cursor: pointer; color: var(--text-muted);
  line-height: 0.8; font-size: 0.7rem; padding: 0 0.2rem;
}
.outcome-move button:hover:not(:disabled) { color: var(--text-primary); }
.outcome-move button:disabled { opacity: 0.25; cursor: default; }
.outcome-name {
  background: none; border: 1px solid transparent; border-radius: 4px;
  padding: 0.2rem 0.35rem; font: inherit; color: var(--text-primary); width: 100%;
}
.outcome-name:hover { border-color: var(--gridline); }
.outcome-name:focus { border-color: var(--baseline); background: var(--surface-1); }
.outcome-uses { color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; }
.outcome-actions { display: flex; align-items: center; gap: 0.6rem; white-space: nowrap; }
.outcome-reached { display: flex; align-items: center; gap: 0.3rem; font-size: 0.75rem; color: var(--text-secondary); }
.outcome-reached input { width: auto; }
#outcome-unlisted h3 { font-size: 0.85rem; margin: 1.2rem 0 0.2rem; }

/* ---- Insights ------------------------------------------------------------ */
.insights-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.5rem;
}
.insights-head h2 { margin: 0; }
.insight-form { display: grid; gap: 0.75rem; margin: 0.5rem 0 1.25rem; }
.insight-form textarea {
  width: 100%; font: inherit; resize: vertical;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--baseline); border-radius: 6px; padding: 0.6rem;
}
.insight-form-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }
.insights-list { display: grid; gap: 0.25rem; }
.insight {
  padding: 0.85rem 0; border-bottom: 1px solid var(--gridline);
}
.insight:last-child { border-bottom: none; }
.insight-meta {
  display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap;
  font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.2rem;
}
.insight-title { font-weight: 650; font-size: 0.95rem; margin: 0 0 0.25rem; }
/* Plain text, rendered with textContent — line breaks are preserved rather
   than interpreted, so nothing typed here can become markup. */
.insight-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: 0.9rem; line-height: 1.55; }
.insight-pin {
  border: 1px solid currentColor; border-radius: 999px;
  padding: 0 0.45rem; font-size: 0.7rem; color: var(--series-1);
}
.insight-actions { display: flex; gap: 0.5rem; margin-left: auto; }

/* ---- Insights, as a sheet ------------------------------------------------ */
.presets .insights-open { margin-left: auto; }
.badge-count {
  display: inline-block; min-width: 1.15rem; padding: 0 0.3rem;
  border-radius: 999px; background: var(--series-1); color: #fff;
  font-size: 0.72rem; font-weight: 650; text-align: center;
  font-variant-numeric: tabular-nums;
}

dialog.sheet {
  width: min(760px, calc(100vw - 2rem));
  max-height: min(80vh, 44rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  color: var(--text-primary);
  box-shadow: 0 12px 40px rgba(11, 11, 11, 0.25);
  overflow: hidden;
}
dialog.sheet::backdrop { background: rgba(11, 11, 11, 0.45); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gridline);
  /* Kept in view while the notes scroll beneath it. */
  position: sticky; top: 0; background: var(--surface-1); z-index: 1;
}
.sheet-head h2 { margin: 0; }
.sheet-head-actions { display: flex; gap: 0.5rem; align-items: center; }
.sheet-body { padding: 0.5rem 1.25rem 1.25rem; overflow-y: auto; max-height: calc(min(80vh, 44rem) - 4.5rem); }

/* ---- Client branding ----------------------------------------------------- */
/* One repository deploys every dashboard, so nothing in these files says which
   client a site belongs to -- it comes from the site's own environment. Both
   are optional, and a site with neither set looks exactly as it did before. */
.client-logo {
  height: 3rem; width: auto; max-width: 200px;
  object-fit: contain; flex: none;
}
.client-name {
  margin: 0 0 0.1rem;
  font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-secondary);
}
/* The sign-in card is a centred grid, so the logo centres with it. */
.gate-logo { height: 3rem; max-width: 100%; margin: 0 auto 0.25rem; }
#gate-client {
  display: block;
  font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-secondary);
}

/* ---- Settings menu ------------------------------------------------------- */
/* Admin tools that used to sit between the charts and the activity log, where
   every reader had to scroll past them. */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 0.35rem);
  min-width: 12rem; z-index: 20;
  display: flex; flex-direction: column;
  padding: 0.3rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
}
.menu-item {
  appearance: none; background: none; border: 0;
  font: inherit; color: inherit; text-align: left;
  padding: 0.45rem 0.6rem; border-radius: 0.35rem;
  cursor: pointer; white-space: nowrap;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2, rgb(0 0 0 / 0.05)); }
.menu-sep { margin: 0.3rem 0; border: 0; border-top: 1px solid var(--border); }
