/* DigiCare management portal.
   Light and dark are both selected, not an automatic inversion: the dark
   series colours are the same hues re-stepped for the dark surface, and
   each set was validated against the surface it renders on. */

:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;   /* cards, table rows */
  --plane:          #f9f9f7;   /* page behind the cards */
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);

  --series-1:       #2a78d6;   /* blue   */
  --series-2:       #eb6834;   /* orange */
  --series-3:       #1baf7a;   /* aqua   */

  --seq-250:        #86b6ef;
  --seq-450:        #2a78d6;

  --good:           #0ca30c;
  --warning:        #fab219;
  --serious:        #ec835a;
  --critical:       #d03b3b;
  --success-text:   #006300;

  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --plane:          #0d0d0d;
    --text-primary:   #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);

    --series-1:       #3987e5;
    --series-2:       #d95926;
    --series-3:       #199e70;

    --seq-250:        #184f95;
    --seq-450:        #3987e5;

    --success-text:   #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --plane:          #0d0d0d;
  --text-primary:   #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);
  --series-1:       #3987e5;
  --series-2:       #d95926;
  --series-3:       #199e70;
  --seq-250:        #184f95;
  --seq-450:        #3987e5;
  --success-text:   #0ca30c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-in {
  max-width: 1280px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  min-height: 56px;
}
.brand { font-weight: 650; letter-spacing: -0.01em; }
.brand-dim { color: var(--text-muted); font-weight: 400; }
.env-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 5px;
  background: var(--warning); color: #0b0b0b;
}
.nav { display: flex; gap: 2px; flex-wrap: wrap; margin-left: 8px; }
.nav a {
  padding: 7px 11px; border-radius: 7px;
  color: var(--text-secondary); font-weight: 500;
}
.nav a:hover { background: var(--plane); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--plane); color: var(--text-primary); font-weight: 600; }
.who {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--text-secondary);
}
.who-name { font-weight: 550; color: var(--text-primary); }
.role-chip {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 2px 7px; border-radius: 5px; font-weight: 700;
  border: 1px solid var(--border); color: var(--text-secondary);
}
.role-admin  { color: var(--series-2); }
.role-editor { color: var(--series-1); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }

/* ---------- headings ---------- */
h1 { font-size: 22px; margin: 4px 0 2px; letter-spacing: -0.015em; }
h2 { font-size: 16px; margin: 0 0 12px; letter-spacing: -0.01em; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--text-secondary); font-weight: 600; }
.sub { color: var(--text-secondary); margin: 0 0 18px; font-size: 14px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* ---------- stat tiles ----------
   Proportional figures: tabular-nums gives every digit the width of a
   zero, which makes a value like 121 look loose at tile sizes. Tabular
   is kept for table columns, where vertical alignment matters. */
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.tile-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.tile-value { font-size: 28px; font-weight: 640; letter-spacing: -0.02em; line-height: 1.1; }
.tile-note  { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.hero { font-size: 48px; font-weight: 650; letter-spacing: -0.03em; line-height: 1; }

/* ---------- bar rows ----------
   A 2px surface gap sits between the fill and the track edge so adjacent
   fills never touch. The value is always printed: three light-mode
   series colours fall below 3:1 on this surface, which obliges a visible
   label rather than relying on the bar. */
.bar-row {
  display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto;
  gap: 10px; align-items: center; padding: 3px 0;
}
.bar-label {
  font-size: 13px; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-track {
  background: var(--grid); border-radius: 5px; height: 14px;
  padding: 2px; overflow: hidden;
}
.bar-fill {
  height: 10px; border-radius: 4px; min-width: 3px;
  transition: width 140ms ease-out;
}
.bar-value {
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  min-width: 58px; text-align: right;
}

/* ---------- sparkline-ish day columns ---------- */
.days { display: flex; align-items: flex-end; gap: 2px; height: 90px; margin-top: 6px; }
.day-col { flex: 1 1 0; min-width: 2px; display: flex; flex-direction: column; justify-content: flex-end; }
.day-bar { background: var(--series-1); border-radius: 3px 3px 0 0; min-height: 2px; }
.day-axis {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-muted); margin-top: 6px;
  border-top: 1px solid var(--baseline); padding-top: 4px;
}

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); }
th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: 650; white-space: nowrap;
}
th a { color: var(--text-muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--plane); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.empty { padding: 28px 10px; text-align: center; color: var(--text-muted); }

/* ---------- forms ---------- */
label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=search], select {
  width: 100%; padding: 8px 10px; font: inherit; font-size: 14px;
  color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--baseline); border-radius: 7px;
}
input:focus, select:focus { outline: 2px solid var(--series-1); outline-offset: 1px; border-color: var(--series-1); }
input[readonly] { background: var(--plane); color: var(--text-muted); }
.field { margin-bottom: 12px; }
.filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }

.btn {
  display: inline-block; padding: 8px 14px; font: inherit; font-size: 14px;
  font-weight: 550; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--baseline); background: var(--surface-1); color: var(--text-primary);
}
.btn:hover { background: var(--plane); text-decoration: none; }
.btn-primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn-primary:hover { filter: brightness(0.94); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- date presets ---------- */
.presets { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.presets a {
  font-size: 13px; padding: 5px 10px; border-radius: 6px;
  color: var(--text-secondary); border: 1px solid transparent;
}
.presets a:hover { background: var(--surface-1); text-decoration: none; }
.presets a.on {
  background: var(--surface-1); border-color: var(--border);
  color: var(--text-primary); font-weight: 600;
}
.presets a.on::before { content: "✓ "; font-weight: 700; }

/* ---------- alerts & notes ---------- */
.alert { border-radius: var(--radius); padding: 11px 14px; margin-bottom: 16px; font-size: 14px; }
.alert p { margin: 2px 0; }
.alert-bad { background: color-mix(in srgb, var(--critical) 12%, var(--surface-1)); border: 1px solid var(--critical); }
.alert-ok  { background: color-mix(in srgb, var(--good) 12%, var(--surface-1)); border: 1px solid var(--good); }
.note {
  font-size: 13px; color: var(--text-secondary);
  border-left: 3px solid var(--baseline); padding: 2px 0 2px 11px; margin: 10px 0;
}
.note-warn { border-left-color: var(--warning); }
.pill {
  display: inline-block; font-size: 11px; font-weight: 650; padding: 2px 7px;
  border-radius: 5px; border: 1px solid var(--border); color: var(--text-secondary);
}
.pill-digicare { color: var(--series-1); border-color: var(--series-1); }
.pill-inspire  { color: var(--series-2); border-color: var(--series-2); }
.pill-unattributed { color: var(--text-muted); }

/* ---------- legend ---------- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- pagination ---------- */
.pager { display: flex; gap: 6px; align-items: center; margin-top: 14px; font-size: 13px; flex-wrap: wrap; }
.pager a, .pager span { padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border); }
.pager .cur { background: var(--series-1); border-color: var(--series-1); color: #fff; font-weight: 600; }

/* ---------- login ---------- */
.login-wrap { max-width: 380px; margin: 9vh auto; padding: 0 16px; }
.login-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 26px; }

/* ---------- footer ---------- */
.foot {
  max-width: 1280px; margin: 0 auto; padding: 18px 16px 34px;
  font-size: 12px; color: var(--text-muted);
  display: flex; gap: 8px; flex-wrap: wrap;
}

@media (max-width: 640px) {
  .topbar-in { padding: 8px 16px; }
  .who { width: 100%; margin-left: 0; }
  .nav { margin-left: 0; }
  .bar-row { grid-template-columns: minmax(78px, 1fr) 1fr auto; }
  .tile-value { font-size: 24px; }
  .hero { font-size: 36px; }
}

@media print {
  .topbar, .presets, .btn, .btn-row, .pager { display: none; }
  .card, .tile { border-color: #999; break-inside: avoid; }
}
