/* AML console. Light and dark follow the OS; every colour is a token defined once here.
   Chart colours were checked with the dataviz palette validator against both surfaces. */

:root {
  color-scheme: light;
  --page: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --ink: #141824;
  --ink-2: #4b5163;
  --muted: #6f7689;
  --line: #e4e7ec;
  --line-2: #d3d8e0;
  --brand: #252c3e;
  --brand-ink: #ffffff;
  --brand-hover: #3a4460;
  --link: #1f63b5;
  --focus: #2a78d6;
  --danger: #b42828;
  --danger-wash: #fdeceb;

  --series-ok: #2a78d6;
  --series-failed: #d03b3b;
  --grid: #e9ebf0;
  --axis: #c3c8d2;

  --good: #0ca30c;
  --good-ink: #006300;
  --good-wash: #e7f4e7;
  --warn: #fab219;
  --warn-ink: #7a5000;
  --warn-wash: #fff3d9;
  --bad: #d03b3b;
  --bad-ink: #a52525;
  --bad-wash: #fdeceb;
  --neutral: #8a91a2;
  --neutral-ink: #4b5163;
  --neutral-wash: #eef0f3;

  --shadow: 0 1px 2px rgb(20 24 36 / 6%);
  --shadow-lg: 0 16px 40px rgb(20 24 36 / 20%);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #11141c;
    --surface: #1b1f2a;
    --surface-2: #242938;
    --ink: #eef0f5;
    --ink-2: #b8bfcd;
    --muted: #8e95a6;
    --line: #2a3040;
    --line-2: #3a4155;
    --brand: #e3e7f1;
    --brand-ink: #1b1f2a;
    --brand-hover: #ffffff;
    --link: #7fb2f0;
    --focus: #6aa5ee;
    --danger: #f08a8a;
    --danger-wash: rgb(208 59 59 / 16%);

    --series-ok: #3987e5;
    --grid: #272c3a;
    --axis: #3d4457;

    --good-ink: #62d062;
    --good-wash: rgb(12 163 12 / 15%);
    --warn-ink: #f5c55a;
    --warn-wash: rgb(250 178 25 / 14%);
    --bad-ink: #f08a8a;
    --bad-wash: rgb(208 59 59 / 18%);
    --neutral-ink: #b8bfcd;
    --neutral-wash: rgb(138 145 162 / 16%);

    --shadow: 0 1px 2px rgb(0 0 0 / 35%);
    --shadow-lg: 0 16px 40px rgb(0 0 0 / 55%);
  }
}

/* ───────────── base ───────────── */

*,
*::before,
*::after { box-sizing: border-box; }

[x-cloak] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; margin: 20px 0 8px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); }
.noscript { padding: 24px; text-align: center; }

/* ───────────── logo (the evolvable.ai mark, tinted by currentColor) ───────────── */

.logo {
  display: inline-block;
  background: currentColor;
  -webkit-mask: url("logo.svg") no-repeat left center / contain;
  mask: url("logo.svg") no-repeat left center / contain;
  aspect-ratio: 184 / 31;
  vertical-align: middle;
}

.logo-sm { height: 14px; }
.logo-md { height: 20px; }
.logo-lg { height: 30px; color: var(--brand); }

/* ───────────── boot & sign in ───────────── */

.boot { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }

.login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding-block: 32px;
  padding-inline: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 32px 28px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { margin-top: 10px; }

.notice {
  background: var(--warn-wash);
  color: var(--warn-ink);
  border-radius: 8px;
  padding: 8px 12px;
}

.powered { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.powered a { color: var(--ink-2); }
.powered a:hover { color: var(--ink); }

/* ───────────── shell ───────────── */

.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding-inline: 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 56px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; color: var(--brand); }
.brand:hover { text-decoration: none; }
.brand-name {
  font-weight: 650;
  color: var(--ink);
  padding-left: 12px;
  border-left: 1px solid var(--line-2);
}

.tabs {
  display: flex;
  gap: 2px;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab {
  padding: 17px 12px 15px;
  color: var(--ink-2);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-weight: 500;
}

.tab:hover { color: var(--ink); text-decoration: none; }
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--brand); }

.who { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.who-name { color: var(--ink-2); }

.content {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding-block: 28px 40px;
  padding-inline: 20px;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-block: 20px;
  padding-inline: 16px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
}

.footer a { color: var(--ink-2); }
.footer a:hover { color: var(--ink); }

/* ───────────── views, cards, tiles ───────────── */

.view { display: flex; flex-direction: column; gap: 20px; }

.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.view-head p { margin-top: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
  transition: opacity 0.15s;
}

/* Refetch keeps the frame: the previous render stays, dimmed, until the new one lands. */
.is-loading { opacity: 0.6; }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.card-head p { margin-top: 2px; }
.card-link { display: inline-block; margin-top: 12px; font-size: 13px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tile-label { color: var(--ink-2); font-size: 13px; }
.tile-value { font-size: 28px; font-weight: 650; line-height: 1.2; }
.tile-foot { color: var(--muted); font-size: 12px; min-height: 18px; }
a.tile-foot { color: var(--link); }

.empty { color: var(--muted); padding: 12px 0; }

/* ───────────── forms ───────────── */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  align-items: end;
}

.field-wide { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span:first-child { font-size: 13px; font-weight: 550; color: var(--ink-2); }
.field-inline { flex-direction: row; align-items: center; gap: 8px; }

input:not([type="checkbox"]):not([type="range"]):not([type="file"]),
select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 38px;
  width: 100%;
  min-width: 0;
}

select { padding-right: 28px; }
input:focus, select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px rgb(42 120 214 / 18%); }
input[type="range"] { width: 100%; accent-color: var(--brand); min-height: 38px; }
input[type="file"] { font: inherit; color: var(--ink-2); max-width: 100%; }
input[type="checkbox"] { accent-color: var(--brand); width: 16px; height: 16px; margin: 2px 0 0; flex: none; }

.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }

.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
progress { width: 180px; max-width: 100%; accent-color: var(--brand); }

.filters { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { width: 240px; max-width: 100%; }
.filters .field-inline { width: auto; }

/* ───────────── buttons ───────────── */

.btn {
  font: inherit;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--line-2); }
.btn-danger:hover:not(:disabled) { background: var(--danger-wash); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.segment {
  font: inherit;
  font-size: 13px;
  padding: 0 14px;
  min-height: 36px;
  border: 0;
  border-right: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.segment:last-child { border-right: 0; }
.segment:hover { background: var(--surface-2); }
.segment[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

/* ───────────── tables ───────────── */

.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.table-scroll { max-height: 360px; overflow-y: auto; margin-top: 16px; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: var(--surface);
  position: sticky;
  top: 0;
}

td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { text-align: right; white-space: nowrap; }
.col-match { min-width: 14rem; }
.clamp-2 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.actions .btn + .btn { margin-left: 4px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td, tr.clickable:focus-visible td { background: var(--surface-2); }
tr.clickable:focus-visible { outline: none; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.pager span { margin-right: 8px; }

/* ───────────── badges: always a dot and a word, never colour alone ───────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-good { background: var(--good-wash); color: var(--good-ink); }
.badge-good::before { background: var(--good); }
.badge-bad { background: var(--bad-wash); color: var(--bad-ink); }
.badge-bad::before { background: var(--bad); }
.badge-warn { background: var(--warn-wash); color: var(--warn-ink); }
.badge-warn::before { background: var(--warn); }
.badge-neutral { background: var(--neutral-wash); color: var(--neutral-ink); }
.badge-neutral::before { background: var(--neutral); }

/* ───────────── screening score ───────────── */

.score { display: inline-flex; align-items: center; gap: 8px; }
.score-track { width: 56px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.score-fill { display: block; height: 100%; background: var(--series-ok); border-radius: 3px; }
.score-value { min-width: 2ch; font-weight: 600; }

/* ───────────── chart ───────────── */

.legend { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; color: var(--ink-2); font-size: 13px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; }
.swatch-ok { background: var(--series-ok); }
.swatch-failed { background: var(--series-failed); }

.chart { position: relative; min-height: 220px; }
.chart-svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart-svg:focus-visible { outline-offset: 4px; border-radius: 4px; }
.chart-grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-empty { fill: var(--muted); font-size: 13px; }
.chart-hover { fill: var(--surface-2); }
.bar-ok { fill: var(--series-ok); }
.bar-failed { fill: var(--series-failed); }

.chart-tip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 8px 10px;
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
}

.tip-title { color: var(--muted); margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row b { color: var(--ink); font-variant-numeric: tabular-nums; }
.tip-key { width: 12px; height: 2px; border-radius: 1px; }
.tip-key-ok { background: var(--series-ok); }
.tip-key-failed { background: var(--series-failed); }

/* ───────────── dialogs ───────────── */

dialog {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  padding: 0;
}

dialog::backdrop { background: rgb(10 12 18 / 45%); }

.modal { width: min(520px, calc(100vw - 32px)); border-radius: 14px; }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.secret { display: flex; gap: 8px; }
.secret input { flex: 1; }

.drawer {
  margin: 0 0 0 auto;
  height: 100vh;
  max-height: 100vh;
  width: min(640px, 100vw);
  /* The UA sheet caps a modal dialog at calc(100% - 6px - 2em), which would leave a gap on a phone. */
  max-width: 100vw;
  border-radius: 0;
  border-width: 0 0 0 1px;
}

.drawer-body { padding: 24px; min-height: 100%; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.drawer-head p { margin-top: 4px; }

.facts { display: grid; grid-template-columns: 150px 1fr; gap: 0; margin: 0; }
.facts > div { display: contents; }
.facts dt, .facts dd { padding: 8px 0; border-bottom: 1px solid var(--line); margin: 0; }
.facts dt { color: var(--muted); padding-right: 12px; }
.facts dd { overflow-wrap: anywhere; }
.remarks { white-space: pre-line; color: var(--ink-2); }

/* ───────────── toasts ───────────── */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--neutral);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 10px 12px;
}

.toast span { flex: 1; }
.toast-success { border-left-color: var(--good); }
.toast-error { border-left-color: var(--bad); }
.toast-info { border-left-color: var(--focus); }

.toast-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

/* ───────────── narrow screens ───────────── */

@media (max-width: 720px) {
  .topbar-inner { gap: 8px 16px; padding-block: 8px 0; padding-inline: 16px; }
  .tabs { order: 3; flex-basis: 100%; }
  .tab { padding: 10px 10px 12px; }
  .brand-name { display: none; }
  .content { padding-block: 20px 32px; padding-inline: 16px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { border-bottom: 0; padding-bottom: 0; }
  .login-card { padding: 24px 20px; }
}
