:root {
  --bg: #f5f2ed;
  --surface: #fffefb;
  --border: #e2ddd6;
  --text: #1c1a17;
  --muted: #8a8479;
  --accent: #2d5a3d;
  --accent-light: #e8f0eb;
  --warn: #8b3a1a;
  --warn-light: #fdf0eb;
  --ok: #2d5a3d;
  --ok-light: #e8f0eb;
  --neutral: #5a5550;
  --neutral-light: #f0ede8;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 24px 16px 48px;
}

/* ── Header ── */
header {
  max-width: 900px;
  margin: 0 auto 32px;
}

.header-top {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
}

h1 {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-weight: 400;
  color: var(--text);
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
}

/* ── Date Tabs ── */
.date-tabs {
  max-width: 900px;
  margin: 0 auto 28px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  padding: 8px 18px;
  border: 1.5px solid var(--border);
  border-radius: 100px;
  background: var(--surface);
  font-family: 'DM Mono', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s ease;
  font-weight: 400;
}

.tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Section Label ── */
.section-label {
  max-width: 900px;
  margin: 0 auto 12px;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  padding: 0 2px;
}

/* ── Blood Chemistry Table ── */
.card {
  max-width: 900px;
  margin: 0 auto 28px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 420px;
}

thead th {
  padding: 14px 18px;
  text-align: left;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1.5px solid var(--border);
  background: var(--bg);
}

thead th:not(:first-child) { text-align: right; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

td {
  padding: 14px 18px;
  font-size: 0.88rem;
  vertical-align: middle;
}

td:not(:first-child) {
  text-align: right;
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
}

.test-name {
  font-weight: 500;
  color: var(--text);
}

.unit {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 1px;
}

.result-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.result-val {
  font-family: 'DM Mono', monospace;
  font-size: 0.9rem;
  font-weight: 500;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge.high { background: var(--warn-light); color: var(--warn); }
.badge.low  { background: #edf0f8; color: #2a3a7a; }
.badge.ok   { background: var(--ok-light); color: var(--ok); }

.result-val.high { color: var(--warn); }
.result-val.low  { color: #2a3a7a; }
.result-val.ok   { color: var(--ok); }

.range {
  font-size: 0.7rem;
  color: var(--muted);
}

/* ── Urinalysis Grid ── */
.ua-grid {
  max-width: 900px;
  margin: 0 auto 28px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.ua-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  transition: border-color 0.15s;
}

.ua-card:hover { border-color: #c5bfb6; }

.ua-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.ua-value {
  font-family: 'DM Mono', monospace;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.ua-value.flag  { color: var(--warn); }
.ua-value.empty { color: var(--border); font-style: italic; font-size: 0.75rem; }

/* ── Trends ── */
.trend-section {
  max-width: 900px;
  margin: 0 auto 28px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  overflow: hidden;
}

.trend-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.05rem;
  font-weight: 400;
  margin-bottom: 20px;
  color: var(--text);
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.trend-test-name {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 8px;
}

.mini-chart {
  position: relative;
  height: 50px;
}

.mini-chart svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.trend-dots {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
}

.trend-dot-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  gap: 2px;
}

.trend-dot-val {
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
}

.trend-dot-date {
  font-family: 'DM Mono', monospace;
  font-size: 0.58rem;
  color: var(--border);
  text-align: center;
  white-space: nowrap;
}

.trend-dot-val.high { color: var(--warn); font-weight: 500; }
.trend-dot-val.ok   { color: var(--ok); font-weight: 500; }

/* ── Loading & Error States ── */
.state-screen {
  max-width: 900px;
  margin: 60px auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.state-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--text);
}

.state-msg {
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 320px;
  line-height: 1.6;
}

.retry-btn {
  margin-top: 4px;
  padding: 9px 22px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 100px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.retry-btn:hover { opacity: 0.85; }

.error-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--warn-light);
  color: var(--warn);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
}

.hidden { display: none; }

/* ── Responsive ── */
@media (max-width: 480px) {
  body { padding: 16px 12px 40px; }
  td, thead th { padding: 12px 12px; }
  .ua-grid { grid-template-columns: repeat(2, 1fr); }
  .trend-grid { grid-template-columns: 1fr 1fr; }
}