/* ОптЛист — общие компоненты. Цвета и размеры только через переменные из tokens.css */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 500 var(--fs-16)/var(--lh-body) var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); letter-spacing: -0.02em; font-weight: 800; }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: var(--fs-14); }
.xsmall { font-size: var(--fs-12); }
.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; }
.wrap { width: 100%; max-width: var(--content); margin: 0 auto; padding: 0 var(--s-4); }
.row { display: flex; align-items: center; gap: var(--s-2); }
.stack { display: flex; flex-direction: column; gap: var(--s-3); }
.grow { flex: 1 1 auto; min-width: 0; }
.ico { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico-sm { width: 16px; height: 16px; }
.ico-lg { width: 24px; height: 24px; }

:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.skip { position: absolute; left: var(--s-2); top: -100px; background: var(--surface); padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); z-index: 100; }
.skip:focus { top: var(--s-2); }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--tap); padding: 0 var(--s-4); border-radius: var(--r-md);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 700; font-size: var(--fs-16); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--action); border-color: var(--action); color: var(--on-action); }
.btn-primary:hover { background: var(--action-hover); border-color: var(--action-hover); }
.btn-primary:active { background: var(--action-active); }
.btn-danger { background: var(--surface); border-color: var(--destructive); color: var(--destructive); }
.btn-danger:hover { background: var(--destructive-soft); }
.btn-danger-solid { background: var(--destructive); border-color: var(--destructive); color: var(--on-destructive); }
.btn-danger-solid:hover { background: var(--destructive-hover); border-color: var(--destructive-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-lg { min-height: 52px; padding: 0 var(--s-6); font-size: var(--fs-18); border-radius: var(--r-lg); }
.btn-sm { min-height: 36px; padding: 0 var(--s-3); font-size: var(--fs-14); border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn-icon { width: var(--tap); padding: 0; }
.btn[aria-busy="true"] { position: relative; color: transparent; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--text-3); border-top-color: transparent; animation: spin 0.7s linear infinite;
}
.btn-primary[aria-busy="true"]::after { border-color: var(--on-action); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- поля ---------- */
.field { display: flex; flex-direction: column; gap: var(--s-1); }
.field > label, .label { font-size: var(--fs-14); font-weight: 700; color: var(--text-2); }
.hint { font-size: var(--fs-12); color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface);
  font-size: var(--fs-16); transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.textarea { min-height: 88px; resize: vertical; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus-ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-ring) 25%, transparent); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--destructive); }
.input:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
.field-error { font-size: var(--fs-14); color: var(--destructive); font-weight: 600; }
.input-group { position: relative; }
.input-group .ico { position: absolute; left: var(--s-3); top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-group .input { padding-left: 40px; }
.check { display: inline-flex; align-items: center; gap: var(--s-2); min-height: var(--tap); cursor: pointer; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--action); }

/* переключатель */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; min-height: var(--tap); font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 44px; height: 26px; border-radius: var(--r-full); background: var(--line-strong); position: relative; transition: background var(--t-med) var(--ease); flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-1); transition: transform var(--t-med) var(--ease); }
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.switch input:disabled + .track { opacity: 0.5; }

/* ---------- карточки, бейджи ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-5); }
.badge { display: inline-flex; align-items: center; gap: var(--s-1); padding: 2px var(--s-2); border-radius: var(--r-full); font-size: var(--fs-12); font-weight: 700; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge-new { background: var(--action-soft); color: var(--action-soft-text); }
.badge-accepted { background: var(--info-soft); color: var(--info); }
.badge-shipped { background: var(--warning-soft); color: var(--warning); }
.badge-done { background: var(--success-soft); color: var(--success); }
.badge-cancelled { background: var(--destructive-soft); color: var(--destructive); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* чипы-фильтры */
.chips { display: flex; gap: var(--s-2); overflow-x: auto; scrollbar-width: none; padding: var(--s-1) 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 var(--s-4); border-radius: var(--r-full);
  border: 1px solid var(--line-strong); background: var(--surface); font-weight: 700; font-size: var(--fs-14);
  cursor: pointer; white-space: nowrap; transition: background var(--t-fast) var(--ease);
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"], .chip[aria-selected="true"], .chip.is-on { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip .count { opacity: 0.7; margin-left: var(--s-1); font-weight: 600; }

/* степпер количества */
.stepper { display: inline-flex; align-items: center; border-radius: var(--r-md); background: var(--action); color: var(--on-action); height: var(--tap); }
.stepper button { width: var(--tap); height: var(--tap); border: 0; background: transparent; color: inherit; display: grid; place-items: center; cursor: pointer; border-radius: var(--r-md); }
.stepper button:hover { background: var(--action-hover); }
.stepper button:active { background: var(--action-active); }
.stepper input { width: 48px; height: 100%; border: 0; background: transparent; color: inherit; text-align: center; font-weight: 800; font-size: var(--fs-16); font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: 2px solid var(--on-action); outline-offset: -4px; border-radius: var(--r-sm); }

/* ---------- диалоги и шторки ---------- */
dialog { border: 0; padding: 0; background: transparent; color: var(--text); width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; margin: 0; }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: var(--scrim); }
.sheet {
  width: min(560px, 100vw); max-height: min(92dvh, 900px); margin: auto auto 0; flex: none; border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: var(--surface); display: flex; flex-direction: column; box-shadow: var(--shadow-3);
}
@media (min-width: 720px) { .sheet { margin: auto; border-radius: var(--r-xl); } }
dialog[open] .sheet { animation: rise var(--t-slow) var(--ease); }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-4) var(--s-3) var(--s-5); border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: var(--fs-20); flex: 1; }
.sheet-body { padding: var(--s-5); overflow-y: auto; flex: 1; }
.sheet-foot { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line); display: flex; gap: var(--s-3); flex-wrap: wrap; padding-bottom: max(var(--s-4), env(safe-area-inset-bottom)); }

/* тосты */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(var(--s-4), env(safe-area-inset-bottom)); z-index: 200; display: flex; flex-direction: column; gap: var(--s-2); width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow-2); animation: rise var(--t-med) var(--ease); }
.toast-error { background: var(--destructive); color: var(--on-destructive); }

/* пустые состояния и загрузка */
.empty { text-align: center; padding: var(--s-12) var(--s-4); color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: var(--s-3); }
.empty .ico { width: 40px; height: 40px; color: var(--text-3); stroke-width: 1.5; }
.empty h3 { color: var(--text); font-size: var(--fs-20); }
.skel { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: var(--r-md); }
@keyframes shimmer { to { background-position: -200% 0; } }
.alert { display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--warning-soft); color: var(--warning); font-weight: 600; font-size: var(--fs-14); align-items: flex-start; }
.alert .ico { margin-top: 1px; }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-error { background: var(--destructive-soft); color: var(--destructive); }
.alert-success { background: var(--success-soft); color: var(--success); }

/* миниатюра товара без фото */
.thumb { width: 64px; height: 64px; border-radius: var(--r-md); background: var(--surface-2); flex: none; overflow: hidden; display: grid; place-items: center; color: var(--text-2); font-weight: 800; font-size: var(--fs-18); letter-spacing: -0.02em; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* логотип */
.logo { display: inline-flex; align-items: center; gap: var(--s-2); font-weight: 800; font-size: var(--fs-18); text-decoration: none; letter-spacing: -0.02em; }
.logo-mark { width: 28px; height: 28px; border-radius: var(--r-sm); background: var(--action); color: var(--on-action); display: grid; place-items: center; }
.logo-mark .ico { width: 18px; height: 18px; }

.theme-toggle .ico-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .ico-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .ico-moon { display: block; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
.chip:has(input:focus-visible) { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
