/* ============================================================
   COMPONENTS
   ============================================================ */

/* ---------------- КАРТОЧКА ---------------- */
.card {
  position: relative;
  background: var(--surface);
  background-image: linear-gradient(180deg, rgba(255,255,255,.028), rgba(255,255,255,0) 42%);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: clamp(16px, 2.4vw, 22px);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease),
              border-color var(--dur-fast),
              box-shadow var(--dur-fast);
}
[data-theme="warm"] .card,
[data-theme="graphite"] .card {
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: var(--r-xl);
}
@media (hover: hover) and (pointer: fine) {
  .card--hover:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
  }
}
.card--flat { box-shadow: none; }
.card--accent { border-color: var(--border-strong); }
.card--pad-lg { padding: clamp(20px, 3vw, 32px); }

/* ---------------- КНОПКИ ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  padding: 13px 22px;
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 14.5px;
  line-height: 1;
  letter-spacing: .01em;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: filter var(--dur-fast), transform var(--dur-fast),
              background var(--dur-fast), border-color var(--dur-fast),
              box-shadow var(--dur-fast), opacity var(--dur-fast);
}
[data-theme="warm"] .btn,
[data-theme="graphite"] .btn { font-weight: 600; letter-spacing: 0; }

.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: .45; cursor: not-allowed; filter: none; transform: none;
}

.btn--primary {
  background: var(--grad);
  color: var(--on-accent);
  border: 0;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,.18);
}
@media (hover: hover) and (pointer: fine) {
  .btn--primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: var(--shadow), var(--glow); }
}

.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
}
@media (hover: hover) and (pointer: fine) {
  .btn--ghost:hover:not(:disabled) { background: var(--grad-soft); border-color: var(--accent); }
}

.btn--soft {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn--soft:hover:not(:disabled) { border-color: var(--border-strong); }

.btn--sm { min-height: 38px; padding: 10px 15px; font-size: 13px; border-radius: var(--r-sm); }
.btn--lg { min-height: 54px; padding: 17px 30px; font-size: 16px; }
.btn--block { width: 100%; }
.btn--icon { padding: 11px; min-height: 42px; aspect-ratio: 1; border-radius: var(--r-sm); }

/* ---------------- ПИЛЮЛИ / ЧИПЫ ---------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.pill--accent {
  background: var(--grad-soft);
  border-color: var(--border-strong);
  color: var(--accent);
}
.pill--dot::before {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  flex: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  min-height: 44px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--dur-fast);
  touch-action: manipulation;
}
@media (hover: hover) and (pointer: fine) {
  .chip:hover { border-color: var(--border-strong); color: var(--text); }
}
.chip[aria-pressed="true"], .chip.is-active {
  background: var(--grad);
  border-color: transparent;
  color: var(--on-accent);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.16);
}

/* мультивыбор — карточка-опция */
.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 14.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all var(--dur-fast);
}
@media (hover: hover) and (pointer: fine) {
  .opt:hover { border-color: var(--border-strong); color: var(--text); background: var(--grad-soft); }
}
.opt.is-active {
  border-color: var(--accent);
  background: var(--grad-soft);
  color: var(--text);
}
.opt__box {
  flex: none;
  width: 22px; height: 22px;
  border-radius: var(--r-xs);
  border: 1.5px solid var(--border-strong);
  display: grid; place-items: center;
  transition: all var(--dur-fast);
}
.opt.is-active .opt__box { background: var(--grad); border-color: transparent; }
.opt__box svg { width: 13px; height: 13px; opacity: 0; transition: opacity var(--dur-fast); color: var(--on-accent); }
.opt.is-active .opt__box svg { opacity: 1; }
.opt__ico { flex: none; color: var(--accent); }
.opt--radio .opt__box { border-radius: 50%; }

/* ---------------- ПОЛЯ ВВОДА ---------------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label { font-size: 13px; font-weight: 700; color: var(--text-dim); }
.field .req { color: var(--accent); }

.input, .textarea, .select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 13px 15px;
  font-size: 16px; /* iOS: не зумить при фокусе */
  font-family: var(--font-body);
  color: var(--text);
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.input::placeholder, .textarea::placeholder { color: var(--text-mute); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--grad-soft);
}
.input.is-error, .textarea.is-error { border-color: var(--danger); }
.field__err { font-size: 12px; color: var(--danger); min-height: 15px; }

.check {
  display: flex; align-items: flex-start; gap: 11px;
  cursor: pointer; font-size: 13.5px; color: var(--text-dim); line-height: 1.5;
}
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check__box {
  flex: none; margin-top: 1px;
  width: 24px; height: 24px;
  border-radius: var(--r-xs);
  border: 1.5px solid var(--border-strong);
  display: grid; place-items: center;
  transition: all var(--dur-fast);
}
.check input:checked + .check__box { background: var(--grad); border-color: transparent; box-shadow: var(--glow); }
.check__box svg { width: 14px; height: 14px; opacity: 0; color: var(--on-accent); transition: opacity var(--dur-fast); }
.check input:checked + .check__box svg { opacity: 1; }
.check input:focus-visible + .check__box { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- ПРОГРЕСС ---------------- */
.progress {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--grad);
  box-shadow: var(--glow);
  transition: width var(--dur-slow) var(--ease);
}
.progress--thin { height: 3px; }

/* кольцо прогресса */
.ring { display: grid; place-items: center; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring__track { stroke: var(--surface-2); }
.ring__bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .7s var(--ease); }
.ring__label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--font-head); font-weight: var(--head-weight); font-size: 19px;
}

/* ---------------- АВАТАР ---------------- */
.avatar {
  flex: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--grad);
  color: var(--on-accent);
  font-family: var(--font-head);
  font-weight: var(--head-weight);
  font-size: 15px;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--lg { width: 58px; height: 58px; font-size: 19px; }
.avatar--sm { width: 32px; height: 32px; font-size: 12px; }

/* ---------------- БЕЙДЖИ ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: var(--r-pill);
  font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  background: var(--grad-soft); color: var(--accent);
  border: 1px solid var(--border-strong);
}
.badge--hot { background: var(--grad); color: var(--on-accent); border-color: transparent; box-shadow: var(--glow); }
.badge--demo {
  background: transparent; color: var(--text-mute);
  border-color: var(--border); letter-spacing: .08em;
}
.badge--free { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }

/* ---------------- ЗВЁЗДЫ ---------------- */
.stars { display: inline-flex; gap: 2px; color: var(--star); }
.stars svg { width: 15px; height: 15px; fill: currentColor; stroke: none; }

/* ---------------- ТАБЫ ---------------- */
.tabs {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs > .chip { flex: none; }

/* ---------------- АККОРДЕОН ---------------- */
.acc { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.acc + .acc { margin-top: 10px; }
.acc__btn {
  width: 100%; display: flex; align-items: center; gap: 14px;
  padding: 18px 20px; text-align: left;
  font-size: 15.5px; font-weight: 700; color: var(--text);
}
.acc__btn:hover { color: var(--accent); }
.acc__ico { flex: none; margin-left: auto; color: var(--accent); transition: transform var(--dur) var(--ease); }
.acc.is-open .acc__ico { transform: rotate(45deg); }
.acc__body {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur) var(--ease);
}
.acc.is-open .acc__body { grid-template-rows: 1fr; }
.acc__inner { overflow: hidden; }
.acc__inner > div { padding: 0 20px 20px; color: var(--text-dim); font-size: 14.5px; line-height: 1.65; }

/* ---------------- МОДАЛКА / ШТОРКА ---------------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: var(--z-overlay);
  opacity: 0;
  animation: fadeIn .2s var(--ease) forwards;
  display: grid;
  place-items: end center;
  padding: 0;
}
@media (min-width: 720px) { .overlay { place-items: center; padding: 24px; } }
@keyframes fadeIn { to { opacity: 1; } }

.sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  padding: 12px clamp(18px, 4vw, 28px) calc(24px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
  transform: translateY(28px);
  opacity: 0;
  animation: sheetIn .3s var(--ease) forwards;
  z-index: var(--z-modal);
}
@media (min-width: 720px) {
  .sheet { border-radius: var(--r-2xl); padding-bottom: 28px; max-height: 88vh; }
}
.sheet--wide { max-width: 760px; }
@keyframes sheetIn { to { transform: none; opacity: 1; } }

.sheet__grab {
  width: 40px; height: 4px; border-radius: 99px;
  background: var(--border-strong);
  margin: 0 auto 16px;
}
@media (min-width: 720px) { .sheet__grab { display: none; } }
.sheet__close {
  position: absolute; top: 14px; right: 14px;
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-dim);
  transition: color var(--dur-fast);
}
.sheet__close:hover { color: var(--accent); }

/* ---------------- ТОСТ ---------------- */
.toast-host {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
  width: max-content; max-width: 92vw;
}
.toast {
  padding: 11px 18px;
  border-radius: var(--r-pill);
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow), var(--glow);
  font-size: 13.5px; font-weight: 700;
  animation: toastIn .25s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------------- СКЕЛЕТОН / СПИННЕР ---------------- */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- ИКОНКИ ---------------- */
.ico {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.ico--sm { width: 16px; height: 16px; }
.ico--lg { width: 26px; height: 26px; }
.ico-box {
  width: 44px; height: 44px; flex: none;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: var(--grad-soft);
  border: 1px solid var(--border);
  color: var(--accent);
}

/* ---------------- ПРОКРУЧИВАЕМЫЙ РЯД ---------------- */
.scroller {
  display: flex; gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
  margin-inline: calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
  scrollbar-width: none;
}
.scroller::-webkit-scrollbar { display: none; }
.scroller > * { scroll-snap-align: start; flex: 0 0 auto; }

/* ---------------- КОД / ПРОМПТ ---------------- */
.code {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  text-transform: none;
  letter-spacing: 0;
}
.code .var { color: var(--accent-2); font-weight: 500; }
