/*
   Kimio.ControlCentre — the Super Admin control centre (ADMIN1 #1006). This ports the design system from the
   ADR's console mock (docs/design/ui/mockups/control-centre-mock.html): a utilitarian, ERD-mirroring operations
   tool — a left rail, a top bar with an environment chip, chip-styled tables, and a card-grid drill-in.
   Theme-aware (light/dark) off shared tokens, so the viewer's OS/theme toggle both work.

   Why this is a GLOBAL stylesheet rather than colocated per-component (.razor.css), per the Blazor CSS-isolation
   rule's "global styles require explicit justification":
     • It is a single, cohesive DESIGN SYSTEM — the tokens (:root), resets, and reused primitives (.btn, .chip,
       .card, tables, .field, .notice, .kv, .rolechip) are shared VERBATIM by every page (Users, UserDetail,
       Tariffs, SignIn). CSS isolation would fragment one primitive into a per-component copy (or force
       ::deep), which is worse for a design system than one shared sheet.
     • The rail's "soon" items are built programmatically (MainLayout.SoonItem via RenderTreeBuilder), so the
       Razor compiler never stamps them with a component scope attribute — scoped .razor.css selectors would
       silently fail to match them. The shell must therefore be styled globally to render correctly.
   Component-private, non-shared styling would still be colocated; nothing here qualifies.
*/

:root {
    --ground: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --ink: #1b2430;
    --ink-2: #59636e;
    --ink-3: #8a929c;
    --line: #e2e6eb;
    --line-2: #cfd5dd;
    --accent: #3b5bdb;
    --accent-soft: #e8ecfb;
    --good: #2f9e44;
    --good-soft: #e6f4ea;
    --warn: #e8830c;
    --warn-soft: #fbefdc;
    --crit: #e03131;
    --crit-soft: #fbe4e4;
    --inert: #868e96;
    --inert-soft: #eceef1;
    --kimio-orange-soft: #FFF3EC;
    /* TEXT weights of the two chip colours. The fill tokens above are tuned to be soft, so the matching
       full-strength colour on top of them lands near 3:1 — under the 4.5:1 WCAG 1.4.3 asks of the 12px
       600-weight chip text. These are the same hues carried to a legible weight, per theme, so the chip
       keeps its colour language and only its text darkens. */
    --kimio-orange-ink: #A32E05;
    --warn-ink: #7A5A0F;
    --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --radius: 5px;
    --shadow: 0 1px 2px rgba(20, 30, 45, 0.06), 0 1px 1px rgba(20, 30, 45, 0.04);
    /* Tell the browser the page's theme so NATIVE controls (the date picker's calendar indicator, the status
       <select>, scrollbars) render theme-correct — without it the calendar icon is dark-on-dark and invisible. */
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --ground: #0e1116; --panel: #161b22; --panel-2: #1c222b; --ink: #e6edf3;
        --ink-2: #9aa4af; --ink-3: #6b7684; --line: #262d37; --line-2: #333c48;
        --accent: #6b8afd; --accent-soft: #1b2540; --good: #4ac26b; --good-soft: #14271a;
        --warn: #f0a53a; --warn-soft: #2c2110; --crit: #f2666a; --crit-soft: #2c1416;
        --inert: #7d8590; --inert-soft: #20262f;
        --kimio-orange-soft: #2e1a10;
        --kimio-orange-ink: #FF9A5E; --warn-ink: #f0a53a;
        color-scheme: dark;
    }
}

:root[data-theme="light"] {
    --ground: #f6f7f9; --panel: #ffffff; --panel-2: #f0f2f5; --ink: #1b2430;
    --ink-2: #59636e; --ink-3: #8a929c; --line: #e2e6eb; --line-2: #cfd5dd;
    --accent: #3b5bdb; --accent-soft: #e8ecfb; --good: #2f9e44; --good-soft: #e6f4ea;
    --warn: #e8830c; --warn-soft: #fbefdc; --crit: #e03131; --crit-soft: #fbe4e4;
    --inert: #868e96; --inert-soft: #eceef1;
    --kimio-orange-soft: #FFF3EC;
    --kimio-orange-ink: #A32E05; --warn-ink: #7A5A0F;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --ground: #0e1116; --panel: #161b22; --panel-2: #1c222b; --ink: #e6edf3;
    --ink-2: #9aa4af; --ink-3: #6b7684; --line: #262d37; --line-2: #333c48;
    --accent: #6b8afd; --accent-soft: #1b2540; --good: #4ac26b; --good-soft: #14271a;
    --warn: #f0a53a; --warn-soft: #2c2110; --crit: #f2666a; --crit-soft: #2c1416;
    --inert: #7d8590; --inert-soft: #20262f;
    --kimio-orange-soft: #2e1a10;
    --kimio-orange-ink: #FF9A5E; --warn-ink: #f0a53a;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0; background: var(--ground); color: var(--ink);
    font-family: var(--sans); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }
button { font-family: inherit; }
a.link { color: var(--accent); cursor: pointer; text-decoration: none; }
a.link:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- shell ---- */
.app { display: grid; grid-template-columns: 216px 1fr; grid-template-rows: 44px 1fr; height: 100vh; }
.topbar {
    grid-column: 1 / -1; display: flex; align-items: center; gap: 14px;
    background: var(--panel); border-bottom: 1px solid var(--line); padding: 0 14px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.brand .dot { width: 9px; height: 9px; border-radius: 2px; background: var(--accent); }
/* Which environment this console operates against — the console's half of the shared colour language
   (REL3 #875). The rule, the three states and why production moved off the critical red are in
   docs/architecture/build-flavours.md, "One colour language, two surfaces"; only the tokens are here. */
.env {
    font-family: var(--mono); font-size: 12px; padding: 2px 7px; border-radius: 4px;
    background: var(--inert-soft); color: var(--ink-2); border: 1px solid transparent; font-weight: 600;
}
/* Fill from the soft token, TEXT from the matching ink token: the full-strength hue on its own soft fill
   lands near 3:1, under the 4.5:1 WCAG 1.4.3 asks of this 12px 600-weight text. The hue is unchanged. */
.env.prod { background: var(--kimio-orange-soft); color: var(--kimio-orange-ink); }
.env.beta { background: var(--warn-soft); color: var(--warn-ink); }
.topsearch {
    flex: 1; max-width: 460px; display: flex; align-items: center; gap: 7px;
    background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 9px; color: var(--ink-3);
}
.topsearch input { border: 0; background: transparent; color: var(--ink); flex: 1; outline: none; font-size: 13.5px; font-family: inherit; }
.whoami { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.theme-btn { background: transparent; border: 1px solid var(--line); color: var(--ink-2); border-radius: var(--radius); padding: 4px 8px; cursor: pointer; font-size: 13px; }
.flag-super { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.signout-form { margin: 0; }

/* ---- rail ---- */
.rail { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 8px 0; }
.rail-group { padding: 10px 14px 4px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-3); font-weight: 650; }
.nav { display: flex; flex-direction: column; }
.nav a, .nav span.navitem {
    display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
    background: transparent; border: 0; color: var(--ink-2); padding: 6px 14px; cursor: pointer;
    font-size: 13.5px; border-left: 2px solid transparent; text-decoration: none;
}
.nav a:hover { background: var(--panel-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.nav .soon { color: var(--ink-3); cursor: default; }
.nav .soon:hover { background: transparent; }
.nav .glyph { width: 15px; text-align: center; opacity: 0.8; }
.nav .cnt { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); background: var(--panel-2); padding: 1px 6px; border-radius: 8px; }
.nav .soon .cnt { background: transparent; text-transform: uppercase; letter-spacing: 0.04em; font-size: 10.5px; }

/* ---- main ---- */
.main { overflow: auto; padding: 16px 18px 40px; }
.crumbs { display: flex; align-items: center; gap: 7px; color: var(--ink-3); font-size: 13px; margin-bottom: 3px; }
.crumbs .mono { color: var(--ink-2); }
.crumbs a { color: var(--accent); cursor: pointer; text-decoration: none; }
.h1 { font-size: 19px; font-weight: 660; letter-spacing: -0.015em; margin: 0 0 2px; display: flex; align-items: center; gap: 10px; }
.schema-note { color: var(--ink-3); font-size: 12.5px; font-family: var(--mono); margin-bottom: 14px; }
.schema-note b { color: var(--ink-2); font-weight: 600; }

/* toolbar */
.toolbar { display: flex; align-items: center; gap: 8px; margin: 6px 0 12px; flex-wrap: wrap; }
.field { display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 9px; color: var(--ink-3); }
.field input, .field select { border: 0; background: transparent; color: var(--ink); outline: none; font-size: 13.5px; font-family: inherit; }
.field.search { min-width: 260px; }
.btn { background: var(--panel); border: 1px solid var(--line-2); color: var(--ink); border-radius: var(--radius); padding: 6px 11px; cursor: pointer; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--crit); border-color: var(--line-2); }
.btn.small { padding: 3px 8px; font-size: 12.5px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.spacer { flex: 1; }
.rowcount { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }

/* tables */
.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
thead th { text-align: left; font-weight: 600; color: var(--ink-2); background: var(--panel-2); padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
thead th .pk { color: var(--accent); font-size: 10px; margin-left: 4px; letter-spacing: 0.05em; }
tbody td { padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
/* Rows are not clickable (a mis-hit should not navigate), so they carry no pointer cursor and no hover
   highlight — either would promise a whole-row click that does nothing. Navigation is the linked cells
   and the row's "…" menu. */
td .sub { color: var(--ink-3); font-size: 12px; }
.sub { color: var(--ink-3); font-size: 12px; }
.id { font-family: var(--mono); color: var(--ink-2); font-size: 12.5px; }
.strong { font-weight: 600; }

/* copyable id chip (IdChip.razor): short 4…4 id + hover-full tooltip + copy button */
.idchip { display: inline-flex; align-items: center; gap: 3px; }
.copy-id { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; padding: 0 3px; font-size: 12px; line-height: 1; border-radius: 3px; opacity: 0.55; }
.copy-id:hover { opacity: 1; color: var(--accent); background: var(--panel-2); }
.copy-id.copied { opacity: 1; color: var(--good); }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; border: 1px solid transparent; white-space: nowrap; }
.chip .led { width: 6px; height: 6px; border-radius: 50%; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.good .led { background: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.warn .led { background: var(--warn); }
.chip.crit { background: var(--crit-soft); color: var(--crit); }
.chip.crit .led { background: var(--crit); }
.chip.inert { background: var(--inert-soft); color: var(--ink-2); }
.chip.inert .led { background: var(--inert); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.accent .led { background: var(--accent); }
.rolechip { font-family: var(--mono); font-size: 11.5px; padding: 1px 7px; border-radius: 3px; font-weight: 600; border: 1px solid var(--line-2); color: var(--ink-2); }
.rolechip.patron { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.rolechip.steward { color: var(--good); border-color: var(--good); }

/* detail */
.detail-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.card > h3 .container-name { font-family: var(--mono); color: var(--ink-3); font-size: 11.5px; text-transform: none; letter-spacing: 0; margin-left: auto; }
.card .body { padding: 12px 14px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 5px 12px; align-items: baseline; margin: 0; }
.kv dt { color: var(--ink-3); font-size: 12.5px; }
.kv dd { margin: 0; }
.card + .card { margin-top: 14px; }
.identityhead { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }

/* small identity roundel (Picture, or initials fallback) in list rows */
.acct { display: flex; align-items: center; gap: 8px; }
.identityhead .name { font-size: 17px; font-weight: 650; display: flex; align-items: center; gap: 10px; }
.cardtable { width: 100%; }
.cardtable td, .cardtable th { padding: 6px 14px; }
.actions-inline { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-note { color: var(--ink-3); font-size: 12px; margin-top: 8px; }

/* grant form */
.grant-form { display: grid; gap: 10px; }
.grant-form label { display: grid; gap: 3px; font-size: 12.5px; color: var(--ink-3); }
.grant-form input, .grant-form select { padding: 5px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); font-size: 13.5px; font-family: inherit; }
.grant-form .check { display: flex; align-items: center; gap: 7px; color: var(--ink-2); }
.grant-form .raw { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.notice { padding: 8px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 10px; }
.notice.ok { background: var(--good-soft); color: var(--good); }
.notice.bad { background: var(--crit-soft); color: var(--crit); }

@media (max-width: 860px) {
    .detail-grid { grid-template-columns: 1fr; }
    .app { grid-template-columns: 56px 1fr; }
    .rail .label, .rail-group, .nav .cnt { display: none; }
    .grant-form .raw { grid-template-columns: 1fr; }
}

/* Population fill meter (ADMIN3 #1008) — a small bar whose inner <i> width is a computed integer percentage. */
.meter {
    display: inline-block;
    width: 64px;
    height: 8px;
    border-radius: 4px;
    background: var(--panel-2);
    overflow: hidden;
    vertical-align: middle;
}
.meter > i { display: block; height: 100%; background: var(--good); }
.meter.warn > i { background: var(--warn); }
.meter.crit > i { background: var(--crit); }

/* An accessible name that is visible only to assistive technology (e.g. the row-overflow column header,
   which shows no label but must still be announced). */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
