/* SEO Monitor - dashboard styles
   Colour roles come from the validated reference palette. Light and dark are
   two selected sets of steps, not an automatic flip. Series hues (blue/orange)
   passed the categorical validator in both modes; status hues are the reserved
   status palette and always ship with an icon + text label, never colour alone. */

.viz-root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.035);

  --series-1: #2a78d6;   /* indexed · clicks */
  --series-2: #eb6834;   /* not indexed */
  --series-3: #1baf7a;   /* impressions */

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --status-neutral: #898781;
  --status-info: #2a78d6;

  /* Performance bands are ordered, not categorical, so they use one hue
     stepped light-to-dark. Opportunity and Dead sit off the scale: one is an
     action flag, the other is the absence of data. Validated as an ordinal
     ramp - see README. */
  --band-performance: #104281;
  --band-good: #1c5cab;
  --band-fair: #2a78d6;
  --band-weak: #5598e7;
  --band-opportunity: #fab219;
  --band-dead: #898781;

  --delta-good: #006300;
  --delta-bad: #d03b3b;

  --radius: 10px;
  --radius-sm: 6px;
}

/* Dark steps are declared twice on purpose: the media query follows the OS,
   the data-theme scope follows the in-page toggle, and the toggle must win
   both ways. The :not() guard lets an explicit "light" beat OS dark. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;

    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.05);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --band-performance: #9ec5f4;
    --band-good: #6da7ec;
    --band-fair: #3987e5;
    --band-weak: #256abf;

    --delta-good: #0ca30c;
  }
}

:root[data-theme="dark"] .viz-root {
  color-scheme: dark;

  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.05);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --band-performance: #9ec5f4;
  --band-good: #6da7ec;
  --band-fair: #3987e5;
  --band-weak: #256abf;

  --delta-good: #0ca30c;
}

/* ---------------------------------------------------------------- base --- */

* { box-sizing: border-box; }

/* min-height, not height: a fixed 100% makes <body> the sticky containing
   block, so the topbar unpins as soon as you scroll past the first viewport. */
html { min-height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
p { margin: 0; }

main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 64px; }

/* ------------------------------------------------------------- topbar --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.topbar__brand { display: flex; align-items: center; gap: 12px; }

.topbar__mark {
  width: 26px; height: 26px; flex: none;
  border-radius: 7px;
  background: var(--series-1);
}

.topbar__sub { color: var(--text-secondary); font-size: 12.5px; }

.topbar__controls { display: flex; align-items: flex-end; gap: 10px; }

/* ------------------------------------------------------------ controls --- */

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field--grow { flex: 1 1 240px; }
.field--inline { min-width: 190px; }

.field__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.control {
  appearance: none;
  width: 100%;
  padding: 7px 10px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
select.control {
  padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.control:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

.btn {
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn:hover { background: var(--wash); }
.btn:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.btn--quiet { background: transparent; color: var(--text-secondary); }
.btn--icon { padding: 7px 10px; line-height: 1; }
.btn__glyph { font-size: 15px; }

/* ------------------------------------------------------------- connect --- */

.connect__badge {
  margin-left: 7px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--wash);
  border: 1px solid var(--border);
}
.connect__badge--on { color: var(--delta-good); border-color: currentColor; }

.connect__row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.connect__add {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--wash);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.connect__block {
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.connect__heading { font-size: 13px; font-weight: 600; margin-bottom: 9px; }

.connect__hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-secondary);
}
.connect__hint code {
  padding: 1px 6px;
  font-size: 12px;
  background: var(--wash);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.connect__status { font-size: 13.5px; margin-right: auto; }
.connect__countdown { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.connect__message {
  padding: 9px 11px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: var(--radius-sm);
  background: var(--wash);
  border: 1px solid var(--border);
}
.connect__message--good { border-color: var(--status-good); }
.connect__message--critical { border-color: var(--status-critical); }

.connect__progress {
  font-size: 12.5px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.btn--primary {
  color: #fff;
  background: var(--series-1);
  border-color: var(--series-1);
}
.btn--primary:hover { filter: brightness(1.08); background: var(--series-1); }
.btn--tiny { padding: 2px 8px; font-size: 11.5px; }

.proplist { list-style: none; margin: 0 0 12px; padding: 0; }
.proplist__item {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--grid);
}
.proplist__item:first-child { border-top: none; }
.proplist__url { font-size: 12.5px; overflow-wrap: anywhere; }
.proplist__perm {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.livebanner {
  margin-top: 16px;
  padding: 10px 13px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--status-warning);
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------- tabs --- */

.tabs {
  display: inline-flex;
  gap: 2px;
  margin-top: 16px;
  padding: 3px;
  background: var(--wash);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.tab {
  padding: 7px 15px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}
.tab:hover { color: var(--text-primary); }
.tab[aria-selected="true"] {
  color: var(--text-primary);
  background: var(--surface-1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.09);
}
.tab:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

/* The panel is the tab's own content; focusing it shouldn't draw a second ring. */
[role="tabpanel"]:focus { outline: none; }

/* -------------------------------------------------------------- panels --- */

.panel {
  margin-top: 16px;
  padding: 18px 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel:first-child { margin-top: 20px; }

.panel__head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel__sub { margin-top: 3px; font-size: 12.5px; color: var(--text-secondary); }

/* ---------------------------------------------------------------- hero --- */

.hero { display: flex; flex-wrap: wrap; gap: 28px; align-items: center; }

.hero__figure { min-width: 190px; }
.hero__label { font-size: 12.5px; color: var(--text-secondary); }
.hero__value {
  margin-top: 2px;
  font-size: 54px;
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.03em;
}
.hero__meta { margin-top: 4px; font-size: 12.5px; color: var(--text-muted); }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(162px, 1fr));
  gap: 10px;
  flex: 1 1 520px;
}

.tile {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.tile__label { font-size: 11.5px; color: var(--text-secondary); }
.tile__value {
  margin-top: 3px;
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.tile__foot { display: flex; align-items: center; gap: 8px; margin-top: 5px; min-height: 16px; }
.tile__delta { font-size: 11.5px; font-weight: 500; color: var(--text-muted); white-space: nowrap; }
.tile__delta--up { color: var(--delta-good); }
.tile__delta--down { color: var(--delta-bad); }
.tile__spark { margin-left: auto; display: block; }

/* --------------------------------------------------------------- chart --- */

.chart { margin: 0; min-width: 0; }
.chart__canvas { position: relative; width: 100%; }

/* Small multiples: one chart per measure, never a shared axis. */
.charts2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 22px;
}
.chart__title {
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.chart__canvas svg { display: block; width: 100%; height: auto; }
.chart__empty { padding: 28px 0; font-size: 13px; color: var(--text-muted); text-align: center; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; }
.legend__item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); }
.legend__key { width: 14px; height: 3px; border-radius: 2px; flex: none; }

.tooltip {
  position: fixed;
  z-index: 60;
  min-width: 132px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.14);
  pointer-events: none;
}
.tooltip__title { font-weight: 600; margin-bottom: 5px; }
.tooltip__row { display: flex; align-items: center; gap: 7px; }
.tooltip__key { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.tooltip__val { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 500; }

/* -------------------------------------------------------- status grid --- */

.statusgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 8px;
}

.statuscard {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  font: inherit;
  text-align: left;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.statuscard:hover { background: var(--wash); }
.statuscard[aria-pressed="true"] { border-color: var(--text-secondary); background: var(--wash); }
.statuscard__text { min-width: 0; display: flex; flex-direction: column; }
.statuscard__label {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.statuscard__value {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  display: flex;
  align-items: baseline;
}
.statuscard__pct { margin-left: 6px; font-size: 11.5px; font-weight: 400; color: var(--text-muted); }

/* The one place the dashboard states which periods it is comparing. */
.period {
  margin-top: 12px;
  padding: 0 2px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* ------------------------------------------------------------ movement --- */

.movement {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.movement__intro {
  margin-bottom: 9px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips--moves { margin-top: 9px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { background: var(--wash); }
.chip[aria-pressed="true"] { border-color: var(--text-secondary); background: var(--wash); }
.chip:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.chip strong {
  padding-left: 5px;
  margin-left: 1px;
  font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--border);
}
.chip--move { font-weight: 400; }

/* Direction uses the delta text tokens, never a series hue. */
.move--up { color: var(--delta-good); }
.move--down { color: var(--delta-bad); }
.move--flat, .chip.move--flat { color: var(--text-muted); }

.move { white-space: nowrap; font-size: 12.5px; font-weight: 500; }

/* ------------------------------------------------------ status marker --- */

.mark { flex: none; display: inline-flex; align-items: center; justify-content: center; }
.mark svg { display: block; }

/* -------------------------------------------------------------- alerts --- */

.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }

.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 2px;
  border-top: 1px solid var(--border);
}
.alert:first-child { border-top: none; }
.alert__body { min-width: 0; flex: 1; }
.alert__msg { font-size: 13px; }
.alert__url {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}
.alert__url:hover { color: var(--text-primary); }
.alert__sev {
  flex: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-top: 1px;
  width: 62px;
}

/* --------------------------------------------------------------- table --- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  padding-bottom: 14px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* This wrapper scrolls in both axes, which also makes it the sticky container
   for the header row below - hence `top: 0` there rather than an offset that
   tries to clear the page topbar. */
.tablewrap {
  overflow: auto;
  max-height: 72vh;
  overscroll-behavior: contain;
}

/* separate, not collapse: collapsed borders are owned by the table rather than
   the cell, so they scroll away from a sticky column instead of riding with it.
   Every border below is therefore drawn per-cell. */
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }

/* Freeze the URL column - without it the URLs scroll out of view exactly when
   you need them to read the metrics. */
.table th:first-child,
.table td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--surface-1);
  /* box-shadow rather than border-right: a border would widen the column and
     nudge every other cell as the table scrolls. */
  box-shadow: 1px 0 0 var(--border);
}

/* Depth only once there is something underneath - a permanent shadow on an
   unscrolled table just looks like a stray line. */
.tablewrap.is-scrolled .table th:first-child,
.tablewrap.is-scrolled .table td:first-child {
  box-shadow: 1px 0 0 var(--border), 8px 0 9px -7px rgba(0, 0, 0, 0.30);
}

/* The corner cell is sticky on both axes, so it has to outrank both. */
.table th:first-child { z-index: 6; }

/* An opaque sticky cell would otherwise sit out the row hover. Layering the
   translucent wash over the surface keeps it in step with the rest of the row. */
.table tbody tr:hover td:first-child {
  background-color: var(--surface-1);
  background-image: linear-gradient(var(--wash), var(--wash));
}

.table th {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 0;
  text-align: left;
  font-weight: 600;
  background: var(--surface-1);
  border-bottom: 1px solid var(--axis);
  white-space: nowrap;
}
.table th button {
  width: 100%;
  padding: 9px 10px 8px;
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
.table th button:hover { color: var(--text-primary); }
.table th[aria-sort] button { color: var(--text-primary); }
.table th[aria-sort="descending"] button::after { content: " ↓"; }
.table th[aria-sort="ascending"] button::after { content: " ↑"; }
.th--num, .th--num button { text-align: right; }
.th--url { width: 340px; }
.th--query { min-width: 170px; max-width: 220px; }

.td--query { max-width: 220px; }
.query {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A hairline marks where Search Console data ends and analytics begins. */
.th--ga4, .td--ga4 { border-left: 1px solid var(--border); }
.th--center, .th--center button { text-align: center; }

.table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--wash); }

.td--num { text-align: right; font-variant-numeric: tabular-nums; }
.td--center { text-align: center; }
.td--muted { color: var(--text-muted); }

.cell-url { display: flex; align-items: center; gap: 7px; min-width: 0; }
.cell-url a {
  color: var(--text-primary);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 252px;   /* leaves room for the CANONICAL / REDIRECT flags */
}
.cell-url a:hover { text-decoration: underline; }

.flag {
  flex: none;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* Status pill: ink text + a shaped, coloured marker. The marker carries the
   colour; the words carry the meaning. Never colour alone. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
  color: var(--text-primary);
  background: var(--wash);
  border: 1px solid var(--border);
}

.tablefoot { display: flex; justify-content: center; padding-top: 14px; }

.empty { font-size: 13px; color: var(--text-muted); text-align: center; padding: 22px 0; }

.footer { margin-top: 22px; font-size: 12px; color: var(--text-muted); text-align: center; }

/* --------------------------------------------------------------- state --- */

.state { padding: 72px 24px; text-align: center; color: var(--text-secondary); }
.state--error { max-width: 660px; margin: 0 auto; text-align: left; }
.state--error h2 { margin-bottom: 8px; color: var(--status-critical); }
.state--error p { font-size: 13.5px; line-height: 1.6; }
.state--error code {
  padding: 1px 5px;
  font-size: 12.5px;
  background: var(--wash);
  border-radius: 4px;
}

@media (max-width: 720px) {
  main { padding: 16px 14px 48px; }
  .topbar { padding: 12px 14px; }
  .hero__value { font-size: 44px; }
  .tablewrap { max-height: 60vh; }
  /* A frozen column would swallow a phone screen, so let it scroll away. */
  .table th:first-child,
  .table td:first-child { position: static; box-shadow: none; }
  .th--url { width: auto; }
}

@media print {
  .topbar__controls, .filters, .btn, .tablefoot { display: none !important; }
  .panel { break-inside: avoid; border-color: #999; }
}
