:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --border: #e5e7eb;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0, 0, 0, .08);
}

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

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

/* ---------- Шапка ---------- */
.header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px;
}

.logo {
  font-size: 20px; font-weight: 800; letter-spacing: -.02em;
  text-decoration: none; color: var(--text);
}

.cart-btn {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 42px; height: 42px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  cursor: pointer; transition: border-color .15s, transform .1s;
}
.cart-btn:hover { border-color: var(--accent); }
.cart-btn:active { transform: scale(.96); }

.cart-count {
  position: absolute; top: -6px; right: -6px;
  min-width: 20px; height: 20px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 700;
  border-radius: 10px;
}

/* ---------- Герой ---------- */
.hero { padding: 40px 0 24px; }
.hero h1 { font-size: 28px; letter-spacing: -.02em; }
.hero p { color: var(--muted); margin-top: 6px; }

/* ---------- Каталог ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding-bottom: 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: box-shadow .2s, transform .2s;
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }

.card-img {
  width: 100%; aspect-ratio: 4 / 3;
  display: flex; align-items: center; justify-content: center;
  font-size: 44px; font-weight: 800; color: rgba(255, 255, 255, .9);
  user-select: none;
}

img.card-img { object-fit: cover; display: block; }

.card-old-price {
  font-size: 13px; font-weight: 600;
  color: var(--muted);
  text-decoration: line-through;
  margin-right: 6px;
}

.card-body {
  padding: 12px 14px 14px;
  display: flex; flex-direction: column; gap: 8px;
  flex: 1;
}

.card-title { font-size: 15px; font-weight: 600; line-height: 1.35; }

/* Бейдж наличия */
.stock-badge {
  display: inline-block;
  font-size: 12px; font-weight: 700;
  padding: 3px 9px;
  border-radius: 8px;
}
.stock-ok  { background: #ecfdf5; color: #059669; }
.stock-low { background: #fff7ed; color: #d97706; }
.stock-out { background: #fef2f2; color: #dc2626; }

/* Службы доставки под карточкой */
.card-carriers {
  font-size: 12px;
  color: var(--muted);
}

.card-bottom {
  margin-top: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}

.card-price { font-size: 17px; font-weight: 800; }

/* ---------- Кнопки ---------- */
.btn {
  border: none; border-radius: 10px;
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; padding: 11px 18px; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-block { width: 100%; }

.btn-add {
  background: var(--accent); color: #fff;
  padding: 8px 14px; font-size: 14px;
}
.btn-add:hover { background: var(--accent-hover); }

.btn-add.in-cart { background: #059669; }

.icon-btn {
  border: none; background: none;
  font-size: 26px; line-height: 1;
  color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); }

/* ---------- Корзина ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(17, 20, 28, .45);
  animation: fade .2s;
}

.cart-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
  width: min(400px, 100%);
  background: var(--surface);
  display: flex; flex-direction: column;
  animation: slide-in .25s ease;
}

@keyframes slide-in { from { transform: translateX(100%); } }
@keyframes fade { from { opacity: 0; } }

.cart-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.cart-head h2 { font-size: 19px; }

.cart-items { flex: 1; overflow-y: auto; padding: 12px 20px; }

.cart-empty { color: var(--muted); text-align: center; padding: 40px 0; }

.cart-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.cart-item-thumb {
  width: 48px; height: 48px; flex-shrink: 0;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 15px;
}

.cart-item-info { flex: 1; min-width: 0; }
.cart-item-title { font-size: 14px; font-weight: 600; }
.cart-item-price { font-size: 13px; color: var(--muted); }

.qty {
  display: flex; align-items: center; gap: 8px;
}
.qty button {
  width: 26px; height: 26px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer;
  font-size: 15px; line-height: 1;
}
.qty button:hover { border-color: var(--accent); }
.qty span { min-width: 18px; text-align: center; font-weight: 600; font-size: 14px; }

.cart-foot {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
}
.cart-total {
  display: flex; justify-content: space-between;
  font-size: 17px; margin-bottom: 12px;
}

/* ---------- Карточка товара ---------- */

.modal-box.product-box {
  width: min(860px, 100%);
  padding: 0;
  overflow: hidden;
}

.pm-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
}

.pm-media { padding: 20px 0 20px 20px; }

.pm-main {
  width: 100%; aspect-ratio: 1 / 1;
  border-radius: 14px; overflow: hidden;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 64px; font-weight: 800; color: rgba(255,255,255,.9);
}
.pm-main img { width: 100%; height: 100%; object-fit: cover; }
.pm-main iframe, .pm-main video { width: 100%; height: 100%; border: none; background: #000; }

.pm-thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pm-thumb {
  width: 56px; height: 56px;
  border-radius: 10px; overflow: hidden;
  border: 2px solid var(--border);
  background: var(--bg);
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  transition: border-color .15s;
}
.pm-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pm-thumb.active, .pm-thumb:hover { border-color: var(--accent); }

.pm-info { padding: 20px 24px 24px; display: flex; flex-direction: column; gap: 10px; }

.pm-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.pm-title { font-size: 21px; font-weight: 800; letter-spacing: -.01em; line-height: 1.3; }

.pm-variants { display: flex; gap: 8px; flex-wrap: wrap; }
.pm-variant {
  border: 2px solid var(--border); border-radius: 10px;
  background: var(--surface);
  padding: 7px 13px; font: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: border-color .15s, color .15s;
}
.pm-variant:hover { border-color: var(--accent); }
.pm-variant.active { border-color: var(--accent); color: var(--accent); background: rgba(79,70,229,.07); }

.pm-price { display: flex; align-items: baseline; gap: 10px; }
.pm-price .card-price { font-size: 24px; }
.pm-price .card-old-price { font-size: 16px; }

.pm-desc {
  font-size: 14px; color: var(--text);
  white-space: pre-line; line-height: 1.55;
  max-height: 280px; overflow-y: auto;
}

.pm-actions { margin-top: auto; padding-top: 8px; }

@media (max-width: 720px) {
  .pm-grid { grid-template-columns: 1fr; }
  .pm-media { padding: 16px 16px 0; }
  .pm-info { padding: 14px 16px 18px; }
}

/* ---------- Модалка заказа ---------- */

.modal {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(17, 20, 28, .5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 12px;
  overflow-y: auto;
  animation: fade .2s;
}

.modal-box {
  background: var(--surface);
  border-radius: 18px;
  width: min(560px, 100%);
  padding-bottom: 24px;
  box-shadow: var(--shadow);
}

.modal-box .cart-head { padding: 18px 24px; }

#order-form { padding: 8px 24px 0; }

fieldset {
  border: none;
  margin-bottom: 18px;
}

legend {
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 10px;
}

label {
  display: block;
  font-size: 13px; font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

input[type="text"], input[type="tel"] {
  display: block; width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  font: inherit;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg);
  transition: border-color .15s, box-shadow .15s;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
input.invalid { border-color: #dc2626; }

.row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.row label { margin-bottom: 0; }

/* Переключатель СДЭК / Почта России */
.provider-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-bottom: 14px;
}

.provider { position: relative; margin: 0; }
.provider input { position: absolute; opacity: 0; }

.provider span {
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
  border: 2px solid var(--border); border-radius: 12px;
  font-weight: 700; font-size: 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.provider input:checked + span {
  border-color: var(--accent);
  background: rgba(79, 70, 229, .07);
  color: var(--accent);
}
.provider input:focus-visible + span { box-shadow: 0 0 0 3px rgba(79, 70, 229, .2); }

/* Карта */
.map-wrap { margin-bottom: 12px; }

#map-frame {
  width: 100%; height: 300px;
  border: 1px solid var(--border); border-radius: 12px;
}

#pvz-map {
  width: 100%; height: 300px;
  border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden;
}

.map-hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Итог в форме */
.order-summary {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 14px;
}
.order-summary .sum-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 3px 0;
}
.order-summary .sum-total {
  border-top: 1px solid var(--border);
  margin-top: 6px; padding-top: 8px;
  font-weight: 800; font-size: 15px;
}

.form-error {
  background: #fef2f2; color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 14px;
}

/* Успех */
.order-success { padding: 32px 24px 8px; text-align: center; }

.success-icon {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: #059669; color: #fff;
  font-size: 32px; font-weight: 800;
  border-radius: 50%;
}

.order-success h3 { margin-bottom: 6px; }
.order-success p { color: var(--muted); margin-bottom: 20px; }

/* ---------- Подвал ---------- */
.footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  color: var(--muted); font-size: 13px;
}

/* ---------- Адаптив ---------- */
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .hero h1 { font-size: 22px; }
  .row { grid-template-columns: 1fr; gap: 0; }
  .row label { margin-bottom: 10px; }
}
