/* Krindam console — "Tactical" theme.
   Deep-space navy, ghost borders, monospaced data. Self-contained, no CDN
   (works offline on the on-prem box). Font STACKS prefer the design fonts if
   present on the machine and fall back to system fonts otherwise.
   ponytail: to guarantee Geist/Inter/JetBrains Mono, vendor woff2 into
   /static/fonts and add @font-face here — a stack is enough for the look today. */

:root {
  color-scheme: dark;                 /* native date pickers / selects render dark */

  --bg: #0b1326;                      /* deep-space background / surface */
  --panel: #171f33;                   /* surface-container — cards, rows */
  --panel-low: #131b2e;               /* surface-container-low — inputs */
  --panel-high: #222a3d;              /* surface-container-high — hover/raised */
  --panel-bright: #2d3449;            /* surface-variant — chart tracks, avatars */

  --line: rgba(255, 255, 255, .08);   /* ghost border — the primary structure */
  --line-strong: #2d3449;             /* solid divider when a hairline won't read */

  --text: #dae2fd;                    /* on-surface */
  --muted: #c1c6d7;                   /* on-surface-variant */
  --faint: #8b90a0;                   /* outline — de-emphasised meta */

  --primary: #adc6ff;                 /* active states, links, primary action */
  --on-primary: #002e69;              /* text on a primary fill */
  --primary-strong: #4b8eff;

  --high: #ef6719;                    /* HIGH risk / elevated — energetic orange */
  --danger: #ffb4ab;                  /* CRITICAL / errors / destructive — coral */
  --ok: #7fd1a4;                      /* healthy / operational — calm green */
  --accent: var(--primary);           /* alias — focus rings / CTAs referenced --accent (was undefined) */

  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, Menlo, monospace;

  --r-sm: 4px;                        /* tags, buttons — sharp, precise */
  --r: 8px;                           /* cards, inputs — soft-rectilinear */
  --r-pill: 999px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --- Top navigation ------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 19, 38, .7);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: .2px;
  color: var(--text);
  text-decoration: none;
}
.brand .mark {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
  font-size: .85rem;
}

nav { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: .82rem;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  transition: color .15s, background .15s;
}
nav a:hover { color: var(--text); background: rgba(255, 255, 255, .05); }
nav a.active { color: var(--primary); background: rgba(173, 198, 255, .10); }

/* Administration dropdown: native <details>/<summary> so it works with NO
   JavaScript (offline/air-gap safe) and stays keyboard- + touch-accessible. */
.admin-menu { position: relative; }
.admin-menu > summary {
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-size: .82rem;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  transition: color .15s, background .15s;
  user-select: none;
}
.admin-menu > summary::-webkit-details-marker { display: none; }
.admin-menu > summary::after { content: " ▾"; opacity: .7; }
.admin-menu > summary:hover { color: var(--text); background: rgba(255, 255, 255, .05); }
.admin-menu > summary.active { color: var(--primary); background: rgba(173, 198, 255, .10); }
.admin-menu-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  margin-top: 6px;
  min-width: 160px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel, rgba(11, 19, 38, .98));
}
/* On a roomy viewport the panel floats over content like a real menu; on a
   narrow (mobile) viewport it stacks inline so nothing is clipped off-screen. */
@media (min-width: 720px) {
  .admin-menu[open] > .admin-menu-panel {
    position: absolute;
    right: 0;
    z-index: 60;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  }
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 32px; }

/* --- Typography ---------------------------------------------------------- */
h1 {
  font-weight: 600;
  font-size: 1.9rem;
  letter-spacing: -.01em;
  margin: 0 0 6px;
}
h2 {
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -.005em;
  margin: 28px 0 14px;
}

.muted { color: var(--muted); }
.info { cursor: help; opacity: .55; font-size: .85em; margin-left: .25rem; }
.info:hover, .info:focus { opacity: 1; }
.digest { font-size: .82rem; margin-top: 2px; }
.crumb { margin: 0 0 10px; font-size: .85rem; }
.crumb a, .host a, .details a, td a { color: var(--primary); text-decoration: none; }
.crumb a:hover, .host a:hover, td a:hover { text-decoration: underline; }

.error {
  color: var(--danger);
  border: 1px solid rgba(255, 180, 171, .35);
  border-radius: var(--r);
  padding: 10px 14px;
  background: rgba(255, 180, 171, .08);
  font-size: .9rem;
}
.empty { color: var(--faint); padding: 24px 0; }

/* --- Cards --------------------------------------------------------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 28px;
  margin-bottom: 24px;
}
.login { max-width: 400px; margin: 10vh auto 0; }
.login label, .field label {
  display: block;
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 14px 0 6px;
}

/* --- Inputs / selects / buttons ----------------------------------------- */
input, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-low);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--text);
  font-family: var(--sans);
  font-size: .95rem;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus {
  outline: none;
  border-color: transparent;
  box-shadow: 0 0 0 2px var(--primary);
}

button {
  margin-top: 4px;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: var(--r-sm);
  padding: 10px 18px;
  font-family: var(--sans);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, background .15s;
}
button:hover { filter: brightness(1.08); }
button.danger { background: transparent; color: var(--danger); border: 1px solid rgba(255, 180, 171, .35); }
button.danger:hover { background: rgba(255, 180, 171, .10); filter: none; }

/* Login/policy field spacing */
.field { margin: 12px 0; }
.field input, .field select { max-width: 360px; }

/* Inline action forms (policy watchlist) */
.actions { white-space: nowrap; }
.inline { display: inline; }
.inline button {
  margin-top: 0; margin-right: 6px; padding: 5px 12px; font-size: .78rem;
  background: transparent; color: var(--muted); border: 1px solid var(--line);
}
.inline button:hover { color: var(--text); background: rgba(255, 255, 255, .05); filter: none; }

/* Add / filter rows */
.add, .filters { display: flex; gap: 10px; align-items: center; margin: 16px 0; flex-wrap: wrap; }
.add input, .filters input { width: auto; min-width: 200px; }
.add button, .filters button { margin-top: 0; }
.filters .clear, .clear { color: var(--muted); font-size: .82rem; text-decoration: none; }
.filters .clear:hover, .clear:hover { color: var(--primary); }

/* --- Tables -------------------------------------------------------------- */
.grid { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: .9rem; }
.grid th {
  text-align: left;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--faint);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.grid td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr.clickable { cursor: pointer; }
.grid tbody tr:hover { background: var(--panel-high); }
.ts { color: var(--faint); white-space: nowrap; font-family: var(--mono); font-size: .82rem; }
.details { color: var(--muted); }
.host a { font-weight: 500; }

/* --- Pills / status chips ------------------------------------------------ */
.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  font-family: var(--mono);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
}
.pill-active { color: var(--ok); background: rgba(127, 209, 164, .10); border-color: rgba(127, 209, 164, .30); }
.pill-revoked { color: var(--faint); background: rgba(255, 255, 255, .04); border-color: var(--line); }
.sev-high { color: var(--danger); background: rgba(255, 180, 171, .10); border-color: rgba(255, 180, 171, .30); }
.sev-medium { color: var(--high); background: rgba(239, 103, 25, .12); border-color: rgba(239, 103, 25, .30); }
.sev-info { color: var(--faint); }

/* --- Connection liveness (distinct from access status; feedback items 8 & 9) ------------- */
/* Each pill carries its WORD too (templates render the label), so meaning is never colour-only. */
.conn-online { color: var(--ok); background: rgba(127, 209, 164, .10); border-color: rgba(127, 209, 164, .30); }
.conn-delayed { color: var(--high); background: rgba(239, 103, 25, .12); border-color: rgba(239, 103, 25, .30); }
.conn-offline { color: var(--danger); background: rgba(255, 180, 171, .10); border-color: rgba(255, 180, 171, .30); }
.conn-never { color: var(--faint); background: rgba(255, 255, 255, .04); border-color: var(--line); }
/* When used inline (Today statcard sub-line) rather than as a pill, keep the colour, drop the chrome. */
.statcard-sub { margin-top: 4px; font-size: .8rem; display: flex; gap: 10px; flex-wrap: wrap; }
.statcard-sub .conn-online, .statcard-sub .conn-delayed,
.statcard-sub .conn-offline, .statcard-sub .conn-never { background: none; border: none; padding: 0; }

/* --- Checkbox fields + sensitive warnings (policy editor) --------------------------------- */
.field label.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.field label.checkbox input { width: auto; margin: 0; }
p.warn, .warn { color: var(--high); }
p.warn strong { color: var(--danger); }

/* --- Risk score ---------------------------------------------------------- */
.risk { font-family: var(--mono); font-weight: 600; }
.risk-high { color: var(--high); }
.risk-mid, .risk-medium { color: var(--primary); }
.risk-low { color: var(--faint); }

/* --- Today: KPI stat row ------------------------------------------------- */
.stat-row { display: flex; gap: 24px; flex-wrap: wrap; margin: 20px 0 32px; }
.statcard {
  flex: 1 1 220px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 20px;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: background .15s;
}
.statcard:hover { background: var(--panel-high); }
.statcard-label {
  font-family: var(--mono);
  color: var(--faint);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 12px;
}
.statcard-value { font-size: 2.2rem; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.statcard-unit { color: var(--faint); font-size: .95rem; font-weight: 400; letter-spacing: 0; }
.risk-dots { display: flex; gap: 18px; font-size: 1.1rem; font-variant-numeric: tabular-nums; }

/* --- Sparklines ---------------------------------------------------------- */
.spark { display: flex; align-items: flex-end; gap: 5px; height: 44px; }
.spark-bar { flex: 1; min-height: 2px; background: var(--primary); border-radius: 2px 2px 0 0; opacity: .85; }
.spark-sm { display: inline-flex; height: 22px; width: 90px; gap: 3px; vertical-align: middle; }

/* --- Today: attention feed / activity timeline --------------------------- */
.attn { display: flex; flex-direction: column; gap: 10px; }
.attn-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--r);
  padding: 14px 18px;
  transition: background .15s;
}
.attn-card:hover { background: var(--panel-high); }
.attn-escalated { border-left-color: var(--danger); }
.attn-dot { font-size: 1.1rem; line-height: 1; }
.attn-text { flex: 1; }
.attn-actions { white-space: nowrap; }
.attn-actions form { display: inline; }
.attn-actions button { margin: 0 0 0 6px; padding: 5px 12px; font-size: .8rem; }

/* 2-hour window heading + post-clear flash + per-person clear panel */
h3.window {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin: 18px 0 8px;
}
.flash {
  background: rgba(96, 165, 250, .12);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px 14px;
  margin: 12px 0;
}
.clear-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* --- Footer -------------------------------------------------------------- */
.foot {
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .03em;
  text-align: center;
  padding: 20px;
  margin-top: 40px;
}

@media (max-width: 640px) {
  .wrap { padding: 20px; }
  .topbar { padding: 12px 20px; }
  .stat-row { gap: 14px; }
  /* Wide data tables (Fleet/People/Devices/Transfers/Updates/Reports/Policy) are
     6-7 columns and overflow a ~390px phone. Make each .grid table its own
     horizontally-scrollable block so the page body never scrolls sideways and no
     column is clipped — the core daily screens stay usable on a phone/tablet. */
  .grid {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
}

/* Accessibility: visually-hidden text that screen readers still announce (e.g. a
   "high risk" label beside a colour dot, or a form field label). */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip-to-content link: off-screen until focused, then visible — lets a keyboard
   user jump past the ~9 nav links on every page. */
.skip {
  position: absolute;
  left: -999px; top: 0;
  background: var(--panel-high, #16223f);
  color: var(--text, #dae2fd);
  padding: 10px 16px;
  z-index: 1000;
  border-radius: 0 0 6px 0;
}
.skip:focus { left: 0; }

/* Visible keyboard focus everywhere (some resets strip the UA outline). */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent, #6ea8fe);
  outline-offset: 2px;
}

/* Respect a reduced-motion preference: drop transitions and the map's motion. */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
