/* Аптечный список покупок: светлая и тёмная темы через CSS-переменные. */

:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #eef1f6;
  --text: #1c2533;
  --muted: #647082;
  --line: #dde3ec;
  --accent: #1a7a4a;
  --accent-contrast: #ffffff;
  --accent-soft: #e2f3ea;
  --warn: #b3541e;
  --warn-soft: #fbeade;
  --danger: #b3261e;
  --danger-soft: #f9e2e0;
  --badge: #e3e8f0;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08);
}

[data-theme="dark"] {
  --bg: #14181f;
  --panel: #1d232d;
  --panel-2: #242b37;
  --text: #e6eaf1;
  --muted: #98a3b5;
  --line: #323b4a;
  --accent: #35b877;
  --accent-contrast: #0d1a12;
  --accent-soft: #1d3226;
  --warn: #e8965a;
  --warn-soft: #3a2a1d;
  --danger: #e5645c;
  --danger-soft: #3d2220;
  --badge: #2c3543;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.hidden { display: none !important; }

/* ---------- шапка ---------- */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar-in {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.brand-icon { font-size: 22px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.table-updated { color: var(--muted); font-size: 12.5px; }
.btn-icon {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  width: 36px; height: 36px; cursor: pointer; font-size: 16px;
}
.btn-icon:hover { border-color: var(--accent); }

/* ---------- панель инструментов ---------- */
.toolbar {
  display: flex; gap: 14px; align-items: center;
  margin: 18px 0 10px;
}
.search {
  flex: 1; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); font-size: 15px;
}
.select-all { color: var(--muted); user-select: none; cursor: pointer; white-space: nowrap; }

/* ---------- алфавит ---------- */
.letter-nav {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 8px 0; position: sticky; top: 56px;
  background: var(--bg); z-index: 5;
}
.letter-nav a {
  min-width: 26px; text-align: center; padding: 3px 6px;
  border-radius: 6px; text-decoration: none;
  color: var(--accent); font-weight: 600; font-size: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.letter-nav a:hover { background: var(--accent-soft); }
.letter-nav a.absent { color: var(--muted); background: var(--bg); border-style: dashed; opacity: .55; }

/* ---------- группы ---------- */
.group-title {
  margin: 18px 0 6px; font-size: 15px; color: var(--muted);
  border-bottom: 1px solid var(--line); padding-bottom: 4px;
}
.group-title b { color: var(--text); font-size: 18px; margin-right: 6px; }

.card {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.card input[type="checkbox"] {
  width: 19px; height: 19px; margin-top: 2px; flex: none; cursor: pointer;
  accent-color: var(--accent);
}
.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 600; }
.card-props { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.card-props .sep { margin: 0 6px; opacity: .5; }
.ph-dots { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.ph-dot {
  font-size: 11.5px; padding: 1px 8px; border-radius: 20px;
  background: var(--badge); color: var(--muted);
}
.ph-dot.has { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- сборка ---------- */
.actionbar {
  position: sticky; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--bg); padding: 12px 0;
  border-top: 1px solid var(--line);
}
.actionbar-info { color: var(--muted); }
.btn {
  border: none; border-radius: 9px; padding: 11px 20px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--accent); padding: 6px 10px; }
.btn:hover:not(:disabled) { filter: brightness(1.06); }

.loading { color: var(--muted); padding: 26px 0; text-align: center; }
.error {
  background: var(--danger-soft); color: var(--danger);
  border-radius: 10px; padding: 14px; margin: 16px 0;
}

/* круговой таймер на время сбора */
.collect-progress {
  display: flex; align-items: center; gap: 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; margin: 14px 0; box-shadow: var(--shadow);
}
.timer-box { position: relative; width: 64px; height: 64px; flex: none; }
.timer { transform: rotate(-90deg); display: block; }
.timer-bg { fill: none; stroke: var(--panel-2); stroke-width: 6; }
.timer-fg {
  fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round;
  stroke-dasharray: 175.93; stroke-dashoffset: 0;
}
.timer-num {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 16px;
}
.timer-label { color: var(--muted); font-size: 13.5px; line-height: 1.5; }

/* ---------- результаты ---------- */
.result-head { display: flex; align-items: baseline; gap: 14px; margin: 18px 0 4px; flex-wrap: wrap; }
.result-head h2 { margin: 0; font-size: 22px; }
.result-meta { color: var(--muted); font-size: 13px; }

.notes {
  background: var(--warn-soft); color: var(--warn);
  border-radius: 10px; padding: 10px 14px; margin: 10px 0; font-size: 14px;
}
.notes div { margin: 3px 0; }

.result-cards { margin-top: 12px; }

.ph-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: 16px; box-shadow: var(--shadow); overflow: hidden;
}
.ph-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; background: var(--panel-2); flex-wrap: wrap;
}
.ph-title { font-size: 18px; font-weight: 650; }
.ph-total { color: var(--muted); }
.ph-card table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.ph-card td { padding: 9px 16px; border-top: 1px solid var(--line); vertical-align: top; }
.ph-card td.name-cell { min-width: 45%; }
.ph-card .site-name { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.ph-card .price-cell { white-space: nowrap; font-weight: 650; text-align: right; }
.ph-card .price-cell small { display: block; color: var(--muted); font-weight: 400; }
.qty-ctl { display: inline-flex; align-items: center; gap: 6px; }
.qty-ctl button {
  width: 24px; height: 24px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  cursor: pointer; line-height: 1;
}
.ph-status { font-size: 12px; color: var(--muted); }
.ph-empty { color: var(--muted); padding: 14px 16px; }

/* спойлер с деталями заказа конкретной аптеки */
.order-details summary {
  cursor: pointer; padding: 11px 16px;
  color: var(--accent); font-weight: 600; font-size: 14px;
  border-top: 1px solid var(--line); list-style: none; user-select: none;
}
.order-details summary::-webkit-details-marker { display: none; }
.order-details summary::before { content: '▸ '; }
.order-details[open] summary::before { content: '▾ '; }
.order-details summary:hover { background: var(--panel-2); }
.order-details summary .sum-total { color: var(--muted); font-weight: 400; }

.ph-card details.skip-details { padding: 0 16px 12px; }
.ph-card details.skip-details summary {
  color: var(--warn); cursor: pointer; font-size: 13.5px; padding: 8px 0;
}
.skip-item { color: var(--muted); font-size: 13.5px; margin: 6px 0; }
.skip-item b { color: var(--text); font-weight: 600; }
.skip-reason { color: var(--warn); }

/* сравнительная таблица цен по препаратам */
.cmp-hint { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
.cmp-wrap { overflow-x: auto; margin-bottom: 16px; }
.cmp-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.cmp-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cmp-table th, .cmp-table td {
  padding: 8px 12px; border-top: 1px solid var(--line);
  text-align: right; white-space: nowrap; vertical-align: top;
}
.cmp-table thead th {
  background: var(--panel-2); border-top: none;
  font-size: 12.5px; color: var(--muted); font-weight: 600;
}
.cmp-table th:first-child, .cmp-table td:first-child {
  text-align: left; white-space: normal; min-width: 210px;
}
.cmp-name b { font-weight: 600; }
.cmp-name small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.cmp-table td.best { color: var(--accent); font-weight: 700; background: var(--accent-soft); }
.cmp-table td.skip { color: var(--muted); font-size: 12px; font-weight: 400; }
.cmp-table td.only { color: var(--text); }

.userscript-help { margin: 14px 0 30px; color: var(--muted); font-size: 14px; }
.userscript-help code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }
.userscript-help p { margin: 8px 0; }

.footer {
  border-top: 1px solid var(--line); color: var(--muted);
  font-size: 12.5px; padding: 14px 0 26px; margin-top: 10px;
}

@media (max-width: 640px) {
  .table-updated { display: none; }
  .toolbar { flex-wrap: wrap; }
  .ph-card td { padding: 8px 10px; }
}
