:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1a1d1f;
  --text-muted: #6b7280;
  --accent: #1c6e5a;
  --accent-soft: #e4f1ec;
  --high: #b3441e;
  --high-soft: #fbeae3;
  --low: #a3730f;
  --low-soft: #fbf1de;
  --abnormal: #a3730f;
  --border: #e6e8eb;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --card: #1e2226;
    --text: #eef1f3;
    --text-muted: #9aa4ab;
    --accent: #4fbf9a;
    --accent-soft: #1c332c;
    --high: #f0876a;
    --high-soft: #3a251e;
    --low: #e0b25c;
    --low-soft: #372c17;
    --border: #2b3034;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(64px + var(--safe-bottom));
  min-height: 100vh;
}

header.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 16px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header.topbar h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 700;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.topbar-user #user-email-label {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
}

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.auth-card { max-width: 360px; width: 100%; text-align: center; }
.auth-card h1 { font-size: 24px; margin: 0 0 8px; }
.auth-card .hint { margin-bottom: 14px; }
#auth-form input,
.profile-form input,
.profile-form select {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 8px;
}
.profile-form label {
  display: block;
  margin: 8px 0 4px;
}

main {
  padding: 8px 16px 24px;
  max-width: 640px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card h2 {
  font-size: 15px;
  margin: 0 0 10px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.profile-row {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  padding: 4px 0;
}
.profile-row span:first-child { color: var(--text-muted); }

.trend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.trend-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.trend-tile .label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.trend-tile .value { font-size: 22px; font-weight: 700; }
.trend-tile .value.flag-high { color: var(--high); }
.trend-tile .value.flag-low { color: var(--low); }
.trend-tile .unit { font-size: 13px; color: var(--text-muted); font-weight: 400; }
.trend-tile svg { display: block; margin-top: 8px; width: 100%; height: 32px; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
.badge.high { background: var(--high-soft); color: var(--high); }
.badge.low { background: var(--low-soft); color: var(--low); }
.badge.abnormal { background: var(--low-soft); color: var(--abnormal); }
.badge.normal { background: var(--accent-soft); color: var(--accent); }

.day-group { margin-bottom: 18px; }
.day-group .date { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.day-group .source { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }

.value-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  gap: 8px;
}
.value-row:last-child { border-bottom: none; }
.value-row .indicator { color: var(--text-muted); flex: 1; }
.value-row .val { font-weight: 600; text-align: right; white-space: nowrap; }
.value-row .ref { font-size: 12px; color: var(--text-muted); display: block; text-align: right; }

.visit-diagnosis { font-size: 14px; margin: 4px 0; }
.visit-rec { font-size: 13px; color: var(--text-muted); margin: 4px 0 0; }

nav.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}
nav.tabbar button {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 0 8px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
nav.tabbar button .icon { font-size: 20px; }
nav.tabbar button.active { color: var(--accent); font-weight: 700; }

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

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 700;
  width: 100%;
  cursor: pointer;
}
button.primary:disabled { opacity: 0.5; }

button.secondary {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 700;
  width: 100%;
  cursor: pointer;
}

.upload-preview {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--border);
}

.hint { font-size: 13px; color: var(--text-muted); line-height: 1.4; }

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin: 10px 0;
}

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px;
  font-size: 14px;
}

.disclaimer {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 12px 4px 4px;
}

.review-item { margin-bottom: 10px; }

.match-banner {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 12px;
}
.match-banner.match { background: var(--accent-soft); color: var(--accent); }
.match-banner.mismatch { background: var(--high-soft); color: var(--high); }
.match-banner.unknown { background: var(--low-soft); color: var(--low); }
.match-banner strong { display: block; margin-bottom: 2px; font-size: 14px; }

button.danger {
  background: var(--high-soft);
  color: var(--high);
}

#insights-content {
  white-space: pre-line;
  line-height: 1.5;
}
