/* ─── Sentinel Design System ─────────────────────────────────────────────
 * Single source of truth for all Sentinel Node Tester pages.
 * Canon: Plan Manager DESIGN-GUIDELINES.md (2026-04-23).
 * Deviations require explicit justification in commit message.
 * ──────────────────────────────────────────────────────────────────────── */

/* Noto Sans Mono — Plan Manager canon mono family. @import must precede all
 * @font-face and rule blocks, so this lives at the very top. */
@import url('https://cdn.jsdelivr.net/npm/@fontsource/noto-sans-mono@5.0.0/400.css');

/* ─── Fonts ───
 * Plan Manager canon (public/design-tokens.md):
 *   Europa Bold (700, self-hosted) → entire UI, headings forced via !important.
 *   Noto Sans Mono (jsDelivr @import above) → machine strings (addresses,
 *   hashes, denoms, log output). Exposed via var(--font-mono) and .mono.
 * !important on the universal + heading rules neutralises legacy inline
 * font-family declarations that pre-date the canon migration.
 */
@font-face {
  font-family: 'Europa';
  src: url('/fonts/europa-bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ─── Tokens ───
 * Canon: Plan Manager public/index.html DESIGN-GUIDELINES (2026-04-23).
 * Values match PM 1:1 — Sentinel blue accent, softened near-black bg,
 * real semantic colours. Every rule below references a var — never raw rgba.
 */
:root {
  /* Surface */
  --bg: #060608;
  --bg-base: #060608;
  --bg-card: rgba(16, 16, 20, 0.72);
  --bg-card-solid: #0d0d12;
  --bg-card-hover: rgba(26, 26, 34, 0.82);
  --bg-input: rgba(255, 255, 255, 0.025);
  --glass-bg: rgba(14, 14, 20, 0.82);

  /* Border */
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.18);

  /* Text */
  --text: #f0f1f5;
  --text-dim: #8a8a9a;
  --text-muted: #55556a;

  /* Accent — Sentinel blue */
  --accent: #1E88E5;
  --accent-bright: #4aa4ec;
  --accent-hover: #4aa4ec;
  --accent-glow: rgba(30, 136, 229, 0.18);
  --accent-dim: rgba(30, 136, 229, 0.12);

  /* Semantic status */
  --green: #00c853;
  --green-bright: #00e676;
  --green-dim: rgba(0, 200, 83, 0.14);
  --red: #ff1744;
  --red-bright: #ff4569;
  --red-dim: rgba(255, 23, 68, 0.12);
  --yellow: #ff9100;
  --yellow-bright: #ffab40;
  --yellow-dim: rgba(255, 145, 0, 0.14);
  --purple: #b388ff;
  --purple-dim: rgba(179, 136, 255, 0.14);

  /* Radii */
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 4px;

  /* Layout */
  --sidebar-w: 272px;
  --header-h: 84px;

  /* Elevation */
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.30);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
  --shadow-accent: 0 0 32px rgba(30, 136, 229, 0.22);
  --shadow-green: 0 0 28px rgba(0, 200, 83, 0.22);

  /* Fonts — Plan Manager canon: Europa (display), Noto Sans Mono (machine strings) */
  --font-display: 'Europa', -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-serif:   'Europa', -apple-system, 'Segoe UI', sans-serif;
  --font-mono:    'Noto Sans Mono', 'Liberation Mono', Consolas, ui-monospace, monospace;
}

html[data-theme="light"] {
  /* Light values from Plan Manager DESIGN-GUIDELINES table */
  --bg: #f6f7fb;
  --bg-base: #f6f7fb;
  --bg-card: rgba(255, 255, 255, 0.92);
  --bg-card-solid: #ffffff;
  --bg-card-hover: #f1f3f9;
  --bg-input: rgba(10, 14, 30, 0.04);
  --glass-bg: rgba(255, 255, 255, 0.85);

  --border: rgba(10, 14, 30, 0.08);
  --border-hover: rgba(10, 14, 30, 0.16);
  --border-strong: rgba(10, 14, 30, 0.22);

  --text: #0d1224;
  --text-dim: #4a5068;
  --text-muted: #8a90a5;

  --accent: #1E88E5;
  --accent-bright: #1d78cc;
  --accent-hover: #1d78cc;
  --accent-glow: rgba(30, 136, 229, 0.12);
  --accent-dim: rgba(30, 136, 229, 0.08);

  --green: #00944a;
  --green-bright: #00a656;
  --green-dim: rgba(0, 148, 74, 0.10);
  --red: #d81b3f;
  --red-bright: #b01635;
  --red-dim: rgba(216, 27, 63, 0.10);
  --yellow: #d97706;
  --yellow-bright: #b25f05;
  --yellow-dim: rgba(217, 119, 6, 0.12);
  --purple: #7c4dff;
  --purple-dim: rgba(124, 77, 255, 0.10);

  --shadow: 0 4px 16px rgba(10, 14, 30, 0.06);
  --shadow-sm: 0 2px 8px rgba(10, 14, 30, 0.06);
  --shadow-md: 0 8px 24px rgba(10, 14, 30, 0.10);
  --shadow-lg: 0 20px 50px rgba(10, 14, 30, 0.14);
  --shadow-accent: 0 0 28px rgba(30, 136, 229, 0.18);
  --shadow-green: 0 0 24px rgba(0, 148, 74, 0.16);
}

/* ─── Reset ─── */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* Europa Bold is the single UI typeface. Europa has only a 700 cut, so every
 * element is clamped to weight 700 and font-synthesis is disabled to stop the
 * browser from fake-bolding or fake-regularizing. !important mirrors Plan
 * Manager (public/index.html:117) so legacy inline font-family declarations
 * can't leak through. Mono elements stay mono. */
*, *::before, *::after {
  font-family: 'Europa', -apple-system, 'Segoe UI', Roboto, sans-serif !important;
  font-weight: 700;
  font-synthesis: none;
}
.page-hero-title, .page-hero-title *, h1, h2, h3 {
  font-family: 'Europa', -apple-system, 'Segoe UI', sans-serif !important;
  font-weight: 700 !important;
}
code, pre, kbd, samp, .mono, .mono-inline, .mono-tag {
  font-family: var(--font-mono) !important;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-image:
    radial-gradient(1000px 600px at 75% -10%, var(--accent-glow), transparent 55%),
    radial-gradient(800px 500px at -10% 110%, var(--accent-dim), transparent 55%);
  background-attachment: fixed;
}

/* ─── Type scale helpers ─── */
.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.text-base { font-size: 13px; }
.text-md { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 22px; }
.text-2xl { font-size: 26px; }
.text-hero { font-size: 44px; line-height: 1.1; letter-spacing: -0.02em; }
.text-hero-xl { font-size: 54px; line-height: 1.08; letter-spacing: -0.02em; }

/* Mono */
.mono,
.mono-inline {
  font-family: var(--font-mono);
  font-feature-settings: 'tnum' 1, 'calt' 0;
}

.mono-tag {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  line-height: 1;
  white-space: nowrap;
}
.mono-tag-blue { background: var(--accent-dim); border-color: var(--accent-dim); color: var(--accent-bright); }
.mono-tag-green { background: var(--green-dim); border-color: var(--green-dim); color: var(--green); }
.mono-tag-red { background: var(--red-dim); border-color: var(--red-dim); color: var(--red); }
.mono-tag-yellow { background: var(--yellow-dim); border-color: var(--yellow-dim); color: var(--yellow); }

/* ─── Links ─── */
a {
  color: var(--accent-bright);
  text-decoration: none;
  transition: color 150ms ease-out;
}
a:hover { color: var(--accent); }

/* ─── Focus ring (WCAG 2.2 SC 1.4.11) ─── */
*:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-glow);
  border-color: var(--accent) !important;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 150ms ease-out, border-color 150ms ease-out, color 150ms ease-out, transform 150ms ease-out, box-shadow 150ms ease-out;
  text-decoration: none;
  user-select: none;
  white-space: nowrap;
}
.btn:disabled,
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }

/* Primary = Sentinel blue fill, white text in both themes. */
.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.btn-green,
.btn-success {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}
.btn-green:hover:not(:disabled),
.btn-success:hover:not(:disabled) {
  background: var(--green-bright);
  border-color: var(--green-bright);
  box-shadow: var(--shadow-green);
}

.btn-red,
.btn-danger {
  background: var(--red);
  color: #ffffff;
  border-color: var(--red);
}
.btn-red:hover:not(:disabled),
.btn-danger:hover:not(:disabled) {
  background: var(--red-bright);
  border-color: var(--red-bright);
}

.btn-yellow {
  background: var(--yellow);
  color: #0d1224;
  border-color: var(--yellow);
}
.btn-yellow:hover:not(:disabled) {
  background: var(--yellow-bright);
  border-color: var(--yellow-bright);
}

.btn-outline-red {
  background: transparent;
  color: var(--red);
  border-color: var(--red-dim);
}
.btn-outline-red:hover:not(:disabled) {
  background: var(--red-dim);
  border-color: var(--red);
  color: var(--red);
}

.btn-sm {
  font-size: 11px;
  padding: 6px 12px;
  border-radius: var(--radius-xs);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  border-color: var(--border);
}
.btn-icon:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.btn-block { width: 100%; }

/* ─── Inputs ─── */
input[type=text],
input[type=password],
input[type=number],
input[type=email],
input[type=search],
select,
textarea {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  outline: none;
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
  width: 100%;
}
input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}
input:hover,
select:hover,
textarea:hover {
  border-color: var(--border-hover);
}

label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-family: var(--font-display);
}

/* ─── Cards ─── */
.card,
.glass-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color 200ms ease-out, transform 200ms ease-out;
}
.card-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-body { padding: 22px; }
.card-body.tight { padding: 16px 18px; }

/* ─── Callouts ─── */
.callout {
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid;
  font-size: 13px;
  line-height: 1.6;
}
.callout-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 4px;
}
.callout-body {
  color: var(--text-dim);
  font-size: 12.5px;
}
.callout-info {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: var(--text);
}
.callout-info .callout-title { color: var(--accent-bright); }
.callout-warn {
  background: var(--yellow-dim);
  border-color: var(--yellow-dim);
  color: var(--text);
}
.callout-warn .callout-title { color: var(--yellow); }
.callout-error,
.callout-danger {
  background: var(--red-dim);
  border-color: var(--red-dim);
  color: var(--text);
}
.callout-error .callout-title,
.callout-danger .callout-title { color: var(--red); }

/* ─── Stat cards ─── */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color 200ms ease-out;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-card:hover { border-color: var(--border-hover); }
.stat-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.stat-value.sm { font-size: 18px; }
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-value.blue { color: var(--accent-bright); }
.stat-value.yellow { color: var(--yellow); }
.stat-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Badges / chips ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
}
.badge-green { background: var(--green-dim); color: var(--green); border: 1px solid var(--green-dim); }
.badge-red { background: var(--red-dim); color: var(--red); border: 1px solid var(--red-dim); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); border: 1px solid var(--yellow-dim); }
.badge-blue,
.badge-public { background: var(--accent-dim); color: var(--accent-bright); border: 1px solid var(--accent-dim); }
.badge-neutral { background: var(--bg-input); color: var(--text-dim); border: 1px solid var(--border); }

/* ─── Status dots ─── real semantic colours */
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.dot-green { background: var(--green); box-shadow: 0 0 6px rgba(0, 200, 83, 0.45); }
.dot-red { background: var(--red); box-shadow: 0 0 6px rgba(255, 23, 68, 0.45); }
.dot-yellow { background: var(--yellow); box-shadow: 0 0 6px rgba(255, 145, 0, 0.45); }
.dot-blue { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.dot-pulse { animation: sentinel-pulse 2s infinite; }

@keyframes sentinel-pulse {
  0%   { transform: scale(0.92); opacity: 1; }
  50%  { transform: scale(1.08); opacity: 0.75; }
  100% { transform: scale(0.92); opacity: 1; }
}

/* ─── Tables ─── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  text-align: left;
  color: var(--text-dim);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-input);
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tbody tr:hover td { background: var(--bg-card-hover); }
tbody tr:last-child td { border-bottom: none; }

/* ─── Scrollbars ─── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ─── Utility ─── */
.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.dimmed { color: var(--text-muted); }
.accent { color: var(--accent-bright); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ─── Reduced motion (MANDATORY) ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── Skeleton rows ─── */
.skel-bar {
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--border) 50%, var(--bg-input) 75%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.2s ease-in-out infinite;
  height: 10px;
  border-radius: 4px;
}
@keyframes skel-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.skel-row td { padding: 14px 12px; }

/* ─── Reduced transparency ─── */
@media (prefers-reduced-transparency: reduce) {
  .card,
  .glass-panel,
  .stat-card { backdrop-filter: none; background: var(--bg-card-solid); }
}

/* ─── Boot gate (zero flash) ─── */
body.boot-pending > *:not(.boot-splash) { visibility: hidden; }
body.boot-pending::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
  background-image:
    radial-gradient(1000px 600px at 75% -10%, var(--accent-glow), transparent 55%),
    radial-gradient(800px 500px at -10% 110%, var(--accent-dim), transparent 55%);
}

/* Country flag images (served from flagcdn.com as SVG to preserve each
   country's native aspect ratio — Nepal is non-rectangular, Qatar is 28:11,
   Switzerland/Vatican are 1:1, etc. Rendered as <img> because Windows
   Chrome/Edge don't draw regional-indicator emoji as flag glyphs. */
.flag-img {
  display: inline-block;
  height: 14px;
  width: auto;
  max-width: 24px;
  vertical-align: -2px;
  border-radius: 2px;
  margin-right: 6px;
  box-shadow: 0 0 0 1px var(--border) inset;
}
