/* =============================================================================
   ДИЗАЙН-СИСТЕМА — компоненты
   Работает поверх tokens.css. Классы с префиксом ds- чтобы не конфликтовать.
   Автоматически подхватывают любую активную вариацию (data-theme).
   ============================================================================= */

/* --- База документа --- */
.ds-root {
  background: var(--bg);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
}

/* --- Типографика --- */
.ds-display { font-size: var(--fs-display); font-weight: var(--fw-extrabold); line-height: var(--lh-heading); letter-spacing: var(--ls-tighter); color: var(--ink); }
.ds-h1      { font-size: var(--fs-h1); font-weight: var(--fw-extrabold); line-height: var(--lh-heading); letter-spacing: var(--ls-tight); color: var(--ink); }
.ds-h2      { font-size: var(--fs-h2); font-weight: var(--fw-bold); line-height: var(--lh-heading); letter-spacing: var(--ls-tight); color: var(--ink); }
.ds-h3      { font-size: var(--fs-h3); font-weight: var(--fw-bold); line-height: var(--lh-snug); letter-spacing: var(--ls-snug); color: var(--ink); }
.ds-title   { font-size: var(--fs-title); font-weight: var(--fw-bold); letter-spacing: var(--ls-snug); color: var(--ink); }
.ds-body    { font-size: var(--fs-base); font-weight: var(--fw-regular); color: var(--ink-2); }
.ds-muted   { color: var(--muted); }
.ds-eyebrow { font-family: var(--font-mono); font-size: var(--fs-2xs); font-weight: var(--fw-semibold); letter-spacing: var(--ls-eyebrow); text-transform: uppercase; color: var(--muted); }
.ds-num     { font-family: var(--font-mono); font-weight: var(--fw-extrabold); letter-spacing: var(--ls-tight); color: var(--ink); font-variant-numeric: tabular-nums; }

/* --- Кнопки --- */
.ds-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-family: var(--font-sans); font-size: var(--fs-sm); font-weight: var(--fw-semibold);
  padding: 12px 22px; border-radius: var(--radius-md); border: 1px solid transparent;
  cursor: pointer; transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur-fast) var(--ease);
  white-space: nowrap; line-height: 1; min-height: 44px; text-decoration: none;
}
.ds-btn:active { transform: translateY(1px); }
.ds-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.ds-btn--primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-cta); }
.ds-btn--primary:hover { background: var(--accent-hover); }

.ds-btn--ink { background: var(--ink); color: var(--bg); }
.ds-btn--ink:hover { opacity: .9; }

.ds-btn--secondary { background: var(--surface); color: var(--ink); border-color: var(--border); box-shadow: var(--shadow-xs); }
.ds-btn--secondary:hover { background: var(--surface-2); }

.ds-btn--ghost { background: transparent; color: var(--ink-2); }
.ds-btn--ghost:hover { background: var(--surface-2); }

.ds-btn--pill { border-radius: var(--radius-pill); }
.ds-btn--sm   { min-height: 40px; padding: 8px 14px; font-size: var(--fs-xs); border-radius: var(--radius-sm); }
.ds-btn--lg   { padding: 15px 30px; font-size: var(--fs-md); }
.ds-btn:disabled, .ds-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; box-shadow: none; pointer-events: none; }
.ds-btn--danger { background: var(--surface); color: var(--danger-ink); border-color: var(--danger-tint); }
.ds-btn--danger:hover { background: var(--danger-bg); }
.ds-btn--block { width: 100%; }

/* --- Поля ввода --- */
.ds-input {
  width: 100%; font-family: var(--font-sans); font-size: var(--fs-base); font-weight: var(--fw-medium);
  color: var(--ink); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 11px 14px; line-height: 1.2;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.ds-input::placeholder { color: var(--muted); }
.ds-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.ds-input--error { border-color: var(--danger); }
.ds-input--error:focus { box-shadow: 0 0 0 3px var(--danger-bg); }
.ds-input:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }

/* Капсула с встроенной кнопкой (hero-инпут) */
.ds-capsule {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 6px 6px 6px 18px; box-shadow: var(--shadow-xs);
}
.ds-capsule input { flex: 1; border: none; background: transparent; font: var(--fw-medium) var(--fs-md) var(--font-sans); color: var(--ink); }
.ds-capsule input:focus { outline: none; }
.ds-capsule input::placeholder { color: var(--muted); }

.ds-label { display: block; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--ink-2); margin-bottom: var(--space-2); }

/* --- Карточки --- */
.ds-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-sm);
}
.ds-card--flat { box-shadow: none; }
.ds-card--raised { box-shadow: var(--shadow-md); border-color: transparent; }
.ds-card--pad-lg { padding: var(--space-8); }

/* Стат-плитка (крупное моно-число + дельта) */
.ds-stat { display: flex; flex-direction: column; gap: var(--space-2); }
.ds-stat__label { font-size: var(--fs-xs); color: var(--muted); }
.ds-stat__value { font-family: var(--font-mono); font-size: var(--fs-h2); font-weight: var(--fw-extrabold); letter-spacing: var(--ls-tight); color: var(--ink); font-variant-numeric: tabular-nums; }
.ds-stat__delta { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--success); }
.ds-stat__delta--down { color: var(--danger); }

/* --- Бейджи / статусы --- */
.ds-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); line-height: 1;
  padding: 5px 9px; border-radius: var(--radius-sm);
}
.ds-badge--neutral { background: var(--surface-2); color: var(--ink-2); }
.ds-badge--accent  { background: var(--accent-tint-1); color: var(--accent); }
.ds-badge--success { background: var(--success-bg); color: var(--success-ink); }
.ds-badge--danger  { background: var(--danger-bg); color: var(--danger-ink); }
.ds-badge--warning { background: var(--warning-bg); color: var(--warning-ink); }

/* Точка-индикатор */
.ds-dot { width: 6px; height: 6px; border-radius: var(--radius-pill); background: currentColor; }

/* --- Тумблер --- */
.ds-switch { position: relative; display: inline-block; width: 40px; height: 24px; }
.ds-switch input { opacity: 0; width: 0; height: 0; }
.ds-switch__track { position: absolute; inset: 0; background: var(--border); border-radius: var(--radius-pill); transition: background var(--dur) var(--ease); cursor: pointer; }
.ds-switch__track::before { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: var(--radius-pill); box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease); }
.ds-switch input:checked + .ds-switch__track { background: var(--accent); }
.ds-switch input:checked + .ds-switch__track::before { transform: translateX(16px); }

/* --- Разделитель --- */
.ds-divider { height: 1px; background: var(--divider); border: none; margin: var(--space-6) 0; }

/* --- Иконки (outline, наследуют цвет текста) --- */
.ds-icon { width: 24px; height: 24px; stroke: currentColor; stroke-width: var(--icon-stroke); stroke-linecap: round; stroke-linejoin: round; fill: none; }
.ds-icon-tile { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: var(--radius-md); background: var(--accent-tint-1); color: var(--accent); }

/* =============================================================================
   Компоненты витрины ЮГС (показ 26.09): сообщения, поля с ошибками,
   пометка примеров, загрузка. Только токены выше — своих цветов нет.
   ============================================================================= */

/* --- Сообщение после действия (успех / ошибка) --- */
.ds-alert { display: flex; gap: var(--space-3); align-items: flex-start; padding: 14px 16px; border-radius: var(--radius-md); font-size: var(--fs-sm); line-height: 1.5; border: 1px solid transparent; }
.ds-alert--success { background: var(--success-bg); color: var(--success-ink); border-color: var(--success-tint); }
.ds-alert--error   { background: var(--danger-bg);  color: var(--danger-ink);  border-color: var(--danger-tint); }
.ds-alert--info    { background: var(--accent-tint-1); color: var(--ink-2); border-color: var(--accent-tint-2); }
.ds-alert svg { flex: none; width: 18px; height: 18px; margin-top: 1px; stroke: currentColor; stroke-width: 1.75; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* --- Поле формы: подпись сверху, подсказка и ошибка снизу --- */
.ds-field { display: grid; gap: 6px; align-content: start; }
.ds-field > .ds-label { margin-bottom: 0; font-size: var(--fs-sm); }
.ds-hint  { font-size: var(--fs-xs); color: var(--muted); line-height: 1.5; }
.ds-error { font-size: var(--fs-xs); color: var(--danger-ink); line-height: 1.5; }
.ds-field--error .ds-input { border-color: var(--danger); }
.ds-input { min-height: 44px; }
textarea.ds-input { line-height: 1.5; }
select.ds-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23676B74' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px; }
.ds-check { display: flex; gap: 10px; align-items: flex-start; font-size: var(--fs-sm); color: var(--ink-2); min-height: 44px; padding-top: 10px; cursor: pointer; }
.ds-check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); flex: none; }

/* --- Выбор роли карточкой --- */
.ds-choice { display: block; cursor: pointer; }
.ds-choice input { position: absolute; opacity: 0; pointer-events: none; }
.ds-choice__box { display: grid; gap: 4px; padding: 16px; border: 1px solid var(--border-2); border-radius: var(--radius-md); background: var(--surface); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); min-height: 44px; }
.ds-choice input:checked + .ds-choice__box { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.ds-choice input:focus-visible + .ds-choice__box { box-shadow: var(--focus-ring); }

/* --- Пометка демо-данных --- */
.ds-demo { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-2xs); font-weight: var(--fw-semibold); line-height: 1; padding: 5px 9px; border-radius: var(--radius-sm); background: var(--surface-3); color: var(--ink-2); border: 1px dashed var(--border-2); }

/* --- Ссылки в тексте и навигации --- */
.ds-link { color: var(--accent); font-weight: var(--fw-semibold); text-decoration: none; }
.ds-link:hover { color: var(--accent-hover); text-decoration: underline; }
.ds-link:focus-visible, .ds-navlink:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 8px; }
.ds-navlink { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; color: var(--ink-2); text-decoration: none; }
.ds-navlink:hover { color: var(--ink); }
.ds-navlink[aria-current="page"] { color: var(--ink); font-weight: var(--fw-semibold); }

/* --- Загрузка: кнопка в процессе запроса HTMX --- */
.htmx-request .ds-btn[type="submit"], .ds-btn.htmx-request { opacity: .6; pointer-events: none; }
.ds-btn .ds-when-loading { display: none; }
.htmx-request .ds-btn .ds-when-loading { display: inline; }
.htmx-request .ds-btn .ds-when-idle { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; }
}

/* --- Карточка задания в ленте --- */
.card-hover { color: inherit; text-decoration: none; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.card-hover:hover { border-color: var(--accent-tint-3); box-shadow: var(--shadow-md); }
.card-hover:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Шаги сделки: на телефоне номер слева, без высоких карточек */
@media (max-width: 767px) {
  .step { display: grid; grid-template-columns: 28px 1fr; column-gap: 12px; padding: 16px 18px; }
  .step > span { grid-row: span 2; padding-top: 2px; }
  .step > h3 { margin-top: 0; }
}

/* Карточка задания: на телефоне решение (ставка + отклик) сразу под заголовком */
.task-grid { display: grid; gap: 32px; grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "aside" "body"; }
@media (min-width: 1024px) {
  .task-grid { grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: "head aside" "body aside"; grid-template-rows: auto 1fr; column-gap: 32px; row-gap: 32px; }
}

/* hidden сильнее утилит display (grid/flex) — иначе скрытые блоки формы видны */
[hidden] { display: none !important; }
