/* ==========================================================================
   Gluten-Free PWA - Единая дизайн-система (Zero CDN, Native CSS)
   ========================================================================== */

:root {
  /* Цветовая палитра безопасности AOECS */
  --color-primary: #059669;
  --color-primary-hover: #047857;
  --color-primary-light: #d1fae5;
  --color-primary-dark: #064e3b;
  
  --color-danger: #dc2626;
  --color-danger-light: #fee2e2;
  --color-warning: #d97706;
  --color-warning-light: #fef3c7;
  --color-info: #0284c7;
  --color-info-light: #e0f2fe;

  /* Нейтральные тона (Светлая тема) */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #f1f5f9;
  --bg-header: rgba(255, 255, 255, 0.92);
  --bg-nav: rgba(255, 255, 255, 0.96);
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-inverted: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #059669;

  /* Типографика: Системный стек 0 мс (Zero CDN) */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Радиусы и тени */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-modal: 0 20px 25px -5px rgba(0, 0, 0, 0.25), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

  /* Геометрия мобильного интерфейса */
  --header-height: 64px;
  --nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --transition-fast: 0.18s ease;
}

/* Темная тема */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-app: #090d16;
    --bg-card: #131b2e;
    --bg-card-hover: #1e293b;
    --bg-input: #1e293b;
    --bg-header: rgba(19, 27, 46, 0.92);
    --bg-nav: rgba(19, 27, 46, 0.96);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #243048;

    --color-primary-light: rgba(5, 150, 105, 0.2);
    --color-danger-light: rgba(220, 38, 38, 0.2);
    --color-warning-light: rgba(217, 119, 6, 0.2);
    --color-info-light: rgba(2, 132, 199, 0.2);
  }
}

/* Базовый сброс */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  min-height: 100%;
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
}

/* ==========================================================================
   Шапка приложения (App Header & Search)
   ========================================================================== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: calc(var(--safe-top) + 8px) 16px 12px 16px;
}

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

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  text-decoration: none;
}

.brand-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.badge-counter {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  background-color: var(--color-primary-light);
  color: var(--color-primary);
  border-radius: var(--radius-full);
}

/* Строка поиска */
.search-container {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 44px 0 40px;
  font-size: 0.95rem;
  font-family: inherit;
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

.search-icon-left {
  position: absolute;
  left: 12px;
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-btn-clear {
  position: absolute;
  right: 44px;
  background: none;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-full);
}

.search-btn-barcode {
  position: absolute;
  right: 6px;
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.search-btn-barcode:hover {
  background: var(--color-primary-hover);
}

/* Выпадающие подсказки */
.suggestions-popover {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 260px;
  overflow-y: auto;
  display: none;
  z-index: 150;
}

.suggestion-item {
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover, .suggestion-item.active {
  background-color: var(--bg-card-hover);
}

/* ==========================================================================
   Чипы категорий и фильтры
   ========================================================================== */

.filters-bar {
  padding: 10px 16px;
  overflow-x: auto;
  white-space: nowrap;
  display: flex;
  gap: 8px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.filters-bar::-webkit-scrollbar {
  display: none;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.chip-btn:hover {
  background-color: var(--bg-card-hover);
}

.chip-btn.active {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
}

/* ==========================================================================
   Сетка каталога продуктов
   ========================================================================== */

.catalog-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
}

.catalog-header-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.product-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

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

.card-brand {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-primary);
  letter-spacing: 0.04em;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.35;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.badge-safety {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.badge-aoecs {
  background-color: var(--color-primary-light);
  color: var(--color-primary);
}

.badge-tested {
  background-color: var(--color-info-light);
  color: var(--color-info);
}

.badge-warning {
  background-color: var(--color-danger-light);
  color: var(--color-danger);
}

.card-bottom {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.price-box {
  display: flex;
  flex-direction: column;
}

.price-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.price-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.retailers-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.retailer-pill {
  font-size: 0.7rem;
  padding: 2px 6px;
  background-color: var(--bg-input);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

/* Скелетон загрузки */
.skeleton-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  min-height: 160px;
  position: relative;
  overflow: hidden;
}

.skeleton-card::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background-image: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0,
    rgba(255, 255, 255, 0.2) 20%,
    rgba(255, 255, 255, 0.5) 60%,
    rgba(255, 255, 255, 0)
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}

/* ==========================================================================
   Нижняя панель навигации (Mobile Thumb Navigation)
   ========================================================================== */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background-color: var(--bg-nav);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 12px;
  transition: color var(--transition-fast);
}

.nav-item svg {
  width: 22px;
  height: 22px;
}

.nav-item.active {
  color: var(--color-primary);
  font-weight: 600;
}

/* ==========================================================================
   Модальные диалоговые окна (<dialog>)
   ========================================================================== */

dialog.app-modal {
  margin: auto;
  border: none;
  border-radius: var(--radius-lg);
  background-color: var(--bg-card);
  color: var(--text-main);
  box-shadow: var(--shadow-modal);
  max-width: 540px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 0;
}

dialog.app-modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 10;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
}

/* Сканер штрихкодов */
.scanner-viewport-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background-color: #000000;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 16px;
}

#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease-out;
}

/* Прицельная рамка по пропорциям штрихкода EAN-13 (узкая горизонтальная) */
.scanner-reticle-box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 76%;
  max-width: 270px;
  height: 105px;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  z-index: 2;
}

/* Угловые контрастные маркеры рамки */
.reticle-corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: #10b981;
  border-style: solid;
  border-width: 0;
  pointer-events: none;
}
.reticle-corner-tl {
  top: 0;
  left: 0;
  border-top-width: 3px;
  border-left-width: 3px;
  border-top-left-radius: 10px;
}
.reticle-corner-tr {
  top: 0;
  right: 0;
  border-top-width: 3px;
  border-right-width: 3px;
  border-top-right-radius: 10px;
}
.reticle-corner-bl {
  bottom: 0;
  left: 0;
  border-bottom-width: 3px;
  border-left-width: 3px;
  border-bottom-left-radius: 10px;
}
.reticle-corner-br {
  bottom: 0;
  right: 0;
  border-bottom-width: 3px;
  border-right-width: 3px;
  border-bottom-right-radius: 10px;
}

/* Лазерный луч, движущийся строго внутри рамки EAN-13 */
.scanner-laser-line {
  position: absolute;
  top: 50%;
  left: 15%;
  right: 15%;
  height: 2px;
  background: #10b981;
  box-shadow: 0 0 8px #10b981, 0 0 16px #10b981;
  animation: laserSweep 1.8s ease-in-out infinite alternate;
  z-index: 3;
  pointer-events: none;
}

/* Индикатор тапа для ручной фокусировки */
.scanner-focus-ring {
  position: absolute;
  width: 52px;
  height: 52px;
  border: 2px solid #38bdf8;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.4);
  opacity: 0;
  z-index: 4;
  transition: transform 0.25s ease-out, opacity 0.25s ease-out;
}
.scanner-focus-ring.active {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.scanner-hint-overlay {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.76rem;
  font-weight: 500;
  color: #f1f5f9;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  margin: 0 12px;
  pointer-events: none;
  z-index: 3;
}

/* Панель кнопок справа вверху (фонарик + смена камеры) */
.scanner-top-right-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
  z-index: 5;
}

.scanner-icon-btn {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-full);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

.scanner-icon-btn:hover {
  background: rgba(0, 0, 0, 0.85);
}

.scanner-icon-btn.active {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
}


@keyframes laserSweep {
  0% { transform: translateY(-38px); opacity: 0.4; }
  100% { transform: translateY(38px); opacity: 1; }
}

/* Офлайн баннер */
.offline-banner {
  display: none;
  background-color: var(--color-warning);
  color: #ffffff;
  padding: 6px 12px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
}
