/* ============================================================
   Periscope — app styles on top of the UX4G Design System.
   The design system's own stylesheet (/ds/styles.css → tokens/fig-tokens.css,
   fonts.css, typography.css, semantic.css) is the source of truth and is linked
   FIRST. This file only adds app-specific components, all expressed through the
   design system's variables: --accent, --bg, --surface, --fg, --fg-muted, --border,
   --divider, --r-*, --s-*, --shadow-*, --focus-ring, --ease, --f-sans, --f-mono,
   --fw-*, and the raw --primary-* / --neutral-* / --success-* ramps.
   ============================================================ */

:root {
  /* app-level derivations from UX4G tokens */
  --accent-fg: var(--fg-link);                 /* accent used as text on surfaces */
  --accent-tint: var(--accent-weak);           /* primary-50 */
  --accent-tint-2: var(--accent-weak-2);       /* primary-100 */
  --badge-success-bg: var(--success-100); --badge-success-fg: var(--success-800);
  --badge-danger-bg:  var(--danger-100);  --badge-danger-fg:  var(--danger-800);
  --badge-warning-bg: var(--warning-100); --badge-warning-fg: var(--warning-800);
  --badge-info-bg:    var(--primary-100); --badge-info-fg:    var(--primary-800);
  --badge-neutral-bg: var(--neutral-50);  --badge-neutral-fg: var(--neutral-900);
  --container: 1880px;   /* the table is the product — use the width the screen actually has */
  /* motion: one easing for things that arrive (fast out, gentle settle), two durations */
  --motion-ease: cubic-bezier(.2, 0, 0, 1);
  --motion-fast: 180ms;
  --motion-panel: 280ms;
}

/* UX4G ships its dark theme on data-theme="dark" only; we also honour the OS preference
   (same UX4G dark values), guarded so an explicit light choice from the toggle wins. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #333742; --surface: #292c35; --surface-2: #23252c;
    --fg: #ebebeb; --fg-muted: #b0b0b0; --border: #474747; --divider: #3a3d47;
    --accent-fg: var(--primary-200); --accent-tint: var(--primary-transparent-16); --accent-tint-2: rgba(97,58,245,.28);
    --badge-success-bg: rgba(60,151,24,.24); --badge-success-fg: var(--success-200);
    --badge-danger-bg: rgba(183,19,26,.28);  --badge-danger-fg: var(--danger-200);
    --badge-warning-bg: rgba(183,114,36,.26); --badge-warning-fg: var(--warning-200);
    --badge-info-bg: rgba(97,58,245,.28);    --badge-info-fg: var(--primary-200);
    --badge-neutral-bg: rgba(255,255,255,.10); --badge-neutral-fg: var(--neutral-200);
    --shadow-1: 0 1px 3px rgba(0,0,0,.35); --shadow-2: 0 4px 12px rgba(0,0,0,.45);
  }
}
:root[data-theme="dark"] {
  --accent-fg: var(--primary-200); --accent-tint: var(--primary-transparent-16); --accent-tint-2: rgba(97,58,245,.28);
  --badge-success-bg: rgba(60,151,24,.24); --badge-success-fg: var(--success-200);
  --badge-danger-bg: rgba(183,19,26,.28);  --badge-danger-fg: var(--danger-200);
  --badge-warning-bg: rgba(183,114,36,.26); --badge-warning-fg: var(--warning-200);
  --badge-info-bg: rgba(97,58,245,.28);    --badge-info-fg: var(--primary-200);
  --badge-neutral-bg: rgba(255,255,255,.10); --badge-neutral-fg: var(--neutral-200);
  --shadow-1: 0 1px 3px rgba(0,0,0,.35); --shadow-2: 0 4px 12px rgba(0,0,0,.45);
}

/* ---------------- base ---------------- */
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--surface); color: var(--fg); font: var(--fw-regular) 14px/20px var(--f-sans); letter-spacing: .25px; }
a { color: var(--accent-fg); }
button, input, select, textarea { font-family: var(--f-sans); }
code { font: var(--fw-regular) .92em/1 var(--f-mono); background: var(--surface-2); border-radius: var(--r-xs); padding: .1em .35em; }
[hidden] { display: none !important; }
.muted { color: var(--fg-muted); }
.small { font-size: 12px; line-height: 16px; letter-spacing: .4px; }
.error { color: var(--danger); font-size: 13px; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* Material Symbols (UX4G icon system, font loaded by the design system's fonts.css) —
   hidden until the font is confirmed loaded so ligature names never show */
.ms {
  font-family: "Material Symbols Rounded"; font-weight: normal; font-style: normal; font-size: 20px; line-height: 1;
  display: inline-block; white-space: nowrap; letter-spacing: normal; text-transform: none; direction: ltr;
  -webkit-font-feature-settings: "liga"; font-feature-settings: "liga"; -webkit-font-smoothing: antialiased; user-select: none;
  visibility: hidden; width: 1em; overflow: hidden;
}
.fonts-ready .ms { visibility: visible; width: auto; overflow: visible; }

/* ---------------- buttons (UX4G Button) ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-sm);
  height: 40px; padding: 10px var(--s-2xl); border-radius: var(--r-md); border: 1px solid transparent;
  background: var(--accent); color: var(--on-accent);
  font: var(--fw-medium) 16px/24px var(--f-sans); letter-spacing: .15px; white-space: nowrap; cursor: pointer;
  transition: background var(--ease), color var(--ease), border-color var(--ease), transform 80ms ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }   /* a press you can feel */
.btn.outline { background: transparent; color: var(--accent-fg); border-color: var(--accent-fg); }
.btn.outline:hover { background: var(--accent-tint); }
.btn.text { background: transparent; color: var(--accent-fg); }
.btn.text:hover { background: var(--accent-tint); }
.btn.small { height: 32px; padding: 6px var(--s-lg); font-size: 14px; line-height: 20px; }
.btn:disabled { opacity: .48; cursor: not-allowed; }
.btn .ms { font-size: 20px; }

/* ---------------- masthead (UX4G Navbar: top strip + main bar) ---------------- */
.masthead { position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow-1); }
.strip { background: var(--neutral-source); color: #fff; }
.strip-in {
  max-width: var(--container); margin: 0 auto; padding: 0 var(--s-2xl); height: 40px;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-lg); font: var(--fw-regular) 13px/16px var(--f-sans);
}
.strip-left, .strip-right { display: flex; align-items: center; gap: 10px; }
.strip a { color: #fff; text-decoration: none; opacity: .85; }
.strip a:hover { opacity: 1; }
.strip .sep { opacity: .4; }
.strip .dim { opacity: .85; }
.mark {
  display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: #fff; color: var(--neutral-source);
  align-items: center; justify-content: center; font-weight: var(--fw-bold); font-size: 12px;
}
.fs-btn {
  background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: var(--r-xs); padding: 2px 7px;
  font: var(--fw-medium) 12px/1 var(--f-sans); cursor: pointer; min-width: 26px; height: 24px; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.fs-btn:hover { background: rgba(255,255,255,.12); }
.fs-btn.bold { font-weight: var(--fw-bold); }
.fs-btn .ms { font-size: 18px; }
.fs-group { display: inline-flex; gap: 4px; }
.mainbar { background: var(--bg); border-bottom: 1px solid var(--divider); }
.mainbar-in { max-width: var(--container); margin: 0 auto; padding: 0 var(--s-2xl); height: 68px; display: flex; align-items: center; gap: var(--s-2xl); }
.brand { display: flex; align-items: center; gap: var(--s-md); text-decoration: none; }
.brand-word { font: var(--fw-bold) 22px/26px var(--f-sans); color: var(--primary-source); letter-spacing: -.2px; }
.brand-sub { border-left: 1px solid var(--border); padding-left: var(--s-md); font: var(--fw-medium) 13px/16px var(--f-sans); color: var(--fg-muted); }
nav.primary { display: flex; gap: 4px; margin-left: var(--s-sm); }
nav.primary a { padding: var(--s-sm) var(--s-md); border-radius: var(--r-md); text-decoration: none; font: var(--fw-regular) 15px/20px var(--f-sans); color: var(--fg); }
nav.primary a.active { font-weight: var(--fw-medium); color: var(--accent-fg); background: var(--accent-tint); }
.actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-md); }
.avatar { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); }
.me-login { font: var(--fw-medium) 14px/20px var(--f-sans); }
/* budget readout: quiet until it actually matters */
.rate-note { font: var(--fw-regular) 12px/16px var(--f-sans); color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.rate-note.low { color: var(--warning); font-weight: var(--fw-medium); }

/* ---------------- login ---------------- */
.login-wrap { min-height: calc(100vh - 108px); display: grid; place-items: center; padding: var(--s-5xl) var(--s-2xl); }
.login-card {
  width: min(440px, 100%); background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s-3xl); box-shadow: var(--shadow-1);
}
.login-card h1 { margin: 0 0 var(--s-sm); color: var(--fg); }
.login-sub { font: var(--fw-regular) 14px/22px var(--f-sans); color: var(--fg-muted); margin: 0 0 var(--s-2xl); }
.login-card .btn { width: 100%; }
.field-label { display: block; color: var(--fg); margin: 0 0 6px; }
.input {
  width: 100%; height: 40px; padding: var(--s-sm) var(--s-md); border: 1px solid var(--border); border-radius: var(--r-xs);
  background: var(--bg); color: var(--fg); font: var(--fw-regular) 14px/20px var(--f-sans);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.input:focus { border-color: var(--accent); box-shadow: var(--focus-ring); outline: none; }
#form-pat .input { font-family: var(--f-mono); }
.help { font: var(--fw-regular) 12px/16px var(--f-sans); color: var(--fg-muted); margin: 6px 0 14px; }
.or-rule { display: flex; align-items: center; gap: 10px; color: var(--fg-muted); font-size: 12px; margin: var(--s-xl) 0 var(--s-lg); }
.or-rule::before, .or-rule::after { content: ""; flex: 1; border-top: 1px solid var(--divider); }
.device-step { margin-top: var(--s-lg); text-align: center; }
.device-code {
  font: var(--fw-semibold) 28px/36px var(--f-mono); letter-spacing: .12em;
  background: var(--accent-tint); color: var(--accent-fg); border: 1px solid var(--accent-tint-2); border-radius: var(--r-md);
  padding: 10px; margin: var(--s-sm) 0; user-select: all;
}

/* ---------------- dashboard ---------------- */
.dash { max-width: var(--container); margin: 0 auto; padding: var(--s-2xl) var(--s-2xl) var(--s-7xl); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-lg); margin-bottom: var(--s-xl); }
.page-head h1 { margin: 0; color: var(--fg); }
.page-head p { font: var(--fw-regular) 15px/22px var(--f-sans); color: var(--fg-muted); margin: 6px 0 0; }

/* StatCard */
/* nine cards: auto-fit lets them wrap instead of shrinking below 148px at any width */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: var(--s-md); margin-bottom: var(--s-2xl); }
.tile { --tile-accent: var(--primary-source); background: var(--bg); border: 1px solid var(--divider); border-radius: var(--r-lg); padding: var(--s-xl); box-shadow: var(--shadow-1); }
.tile.ok { --tile-accent: var(--success-source); }
.tile.bad { --tile-accent: var(--danger-source); }
.tile.dim { --tile-accent: var(--neutral-600); }
.tile-ic {
  display: inline-flex; width: 44px; height: 44px; border-radius: var(--r-md); align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--tile-accent) 12%, var(--bg)); color: var(--tile-accent);
}
.tile-ic .ms { font-size: 24px; }
.tile-n { font: var(--fw-medium) 30px/34px var(--f-sans); color: var(--fg); margin-top: 14px; font-variant-numeric: tabular-nums; transform-origin: left center; }
.tile-n.bump { animation: periscope-bump 480ms var(--motion-ease); }
@keyframes periscope-bump { 30% { transform: scale(1.08); color: var(--tile-accent); } }
.tile-l { font: var(--fw-regular) 14px/20px var(--f-sans); color: var(--fg-muted); margin-top: 2px; }

/* controls: Search + Chips */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-md); margin-bottom: var(--s-lg); }
.search { position: relative; flex: 1 1 240px; max-width: 340px; display: block; }
.search .ms { position: absolute; left: 10px; top: 10px; color: var(--fg-muted); }
.search .input { padding-left: 38px; border-radius: var(--r-md); }
.chips { display: flex; gap: var(--s-sm); flex-wrap: wrap; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 var(--s-md); border-radius: var(--r-md);
  border: 1px solid var(--border); background: transparent; color: var(--fg);
  font: var(--fw-medium) 14px/20px var(--f-sans); cursor: pointer; transition: background var(--ease);
}
.chip-btn:hover { background: var(--accent-tint); }
.chip-btn.active { background: var(--accent-tint-2); color: var(--badge-info-fg); border-color: transparent; }
.toggle { font: var(--fw-regular) 14px/20px var(--f-sans); color: var(--fg-muted); display: flex; gap: 6px; align-items: center; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.progress { font: var(--fw-regular) 13px/16px var(--f-sans); color: var(--fg-muted); font-variant-numeric: tabular-nums; }
/* Combined progress of the passes filling the table in: 2px, always laid out (no shift), faded when idle */
.load-bar {
  position: relative; height: 2px; margin: calc(var(--s-sm) * -1) 0 calc(var(--s-sm) - 2px);
  border-radius: 2px; overflow: hidden; background: var(--accent-tint);
  transition: opacity 400ms ease;
}
.load-bar.done { opacity: 0; transition-delay: 300ms; }
.load-bar-fill {
  position: absolute; inset: 0; background: var(--accent);
  transform-origin: left center; transform: scaleX(var(--share, 0)); transition: transform 360ms var(--motion-ease);
}
.load-bar.done .load-bar-fill { transform: scaleX(1); }
.load-bar.indeterminate .load-bar-fill { right: auto; width: 30%; transform: none; animation: periscope-sweep 1.2s ease-in-out infinite; }
@keyframes periscope-sweep { from { left: -30%; } to { left: 100%; } }
.count-note { font: var(--fw-medium) 13px/16px var(--f-sans); color: var(--fg-muted); margin-left: auto; font-variant-numeric: tabular-nums; }
/* Column filter controls (compact UX4G inputs/selects living inside the header) */
.f-input, .f-select {
  width: 100%; height: 28px; padding: 0 6px; border: 1px solid var(--border); border-radius: var(--r-xs);
  background: var(--bg); color: var(--fg); font: var(--fw-regular) 12px/16px var(--f-sans); text-transform: none; letter-spacing: 0;
}
.f-select { cursor: pointer; padding-right: 2px; }
.f-input:focus, .f-select:focus { border-color: var(--accent); box-shadow: var(--focus-ring); outline: none; }
.f-select:disabled { opacity: .6; cursor: not-allowed; }

/* Table (UX4G Table) */
.tablewrap { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md); overflow: visible; }
table { border-collapse: collapse; width: 100%; table-layout: fixed; font: var(--fw-regular) 14px/20px var(--f-sans); }
/* eleven columns — Repository, Platform, Tags, Activity, CI/CD, Last run, Site, SSL, Deployment, Pushed and the
   per-row re-check button — widths sum to 100% so the fixed layout never overflows horizontally (Language lives
   in the repository cell's meta line) */
col.c-repo { width: 18%; } col.c-platform { width: 9%; } col.c-tags { width: 9%; } col.c-activity { width: 9%; }
col.c-ci { width: 7%; } col.c-run { width: 10%; } col.c-site { width: 6%; } col.c-ssl { width: 6%; }
col.c-audit { width: 8%; } col.c-dep { width: 8%; } col.c-push { width: 5%; } col.c-act { width: 5%; }
thead th {
  text-align: left; text-transform: uppercase; color: var(--fg-muted); background: var(--surface-2);
  padding: var(--s-md); border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  position: sticky; top: 108px; z-index: 2;   /* 108px = masthead strip (40) + main bar (68) */
}
/* the filter row sits directly under the sticky header row */
thead tr.filter-row th { top: 149px; padding: 6px var(--s-sm) 8px; }
/* Sort control: the whole header cell is clickable, the arrow shows the active direction */
.th-sort {
  display: flex; align-items: center; gap: 4px; width: 100%; padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; text-align: left;
}
.th-sort .sort-ic { font-size: 15px; opacity: .35; flex: none; }
.th-sort:hover .sort-ic { opacity: .7; }
thead th.sorted { color: var(--accent-fg); }
thead th.sorted .sort-ic { opacity: 1; }
thead th:first-child { border-top-left-radius: var(--r-md); }
thead th:last-child { border-top-right-radius: var(--r-md); }
tbody td { padding: 10px var(--s-md); border-bottom: 1px solid var(--divider); vertical-align: middle; overflow: hidden; color: var(--fg); }
tbody td, tbody td div { overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }
/* Pushed (10th) is the narrowest text column: minimal padding, no wrapping, so "PUSHED" and "10m ago" stay on one line */
thead th:nth-child(10), tbody td:nth-child(10) { padding-left: var(--s-xs); padding-right: var(--s-xs); }
tbody td:nth-child(10) { white-space: nowrap; font-size: 13px; text-overflow: ellipsis; }
/* the action column holds one icon button */
thead th.th-act, tbody td.row-act { padding-left: 0; padding-right: var(--s-sm); text-align: right; overflow: visible; }
thead th.th-act .ms { font-size: 16px; opacity: .55; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .15s ease; }
tbody tr:hover { background: var(--accent-tint); }
/* keyboard focus on a row: tinted, with an accent edge on the first cell (a ring on a <tr> is unreliable) */
tbody tr:focus-visible { outline: none; box-shadow: none; background: var(--accent-tint); }
tbody tr:focus-visible td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.repo-cell a { font-weight: var(--fw-medium); color: var(--accent-fg); text-decoration: none; }
.repo-cell a:hover { text-decoration: underline; }
.repo-meta { font: var(--fw-regular) 12px/16px var(--f-sans); color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.lock { display: inline-flex; align-items: center; gap: 2px; font: var(--fw-regular) 11px/16px var(--f-sans); color: var(--fg-muted); margin-left: 6px; vertical-align: middle; }
.lock .ms { font-size: 14px; }
/* Live URL link inside the repository meta line (user-entered, rendered only when it is an absolute http(s) URL) */
.repo-meta .live-link { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; vertical-align: bottom; }
.repo-meta .live-link .ms { font-size: 13px; flex: none; }
/* Commit activity sparkline (inline SVG, 52 weekly points): success-green line over a faint baseline, like
   GitHub's participation graph. Stretches to the cell width; non-scaling strokes keep it crisp. */
.spark-wrap { display: block; width: 100%; line-height: 0; }
.spark { display: block; width: 100%; height: 28px; overflow: visible; }
.spark-base { stroke: var(--divider); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark-area { fill: color-mix(in srgb, var(--success) 12%, transparent); stroke: none; }
.spark-line { fill: none; stroke: var(--success); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
/* Narrower windows drop the least load-bearing columns rather than scrolling sideways. */
@media (max-width: 1400px) {
  /* hide Activity (4th) and Pushed (11th) — widths below sum to 100 across the ten that remain */
  col.c-activity, col.c-push,
  td:nth-child(4), th:nth-child(4), td:nth-child(11), th:nth-child(11) { display: none; }
  col.c-repo { width: 21%; } col.c-platform { width: 11%; } col.c-tags { width: 11%; } col.c-ci { width: 9%; }
  col.c-run { width: 13%; } col.c-site { width: 8%; } col.c-ssl { width: 7%; } col.c-audit { width: 8%; }
  col.c-dep { width: 7%; } col.c-act { width: 5%; }
}
@media (max-width: 1000px) {
  /* also hide Tags (3rd) and Deployment (10th) — the eight that remain sum to 100 */
  col.c-tags, col.c-dep, td:nth-child(3), th:nth-child(3), td:nth-child(10), th:nth-child(10) { display: none; }
  col.c-repo { width: 25%; } col.c-platform { width: 14%; } col.c-ci { width: 12%; } col.c-run { width: 16%; }
  col.c-site { width: 10%; } col.c-ssl { width: 9%; } col.c-audit { width: 9%; } col.c-act { width: 5%; }
}

/* Platform chips (UX4G Chip, soft) — icon + short label, one per platform */
.pf-list { display: flex; flex-wrap: wrap; gap: 4px; }
.pf {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 2px var(--s-sm) 2px 6px; border-radius: 100px;
  background: var(--accent-tint); color: var(--accent-fg); border: 1px solid var(--accent-tint-2);
  font: var(--fw-medium) 11px/16px var(--f-sans); letter-spacing: .25px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.pf .ms { font-size: 14px; flex: none; }
.pf-none { font: var(--fw-regular) 12px/16px var(--f-sans); }
/* Free-form tags (neutral pill) */
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag {
  display: inline-flex; align-items: center; height: 20px; padding: 2px var(--s-sm); border-radius: 100px; max-width: 100%;
  background: var(--badge-neutral-bg); color: var(--badge-neutral-fg); font: var(--fw-medium) 11px/16px var(--f-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Badges (UX4G Badge, soft variant, with status dot) */
.st {
  display: inline-flex; align-items: center; gap: 6px; height: 20px; padding: 2px var(--s-sm); border-radius: 100px;
  font: var(--fw-medium) 11px/16px var(--f-sans); letter-spacing: .5px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.st.pass, .st.live { background: var(--badge-success-bg); color: var(--badge-success-fg); }
.st.fail, .st.down { background: var(--badge-danger-bg); color: var(--badge-danger-fg); }
.st.warn { background: var(--badge-warning-bg); color: var(--badge-warning-fg); }
.st.info { background: var(--badge-info-bg); color: var(--badge-info-fg); }
.st.unknown { background: var(--badge-neutral-bg); color: var(--badge-neutral-fg); }
/* Loading: a skeleton shimmer, so a column still filling in reads as "on its way" rather than as a value */
.st.load {
  color: var(--fg-muted);
  background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 40%, var(--bg)) 50%, var(--surface-2) 75%);
  background-size: 300% 100%; animation: periscope-shimmer 1.6s linear infinite;
}
.st.load::before { display: none; }
@keyframes periscope-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
/* Stale: the last known result, shown while the server re-checks it — a faint ring and a breathing dot */
.st.stale { box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 30%, transparent); }
.st.stale::before { animation: periscope-breathe 1.6s ease-in-out infinite; }
@keyframes periscope-breathe { 50% { opacity: .3; } }
/* Down asks for attention a few times when it appears, then stays still */
.st.down::before { animation: periscope-ping 1.8s ease-out 3; }
@keyframes periscope-ping {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
  70%, 100% { box-shadow: 0 0 0 5px transparent; }
}
/* A value that has just arrived eases in; a verdict that changed flashes once */
td.cell-in > * { animation: periscope-in var(--motion-fast) var(--motion-ease) both; }
@keyframes periscope-in { from { opacity: 0; transform: translateY(3px); } }
td.cell-changed > .st { animation: periscope-flag 700ms ease-out; }
@keyframes periscope-flag {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 45%, transparent); }
  100% { box-shadow: 0 0 0 6px transparent; }
}
.st .st-l { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* SSL expiry (9%): slightly tighter cell and badge so "Unreachable" fits at 1366px */
.ssl-cell { padding-left: var(--s-sm); padding-right: var(--s-sm); }
.ssl-cell .st { gap: 4px; padding-left: 6px; padding-right: 6px; letter-spacing: .25px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.pass, .dot.live { background: var(--success); }
.dot.fail, .dot.down { background: var(--danger); }
.dot.warn { background: var(--warning); }
.dot.info { background: var(--accent); }
.dot.unknown { background: var(--neutral-200); }

/* Callout (UX4G Callout / helpdesk box) */
.callout {
  margin-top: var(--s-xl); background: var(--accent-tint); border: 1px solid var(--accent-tint-2); border-radius: var(--r-lg);
  padding: var(--s-lg) var(--s-xl); display: flex; gap: var(--s-md); align-items: flex-start; font: var(--fw-regular) 14px/22px var(--f-sans); color: var(--fg-muted);
}
.callout .ms { color: var(--accent); font-size: 22px; flex: none; }
.callout b { color: var(--fg); font-weight: var(--fw-medium); }
.callout .st { vertical-align: middle; }
.capped { margin: 10px 0 0; }

/* ---------------- drawer (side panel) ---------------- */
#drawer-backdrop { position: fixed; inset: 0; background: rgba(33,33,33,.4); z-index: 80; opacity: 0; transition: opacity var(--motion-panel) ease; }
#drawer-backdrop.open { opacity: 1; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(500px, 94vw); z-index: 90;
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: var(--shadow-2); overflow-y: auto; padding: var(--s-2xl);
  overscroll-behavior: contain;   /* scrolling the panel never scrolls the table behind it */
  transform: translateX(100%); transition: transform var(--motion-panel) var(--motion-ease);
}
#drawer.open { transform: none; }
#drawer:focus, #drawer:focus-visible { outline: none; box-shadow: var(--shadow-2); }
/* sections settle in one after another as the panel arrives */
#drawer.open #drawer-body > * { animation: periscope-in var(--motion-panel) var(--motion-ease) both; }
#drawer.open #drawer-body > :nth-child(2) { animation-delay: 30ms; }
#drawer.open #drawer-body > :nth-child(3) { animation-delay: 60ms; }
#drawer.open #drawer-body > :nth-child(n+4) { animation-delay: 90ms; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-md); padding-bottom: var(--s-lg); border-bottom: 1px solid var(--divider); }
.drawer-head h2 { margin: 0; font: var(--fw-medium) 18px/24px var(--f-sans); color: var(--fg); overflow-wrap: anywhere; }
.drawer-head .btn { padding: 0; width: 32px; }
#drawer-body h3 { font: var(--fw-medium) 12px/16px var(--f-sans); letter-spacing: .5px; text-transform: uppercase; color: var(--fg-muted); margin: var(--s-2xl) 0 10px; }
.drawer-list { display: flex; flex-direction: column; gap: var(--s-sm); }
.drawer-item {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s-md);
  border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px var(--s-md); background: var(--bg);
}
.drawer-item .di-main { min-width: 0; display: flex; gap: 10px; align-items: center; }
.drawer-item .di-name { font: var(--fw-medium) 14px/20px var(--f-sans); color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-item .di-sub { font: var(--fw-regular) 12px/16px var(--f-sans); color: var(--fg-muted); }
.drawer-item a { font: var(--fw-medium) 13px/16px var(--f-sans); text-decoration: none; white-space: nowrap; }
.drawer-links { margin-top: var(--s-xl); font: var(--fw-medium) 14px/20px var(--f-sans); }
.drawer-links a { text-decoration: none; }
/* Live URL in the drawer header (from the classification) */
.drawer-live { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; max-width: 100%; font: var(--fw-medium) 13px/16px var(--f-sans); color: var(--accent-fg); text-decoration: none; overflow-wrap: anywhere; }
.drawer-live:hover { text-decoration: underline; }
.drawer-live .ms { font-size: 16px; flex: none; }

/* Classification editor (drawer) — Periscope-owned metadata, stored in MongoDB */
.classify fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.classify fieldset:disabled { opacity: .55; }
.classify .field-label { margin-top: var(--s-md); }
.classify .field-label:first-child { margin-top: 0; }
.classify .help { margin: var(--s-md) 0 0; }
.notice {
  display: flex; align-items: center; gap: var(--s-sm); margin: 0 0 var(--s-md);
  background: var(--badge-warning-bg); color: var(--badge-warning-fg); border-radius: var(--r-xs);
  padding: var(--s-sm) var(--s-md); font: var(--fw-regular) 13px/18px var(--f-sans);
}
.notice .ms { font-size: 18px; flex: none; }
.pf-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.pf-opt {
  display: flex; align-items: center; gap: var(--s-sm); padding: 6px var(--s-sm); border: 1px solid var(--border); border-radius: var(--r-xs);
  font: var(--fw-regular) 13px/16px var(--f-sans); color: var(--fg); cursor: pointer; transition: background var(--ease), border-color var(--ease);
}
.pf-opt:hover { background: var(--accent-tint); }
.pf-opt:has(input:checked) { background: var(--accent-tint); border-color: var(--accent-tint-2); color: var(--accent-fg); }
.pf-opt input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; flex: none; }
.pf-opt .ms { font-size: 18px; color: var(--fg-muted); flex: none; }
.pf-opt:has(input:checked) .ms { color: var(--accent-fg); }
.pf-opt .pf-opt-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* "Add platform" control at the end of the checkbox grid (POST /api/meta/platforms — MongoDB only) */
.pf-add { display: flex; align-items: center; gap: var(--s-sm); margin-top: 6px; }
.pf-add .input { height: 32px; flex: 1 1 auto; min-width: 0; }
.pf-add .btn { flex: none; }
#class-add-error { margin: 4px 0 0; }
/* Certificate line (read-only, from /api/ssl/*): state badge · "Valid until … · issuer · subject" · Re-check */
.cert-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-sm); min-height: 32px; }
.cert-line .st { flex: none; }
.cert-text { flex: 1 1 200px; min-width: 0; font: var(--fw-regular) 13px/18px var(--f-sans); color: var(--fg); overflow-wrap: anywhere; }
.cert-text.muted { color: var(--fg-muted); }
.cert-line .btn { flex: none; margin-left: auto; }
#class-cert-note { margin: 4px 0 0; }
.textarea { height: auto; min-height: 72px; resize: vertical; line-height: 20px; }
.class-actions { display: flex; align-items: center; gap: var(--s-md); margin-top: var(--s-md); }

/* Tags in the row (free-form classification, MongoDB) — a few pills plus a +N overflow */
.tag-cell { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tag-cell .tag { height: 18px; padding: 1px 7px; font-size: 10px; line-height: 16px; }
.tag-cell .tag.more { background: transparent; border: 1px dashed var(--border); color: var(--fg-muted); }

/* Clear lights up while any filter or search is narrowing the list */
.btn.text.on { background: var(--accent-tint); color: var(--accent-fg); }

/* Compact density: same information, ~30% more rows on screen */
body.dense tbody td { padding-top: 4px; padding-bottom: 4px; }
body.dense .repo-meta { display: none; }
body.dense .spark, body.dense .spark-wrap { height: 20px; }
body.dense .tiles { margin-bottom: var(--s-lg); }

/* Per-row buttons (re-check, security scan): quiet until the row is hovered or a button is focused, so
   145 rows stay calm. A disabled scan button stays faint on hover and explains itself in its tooltip. */
.row-act { white-space: nowrap; }
.row-refresh, .row-scan {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  border: 1px solid transparent; border-radius: var(--r-md); background: transparent; color: var(--fg-muted);
  cursor: pointer; opacity: 0; transition: opacity var(--ease), background var(--ease), color var(--ease);
}
.row-refresh .ms, .row-scan .ms { font-size: 18px; }
tbody tr:hover .row-refresh, .row-refresh:focus-visible, .row-refresh.busy,
tbody tr:hover .row-scan:not(:disabled), .row-scan:focus-visible { opacity: 1; }
tbody tr:hover .row-scan:disabled { opacity: .35; cursor: not-allowed; }
.row-refresh:hover, .row-scan:hover:not(:disabled) { background: var(--bg); border-color: var(--border); color: var(--accent-fg); }
.row-refresh.busy { color: var(--accent-fg); cursor: progress; }
.row-refresh.busy .ms { animation: periscope-spin 1s linear infinite; }
@keyframes periscope-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .row-refresh.busy .ms { animation: none; } }

/* ---------------- accounts: sign in, registration, settings (spec v5) ---------------- */
.login-card.wide { width: min(760px, 100%); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-md) var(--s-lg); }
.field-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .field-grid { grid-template-columns: 1fr; } }
.req { color: var(--danger); }
.notice {
  display: flex; gap: var(--s-sm); align-items: flex-start; margin: var(--s-md) 0 0;
  background: var(--accent-tint); border: 1px solid var(--accent-tint-2); border-radius: var(--r-md);
  padding: var(--s-md); font: var(--fw-regular) 13px/20px var(--f-sans); color: var(--fg);
}
.notice .ms { font-size: 18px; color: var(--accent-fg); flex: none; }

/* account chip in the masthead */
.me-block { display: flex; align-items: center; gap: 6px; }
.role-chip {
  font: var(--fw-medium) 10px/16px var(--f-sans); letter-spacing: .06em; text-transform: uppercase;
  padding: 1px 7px; border-radius: 100px; background: var(--badge-neutral-bg); color: var(--badge-neutral-fg);
}
.role-chip.admin { background: var(--badge-info-bg); color: var(--badge-info-fg); }

/* settings tabs and panels */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--s-xl); flex-wrap: wrap; }
.tab {
  border: 0; background: none; cursor: pointer; padding: 10px var(--s-lg); margin-bottom: -1px;
  font: var(--fw-medium) 14px/20px var(--f-sans); color: var(--fg-muted); border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--accent-fg); border-bottom-color: var(--accent); }
.panel {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s-2xl); max-width: 980px;
}
.panel h3 { margin: 0 0 6px; color: var(--fg); }
.panel .help { margin-bottom: var(--s-lg); }
.input.mono { font-family: var(--f-mono); }

/* connected service row */
.service-row {
  display: flex; align-items: center; gap: var(--s-lg); padding: var(--s-lg);
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); margin-bottom: var(--s-xl);
}
.service-ic { font-size: 28px; color: var(--accent-fg); }
.service-main { flex: 1; min-width: 0; }
.service-state { font: var(--fw-medium) 15px/22px var(--f-sans); color: var(--fg-muted); }
.service-state.on { color: var(--success); }

/* dashboard empty state when no GitHub account is connected */
.empty-state {
  display: flex; gap: var(--s-xl); align-items: center; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--s-3xl); max-width: 720px; margin: 0 auto;
}
.empty-state > .ms { font-size: 44px; color: var(--accent-fg); flex: none; }
.empty-state h3 { margin: 0 0 6px; color: var(--fg); }
.empty-state p { margin: 0 0 var(--s-lg); color: var(--fg-muted); font: var(--fw-regular) 14px/22px var(--f-sans); }

/* vendor administration table: content-sized, not the fixed dashboard grid, and never
   mid-word broken (the repository table breaks anywhere; account data must stay readable) */
#tab-vendors { max-width: none; }
#vendor-table { table-layout: auto; }
#vendor-table tbody tr { cursor: default; }
#vendor-table tbody tr:hover { background: transparent; }
#vendor-table thead th { position: static; }
#vendor-table td, #vendor-table th { overflow-wrap: normal; word-break: normal; white-space: nowrap; }
#vendor-table td:first-child, #vendor-table td:nth-child(2) { white-space: normal; }
#vendor-table .btn { white-space: nowrap; }

/* ---- Security audit (ADR-23) ------------------------------------------------------------ */
.audit-panel { display: flex; flex-direction: column; gap: var(--s-sm); margin-bottom: var(--s-lg); }
.audit-head { display: flex; align-items: center; gap: var(--s-sm); flex-wrap: wrap; }
.audit-head .btn.text.danger { color: var(--danger-fg, #B3261E); margin-left: auto; }
.audit-identity { font: var(--fw-regular) 12px/18px var(--f-sans); margin: 0; }
.audit-identity .ms { font-size: 15px; vertical-align: -3px; margin-right: 4px; }
.audit-identity.ok { color: var(--success-fg, #1B7A3D); }
.audit-identity.warn { color: var(--warn-fg, #8A5B00); }
.audit-identity.bad { color: var(--danger-fg, #B3261E); }
.audit-dates { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-sm); }
/* How a date was obtained is part of the value: read from the document, worked out from it, or typed. */
.src-note { display: block; font: var(--fw-regular) 11px/16px var(--f-sans); color: var(--fg-muted); margin-top: 2px; }
.src-note.derived { color: var(--warn-fg, #8A5B00); }
.audit-notes { margin: 0; padding-left: 18px; font: var(--fw-regular) 12px/18px var(--f-sans); color: var(--fg-muted); }
.audit-empty {
  display: flex; align-items: center; gap: var(--s-sm); padding: var(--s-md);
  border: 1px dashed var(--border); border-radius: var(--r-md); color: var(--fg-muted);
  font: var(--fw-regular) 13px/20px var(--f-sans);
}
.audit-empty .ms { font-size: 22px; }
.audit-empty p { margin: 0; }
.audit-upload { display: flex; align-items: center; gap: var(--s-sm); flex-wrap: wrap; }
.audit-history { list-style: none; margin: var(--s-sm) 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.audit-history li {
  display: flex; align-items: center; gap: var(--s-sm); padding: 4px 0;
  border-top: 1px solid var(--divider); font: var(--fw-regular) 12px/18px var(--f-sans);
}
.audit-history .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Expiry reminders (ADR-24) ---------------------------------------------------------- */
.reminder-panel { display: flex; flex-direction: column; gap: var(--s-sm); margin-bottom: var(--s-lg); }
.reminder-actions { display: flex; gap: var(--s-sm); flex-wrap: wrap; }
.rem-preview {
  margin: var(--s-sm) 0 0; padding: var(--s-sm); background: var(--surface-2, var(--bg));
  border: 1px solid var(--border); border-radius: var(--r-sm);
  font: var(--fw-regular) 12px/18px var(--f-mono, monospace); white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow: auto;
}
.rem-history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rem-history li {
  display: flex; align-items: center; gap: var(--s-sm); padding: 6px 0;
  border-top: 1px solid var(--divider); font: var(--fw-regular) 12px/18px var(--f-sans);
}
.rem-history .grow { flex: 1; min-width: 0; }
.rem-history .rem-when { color: var(--fg-muted); white-space: nowrap; }
.rem-history .rem-why { color: var(--fg-muted); display: block; }
.rem-empty { color: var(--fg-muted); font: var(--fw-regular) 12px/18px var(--f-sans); }

/* ---- Connected services, added vendors and hand-added projects (spec v7) --------------- */
.planned-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.planned-list li {
  display: flex; align-items: center; gap: var(--s-sm); padding: var(--s-sm) 0;
  border-top: 1px solid var(--divider); color: var(--fg-muted);
  font: var(--fw-regular) 13px/20px var(--f-sans);
}
.planned-list .ms { font-size: 20px; }
.planned-list b { color: var(--fg); font-weight: var(--fw-medium); }

/* One block per code host: its state, and either a token field or a disconnect control. */
.svc {
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s-md); margin-bottom: var(--s-sm);
}
.svc-head { display: flex; align-items: center; gap: var(--s-sm); }
.svc-head .ms { font-size: 22px; color: var(--accent-fg); }
.svc-title { font: var(--fw-medium) 15px/22px var(--f-sans); }
.svc-state { margin-left: auto; display: flex; align-items: center; gap: var(--s-sm); }
.svc-body { margin-top: var(--s-sm); }
.svc-body .input { max-width: 520px; }
.svc-body .field-label { display: block; margin-top: var(--s-sm); }
.svc-caps { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.svc-cap {
  font: var(--fw-regular) 11px/16px var(--f-sans); color: var(--fg-muted);
  border: 1px solid var(--divider); border-radius: 100px; padding: 1px 8px;
}

/* The inline "add" panels for a vendor and for a project. */
.add-panel {
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s-md); margin: var(--s-sm) 0 var(--s-lg);
  background: var(--surface);
}
.page-head { display: flex; align-items: flex-start; gap: var(--s-md); }
.page-head > div { flex: 1; }

/* A password shown once: made obvious, and obviously not repeatable. */
.credential-note {
  margin-top: var(--s-sm); padding: var(--s-md);
  border: 1px solid var(--accent-tint-2); background: var(--accent-tint); border-radius: var(--r-md);
}
.credential-note p { margin: 0 0 4px; }
.credential-note .cred { font: var(--fw-medium) 15px/24px var(--f-sans); }
.credential-note .mono { font-family: var(--f-mono, monospace); user-select: all; }

/* ---- Nodal officer and repository link (spec v11) ------------------------------------------- */
.nodal-grid { grid-template-columns: 1fr 1fr 1fr; gap: var(--s-sm); margin-bottom: 4px; }
@media (max-width: 900px) { .nodal-grid { grid-template-columns: 1fr; } }
.link-panel { display: flex; flex-direction: column; gap: var(--s-sm); margin-bottom: var(--s-lg); }
.link-state { margin: 0; font: var(--fw-regular) 13px/20px var(--f-sans); }
.link-state .ms { font-size: 16px; vertical-align: -3px; margin-right: 4px; color: var(--accent-fg); }
#link-select { max-width: 420px; }

/* Project lifecycle panel (ADR-31) */
.btn.outline.danger { color: var(--danger); border-color: var(--danger); }
#project-panel .field-grid { margin-top: var(--s-sm); }
#project-panel details > summary { cursor: pointer; margin: var(--s-md) 0 var(--s-sm); color: var(--fg-muted); }

/* CSV export / import (ADR-34) */
.page-actions { display: flex; gap: var(--s-sm); flex-wrap: wrap; align-items: center; }
.imp-wrap { overflow-x: auto; margin-top: var(--s-md); }
.import-preview { width: 100%; border-collapse: collapse; font-size: 12px; }
.import-preview th, .import-preview td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--divider); vertical-align: top; }
.import-preview th { color: var(--fg-muted); font-weight: var(--fw-medium); }

/* The administrator's vendor filter and vendor name on the row (ADR-35) */
.vendor-filter { max-width: 220px; }
.vendor-name { color: var(--accent-fg); }

/* Vendors page (ADR-36): the table scrolls inside its card rather than clipping, and the section heading breathes. */
#tab-vendors .class-actions + h3 { margin-top: var(--s-xl, 24px); }
#tab-vendors .tablewrap { overflow-x: auto; }
#tab-vendors table { width: 100%; min-width: 960px; }

/* Work orders page (ADR-37) */
.toolbar-row { display: flex; gap: var(--s-sm); align-items: center; flex-wrap: wrap; margin: var(--s-md) 0; }
.toolbar-row .input { max-width: 300px; }
#view-workorders .tablewrap { overflow-x: auto; }
#wo-table { width: 100%; min-width: 1100px; }
.wo-actions { white-space: nowrap; }
.wo-panel { margin-bottom: var(--s-md); }
/* The dashboard's table rules (sticky header, fixed layout, column-10 ellipsis) are for #repo-table; the work-orders table is an ordinary one. */
#wo-table { table-layout: auto; }
#wo-table thead th { position: static; }
#wo-table tbody td { overflow: visible; }
#wo-table tbody td:nth-child(10) { white-space: normal; text-overflow: clip; font-size: inherit; }
.toolbar-row .f-select { width: auto; max-width: 220px; }
#wo-table tbody td:nth-child(2), #wo-table tbody td:nth-child(7), #wo-table tbody td:nth-child(4) { white-space: nowrap; overflow-wrap: normal; }
