/* ============================================================
   ShiningAsia refresh theme (Stable stand)
   Изолированная тема: все правила действуют только внутри
   html[data-sa-theme="refresh"]. Legacy-страницы не меняются.
   Токены с префиксом --sa- отделены от старых переменных.
   ============================================================ */

html[data-sa-theme="refresh"] {
  --sa-bg: #fffaf7;
  --sa-surface: #ffffff;
  --sa-ink: #292521;
  --sa-muted: #625952;
  --sa-line: #f0e2d6;
  --sa-accent: #994318;
  --sa-primary: linear-gradient(110deg, #ffd5a3, #ffc4ad);
  --sa-primary-hover: linear-gradient(110deg, #ffca8e, #ffb89e);
  --sa-secondary: linear-gradient(115deg, #fff0db, #ffe4d6);
  --sa-on-primary: #50301e;
  --sa-primary-border: #dba178;
  --sa-focus: rgba(153, 67, 24, 0.35);
  --sa-radius-sm: 12px;
  --sa-radius-md: 16px;
  --sa-radius-lg: 22px;
  --sa-shadow: 0 4px 22px rgba(80, 48, 30, 0.08);

  /* Перекрываем legacy-переменные только внутри refresh */
  --paper: var(--sa-bg);
  --surface: var(--sa-surface);
  --ink: var(--sa-ink);
  --muted: var(--sa-muted);
  --line: var(--sa-line);
  --accent: #f0a468;
  --accent-dark: var(--sa-accent);
  --highlight: #ffd5a3;
  --soft: #fff3e9;
  --shadow: var(--sa-shadow);

  color-scheme: light;
  background: var(--sa-bg);
}

html[data-sa-theme="refresh"] body {
  background: var(--sa-bg);
  background-image: none;
  color: var(--sa-ink);
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

html[data-sa-theme="refresh"] a {
  color: var(--sa-accent);
}

html[data-sa-theme="refresh"] a:hover {
  color: #7d3513;
}

html[data-sa-theme="refresh"] h1,
html[data-sa-theme="refresh"] h2,
html[data-sa-theme="refresh"] h3 {
  font-weight: 700;
  letter-spacing: -0.01em;
}

html[data-sa-theme="refresh"] .product-card h3,
html[data-sa-theme="refresh"] section .product-card h3 {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
}

html[data-sa-theme="refresh"] a:focus-visible,
html[data-sa-theme="refresh"] button:focus-visible,
html[data-sa-theme="refresh"] input:focus-visible,
html[data-sa-theme="refresh"] select:focus-visible,
html[data-sa-theme="refresh"] textarea:focus-visible {
  outline: 3px solid var(--sa-focus);
  outline-offset: 3px;
}

/* ---------------- Шапка ---------------- */

html[data-sa-theme="refresh"] .site-header {
  background: rgba(255, 250, 247, 0.94);
  border-bottom: 1px solid var(--sa-line);
  backdrop-filter: blur(14px);
}

html[data-sa-theme="refresh"] .site-header.is-scrolled {
  border-bottom-color: var(--sa-line);
  box-shadow: 0 8px 24px rgba(80, 48, 30, 0.08);
}

html[data-sa-theme="refresh"] .site-brand img {
  border-radius: 14px;
}

html[data-sa-theme="refresh"] .catalog-button {
  border: 1px solid var(--sa-primary-border);
  border-radius: 15px;
  background: var(--sa-primary);
  color: var(--sa-on-primary);
  font-weight: 700;
  box-shadow: 0 2px 10px rgba(219, 161, 120, 0.18);
}

html[data-sa-theme="refresh"] .catalog-button:hover {
  background: var(--sa-primary-hover);
  color: var(--sa-on-primary);
  box-shadow: 0 7px 18px rgba(219, 161, 120, 0.28);
}

html[data-sa-theme="refresh"] .catalog-button:active {
  box-shadow: 0 2px 7px rgba(219, 161, 120, 0.22);
}

html[data-sa-theme="refresh"] .site-search {
  border: 2px solid #f2ddcc;
  border-radius: 15px;
  background: var(--sa-surface);
  box-shadow: none;
}

html[data-sa-theme="refresh"] .site-search:focus-within {
  border-color: var(--sa-primary-border);
  box-shadow: 0 0 0 4px rgba(255, 196, 173, 0.28);
}

html[data-sa-theme="refresh"] .site-search input {
  color: var(--sa-ink);
  font-size: 16px;
}

html[data-sa-theme="refresh"] .site-search input::placeholder {
  color: #8a7a6d;
}

html[data-sa-theme="refresh"] .site-search button {
  border: 1px solid var(--sa-primary-border);
  border-radius: 12px;
  background: var(--sa-primary);
  color: var(--sa-on-primary);
  font-weight: 700;
}

html[data-sa-theme="refresh"] .site-search button:hover {
  background: var(--sa-primary-hover);
  color: var(--sa-on-primary);
}

html[data-sa-theme="refresh"] .search-results {
  border-color: var(--sa-line);
  border-radius: 14px;
  box-shadow: var(--sa-shadow);
}

html[data-sa-theme="refresh"] .search-results a {
  color: var(--sa-ink);
}

html[data-sa-theme="refresh"] .search-results a:hover {
  background: #fff6ee;
}

html[data-sa-theme="refresh"] .auth-button,
html[data-sa-theme="refresh"] .menu-burger,
html[data-sa-theme="refresh"] .site-header .menu-burger {
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--sa-secondary);
  color: var(--sa-on-primary);
}

html[data-sa-theme="refresh"] .auth-button:hover,
html[data-sa-theme="refresh"] .menu-burger:hover,
html[data-sa-theme="refresh"] .site-header .menu-burger:hover {
  background: #ffe9d8;
  color: var(--sa-accent);
}

html[data-sa-theme="refresh"] .auth-button.is-authed {
  background: #ffe4d6;
  color: var(--sa-accent);
}

html[data-sa-theme="refresh"] .cart-link {
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--sa-secondary);
  color: var(--sa-on-primary);
}

html[data-sa-theme="refresh"] .cart-link:hover {
  background: #ffe9d8;
  color: var(--sa-accent);
}

html[data-sa-theme="refresh"] .cart-link.has-items,
html[data-sa-theme="refresh"] .cart-link.has-items:hover {
  border-color: var(--sa-primary-border);
  background: var(--sa-primary);
  color: var(--sa-on-primary);
  box-shadow: 0 6px 16px rgba(219, 161, 120, 0.24);
}

html[data-sa-theme="refresh"] .cart-count {
  background: var(--sa-accent);
  color: #fff;
}

html[data-sa-theme="refresh"] .cart-link.has-items .cart-count {
  background: #fff;
  color: var(--sa-accent);
}

html[data-sa-theme="refresh"] .header-contacts a,
html[data-sa-theme="refresh"] .header-links a {
  color: var(--sa-muted);
  font-size: 14px;
}

html[data-sa-theme="refresh"] .header-contacts a:hover,
html[data-sa-theme="refresh"] .header-links a:hover {
  color: var(--sa-accent);
}

html[data-sa-theme="refresh"] .header-contacts .contact-icon {
  background: var(--sa-secondary);
  color: var(--sa-on-primary);
}

/* ---------------- Нижняя навигация (телефон) ---------------- */

.sa-bottom-nav {
  display: none;
}

html[data-sa-theme="refresh"] .sa-bottom-nav {
  position: fixed;
  z-index: 80;
  right: 0;
  bottom: 0;
  left: 0;
  display: none;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--sa-line);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 -6px 20px rgba(80, 48, 30, 0.06);
  backdrop-filter: blur(14px);
}

@media (max-width: 700px) {
  html[data-sa-theme="refresh"] .sa-bottom-nav {
    display: grid;
  }
}

html[data-sa-theme="refresh"] .sa-bottom-nav__item {
  display: flex;
  min-height: 60px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  padding: 6px 2px;
  border: 0;
  background: transparent;
  color: var(--sa-muted);
  font: inherit;
  font-size: 12px;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

html[data-sa-theme="refresh"] .sa-bottom-nav__item svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

html[data-sa-theme="refresh"] .sa-bottom-nav__item.is-active {
  color: var(--sa-accent);
}

html[data-sa-theme="refresh"] .sa-bottom-nav__icon {
  position: relative;
  display: inline-flex;
}

html[data-sa-theme="refresh"] .sa-bottom-nav__count {
  position: absolute;
  top: -6px;
  right: -10px;
  display: none;
  min-width: 17px;
  height: 17px;
  place-items: center;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--sa-accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

html[data-sa-theme="refresh"] .sa-bottom-nav__count.is-visible {
  display: inline-grid;
}

@media (max-width: 700px) {
  html[data-sa-theme="refresh"] body {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  /* Компактная шапка: контакты остаются в футере, меню-бургер работает */
  html[data-sa-theme="refresh"] .header-contacts {
    display: none;
  }

  html[data-sa-theme="refresh"] .header-subline {
    padding-bottom: 8px;
  }

  html[data-sa-theme="refresh"] .scroll-to-top {
    bottom: calc(78px + env(safe-area-inset-bottom));
  }

  /* Кнопка установки PWA не должна перекрывать нижнее меню */
  html[data-sa-theme="refresh"] #sa-install {
    bottom: calc(80px + env(safe-area-inset-bottom)) !important;
  }
}

/* ---------------- Переключатель темы (только Stable/localhost) ---------------- */

.sa-theme-switch {
  position: fixed;
  z-index: 120;
  bottom: 14px;
  left: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--sa-line, #f0e2d6);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: #625952;
  font: 600 12px/1 "Avenir Next", "Segoe UI", sans-serif;
  box-shadow: 0 4px 14px rgba(80, 48, 30, 0.12);
  backdrop-filter: blur(10px);
  cursor: pointer;
}

.sa-theme-switch:hover {
  color: #994318;
  border-color: #dba178;
}

@media (max-width: 700px) {
  .sa-theme-switch {
    bottom: calc(74px + env(safe-area-inset-bottom));
    left: 10px;
  }
}

/* Очень узкие экраны: компактная шапка без обрезания действий */
@media (max-width: 360px) {
  html[data-sa-theme="refresh"] .site-brand,
  html[data-sa-theme="refresh"] .site-brand img {
    width: 46px;
    height: 46px;
  }

  html[data-sa-theme="refresh"] .catalog-button {
    width: 44px;
    min-height: 44px;
    justify-content: center;
    gap: 0;
    padding: 0;
  }

  html[data-sa-theme="refresh"] .catalog-button .catalog-label {
    display: none;
  }
}
