/* Спільна структура прототипів design-lab. Усі кольори — через семантичні
   токени (нижче :root-дефолти = варіант v1 light-trust). Варіанти
   перевизначають лише :root + кілька характерних правил. */
@font-face {
  font-family: "Montserrat";
  src: url("./assets/fonts/montserrat-var-cyrillic.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Montserrat";
  src: url("./assets/fonts/montserrat-var-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+20B4, U+2212;
}
:root {
  --bg: #ffffff;
  --backdrop: #edecf4;
  --surface: #f6f5fb;
  --line: #e8e6f1;
  --ink: #201747;
  --ink-2: #4a406a;
  --ink-3: #635c85;
  --green: #89dc65;
  --green-deep: #5ab031;
  --on-green: #201747; /* текст на зелених поверхнях — завжди кобальт (контраст) */
  --coral: #ff595a;
  --coral-ink: #e30137;
  --coral-tint: #fdedee;
  --accent: #201747; /* колір головної дії (кнопки, вибрані пігулки) */
  --on-accent: #ffffff;
  --accent-ico: #5ab031; /* активна іконка нав-бару */
  --r-card: 16px;
  --r-ctrl: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: "Montserrat", system-ui, sans-serif;
  background: var(--backdrop);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
}
button { font: inherit; }

.phone {
  width: 390px;
  flex: none;
  min-width: 0; /* інакше min-width:auto flex-елемента розпирає телефон понад 390px */
  height: 844px;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
/* На широкому екрані (десктоп-прев'ю) — рамка пристрою на нейтральному стейджі.
   На вузькому (телефон) рамки нема, застосунок на весь екран. */
@media (min-width: 431px) {
  body {
    padding: 44px 0;
    align-items: flex-start;
    background: radial-gradient(125% 80% at 50% 0%, #eeedf5 0%, #d5d3e6 100%);
  }
  .phone {
    border-radius: 46px;
    box-shadow:
      0 0 0 2px #4a4470,                 /* кант екрана */
      0 0 0 13px #17122e,                /* корпус */
      0 0 0 15px #2a2450,                /* блик по краю корпусу */
      0 34px 72px rgba(12, 8, 28, 0.5);  /* тінь пристрою */
  }
  /* Динамічний острівець */
  .phone::after {
    content: "";
    position: absolute;
    top: 9px; left: 50%; transform: translateX(-50%);
    width: 104px; height: 26px;
    background: #0c0920;
    border-radius: 999px;
    z-index: 40;
    pointer-events: none;
  }
  /* Місце під острівець, щоб він не перекривав контент */
  .home-top, .topbar { padding-top: 40px; }
}

/* ===== Екрани та переходи ===== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.32s var(--ease), visibility 0.32s;
}
.screen.is-active { transform: translateX(0); visibility: visible; }
.screen.is-behind { transform: translateX(-24%); visibility: visible; }
.scroll { flex: 1; min-height: 0; min-width: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
@media (prefers-reduced-motion: reduce) {
  .screen { transition: visibility 0.01s; }
}

/* ===== Спільні контролі ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 22px 12px 10px;
  flex: none;
}
.icon-btn {
  width: 44px; height: 44px;
  border: 0; background: none;
  border-radius: var(--r-ctrl);
  color: var(--ink);
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface); }
.topbar h1 { font-size: 1.0625rem; font-weight: 600; flex: 1; text-align: center; }
.btn {
  min-height: 52px;
  border-radius: var(--r-ctrl);
  font-size: 0.9375rem; font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.15s var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--on-accent); border: 0; }
.btn-secondary { background: none; color: var(--ink); border: 1.5px solid var(--line); }
:focus-visible { outline: 3px solid var(--green-deep); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } }

/* ===== HOME ===== */
.home-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px 20px 8px; flex: none;
}
.home-top img { height: 34px; display: block; }
.greeting { padding: 12px 20px 4px; }
.greeting h1 { font-size: 1.5rem; font-weight: 650; letter-spacing: -0.01em; }
.greeting p { margin-top: 4px; font-size: 0.8125rem; color: var(--ink-2); }
.patients { display: flex; gap: 8px; padding: 14px 20px 4px; overflow-x: auto; scrollbar-width: none; }
.patients::-webkit-scrollbar { display: none; }
.patient-chip {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.8125rem; font-weight: 600;
  padding: 8px 16px 8px 10px; min-height: 44px;
  border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--ink);
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.patient-chip .ava {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  background: var(--surface); color: var(--ink-2);
}
.patient-chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.patient-chip[aria-pressed="true"] .ava { background: rgba(255,255,255,0.18); color: var(--on-accent); }
.patient-chip.all-chip { padding-left: 16px; }

section.blk { padding: 18px 20px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.section-head h2 { font-size: 1.0625rem; font-weight: 650; }
.section-head a { font-size: 0.8125rem; font-weight: 600; color: var(--ink-2); text-decoration: none; cursor: pointer; }

.result-card {
  display: flex; align-items: center; gap: 14px; width: 100%;
  text-align: left; color: inherit; background: var(--surface);
  border: 0; border-radius: var(--r-card); padding: 16px; cursor: pointer;
}
.result-card:active { background: var(--line); }
.ready-dot {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  background: var(--green); display: grid; place-items: center; color: var(--on-green);
}
.result-card .txt { flex: 1; min-width: 0; }
.result-card .name { font-size: 0.875rem; font-weight: 600; line-height: 1.3; }
.result-card .meta { margin-top: 3px; font-size: 0.75rem; color: var(--ink-2); }
.chev { color: var(--ink-3); flex: none; }

.order { display: flex; align-items: center; gap: 12px; padding: 14px 2px; border-bottom: 1px solid var(--line); }
.order:last-child { border-bottom: 0; }
.order .txt { flex: 1; min-width: 0; }
.order .title { font-size: 0.875rem; font-weight: 600; }
.order .meta { margin-top: 3px; font-size: 0.75rem; color: var(--ink-2); }
.order .sum { font-size: 0.875rem; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-block; font-size: 0.6875rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; margin-top: 6px; }
.badge-progress { background: var(--surface); color: var(--ink-2); }
.badge-paid { background: var(--green); color: var(--on-green); }
.orders-empty { font-size: 0.8125rem; color: var(--ink-2); background: var(--surface); border-radius: var(--r-card); padding: 16px; line-height: 1.5; }

.cta-wrap { padding: 22px 20px; margin-top: auto; }
.btn-cta {
  width: 100%; min-height: 56px; border: 0; border-radius: 14px;
  background: var(--green); color: var(--on-green);
  font-size: 1rem; font-weight: 650; cursor: pointer;
  transition: transform 0.15s var(--ease);
}
.btn-cta:active { transform: scale(0.98); }
.nav {
  display: grid; grid-template-columns: repeat(4, 1fr); flex: none;
  border-top: 1px solid var(--line); padding: 6px 8px 16px; background: var(--bg);
}
.nav button {
  font-size: 0.6875rem; font-weight: 600; border: 0; background: none; color: var(--ink-3);
  display: grid; justify-items: center; gap: 3px; padding: 8px 0 2px; min-height: 48px;
  cursor: pointer; border-radius: var(--r-ctrl);
}
.nav button.is-active { color: var(--ink); }
.nav button.is-active svg { color: var(--accent-ico); }

/* ===== RESULT ===== */
.result-head { padding: 8px 20px 16px; }
.status-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--green); color: var(--on-green);
  font-size: 0.75rem; font-weight: 600; padding: 5px 12px; border-radius: 999px;
}
.status-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--on-green); }
.result-head h2 { font-size: 1.375rem; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; margin-top: 12px; text-wrap: balance; }
.result-meta { margin-top: 8px; font-size: 0.8125rem; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 8px; }
.result-meta .dot::before { content: "·"; margin-right: 8px; color: var(--ink-3); }
.summary { margin: 0 20px; padding: 12px 16px; background: var(--surface); border-radius: var(--r-card); font-size: 0.8125rem; line-height: 1.45; color: var(--ink-2); }
.summary strong { color: var(--ink); font-weight: 600; }
.analytes { padding: 12px 20px 0; }
.analytes-caption { font-size: 0.75rem; font-weight: 600; color: var(--ink-3); padding: 12px 0 4px; }
.analyte { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 14px 0 16px; cursor: pointer; color: inherit; display: block; }
.analyte:last-of-type { border-bottom: 0; }
.analyte-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.analyte-name { font-size: 0.9375rem; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.analyte-name .mini-chev { color: var(--ink-3); }
.analyte-value { font-size: 0.9375rem; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.analyte-value .unit { font-weight: 400; font-size: 0.75rem; color: var(--ink-2); margin-left: 2px; }
.analyte.is-off .analyte-value { color: var(--coral-ink); }
.flag-note { display: inline-block; margin-top: 6px; font-size: 0.75rem; font-weight: 600; color: var(--coral-ink); background: var(--coral-tint); padding: 3px 10px; border-radius: 999px; }
.range { margin-top: 12px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
.range-track { position: relative; height: 6px; border-radius: 999px; background: var(--line); }
.range-zone { position: absolute; top: 0; bottom: 0; background: var(--green); border-radius: 999px; }
.range-marker { position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%; background: var(--ink); border: 3px solid var(--bg); box-shadow: 0 1px 4px rgba(20,14,44,0.45); transform: translate(-50%, -50%); }
.analyte.is-off .range-marker { background: var(--coral-ink); }
.range-label { font-size: 0.6875rem; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.disclaimer { margin: 8px 20px 0; font-size: 0.75rem; line-height: 1.5; color: var(--ink-2); }
.actions { padding: 16px 20px 28px; display: grid; gap: 10px; }

/* ===== HISTORY ===== */
.history-head { padding: 4px 20px 8px; }
.history-head h2 { font-size: 1.375rem; font-weight: 650; letter-spacing: -0.01em; }
.history-head p { margin-top: 4px; font-size: 0.8125rem; color: var(--ink-2); }
.metric-switch { display: flex; gap: 8px; padding: 12px 20px 4px; }
.metric-tab {
  font-size: 0.8125rem; font-weight: 600; padding: 9px 16px; min-height: 40px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer;
}
.metric-tab[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chart-wrap { padding: 16px 12px 4px; }
.chart-latest { display: flex; align-items: baseline; gap: 10px; padding: 4px 8px 12px; }
.chart-latest .big { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.chart-latest .u { font-size: 0.875rem; color: var(--ink-2); }
.chart-latest .delta { margin-left: auto; font-size: 0.8125rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--surface); color: var(--ink-2); }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend { display: flex; gap: 16px; padding: 10px 20px 0; font-size: 0.75rem; color: var(--ink-2); }
.chart-legend .k { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .sw { width: 14px; height: 4px; border-radius: 2px; }
.history-note { margin: 16px 20px 28px; padding: 14px 16px; background: var(--surface); border-radius: var(--r-card); font-size: 0.8125rem; line-height: 1.5; color: var(--ink-2); }
.history-note strong { color: var(--ink); }

/* ===== SHARE SHEET ===== */
.sheet-backdrop {
  position: absolute; inset: 0; background: rgba(20, 14, 44, 0.5);
  opacity: 0; visibility: hidden; transition: opacity 0.28s, visibility 0.28s; z-index: 30;
}
.sheet-backdrop.is-open { opacity: 1; visibility: visible; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 0.32s var(--ease);
  max-height: 92%; overflow-y: auto;
}
.sheet.is-open { transform: translateY(0); }
@media (prefers-reduced-motion: reduce) {
  .sheet-backdrop { transition: visibility 0.01s; }
  .sheet { transition: none; }
}
.grabber { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { font-size: 1.1875rem; font-weight: 650; text-align: center; }
.sheet .sub { font-size: 0.8125rem; color: var(--ink-2); text-align: center; margin-top: 6px; line-height: 1.45; }
.sheet .sub b { color: var(--ink); font-weight: 600; }
.qr-card {
  margin: 18px auto 6px; width: 210px; padding: 16px;
  background: var(--bg); border: 1.5px solid var(--line); border-radius: 20px;
  display: grid; place-items: center; gap: 12px;
}
.qr-card svg { width: 168px; height: 168px; display: block; }
.share-code {
  font-variant-numeric: tabular-nums; letter-spacing: 0.06em;
  font-size: 1.0625rem; font-weight: 650; color: var(--ink);
}
.expiry { display: inline-flex; align-items: center; gap: 6px; margin: 12px auto 0; justify-content: center; width: 100%; font-size: 0.8125rem; color: var(--coral-ink); font-weight: 600; }
.expiry .clock { width: 7px; height: 7px; border-radius: 50%; background: var(--coral); }
.share-info { margin-top: 16px; display: grid; gap: 10px; }
.info-row { display: flex; gap: 12px; align-items: flex-start; font-size: 0.8125rem; color: var(--ink-2); line-height: 1.4; }
.info-row .ic { flex: none; width: 34px; height: 34px; border-radius: 10px; background: var(--surface); display: grid; place-items: center; color: var(--green-deep); }
.info-row b { color: var(--ink); font-weight: 600; }
.share-actions { margin-top: 18px; display: grid; gap: 10px; }
.btn-link { background: var(--surface); color: var(--ink); border: 0; }
