/*
 * Actavela web design system: the console, the reports page and the login page all use it.
 * Navy is the brand colour; the orange belongs only to the mark (ADR 0009). Warnings keep amber
 * and errors keep red, so nothing else on a page is allowed to look like them.
 */

@font-face { font-family: "IBM Plex Sans"; src: url(/assets/plex-sans-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url(/assets/plex-sans-500.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url(/assets/plex-sans-600.woff2) format("woff2"); font-weight: 600 700; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url(/assets/plex-mono-500.woff2) format("woff2"); font-weight: 400 600; font-display: swap; }

:root {
  color-scheme: light;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --navy: #06293f;
  --mark: #e08e4a;

  --page: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --surface-3: #eceff3;
  --hover: #f4f7fa;
  --field: #ffffff;
  --ink: #0b1b26;
  --ink-2: #44525e;
  --ink-3: #5f6f7c;
  --line: #e2e7ec;
  --line-2: #cdd5dd;
  --line-3: #aab6c1;
  --brand: #06293f;
  --brand-hover: #0d3c5b;
  --on-brand: #ffffff;
  --brand-soft: #e2ecf4;
  --brand-ink: #0b4a74;
  --link: #0b5a8c;
  --focus: #2f73a8;
  --focus-ring: rgba(47, 115, 168, .22);
  --warn: #8a5300;
  --warn-bg: #fff4dc;
  --warn-line: #e3ab45;
  --error: #b3261e;
  --error-bg: #fdecea;

  --side: #06293f;
  --side-ink: rgba(255, 255, 255, .74);
  --side-line: rgba(255, 255, 255, .1);
  --side-active: #9dc3de;

  --shadow-xs: 0 1px 1px rgba(14, 33, 48, .04);
  --shadow-sm: 0 1px 2px rgba(14, 33, 48, .05), 0 1px 3px rgba(14, 33, 48, .04);
  --shadow-lg: 0 24px 48px -12px rgba(6, 25, 40, .28), 0 2px 6px rgba(6, 25, 40, .08);
  --radius: 8px;
  --radius-lg: 14px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237b8a97' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  --magnifier: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237b8a97' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0a1219; --surface: #111c25; --surface-2: #15212b; --surface-3: #1c2a35; --hover: #172530; --field: #0d171f;
    --ink: #e6edf2; --ink-2: #aebdc8; --ink-3: #8b9dab; --line: #213140; --line-2: #2c3e4d; --line-3: #44596a;
    --brand: #9dc3de; --brand-hover: #b7d4e9; --on-brand: #06293f; --brand-soft: #12364f; --brand-ink: #b7d4e9;
    --link: #9dc3de; --focus: #7fb0d4; --focus-ring: rgba(127, 176, 212, .25);
    --warn: #ffcf7a; --warn-bg: #33270d; --warn-line: #b8801c; --error: #ffb4ab; --error-bg: #3b1714;
    --side: #061d2d; --side-line: rgba(255, 255, 255, .08);
    --shadow-xs: none; --shadow-sm: none; --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .6), 0 0 0 1px #213140;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0a1219; --surface: #111c25; --surface-2: #15212b; --surface-3: #1c2a35; --hover: #172530; --field: #0d171f;
  --ink: #e6edf2; --ink-2: #aebdc8; --ink-3: #8b9dab; --line: #213140; --line-2: #2c3e4d; --line-3: #44596a;
  --brand: #9dc3de; --brand-hover: #b7d4e9; --on-brand: #06293f; --brand-soft: #12364f; --brand-ink: #b7d4e9;
  --link: #9dc3de; --focus: #7fb0d4; --focus-ring: rgba(127, 176, 212, .25);
  --warn: #ffcf7a; --warn-bg: #33270d; --warn-line: #b8801c; --error: #ffb4ab; --error-bg: #3b1714;
  --side: #061d2d; --side-line: rgba(255, 255, 255, .08);
  --shadow-xs: none; --shadow-sm: none; --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .6), 0 0 0 1px #213140;
}

/* ---- Base ------------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
strong, b { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 13px; }
.sub { color: var(--ink-3); font-size: 13px; }
.muted { color: var(--ink-3); }
.ico { display: inline-flex; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---- App shell: navy sidebar, content beside it --------------------------------------- */
.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow: hidden;
  background: var(--side); color: #fff;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "brand" "nav" "foot";
  gap: 20px; padding: 20px 12px 14px;
}
.side-brand { grid-area: brand; display: flex; align-items: center; gap: 12px; padding: 2px 10px; color: #fff; }
.side-brand:hover { text-decoration: none; }
.side-brand svg { width: 30px; height: 28px; flex: none; }
.side-brand span { font-weight: 600; font-size: 15px; letter-spacing: .2em; }
.side-nav { grid-area: nav; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.side-label { font-size: 11px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; color: rgba(255, 255, 255, .42); padding: 14px 12px 6px; }
.side-label:first-child { padding-top: 0; }
.side-nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px;
  color: var(--side-ink); font-weight: 500; transition: background-color .12s, color .12s;
}
.side-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.side-nav a[aria-current="page"] { background: rgba(255, 255, 255, .11); color: #fff; box-shadow: inset 3px 0 0 var(--side-active); }
.side-nav a[aria-current="page"] svg { color: var(--side-active); }
.side-foot { grid-area: foot; display: flex; align-items: center; gap: 8px; padding: 14px 6px 0; border-top: 1px solid var(--side-line); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: #12405e; color: #d6e4ee; font-weight: 600; font-size: 12.5px; letter-spacing: .02em;
}
.me { flex: 1; min-width: 0; line-height: 1.3; }
.me b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me span { font-size: 12px; color: rgba(255, 255, 255, .58); }
.side-foot form { margin: 0; display: contents; }
button.side-btn {
  width: 34px; height: 34px; padding: 0; border: 0; box-shadow: none; flex: none;
  background: transparent; color: rgba(255, 255, 255, .7);
}
button.side-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
button.side-btn:focus-visible { outline-color: var(--side-active); }

.content { min-width: 0; padding: 32px 40px 72px; }
.content-inner { max-width: 1200px; margin: 0 auto; }

@media (max-width: 899px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: static; height: auto; overflow: visible;
    grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; grid-template-areas: "brand foot" "nav nav";
    gap: 6px 12px; padding: 12px 16px 0;
  }
  .side-nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 4px 16px 0; }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav a { white-space: nowrap; flex: none; border-radius: 8px 8px 0 0; padding: 10px 12px 11px; }
  .side-nav a[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--side-active); background: rgba(255, 255, 255, .08); }
  .side-label { display: none; }
  .side-foot { border: 0; padding: 0; }
  .me { display: none; }
  .content { padding: 24px 24px 56px; }
}
@media (max-width: 560px) {
  .content { padding: 20px 16px 48px; }
  .side-nav a svg { display: none; }
}

/* ---- Page header -------------------------------------------------------------------------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px 24px; margin-bottom: 24px; }
.page-head > div:first-child { min-width: 0; flex: 1 1 420px; }
.page-head h1 { font-size: 26px; line-height: 1.2; font-weight: 600; letter-spacing: -.015em; margin: 0; }
.page-head .lede { color: var(--ink-2); margin: 8px 0 0; max-width: 72ch; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (max-width: 560px) { .page-head h1 { font-size: 22px; } }

/* ---- Controls ------------------------------------------------------------------------------ */
button, .button {
  font: inherit; font-size: 14px; font-weight: 500; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-xs); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .12s, border-color .12s, color .12s, box-shadow .12s;
}
button:hover, .button:hover { background: var(--surface-2); border-color: var(--line-3); text-decoration: none; }
button:disabled { opacity: .55; cursor: default; }
button svg.i, .button svg.i { width: 16px; height: 16px; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
button.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
button.small, .button.small { height: 30px; padding: 0 10px; font-size: 13px; gap: 5px; }
button.danger { color: var(--error); }
button.danger:hover { background: var(--error-bg); border-color: var(--error-bg); }
button.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-2); }
button.ghost:hover { background: var(--surface-3); color: var(--ink); }
button.icon-only { width: 32px; padding: 0; }
button.link { border: 0; background: none; box-shadow: none; color: var(--link); padding: 0 4px; height: auto; }

input, select, textarea {
  font: inherit; font-size: 14px; color: var(--ink); background-color: var(--field);
  border: 1px solid var(--line-2); border-radius: var(--radius); height: 38px; padding: 0 12px; min-width: 0;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: var(--line-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus-ring); }
select {
  appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: var(--chevron); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
select:disabled { opacity: .55; cursor: default; }
input[type="search"] { padding-left: 36px; background-image: var(--magnifier); background-repeat: no-repeat; background-position: 11px center; background-size: 16px; }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; margin: 0; accent-color: var(--brand); box-shadow: none; cursor: pointer; }
textarea { height: auto; padding: 9px 12px; line-height: 1.45; resize: vertical; }
label.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

/* ---- Surfaces ------------------------------------------------------------------------------ */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.panel.flush { overflow: hidden; }
.panel-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel-bar .grow { flex: 1 1 220px; }
.panel-bar .push { margin-left: auto; }
.panel-bar label.field { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; padding: 16px 18px 0; }
.panel-head h2 { font-size: 15px; font-weight: 600; margin: 0; }
.panel-head p { color: var(--ink-3); font-size: 13px; margin: 2px 0 0; flex-basis: 100%; }
.panel-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.empty { padding: 48px 16px; text-align: center; color: var(--ink-2); }
.empty svg.i { width: 28px; height: 28px; color: var(--ink-3); display: block; margin: 0 auto 10px; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  display: grid; gap: 4px; align-content: start; justify-content: stretch; justify-items: start; text-align: left;
  height: auto; padding: 16px 18px; white-space: normal; line-height: 1.4; font-weight: 400;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.stat .label { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-2); font-size: 13px; font-weight: 500; }
.stat .label svg.i { width: 16px; height: 16px; color: var(--ink-3); }
.stat .value { font-size: 30px; font-weight: 600; line-height: 1.15; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--ink-3); font-size: 12.5px; }
button.stat:hover { background: var(--surface); border-color: var(--line-3); }
button.stat[aria-pressed="true"] { border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus-ring); }
.stat.alert { background: var(--warn-bg); border-color: var(--warn-line); }
.stat.alert .label, .stat.alert .label svg.i, .stat.alert .value { color: var(--warn); }
button.stat.alert:hover { background: var(--warn-bg); border-color: var(--warn); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
table.wide { min-width: 900px; }
th {
  text-align: left; font-weight: 500; font-size: 12px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-3); background: var(--surface-2); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td, tbody tr.hover:hover td { background: var(--hover); }
td.empty { padding: 48px 16px; }

/* At phone width a table turns into one card per row, each value under its column's name. */
@media (max-width: 760px) {
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards.wide { min-width: 0; }
  table.cards thead { display: none; }
  table.cards tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  table.cards tbody tr:last-child { border-bottom: 0; }
  table.cards td { position: relative; padding: 4px 0 4px 124px; border: 0; min-height: 28px; }
  table.cards td::before { content: attr(data-label); position: absolute; left: 0; top: 5px; width: 112px; color: var(--ink-3); font-size: 12.5px; }
  table.cards td[data-label=""], table.cards td[colspan] { padding-left: 0; }
  table.cards td[data-label=""]::before, table.cards td[colspan]::before { content: none; }
  table.cards td.num { white-space: normal; }
  table.cards tr.click:hover, table.cards tr.hover:hover { background: var(--hover); }
  table.cards tr.click:hover td, table.cards tr.hover:hover td { background: none; }
}

/* Status pills: Valid is quiet; only due and expired draw the eye. */
.status {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-weight: 500; font-size: 12.5px; line-height: 1.3; border-radius: 999px; padding: 3px 10px 3px 8px; border: 1px solid transparent;
}
.status svg { width: 14px; height: 14px; }
.status.ok { color: var(--ink-2); background: var(--surface-3); }
.status.soon { color: var(--warn); border-color: var(--warn-line); }
.status.expired { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.chip {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-3); background: var(--surface-3); padding: 3px 8px; border-radius: 6px;
}
.tag { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-2); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.tag svg.i { width: 13px; height: 13px; color: var(--ink-3); }

details.more summary { cursor: pointer; color: var(--link); font-size: 13px; list-style: none; display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: ""; width: 7px; height: 7px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg) translateY(-2px); transition: transform .12s; }
details.more[open] summary::after { transform: rotate(-135deg) translateX(-2px); }
details.more ul { margin: 8px 0 0; padding-left: 18px; color: var(--ink-2); display: grid; gap: 2px; }

/* ---- Dialogs ------------------------------------------------------------------------------- */
/* No flexbox here: older Safari collapses a flex child of an auto-height dialog to nothing. The dialog
   scrolls as a whole and the footer sticks to its bottom edge instead. */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(600px, calc(100vw - 24px)); max-height: calc(100vh - 48px);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); overflow-y: auto; overscroll-behavior: contain;
}
dialog[open] { animation: dlg-in .16s ease-out; }
dialog::backdrop { background: rgba(4, 18, 30, .5); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }
dialog > form { display: block; margin: 0; }
.dlg-head { padding: 22px 24px 0; }
.dlg-head h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.dlg-head p { margin: 6px 0 0; color: var(--ink-2); }
.dlg-body { padding: 18px 24px 22px; display: grid; gap: 16px; }
.dlg-foot {
  position: sticky; bottom: 0; z-index: 1;
  display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--line); background: var(--surface-2);
}
dialog label { display: grid; gap: 6px; color: var(--ink); font-size: 13px; font-weight: 500; }
dialog label.check { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 400; }
dialog input, dialog select, dialog textarea { width: 100%; }
dialog input[type="checkbox"] { width: 16px; }
.hint { color: var(--ink-3); font-size: 12.5px; font-weight: 400; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } .dlg-head, .dlg-body, .dlg-foot { padding-left: 18px; padding-right: 18px; } }
.form-error { color: var(--error); background: var(--error-bg); border-radius: var(--radius); padding: 10px 12px; margin: 0; }
.code {
  font: 500 34px/1.2 var(--mono); letter-spacing: .14em; text-align: center; padding: 20px 16px;
  background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: 12px; user-select: all; color: var(--ink);
}
ol.steps { margin: 0; padding-left: 20px; color: var(--ink-2); display: grid; gap: 6px; }

/* Brief confirmation at the bottom of the screen */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  display: inline-flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  background: #0b1b26; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px;
  animation: dlg-in .16s ease-out;
}
.toast svg.i { color: #9dc3de; }

/* Phone width: two stat cards a row, and filters that fill the row. Last, so they win. */
@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .value { font-size: 24px; }
  .panel-bar.panel-bar > select, .panel-bar.panel-bar > input:not([type="checkbox"]), .panel-bar.panel-bar > label.field { flex: 1 1 140px; max-width: none; width: auto; }
  .panel-bar > label.field input { flex: 1; min-width: 0; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
