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

/* Фон и текст — своя палитра: переменные --tg-theme-* внутри Telegram заданы
   всегда (по теме Telegram) и ломали ручное переключение темы. От Telegram
   берём только акцентный цвет. */
:root {
  --bg: #eef1f6;
  --text: #101418;
  --hint: #79808c;
  --accent: var(--tg-theme-button-color, #2f7cf6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e5484d;
  --glass: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.65);
  --glass-strong: rgba(255, 255, 255, 0.72);
  --shadow: 0 8px 32px rgba(30, 41, 59, 0.10);
  --skeleton: rgba(0, 0, 0, 0.06);
}

html[data-theme="dark"] {
  --bg: #101418;
  --text: #f1f3f6;
  --hint: #8a919e;
  --glass: rgba(255, 255, 255, 0.07);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-strong: rgba(30, 34, 42, 0.85);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --skeleton: rgba(255, 255, 255, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Фоновые цветовые пятна под стеклом */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.45; }
.b1 { width: 340px; height: 340px; top: -120px; right: -100px;
      background: radial-gradient(circle, #6ea8ff, transparent 70%); }
.b2 { width: 300px; height: 300px; top: 40%; left: -140px;
      background: radial-gradient(circle, #b08cff, transparent 70%);
      animation: drift 24s ease-in-out infinite alternate; }
.b3 { width: 260px; height: 260px; bottom: -80px; right: -60px;
      background: radial-gradient(circle, #6fe3c4, transparent 70%); }
@keyframes drift { to { transform: translate(60px, -40px) scale(1.15); } }
html[data-theme="dark"] .blob { opacity: 0.22; }

main {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

header { display: flex; align-items: center; gap: 10px; padding: 8px 4px 16px; }
.theme-toggle {
  margin-left: auto; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--glass-border); background: var(--glass);
  backdrop-filter: blur(24px) saturate(160%); -webkit-backdrop-filter: blur(24px) saturate(160%);
  box-shadow: var(--shadow); color: var(--text); cursor: pointer;
  display: grid; place-items: center; transition: transform 0.15s;
}
.theme-toggle:active { transform: scale(0.9); }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.counter { font-size: 15px; color: var(--hint); font-weight: 500; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

/* Строка добавления */
.add-row { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 18px; margin-bottom: 16px; }
.add-row input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  font-size: 16px; color: var(--text); padding: 10px 0;
}
.add-row input::placeholder { color: var(--hint); }
.add-row button {
  flex-shrink: 0; width: 42px; height: 42px; border: none; border-radius: 14px;
  background: var(--accent); color: var(--accent-text); cursor: pointer;
  display: grid; place-items: center; transition: transform 0.15s, opacity 0.15s;
}
.add-row button:active { transform: scale(0.92); }
.add-row button:disabled { opacity: 0.55; }

/* Карточки товаров */
#list { display: flex; flex-direction: column; gap: 12px; }
.item {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px;
  padding: 14px; align-items: center;
  animation: rise 0.3s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.thumb {
  width: 64px; height: 64px; border-radius: 14px; object-fit: cover;
  background: var(--skeleton);
}
.thumb-placeholder {
  width: 64px; height: 64px; border-radius: 14px; background: var(--skeleton);
  display: grid; place-items: center; font-size: 24px;
}

.item-body { min-width: 0; }
.item-name {
  font-size: 14px; font-weight: 500; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; text-decoration: none; color: var(--text);
}
.price-row { display: flex; align-items: baseline; gap: 8px; margin-top: 5px; flex-wrap: wrap; }
.price { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.price-old { font-size: 13px; color: var(--hint); text-decoration: line-through; }
.badge {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: rgba(229, 72, 77, 0.12); color: var(--danger);
}
.badge.ok { background: rgba(48, 164, 108, 0.14); color: #2c9d68; }

.target-chip {
  margin-top: 8px; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--glass-border); background: var(--glass);
  color: var(--text); cursor: pointer; transition: transform 0.15s;
}
.target-chip:active { transform: scale(0.95); }
.target-chip.unset { color: var(--accent); border-style: dashed; }
.target-chip.hit { background: rgba(48, 164, 108, 0.14); color: #2c9d68; border-color: transparent; }

.item-actions { display: flex; flex-direction: column; gap: 6px; align-self: start; }
.icon-btn {
  width: 34px; height: 34px; border: none; border-radius: 12px; cursor: pointer;
  background: transparent; color: var(--hint); display: grid; place-items: center;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn.danger:active { color: var(--danger); background: rgba(229, 72, 77, 0.1); }

/* Скелетон, пока парсер проверяет товар */
.pending-label { font-size: 13px; color: var(--hint); display: flex; align-items: center; gap: 7px; }
.spinner {
  width: 13px; height: 13px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--skeleton); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton-line {
  height: 12px; border-radius: 6px; background: var(--skeleton);
  margin-top: 7px; overflow: hidden; position: relative;
}
.skeleton-line::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* Пустые состояния */
.empty { text-align: center; padding: 56px 24px; color: var(--text); }
.empty-icon { font-size: 44px; margin-bottom: 14px; }
.empty p { font-size: 17px; font-weight: 600; }
.empty .hint { font-size: 14px; font-weight: 400; color: var(--hint); margin-top: 6px; line-height: 1.5; }
.hidden { display: none !important; }

/* Шторка целевой цены */
#sheet-backdrop, #chart-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 18, 24, 0.45);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 480px;
  border-radius: 26px 26px 0 0; border-bottom: none;
  background: var(--glass-strong);
  padding: 10px 22px calc(26px + env(safe-area-inset-bottom));
  animation: slide-up 0.28s cubic-bezier(0.32, 0.72, 0.25, 1);
}
@keyframes slide-up { from { transform: translateY(100%); } }
.sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--hint); opacity: 0.4; margin: 4px auto 16px; }
.sheet h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-product { font-size: 13.5px; color: var(--hint); margin-top: 5px;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.target-input-wrap { position: relative; margin-top: 16px; }
.target-input-wrap input {
  width: 100%; font-size: 22px; font-weight: 600; color: var(--text);
  background: var(--glass); border: 1px solid var(--glass-border); border-radius: 16px;
  padding: 14px 44px 14px 18px; outline: none;
}
.target-input-wrap input:focus { border-color: var(--accent); }
.target-input-wrap .rub {
  position: absolute; right: 18px; top: 50%; transform: translateY(-50%);
  font-size: 20px; color: var(--hint);
}
.sheet .hint { font-size: 13px; color: var(--hint); margin-top: 10px; line-height: 1.45; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn-primary, .btn-secondary {
  flex: 1; border: none; border-radius: 16px; padding: 15px 10px;
  font-size: 16px; font-weight: 600; cursor: pointer; transition: transform 0.15s, opacity 0.15s;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--glass); border: 1px solid var(--glass-border); color: var(--danger); }
.btn-primary:active, .btn-secondary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.55; }

/* График истории цены */
#chart-wrap { margin-top: 16px; }
#chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-price-label { font-size: 12px; font-weight: 600; fill: var(--hint); }
.chart-empty {
  padding: 28px 12px; text-align: center; font-size: 14px; color: var(--hint);
  line-height: 1.5;
}
.chart-range {
  display: flex; justify-content: space-between; margin-top: 8px;
  font-size: 12px; color: var(--hint); padding: 0 2px 4px;
}

/* Тост */
#toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 100;
  background: var(--glass-strong);
  backdrop-filter: blur(24px) saturate(160%); -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--glass-border); border-radius: 16px; box-shadow: var(--shadow);
  padding: 12px 20px; font-size: 14px; font-weight: 500; color: var(--text);
  max-width: calc(100vw - 48px); text-align: center;
  animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }
