:root {
  --bg: #0d0d0f;
  --surface: #18181c;
  --surface2: #222228;
  --border: #2a2a32;
  --text: #e8e8f0;
  --text-muted: #7878a0;
  --accent: #5b8dd9;
  --ok: #3ec97a;
  --warn: #e07c2a;
  --bad: #d94f4f;
  --chart-band: rgba(91, 141, 217, 0.12);
  --radius: 12px;
  --gap: 16px;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* ── Layout ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px var(--gap);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: background 0.15s;
}
.btn-icon:hover, .btn-icon:focus {
  background: var(--surface2);
  color: var(--text);
  outline: none;
}

.main {
  padding: var(--gap);
  max-width: 900px;
  margin: 0 auto;
}

/* ── Settings panel ── */
.settings-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: var(--gap);
}

.settings-panel h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.settings-row label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.settings-row input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  padding: 10px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
.settings-row input:focus {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 11px 20px;
  min-height: 44px;
  transition: opacity 0.15s;
}
.btn-primary:hover {
  opacity: 0.85;
}

/* ── Error banner ── */
.error-banner {
  background: rgba(217, 79, 79, 0.15);
  border: 1px solid var(--bad);
  border-radius: 8px;
  color: var(--bad);
  font-size: 0.9rem;
  padding: 10px 14px;
  margin-bottom: var(--gap);
  display: none;
}
.error-banner.visible {
  display: block;
}

/* ── Section headings ── */
.section-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 10px;
}

/* ── Latest cards grid ── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: calc(var(--gap) * 1.5);
}

@media (min-width: 600px) {
  .cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .cards-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s;
}
.metric-card:hover {
  border-color: var(--accent);
}

.card-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-value {
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

.card-value.status-ok   { color: var(--ok); }
.card-value.status-warn { color: var(--warn); }
.card-value.status-bad  { color: var(--bad); }

.card-unit {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.card-date {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-value.loading {
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 400;
}

/* ── Charts ── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
}

@media (min-width: 700px) {
  .charts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.chart-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.chart-wrap {
  position: relative;
  height: 200px;
}

.chart-wrap canvas {
  width: 100% !important;
}

/* ── Doctor-view notice ── */
.doctor-badge {
  background: rgba(91, 141, 217, 0.15);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Skeleton shimmer ── */
@keyframes shimmer {
  0%   { opacity: 0.4; }
  50%  { opacity: 0.8; }
  100% { opacity: 0.4; }
}

.skeleton {
  animation: shimmer 1.4s ease-in-out infinite;
  background: var(--surface2);
  border-radius: 4px;
  display: inline-block;
  height: 1em;
  width: 60%;
}

/* ── Refresh timestamp ── */
.refresh-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: var(--gap);
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Injections mini-log (optional, doctor view) ── */
.inj-log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: var(--gap);
}

.inj-log h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.inj-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.inj-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}

.inj-table td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(42,42,50,0.5);
  vertical-align: top;
}

.inj-table tr:last-child td {
  border-bottom: none;
}
