/* pcs-console. Same identity as the Command Centre: near-black control room, AI-Tomation red for identity only
   (mark, active route, focus, primary button), IBM Plex Sans + JetBrains Mono for figures. Data colours are the
   validated categorical set (validate_palette.js, both surfaces) and the fixed status set; red is never a series. */
:root {
  color-scheme: dark;
  --page: #0a0a0c; --card: #131317; --card-2: #1a1a20; --line: rgba(255,255,255,.08); --line-2: rgba(255,255,255,.14);
  --ink: #f2f2f5; --ink-2: #b9b9c4; --muted: #8b8b98; --grid: #24242b; --base: #3a3a44;
  --brand: #fc1617; --brand-fill: #e01415; --brand-deep: #c81011; --focus: #fc1617;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767; --s0: #6b6b75;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
  --good-ink: #3ccf3c; --warn-ink: #fab219; --crit-ink: #ff6b6b;
  --shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 8px 24px rgba(0,0,0,.35);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f4f4f2; --card: #ffffff; --card-2: #f7f7f5; --line: rgba(11,11,11,.09); --line-2: rgba(11,11,11,.16);
  --ink: #111114; --ink-2: #44444d; --muted: #63636e; --grid: #e6e5df; --base: #c3c2b7;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948; --s0: #a3a3ab;
  --good-ink: #006300; --warn-ink: #8a5a00; --crit-ink: #b42323;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 18px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --page: #f4f4f2; --card: #ffffff; --card-2: #f7f7f5; --line: rgba(11,11,11,.09); --line-2: rgba(11,11,11,.16);
    --ink: #111114; --ink-2: #44444d; --muted: #63636e; --grid: #e6e5df; --base: #c3c2b7;
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948; --s0: #a3a3ab;
    --good-ink: #006300; --warn-ink: #8a5a00; --crit-ink: #b42323;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 18px rgba(0,0,0,.05);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.55 var(--sans); }
a { color: inherit; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--brand); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }
code, .mono { font-family: var(--mono); font-size: .92em; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.thin { font-weight: 400; }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.pad { padding: 4px 0; }
.inline { display: inline; margin: 0; }

/* ---------------------------------------------------------------- top bar */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1320px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { display: block; }
.wm { font-weight: 700; letter-spacing: .02em; font-size: 15px; }
.wm b { color: var(--brand); font-weight: 800; }
.wm.big { font-size: 20px; }
.sep { width: 1px; height: 18px; background: var(--line-2); }
.prod { color: var(--ink-2); font-size: 14px; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-weight: 500; min-height: 40px; display: inline-flex; align-items: center; }
.nav a:hover { background: var(--card); color: var(--ink); }
.nav a.on { color: var(--ink); background: var(--card); box-shadow: inset 0 -2px 0 var(--brand); }
.nav a.ext::after { content: "\2197"; margin-left: 4px; color: var(--muted); font-size: 12px; }
.top-r { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.fresh { font-size: 13px; color: var(--muted); }
.icon-btn { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink-2); cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.icon-btn:hover { color: var(--ink); border-color: var(--line-2); }
.link-btn { background: none; border: 0; color: var(--ink-2); font: inherit; cursor: pointer; padding: 8px 4px; min-height: 40px; }
.link-btn:hover { color: var(--ink); text-decoration: underline; text-decoration-color: var(--brand); }

/* ---------------------------------------------------------------- layout */
.wrap { max-width: 1320px; margin: 0 auto; padding: 24px 16px 64px; display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.grid2, .charts2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.charts2 > div { min-width: 0; }
.crumb { margin: 0; font-size: 13px; color: var(--muted); }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap; padding: 8px 2px 4px; }
.hero > div:first-child { max-width: 760px; }
.hero p { margin: 6px 0 0; }
.hero-status { text-align: right; min-width: 240px; }
.hero-status .meter { margin-top: 8px; }
.eyebrow { margin: 0 0 6px !important; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--brand); }
.problems ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

/* ---------------------------------------------------------------- tiles */
.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.tile h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.tile p { margin: 6px 0 0; }
.big { font-size: 24px; font-weight: 600; line-height: 1.2; margin: 0; }
.big .st { font-size: 17px; }
.mid { font-size: 17px; font-weight: 600; }
.of { font-size: 13px; font-weight: 400; color: var(--muted); }

/* ---------------------------------------------------------------- status + pills + meters */
.st { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.st svg { width: 16px; height: 16px; flex: none; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.st-good { color: var(--good-ink); } .st-good svg { stroke: var(--good); }
.st-warn { color: var(--warn-ink); } .st-warn svg { stroke: var(--warn); }
.st-crit { color: var(--crit-ink); } .st-crit svg { stroke: var(--crit); }
.st-idle { color: var(--muted); } .st-idle svg { stroke: var(--muted); }
.pill { white-space: nowrap; overflow-wrap: normal; display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--line-2); color: var(--ink-2); vertical-align: 1px; }
.pill.warn { border-color: var(--warn); color: var(--warn-ink); }
.meter { display: block; height: 6px; border-radius: 99px; background: var(--grid); overflow: hidden; margin-top: 6px; min-width: 60px; }
.meter > span { display: block; height: 100%; border-radius: 99px; background: var(--s1); }
.meter.warn > span { background: var(--warn); }
.meter.crit > span { background: var(--crit); }
td .meter { max-width: 220px; }
.meter.share > span { background: var(--ink-2); opacity: .55; }
.pivot th.mono { text-transform: none; letter-spacing: 0; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tfoot th { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 14px; border-top: 1px solid var(--line-2); border-bottom: 0; }
tbody tr:hover { background: var(--card-2); }
.num { text-align: right; white-space: nowrap; }
.client-link { font-weight: 600; text-decoration: none; font-size: 15px; }
.client-link:hover { text-decoration: underline; text-decoration-color: var(--brand); }
.clients .site { display: flex; align-items: center; gap: 2px; white-space: nowrap; font-size: 13px; }
.clients .site .st svg { width: 14px; height: 14px; }
tr.sys td { background: color-mix(in srgb, var(--card-2) 60%, transparent); }
table.compact td, table.compact th { padding: 6px 8px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: 0; background: var(--s0); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; margin: 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; }
.sources { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.sources li > strong { margin-right: 8px; }

/* ---------------------------------------------------------------- series colours */
.s1 { --c: var(--s1); } .s2 { --c: var(--s2); } .s3 { --c: var(--s3); } .s4 { --c: var(--s4); }
.s5 { --c: var(--s5); } .s6 { --c: var(--s6); } .s7 { --c: var(--s7); } .s8 { --c: var(--s8); } .s0 { --c: var(--s0); }
.key.s1, .key.s2, .key.s3, .key.s4, .key.s5, .key.s6, .key.s7, .key.s8, .key.s0 { background: var(--c); }

/* ---------------------------------------------------------------- time charts */
.tchart { margin: 0; --c: var(--s1); }
.tchart.s3 { --c: var(--s3); }
.tplot { position: relative; height: 190px; margin-left: 56px; }
.tplot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.tplot .grid { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.tplot .base { stroke: var(--base); stroke-width: 1; vector-effect: non-scaling-stroke; }
.tplot .ref { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
.tplot .area { fill: var(--c); opacity: .14; }
.tplot .line { fill: none; stroke: var(--c); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.ylab { position: absolute; left: -56px; width: 50px; text-align: right; transform: translateY(50%); font: 11px var(--mono); color: var(--muted); }
.reflab { position: absolute; right: 0; transform: translateY(-2px); font-size: 11px; color: var(--warn-ink); background: var(--card); padding: 0 4px; }
.xaxis { position: relative; height: 22px; margin-left: 56px; }
.xlab { position: absolute; top: 6px; transform: translateX(-50%); font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.cross { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line-2); pointer-events: none; }
.dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--card); pointer-events: none; }
.tip { position: absolute; z-index: 5; pointer-events: none; background: var(--card-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 9px; font-size: 12px; white-space: nowrap; box-shadow: var(--shadow); }
.tip b { display: block; font: 600 13px var(--mono); }
.chart-empty { padding: 36px 8px; text-align: center; color: var(--muted); font-size: 14px; border: 1px dashed var(--line-2); border-radius: 10px; }

/* ---------------------------------------------------------------- stacked bars */
.bchart { margin: 0; position: relative; }
.bplot { position: relative; height: 240px; margin-left: 64px; }
.bplot .ylab { left: -64px; width: 58px; }
.bgrid { position: absolute; inset: 0; background: repeating-linear-gradient(to top, var(--base) 0 1px, transparent 1px 100%) bottom/100% 100% no-repeat,
  repeating-linear-gradient(to top, transparent 0 calc(25% - 1px), var(--grid) calc(25% - 1px) 25%); pointer-events: none; }
.bcols { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); align-items: end; gap: 2px; }
.bcol { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.bar { width: min(28px, 78%); display: flex; flex-direction: column-reverse; gap: 2px; min-height: 2px; }
.seg { display: block; background: var(--c); min-height: 2px; cursor: default; }
.bar .seg:last-child { border-radius: 4px 4px 0 0; }
.seg:hover { filter: brightness(1.15); }
.blab { position: absolute; top: 100%; margin-top: 6px; font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.bchart { padding-bottom: 26px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; }

/* ---------------------------------------------------------------- controls */
.seg-ctl { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; }
.seg-ctl a { padding: 7px 12px; border-radius: 7px; text-decoration: none; color: var(--ink-2); font-size: 14px; font-weight: 500; min-height: 36px; display: inline-flex; align-items: center; }
.seg-ctl a:hover { color: var(--ink); background: var(--card); }
.seg-ctl a.on { background: var(--card); color: var(--ink); box-shadow: inset 0 -2px 0 var(--brand), 0 1px 3px rgba(0,0,0,.2); }
.seg-ctl.small a { padding: 5px 10px; font-size: 13px; min-height: 32px; }
.filters { display: grid; gap: 14px; }
.fields { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.fields label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
input, select { font: 15px var(--sans); color: var(--ink); background: var(--card-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; min-height: 40px; min-width: 0; }
select { padding-right: 28px; }
input:focus, select:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--card-2); color: var(--ink); font: 600 14px var(--sans); cursor: pointer; text-decoration: none; transition: background-color .15s, border-color .15s; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--brand-fill); border-color: var(--brand-fill); color: #fff; }
.btn.primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); }
.btn.ghost { background: transparent; }

/* ---------------------------------------------------------------- sign in */
.login { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: min(420px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-brand { display: flex; gap: 12px; align-items: center; }
.login h1 { font-size: 22px; }
.login p { margin: 0; }
.stack { display: grid; gap: 8px; }
.stack label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.stack .btn { margin-top: 10px; }
.alert { margin: 0; padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--crit) 12%, transparent); border: 1px solid color-mix(in srgb, var(--crit) 40%, transparent); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .grid2, .charts2 { grid-template-columns: minmax(0, 1fr); }
  .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-status { text-align: left; }
  .top-r { margin-left: 0; width: 100%; justify-content: space-between; }
  .prod, .sep { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tiles.four { gap: 10px; }
  .tile { padding: 12px; }
  .big { font-size: 20px; }
  .card { padding: 14px; }
  h1 { font-size: 22px; }
  /* tables become stacked cards: each cell carries its own heading */
  .table-wrap { overflow: visible; margin: 0; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
  /* the label sits in a fixed left gutter, so a cell with several children (sites, a link + a pill) stays in one column */
  td { border: 0; padding: 4px 0 4px 128px; position: relative; min-height: 28px; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  td::before { content: attr(data-label); position: absolute; left: 0; top: 6px; width: 120px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
  .clients .site { white-space: normal; }
  .blab.alt { display: none; }
  td.num { text-align: left; }
  tfoot { display: block; }
  tfoot tr { display: flex; flex-wrap: wrap; gap: 6px 14px; }
  tfoot th { padding: 4px 0; border: 0; }
  tfoot th:empty { display: none; }
  .fields label { flex: 1 1 140px; }
  .fields select, .fields input { width: 100%; }
  .bplot { height: 200px; margin-left: 52px; }
  .bplot .ylab { left: -52px; width: 48px; }
  .tplot, .xaxis { margin-left: 46px; }
  .tplot .ylab { left: -46px; width: 42px; }
  .facts { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .facts dd { margin-bottom: 10px; }
  .hero-status { min-width: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (forced-colors: active) { .seg, .meter > span, .key { forced-color-adjust: none; } }
