/* Аптечная тема: зелёный крест, мятные тона, белые карточки. */
:root {
  --bg: #f1f8f5;
  --card: #ffffff;
  --text: #12261f;
  --muted: #587068;
  --line: #d4e5dd;
  --tint: #e3f4ec;
  --brand: #0b7a5a;
  --brand-dark: #075c43;
  --brand-text: #ffffff;
  --head-bg: #0b7a5a;
  --head-text: #ffffff;
  --bad: #b42318;
  --bad-bg: #fee4e2;
  --warn: #8a5a00;
  --warn-bg: #fef0c7;
  --ok-bg: #d1fadf;
  --ok: #05603a;
  --shadow: 0 1px 2px rgba(11, 60, 45, 0.06), 0 4px 14px rgba(11, 60, 45, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1613;
    --card: #15211d;
    --text: #e4f1ec;
    --muted: #94b0a6;
    --line: #25382f;
    --tint: #14302a;
    --brand: #34d399;
    --brand-dark: #6ee7b7;
    --brand-text: #04281c;
    --head-bg: #11251f;
    --head-text: #e4f1ec;
    --bad: #fda29b;
    --bad-bg: #4a1b17;
    --warn: #fedf89;
    --warn-bg: #4a3500;
    --ok-bg: #0b3b24;
    --ok: #75e0a7;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}
a { color: var(--brand-dark); }
h1 { font-size: 1.45rem; margin: 0.7rem 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; color: var(--brand-dark); text-transform: none; }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }

/* шапка */
.top { background: var(--head-bg); color: var(--head-text); position: sticky; top: 0; z-index: 5; }
.top-in { display: flex; justify-content: space-between; align-items: center; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--head-text); text-decoration: none; font-weight: 700; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .logo { color: var(--head-text); flex: none; }
button.link.on-head { color: var(--head-text); opacity: 0.9; }

.head-link { color: var(--head-text); opacity: 0.9; text-decoration: none; padding: 8px; }
.head-link:hover { opacity: 1; text-decoration: underline; }

/* справка */
.steps { list-style: none; counter-reset: step; padding: 0; margin: 12px 0; }
.steps li {
  counter-increment: step; position: relative;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px 12px 52px; margin: 10px 0; box-shadow: var(--shadow);
}
.steps li::before {
  content: counter(step); position: absolute; left: 14px; top: 14px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand); color: var(--brand-text);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem;
}
.steps h2 { margin: 0 0 4px; }
.steps p { margin: 0; }
.legend { line-height: 2; }
code { background: var(--tint); color: var(--brand-dark); padding: 1px 6px; border-radius: 6px; }
.note-box { background: var(--tint); border-radius: 12px; padding: 10px 14px; color: var(--brand-dark); font-size: 0.9rem; }

/* назначения */
.dot { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 0.8rem; font-weight: 600; background: var(--line); color: var(--muted); }
.st-ontime { background: var(--ok-bg); color: var(--ok); }
.st-late, .st-overdue { background: var(--warn-bg); color: var(--warn); }
.st-missed { background: var(--bad-bg); color: var(--bad); }
.st-upcoming { background: var(--line); color: var(--muted); }
.st-ready, .st-due { background: var(--tint); color: var(--brand-dark); }
.today { border-left: 5px solid var(--brand); }
.today h2 { margin: 0 0 6px; }
.today-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.today-row:first-of-type { border-top: none; }
.asg-card { display: block; color: inherit; text-decoration: none; }
.asg-card.is-done { opacity: 0.75; }
.pct { text-align: right; display: flex; flex-direction: column; }
.pct strong { font-size: 1.4rem; color: var(--brand-dark); line-height: 1.1; }
.label-text { font-size: 0.88rem; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.times { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.times input { min-width: 0; }
@media (min-width: 560px) { .times { grid-template-columns: repeat(4, 1fr); } }
.warnbox { background: var(--warn-bg); color: var(--warn); }
.warnbox a { color: inherit; font-weight: 700; }
.strip .day { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.strip .day:last-of-type { border-bottom: none; }
.strip .d { width: 46px; color: var(--muted); font-size: 0.85rem; flex: none; }
.dots { display: flex; flex-wrap: wrap; gap: 6px; }
.legend { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* статистика */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.stat strong { font-size: 1.7rem; line-height: 1.1; color: var(--brand-dark); }
.stat span { font-weight: 500; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 70px; margin: 10px 0 4px; }
.bar { flex: 1; height: 100%; display: flex; align-items: flex-end; background: var(--tint); border-radius: 3px; }
.bar i { display: block; width: 100%; background: var(--brand); border-radius: 3px; min-height: 2px; }
.hbar { display: grid; grid-template-columns: 70px 1fr 36px; gap: 8px; align-items: center; margin: 6px 0; font-size: 0.9rem; }
.hbar div { background: var(--tint); border-radius: 6px; height: 14px; }
.hbar i { display: block; height: 100%; background: var(--brand); border-radius: 6px; min-width: 2px; }
.hbar b { text-align: right; }
@media (min-width: 560px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

.hero { text-align: center; padding: 18px 0 6px; }
.hero .logo { color: var(--brand); }
.hero h1 { margin: 8px 0 2px; }
.hero p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.top-align { align-items: flex-start; }
.row.spaced, .spaced { margin-top: 10px; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.ico { flex: none; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin: 10px 0;
  box-shadow: var(--shadow);
}
.card h2 { margin-top: 0; }

/* формы */
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; color: var(--muted); font-weight: 500; }
input, select, textarea, button, .btn {
  font: inherit;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
}
input, select, textarea { width: 100%; background: var(--bg); }
.row > input, .row > select { flex: 1; width: auto; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button, .btn { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 500; }
button:hover:not(:disabled), .btn:hover { border-color: var(--brand); }
button:disabled { opacity: 0.6; cursor: wait; }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-text); border-color: var(--brand); font-weight: 600; }
button.primary:hover:not(:disabled), .btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
button.link { background: none; border: none; color: var(--brand-dark); padding: 4px 8px; min-height: 36px; }
button.danger, .danger { color: var(--bad); }
button.danger-solid { background: var(--bad); color: #fff; border-color: var(--bad); font-weight: 600; }
button.ai-btn { background: var(--tint); border-color: transparent; color: var(--brand-dark); width: 100%; font-weight: 600; }
.row.ai-row { margin-top: -4px; }
.danger-zone { border-color: var(--bad); }

.flash { padding: 10px 14px; border-radius: 10px; margin: 12px 0; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }

.empty { color: var(--muted); text-align: center; padding: 36px 0; }

/* переключатель «Все / Закончились» */
.seg { display: flex; background: var(--tint); border-radius: 12px; padding: 4px; gap: 4px; margin: 10px 0; }
.seg a { flex: 1; text-align: center; padding: 9px 8px; border-radius: 9px; text-decoration: none; color: var(--muted); min-height: 40px; font-weight: 500; }
.seg a.on { background: var(--card); color: var(--brand-dark); font-weight: 700; box-shadow: var(--shadow); }
.filters { margin: 12px 0; flex-wrap: wrap; }
.filters input[type="search"] { flex: 1 1 100%; }
.filters select { flex: 1 1 0; }
.filters button { flex: 0 0 auto; }
.summary { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

/* карточка лекарства */
.med { border-left: 5px solid var(--brand); }
.med.is-warn { border-left-color: #e0a100; }
.med.is-bad { border-left-color: var(--bad); }
.med-name { font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; margin-right: 6px; }
.stock {
  white-space: nowrap; font-size: 0.95rem;
  background: var(--tint); color: var(--brand-dark);
  padding: 4px 12px; border-radius: 99px;
}
.stock strong { font-size: 1.15rem; }
.stock .muted { color: inherit; opacity: 0.8; }
.stock.big { font-size: 1.05rem; padding: 6px 16px; }
.stock.big strong { font-size: 1.6rem; }
.med.is-bad .stock { background: var(--bad-bg); color: var(--bad); }
.med.is-warn .stock { background: var(--warn-bg); color: var(--warn); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0; }
.note { margin: 6px 0; color: var(--muted); font-size: 0.9rem; white-space: pre-wrap; }
.intake { margin-top: 10px; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 0.78rem; font-weight: 600; background: var(--line); color: var(--muted); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.chip { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: 0.8rem; background: var(--tint); color: var(--brand-dark); font-weight: 500; }

/* журнал */
.log { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.log li { display: flex; justify-content: space-between; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: none; }
.log li.cancelled strong { text-decoration: line-through; color: var(--muted); }
.code {
  font: 700 1.7rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: 0.1em; margin: 6px 0;
  user-select: all; color: var(--brand-dark); background: var(--tint); padding: 8px 14px; border-radius: 10px; display: inline-block;
}

details summary { cursor: pointer; font-weight: 600; min-height: 28px; color: var(--brand-dark); }

/* подсказка ИИ */
#pharm-out, #pharm-out-top { margin: 6px 0; }

/* нижнее меню */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 8px 4px; font-size: 0.72rem; color: var(--muted); text-decoration: none; min-height: 58px; position: relative;
}
.tabs a.on { color: var(--brand-dark); font-weight: 700; }
.tabs a.on::before {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px;
  background: var(--brand); border-radius: 0 0 3px 3px;
}

@media (min-width: 700px) {
  .wrap { padding: 0 24px; }
}
