/* GenieJack — экраны анкеты и выдачи (ТЗ 4.4, часть 3б).
 *
 * Токены — документ 19, раздел 3: светлая тема на :root, тёмная — на
 * [data-theme="dark"] (атрибут ставит theme.js в <head>). Компоненты ссылаются
 * только на токены, не на HEX: тема меняет значения, а не правила.
 * Шрифты — системный стек; Unbounded и Manrope стоят первыми и сработают, если
 * установлены (файлов шрифтов в репозитории нет, внешние CDN не подключаются;
 * OPEN_QUESTIONS, 4.4а). Тени не используются (документ 19, раздел 3).
 */

:root {
  color-scheme: light;
  --paper: #FAF8F4;
  --surface: #FFFFFF;
  --lilac: #EFEBFB;
  --ink: #1B1030;
  --ink-soft: #5B5470;
  --indigo: #4B2FD1;
  --on-indigo: #FFFFFF;
  --indigo-text: #4B2FD1;
  --progress: #4B2FD1;
  --link-hover: #1F2270;
  --pressed: #1F2270;
  --indigo-disabled: #B4A8E6;
  --on-disabled: #FFFFFF;
  --night: #1F2270;
  --on-night: #FFFFFF;
  --step: #1F2270;
  --logo: #4B2FD1;
  --gold: #F2A93B;
  --border: #E4DEF7;
  --border-strong: #857CA5;
  --track: #857CA5;
  --error: #B42318;
  --success: #257A4B;
  --on-status: #FFFFFF;
  --skeleton: #E4DEF7;
  --photo-bg: #FFFFFF;

  --font-display: "Unbounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-text: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #141417;
  --surface: #1E1E23;
  --lilac: #231F38;
  --ink: #EEECF4;
  --ink-soft: #ADA8BD;
  --indigo: #5F55EE;
  --on-indigo: #FFFFFF;
  --indigo-text: #A59BFF;
  --progress: #A59BFF;
  --link-hover: #CCC5FF;
  --pressed: #4B2FD1;
  --indigo-disabled: #38364F;
  --on-disabled: #A39FB8;
  --step: #57527A;
  --logo: #FFFFFF;
  --border: #302F38;
  --border-strong: #7C7792;
  --track: #66627A;
  --error: #FF7A6B;
  --success: #4CC38A;
  --on-status: #141417;
  --skeleton: #2A2930;
}

/* --- основа ------------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 500 16px/24px var(--font-text);
}

h1, h2, h3, p, fieldset, legend, ol, ul {
  margin: 0;
  padding: 0;
}

fieldset {
  border: 0;
  min-width: 0;
}

ol, ul {
  list-style: none;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--indigo-text);
  outline-offset: 2px;
}

.app {
  max-width: 480px;           /* одна колонка и центрирование (ТЗ п. 4) */
  margin: 0 auto;
  padding: 0 16px 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1 0 auto;
}

/* --- роли типографики (документ 19, раздел 3) ---------------------------------- */
.t-display { font: 600 28px/34px var(--font-display); }
.t-h2 { font: 600 22px/28px var(--font-display); }
.t-h3 { font: 600 17px/22px var(--font-display); }
.t-accent { font: 700 16px/22px var(--font-text); }
.t-body { font: 500 16px/24px var(--font-text); }
.t-body-small { font: 500 14px/20px var(--font-text); }
.t-caption { font: 500 13px/18px var(--font-text); }
.soft { color: var(--ink-soft); }

/* --- шапка экранов 1 и 5: логотип и переключатель темы -------------------------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 600 17px/22px var(--font-display);
  color: var(--ink);
}

.logo-mark,
.logo-mark svg {
  display: block;
  width: 32px;
  height: 32px;
}

.theme-toggle {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Луна — в светлой теме, солнце — в тёмной (документ 19, раздел 4). */
.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* --- шапка шагов 2–4: «← Назад» и прогресс, закреплены сверху ------------------- */
.step-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--paper);
  padding: 4px 0 12px;
}

.progress {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-bar {
  flex: 1;
  display: flex;
  gap: 4px;
}

.progress-bar span {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: var(--track);
}

.progress-bar span.done {
  background: var(--progress);
}

/* --- ссылки-действия и кнопки -------------------------------------------------- */
.link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--indigo-text);
  font: 600 14px/20px var(--font-text);
  text-decoration: none;
  cursor: pointer;
}

.link:hover {
  color: var(--link-hover);
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 0 24px;
  border-radius: 999px;
  font: 700 16px/20px var(--font-text);
  cursor: pointer;
}

.btn-primary {
  border: 0;
  background: var(--indigo);
  color: var(--on-indigo);
}

.btn-primary:active {
  background: var(--pressed);
}

.btn-secondary {
  border: 1.5px solid var(--indigo-text);
  background: transparent;
  color: var(--indigo-text);
}

/* --- экран 1 ----------------------------------------------------------------- */
.home {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 8px;
}

/* Первый вопрос анкеты на главной (ТЗ 10.12.2). */
.home-s1 {
  margin-top: 8px;
}

.home-note {
  text-align: center;
}

.how {
  margin-top: 16px;
  padding: 24px;
  border-radius: 32px;
  background: var(--lilac);
}

.how h2 {
  margin-bottom: 16px;
}

.how ol {
  display: flex;
  flex-direction: column;
  gap: 12px;
  counter-reset: how;
}

.how li {
  display: flex;
  align-items: center;
  gap: 12px;
  counter-increment: how;
}

.how li::before {
  content: counter(how);
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--step);
  color: var(--on-night);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 600 14px/1 var(--font-display);
}

/* --- шаги анкеты --------------------------------------------------------------- */
.step-title {
  margin: 8px 0 24px;
}

.questions {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.q-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-bottom: 12px;
  font: 700 16px/22px var(--font-text);
}

.q-optional {
  flex: none;
  color: var(--ink-soft);
  font: 500 13px/18px var(--font-text);
}

.q.has-error .q-text {
  color: var(--error);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips-column {
  flex-direction: column;
  align-items: stretch;
}

.chip {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font: 600 14px/18px var(--font-text);
  text-align: center;
  cursor: pointer;
}

.chips-column .chip {
  text-align: left;
  border-radius: 20px;
}

.chip[aria-pressed="true"] {
  background: var(--indigo);
  border-color: var(--indigo);
  color: var(--on-indigo);
}

.chip:disabled {
  opacity: 0.5;
  cursor: default;
}

.field {
  margin-top: 12px;
}

.q > .field:first-of-type {
  margin-top: 0;
}

.input {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font: 500 16px/24px var(--font-text);
}

textarea.input {
  min-height: 96px;
  resize: vertical;
}

.input::placeholder {
  color: var(--ink-soft);
  opacity: 1;
}

.input:focus-visible {
  outline: 2px solid var(--indigo-text);
  outline-offset: 0;
  border-color: transparent;
}

.input.has-error {
  border-color: var(--error);
}

.field-note {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
  color: var(--ink-soft);
  font: 500 13px/18px var(--font-text);
}

.counter {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.caption {
  margin-top: 8px;
  color: var(--ink-soft);
  font: 500 13px/18px var(--font-text);
}

.error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 8px;
  color: var(--error);
  font: 500 13px/18px var(--font-text);
}

/* Значок «!» в круге перед текстом ошибки: цвет — не единственный носитель смысла. */
.error::before {
  content: "!";
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  border-radius: 999px;
  background: var(--error);
  color: var(--on-status);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 700 11px/1 var(--font-text);
}

.extra-toggle {
  margin-top: 4px;
}

.extra-list {
  margin-top: 4px;
}

/* R9 — выделенная панель: рамка indigo-text, вопрос в H3 (документ 19, экран 3). */
.r9-lead {
  font: 600 13px/18px var(--font-text);
  color: var(--ink);
  margin-bottom: 8px;
}

.r9 {
  padding: 16px;
  border-radius: 20px;
  border: 1.5px solid var(--indigo-text);
  background: var(--surface);
}

.r9 .q-title {
  font: 600 17px/22px var(--font-display);
}

.step-actions {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.required-count {
  text-align: center;
}

/* --- выдача -------------------------------------------------------------------- */
.results-head {
  margin: 8px 0 16px;
}

.results-context {
  margin-top: 4px;
  color: var(--ink-soft);
  font: 500 13px/18px var(--font-text);
}

.results-context .link {
  display: inline;
  min-height: 0;
  /* Ссылка внутри строки подписи: зона касания 44px — отступом, без сдвига строки. */
  padding: 13px 0;
  margin: -13px 0;
  font-size: 13px;
  line-height: 18px;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  padding: 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.card-top {
  display: flex;
  gap: 12px;
}

.card-photo {
  position: relative;
  flex: none;
  width: 96px;
  height: 96px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--skeleton);
}

/* Фото целиком, без обрезки и фильтров, на подложке photo-bg (документ 19, раздел 3). */
.card-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--photo-bg);
}

.card-photo .photo-missing {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  --logo: var(--border-strong);
}

.card-photo .photo-missing svg {
  width: 40px;
  height: 40px;
}

.card-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-title {
  font: 700 16px/22px var(--font-text);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.card-price {
  font: 600 18px/22px var(--font-display);
  white-space: nowrap;
}

.card-price-note {
  color: var(--ink-soft);
  font: 500 13px/18px var(--font-text);
}

/* Reason-to-buy: фон paper, золотая полоса 3px слева — у каждой карточки (Р4). */
.card-reason {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  border-left: 3px solid var(--gold);
  background: var(--paper);
  color: var(--ink-soft);
  font: 500 14px/20px var(--font-text);
}

/* Блок маркировки: линия сверху, «Реклама» в рамке, строка рекламодателя и erid. */
.card-ad {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--ink-soft);
  font: 500 13px/18px var(--font-text);
  overflow-wrap: anywhere;
}

.ad-label {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--ink);
  font: 600 13px/18px var(--font-text);
}

/* 5a — скелетон без анимации (Р10). */
.skeleton-card .card-photo,
.skeleton-line {
  background: var(--skeleton);
}

.skeleton-line {
  height: 16px;
  border-radius: 999px;
}

.skeleton-line.short {
  width: 40%;
}

.skeleton-card .card-main {
  flex: 1;
  gap: 12px;
  padding-top: 8px;
}

.loading-text {
  margin: 16px 0 12px;
  color: var(--ink-soft);
}

/* Нейтральная панель: пустая выдача и 5d — не красная, сбой не ошибка человека. */
.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
}

/* 5b над карточками, 5c под ними — та же нейтральная панель с отступом от карточек. */
[data-few].results-note {
  margin-bottom: 12px;
}

[data-low].results-note {
  margin-top: 12px;
}

.results-note .link {
  align-self: center;
}

/* Блок почты на экране 5 (документ 19, Р6; документ 40, Е-01): под карточками. */
.mail-block {
  margin-top: 12px;
}

.mail-block form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mail-block .caption {
  margin-top: 0;
}

/* «Поделиться» до части Б (документ 39, Ш-12): под шапкой — строка «Ссылка
   скопирована» или, если копирование не вышло, поле с адресом для копирования. */
.share-note {
  margin-bottom: 8px;
  color: var(--success);
  font: 500 13px/18px var(--font-text);
  text-align: right;
}

.share-url {
  margin-bottom: 8px;
  font-size: 14px;
}

/* Подпись «Данные сервиса Яндекс Маркет» и логотип (решение 6 ТЗ 4.7): Caption
   ink-soft под строкой рекламодателя; логотип — встроенный <svg>, только если файл
   есть, 16 px по высоте; надпись «Маркет» (currentColor) — цветом текста темы. */
.ad-source {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  color: var(--ink-soft);
  font: 500 13px/18px var(--font-text);
}

.ad-source a {
  color: inherit;
}

.ad-source-logo {
  display: block;
  flex: none;
  height: 16px;
  width: auto;
  color: var(--ink);
}

/* --- экран 6: карточка товара (документ 19, экран 6 и 6a; ТЗ 4.7, раздел 4) ------- */
.back-link {
  font: 500 16px/24px var(--font-text);
}

.product {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Фото 4:3, радиус 20, целиком (contain) на подложке photo-bg, без правок. */
.product-photo {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 20px;
  overflow: hidden;
  background: var(--skeleton);
}

.product-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--photo-bg);
}

.product-photo .photo-missing {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  --logo: var(--border-strong);
}

.product-photo .photo-missing svg {
  width: 64px;
  height: 64px;
}

.product-title {
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.product .card-reason {
  margin-top: 4px;
}

/* Маркировка в две строки прямо над кнопкой; токен — внутри ссылки кнопки (М-12). */
.product-ad {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink-soft);
  font: 500 13px/18px var(--font-text);
  overflow-wrap: anywhere;
}

.product-ad .link {
  display: inline;
  min-height: 0;
  font: inherit;
}

.product-buy {
  margin-top: 8px;
  text-decoration: none;
}

/* Реакции автора (документ 19, раздел 4: чипсы 40px с SVG-иконкой 20px одним контуром;
   в MVP — «Подходит» и «Не то»). Под карточкой выдачи и под кнопкой экрана 6 (4.11а-2).
   Нажатая — как нажатый чипс анкеты (`.chip[aria-pressed="true"]`). */
.reactions {
  margin-top: 12px;
}

.chip.reaction {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip.reaction svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Название карточки — ссылка на экран 6 цветом текста (документ 39, Ш-03). */
.card-title a {
  color: inherit;
  text-decoration: none;
}

.card-title a:hover {
  text-decoration: underline;
}

/* --- футер-строка ---------------------------------------------------------------- */
.legal {
  margin-top: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font: 500 13px/18px var(--font-text);
}
