:root {
  --bg: #f4f4f7;
  --secondary-bg: #ffffff;
  --text: #1c1c1e;
  --hint: #8a8a8e;
  --link: #2481cc;
  --button: #2481cc;
  --button-text: #ffffff;
  --border: #e3e3e8;
  --danger: #e5484d;
  --success: #2fa84f;
  --warning: #d98c00;
  --systolic: #1c1c1e;
  --diastolic: #e5484d;
  --card-radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-force-light]) {
    --bg: #0f0f12;
    --secondary-bg: #1c1c1f;
    --text: #f2f2f2;
    --hint: #8e8e93;
    --border: #2c2c2f;
    --systolic: #f2f2f2;
  }
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 72px;
}

.topbar {
  padding: 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.topbar h1 { font-size: 20px; margin: 0; }

main#app { padding: 0 12px 12px; }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--secondary-bg);
  border-top: 1px solid var(--border);
  padding: 6px env(safe-area-inset-right) calc(6px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
  z-index: 10;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--hint);
  font-size: 12px;
  padding: 8px 2px;
  border-radius: 10px;
}
.tab.active { color: var(--link); font-weight: 600; background: color-mix(in srgb, var(--link) 12%, transparent); }

.card {
  background: var(--secondary-bg);
  border-radius: var(--card-radius);
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.card h2 { font-size: 15px; margin: 0 0 10px; }
.card h3 { font-size: 14px; margin: 0 0 6px; }

.muted { color: var(--hint); font-size: 13px; }
.row { display: flex; justify-content: space-between; gap: 8px; }
.row + .row { margin-top: 6px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.stat-tile {
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 10px 12px;
}
.stat-tile .label { font-size: 11px; color: var(--hint); text-transform: uppercase; letter-spacing: .02em; }
.stat-tile .value { font-size: 18px; font-weight: 600; margin-top: 2px; }
.stat-tile .value.systolic::before { content: "○ "; color: var(--systolic); }
.stat-tile .value.diastolic::before { content: "◇ "; color: var(--diastolic); }

.range-switch { display: flex; gap: 6px; margin-bottom: 12px; }
.range-switch button {
  flex: 1;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 13px;
}
.range-switch button.active { background: var(--link); color: #fff; border-color: var(--link); }

.chart-wrap { position: relative; height: 260px; margin-bottom: 8px; }
.chart-wrap.small { height: 90px; margin-bottom: 4px; }

.table-scroll { overflow-x: auto; margin: 0 -4px; }
table.log-table { width: 100%; min-width: 420px; border-collapse: collapse; font-size: 13px; }
table.log-table th, table.log-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.log-table th { color: var(--hint); font-weight: 500; }

.classification-list .row span:last-child { font-weight: 600; }

.section-header { font-size: 13px; color: var(--hint); text-transform: uppercase; letter-spacing: .03em; margin: 18px 4px 8px; }

.lab-metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.lab-metric-row:last-child { border-bottom: none; }
.lab-metric-row .name { font-size: 14px; }
.lab-metric-row .meta { font-size: 12px; color: var(--hint); }
.lab-metric-row .value { font-size: 15px; font-weight: 600; text-align: right; }
.status-badge { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-badge.normal { background: var(--success); }
.status-badge.high { background: var(--danger); }
.status-badge.low { background: var(--warning); }

.timeline-item { margin-bottom: 12px; }
.timeline-item .date { font-size: 12px; color: var(--hint); margin-bottom: 4px; }
.timeline-item .title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.timeline-item .specialty { font-size: 12px; color: var(--link); margin-bottom: 6px; }
.timeline-item ul { margin: 6px 0; padding-left: 18px; font-size: 13px; }
.timeline-item .findings-table td { padding: 2px 6px 2px 0; font-size: 13px; vertical-align: top; }
.timeline-item .findings-table td:first-child { color: var(--hint); white-space: nowrap; }

a.file-link, button.link-button {
  display: inline-block;
  margin-top: 6px;
  color: var(--link);
  font-size: 13px;
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
}

form.entry-form { display: flex; flex-direction: column; gap: 8px; }
form.entry-form label { font-size: 12px; color: var(--hint); }
form.entry-form input, form.entry-form select, form.entry-form textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
form.entry-form .fields-row { display: flex; gap: 8px; }
form.entry-form .fields-row > div { flex: 1; }
form.entry-form button[type="submit"] {
  margin-top: 4px;
  padding: 10px;
  border-radius: 10px;
  border: none;
  background: var(--button);
  color: var(--button-text);
  font-size: 14px;
  font-weight: 600;
  flex: 1;
}
form.entry-form button[type="button"] {
  margin-top: 4px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 14px;
  flex: 1;
}

details.card { padding: 0; }
details.card summary {
  padding: 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "›"; float: right; color: var(--hint); transform: rotate(90deg); display: inline-block; }
details.card[open] summary::after { transform: rotate(-90deg); }
details.card form.entry-form { padding: 0 14px 14px; }

.empty-state { text-align: center; color: var(--hint); padding: 24px 8px; font-size: 13px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal-sheet {
  background: var(--secondary-bg);
  border-radius: 16px 16px 0 0;
  padding: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-sheet .close-btn {
  float: right;
  background: none;
  border: none;
  color: var(--hint);
  font-size: 20px;
  line-height: 1;
}

.toggle-row { display: flex; justify-content: space-between; align-items: center; }

/* ── Обзор: hub (hero + плитки), по референсу мини-аппа ────── */

.hero-block {
  padding: 18px 4px 14px;
}
.hero-block .hero-name { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.hero-block .hero-meta { font-size: 13px; color: var(--hint); }

.spotlight-card {
  background: var(--link);
  color: #fff;
  border-radius: var(--card-radius);
  padding: 16px;
  margin-bottom: 12px;
}
.spotlight-card .label { font-size: 12px; opacity: .85; text-transform: uppercase; letter-spacing: .03em; }
.spotlight-card .headline { font-size: 19px; font-weight: 700; margin: 4px 0 2px; }
.spotlight-card .sub { font-size: 13px; opacity: .9; }
.spotlight-card.warning { background: var(--danger); }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.tile {
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 14px;
  text-align: left;
  color: var(--text);
}
.tile .tile-icon { font-size: 22px; margin-bottom: 8px; display: block; }
.tile .tile-title { font-size: 14px; font-weight: 600; }
.tile .tile-sub { font-size: 12px; color: var(--hint); margin-top: 2px; }

.info-row-list .info-row {
  display: flex;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.info-row-list .info-row:last-child { border-bottom: none; }
.info-row .icon {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.info-row .label { font-size: 12px; color: var(--hint); }
.info-row .text { font-size: 14px; margin-top: 1px; }
