/* ============================================================================
 *  base.css — сброс стилей и базовая типографика
 * ----------------------------------------------------------------------------
 *  Подключается после variables.css. Современный reset + базовые элементы,
 *  утилитарные классы текста, ключевые кадры анимаций, доступность.
 * ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  text-rendering: optimizeLegibility;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; background: none; border: none; }

a { color: inherit; text-decoration: none; transition: var(--transition-fast); }
a:hover { color: var(--color-primary); }

ul, ol { list-style: none; }

p { overflow-wrap: break-word; }

/* --- Заголовки ------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 { color: var(--color-dark); }
h1 { font-size: var(--fs-h1); font-weight: var(--fw-bold);     line-height: 1.2; letter-spacing: -0.02em; }
h2 { font-size: var(--fs-h2); font-weight: var(--fw-semibold); line-height: 1.3; letter-spacing: -0.01em; }
h3 { font-size: var(--fs-h3); font-weight: var(--fw-semibold); line-height: 1.4; }
h4 { font-size: var(--fs-h4); font-weight: var(--fw-semibold); line-height: 1.5; }

/* --- Утилиты размера текста ------------------------------------------------ */
.text-xl   { font-size: var(--fs-xl); }
.text-base { font-size: var(--fs-base); }
.text-sm   { font-size: var(--fs-sm); }
.text-xs   { font-size: var(--fs-xs); }

.text-muted   { color: var(--color-text-muted); }
.text-light   { color: var(--color-text-light); }
.text-primary { color: var(--color-primary); }
.text-success { color: var(--color-success-text); }
.text-danger  { color: var(--color-danger-text); }

.fw-medium   { font-weight: var(--fw-medium); }
.fw-semibold { font-weight: var(--fw-semibold); }
.fw-bold     { font-weight: var(--fw-bold); }

.text-center { text-align: center; }
.text-right  { text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- Контейнеры и сетка ---------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
}
.content-narrow { max-width: var(--content-max); margin-inline: auto; }

.flex   { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.grid  { display: grid; }
.hidden { display: none !important; }

/* --- Полоса прокрутки ------------------------------------------------------ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
  border: 2px solid var(--color-bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-text-light); }

/* --- Выделение текста ------------------------------------------------------ */
::selection { background: var(--color-primary-bg); color: var(--color-primary-dark); }

/* --- Видимый фокус (доступность) ------------------------------------------ */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* --- Доступность: скрытие визуально, но не для скринридеров ---------------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ===========================================================================
 *  Ключевые кадры анимаций
 * ========================================================================== */

/* Плавное появление снизу */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Просто появление */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Skeleton-загрузчик */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

/* Пульс кнопки «В корзину» */
@keyframes addedPulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Появление модального окна */
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Выезд bottom sheet снизу */
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* Выезд toast справа снизу */
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* Вращение спиннера */
@keyframes spin { to { transform: rotate(360deg); } }

/* Класс появления контента */
.fade-in-up { animation: fadeInUp 0.3s ease both; }
.fade-in    { animation: fadeIn 0.25s ease both; }

/* Stagger: задержки для каскадного появления карточек */
.stagger > * { animation: fadeInUp 0.3s ease both; }
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.06s; }
.stagger > *:nth-child(3) { animation-delay: 0.10s; }
.stagger > *:nth-child(4) { animation-delay: 0.14s; }
.stagger > *:nth-child(5) { animation-delay: 0.18s; }
.stagger > *:nth-child(6) { animation-delay: 0.22s; }
.stagger > *:nth-child(7) { animation-delay: 0.26s; }
.stagger > *:nth-child(8) { animation-delay: 0.30s; }

/* Ленивые картинки: плавное проявление после загрузки */
img[loading="lazy"] { opacity: 0; transition: opacity 0.4s ease; }
img[loading="lazy"].loaded,
img[loading="lazy"][data-loaded] { opacity: 1; }

/* --- Уважение к настройке «уменьшить движение» ---------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
