/* Ensure [hidden] wins over component display rules (e.g. .empty-glucose). */
[hidden] { display: none !important; }

:root {
  --bg: #0f1114;
  --bg-elev: #171a1f;
  --bg-soft: #1e2329;
  --ink: #e8ebe6;
  --muted: #8b938a;
  --line: #2a3138;
  --teal: #2dd4bf;
  --teal-dim: rgba(45, 212, 191, 0.15);
  --amber: #fbbf24;
  --amber-dim: rgba(251, 191, 36, 0.12);
  --rose: #fb7185;
  --rose-dim: rgba(251, 113, 133, 0.12);
  --stone: #a8a29e;
  --font-ui: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", ui-monospace, monospace;
  --font-display: "Fraunces", "Palatino Linotype", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: radial-gradient(1200px 600px at 10% -10%, #1a2422 0%, var(--bg) 55%);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.45;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 17, 20, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; gap: 0.75rem; align-items: center; }
.mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 4px var(--teal-dim), 0 0 18px rgba(45, 212, 191, 0.45);
}
h1 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.subtitle { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.8rem; }

.tabs { display: flex; gap: 0.35rem; margin-left: auto; }
.tab {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  font: inherit;
}
.tab.active {
  color: var(--bg);
  background: var(--teal);
  border-color: var(--teal);
  font-weight: 600;
}
.auto-refresh { color: var(--muted); font-size: 0.85rem; display: flex; gap: 0.4rem; align-items: center; }

.card {
  margin: 1rem 1.25rem;
  padding: 1rem 1.1rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin-bottom: 0.75rem; }
.row:last-child { margin-bottom: 0; }
.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 12rem; }
.field.grow { flex: 1; }
.field span, .unit-toggle legend { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
input[type="password"], input[type="search"], select {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font: inherit;
}
.unit-toggle {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.35rem 0.6rem 0.5rem;
  margin: 0;
  display: flex;
  gap: 0.75rem;
}
.remember { font-size: 0.85rem; color: var(--muted); display: flex; gap: 0.35rem; align-items: center; padding-bottom: 0.4rem; }
.key-status { margin: 0 0 0.5rem; }
.key-status.ok { color: var(--ok, #1a7f37); font-weight: 600; }
.remember-hint { margin: 0 0 0.35rem; font-size: 0.8rem; max-width: 52rem; }

.btn {
  background: var(--teal);
  color: #042f2e;
  border: none;
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.health-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
}
.health-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  font: inherit;
}
.hi-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--stone);
}
.state-live .hi-dot { background: var(--teal); box-shadow: 0 0 10px var(--teal); }
.state-stale .hi-dot, .state-partial .hi-dot { background: var(--amber); }
.state-failed .hi-dot { background: var(--rose); }
.state-running .hi-dot {
  background: var(--teal);
  animation: pulse 1.2s ease-in-out infinite;
}
.state-queued .hi-dot { background: var(--stone); }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}
.hi-meta { display: flex; flex-wrap: wrap; gap: 0.85rem; align-items: baseline; font-size: 0.9rem; }
.mono { font-family: var(--font-mono); font-size: 0.8rem; }
.muted { color: var(--muted); }

.banner {
  margin: 0 1.25rem 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  font-size: 0.9rem;
}
.banner.warn { background: var(--amber-dim); color: #fde68a; border: 1px solid rgba(251,191,36,0.35); }
.error {
  margin: 0 1.25rem 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  background: var(--rose-dim);
  color: #fecdd3;
  border: 1px solid rgba(251,113,133,0.35);
}

.panel { display: none; }
.panel.active { display: block; }

.reading-main {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.value {
  font-family: var(--font-display);
  font-size: 3.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.unit { color: var(--muted); font-size: 1rem; }
.trend { font-size: 1.6rem; color: var(--teal); }
.meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.75rem;
  margin: 0;
}
.meta dt { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.meta dd { margin: 0.15rem 0 0; font-size: 0.95rem; }
.range-in_target { color: var(--teal); }
.range-high, .range-very_high { color: var(--amber); }
.range-low { color: var(--rose); }

.chart-wrap { height: 280px; position: relative; }
.chart-card h2, .status-strip h2, .hygiene h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-family: var(--font-display);
}

.status-strip { display: flex; justify-content: space-between; gap: 1rem; align-items: start; flex-wrap: wrap; }
.dev-actions { display: flex; gap: 0.5rem; }
.dev-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 0;
}
@media (max-width: 900px) {
  .dev-grid { grid-template-columns: 1fr; }
  .inspector.mobile-open { position: fixed; inset: 0; z-index: 30; margin: 0; border-radius: 0; overflow: auto; }
  .runs-panel.hidden-mobile { display: none; }
  .mobile-only { display: inline-flex !important; }
}
.mobile-only { display: none; }

.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
}
.chip.active { background: var(--teal-dim); color: var(--teal); border-color: rgba(45,212,191,0.4); }
#runSearch { flex: 1; min-width: 10rem; }

.run-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; }
.run-list li {
  border-top: 1px solid var(--line);
  padding: 0.7rem 0.25rem;
  cursor: pointer;
  display: grid;
  gap: 0.2rem;
}
.run-list li:hover, .run-list li.active { background: rgba(255,255,255,0.03); }
.run-list .rid { font-family: var(--font-mono); font-size: 0.8rem; color: var(--teal); }
.run-list .meta-line { font-size: 0.8rem; color: var(--muted); }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--line);
}
.badge.succeeded { color: var(--teal); border-color: rgba(45,212,191,0.35); }
.badge.failed { color: var(--rose); border-color: rgba(251,113,133,0.35); }
.badge.partial, .badge.stale { color: var(--amber); border-color: rgba(251,191,36,0.35); }
.badge.running { color: var(--teal); }
.empty-state { padding: 1rem 0; }

.inspector-header {
  display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.inspector-header h3 { margin: 0; flex: 1; font-size: 1rem; }
.inspector-body { font-size: 0.9rem; }
.stages { list-style: none; padding: 0; margin: 0 0 1rem; }
.stages li {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.35rem 0; border-bottom: 1px solid var(--line);
}
.log-tail {
  background: #0b0d10;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}

.hygiene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
}
.hygiene h3 { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  display: flex; justify-content: space-between; gap: 0.5rem; align-items: center;
}
.meta-box a { color: var(--teal); }

.footer {
  margin: 2rem 1.25rem 2.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  max-width: 52rem;
}

.banner.ok { background: rgba(45, 212, 191, 0.12); color: #99f6e4; border: 1px solid rgba(45, 212, 191, 0.35); }
.onboard h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.onboard .steps { margin: 0 0 1rem; padding-left: 1.25rem; color: var(--muted); line-height: 1.45; }
.onboard .steps li { margin-bottom: 0.35rem; }
.onboard .steps strong { color: var(--ink); }
.row.wrap { flex-wrap: wrap; }
.patient-pick { margin: 0.75rem 0; }
.patient-pick select { width: 100%; max-width: 28rem; }

.conn-actions { display: inline-flex; align-items: center; gap: 0.4rem; }
.btn-xs {
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  border-radius: 8px;
}
.badge.unverified, .badge.auth_failed, .badge.schema_error {
  color: var(--amber);
  border-color: rgba(251,191,36,0.35);
}
.badge.active { color: var(--teal); border-color: rgba(45,212,191,0.35); }

.glucose-toolbar-main {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
}
.toolbar-title {
  margin: 0;
  font-size: 1rem;
  font-family: var(--font-display);
}
.toolbar-hint { margin: 0.2rem 0 0; font-size: 0.85rem; }
.glucose-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}
.reading-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.reading-header .reading-main { margin-bottom: 0; }
.store-notice { margin: 0 0 0.85rem; }
.empty-glucose {
  text-align: left;
  display: grid;
  gap: 0.75rem;
  justify-items: start;
}
.empty-glucose h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
}
.empty-glucose p { margin: 0; max-width: 36rem; }
input[type="text"], input[type="email"] {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font: inherit;
}

.whoami {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.whoami strong { font-weight: 600; color: var(--ink); }

.linkish {
  background: none; border: none; color: var(--teal); cursor: pointer; font: inherit; padding: 0;
  text-decoration: underline;
}
