/* Тема наследуется от Telegram через css-переменные с запасными значениями */
:root {
  --bg: var(--tg-theme-bg-color, #f4f4f5);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --muted: var(--tg-theme-hint-color, #8e8e93);
  --accent: var(--tg-theme-button-color, #2e6be6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2e6be6);
  --danger: #d63b3b;
  --good: #1f9d55;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  /* без этого iOS выделяет текст при тапах по графику и карточкам */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

input {
  -webkit-user-select: text;
  user-select: text;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 14px calc(28px + env(safe-area-inset-bottom));
}

/* ── шапка ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px 14px;
}
.topbar h1 { font-size: 21px; font-weight: 700; }
.topbar-text { flex: 1; }
.last-check { font-size: 12px; color: var(--muted); margin-top: 2px; }
.detail-title {
  font-size: 15px !important;
  font-weight: 600 !important;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.icon-btn {
  border: 0;
  background: var(--card);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

/* ── добавление ── */
.add-card {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.add-card input {
  flex: 1;
  border: 0;
  border-radius: var(--radius);
  padding: 13px 14px;
  font-size: 15px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  outline: none;
  min-width: 0;
}
.add-card input::placeholder { color: var(--muted); }
.add-card button {
  border: 0;
  border-radius: var(--radius);
  padding: 0 18px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
.add-card button:disabled { opacity: .55; }

.list-status {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
}

/* ── карточки товаров ── */
.group-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .3px;
  color: var(--muted);
  text-transform: uppercase;
  margin: 14px 4px 8px;
}
.group-title:first-child { margin-top: 0; }

.product {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform .08s;
}
.product:active { transform: scale(.985); }

.p-info { flex: 1; min-width: 0; }
.p-name {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 5px;
}
.p-price-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
}
.p-price { font-size: 17px; font-weight: 700; }
.p-old {
  font-size: 13px;
  color: var(--muted);
  text-decoration: line-through;
}
.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  color: #fff;
  background: var(--good);
}
.badge-off { background: var(--danger); }
.p-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

.product.oos { opacity: .72; }
.p-last-price {
  font-size: 13px;
  color: var(--muted);
  text-decoration: line-through;
}
.badge-big { font-size: 15px; padding: 5px 14px; }

.spark { flex-shrink: 0; opacity: .9; }

.spinner {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border: 2.5px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-hint {
  text-align: center;
  color: var(--muted);
  margin-top: 48px;
  line-height: 1.6;
}

.p-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}
.p-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

/* ── детальная ── */
.hero {
  padding: 4px 2px 14px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.hero-main { flex: 1; min-width: 0; }
.detail-img {
  width: 84px;
  height: 84px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--card);
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.hero-price {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.hero-sub { margin-top: 4px; font-size: 14px; color: var(--muted); }

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  margin-bottom: 12px;
}
.chart-wrap { position: relative; height: 240px; }

.chips { display: flex; gap: 8px; margin-bottom: 10px; }
/* одинаковый отступ до контента в любом режиме сортировки,
   чтобы список не «прыгал» при переключении */
.sort-chips { margin-bottom: 12px; }
.sort-chips .chip { background: var(--card); box-shadow: var(--shadow); }
.sort-chips .chip-active { background: var(--accent); color: var(--accent-text); }
.chip {
  border: 0;
  border-radius: 20px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}
.chip-active { background: var(--accent); color: var(--accent-text); }

.legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ── статистика ── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 8px;
  text-align: center;
}
.stat b { display: block; font-size: 15px; margin-top: 2px; }
.stat span { font-size: 11.5px; color: var(--muted); }

/* ── импорт вишлиста ── */
.import-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 14px;
  margin-bottom: 12px;
}
.import-bar {
  height: 8px;
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 10px;
}
#import-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 8px;
  background: var(--accent);
  transition: width .4s;
}
.import-status { font-size: 14px; color: var(--muted); }
.import-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 13px;
  margin-bottom: 8px;
  font-size: 13.5px;
  animation: fadein .25s;
}
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }
.import-item .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-item .p { font-weight: 700; white-space: nowrap; }
.import-item.dup, .import-item.error { opacity: .55; }

/* ── настройки уведомлений ── */
.notify-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 14px;
}
.notify-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.notify-mute {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14.5px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--bg);
  cursor: pointer;
}
.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 46px;
  height: 27px;
  border-radius: 27px;
  background: var(--bg);
  position: relative;
  cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: left .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { left: 22px; }
.notify-card.muted .notify-title,
.notify-card.muted .notify-option { opacity: .4; pointer-events: none; }

.archive-toggle {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 14px 0 6px;
  cursor: pointer;
  text-align: center;
}
#archive-list .product { opacity: .65; }
.notify-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 2px;
  font-size: 14.5px;
  cursor: pointer;
  flex-wrap: wrap;
}
.notify-option input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.notify-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
}
.notify-input-wrap input {
  width: 76px;
  border: 1.5px solid var(--muted);
  border-radius: 9px;
  padding: 6px 9px;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.btn-small { padding: 10px; margin-top: 8px; font-size: 14px; }

/* ── кнопки ── */
.detail-actions { display: grid; gap: 8px; }
.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
.btn-secondary { background: var(--card); color: var(--link); box-shadow: var(--shadow); }
.btn-danger { background: transparent; color: var(--danger); }

/* ── модалка ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}
.modal-body {
  background: var(--card);
  border-radius: 18px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
}
.modal-body h2 { font-size: 17px; margin-bottom: 8px; }
.modal-body p { font-size: 13.5px; line-height: 1.45; margin-bottom: 14px; }
.modal-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.modal-row input {
  flex: 1;
  border: 1.5px solid var(--muted);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { padding: 11px; }

/* ── тост ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(30, 30, 30, .92);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 22px;
  z-index: 30;
  max-width: 88vw;
  text-align: center;
}
