:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --surface-page:   #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6; /* systolic */
  --series-2:       #eb6834; /* diastolic */
  --series-pulse:   #4a3aa7;
  --status-good:      #0ca30c;
  --status-warning:   #fab219;
  --status-serious:   #ec835a;
  --status-critical:  #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --surface-page:   #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --series-pulse:   #9085e9;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --surface-page:   #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);
  --series-1:       #3987e5;
  --series-2:       #d95926;
  --series-pulse:   #9085e9;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
h1 {
  font-size: 1.35rem;
  margin: 4px 0;
}
h2 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin: 0 0 12px;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.logout-btn {
  background: none;
  border: 1px solid var(--baseline);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}
.logout-btn:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--gridline);
}
.tab {
  padding: 10px 4px;
  margin-right: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--series-1); border-bottom-color: var(--series-1); }
.stat-tile {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}
.stat-tile .value {
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-tile .unit {
  font-size: 1rem;
  color: var(--text-muted);
}
.stat-tile .delta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.stat-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 16px;
}
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}
form.entry {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
form.entry .full { grid-column: 1 / -1; }
label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
input, textarea {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 1rem;
}
button {
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--series-1);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
form.entry button { grid-column: 1 / -1; }
.legend {
  display: flex;
  gap: 16px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px 0;
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--gridline); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
td.num { font-variant-numeric: tabular-nums; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.good     { color: var(--status-good);     background: color-mix(in srgb, var(--status-good) 14%, transparent); }
.badge.warning  { color: #8a5a00;                background: color-mix(in srgb, var(--status-warning) 22%, transparent); }
.badge.serious  { color: #a4431f;                background: color-mix(in srgb, var(--status-serious) 22%, transparent); }
.badge.critical { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 14%, transparent); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .badge.warning { color: var(--status-warning); }
  :root:where(:not([data-theme="light"])) .badge.serious { color: var(--status-serious); }
}
:root[data-theme="dark"] .badge.warning { color: var(--status-warning); }
:root[data-theme="dark"] .badge.serious { color: var(--status-serious); }
.del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 6px;
}
.del-btn:hover { color: var(--status-critical); }
canvas { max-width: 100%; }

.hint {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-muted);
}
.day-row { cursor: pointer; }
.day-row:hover { background: color-mix(in srgb, var(--series-1) 6%, transparent); }
.day-count { color: var(--text-muted); }
.note-row td {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  padding-top: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--gridline);
}

.modal-backdrop[hidden] {
  display: none;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 560px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 16px;
}
@media (min-width: 560px) {
  .modal { border-radius: 12px; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-header h2 {
  font-size: 1rem;
  color: var(--text-primary);
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text-primary); }

.login-wrap {
  max-width: 340px;
  margin: 15vh auto 0;
  padding: 0 16px;
}
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.login-card h1 {
  font-size: 1.2rem;
  margin: 0 0 18px;
  text-align: center;
}
.login-card .field { margin-bottom: 14px; }
.login-card button { width: 100%; }
.login-error {
  color: var(--status-critical);
  font-size: 0.85rem;
  margin: 0 0 14px;
  text-align: center;
}
