/* ============================================================
   Apple Store 178 — Mini App CSS
   Dark Apple-style theme — pure CSS, no frameworks
   ============================================================ */

/* ── TOKENS ──────────────────────────────────────────────── */
:root {
  /* Typography */
  --font-body: 'Cabinet Grotesk', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;

  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2rem);

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radius */
  --radius-sm: 0.5rem;
  --radius-md: 0.875rem;
  --radius-lg: 1.25rem;
  --radius-xl: 1.75rem;
  --radius-full: 9999px;

  /* Transitions */
  --t-fast: 140ms cubic-bezier(0.16, 1, 0.3, 1);
  --t-mid: 250ms cubic-bezier(0.16, 1, 0.3, 1);
  --t-slow: 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── DARK THEME (only, Apple-style) ─────────────────────── */
[data-theme="dark"] {
  --bg: #000000;
  --bg-2: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1e;
  --surface-3: #2c2c2e;
  --border: #2c2c2e;
  --border-light: #3a3a3c;

  --text: #f5f5f7;
  --text-muted: #8e8e93;
  --text-faint: #48484a;

  --accent: #0a84ff;          /* iOS blue */
  --accent-hover: #0071e3;
  --accent-glow: rgba(10, 132, 255, 0.18);

  --green: #30d158;            /* Available */
  --red: #ff453a;              /* Out of stock */
  --gold: #ffd60a;

  --shadow-card: 0 2px 12px rgba(0,0,0,0.5);
  --shadow-modal: 0 -8px 40px rgba(0,0,0,0.7);

  /* Header glass */
  --header-bg: rgba(0, 0, 0, 0.82);
  --header-blur: blur(20px) saturate(180%);
}

/* ── RESET ───────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  /* Safe area for iPhone notch */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  overflow-x: hidden;
  /* Remove tap highlight on mobile */
  -webkit-tap-highlight-color: transparent;
}
img { display: block; max-width: 100%; height: auto; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input { font: inherit; color: inherit; }

/* ── HEADER ──────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: var(--header-blur);
  -webkit-backdrop-filter: var(--header-blur);
  border-bottom: 1px solid var(--border);
  transition: border-color var(--t-mid);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  height: 52px;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.logo-icon {
  width: 24px;
  height: 24px;
  color: var(--text);
  flex-shrink: 0;
}
.logo-text {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* Icon button */
.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--accent);
  transition: background var(--t-fast), transform var(--t-fast);
}
.icon-btn:active { transform: scale(0.9); background: var(--surface-3); }

/* Search bar */
.search-bar {
  padding: var(--space-2) var(--space-4);
  padding-bottom: var(--space-3);
  display: none;
}
.search-bar.visible { display: block; }
.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: var(--space-3);
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
}
#search-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-8) var(--space-2) 2.25rem;
  font-size: var(--text-sm);
  color: var(--text);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
#search-input::placeholder { color: var(--text-muted); }
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
#search-input::-webkit-search-cancel-button { display: none; }
.clear-search {
  position: absolute;
  right: var(--space-3);
  color: var(--text-muted);
  display: none;
  padding: var(--space-1);
  border-radius: var(--radius-full);
  transition: color var(--t-fast);
}
.clear-search.visible { display: flex; }
.clear-search:hover { color: var(--text); }

/* ── CATEGORIES ──────────────────────────────────────────── */
.categories-nav {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px; /* header height */
  z-index: 90;
}
.categories-scroll {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.categories-scroll::-webkit-scrollbar { display: none; }

.cat-btn {
  flex-shrink: 0;
  padding: var(--space-1) var(--space-4);
  height: 32px;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: all var(--t-fast);
  white-space: nowrap;
}
.cat-btn:active { transform: scale(0.95); }
.cat-btn.active {
  color: var(--bg);
  background: var(--text);
  border-color: var(--text);
  font-weight: 700;
}

/* ── SORT BAR ────────────────────────────────────────────── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
}
.sort-bar::-webkit-scrollbar { display: none; }
.sort-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.sort-buttons {
  display: flex;
  gap: var(--space-2);
}
.sort-btn {
  flex-shrink: 0;
  padding: 4px var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  transition: all var(--t-fast);
  white-space: nowrap;
}
.sort-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
}

/* ── PRODUCTS GRID ───────────────────────────────────────── */
.main {
  padding: var(--space-4);
  padding-bottom: calc(var(--space-12) + env(safe-area-inset-bottom));
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

/* Product Card */
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
  /* Entrance animation */
  animation: cardIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.product-card:active {
  transform: scale(0.96);
  box-shadow: none;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

/* Stagger cards */
.product-card:nth-child(1) { animation-delay: 0ms; }
.product-card:nth-child(2) { animation-delay: 40ms; }
.product-card:nth-child(3) { animation-delay: 80ms; }
.product-card:nth-child(4) { animation-delay: 120ms; }
.product-card:nth-child(5) { animation-delay: 160ms; }
.product-card:nth-child(6) { animation-delay: 200ms; }
.product-card:nth-child(n+7) { animation-delay: 220ms; }

/* Card image */
.card-img-wrap {
  position: relative;
  width: 100%;
  height: 160px;
  background: var(--surface-2);
  overflow: hidden;
  flex-shrink: 0;
}
.card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--t-mid);
}
.product-card:active .card-img-wrap img {
  transform: scale(1.03);
}

/* Placeholder when no image */
.card-img-placeholder {
  width: 100%;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}
.card-img-placeholder svg {
  opacity: 0.2;
}

/* Stock badge on image */
.stock-badge {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.stock-badge.in-stock {
  background: rgba(48, 209, 88, 0.15);
  color: var(--green);
  border: 1px solid rgba(48, 209, 88, 0.3);
}
.stock-badge.out-of-stock {
  background: rgba(255, 69, 58, 0.12);
  color: var(--red);
  border: 1px solid rgba(255, 69, 58, 0.25);
}

/* Card body */
.card-body {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  flex: 1;
}
.card-category {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.card-name {
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  /* Ограничиваем 2 строки */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-price {
  font-size: var(--text-base);
  font-weight: 800;
  color: var(--text);
  margin-top: auto;
  padding-top: var(--space-2);
  letter-spacing: -0.02em;
}

/* ── SKELETON LOADERS ────────────────────────────────────── */
.skeleton-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  height: 260px;
  background: var(--surface);
  position: relative;
  overflow: hidden;
}
.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255,255,255,0.04) 50%,
    transparent 100%
  );
  animation: shimmer 1.4s ease-in-out infinite;
  background-size: 200% 100%;
}
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ── EMPTY / ERROR STATES ────────────────────────────────── */
.empty-state,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-12) var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}
.btn-secondary {
  padding: var(--space-2) var(--space-6);
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background var(--t-fast);
}
.btn-secondary:active { background: var(--surface-3); }

/* ── MODAL (bottom sheet) ────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0);
  display: flex;
  align-items: flex-end;
  pointer-events: none;
  transition: background var(--t-mid);
}
.modal-overlay.open {
  background: rgba(0,0,0,0.6);
  pointer-events: auto;
}

.modal-sheet {
  width: 100%;
  max-height: 92dvh;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
  transform: translateY(100%);
  transition: transform var(--t-slow);
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
}
.modal-overlay.open .modal-sheet {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--border-light);
  margin: var(--space-3) auto var(--space-2);
  flex-shrink: 0;
}

.modal-content {
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--space-5) var(--space-4);
}

/* Modal image */
.modal-img-wrap {
  width: 100%;
  aspect-ratio: 4/3;
  max-height: 280px;
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-5);
}
.modal-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Modal info */
.modal-category {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-1);
}
.modal-name {
  font-size: var(--text-lg);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: var(--space-3);
}
.modal-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.modal-price {
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
}
.modal-stock {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
}
.modal-stock.in-stock { color: var(--green); }
.modal-stock.out-of-stock { color: var(--red); }
.modal-stock-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* Description */
.modal-desc {
  font-size: var(--text-sm);
  line-height: 1.65;
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  max-width: none;
}

/* Order button */
.btn-order {
  width: 100%;
  padding: var(--space-4);
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #fff;
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: center;
  border: none;
  transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-order:active {
  transform: scale(0.97);
  background: var(--accent-hover);
  box-shadow: none;
}
.btn-order:disabled {
  background: var(--surface-3);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

/* ── HAPTIC PULSE (purely visual, TG haptic via JS) ─────── */
@keyframes pulse-accent {
  0%   { box-shadow: 0 4px 20px var(--accent-glow); }
  50%  { box-shadow: 0 4px 36px rgba(10,132,255,0.45); }
  100% { box-shadow: 0 4px 20px var(--accent-glow); }
}

/* ── SCROLLBAR (webkit) ──────────────────────────────────── */
::-webkit-scrollbar { width: 0; height: 0; }
