/* ==========================================================================
   Калькулятор анализов «Лекарь» — mobile-first
   Палитра взята с mclekar.ru: маджента #d0147f, голубой акцент #00a0e3
   ========================================================================== */

:root {
  --brand:        #d0147f;
  --brand-dark:   #9a0057;
  --brand-tint:   #fdeef6;
  --accent:       #0084bd;
  --accent-tint:  #e8f6fd;

  --ink:          #15171c;
  --ink-2:        #454b57;
  --muted:        #6d7482;
  --line:         #e6e8ec;
  --bg:           #f5f6f8;
  --card:         #ffffff;
  --ok:           #0f8a4a;
  --danger:       #d12626;

  --r-sm: 10px;
  --r:    14px;
  --r-lg: 20px;

  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;

  --shadow:    0 1px 2px rgba(16,20,30,.05), 0 4px 14px rgba(16,20,30,.06);
  --shadow-lg: 0 -2px 10px rgba(16,20,30,.06), 0 -12px 40px rgba(16,20,30,.14);

  --safe-b: env(safe-area-inset-bottom, 0px);
  --bar-h:  76px;
  --ease:   cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
body.is-locked { overflow: hidden; }

.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 var(--sp-4); }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- Шапка ---------- */
.hdr {
  position: sticky; top: 0; z-index: 40;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.hdr__in { display: flex; align-items: center; gap: var(--sp-3); padding-top: var(--sp-3); padding-bottom: var(--sp-2); }
.hdr__brand { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; flex: 1; }
.hdr__logo {
  flex: none; width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff; font-weight: 700; font-size: 19px;
  display: grid; place-items: center;
}
.hdr__txt { display: flex; flex-direction: column; min-width: 0; }
.hdr__txt strong { font-size: 16px; line-height: 1.2; letter-spacing: -.2px; }
.hdr__txt small { font-size: 12px; color: var(--muted); }
.hdr__call {
  flex: none; width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--brand-tint); color: var(--brand-dark);
  text-decoration: none; transition: background .2s var(--ease);
}
.hdr__call:active { background: #f9dcec; }
.hdr__cart {
  position: relative; flex: none;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center;
  transition: transform .15s var(--ease);
}
.hdr__cart:active { transform: scale(.94); }
.hdr__badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px; border: 2px solid var(--card);
  background: var(--ink); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
}

/* ---------- Поиск ---------- */
.search { padding-bottom: var(--sp-3); }
.search__box { position: relative; display: block; }
.search__icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
#q {
  width: 100%; height: 48px;
  padding: 0 46px 0 44px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--bg); color: var(--ink);
  font-size: 16px; /* не меньше 16px — иначе iOS зумит */
  appearance: none; -webkit-appearance: none;
  transition: border-color .2s var(--ease), background .2s var(--ease);
}
#q::-webkit-search-cancel-button { display: none; }
#q:focus { outline: none; border-color: var(--brand); background: var(--card); }
#q::placeholder { color: var(--muted); }
.search__clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border: 0; background: none; color: var(--muted);
  display: grid; place-items: center; border-radius: 50%;
}

/* ---------- Чипсы категорий ---------- */
.chips {
  display: flex; gap: var(--sp-2);
  overflow-x: auto; scrollbar-width: none;
  padding: 0 var(--sp-4) var(--sp-3);
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; scroll-snap-align: start;
  min-height: 38px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink-2);
  font-size: 14px; white-space: nowrap;
  transition: background .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease);
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500; }

/* ---------- Основной список ---------- */
.main { padding-top: var(--sp-4); padding-bottom: calc(var(--bar-h) + var(--safe-b) + var(--sp-6)); }

.note {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  margin: 0 0 var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--accent-tint); border-radius: var(--r);
  font-size: 13px; line-height: 1.45; color: #0b4c67;
}
.note svg { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--accent); }

.group { margin-bottom: var(--sp-5); }
.group__head {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; gap: var(--sp-2);
  padding: var(--sp-2) 2px;
  background: var(--bg);
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .55px;
  color: var(--muted);
}
.group__n { font-weight: 400; letter-spacing: 0; text-transform: none; }
.group__box { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }

.item {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; min-height: 60px;
  padding: var(--sp-3) var(--sp-4);
  border: 0; border-top: 1px solid var(--line);
  background: none; text-align: left;
  transition: background .15s var(--ease);
}
.item:first-child { border-top: 0; }
.item:active { background: var(--bg); }
.item__t { flex: 1; min-width: 0; }
.item__n { display: block; font-size: 15px; line-height: 1.35; color: var(--ink); }
.item__n mark { background: #ffe9a8; color: inherit; padding: 0 1px; border-radius: 3px; }
.item__b {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 5px; font-size: 12px; color: var(--muted);
}
.item__b svg { width: 13px; height: 13px; }
.item__p { flex: none; font-size: 15px; font-weight: 600; white-space: nowrap; }
.item__add {
  flex: none; width: 44px; height: 44px; margin-right: -8px;
  border: 0; background: none; color: var(--brand);
  display: grid; place-items: center;
}
.item__add span {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1.5px solid currentColor;
  display: grid; place-items: center;
  transition: background .18s var(--ease), color .18s var(--ease), transform .18s var(--ease);
}
.item.is-on .item__add { color: var(--ok); }
.item.is-on .item__add span { background: var(--ok); border-color: var(--ok); color: #fff; }
.item.is-on .item__n { font-weight: 500; }

.empty { padding: var(--sp-8) var(--sp-4); text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 6px; font-size: 16px; }
.skeleton { height: 60px; margin-bottom: 1px; background: var(--card); }
.skeleton::after {
  content: ""; display: block; height: 14px; width: 60%;
  margin: 23px var(--sp-4); border-radius: 7px;
  background: linear-gradient(90deg, #eceef1, #f6f7f9, #eceef1);
  background-size: 200% 100%; animation: sk 1.2s infinite linear;
}
@keyframes sk { to { background-position: -200% 0; } }

.upd { margin: var(--sp-5) 0 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- Нижняя панель ---------- */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  padding-bottom: var(--safe-b);
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  animation: barUp .28s var(--ease);
}
@keyframes barUp { from { transform: translateY(100%); } }
.bar__in { padding-top: var(--sp-3); padding-bottom: var(--sp-3); }
.bar__btn {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; min-height: 52px; padding: 0 var(--sp-4);
  border: 0; border-radius: var(--r);
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  box-shadow: 0 6px 18px rgba(208,20,127,.28);
  transition: transform .15s var(--ease);
}
.bar__btn:active { transform: scale(.985); }
.bar__ico { position: relative; display: grid; place-items: center; }
.bar__badge {
  position: absolute; top: -7px; right: -10px;
  min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 999px; background: #fff; color: var(--brand-dark);
  font-size: 11px; font-weight: 700; line-height: 19px; text-align: center;
}
.bar__lbl { flex: 1; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
.bar__lbl span { font-size: 12px; opacity: .88; }
.bar__lbl strong { font-size: 17px; }
.bar__chev { opacity: .8; }

/* ---------- Шторки ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet__back { position: absolute; inset: 0; background: rgba(12,15,22,.45); animation: fade .25s var(--ease); }
@keyframes fade { from { opacity: 0; } }
.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 92vh; max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--card);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-lg);
  animation: up .3s var(--ease);
}
@keyframes up { from { transform: translateY(6%); opacity: .6; } }
.sheet__grab { width: 38px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: #d8dbe1; }
.sheet__head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--line);
}
.sheet__head h2 { flex: 1; margin: 0; font-size: 18px; letter-spacing: -.2px; }
.sheet__body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: var(--sp-4);
}
.sheet__foot {
  padding: var(--sp-4);
  padding-bottom: calc(var(--sp-4) + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--card);
}
.iconbtn {
  flex: none; width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: var(--bg); color: var(--ink-2);
  display: grid; place-items: center;
}

/* ---------- Корзина ---------- */
.cartsec { margin-bottom: var(--sp-5); }
.cartsec:last-child { margin-bottom: 0; }
.cartsec__h { margin: 0 0 var(--sp-3); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .55px; color: var(--muted); }

.line { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--line); }
.line:first-of-type { border-top: 0; padding-top: 0; }
.line__t { flex: 1; min-width: 0; font-size: 15px; line-height: 1.35; }
.line__p { flex: none; font-size: 15px; font-weight: 600; }
.line__del { flex: none; width: 36px; height: 36px; margin: -6px -8px -6px 0; border: 0; background: none; color: var(--muted); display: grid; place-items: center; border-radius: 50%; }
.line__del:active { background: var(--bg); color: var(--danger); }

/* Блок автоматически добавленных услуг — главный акцент корзины */
.auto {
  border: 1px solid #b9e4f7;
  background: linear-gradient(180deg, var(--accent-tint), #fff);
  border-radius: var(--r);
  padding: var(--sp-4);
}
.auto__badge {
  display: inline-flex; align-items: center; gap: 5px;
  margin-bottom: var(--sp-2);
  padding: 4px 9px; border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
}
.auto__badge svg { width: 13px; height: 13px; stroke-width: 2.4; }
.auto__note { margin: 0 0 var(--sp-3); font-size: 13px; line-height: 1.45; color: #0b4c67; }
.auto .line { border-top-color: #cfe9f6; }
.auto__row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid #cfe9f6; }
.auto__row:first-of-type { border-top: 0; }
.auto__ico { flex: none; width: 34px; height: 34px; border-radius: 10px; background: #fff; color: var(--accent); display: grid; place-items: center; border: 1px solid #cfe9f6; }
.auto__t { flex: 1; min-width: 0; }
.auto__n { display: block; font-size: 14px; font-weight: 600; line-height: 1.3; }
.auto__s { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }
.auto__p { flex: none; font-size: 15px; font-weight: 700; }

.total { display: flex; align-items: baseline; justify-content: space-between; padding: var(--sp-3) 0; font-size: 15px; }
.total strong { font-size: 24px; letter-spacing: -.5px; }
.total--form { border-top: 1px solid var(--line); margin: var(--sp-4) 0 var(--sp-4); }
.total--sum { border-top: 1px solid var(--line); padding-top: var(--sp-4); margin-bottom: var(--sp-3); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  width: 100%; min-height: 48px; padding: 0 var(--sp-4);
  border: 1px solid transparent; border-radius: var(--r);
  font-size: 15px; font-weight: 600; text-decoration: none;
  transition: transform .15s var(--ease), background .2s var(--ease), opacity .2s var(--ease);
}
.btn:active { transform: scale(.985); }
.btn--lg { min-height: 52px; font-size: 16px; }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:disabled { opacity: .55; }
.btn--sec { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn--ghost { background: var(--bg); color: var(--ink-2); }
.btn + .btn { margin-top: var(--sp-2); }
.btn.is-busy { opacity: .7; pointer-events: none; }

/* ---------- Форма ---------- */
.f { margin-bottom: var(--sp-4); }
.f label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; color: var(--ink-2); }
.req { color: var(--brand); }
.f input, .f textarea {
  width: 100%; min-height: 48px;
  padding: 12px var(--sp-4);
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--bg); color: var(--ink);
  font: inherit; font-size: 16px;
  appearance: none; -webkit-appearance: none;
  transition: border-color .2s var(--ease), background .2s var(--ease);
}
.f textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
.f input:focus, .f textarea:focus { outline: none; border-color: var(--brand); background: var(--card); }
.f input[aria-invalid="true"] { border-color: var(--danger); background: #fdf2f2; }
.f--row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.f--row > div { margin: 0; }
.hint { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.err { margin: 6px 0 0; font-size: 13px; font-weight: 500; color: var(--danger); }
.fine { margin: var(--sp-3) 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); text-align: center; }

.alert {
  margin-bottom: var(--sp-4); padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r); border: 1px solid #f3c9c9; background: #fdf2f2;
  color: #8c1d1d; font-size: 14px; line-height: 1.45;
}

.switch { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__ui {
  flex: none; width: 48px; height: 29px; border-radius: 999px;
  background: #d6d9df; position: relative;
  transition: background .2s var(--ease);
}
.switch__ui::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 23px; height: 23px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .2s var(--ease);
}
.switch input:checked + .switch__ui { background: var(--brand); }
.switch input:checked + .switch__ui::after { transform: translateX(19px); }
.switch input:focus-visible + .switch__ui { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch__lbl { font-size: 15px; line-height: 1.3; }
.switch__lbl small { display: block; margin-top: 2px; font-size: 12.5px; color: var(--muted); }

.check { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-2) 0; font-size: 14px; line-height: 1.4; color: var(--ink-2); cursor: pointer; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check__ui {
  flex: none; width: 24px; height: 24px; margin-top: -1px;
  border: 1.5px solid #c6cad2; border-radius: 7px;
  display: grid; place-items: center; color: transparent;
  transition: background .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease);
}
.check__ui svg { width: 15px; height: 15px; stroke-width: 3; }
.check input:checked + .check__ui { background: var(--brand); border-color: var(--brand); color: #fff; }
.check input:focus-visible + .check__ui { outline: 2px solid var(--brand); outline-offset: 2px; }
.check.is-bad .check__ui { border-color: var(--danger); }

.done { padding: var(--sp-6) var(--sp-2) var(--sp-4); text-align: center; }
.done__ico {
  width: 64px; height: 64px; margin: 0 auto var(--sp-4);
  border-radius: 50%; background: #e6f6ee; color: var(--ok);
  display: grid; place-items: center;
}
.done__ico svg { width: 32px; height: 32px; stroke-width: 2.6; }
.done h3 { margin: 0 0 var(--sp-2); font-size: 20px; }
.done p { margin: 0 0 var(--sp-5); color: var(--ink-2); line-height: 1.5; }

/* ---------- Тост ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + var(--safe-b) + 12px);
  transform: translateX(-50%);
  z-index: 70; max-width: calc(100% - 32px);
  padding: 11px var(--sp-4);
  border-radius: 999px; background: rgba(21,23,28,.94); color: #fff;
  font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: toastIn .22s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Планшет и десктоп ---------- */
@media (min-width: 768px) {
  :root { --bar-h: 82px; }
  .wrap { padding: 0 var(--sp-6); }
  .chips { max-width: 760px; margin: 0 auto; padding-left: var(--sp-6); padding-right: var(--sp-6); }
  .hdr__txt strong { font-size: 18px; }
  .item { min-height: 64px; }
  .item__n { font-size: 15.5px; }
  .sheet__panel { max-width: 560px; left: 50%; transform: translateX(-50%); border-radius: var(--r-lg); bottom: var(--sp-6); max-height: 86vh; }
  @keyframes up { from { transform: translate(-50%, 4%); opacity: .6; } }
  .sheet__panel { animation: up .28s var(--ease); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
