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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #ea580c;
  --accent-hover: #c2410c;
  --danger: #dc2626;
  --success: #16a34a;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
}

/* overflow-x: clip обрезает горизонтальный вылет, НО (в отличие от hidden) не создаёт
   scroll-контейнер и не ломает position: sticky у шапки/навбара */
html, body { overflow-x: clip; max-width: 100%; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--gray-50); color: var(--gray-800); min-height: 100vh; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.page { display: none; }
.page.active { display: block; }

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

/* Navbar — светлая, читаемая шапка с плашками (десктоп) */
nav { position: sticky; top: 0; z-index: 200; }
#main-nav { background: #fff; border-bottom: 1px solid var(--gray-200); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 60px;
  flex-wrap: nowrap; gap: 12px; }
.nav-logo { font-weight: 800; font-size: 1.2rem; color: var(--primary); letter-spacing: -.02em;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; flex-shrink: 0; }
.nav-logo::before { content: "⚡"; font-size: 1.25rem; }
.nav-links { display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }
.nav-links button, #btn-nav-admin { background: var(--gray-100); border: none; cursor: pointer;
  padding: 9px 16px; border-radius: 22px; color: var(--gray-800); font-size: .9rem; font-weight: 600;
  white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center;
  transition: background .15s, color .15s; }
.nav-links button:hover, #btn-nav-admin:hover { background: var(--primary); color: #fff; }
#btn-logout { background: none; color: var(--gray-400); font-weight: 500; padding: 9px 12px; }
#btn-logout:hover { background: #fee2e2; color: var(--danger); }
#btn-nav-login { background: var(--primary) !important; color: #fff !important; font-weight: 700;
  padding: 9px 18px !important; box-shadow: 0 2px 8px rgba(37,99,235,.3); }
#btn-nav-login:hover { background: var(--primary-hover) !important; }
.nav-cart-btn { display: inline-flex; align-items: center; gap: 7px; background: var(--accent) !important;
  border: none !important; color: #fff !important; font-weight: 700; padding: 9px 18px !important;
  border-radius: 22px !important; cursor: pointer; font-size: .9rem; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(234,88,12,.35); transition: background .15s, transform .12s; }
.nav-cart-btn:hover { background: var(--accent-hover) !important; transform: translateY(-1px); }
.nav-cart-btn .badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 0 6px;
  font-size: .75rem; font-weight: 700; line-height: 1.5; display: inline-block; box-shadow: 0 0 0 2px #fff; }

/* Cards */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }

/* Auth */
.auth-wrap { min-height: calc(100vh - 57px); display: flex; align-items: center; justify-content: center; }
.auth-box { width: 100%; max-width: 400px; }
.auth-box h1 { font-size: 1.4rem; margin-bottom: 24px; }
.auth-step { display: none; }
.auth-step.active { display: block; }

/* Forms */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: .85rem; font-weight: 500; color: var(--gray-600); margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"], textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--gray-200); border-radius: var(--radius);
  font-size: 1rem; outline: none; transition: border .15s;
}
input:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 20px;
  border-radius: var(--radius); border: none; cursor: pointer; font-size: .95rem; font-weight: 500;
  transition: background .15s; width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--gray-50); }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.error-msg { color: var(--danger); font-size: .85rem; margin-top: 8px; min-height: 18px; }
.success-msg { color: var(--success); font-size: .85rem; margin-top: 8px; }

/* Products */
.toolbar { display: flex; gap: 12px; margin-bottom: 20px; align-items: center; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; }
.badge { background: var(--primary); color: #fff; border-radius: 12px; padding: 2px 8px; font-size: .75rem; font-weight: 600; }

/* Brand sidebar */
.brand-filter-section { padding-bottom: 12px; }
.brand-item { padding: 7px 12px; font-size: .85rem; color: var(--gray-700); cursor: pointer; border-radius: 6px; transition: background .15s; }
.brand-item:hover { background: var(--gray-100); }
.brand-item.active { background: var(--primary); color: #fff; font-weight: 600; }

.products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.product-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  display: flex; flex-direction: column; gap: 8px; min-width: 0; overflow: hidden; }
.product-brand { font-size: .75rem; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; overflow-wrap: anywhere; }
.product-name { font-weight: 600; font-size: .95rem; cursor: pointer; overflow-wrap: anywhere; }
.product-name.has-desc { text-decoration-line: underline; text-decoration-style: dotted; text-underline-offset: 3px; color: inherit; }
.product-code { color: var(--gray-400); font-size: .8rem; overflow-wrap: anywhere; }
.product-desc { font-size: .82rem; color: var(--gray-600); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.product-desc.expanded { -webkit-line-clamp: unset; display: block; overflow: visible; }
.product-name.has-desc { cursor: pointer; }
.product-stock { font-size: .8rem; font-weight: 600; }
.product-stock.in-stock { color: var(--success); }
.product-stock.out-stock { color: var(--gray-400); font-weight: 500; }

/* Маркетинг: бейдж и «выгода» */
.mk-badges { display: flex; flex-wrap: wrap; gap: 4px; align-self: flex-start; }
.mk-badge { display: inline-block; align-self: flex-start; background: var(--gray-600); color: #fff;
  font-size: .72rem; font-weight: 700; padding: 2px 9px; border-radius: 10px; text-transform: uppercase; letter-spacing: .02em; }
.mk-sale       { background: #dc2626; }  /* Распродажа — красный */
.mk-promo      { background: #ea580c; }  /* Акции — оранжевый */
.mk-bestseller { background: #7c3aed; }  /* Хит продаж — фиолетовый */
.mk-new        { background: #16a34a; }  /* Новинка — зелёный */
.mk-saving { font-size: .82rem; font-weight: 700; color: var(--success); margin-top: 2px; }
.pm-head .mk-badges { margin-bottom: 6px; }

/* Модалка товара (открытие карточки) */
.pm-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 1300; display: none;
  align-items: center; justify-content: center; padding: 16px; }
.pm-overlay.open { display: flex; }
/* Модалка = flex-колонка: галерея/шапка/кнопка фиксированы, скроллится только описание */
.pm { background: #fff; border-radius: var(--radius); width: 100%; max-width: 520px; max-height: 90vh;
  position: relative; box-shadow: 0 10px 40px rgba(0,0,0,.3);
  display: flex; flex-direction: column; overflow: hidden; }
.pm-close { position: absolute; top: 8px; right: 8px; z-index: 5; width: 32px; height: 32px; border: none;
  border-radius: 50%; background: rgba(0,0,0,.5); color: #fff; font-size: 1.05rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; }
.pm-gallery { flex-shrink: 0; padding: 16px 16px 0; }
.pm-gallery .product-img-wrap { height: 280px; margin-bottom: 0; }
.pm-head { flex-shrink: 0; padding: 12px 18px 8px; }
.pm-name { font-size: 1.15rem; line-height: 1.3; margin: 4px 0 8px; }
.pm-meta { font-size: .82rem; color: var(--gray-400); margin-bottom: 8px; }
.pm-price { font-size: 1.35rem; font-weight: 700; color: var(--primary); }
.pm-stock-row { margin: 6px 0 0; }
.pm-desc { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 10px 18px; font-size: .9rem; line-height: 1.55; color: var(--gray-700);
  white-space: pre-wrap; overflow-wrap: anywhere; border-top: 1px solid var(--gray-100); }
.pm-buy { flex-shrink: 0; padding: 12px 18px calc(16px + env(safe-area-inset-bottom)); margin: 0;
  border-top: 1px solid var(--gray-100); }
@media (max-width: 768px) {
  /* dvh учитывает плавающую панель браузера на iOS — кнопка не уходит под неё */
  .pm { max-height: 88vh; max-height: 88dvh; }
  .pm-gallery { padding: 12px 12px 0; }
  .pm-gallery .product-img-wrap { height: 200px; }
}
.product-price { font-size: 1.1rem; font-weight: 700; color: var(--primary); margin-top: auto; }
.product-unit { color: var(--gray-400); font-size: .8rem; }
.qty-row { display: flex; align-items: center; gap: 8px; margin-top: auto; }
.qty-row input { width: 60px; text-align: center; }
.btn-add { padding: 8px 14px; width: auto; font-size: .85rem; }

/* Переключатель вида каталога */
.view-switch { display: inline-flex; border: 1px solid var(--gray-200); border-radius: var(--radius);
  overflow: hidden; flex-shrink: 0; }
.view-switch button { background: #fff; border: none; border-left: 1px solid var(--gray-200);
  padding: 8px 13px; cursor: pointer; font-size: 1.05rem; line-height: 1; color: var(--gray-600); width: auto; }
.view-switch button:first-child { border-left: none; }
.view-switch button:hover { background: var(--gray-50); }
.view-switch button.active { background: var(--primary); color: #fff; }

/* Режимы вида: 2 в ряд */
.products-grid.view-grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* Режим списка: компактная строка, справа — управление и небольшое фото */
.products-grid.view-list { display: flex; flex-direction: column; gap: 10px; }
.products-grid.view-list .product-card {
  display: block; position: relative; padding: 12px 192px 12px 16px; min-height: 118px;
}
.products-grid.view-list .product-desc { display: none; }
.products-grid.view-list .product-brand,
.products-grid.view-list .product-name,
.products-grid.view-list .product-code { margin: 0; }
.products-grid.view-list .product-name { font-size: .92rem; }
.products-grid.view-list .product-price { margin: 6px 0 0; font-size: 1rem; }
/* Управление — сверху справа */
.products-grid.view-list .qty-row {
  position: absolute; top: 12px; right: 16px; margin: 0; width: auto;
}
/* Небольшое фото — под кнопкой «В корзину» */
.products-grid.view-list .product-img-wrap {
  display: flex; position: absolute; right: 16px; bottom: 12px;
  width: 76px; height: 76px; margin: 0;
}
.products-grid.view-list .product-img-zoom { display: none; }

/* Cart */
.cart-panel { position: fixed; right: 0; top: 56px; bottom: 0; width: 360px; background: #fff;
  border-left: 1px solid var(--gray-200); transform: translateX(100%); transition: transform .25s;
  display: flex; flex-direction: column; z-index: 50; }
.cart-panel.open { transform: translateX(0); }
.cart-header { padding: 16px; border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }
.cart-header h2 { font-size: 1rem; }
.cart-body { flex: 1; overflow-y: auto; padding: 12px; }
.cart-footer { padding: 16px; border-top: 1px solid var(--gray-200); }
.cart-item { display: flex; gap: 8px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--gray-100); }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-size: .9rem; font-weight: 500; word-break: break-word; }
.cart-item-price { font-size: .85rem; color: var(--gray-600); }
.cart-item-controls { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.qty-btn { width: 28px; height: 28px; border: 1px solid var(--gray-200); background: var(--gray-50);
  border-radius: 4px; cursor: pointer; font-size: 1rem; line-height: 1; display: flex; align-items: center; justify-content: center; }
.qty-btn:hover { background: var(--gray-100); }
.qty-input { width: 48px; height: 28px; text-align: center; padding: 0 4px; font-size: .9rem;
  border: 1px solid var(--gray-200); border-radius: 4px; }
.cart-item-remove { background: none; border: none; color: var(--gray-400); cursor: pointer; font-size: 1.2rem;
  line-height: 1; padding: 0 2px; margin-left: 2px; }
.cart-item-remove:hover { color: var(--danger); }
.cart-total { font-size: 1rem; font-weight: 700; margin-bottom: 12px; }
.cart-empty { color: var(--gray-400); text-align: center; padding: 40px 0; }
.cart-toggle { position: relative; }
.cart-toggle .badge { position: absolute; top: -4px; right: -4px; }
.btn-sm { padding: 5px 12px; font-size: .8rem; width: auto; }

/* Toast notification */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--gray-800); color: #fff; padding: 10px 20px; border-radius: var(--radius);
  font-size: .9rem; opacity: 0; transition: opacity .2s, transform .2s; z-index: 300; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: var(--danger); }

/* Orders history */
.orders-list { display: flex; flex-direction: column; gap: 16px; }
.order-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  border-left: 4px solid var(--gray-200); }
/* Чередование фона, чтобы визуально различать соседние заказы */
.orders-list .order-card:nth-child(odd)  { background: #fff;    border-left-color: var(--primary); }
.orders-list .order-card:nth-child(even) { background: #f4f7ff; border-left-color: #93b4f5; }
.order-meta { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.order-num { font-weight: 700; }
/* Сворачиваемая шапка заказа */
.order-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; cursor: pointer; user-select: none; }
.order-head:hover .order-num { color: var(--primary); }
.order-toggle { color: var(--gray-400); font-size: .8rem; width: 12px; flex-shrink: 0; }
.order-head.open .order-toggle { color: var(--primary); }
.order-date { color: var(--gray-400); font-size: .85rem; }
.order-count { color: var(--gray-500); font-size: .85rem; }
.order-1c { font-size: .85rem; }
.order-sum { margin-left: auto; font-weight: 700; color: var(--gray-800); font-size: 1rem; }
.order-body { margin-top: 12px; }
.status-badge { padding: 2px 10px; border-radius: 12px; font-size: .78rem; font-weight: 600; text-transform: uppercase; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-sent_to_1c { background: #d1fae5; color: #065f46; }
.status-error { background: #fee2e2; color: #991b1b; }
.order-items-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.order-items-table th { text-align: left; color: var(--gray-400); font-weight: 500; border-bottom: 1px solid var(--gray-100); padding: 4px 0; }
.order-items-table td { padding: 4px 0; }

/* Modals */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 200; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 28px; width: 100%; max-width: 440px; margin: 16px;
  max-height: calc(100vh - 32px); overflow-y: auto; }
.modal h2 { margin-bottom: 16px; font-size: 1.1rem; }

/* Product images */
.product-img-wrap { position: relative; width: 100%; height: 160px; border-radius: 6px; background: var(--gray-100); margin-bottom: 8px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.product-img { width: 100%; height: 100%; object-fit: contain; }
.product-img-zoom { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px;
  background: rgba(0,0,0,.45); border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 14px; color: #fff; cursor: zoom-in;
  opacity: 0; transition: opacity .15s; z-index: 2; pointer-events: auto; }
.product-img-wrap:hover .product-img-zoom { opacity: 1; }
.product-img-placeholder { font-size: 2.5rem; color: var(--gray-400); user-select: none; }

/* Карусель фото товара */
.car-btn { position: absolute; top: 50%; transform: translateY(-50%); width: 26px; height: 26px;
  border: none; border-radius: 50%; background: rgba(0,0,0,.4); color: #fff; font-size: 1.15rem;
  line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
  z-index: 3; opacity: .85; padding: 0; }
.car-btn:hover { background: rgba(0,0,0,.7); opacity: 1; }
.car-prev { left: 4px; }
.car-next { right: 4px; }
.car-dots { position: absolute; bottom: 6px; left: 0; right: 0; display: flex; justify-content: center;
  gap: 5px; z-index: 3; pointer-events: none; }
.car-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(0,0,0,.28);
  cursor: pointer; pointer-events: auto; transition: background .15s; }
.car-dot.active { background: var(--primary); }
/* В режиме списка (мелкое фото) стрелки/точки не показываем */
.products-grid.view-list .car-btn, .products-grid.view-list .car-dots { display: none; }

/* Profile */
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--gray-800); }
.profile-info { display: flex; flex-direction: column; gap: 12px; }
.profile-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--gray-100); font-size: .9rem; }
.profile-label { color: var(--gray-600); }
.discount-badge { background: #fef3c7; color: #92400e; padding: 2px 8px; border-radius: 12px; font-weight: 600; font-size: .8rem; }
.bonus-badge { background: #dcfce7; color: #166534; padding: 2px 10px; border-radius: 12px; font-weight: 600; font-size: .85rem; }
.price-original { text-decoration: line-through; color: var(--gray-400); font-size: .9rem; font-weight: 400; margin-right: 4px; }
.price-discounted { color: var(--primary); font-weight: 700; }
.order-items-table th, .order-items-table td { padding: 4px 6px; }
.nav-profile-btn { background: var(--gray-100); border: none; cursor: pointer; padding: 9px 16px;
  border-radius: 22px; color: var(--gray-800); font-size: .9rem; font-weight: 600; display: inline-flex;
  align-items: center; gap: 6px; white-space: nowrap; transition: background .15s, color .15s; }
.nav-profile-btn::before { content: "👤"; font-size: .95rem; }
.nav-profile-btn:hover { background: var(--primary); color: #fff; }
/* Компактный навбар на узких ноутбуках/планшетах (навбар виден ≥769px) */
@media (min-width: 769px) and (max-width: 1000px) {
  .nav-links { gap: 6px; }
  .nav-links button, #btn-nav-admin, .nav-profile-btn { padding: 8px 12px; font-size: .85rem; }
  .nav-cart-btn, #btn-nav-login { padding: 8px 14px !important; }
}

/* Admin */
.admin-tabs { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 2px solid var(--gray-200); }
.admin-tab { background: none; border: none; cursor: pointer; padding: 10px 20px; font-size: .9rem;
  color: var(--gray-600); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.admin-tab:hover { color: var(--gray-800); }
.admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.admin-tab-content { display: none; }
.admin-tab-content.active { display: block; }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.admin-product-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px;
  display: flex; flex-direction: column; gap: 8px; }
.admin-card-img { width: 100%; height: 140px; object-fit: cover; border-radius: 4px; background: var(--gray-100);
  display: flex; align-items: center; justify-content: center; overflow: hidden; }
.admin-card-img img { width: 100%; height: 100%; object-fit: cover; }
.admin-card-img .no-img { font-size: 2rem; color: var(--gray-400); }
.admin-card-name { font-size: .82rem; font-weight: 500; line-height: 1.3; }
.admin-card-code { font-size: .75rem; color: var(--gray-400); }
.admin-card-actions { display: flex; gap: 6px; margin-top: auto; }
.admin-card-actions button { flex: 1; padding: 5px 8px; font-size: .78rem; border-radius: 4px;
  border: 1px solid var(--gray-200); background: #fff; cursor: pointer; }
.admin-card-actions button:hover { background: var(--gray-50); }
.admin-card-actions .btn-pick { border-color: var(--primary); color: var(--primary); }
.admin-card-actions .btn-del { border-color: var(--danger); color: var(--danger); }

/* Image import */
.import-file-label { display:block; border:2px dashed var(--gray-300); border-radius: var(--radius);
  padding: 32px 16px; text-align:center; cursor:pointer; transition: border-color .15s, background .15s; }
.import-file-label:hover { border-color: var(--primary); background: var(--gray-50); }
.import-drop-inner { display:flex; flex-direction:column; align-items:center; gap:8px;
  font-size: .9rem; color: var(--gray-500); pointer-events:none; }
.import-drop-icon { font-size: 2rem; }
.import-code { background: var(--gray-100); border-radius:6px; padding:10px 14px;
  font-size: .82rem; line-height:1.6; overflow-x:auto; }

/* Product popover */
.product-popover {
  position: fixed;
  z-index: 1200;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.10);
  padding: 16px;
  width: 300px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
.product-popover.visible { opacity: 1; pointer-events: auto; }
.product-popover-img-wrap { width: 100%; height: 150px; overflow: hidden; border-radius: 6px;
  background: var(--gray-100); margin-bottom: 10px; display: flex; align-items: center; justify-content: center; }
.product-popover-img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.product-popover-img-wrap:empty { display: none; }
.product-popover-brand { font-size: .72rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.product-popover-brand:empty { display: none; }
.product-popover-name { font-weight: 700; font-size: .97rem; line-height: 1.35; margin-bottom: 4px; }
.product-popover-code { font-size: .78rem; color: var(--gray-400); margin-bottom: 6px; }
.product-popover-code:empty { display: none; }
.product-popover-desc { font-size: .84rem; color: var(--gray-700); line-height: 1.5; margin-bottom: 8px; max-height: 180px; overflow-y: auto; }
.product-popover-desc:empty { display: none; }
.product-popover-price { font-size: 1.1rem; font-weight: 700; color: var(--primary); }

.admin-cat-row { display: flex; align-items: center; padding: 5px 8px; border-radius: 6px; }
.admin-cat-row:hover { background: var(--gray-50); }
.admin-cat-label { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: .9rem; color: var(--gray-700); user-select: none; }
.admin-cat-label input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.admin-cat-name { line-height: 1.3; }

.img-upload-btn { display:inline-flex; align-items:center; gap:6px; padding:7px 14px;
  border:1px solid var(--gray-300); border-radius:6px; font-size:.85rem; font-weight:500;
  cursor:pointer; white-space:nowrap; background:#fff; transition:background .15s,border-color .15s; }
.img-upload-btn:hover { background:var(--gray-50); border-color:var(--primary); }

.img-candidates-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.img-candidate { position: relative; cursor: pointer; border-radius: 6px; overflow: hidden;
  border: 2px solid transparent; aspect-ratio: 1; background: var(--gray-100);
  display: flex; align-items: center; justify-content: center; }
.img-candidate:hover { border-color: var(--primary); }
.img-candidate img { width: 100%; height: 100%; object-fit: contain; display: block; }
.img-candidate--err { font-size: 1.5rem; color: var(--gray-400); }
.img-candidate-err { font-size: .75rem; color: var(--gray-400); text-align: center; }

/* Magnifier — fixed layer, positioned via JS */
.img-zoom-btn { position: fixed; width: 26px; height: 26px;
  background: rgba(0,0,0,.55); border-radius: 50%; display: none; align-items: center;
  justify-content: center; font-size: 13px; color: #fff; cursor: zoom-in;
  z-index: 1400; pointer-events: auto; transform: translate(-50%,-50%); }
.img-zoom-btn.visible { display: flex; }

/* Zoomed preview on magnifier area hover */
.img-zoom-preview { position: fixed; z-index: 1500; pointer-events: none; opacity: 0;
  transition: opacity .15s; border-radius: 8px; box-shadow: 0 8px 32px rgba(0,0,0,.35);
  background: #fff; overflow: hidden; }
.img-zoom-preview.visible { opacity: 1; }
.img-zoom-preview img { display: block; max-width: 400px; max-height: 400px;
  width: auto; height: auto; object-fit: contain; }

/* ── Mobile header + drawer (базовые; шапка видна только на мобильном) ── */
#mobile-header { display: none; }
.mh-search { display: none; }
.mh-badge { border-radius: 10px; padding: 1px 8px; font-size: .72rem; font-weight: 700; }
.mh-badge-disc { background: #fef3c7; color: #92400e; }
.mh-badge-bonus { background: #dcfce7; color: #166534; }
.cart-count-badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 0 6px;
  font-size: .72rem; font-weight: 700; line-height: 1.5; margin-left: -6px; box-shadow: 0 0 0 2px #fff; }

.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1099;
  opacity: 0; pointer-events: none; transition: opacity .25s; }
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; left: 0; bottom: 0; width: 82%; max-width: 320px; background: #fff;
  z-index: 1100; transform: translateX(-100%); transition: transform .25s; overflow-y: auto;
  box-shadow: 2px 0 16px rgba(0,0,0,.15); display: flex; flex-direction: column; }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px;
  border-bottom: 1px solid var(--gray-200); }
.drawer-title { font-weight: 700; color: var(--primary); }
.drawer-x { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--gray-400); }
.drawer-link { display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 13px 16px; font-size: .95rem; color: var(--gray-800); cursor: pointer; text-decoration: none;
  border-bottom: 1px solid var(--gray-100); }
.drawer-link:hover { background: var(--gray-50); }
.drawer-sep { height: 8px; background: var(--gray-50); border-top: 1px solid var(--gray-100);
  border-bottom: 1px solid var(--gray-100); }
.drawer-cats { max-height: 46vh; overflow-y: auto; background: var(--gray-50); }
.drawer-cat { display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 9px 16px; font-size: .85rem; color: var(--gray-700); cursor: pointer; }
.drawer-cat:hover { background: var(--gray-100); color: var(--primary); }

/* Catalog with sidebar */
.catalog-layout { display: flex; gap: 0; min-height: calc(100vh - 57px); }
.cat-sidebar { width: 240px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--gray-200);
  overflow-y: auto; padding: 0; position: sticky; top: 56px; max-height: calc(100vh - 56px); }
.cat-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px;
  border-bottom: 1px solid var(--gray-100); font-size: .9rem; }
.cat-reset-btn { background: none; border: none; cursor: pointer; color: var(--primary); font-size: .8rem;
  padding: 0; text-decoration: underline; }
.catalog-main { flex: 1; min-width: 0; padding: 20px 20px 40px; }

/* Category tree */
.cat-item { display: block; width: 100%; text-align: left; background: none; border: none;
  cursor: pointer; padding: 7px 14px; font-size: .88rem; color: var(--gray-800);
  border-left: 3px solid transparent; transition: background .1s; }
.cat-item:hover { background: var(--gray-50); }
.cat-item.active { background: #eff6ff; border-left-color: var(--primary); color: var(--primary); font-weight: 600; }
.cat-children { padding-left: 10px; }
.cat-toggle { margin-right: 4px; font-size: .75rem; display: inline-block; width: 12px; }

/* Pagination */
.page-btn { padding: 6px 12px; border: 1px solid var(--gray-200); border-radius: var(--radius);
  background: #fff; cursor: pointer; font-size: .85rem; }
.page-btn:hover { background: var(--gray-50); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Misc */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-header { margin: 24px 0 20px; display: flex; align-items: center; gap: 12px; }
.page-header h1 { font-size: 1.3rem; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .admin-grid    { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .img-candidates-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  /* Navbar — компактный, всё в один ряд без переполнения */
  .nav-inner { gap: 6px; }
  .nav-logo { flex-shrink: 0; font-size: .95rem; }
  .nav-links { gap: 2px; min-width: 0; flex-shrink: 1; }
  .nav-links button { padding: 6px 7px; font-size: .8rem; }
  /* Длинное имя контрагента распирает навбар — скрываем, показываем иконку */
  #nav-user-name { display: none; }
  .nav-profile-btn { padding: 6px 8px; }
  .nav-profile-btn::before { content: "👤"; font-size: 1rem; }
  .nav-cart-btn { padding: 6px 10px !important; }

  /* Sidebar hidden by default on mobile, shown by toggle */
  .catalog-layout { flex-direction: column; }
  .cat-sidebar {
    width: 100%; border-right: none; border-bottom: 1px solid var(--gray-200);
    position: static; max-height: 0; overflow: hidden;
    transition: max-height .3s ease;
  }
  .cat-sidebar.open { max-height: 400px; overflow-y: auto; }
  .sidebar-toggle { display: flex !important; }
  .catalog-main { padding: 12px; }

  /* Cart full width */
  .cart-panel { width: 100%; top: 56px; }

  /* Admin tabs scroll */
  .admin-tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .admin-tab   { white-space: nowrap; flex-shrink: 0; }

  /* Modal full screen */
  .modal { margin: 0; border-radius: 0; max-width: 100%; max-height: 100vh;
    width: 100%; min-height: 100vh; padding: 20px 16px; }
  .modal-overlay { align-items: flex-end; }

  /* Image grid 3 cols in modal */
  .img-candidates-grid { grid-template-columns: repeat(3, 1fr); }

  /* Profile */
  .profile-grid { grid-template-columns: 1fr; }

  /* Page header */
  .page-header { margin: 16px 0 12px; }
  .page-header h1 { font-size: 1.1rem; }

  /* Card padding */
  .card { padding: 16px; }

  /* Popover disabled on touch */
  .product-popover { display: none !important; }

  /* ── «Мои заказы» — карточки вместо тесной таблицы ── */
  .order-card { padding: 14px; }
  .order-meta { gap: 6px 10px; margin-bottom: 12px; }
  .order-meta .order-num { font-size: .95rem; }
  .order-meta > span:last-child { flex-basis: 100%; }  /* дата на своей строке */

  .order-items-table { display: block; }
  .order-items-table .oit-head { display: none; }
  .order-items-table tbody, .order-items-table tr, .order-items-table td { display: block; }
  .order-items-table tr.oit-row {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    padding: 10px 12px; margin-bottom: 8px;
  }
  .order-items-table tr.oit-row td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding: 3px 0; border: none; text-align: right; font-size: .85rem;
  }
  .order-items-table tr.oit-row td::before {
    content: attr(data-label); color: var(--gray-500); font-weight: 500;
    text-align: left; flex-shrink: 0;
  }
  .order-items-table tr.oit-row td.oit-name {
    display: block; text-align: left; font-weight: 600; font-size: .9rem; line-height: 1.35;
    margin-bottom: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--gray-200);
  }
  .order-items-table tr.oit-row td.oit-name::before { display: none; }
  .order-items-table tr.oit-row td.oit-amount { font-weight: 700; color: var(--gray-800); }
  .order-items-table tr.oit-total {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 4px; padding-top: 10px; border-top: 2px solid var(--gray-200); font-size: .95rem;
  }
  .order-items-table tr.oit-total td { display: inline; padding: 0; border: none; }
}

@media (max-width: 480px) {
  /* Single column catalog */
  .products-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }

  /* Nav compact on very small screens — прячем логотип, чтобы кнопки влезли */
  .nav-logo { display: none; }
  .nav-inner { justify-content: flex-end; }
  .nav-links { gap: 0; width: 100%; justify-content: space-between; }
  .nav-links button { padding: 6px 6px; font-size: .78rem; }

  /* Auth box */
  .auth-wrap { align-items: flex-start; padding-top: 24px; }
  .auth-box { max-width: 100%; box-shadow: none; border-radius: 0; }

  /* Toolbar stacks */
  .toolbar { gap: 8px; }
  .search-input { min-width: 0; }

  /* Admin grid 2 cols */
  .admin-grid { grid-template-columns: 1fr 1fr; }

  /* Image modal 2 cols */
  .img-candidates-grid { grid-template-columns: repeat(2, 1fr); }

  /* Product card: compact image */
  .product-img-wrap { height: 130px; }

  /* Qty row wraps */
  .qty-row { flex-wrap: wrap; }
  .btn-add { flex: 1; min-width: 120px; }

  /* Orders */
  .order-meta { gap: 6px; }
}

/* Узкие экраны: ужимаем правую колонку списка и фото */
@media (max-width: 480px) {
  .products-grid.view-list .product-card { padding-right: 160px; min-height: 106px; }
  .products-grid.view-list .qty-row input { width: 46px; }
  .products-grid.view-list .product-img-wrap { width: 62px; height: 62px; }
}

/* ── Мобильная шапка (заменяет десктоп-навбар на узких экранах) ── */
@media (max-width: 768px) {
  #main-nav { display: none !important; }
  #mobile-header { display: block; background: #fff; }
  .mh-row { display: flex; align-items: center; padding: 8px 12px; gap: 10px; }
  .mh-top { padding-bottom: 4px; }
  .mh-logo { font-weight: 700; color: var(--primary); font-size: 1.05rem; flex: 1; cursor: pointer; }
  .mh-burger { background: none; border: none; font-size: 1.5rem; cursor: pointer;
    color: var(--gray-800); line-height: 1; padding: 0 4px; }

  .mh-auth { padding-top: 0; padding-bottom: 8px; justify-content: space-between;
    flex-wrap: wrap; gap: 6px 10px; border-bottom: 1px solid var(--gray-100); min-height: 0; }
  .mh-auth:empty { display: none; }
  .mh-login { background: var(--primary); color: #fff; border: none; border-radius: var(--radius);
    padding: 8px 22px; font-weight: 600; font-size: .9rem; cursor: pointer; }
  .mh-user { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
  .mh-user-name { font-weight: 600; font-size: .9rem; color: var(--gray-800); cursor: pointer;
    text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; }
  .mh-user-actions { display: flex; gap: 10px; flex-shrink: 0; }
  .mh-linkbtn { background: none; border: none; color: var(--primary); font-size: .82rem;
    cursor: pointer; padding: 2px 2px; }
  .mh-logout { color: var(--danger); }

  /* Только строка поиска + корзина закреплена вверху при прокрутке (вынесена из шапки) */
  .mh-search {
    display: flex; align-items: center; gap: 10px; padding: 8px 12px;
    position: sticky; top: 0; z-index: 1000; background: #fff;
    border-bottom: 1px solid var(--gray-200); box-shadow: 0 2px 6px rgba(0,0,0,.06);
  }
  .mh-search .search-input { flex: 1; min-width: 0; font-size: 16px; }
  .mh-cart { background: var(--accent); border: none; border-radius: var(--radius);
    padding: 7px 12px; font-size: 1.15rem; cursor: pointer; position: relative; display: flex;
    align-items: center; flex-shrink: 0; box-shadow: 0 2px 6px rgba(234,88,12,.3); }

  /* На мобильном поиск — в шапке; в тулбаре каталога скрываем дублирующее поле */
  .catalog-main .toolbar #inp-search { display: none; }

  /* Корзина-панель поверх шапки на весь экран */
  .cart-panel { top: 0; z-index: 1200; }
}
