/* SiteAudit — the manager dashboard.
   Palette: validated data-viz reference instance. Categorical slots carry
   identity; the reserved status palette carries quality and is always paired
   with a label, never colour alone. */

:root {
  --surface-0:#f5f6f8; --surface-1:#ffffff; --surface-2:#fafbfc;
  --ink-1:#12161f; --ink-2:#4c5566; --ink-3:#8b94a5;
  --line:#e4e8ee; --line-soft:#eef1f5;

  --series-1:#2a78d6; --series-2:#eb6834; --series-3:#1baf7a; --series-4:#eda100;
  --series-5:#e87ba4; --series-7:#4a3aa7;

  --good:#0ca30c; --warning:#fab219; --serious:#ec835a; --critical:#d03b3b;
  --neutral:#9aa3b2;

  --nav-bg:#141a26; --nav-bg-2:#1d2534; --nav-ink:#c2cad8; --nav-ink-dim:#7d8798;

  /* Each portal keeps its own identity by overriding these four and nothing else.
     The glows are separate variables because a focus ring and an active-tab shadow
     need the accent at low alpha, and CSS cannot derive that from a hex value. */
  --accent:#d97535; --accent-2:#f0a35f;
  --accent-glow:rgba(217,117,53,.16); --accent-shadow:rgba(217,117,53,.35);

  --radius:14px; --radius-sm:9px;
  --shadow-sm:0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.04);
  --shadow-md:0 4px 14px rgba(16,24,40,.07), 0 2px 5px rgba(16,24,40,.04);
  --shadow-lg:0 18px 40px rgba(16,24,40,.12);
}

:root[data-theme="dark"] {
  --surface-0:#0f131b; --surface-1:#171d28; --surface-2:#1b2230;
  --ink-1:#f2f5f9; --ink-2:#aab3c2; --ink-3:#7a8496;
  --line:#28303e; --line-soft:#222a37;
  --series-1:#3987e5; --series-2:#d95926; --series-3:#199e70; --series-4:#c98500;
  --series-5:#d55181; --series-7:#9085e9;
  --nav-bg:#0b0f16; --nav-bg-2:#141a26;
  --shadow-sm:0 1px 2px rgba(0,0,0,.4);
  --shadow-md:0 4px 14px rgba(0,0,0,.45);
  --shadow-lg:0 18px 40px rgba(0,0,0,.55);
}

* { box-sizing:border-box; }
html, body { height:100%; }
body {
  margin:0; background:var(--surface-0); color:var(--ink-1);
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
  font-size:14px; line-height:1.5; -webkit-font-smoothing:antialiased;
}
.hide { display:none !important; }
a { color:inherit; }

/* ------------------------------- login -------------------------------- */
.login-wrap {
  min-height:100vh; display:grid; place-items:center; padding:24px;
  background:
    radial-gradient(1100px 500px at 12% -10%, var(--accent-shadow), transparent 60%),
    radial-gradient(900px 460px at 92% 8%, rgba(42,120,214,.26), transparent 62%),
    linear-gradient(160deg,#0d121b 0%,#161d2b 55%,#0d121b 100%);
}
.login-card {
  width:100%; max-width:400px; background:var(--surface-1); border-radius:18px;
  padding:32px 30px; box-shadow:var(--shadow-lg);
}
.login-card .logo { font-size:24px; font-weight:800; letter-spacing:-.4px; }
.logo span { color:var(--accent); }
.portal-tag {
  display:inline-block; margin:8px 0 20px; font-size:11px; font-weight:700;
  letter-spacing:.8px; text-transform:uppercase; color:var(--accent);
  background:var(--accent-glow); padding:5px 11px; border-radius:20px;
}
label { display:block; font-size:12.5px; font-weight:600; color:var(--ink-2); margin:14px 0 6px; }
input, select {
  width:100%; padding:11px 13px; border:1px solid var(--line); border-radius:var(--radius-sm);
  font:inherit; background:var(--surface-1); color:var(--ink-1); transition:border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline:none; border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-glow);
}

.btn {
  background:var(--accent); color:#fff; border:0; padding:11px 20px; border-radius:var(--radius-sm);
  font:inherit; font-weight:650; cursor:pointer; transition:filter .15s, transform .05s;
}
.btn:hover { filter:brightness(1.06); }
.btn:active { transform:translateY(1px); }
.btn:disabled { opacity:.55; cursor:not-allowed; }
.btn.sec { background:var(--surface-1); color:var(--ink-1); border:1px solid var(--line); }
.btn.sm { padding:7px 13px; font-size:12.5px; }
.btn.block { width:100%; }

/* Destructive actions. Deliberately not the same weight as a primary button — this
   is the only control in the console that destroys inspection history. */
.btn.danger {
  background:transparent; color:#c0392b;
  border:1px solid rgba(192,57,43,.35);
}
.btn.danger:hover { background:rgba(192,57,43,.10); border-color:rgba(192,57,43,.55); }
.btn.danger:disabled { opacity:.5; cursor:not-allowed; }

.alert { display:none; padding:11px 13px; border-radius:var(--radius-sm); font-size:13px; margin:10px 0; }
.alert.show { display:block; }
.alert.err { background:rgba(208,59,59,.10); color:#a52c2c; border:1px solid rgba(208,59,59,.28); }
.alert.ok  { background:rgba(12,163,12,.10); color:#0a7d0a; border:1px solid rgba(12,163,12,.28); }
.switcher { margin-top:20px; text-align:center; font-size:12px; color:var(--ink-3); }
.switcher a { color:var(--accent); text-decoration:none; margin:0 5px; font-weight:600; }

/* ------------------------------- shell -------------------------------- */
.shell { display:grid; grid-template-columns:236px 1fr; min-height:100vh; }

.sidebar {
  background:linear-gradient(180deg,var(--nav-bg) 0%,var(--nav-bg-2) 100%);
  color:var(--nav-ink); padding:20px 14px; position:sticky; top:0; height:100vh;
  display:flex; flex-direction:column; gap:6px;
}
.sidebar .brand { font-size:19px; font-weight:800; color:#fff; padding:4px 10px 2px; letter-spacing:-.3px; }
.sidebar .brand-sub {
  font-size:10.5px; letter-spacing:.9px; text-transform:uppercase;
  color:var(--accent-2); padding:0 10px 18px; font-weight:700;
}
.sidebar nav { display:flex; flex-direction:column; gap:3px; }
.sidebar nav button {
  display:flex; align-items:center; gap:11px; width:100%; text-align:left;
  background:transparent; border:0; color:var(--nav-ink); font:inherit; font-weight:550;
  padding:10px 11px; border-radius:10px; cursor:pointer; transition:background .15s, color .15s;
}
.sidebar nav button:hover { background:rgba(255,255,255,.07); color:#fff; }
.sidebar nav button.active { background:var(--accent); color:#fff; box-shadow:0 4px 12px var(--accent-shadow); }
.sidebar nav button svg { width:17px; height:17px; flex:none; opacity:.9; }
.sidebar .count {
  margin-left:auto; background:var(--critical); color:#fff; font-size:10.5px; font-weight:700;
  border-radius:20px; padding:1px 7px; min-width:19px; text-align:center;
}
.sidebar nav button.active .count { background:rgba(0,0,0,.28); }
.side-foot { margin-top:auto; border-top:1px solid rgba(255,255,255,.10); padding-top:14px; }
.side-user { display:flex; align-items:center; gap:10px; padding:0 6px 12px; }
.avatar {
  width:34px; height:34px; border-radius:50%; flex:none; display:grid; place-items:center;
  background:linear-gradient(135deg,var(--accent),var(--accent-2)); color:#fff; font-weight:700; font-size:13px;
}
.side-user b { color:#fff; font-size:13px; display:block; line-height:1.25; }
.side-user span { font-size:11px; color:var(--nav-ink-dim); }

.main { min-width:0; }
.topbar {
  display:flex; align-items:center; gap:14px; padding:16px 26px;
  background:var(--surface-1); border-bottom:1px solid var(--line); position:sticky; top:0; z-index:20;
}
.topbar h1 { font-size:19px; margin:0; font-weight:700; letter-spacing:-.3px; }
.topbar .crumb { font-size:12.5px; color:var(--ink-3); }
.topbar .spacer { margin-left:auto; }
.icon-btn {
  background:var(--surface-2); border:1px solid var(--line); color:var(--ink-2);
  width:36px; height:36px; border-radius:9px; display:grid; place-items:center; cursor:pointer;
}
.icon-btn:hover { color:var(--ink-1); border-color:var(--ink-3); }
.icon-btn svg { width:17px; height:17px; }

.page { padding:24px 26px 60px; max-width:1440px; }
.view { display:none; }
.view.active { display:block; animation:fade .22s ease; }
@keyframes fade { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:none; } }

/* ------------------------------- cards -------------------------------- */
.card {
  background:var(--surface-1); border:1px solid var(--line); border-radius:var(--radius);
  padding:18px 20px; box-shadow:var(--shadow-sm);
}
.card.tight { padding:0; overflow:hidden; }
.card-head { display:flex; align-items:center; gap:10px; margin-bottom:14px; }
.card-head h3 { margin:0; font-size:14.5px; font-weight:680; }
.card-head .sub { font-size:12px; color:var(--ink-3); }
.card-head .spacer { margin-left:auto; }

.grid { display:grid; gap:16px; align-items:start; }
.g-2 { grid-template-columns:repeat(2,1fr); }
.g-3 { grid-template-columns:repeat(3,1fr); }
.g-2-1 { grid-template-columns:2fr 1fr; }
@media (max-width:1180px) { .g-2-1, .g-2, .g-3 { grid-template-columns:1fr; } }

/* ------------------------------ KPI tiles ------------------------------ */
.kpi-row { display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:14px; margin-bottom:18px; }
.kpi {
  position:relative; overflow:hidden; border-radius:var(--radius); padding:16px 17px;
  background:var(--surface-1); border:1px solid var(--line); box-shadow:var(--shadow-sm);
  transition:transform .16s, box-shadow .16s;
}
.kpi:hover { transform:translateY(-2px); box-shadow:var(--shadow-md); }
.kpi::after {
  content:''; position:absolute; inset:0 0 auto 0; height:3px; background:var(--k, var(--series-1));
}
.kpi .kpi-top { display:flex; align-items:center; gap:9px; margin-bottom:9px; }
.kpi .kpi-ico {
  width:30px; height:30px; border-radius:9px; display:grid; place-items:center;
  background:color-mix(in srgb, var(--k, var(--series-1)) 14%, transparent); color:var(--k, var(--series-1));
}
.kpi .kpi-ico svg { width:16px; height:16px; }
.kpi .kpi-label { font-size:11.5px; font-weight:650; letter-spacing:.4px; text-transform:uppercase; color:var(--ink-3); }
.kpi .kpi-val { font-size:29px; font-weight:750; letter-spacing:-1px; line-height:1.05; }
.kpi .kpi-foot { display:flex; align-items:center; gap:8px; margin-top:7px; font-size:12px; color:var(--ink-3); }
.kpi .spark { color:var(--k, var(--series-1)); opacity:.85; margin-left:auto; }

.hero {
  border-radius:var(--radius); padding:22px 24px; margin-bottom:18px; color:#fff; position:relative; overflow:hidden;
  background:
    radial-gradient(700px 220px at 88% -30%, rgba(240,163,95,.50), transparent 65%),
    linear-gradient(120deg,#1d2534 0%,#243044 58%,#1a2230 100%);
  box-shadow:var(--shadow-md);
}
.hero h2 { margin:0 0 5px; font-size:20px; font-weight:720; letter-spacing:-.3px; }
.hero p { margin:0; color:#b9c3d4; font-size:13px; max-width:620px; }
.hero .hero-stats { display:flex; gap:26px; margin-top:16px; flex-wrap:wrap; }
.hero .hs b { display:block; font-size:22px; font-weight:750; letter-spacing:-.5px; }
.hero .hs span { font-size:11.5px; color:#9fabbf; letter-spacing:.4px; text-transform:uppercase; }

/* ------------------------------- tables -------------------------------- */
table { width:100%; border-collapse:collapse; font-size:13px; }
thead th {
  text-align:left; font-size:10.5px; letter-spacing:.6px; text-transform:uppercase;
  color:var(--ink-3); font-weight:700; padding:11px 14px;
  background:var(--surface-2); border-bottom:1px solid var(--line);
}
tbody td { padding:12px 14px; border-bottom:1px solid var(--line-soft); vertical-align:middle; }
tbody tr:last-child td { border-bottom:0; }
tbody tr { transition:background .12s; }
tbody tr:hover { background:var(--surface-2); }
th.num, td.num { text-align:right; }
th.c, td.c { text-align:center; }
.muted { color:var(--ink-3); }
.empty, .loading { text-align:center; color:var(--ink-3); padding:26px; font-style:italic; }

.chip {
  display:inline-flex; align-items:center; gap:5px; padding:3px 9px; border-radius:20px;
  font-size:11.5px; font-weight:650; white-space:nowrap;
}
.chip i { width:7px; height:7px; border-radius:50%; background:currentColor; flex:none; }
.c-good { background:rgba(12,163,12,.12); color:#0a7d0a; }
.c-acceptable { background:rgba(250,178,25,.16); color:#8a6100; }
.c-not_satisfied { background:rgba(208,59,59,.12); color:#a52c2c; }
.c-warn { background:rgba(250,178,25,.16); color:#8a6100; }
.c-info { background:rgba(42,120,214,.12); color:#1f5da8; }
.c-crit { background:rgba(208,59,59,.12); color:#a52c2c; }
.c-na   { background:rgba(154,163,178,.16); color:#5f6878; }
.c-acc  { background:rgba(235,104,52,.12); color:#b04a1e; }

.score { font-weight:750; font-size:12.5px; padding:3px 9px; border-radius:7px; display:inline-block; }
.s-pass { background:rgba(12,163,12,.12); color:#0a7d0a; }
.s-warn { background:rgba(250,178,25,.18); color:#8a6100; }
.s-fail { background:rgba(208,59,59,.12); color:#a52c2c; }

.meter { height:6px; border-radius:6px; background:var(--line-soft); overflow:hidden; min-width:70px; }
.meter i { display:block; height:100%; border-radius:6px; }

/* ------------------------------ activity ------------------------------- */
.feed { display:flex; flex-direction:column; }
.feed-item { display:flex; gap:12px; padding:11px 0; border-bottom:1px solid var(--line-soft); }
.feed-item:last-child { border-bottom:0; }
.feed-dot {
  width:30px; height:30px; border-radius:9px; flex:none; display:grid; place-items:center;
  background:var(--surface-2); color:var(--ink-2);
}
.feed-dot svg { width:15px; height:15px; }
.feed-body { min-width:0; flex:1; }
.feed-body b { font-weight:650; }
.feed-body .when { font-size:11.5px; color:var(--ink-3); }

/* -------------------------------- viz ---------------------------------- */
.viz { display:block; overflow:visible; }
.viz-grid { stroke:var(--line-soft); stroke-width:1; }
.viz-axis { fill:var(--ink-3); font-size:10.5px; font-family:inherit; }
.viz-crosshair { stroke:var(--ink-3); stroke-width:1; stroke-dasharray:3 3; }
.viz-empty { text-align:center; color:var(--ink-3); padding:34px 10px; font-style:italic; font-size:13px; }

.viz-tip {
  position:fixed; z-index:999; pointer-events:none; opacity:0; transform:translateY(3px);
  transition:opacity .12s, transform .12s; background:var(--nav-bg); color:#fff;
  padding:8px 11px; border-radius:8px; font-size:12px; line-height:1.45; box-shadow:var(--shadow-lg); max-width:230px;
}
.viz-tip.show { opacity:1; transform:none; }

.viz-bars { display:flex; flex-direction:column; gap:11px; }
.viz-bar-row { display:grid; grid-template-columns:1fr 2fr auto; gap:12px; align-items:center; cursor:default; }
.viz-bar-label { font-size:12.5px; color:var(--ink-2); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.viz-bar-track { background:var(--line-soft); border-radius:6px; height:9px; overflow:hidden; }
.viz-bar-fill { height:100%; border-radius:6px; transition:width .5s cubic-bezier(.3,.9,.4,1); }
.viz-bar-value { font-size:12.5px; font-weight:700; min-width:46px; text-align:right; }

.viz-stack { display:flex; height:26px; border-radius:7px; overflow:hidden; background:var(--line-soft); gap:2px; }
.viz-stack-seg {
  display:grid; place-items:center; color:#fff; font-size:11px; font-weight:700;
  transition:filter .15s; cursor:default; min-width:3px;
}
.viz-stack-seg:hover { filter:brightness(1.1); }
.viz-legend { display:flex; flex-wrap:wrap; gap:12px; margin-top:11px; font-size:12px; color:var(--ink-2); }
.viz-legend.col { flex-direction:column; gap:8px; margin-top:0; }
.viz-legend i { display:inline-block; width:9px; height:9px; border-radius:3px; margin-right:6px; vertical-align:baseline; }
.viz-legend b { color:var(--ink-1); }

.viz-donut-wrap { display:flex; align-items:center; gap:22px; flex-wrap:wrap; }
.viz-donut-num { fill:var(--ink-1); font-size:26px; font-weight:750; font-family:inherit; }
.viz-donut-cap { fill:var(--ink-3); font-size:10.5px; letter-spacing:.5px; font-family:inherit; text-transform:uppercase; }

.spinner {
  display:inline-block; width:13px; height:13px; border:2px solid rgba(255,255,255,.35);
  border-top-color:#fff; border-radius:50%; animation:spin .7s linear infinite; vertical-align:-2px;
}
@keyframes spin { to { transform:rotate(360deg); } }

.row { display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:14px; }

/* ------------------------------- drawer ---------------------------------- */
/* Detail panel that slides in from the right. Used for editing a site and for
   opening an inspection — both are "look at one record without losing the list",
   which is exactly what a drawer is for and what a modal is not. */
.drawer {
  position:fixed; inset:0; z-index:60; display:none;
  background:rgba(9,13,20,.45); backdrop-filter:blur(2px);
}
.drawer.show { display:block; }
.drawer-panel {
  position:absolute; top:0; right:0; height:100%; width:min(680px,100%);
  background:var(--surface-1); box-shadow:var(--shadow-lg);
  display:flex; flex-direction:column; animation:drawerIn .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes drawerIn { from { transform:translateX(24px); opacity:.4; } to { transform:none; opacity:1; } }
.drawer-head {
  display:flex; align-items:flex-start; gap:12px;
  padding:18px 22px; border-bottom:1px solid var(--line);
}
.drawer-head h3 { margin:0; font-size:16px; color:var(--ink-1); }
.drawer-head .sub { display:block; margin-top:3px; font-size:12px; color:var(--ink-3); }
.drawer-head .x {
  margin-left:auto; background:none; border:0; cursor:pointer; padding:4px 8px;
  font-size:22px; line-height:1; color:var(--ink-3); border-radius:var(--radius-sm);
}
.drawer-head .x:hover { background:var(--surface-0); color:var(--ink-1); }
.drawer-body { flex:1; overflow-y:auto; padding:20px 22px; }
.drawer-foot {
  display:flex; gap:10px; align-items:center;
  padding:14px 22px; border-top:1px solid var(--line); background:var(--surface-2);
}

/* key/value pairs in a detail panel */
.kv { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:14px 18px; margin-bottom:18px; }
.kv > div > span { display:block; font-size:10.5px; letter-spacing:.4px; text-transform:uppercase; color:var(--ink-3); margin-bottom:3px; }
.kv > div > b { font-size:13.5px; color:var(--ink-1); font-weight:650; }

/* one checklist line inside an inspection */
.item { display:flex; gap:12px; padding:11px 0; border-top:1px solid var(--line-soft); }
.item:first-child { border-top:0; }
.item-main { flex:1; min-width:0; }
.item-q { font-size:13px; color:var(--ink-1); line-height:1.45; }
.item-note { margin-top:4px; font-size:12px; color:var(--ink-2); font-style:italic; }
.area-block { margin-bottom:20px; }
.area-head { display:flex; align-items:center; gap:10px; margin-bottom:6px; }
.area-head b { font-size:13.5px; color:var(--ink-1); }

/* event trail */
.trail { list-style:none; margin:0; padding:0; }
.trail li { position:relative; padding:0 0 14px 20px; border-left:2px solid var(--line); }
.trail li:last-child { border-left-color:transparent; padding-bottom:0; }
.trail li::before {
  content:''; position:absolute; left:-6px; top:3px; width:10px; height:10px;
  border-radius:50%; background:var(--series-1); box-shadow:0 0 0 3px var(--surface-1);
}
.trail .t-when { font-size:11.5px; color:var(--ink-3); }
.trail .t-what { font-size:13px; color:var(--ink-1); }

/* evidence thumbnails + lightbox (console.css is standalone — app.css is not loaded here) */
.thumb {
  width:58px; height:44px; object-fit:cover; border-radius:var(--radius-sm);
  border:1px solid var(--line); cursor:zoom-in; background:var(--surface-0);
}
.thumb:hover { border-color:var(--accent); }
/* Filled in by loadPhotos(); until then a quiet placeholder, not a broken-image icon. */
img[data-photo]:not([src]) { background:var(--surface-2, #eef0f4); color:transparent; }
img.missing { color:var(--ink-3); font-size:11px; }
.lightbox { position:fixed; inset:0; z-index:80; display:none; place-items:center; background:rgba(9,13,20,.82); }
.lightbox.show { display:grid; }
.lightbox img { max-width:92vw; max-height:88vh; border-radius:var(--radius); box-shadow:var(--shadow-lg); }
.lightbox .x { position:absolute; top:18px; right:22px; background:none; border:0; color:#fff; font-size:34px; cursor:pointer; }

/* filter bar above a table */
.filters { display:flex; flex-wrap:wrap; gap:10px; align-items:flex-end; margin-bottom:14px; }
.filters > div { display:flex; flex-direction:column; gap:4px; }
.filters label { font-size:10.5px; letter-spacing:.4px; text-transform:uppercase; color:var(--ink-3); }
.filters select, .filters input { min-width:150px; }
.filters .grow { margin-left:auto; }
.filter-count { font-size:12px; color:var(--ink-3); align-self:center; }

/* rows that open something */
tr.rowlink { cursor:pointer; }
tr.rowlink:hover td { background:var(--surface-2); }
tr.selected td { background:var(--accent-glow); }

/* --------------------------- provider branding --------------------------- */
/* A company's own logo in place of the wordmark, in their own console only.
   Contained rather than sized, because logos arrive square, wide and everything
   between, and a stretched client logo is worse than none. */
/*
 * A company's logo in the sidebar.
 *
 * Two kinds arrive and they need opposite treatment.
 *
 * Most are artwork on transparency, usually dark. On a dark sidebar those vanish, so
 * they get a white plate — the default below.
 *
 * Some are a finished lockup with their own background baked in: white type on the
 * company's own navy, say. Putting one of those on a white plate produces a coloured
 * rectangle inside a white rectangle, which looks like a mistake because it is one.
 * Those get `.own-bg` (set by fitBrandLogo, which reads the corner pixels) and are
 * shown edge to edge, letting their own background be the card.
 */
.brand-logo {
  display:block; box-sizing:border-box;
  width:calc(100% - 24px); max-height:58px;
  object-fit:contain; object-position:center;
  margin:2px 12px 14px; padding:11px 13px;
  background:#fff; border-radius:10px;
  box-shadow:0 1px 3px rgba(0,0,0,.16);
}

/* Carries its own background: no plate, no padding, nothing added around it. */
.brand-logo.own-bg {
  padding:0;
  background:none;
  box-shadow:none;
  max-height:64px;
  object-fit:cover;
  border-radius:8px;
}

/* ---------------------------- internal links ----------------------------- */
/* A cross-reference to something you can open. Underlined on hover rather than
   always, so a table of them doesn't turn into a wall of blue. */
.ilink {
  color:var(--accent); text-decoration:none; font-weight:600; cursor:pointer;
  border-radius:3px;
}
.ilink:hover { text-decoration:underline; }
.ilink:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
.feed-body .ilink { font-weight:700; }

/* KPI tiles and chart bars that stand for a filtered list */
.kpi.clickable, .viz-bar-row.clickable { cursor:pointer; }
.kpi.clickable:hover { transform:translateY(-2px); box-shadow:var(--shadow-md); }
.kpi.clickable:focus-visible, .viz-bar-row.clickable:focus-visible {
  outline:2px solid var(--accent); outline-offset:2px;
}
.viz-bar-row.clickable:hover .viz-bar-label { color:var(--accent); }
.viz-bar-row.clickable:hover .viz-bar-fill { filter:brightness(1.08); }

@media (max-width:900px) {
  /*
   * min-width:0 is what actually lets these shrink.
   *
   * A grid item defaults to min-width:auto, meaning it refuses to go narrower than its
   * own content. The nav shrank as told and the sidebar still measured 1012px inside a
   * 753px screen, pushing Sign out off the edge — the track would not narrow, so
   * nothing inside it could.
   */
  .shell { grid-template-columns:1fr; }
  .shell > * { min-width:0; }
  .sidebar {
    position:sticky; top:0; z-index:30; height:auto;
    flex-direction:row; align-items:center; gap:10px;
    padding:10px 12px; overflow:visible;
  }
  /*
   * The nav is the scroller, not the sidebar.
   *
   * When the whole bar scrolled, the account block sat past the end of it — so Sign
   * out was off-screen until you swiped the navigation sideways, which nobody thinks
   * to do. Scrolling only the buttons keeps it pinned and always reachable.
   */
  .sidebar nav {
    flex:1 1 auto; min-width:0;
    flex-direction:row; gap:4px;
    overflow-x:auto; -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
  }
  .sidebar nav::-webkit-scrollbar { display:none; }
  .sidebar nav button { padding:8px 10px; white-space:nowrap; }
  .sidebar .brand-sub { display:none; }
  .brand-logo { display:none; }

  /*
   * The account block stays.
   *
   * It used to be hidden here along with the subtitle, which took Sign out and Change
   * password with it — so on a phone there was no way to leave the account you were
   * signed into. It becomes a compact strip on the end of the nav bar instead.
   */
  .side-foot {
    margin-top:0; margin-left:auto; border-top:0; padding-top:0;
    display:flex; align-items:center; gap:6px; flex:none;
  }
  .side-user { padding:0; }
  .side-user > div:not(.avatar) { display:none; }   /* the avatar is enough */
  .side-foot .btn.block { width:auto; margin-bottom:0 !important; white-space:nowrap; }

  .page { padding:16px; }
  .drawer-panel { width:100%; }
  .filters .grow { margin-left:0; }
}

/* ------------------------------ narrow phones ----------------------------- */
/*
 * On a 375px screen the bar cannot hold a wordmark, the navigation and a full account
 * block: measured, the wordmark took 105px, the account block 255px, and the nav was
 * squeezed to nothing — the navigation was invisible.
 *
 * The wordmark and avatar go first. The page header already names where you are, and
 * being able to move around matters more than being reminded whose portal it is.
 */
@media (max-width:560px) {
  .sidebar .brand { display:none; }
  .side-foot .avatar { display:none; }
  .side-foot .side-user { display:none; }
  .side-foot .btn.block {
    padding:7px 9px; font-size:11.5px;
  }
  .page { padding:12px; }
  .filters { gap:8px; }
}

/* --------------------------- tables on a phone ---------------------------- */
/*
 * Below this width a row becomes a card — the same 900px at which the sidebar
 * collapses, so there is one definition of "small screen" rather than two that
 * disagree between 720 and 900 and leave a table clipped in the gap.
 *
 * These tables run to nine columns and 840px. On a 375px screen that was not merely
 * cramped: the container clipped at `overflow:hidden`, so more than half of every row
 * — the score, the stage, the buttons — was unreachable with no scrollbar to suggest
 * anything was missing.
 *
 * Each cell carries its column heading in `data-label`, stamped by
 * enableResponsiveTables() in console.js from the table's own <thead>, so this works
 * for tables that do not exist yet and needs no change to any markup.
 */
@media (max-width:900px) {
  .card.tight { overflow:visible; }

  table thead { display:none; }
  table, table tbody, table tr, table td { display:block; width:auto; }

  table tbody tr {
    border:1px solid var(--line); border-radius:var(--radius-sm);
    padding:10px 12px; margin:0 0 10px;
    background:var(--surface-1);
  }
  table tbody tr:last-child { margin-bottom:0; }

  table tbody td {
    display:flex; align-items:center; gap:12px;
    padding:5px 0; border:0; text-align:left !important;
  }
  /* The heading this cell came from, so a value is never left unlabelled. */
  table tbody td::before {
    content:attr(data-label);
    flex:0 0 40%; min-width:0;
    font-size:11px; font-weight:650; letter-spacing:.2px;
    text-transform:uppercase; color:var(--ink-3);
  }
  table tbody td:empty { display:none; }
  /* A cell with no heading — the actions column — spans the card instead. */
  table tbody td[data-label=""]::before { display:none; }
  table tbody td[data-label=""] { justify-content:flex-end; gap:6px; padding-top:9px; }

  /* An empty-state row is a sentence, not a record. */
  table tbody tr:has(td[colspan]) { border:0; background:none; padding:0; }
  table tbody td[colspan]::before { display:none; }
  table tbody td[colspan] { justify-content:center; }

  .kpi-row, .grid { gap:12px; }
  .drawer-panel { padding:16px; }
}
