:root {
  /* Brand palette — sourced from app.pointonenav.com tokens */
  --mine-shaft: #222222;
  --cerulean: #009de0;
  --cerulean-dark: #0075db;
  --point1-green: #19a866;
  --point1-green-dark: #148550;
  --lightning-yellow: #ffcc1d;
  --red-orange: #ff4c2d;
  --danger-red: #e22822;

  /* Surfaces (warm light theme to match app) */
  --bg: #ffffff;
  --bg-alt: #f6f6f4;
  --bg-soft: #f2f2f0;
  --bg-inverse: #141413;
  --border: #e7e7e4;
  --border-strong: #dededc;

  /* Text */
  --text: #0b0b0a;
  --text-muted: rgba(34, 34, 34, 0.65);
  --text-subtle: rgba(34, 34, 34, 0.5);

  /* Status surfaces */
  --good-bg: rgba(25, 168, 102, 0.10);
  --good-fg: var(--point1-green-dark);
  --warn-bg: rgba(255, 204, 29, 0.18);
  --warn-fg: #6b5400;
  --bad-bg: rgba(255, 76, 45, 0.10);
  --bad-fg: #b8311a;

  /* Misc */
  --radius: 12px;
  --radius-pill: 100px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 14px rgba(34, 34, 34, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font-sans: "Instrument Sans", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "Azeret Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.bg-station, .bg-admin { background: var(--bg); }

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

.muted { color: var(--text-muted); }
.small { font-size: 13px; }

/* ---------- Centered card layout (login screens) ---------- */
.card-screen {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(48px + var(--safe-top)) 22px calc(28px + var(--safe-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.brand { display: flex; flex-direction: column; align-items: center;
  gap: 14px; margin-bottom: 32px; text-align: center; }
.brand-logo { height: 60px; width: auto; display: block; }
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { font-size: 13px; color: var(--text-muted); }

/* ---------- Topbar (logged-in screens) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-title { font-weight: 600; font-size: 16px; max-width: 60vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  letter-spacing: -0.01em; }
.topbar-sub { font-size: 12px; color: var(--text-muted);
  font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.link-back { color: var(--text-muted); font-size: 14px; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--text-muted); }
.field input, .field textarea {
  width: 100%;
  font: inherit; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 14px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
.field input::placeholder { color: var(--text-subtle); }
.field input:focus, .field textarea:focus {
  border-color: var(--mine-shaft);
  box-shadow: 0 0 0 3px rgba(34, 34, 34, 0.08);
}
.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row input { flex: 1; }
.input-row .btn-icon { flex: 0 0 auto; }

/* ---------- Station locked (PIN-only login) ---------- */
.station-locked {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.station-locked-label {
  font-size: 12px; color: var(--text-muted);
  letter-spacing: 0.02em; margin-bottom: 2px;
}
.station-locked-cas {
  font-family: var(--font-mono); font-size: 15px; font-weight: 600;
  background: transparent; padding: 0;
}

/* ---------- Buttons ---------- */
.btn, .btn-ghost, .btn-icon, .btn-danger, .link-btn {
  font: inherit; cursor: pointer; border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background-color 120ms, color 120ms, border-color 120ms,
    transform 100ms;
}
.btn {
  border-radius: var(--radius-pill);
  padding: 13px 26px;
  font-weight: 500;
  font-size: 15px;
}
.btn-primary {
  background: var(--mine-shaft);
  color: #fff;
}
.btn-primary:hover { background: #000; }
.btn-primary:active { transform: translateY(1px); }
/* Prominent QR-scan CTA. Green tint distinguishes it from the standard
   primary submit button so users can find it at a glance. */
.btn-scan {
  width: 100%;
  background: var(--point1-green);
  color: #fff;
  padding: 16px 22px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.btn-scan:hover { background: var(--point1-green-dark); }
.btn-scan:active { transform: translateY(1px); }
.btn-scan svg { stroke-width: 2.2; }

/* "or enter manually" divider used on the station login screen. */
.form-or {
  display: flex; align-items: center; gap: 12px;
  color: var(--text-muted); font-size: 11px;
  letter-spacing: 0.08em; text-transform: uppercase;
  margin: 2px 0;
}
.form-or::before, .form-or::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.btn-ghost {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 500;
}
.btn-ghost:hover { background: var(--bg-alt); border-color: var(--border-strong); }
.btn-danger {
  background: var(--bg);
  color: var(--red-orange);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 500;
}
.btn-danger:hover { background: rgba(255, 76, 45, 0.06);
  border-color: rgba(255, 76, 45, 0.4); }
.btn-icon {
  background: var(--bg-alt); border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0 14px; min-width: 50px;
}
.btn-icon:hover { background: var(--border); }
.link-btn { background: transparent; border: none; padding: 0;
  color: var(--cerulean); font-size: inherit; }
.link-btn:hover { text-decoration: underline; }

.tiny-link { text-align: center; margin-top: 22px; font-size: 13px;
  color: var(--text-muted); }

/* ---------- Page layout ---------- */
.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 16px calc(36px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 14px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.card-header .card-title { margin-bottom: 0; }
.card-meta { font-size: 12px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px;
  border: 1px solid transparent; }
.alert-error { background: var(--bad-bg); color: var(--bad-fg);
  border-color: rgba(255, 76, 45, 0.25); }
.alert-ok { background: var(--good-bg); color: var(--good-fg);
  border-color: rgba(25, 168, 102, 0.25); }
.alert-info { background: rgba(0, 157, 224, 0.08); color: var(--cerulean-dark);
  border-color: rgba(0, 157, 224, 0.25); }

/* ---------- Pills & dots ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: var(--bg-alt); color: var(--text);
  font-weight: 500; letter-spacing: 0.02em; }
.pill-good { background: var(--good-bg); color: var(--good-fg); }
.pill-warn { background: var(--warn-bg); color: var(--warn-fg); }
.pill-bad  { background: var(--bad-bg); color: var(--bad-fg); }
/* ---------- Location card ---------- */
.location-coords {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  margin-bottom: 10px;
}
.location-map {
  width: 100%;
  height: 240px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}
.location-map iframe {
  width: 100%; height: 100%;
  border: 0; display: block;
}

/* ---------- CNO card ---------- */
.cno-header { display: flex; align-items: center;
  justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.cno-header .card-title { margin-bottom: 0; }
.band-selector {
  display: inline-flex; padding: 3px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 999px;
}
.band-btn {
  border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 6px 14px; border-radius: 999px;
  color: var(--text-muted);
  transition: background-color 120ms, color 120ms;
}
.band-btn:hover { color: var(--text); }
.band-btn.is-active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.cno-chart { display: flex; flex-direction: column; gap: 6px;
  min-height: 60px; }
.cno-empty { padding: 14px 0; text-align: center; }

.cno-row {
  display: grid;
  grid-template-columns: 70px 1fr 56px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.cno-sat { font-family: var(--font-mono); color: var(--text-muted);
  white-space: nowrap; }
.cno-bar-wrap {
  position: relative;
  height: 14px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.cno-bar {
  position: absolute; inset: 0 auto 0 0;
  border-radius: 999px;
  transition: width 240ms ease, background-color 120ms;
  background: var(--point1-green);
}
.cno-bar.warn { background: var(--lightning-yellow); }
.cno-bar.bad  { background: var(--red-orange); }
.cno-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  text-align: right; color: var(--text); }

.cno-meta { margin-top: 10px; min-height: 1.2em; text-align: right; }

/* ---------- Summary card (top of station view) ---------- */
.summary-card {
  padding: 24px 20px;
  text-align: center;
  border: 1px solid var(--border);
  transition: background-color 200ms, border-color 200ms, color 200ms;
}
.summary-headline {
  font-size: 28px; line-height: 1.15; font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}
.summary-message {
  font-size: 14px; line-height: 1.5;
  margin: 0 auto; max-width: 60ch;
  /* Lets the JS emit "\n\n" between paragraphs without resorting to
     innerHTML, since setSummary uses textContent. */
  white-space: pre-line;
}
.summary-details {
  font-size: 13px; line-height: 1.5;
  margin: 14px auto 0; max-width: 60ch;
  text-align: left;
  white-space: pre-line;
}
.summary-card[data-status="loading"] {
  background: var(--bg-soft);
  color: var(--text-muted);
}
.summary-card[data-status="loading"] .summary-headline { color: var(--text); }
.summary-card[data-status="pass"] {
  background: var(--good-bg);
  border-color: rgba(25, 168, 102, 0.35);
  color: var(--good-fg);
}
.summary-card[data-status="fail"] {
  background: var(--bad-bg);
  border-color: rgba(255, 76, 45, 0.4);
  color: var(--bad-fg);
}

/* ---------- Quality cards ---------- */
.quality-card { padding: 14px 16px; }
.quality-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 32px;
}
.quality-title {
  font-size: 16px; font-weight: 600; letter-spacing: -0.01em;
}
.quality-pill {
  font-size: 13px; padding: 5px 14px; font-weight: 600;
}

.quality-details { margin-top: 10px; }
.quality-details > summary {
  font-size: 12px; color: var(--text-muted); cursor: pointer;
  list-style: none; padding: 4px 0;
  display: inline-flex; align-items: center; gap: 4px;
  user-select: none;
}
.quality-details > summary::-webkit-details-marker { display: none; }
.quality-details > summary::before {
  content: '›'; display: inline-block;
  transition: transform 120ms; font-size: 14px; line-height: 1;
}
.quality-details[open] > summary::before { transform: rotate(90deg); }
.quality-details > summary:hover { color: var(--text); }

.quality-sub-list {
  list-style: none; padding: 0; margin: 8px 0 0;
  display: flex; flex-direction: column; gap: 4px;
  border-top: 1px solid var(--border);
}
.quality-sub {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.quality-sub:last-child { border-bottom: 0; }
.quality-sub-name { color: var(--text); }
.quality-sub-value {
  font-family: var(--font-mono); font-size: 13px;
  font-variant-numeric: tabular-nums; color: var(--text-muted);
}
.quality-sub-pill { font-size: 11px; padding: 2px 9px; }

/* ---------- KV ---------- */
.kv { display: grid; grid-template-columns: 110px 1fr;
  row-gap: 8px; column-gap: 12px; margin: 0; }
.kv dt { color: var(--text-muted); font-size: 13px; }
.kv dd { margin: 0; word-break: break-word; font-size: 14px; }

/* ---------- Admin station list ---------- */
.station-list { list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px; }
.station-row {
  display: flex; gap: 10px; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
}
.station-meta { min-width: 0; }
.station-cas { font-weight: 600; font-family: var(--font-mono); font-size: 14px; }
.station-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.station-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
code { font-family: var(--font-mono);
  background: var(--bg-soft); padding: 1px 6px; border-radius: 6px;
  font-size: 12px; }

/* ---------- Status row (admin creds card) ---------- */
.status-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status-row .pill { font-size: 13px; padding: 4px 12px; }
.status-row .meta { color: var(--text-muted); font-size: 13px;
  font-family: var(--font-mono); }

/* ---------- QR modal ---------- */
.modal {
  position: fixed; inset: 0; display: none;
  background: rgba(34, 34, 34, 0.45); backdrop-filter: blur(4px);
  z-index: 50; align-items: center; justify-content: center;
  padding: 16px;
}
.modal.open { display: flex; }
.modal-body {
  width: 100%; max-width: 480px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow-md);
}
.modal-header { display: flex; justify-content: space-between;
  align-items: center; font-weight: 600; margin-bottom: 10px; }
#qr-reader { width: 100%; min-height: 280px; border-radius: 10px; overflow: hidden;
  background: var(--bg-soft); }
#qr-reader video { width: 100% !important; border-radius: 10px; }
#qr-status { margin-top: 8px; min-height: 1.4em; color: var(--text-muted); font-size: 13px; }

/* ---------- Wider screens ---------- */
@media (min-width: 600px) {
  .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .station-row { align-items: center; }
}

/* ---------- Factory activation card ---------- */
.sheet-page { max-width: 760px; }
.sheet {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  display: flex; flex-direction: column; gap: 22px;
}
.sheet-header { display: flex; align-items: center; gap: 18px; }
.sheet-logo { height: 36px; width: auto; }
.sheet-header-text h1 { margin: 0; font-size: 22px; font-weight: 700;
  letter-spacing: -0.01em; }
.sheet-subtitle { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }

.sheet-ids {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.sheet-id-block {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
}
.sheet-id-label { font-size: 11px; color: var(--text-muted);
  letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 6px; }
.sheet-id-value { font-family: var(--font-mono); font-size: 24px;
  font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  word-break: break-all; }
.sheet-pin .sheet-pin-value { font-size: 34px; letter-spacing: 0.04em; }
.sheet-label { font-size: 14px; }

.sheet-qr {
  display: flex; align-items: center; gap: 20px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.sheet-qr-img { display: block; width: 180px; height: 180px;
  background: #fff; padding: 8px; border-radius: 8px; }
.sheet-qr-headline { font-weight: 600; margin-bottom: 4px; }
.sheet-qr-url code { background: transparent; padding: 0; font-size: 12px; }

.sheet-instructions h2 {
  margin: 0 0 8px; font-size: 14px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600;
}
.sheet-instructions ol { margin: 0; padding-left: 22px;
  display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.sheet-footer { padding-top: 8px; border-top: 1px solid var(--border); }

/* ---------- Print rules ---------- */
@media print {
  body, .bg-station, .bg-admin { background: #fff !important; color: #000 !important; }
  .topbar, .sheet-screen-only, .scan-modal, .modal,
  .btn-ghost, #refresh-btn { display: none !important; }
  .page { padding: 0; max-width: none; }
  .sheet {
    border: 0; padding: 0; box-shadow: none;
    page-break-inside: avoid;
  }
  .sheet-id-block, .sheet-qr {
    border-color: #999 !important; background: #fff !important;
    box-shadow: none !important;
  }
  .sheet-id-value, .sheet-pin-value { color: #000 !important; }
  a, code { color: #000 !important; }
  @page { margin: 16mm; }
}
