/* Priorio Admin — modern light design system.
   Self-hosted IBM Plex (SIL OFL 1.1); CSP allows font-src 'self'.
   Sans for prose, Mono for code, IDs, timestamps, KPIs and badges.
   Inline SVG icons inherit currentColor. */
@font-face { font-family: "IBM Plex Sans"; src: url("/admin/static/fonts/IBMPlexSans-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/admin/static/fonts/IBMPlexSans-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/admin/static/fonts/IBMPlexSans-SemiBold.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/admin/static/fonts/IBMPlexSans-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("/admin/static/fonts/IBMPlexMono-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("/admin/static/fonts/IBMPlexMono-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("/admin/static/fonts/IBMPlexMono-SemiBold.woff2") format("woff2"); font-weight: 600; font-display: swap; }
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --ink: #101828;
  --ink-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #eaecf0;
  --line-strong: #d0d5dd;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-ink: #ffffff;
  --series: #6366f1;
  --good-bg: #ecfdf3; --good: #067647; --good-line: #a6f4c5;
  --warn-bg: #fffaeb; --warn: #b54708; --warn-line: #fedf89;
  --bad-bg: #fef3f2;  --bad: #b42318; --bad-line: #fecdca;
  --neutral-bg: #f2f4f7; --neutral: #475467; --neutral-line: #e4e7ec;
  --info-bg: #eff4ff; --info: #3538cd; --info-line: #c7d7fe;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, .10), 0 2px 4px -2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 24px -4px rgba(16, 24, 40, .10), 0 8px 8px -4px rgba(16, 24, 40, .04);
  --ring: 0 0 0 4px rgba(79, 70, 229, .14);
  --side: #0d1321;
  --side-ink: #a5abb8;
  --side-faint: #5f6879;
  --sans: "IBM Plex Sans", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 13px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.mono, code { font-family: var(--mono); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code { font-size: 12px; background: var(--neutral-bg); border: 1px solid var(--neutral-line); padding: 1px 5px; border-radius: 5px; word-break: break-all; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; margin: 0 0 4px; }
h2 { font-size: 13px; font-weight: 650; letter-spacing: .01em; margin: 26px 0 10px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
::selection { background: rgba(79, 70, 229, .16); }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: none; background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; color: #fff; font-weight: 600; font-size: 14.5px; }
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand .logo {
  width: 26px; height: 26px; flex: none; border-radius: 7px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
.sidebar .brand .logo svg { width: 15px; height: 15px; }
.sidebar .brand em { font-style: normal; font-weight: 400; color: var(--side-faint); margin-left: 1px; }
.sidebar nav { flex: 1; padding: 2px 10px 12px; display: flex; flex-direction: column; }
.side-label { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--side-faint); padding: 14px 8px 5px; }
.side-label:first-child { padding-top: 4px; }
.sidebar ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.sidebar li a {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 7px;
  color: var(--side-ink); font-size: 13px; font-weight: 500; transition: background-color .12s ease, color .12s ease;
}
.sidebar li a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.sidebar li a .ic { width: 16px; height: 16px; flex: none; color: var(--side-faint); transition: color .12s ease; }
.sidebar li a:hover .ic { color: #c7cdd9; }
.sidebar li a.on { background: rgba(129, 140, 248, .16); color: #e0e7ff; font-weight: 600; }
.sidebar li a.on .ic { color: #a5b4fc; }

/* ---------- Top bar ---------- */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; min-height: 46px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.env-badge {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); background: var(--neutral-bg);
  border: 1px solid var(--neutral-line); padding: 3px 9px; border-radius: 6px;
}
.env-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #12b76a; }
.env-badge.prod { color: var(--bad); background: var(--bad-bg); border-color: var(--bad-line); }
.env-badge.prod::before { background: var(--bad); }
.topbar .fill { flex: 1; }
.topbar .role-chip {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-2); background: var(--surface); border: 1px solid var(--line-strong); padding: 3px 9px; border-radius: 6px;
}
.topbar .who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.topbar .who .avatar {
  width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700;
}
.topbar .who .id { min-width: 0; display: grid; line-height: 1.25; }
.topbar .who .id a { color: var(--ink); font-weight: 600; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .who .id .muted { font-size: 11px; }
button.link {
  background: none; border: 0; padding: 4px; border-radius: 6px; color: var(--faint); cursor: pointer;
  font: inherit; font-size: 12px; display: inline-flex; align-items: center; transition: color .12s ease, background-color .12s ease;
}
button.link:hover { color: var(--bad); background: var(--bad-bg); text-decoration: none; }
button.link .ic { width: 16px; height: 16px; }

main { flex: 1; min-width: 0; padding: 20px 26px 52px; }
.crumbs { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-bottom: 12px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.crumbs span { margin: 0 4px; color: var(--line-strong); }
.crumbs b { color: var(--ink-2); font-weight: 500; }

/* ---------- Page header ---------- */
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.head .meta { color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons and forms ---------- */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 13px; font-weight: 550;
  padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink-2); cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm);
  transition: background-color .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease;
}
.btn:hover { background: var(--surface-2); border-color: #b7bec9; text-decoration: none; }
.btn:active { box-shadow: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--surface); border-color: var(--bad-line); color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: #fda29b; }
dialog .btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
dialog .btn.danger:hover { background: #912018; }
.btn.small { padding: 3px 9px; font-size: 12px; border-radius: 7px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input, select, textarea {
  font: inherit; font-size: 13px; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
textarea { width: 100%; resize: vertical; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 12px 14px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.filters input[type=search], .filters input[type=text] { min-width: 260px; }
.stack { display: grid; gap: 12px; max-width: 420px; }
.inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }

/* ---------- Profile header (detail pages) ---------- */
.profile { padding: 14px 18px; }
.profile .p-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.profile .p-top h1 { margin: 0; font-size: 19px; }
.profile .p-top .actions { margin-left: auto; }
.profile .p-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, max-content)); column-gap: 44px; row-gap: 8px; margin-top: 12px; }
.profile .pm { display: grid; gap: 0; }
.profile .pm .l { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.profile .pm .val { font-size: 13px; color: var(--ink); }

/* ---------- Cards and tiles ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card > h2 { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--ink); margin-bottom: 10px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.tiles { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow-sm); transition: box-shadow .15s ease, transform .15s ease;
}
.tile:hover { box-shadow: var(--shadow-md); }
.tile .k { display: flex; align-items: center; gap: 7px; font-size: 11.5px; font-weight: 500; color: var(--muted); }
.tile .k::before { content: ""; width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--accent); }
.tile.attn .k::before { background: #d92d20; }
.tile .v { font-family: var(--mono); font-size: 20px; font-weight: 600; line-height: 1.3; margin-top: 2px; }
.tile .h { font-size: 11px; color: var(--muted); margin-top: 1px; }
.tile.alert { border-color: var(--bad-line); background: linear-gradient(180deg, #fffbfb, var(--surface)); }
.tile.alert .v { color: var(--bad); }
.tile.na { background: var(--surface-2); }
.tile.na .k::before { background: var(--faint); }
.tile.na .v { font-size: 12px; font-weight: 500; font-family: var(--sans); color: var(--faint); padding: 4px 0; }
.kv { display: grid; grid-template-columns: minmax(140px, 42%) 1fr; gap: 0; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); padding: 6px 12px 6px 0; border-bottom: 1px solid var(--line); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv dt:nth-last-of-type(1), .kv dt:nth-last-of-type(1) + dd { border-bottom: 0; }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  overflow-x: auto; margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data.narrow { width: auto; min-width: 420px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 600; padding: 9px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2);
}
table.data td { padding: 9px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background-color .1s ease; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td a { font-weight: 550; }
table.data .n { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.empty { text-align: center; color: var(--muted); padding: 28px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; font-size: 13px; }

/* ---------- Chips: the label carries the meaning, colour reinforces it. ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 6px;
  font-family: var(--mono); font-size: 11px; font-weight: 500; white-space: nowrap; line-height: 1.7;
  background: var(--neutral-bg); color: var(--neutral); box-shadow: inset 0 0 0 1px var(--neutral-line);
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; }
.chip.good { background: var(--good-bg); color: var(--good); box-shadow: inset 0 0 0 1px var(--good-line); }
.chip.warn { background: var(--warn-bg); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn-line); }
.chip.bad { background: var(--bad-bg); color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad-line); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 0 16px; flex-wrap: wrap; }
.tabs a {
  padding: 8px 12px; color: var(--muted); font-weight: 550; font-size: 13.5px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .12s ease, border-color .12s ease;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- Messages ---------- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-sm); }
.flash.ok { background: var(--good-bg); color: var(--good); border-color: var(--good-line); }
.flash.err { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-line); }
.notice { padding: 10px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line); margin-bottom: 14px; }
.notice.info { background: var(--info-bg); color: var(--info); border-color: var(--info-line); }
.notice.private { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-line); }
.health { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 13.5px; }
.health li.ok { color: var(--good); }
.health li.warn { color: var(--warn); font-weight: 600; }
.health li.info { color: var(--muted); }
.revealed { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 2px 0 12px; }
.note { border-left: 3px solid var(--line-strong); padding: 2px 0 2px 12px; margin-bottom: 12px; }
.note p { white-space: pre-wrap; margin: 0; }

/* ---------- Dialogs ---------- */
dialog.dialog { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0; width: min(460px, 92vw); box-shadow: var(--shadow-lg); color: var(--ink); }
dialog.dialog::backdrop { background: rgba(16, 24, 40, .5); }
dialog.dialog form { display: grid; gap: 12px; padding: 22px; }
dialog.dialog h3 { margin: 0; font-size: 16px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* ---------- Charts: one series, one hue; grid and axes stay recessive. ---------- */
.charts { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart .mark { fill: var(--series); transition: fill .12s ease; }
svg.chart .hit { fill: transparent; }
svg.chart g.bar:hover .mark { fill: var(--accent-hover); }
svg.chart .base { stroke: var(--line-strong); stroke-width: 1; }
svg.chart .axis { font-size: 10px; fill: var(--muted); }
.chart-tip { position: absolute; z-index: 10; background: var(--ink); color: #fff; font-size: 12px; font-weight: 500; padding: 4px 9px; border-radius: 6px; pointer-events: none; white-space: nowrap; box-shadow: var(--shadow-md); }

/* ---------- Signed-out pages ---------- */
body.bare { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(180deg, #eef0f6, var(--bg) 40%); }
body.bare main { width: min(400px, 92vw); padding: 0; }
.login { display: grid; gap: 18px; }
.login .brandline { display: flex; align-items: center; justify-content: center; gap: 10px; }
.login .brandline .logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; box-shadow: var(--shadow-md);
}
.login .brandline .logo svg { width: 19px; height: 19px; }
.login .brandline h1 { margin: 0; font-size: 19px; }
.login .brandline h1 em { font-style: normal; font-weight: 500; color: var(--muted); }
.login .card { padding: 24px; box-shadow: var(--shadow-md); }
.login .foot { text-align: center; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; }
  .sidebar nav { padding: 0 10px 10px; display: block; }
  .sidebar ul { display: flex; flex-wrap: wrap; gap: 2px; }
  .side-label { padding-top: 10px; }
  .topbar { position: static; min-height: 0; padding: 8px 14px; flex-wrap: wrap; }
  main { padding: 14px; }
}
