/* ── Design tokens ───────────────────────────────────────────── */
:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --surface-2: #23232e;
  --surface-3: #2c2c3a;
  --border: rgba(255, 255, 255, 0.07);
  --accent: #4f7fff;
  --accent-dim: rgba(79, 127, 255, 0.15);
  --accent-hover: #6690ff;
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --warning-dim: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --text-primary: #f0f0f8;
  --text-secondary: #8e8ea8;
  --text-muted: #5a5a72;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-drawer: 0 -8px 40px rgba(0, 0, 0, 0.6);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --header-h: 60px;
  --search-h: 60px;
  --catnav-h: 46px;
  --movbar-h: 38px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input { font-family: inherit; }

/* ── Header ───────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(15, 15, 19, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.header-supplier {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-address {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-fab {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
  margin-left: 12px;
}
.cart-fab:active { transform: scale(0.9); }
.cart-fab:hover { background: rgba(79, 127, 255, 0.25); }

.cart-count {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 2px solid var(--bg);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity var(--transition), transform var(--transition);
}
.cart-count.visible {
  opacity: 1;
  transform: scale(1);
}

/* ── Search ───────────────────────────────────────────────────── */
.search-wrap {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  height: var(--search-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: rgba(15, 15, 19, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.search-box {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
}

#search-input {
  width: 100%;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 0 36px 0 38px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}
#search-input::placeholder { color: var(--text-muted); }
#search-input:focus {
  border-color: var(--accent);
  background: var(--surface-2);
}

.search-clear {
  position: absolute;
  right: 10px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 4px;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.search-clear.visible {
  opacity: 1;
  pointer-events: auto;
}
.search-clear:hover { color: var(--text-secondary); }

/* ── Category Nav ─────────────────────────────────────────────── */
.cat-nav {
  position: sticky;
  top: calc(var(--header-h) + var(--search-h));
  z-index: 80;
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: rgba(15, 15, 19, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.cat-nav::-webkit-scrollbar { display: none; }

.cat-tab {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all var(--transition);
  white-space: nowrap;
}
.cat-tab[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.cat-tab:active { transform: scale(0.95); }

/* ── MOV Progress Bar ─────────────────────────────────────────── */
.mov-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 16px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.mov-bar-track {
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}

.mov-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #7c9fff);
  border-radius: 2px;
  width: 0%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.4s;
}
.mov-bar-fill.complete {
  background: linear-gradient(90deg, var(--success), #4ade80);
}

.mov-label {
  font-size: 11.5px;
  color: var(--text-muted);
}
.mov-label strong { color: var(--text-secondary); font-weight: 600; }
.mov-bar.complete .mov-label { color: var(--success); }
.mov-bar.complete .mov-label strong { color: var(--success); }

/* ── Catalog Grid ─────────────────────────────────────────────── */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 14px 12px 120px;
}

/* ── Product Card ─────────────────────────────────────────────── */
.product-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition), transform var(--transition);
  position: relative;
}
.product-card.in-cart {
  border-color: rgba(79, 127, 255, 0.4);
}
.product-card:active { transform: scale(0.98); }

.product-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  user-select: none;
  line-height: 1;
}

.product-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.product-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.product-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.product-unit {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 5px;
}

.product-mult-badge {
  font-size: 10px;
  color: var(--warning);
  background: var(--warning-dim);
  padding: 2px 6px;
  border-radius: 5px;
  font-weight: 500;
}

/* ── Quantity controls ────────────────────────────────────────── */
.qty-controls {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: auto;
}

.qty-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 300;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.qty-btn:active { background: var(--surface-3); color: var(--text-primary); }

.qty-value {
  flex: 1;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 28px;
}

.btn-add-to-cart {
  width: 100%;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  transition: background var(--transition);
  margin-top: auto;
}
.btn-add-to-cart:active { background: rgba(79, 127, 255, 0.3); }

/* ── Multiplicity violation indicator ────────────────────────── */
.mult-violation {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--warning);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
}

/* ── Empty State ─────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 8px;
}
.empty-emoji { font-size: 48px; }
.empty-state p { font-size: 16px; font-weight: 600; color: var(--text-secondary); }
.empty-state small { font-size: 13px; color: var(--text-muted); }
.hidden { display: none !important; }

/* ── Cart Drawer ─────────────────────────────────────────────── */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.cart-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 210;
  max-height: 90dvh;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-drawer);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.cart-drawer.open { transform: translateY(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.drawer-close {
  width: 30px;
  height: 30px;
  background: var(--surface-3);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.drawer-close:active { background: var(--surface-2); }

.drawer-body {
  overflow-y: auto;
  flex: 1;
  padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.cart-empty-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 32px 0;
}

/* ── Cart Item ────────────────────────────────────────────────── */
.cart-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }

.cart-item-emoji {
  font-size: 28px;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

.cart-item-info {
  flex: 1;
  min-width: 0;
}

.cart-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-item-price {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.cart-item-violation {
  font-size: 11px;
  color: var(--warning);
  margin-top: 2px;
}

.cart-item-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.cart-qty-btn {
  width: 28px;
  height: 28px;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  font-size: 16px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.cart-qty-btn:active { background: var(--surface-2); }

.cart-qty-value {
  min-width: 28px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.cart-item-subtotal {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 52px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Drawer Footer ────────────────────────────────────────────── */
.drawer-footer {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  color: var(--text-secondary);
}
.cart-total-row strong {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.mov-warning {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--warning-dim);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--warning);
}

.btn-primary {
  width: 100%;
  height: 50px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
}
.btn-primary:active { transform: scale(0.98); background: var(--accent-hover); }
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-3);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13.5px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
  z-index: 300;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Animations ──────────────────────────────────────────────── */
@keyframes pop-in {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.product-card { animation: pop-in 0.2s ease both; }

/* ── Safe area awareness ─────────────────────────────────────── */
.catalog-grid { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
