/*
 * Конструктор карточек. Размеры относятся только к панели настроек и шапке результата.
 * Печатный лист остаётся в style.css и не наследует эти высоты.
 *
 * 1. Оболочка
 * 2. Разделы формы
 * 3. Переключатели
 * 4. Поля и степперы
 * 5. Оформление
 * 6. Действия
 * 7. Шапка результата
 * 8. Состояния
 * 9. Адаптивность
 */

.card-builder,
.card-builder *,
.card-builder *::before,
.card-builder *::after,
.card-stage__head,
.card-stage__head *,
.card-stage__download-wrap,
.card-stage__download-wrap *,
.card-stage__pager,
.card-stage__pager *,
.card-stage__answers,
.card-stage__answers * {
  box-sizing: border-box;
}

.card-builder,
.card-stage {
  min-width: 0;
}

.card-builder {
  position: relative;
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.card-builder:has(.pdf-download-stats) .card-builder__section:first-child .card-builder__section-title {
  padding-right: 16rem;
}

@media (max-width: 640px) {
  .card-builder > .pdf-download-stats {
    position: static;
    margin: 0 0 12px;
    max-width: 100%;
  }

  .card-builder:has(.pdf-download-stats) .card-builder__section:first-child .card-builder__section-title {
    padding-right: 0;
  }
}

.card-builder fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.card-builder__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.card-builder__sections {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.card-builder__section + .card-builder__section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.card-builder__section-title {
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.35;
  font-weight: 650;
}

.card-builder__field + .card-builder__field {
  margin-top: 12px;
}

.card-builder legend {
  margin: 0 0 6px;
  padding: 0;
  font-size: 15px;
  line-height: 1.35;
  font-weight: 650;
}

.card-builder__mode-hint {
  margin: 8px 0 0;
  color: var(--color-muted);
  font-size: 14px;
  line-height: 1.45;
}

.card-builder__panel {
  margin-top: 8px;
}

.card-builder__label {
  display: block;
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.35;
  font-weight: 650;
  color: var(--color-text);
}

.card-choice-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.card-choice {
  position: relative;
}

.card-choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.card-choice:not(.card-choice--mode) > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 15px;
  line-height: 22px;
  font-weight: 500;
  cursor: pointer;
}

.card-choice.card-choice--quantity > span {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
}

.card-choice:not(.card-choice--mode) input:checked + span {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #ffffff;
}

.card-choice input:focus-visible {
  outline: none;
}

.card-choice input:focus-visible + span {
  outline: 3px solid #8bb4e8;
  outline-offset: 2px;
}

.card-choice input:disabled + span {
  opacity: 0.6;
  cursor: not-allowed;
}

.card-builder__mode-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: #f1f4f8;
  border: 1px solid #e0e6ee;
  border-radius: 8px;
}

.card-choice--mode {
  display: block;
  min-width: 0;
}

.card-choice--mode > .card-mode-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text);
  text-align: center;
  line-height: 1.35;
  cursor: pointer;
}

.card-choice--mode > span::before {
  content: none;
}

.card-mode-option__title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.card-choice--mode .card-choice__note {
  display: none;
  margin-top: 4px;
  color: var(--color-muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.35;
}

.card-choice--mode input:checked + .card-mode-option {
  background: #ffffff;
  border-color: #d6dfeb;
  color: var(--color-primary);
  box-shadow: 0 1px 3px rgb(20 40 70 / 8%);
}

.card-builder__count-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  max-width: 440px;
}

.card-stepper {
  display: inline-flex;
  align-items: stretch;
  height: 44px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  overflow: hidden;
}

.card-stepper button {
  width: 44px;
  height: 44px;
  border: 0;
  background: var(--color-surface);
  color: var(--color-primary);
  font: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.card-stepper button:hover,
.card-stepper button:focus-visible {
  background: #eef3fb;
}

.card-stepper button:disabled {
  color: #9aa6b8;
  cursor: not-allowed;
  background: var(--color-surface);
}

.card-stepper input {
  width: 52px;
  height: 44px;
  border: 0;
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 16px;
  font-weight: 650;
  text-align: center;
}

.card-stepper input::-webkit-outer-spin-button,
.card-stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.card-stepper input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.card-copy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 440px;
  margin-top: 12px;
}

.card-copy-row span {
  font-size: 15px;
  font-weight: 600;
}

.card-copy-row input {
  width: 72px;
  height: 44px;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 16px;
  font-weight: 650;
  text-align: center;
}

.card-builder__rows-title {
  margin: 16px 0 0;
  font-size: 15px;
  line-height: 1.35;
  font-weight: 650;
}

.card-builder__print-total {
  margin-top: 12px;
  padding: 8px 12px;
  background: #f4f7fb;
  border: 1px solid #e3e9f1;
  border-radius: 8px;
}

.card-builder__print-total-title {
  margin: 0;
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.4;
  font-weight: 650;
}

.card-builder__print-total-detail {
  margin: 4px 0 0;
  color: var(--color-muted);
  font-size: 14px;
  line-height: 1.45;
  font-weight: 400;
}

.card-text-button {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-primary);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

#card-copies-toggle {
  display: inline-block;
  margin-top: 4px;
}

.card-builder__copies-column {
  min-width: 0;
}

#card-copies-toggle::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  vertical-align: middle;
}

#card-copies-toggle[aria-expanded="true"]::after {
  transform: translateY(2px) rotate(225deg);
}

.card-text-button:hover,
.card-text-button:focus-visible {
  text-decoration: underline;
}

.card-text-button:disabled {
  color: #9aa6b8;
  cursor: not-allowed;
  text-decoration: none;
}

.card-apply {
  max-width: 360px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: #f7f9fc;
}

.card-apply p {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

.card-apply .card-builder__label {
  margin-top: 10px;
}

.card-apply input {
  width: 72px;
  height: 44px;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font: inherit;
  font-size: 16px;
  text-align: center;
}

.card-apply__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.card-field-error {
  margin: 8px 0 0;
  color: #8a3b2a;
  font-size: 14px;
  line-height: 1.4;
}

.card-builder__notice {
  margin: 16px 0 0;
  color: #8a5a12;
  font-size: 14px;
  line-height: 1.45;
}

.card-builder__fold {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

/* Заголовок и короткая подпись стоят в одну строку, поэтому закрытый блок остаётся около 44px.
   На узкой ширине подпись переносится целиком, не сжимаясь в столбик букв. */
.card-builder__fold > summary {
  position: relative;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  column-gap: 10px;
  row-gap: 2px;
  min-height: 44px;
  padding: 8px 40px 8px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  list-style: none;
  cursor: pointer;
}

.card-builder__fold > summary::-webkit-details-marker {
  display: none;
}

.card-builder__fold > summary::marker {
  content: "";
}

.card-builder__fold > summary:hover {
  border-color: #3b66a5;
  background: #f8fafc;
}

.card-builder__fold > summary:focus-visible {
  outline: 2px solid #3b66a5;
  outline-offset: 2px;
}

.card-builder__fold > summary::after {
  content: "";
  position: absolute;
  right: 18px;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -6px;
  border-right: 2px solid #64748b;
  border-bottom: 2px solid #64748b;
  transform: rotate(45deg);
  transition: transform 0.15s;
}

.card-builder__fold[open] > summary {
  border-radius: 10px 10px 0 0;
}

.card-builder__fold[open] > summary::after {
  margin-top: -2px;
  transform: rotate(-135deg);
}

.card-builder__fold-title,
.card-builder__fold-brief {
  flex: 0 0 auto;
  max-width: 100%;
}

.card-builder__fold-title {
  font-size: 16px;
  line-height: 1.35;
  font-weight: 650;
}

.card-builder__fold-brief {
  color: var(--color-muted);
  font-size: 14px;
  line-height: 1.4;
  font-weight: 400;
}

.card-builder__fold-body {
  padding: 12px 16px 16px;
  border: 1px solid #cbd5e1;
  border-top: 0;
  border-radius: 0 0 10px 10px;
  background: #fff;
}

.card-builder__fold-lead {
  margin: 0 0 14px;
  color: var(--color-muted);
  font-size: 14px;
  line-height: 1.45;
}

.card-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  cursor: pointer;
}

.card-check + .card-check {
  margin-top: 12px;
}

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

.card-check__title {
  color: var(--color-text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.card-check__note {
  color: var(--color-muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.4;
}

.card-check.card-check--answers {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
}

.card-check input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--color-primary);
}

.card-builder__hint {
  margin: 14px 0 0;
  color: var(--color-muted);
  font-size: 14px;
  line-height: 1.45;
}

.card-builder__actions {
  display: block;
  margin-top: 12px;
}

.card-builder__action-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
}

.card-builder__submit,
.card-builder__regenerate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 11px 18px;
  border-radius: var(--tool-action-radius, 10px);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 20px;
  cursor: pointer;
}

.card-builder__submit {
  border: 0;
  background: linear-gradient(135deg, var(--tool-file-from, #34a853) 0%, var(--tool-file-via, #2d9248) 100%);
  color: #ffffff;
  box-shadow: var(--tool-file-shadow, 0 6px 14px rgba(52, 168, 83, 0.22));
}

.card-builder__submit:hover,
.card-builder__submit:focus-visible {
  background: linear-gradient(135deg, var(--tool-file-via, #2d9248) 0%, var(--tool-file-to, #267a3d) 100%);
  box-shadow: var(--tool-file-shadow-hover, 0 8px 18px rgba(52, 168, 83, 0.28));
}

.card-builder__submit:disabled,
.card-builder__submit:disabled:hover,
.card-builder__submit:disabled:focus-visible {
  background: #d5dde8;
  color: #667588;
  box-shadow: none;
  cursor: not-allowed;
}

.card-builder__regenerate {
  border: 1px solid var(--color-primary);
  background: var(--color-surface);
  color: var(--color-primary);
}

.card-builder__regenerate:hover,
.card-builder__regenerate:focus-visible {
  background: #eef3fb;
}

.card-builder__regenerate:disabled,
.card-builder__regenerate:disabled:hover,
.card-builder__regenerate:disabled:focus-visible {
  border-color: #c5d0de;
  background: var(--color-surface);
  color: #8b97a8;
  cursor: not-allowed;
}

.card-builder__action-note {
  margin: 8px 0 0;
  color: var(--color-muted);
  font-size: 13px;
  line-height: 1.4;
}

.card-stage {
  margin-top: 12px;
  padding: 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.card-stage__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px 24px;
  margin-bottom: 16px;
}

.card-stage__intro {
  min-width: 0;
}

.card-stage__head h2 {
  margin: 0;
  color: #24324a;
  font-size: 20px;
  font-weight: 650;
  line-height: 1.3;
}

.card-stage__meta {
  margin: 8px 0 0;
  color: var(--color-text);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
}

.card-stage__answers-note {
  margin: 2px 0 0;
  color: var(--color-muted);
  font-size: 14px;
  line-height: 1.5;
}

.card-stage__status {
  margin: 8px 0 0;
  color: #1f7a3a;
  font-size: 14px;
  line-height: 1.4;
}

.card-stage__status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: #2e9b4f;
  vertical-align: 0.05em;
}

.card-stage__download-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: max-content;
  max-width: 100%;
  gap: 6px;
}

.card-stage__download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-height: 44px;
  padding: 11px 18px;
  border: 0;
  border-radius: var(--tool-action-radius, 10px);
  background: linear-gradient(135deg, var(--tool-file-from, #34a853) 0%, var(--tool-file-via, #2d9248) 100%);
  color: #ffffff;
  box-shadow: var(--tool-file-shadow, 0 6px 14px rgba(52, 168, 83, 0.22));
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 20px;
  text-decoration: none;
  cursor: pointer;
}

.card-stage__download:hover,
.card-stage__download:focus-visible {
  background: linear-gradient(135deg, var(--tool-file-via, #2d9248) 0%, var(--tool-file-to, #267a3d) 100%);
  box-shadow: var(--tool-file-shadow-hover, 0 8px 18px rgba(52, 168, 83, 0.28));
  color: #ffffff;
}

.card-stage__download:disabled,
.card-stage__download:disabled:hover,
.card-stage__download:disabled:focus-visible {
  background: #d5dde8;
  color: #667588;
  box-shadow: none;
  cursor: not-allowed;
}

.card-stage__download-note {
  margin: 0;
  max-width: 14rem;
  color: var(--color-muted);
  font-size: 13px;
  line-height: 1.4;
  text-align: right;
}

.card-stage__viewer {
  border: 1px solid #d5e0ec;
  border-radius: 10px;
  background: #f3f7fb;
  overflow: hidden;
}

.card-stage__viewer-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}

.card-stage__viewer:has(.print-sheet) .card-stage__viewer-bar {
  display: flex;
}

.card-stage__format,
.card-stage__scroll-hint {
  margin: 0;
  color: #5c6b80;
  font-size: 13px;
  line-height: 1.3;
}

.card-stage__scroll-hint {
  display: none;
}

.card-stage__viewer[data-overflow="true"] .card-stage__scroll-hint {
  display: block;
}

.card-stage__canvas {
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 160px;
  margin: 0 10px 10px;
  padding: 16px 12px 20px;
  background: #e7eef6;
  border: 1px solid #d5e0ec;
  border-radius: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.card-stage:not([data-state="empty"]) .card-stage__canvas {
  height: clamp(420px, 70vh, 860px);
}

.card-stage__empty {
  max-width: 28rem;
  margin: 36px auto;
  text-align: center;
  color: var(--color-muted);
  font-size: 15px;
  line-height: 1.45;
}

.card-stage__empty p {
  margin: 0;
}

.card-stage__answers {
  margin-top: 20px;
}

.card-stage__answers-title {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 650;
  line-height: 1.3;
}

.card-stage__pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.card-stage__pager p {
  margin: 0;
  min-width: 8rem;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
}

.card-stage__pager button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.card-stage__pager button:hover,
.card-stage__pager button:focus-visible {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.card-stage__pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

.card-stage[data-state="stale"] .card-stage__status,
.card-stage[data-state="previous"] .card-stage__status,
.card-stage[data-state="error"] .card-stage__status {
  color: #8a5a12;
}

.card-stage[data-state="stale"] .card-stage__status::before,
.card-stage[data-state="previous"] .card-stage__status::before,
.card-stage[data-state="error"] .card-stage__status::before {
  background: #d0891f;
}

.card-stage[data-state="loading"] .card-stage__status {
  color: var(--color-muted);
}

.card-stage[data-state="loading"] .card-stage__status::before {
  background: var(--color-primary);
}

.card-stage[data-state="loading"] .card-stage__empty {
  display: none;
}

@media (max-width: 640px) {
  .card-builder {
    padding: 16px;
  }

  .card-builder__mode-options {
    grid-template-columns: 1fr;
  }

  .card-builder__count-grid {
    gap: 12px;
  }

  .card-stepper input {
    width: 44px;
  }

  .card-choice--mode > .card-mode-option {
    align-items: flex-start;
    text-align: left;
    padding: 12px;
  }

  .card-choice--mode .card-choice__note {
    display: block;
  }

  .card-builder__mode-hint {
    display: none;
  }

  .card-builder__action-buttons {
    flex-direction: column;
    align-items: stretch;
  }

  .card-builder__action-buttons > button {
    width: 100%;
  }

  .card-stage {
    padding: 16px;
  }

  .card-stage__head {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card-stage__head h2 {
    font-size: 18px;
  }

  .card-stage__download-wrap {
    align-items: stretch;
    width: 100%;
  }

  .card-stage__download {
    width: 100%;
  }

  .card-stage__download-note {
    max-width: none;
    text-align: left;
  }

  .card-stage:not([data-state="empty"]) .card-stage__canvas {
    height: clamp(280px, 60vh, 640px);
  }
}
