/*
 * CityViz Ops. Brand palette from the CityViz guidelines; health colours are
 * functional additions, always paired with a text label and a glyph so meaning
 * never rests on colour alone. No inline styles anywhere (strict CSP).
 */
:root {
  --royal: #2158a6;
  --cornflower: #427ec1;
  --navy: #24356f;
  --midnight: #151a44;
  --sky: #7cb8e5;
  --ice: #cbe3f5;
  --coral: #ff7676;
  --coral-red: #ff605c;
  --slate: #454d56;
  --steel: #5a6470;
  --cadet: #99aabf;
  --periwinkle: #c2d6f2;
  --alice: #d0deef;

  --bg: #f4f7fb;
  --surface: #ffffff;
  --line: #dde5f0;
  --line-strong: var(--cadet);
  --text: var(--slate);
  --muted: var(--steel);

  --ok: #1f7a4d;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff1d6;
  --crit: #b3261e;
  --crit-bg: #ffe3e1;
  --unknown: #5a6470;
  --unknown-bg: #eef1f5;

  --font-body: 'DINPro', 'DIN', 'DIN Alternate', 'Helvetica Neue', Arial, sans-serif;
  --font-head: 'DINPro Bold', 'DIN Bold', 'DIN Alternate', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Consolas, Monaco, 'Courier New', monospace;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(21, 26, 68, .06), 0 1px 1px rgba(21, 26, 68, .04);
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--royal); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; border-radius: 3px; }
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 700; color: var(--navy); margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; margin-top: 1.75rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: var(--font-mono); font-size: .88em; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--midnight);
  color: var(--alice);
  display: flex;
  align-items: stretch;
  gap: 1.5rem;
  padding: 0 1.25rem;
  min-height: 52px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex; align-items: center; gap: .5rem;
  font-family: var(--font-head); font-size: 1.05rem; color: #fff; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--coral); box-shadow: 6px 6px 0 var(--sky); margin-right: 6px; }
.brand-sub { color: var(--sky); font-family: var(--font-body); }
.nav { display: flex; align-items: stretch; gap: .1rem; flex-wrap: wrap; }
.nav a, .nav button {
  display: flex; align-items: center; padding: 0 .7rem;
  color: var(--alice); font-size: .93rem; border-bottom: 3px solid transparent;
  background: none; border-top: 0; border-left: 0; border-right: 0; font-family: inherit; cursor: pointer;
}
.nav a:hover, .nav button:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,.06); }
.nav a.active { color: #fff; border-bottom-color: var(--coral); }
.nav-end { margin-left: auto; }
.nav form { display: flex; }
.badge-count { background: var(--coral-red); color: #fff; border-radius: 9px; font-size: .72rem; padding: 0 .4rem; margin-left: .35rem; line-height: 1.4; }

/* ---------- Layout ---------- */
main { padding: 1.25rem 1.25rem 3rem; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stack > * + * { margin-top: 1rem; }
main > .grid + .grid, main > .grid + .card, main > .card + .grid { margin-top: 1rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .end { margin-left: auto; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: .85rem 1.1rem .35rem; }

/* ---------- Summary strip ---------- */
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1.1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; box-shadow: var(--shadow); color: inherit; }
a.stat:hover { text-decoration: none; border-color: var(--cadet); }
.stat .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat .value { font-family: var(--font-head); font-size: 1.6rem; color: var(--navy); line-height: 1.15; }
.stat .detail { font-size: .85rem; color: var(--muted); }
.stat.crit { border-left: 4px solid var(--crit); }
.stat.warn { border-left: 4px solid #d99a1e; }
.stat.ok { border-left: 4px solid var(--ok); }
.stat.info { border-left: 4px solid var(--royal); }

/* ---------- Health pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .76rem; font-weight: 700; letter-spacing: .02em;
  padding: .1rem .5rem; border-radius: 999px; white-space: nowrap; border: 1px solid transparent;
}
.pill::before { font-size: .7rem; line-height: 1; }
.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.ok::before { content: "●"; }
.pill.warning { color: var(--warn); background: var(--warn-bg); }
.pill.warning::before { content: "▲"; }
.pill.critical { color: var(--crit); background: var(--crit-bg); }
.pill.critical::before { content: "■"; }
.pill.unknown { color: var(--unknown); background: var(--unknown-bg); }
.pill.unknown::before { content: "○"; }
.pill.disabled { color: var(--steel); background: transparent; border: 1px dashed var(--cadet); }
.pill.disabled::before { content: "–"; }

.status-tag { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 4px; background: var(--ice); color: var(--navy); }
.status-tag.churned, .status-tag.revoked { background: var(--unknown-bg); color: var(--muted); }
.status-tag.suspended { background: var(--warn-bg); color: var(--warn); }
.status-tag.onboarding { background: #e8f0fb; color: var(--royal); }

.ev { font-size: .76rem; font-weight: 700; padding: .05rem .4rem; border-radius: 4px; white-space: nowrap; display: inline-block; }
.ev.success { color: var(--ok); background: var(--ok-bg); }
.ev.failure { color: var(--crit); background: var(--crit-bg); }
.ev.warning { color: var(--warn); background: var(--warn-bg); }
.ev.started, .ev.info { color: var(--navy); background: var(--ice); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: .5rem .65rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: #f8fafd; white-space: nowrap; }
tbody tr:hover { background: #f7faff; }
td.cell { min-width: 118px; }
td .value { display: block; margin-top: .15rem; font-size: .86rem; color: var(--text); }
td .reason { display: block; font-size: .8rem; color: var(--muted); max-width: 30ch; }
.client-name { font-family: var(--font-head); color: var(--navy); }
.client-meta { display: block; font-size: .8rem; color: var(--muted); }
tr.row-critical td:first-child { box-shadow: inset 4px 0 0 var(--crit); }
tr.row-warning td:first-child { box-shadow: inset 4px 0 0 #d99a1e; }
.dense td, .dense th { padding: .35rem .55rem; }
tr.is-hidden { display: none; }

/* ---------- Definition lists ---------- */
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: .5rem 0 0; font-size: .92rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Topic cards (client page) ---------- */
.topic-card { display: flex; flex-direction: column; }
.topic-card .reason { margin: .35rem 0 .1rem; font-size: .92rem; }
.topic-card .foot { margin-top: auto; padding-top: .6rem; font-size: .82rem; }
.topic-card.critical { border-top: 3px solid var(--crit); }
.topic-card.warning { border-top: 3px solid #d99a1e; }
.topic-card.ok { border-top: 3px solid var(--ok); }
.topic-card.unknown, .topic-card.disabled { border-top: 3px solid var(--line); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 9.5rem 5.5rem 1fr; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.timeline .when { color: var(--muted); font-size: .85rem; }
.timeline .what .type { font-family: var(--font-mono); font-size: .85rem; color: var(--navy); }
.timeline .what .msg { display: block; color: var(--text); overflow-wrap: anywhere; }
.timeline .what .meta { display: block; font-size: .8rem; color: var(--muted); }
details.data summary { cursor: pointer; font-size: .8rem; color: var(--cornflower); }
details.data pre { background: #f5f8fc; border: 1px solid var(--line); padding: .5rem; border-radius: 4px; font-size: .78rem; overflow-x: auto; max-height: 20rem; white-space: pre-wrap; }

/* ---------- Tabs, filters ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .45rem .8rem; color: var(--steel); border-bottom: 3px solid transparent; margin-bottom: -2px; font-size: .93rem; }
.tabs a:hover { text-decoration: none; color: var(--navy); }
.tabs a.active { color: var(--navy); border-bottom-color: var(--royal); font-weight: 700; }
.filters { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: .9rem; }
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .78rem; color: var(--muted); }
.filters .check { flex-direction: row; align-items: center; gap: .35rem; font-size: .9rem; color: var(--text); padding-bottom: .55rem; }

/* ---------- Forms & buttons ---------- */
input[type=text], input[type=email], input[type=password], input[type=url], input[type=tel], input[type=number], input[type=date], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: #fff;
  border: 1px solid var(--line-strong); border-radius: 5px; padding: .45rem .6rem; min-height: 38px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--royal); box-shadow: 0 0 0 3px rgba(33, 88, 166, .18); }
.filters input, .filters select { width: auto; min-width: 11rem; }
.filters input[type=checkbox] { min-width: 0; }
textarea { min-height: 5rem; }
.form-row { margin-bottom: 1rem; }
.form-row > label, .form-label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: .3rem; color: var(--navy); }
.form-row .help { font-size: .82rem; color: var(--muted); margin-top: .25rem; }
.form-row.check-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.form-row.check-row label { font-weight: 400; color: var(--text); margin: 0; }
.form-row.check-row .help { flex-basis: 100%; }
.errors { list-style: none; padding: 0; margin: .3rem 0 0; color: var(--crit); font-size: .85rem; }
.form-narrow { max-width: 680px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 1rem; }
.choice-list { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; }
.choice-list label { display: flex; align-items: center; gap: .35rem; font-weight: 400; color: var(--text); }
.money-input { display: flex; align-items: center; gap: .35rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 38px; padding: .4rem .95rem; border-radius: 5px; border: 1px solid var(--royal);
  background: var(--royal); color: #fff; font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--navy); border-color: var(--navy); text-decoration: none; color: #fff; }
.btn.secondary { background: #fff; color: var(--royal); }
.btn.secondary:hover { background: #eef4fc; color: var(--navy); }
.btn.danger { background: #fff; color: var(--crit); border-color: #e7a19c; }
.btn.danger:hover { background: var(--crit-bg); }
.btn.small { min-height: 30px; padding: .2rem .6rem; font-size: .85rem; }
.inline-form { display: inline; }
.button-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }
.danger-zone { margin-top: 2rem; padding: 1rem; border: 1px solid #f1c3bf; border-radius: var(--radius); background: #fffafa; }
.danger-zone .inline-fields { display: flex; gap: .5rem; flex-wrap: wrap; }
.danger-zone .inline-fields input { max-width: 16rem; }

/* ---------- Flash messages ---------- */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash.success { background: var(--ok-bg); border-color: #b5dfc6; color: #174f33; }
.flash.error { background: var(--crit-bg); border-color: #f1b8b3; color: #7a1a14; }
.flash.notice { background: #eaf2fc; border-color: var(--periwinkle); color: var(--navy); }

/* ---------- Auth pages ---------- */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--midnight) 0%, var(--navy) 55%, var(--royal) 100%); padding: 1rem; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 10px; padding: 2rem; box-shadow: 0 20px 40px rgba(0,0,0,.25); }
.auth-card .brand { color: var(--navy); margin-bottom: 1.25rem; font-size: 1.2rem; }
.auth-card .brand-sub { color: var(--cornflower); }
.auth-card .btn { width: 100%; margin-top: .5rem; }
.otp-input { font-family: var(--font-mono); font-size: 1.4rem; letter-spacing: .3em; text-align: center; }

.qr { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; }
.qr img { width: 220px; height: 220px; border: 1px solid var(--line); border-radius: 6px; padding: 6px; background: #fff; }
.secret { font-family: var(--font-mono); font-size: 1.05rem; letter-spacing: .05em; background: #f5f8fc; padding: .4rem .6rem; border-radius: 4px; display: inline-block; }
.codes { columns: 2; font-family: var(--font-mono); font-size: 1.1rem; list-style: none; padding: 1rem; background: #f5f8fc; border-radius: 6px; max-width: 360px; margin: 1rem 0; }
.token-box { font-family: var(--font-mono); font-size: 1rem; background: var(--midnight); color: #fff; padding: .8rem 1rem; border-radius: 6px; overflow-wrap: anywhere; }

.empty { padding: 1.25rem; text-align: center; color: var(--muted); }
meter { width: 7rem; height: 10px; vertical-align: middle; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { font-size: .82rem; background: var(--ice); color: var(--navy); padding: .1rem .5rem; border-radius: 4px; }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.version-group { margin-bottom: 1rem; }
.version-group h3 { display: flex; gap: .5rem; align-items: center; }
.pager { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .75rem; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: .4rem .75rem; gap: .25rem; }
  .nav a, .nav button { padding: .45rem .5rem; }
  .timeline li { grid-template-columns: 1fr; gap: .15rem; }
  main { padding: 1rem .75rem 2rem; }
}
