/* PP-OPO generator (paperwork/dividends) — a four-step wizard:
   Загрузка → Проверка → Расчёт → Готово. Lives inside the white .main-content
   card, so panels are transparent and the inner blocks (drop-zone, table, calc,
   next-steps) carry the visual weight. */

.ppopo {
  margin: 8px 0 12px;
}

.wizard {
  min-width: 0;
}

/* Component display rules (flex/grid/block) outrank the UA `[hidden]` rule, so
   make `hidden` authoritative everywhere inside the wizard. */
.wizard [hidden] {
  display: none !important;
}

/* ===== Stepper ========================================================== */
.stepper {
  display: flex;
  align-items: center;
  list-style: none;
  margin: 4px 0 30px;
  padding: 0;
}

.stepper__item {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  color: var(--muted-2);
}

.stepper__item:not(:last-child) {
  flex: 1 1 auto;
}

/* Connector line to the next step. */
.stepper__item:not(:last-child)::after {
  content: "";
  flex: 1 1 auto;
  height: 2px;
  min-width: 16px;
  margin-left: 12px;
  background: var(--border);
  transition: background-color 0.2s ease;
}

.stepper__num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  background: var(--fill);
  color: var(--muted-2);
  font-size: 14px;
  font-weight: 700;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.stepper__label {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.stepper__item.is-active .stepper__num,
.stepper__item.is-done .stepper__num {
  background: var(--brand);
  color: #fff;
}

.stepper__item.is-active,
.stepper__item.is-done {
  color: var(--text);
}

.stepper__item.is-active .stepper__label {
  font-weight: 700;
}

.stepper__item.is-done::after {
  background: var(--brand);
}

.stepper__item.is-final .stepper__num {
  background: var(--success);
}

.stepper__item.is-final .stepper__label {
  color: var(--success);
}

@media (max-width: 640px) {
  .stepper__label {
    display: none;
  }
  .stepper__item:not(:last-child)::after {
    margin-left: 0;
  }
}

/* ===== Panels & shared bits ============================================= */
.wizard__panel {
  min-width: 0;
}

.wizard__panel[hidden] {
  display: none;
}

.wizard__panel--center {
  text-align: center;
}

.wizard__title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0 0 6px;
}

.wizard__lead {
  font-size: 15px;
  line-height: 1.55;
  color: var(--muted);
  margin: 0 0 22px;
}

.wizard__lead--center {
  max-width: 470px;
  margin: 0 auto 26px;
}

.wizard__section {
  margin-top: 22px;
}

.wizard__section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 14px;
}

.wizard__note {
  margin: 22px 0 0;
  padding: 15px 18px;
  text-align: left;
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius);
}

.wizard__note p {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-2);
}

/* Collapsible help / caveat embedded in a step (Где взять…, Известные
   ограничения). Folded away by default so the step stays clean. */
.wizard__details {
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.wizard__details > summary {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  list-style: none;
}

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

/* Chevron that rotates open. */
.wizard__details > summary::before {
  content: "›";
  font-size: 17px;
  line-height: 1;
  color: var(--muted-2);
  transition: transform 0.16s ease;
}

.wizard__details[open] > summary::before {
  transform: rotate(90deg);
}

.wizard__details-body {
  padding: 0 16px 15px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
}

.wizard__details-body p {
  margin: 0 0 10px;
}

.wizard__details-body p:last-child {
  margin-bottom: 0;
}

.wizard__details-body ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.wizard__details-body li {
  margin-bottom: 6px;
}

.wizard__details-body li:last-child {
  margin-bottom: 0;
}

/* Action rows. */
.wizard__actions {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 28px;
  flex-wrap: wrap;
}

.wizard__actions--end {
  justify-content: flex-end;
}

.wizard__actions--center {
  justify-content: center;
}

/* ===== Buttons ========================================================== */
.wizard .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 26px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  border-radius: 11px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.16s ease, background-color 0.16s ease, border-color 0.16s ease;
}

.wizard .btn--primary {
  background: var(--brand);
  color: #fff;
}

.wizard .btn--primary:hover {
  filter: brightness(1.07);
}

.wizard .btn--ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.wizard .btn--ghost:hover {
  border-color: var(--muted-2);
}

.wizard .btn--dark {
  background: var(--ink);
  color: #fff;
}

.wizard .btn--dark:hover {
  filter: brightness(1.15);
}

/* ===== Drop zone (step 1) ============================================== */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  border: 2px dashed var(--border-dashed);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.16s ease, background-color 0.16s ease;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.drop-zone.invalid {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.drop-zone.file-selected {
  border-style: solid;
  border-color: var(--brand);
  background: var(--brand-soft);
}

.drop-zone__input {
  display: none;
}

.drop-zone__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 24px;
  font-weight: 700;
}

.drop-zone.file-selected .drop-zone__icon {
  background: #fff;
}

.drop-zone__label {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  pointer-events: none;
}

.drop-zone__hint {
  margin-top: 5px;
  font-size: 14px;
  color: var(--muted-2);
  pointer-events: none;
}

/* Personal-data fields (step 1) use the shared .field-grid / .field / .field__label
   primitives (application.css). */

.form-hint {
  display: block;
  margin-top: 7px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted-2);
}

/* A hint that introduces a section (right under its title) needs room below it
   before the fields, not the tight top gap a field-level hint carries. */
.wizard__section-title + .form-hint {
  margin: 0 0 16px;
}

/* The taxpayer-profile picker keeps its own component styles (profiles.css); it
   sits in a .wizard__section, which supplies the surrounding spacing. */

/* ===== Review table (step 2) ========================================== */
.review {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.review__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.review__table thead th {
  padding: 12px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-2);
  background: var(--surface-2);
}

.review__table th.num,
.review__table td.num {
  text-align: right;
}

.review__table tbody td {
  padding: 13px 14px;
  border-top: 1px solid var(--border);
  color: var(--text);
}

/* Each dividend (with its optional withholding sub-row) is its own <tbody>, so
   the zebra striping and the divider go per-group — a dividend and the tax held
   on it never land in different stripes. */
.review__table tbody:nth-of-type(even) {
  background: var(--surface-2);
}

.review__table td.ticker {
  font-weight: 600;
}

.review__table td.rate,
.review__table td.num {
  font-family: var(--mono);
  font-size: 13px;
}

/* Withholding sub-row: muted and tucked under its dividend (no divider between
   the two — the divider sits above the dividend). */
.review__table .review__subrow td {
  border-top: 0;
  padding-top: 2px;
  color: var(--muted-2);
  font-size: 12px;
}

.review__table .review__subrow td.sublabel {
  font-weight: 400;
  font-style: italic;
}

/* ===== Calc summary (step 3) ========================================== */
.calc {
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 22px 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.calc__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  font-size: 15px;
  color: var(--muted);
}

/* A display rule on the row would otherwise beat the `hidden` attribute. */
.calc__row[hidden] {
  display: none;
}

.calc__val {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.calc__val--minus {
  color: var(--success);
}

.calc__sep {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

.calc__row--total {
  font-size: 19px;
  font-weight: 800;
  color: var(--text);
}

.calc__row--total .calc__val {
  font-size: 19px;
  font-weight: 800;
  color: var(--success);
}

.calc__row--kamata .calc__val {
  color: var(--danger);
}

/* ===== Done (step 4) ================================================== */
.wizard__check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  margin: 4px auto 16px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success);
  font-size: 30px;
  font-weight: 700;
}

.next-steps {
  text-align: left;
  margin: 30px 0 26px;
  padding: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.next-steps__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
}

.next-steps__list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.next-steps__list li {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-2);
}

/* ===== Alert + loading ================================================ */
.wizard__alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 22px;
  padding: 14px 16px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
}

.wizard__alert[hidden] {
  display: none;
}

.wizard__alert-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.wizard__alert p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--danger);
}

.wizard__alert-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wizard__alert-hint {
  font-size: 13px;
  font-weight: 600;
}

/* Step 1 after a server/processing error: dimmed and inert, so the document
   can't be re-uploaded and "Рассчитать" can't be pressed again. The one way
   back is a page reload (see .wizard__alert-hint). */
.wizard__panel.is-blocked {
  opacity: 0.55;
  pointer-events: none;
}

.wizard__loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 24px;
}

.wizard__loading p {
  margin-top: 18px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--muted);
}

.wizard__spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid var(--brand-soft);
  border-top-color: var(--brand);
  animation: wizard-spin 0.8s linear infinite;
}

@keyframes wizard-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== Signed-out nudge =============================================== */
.ppopo .signin-nudge p {
  text-align: left;
  margin-bottom: 0;
}

/* ===== Responsive ===================================================== */
@media (max-width: 640px) {
  /* .field-grid stacks via the shared rule in application.css. */

  .wizard__actions {
    flex-direction: column-reverse;
  }

  .wizard__actions .btn {
    width: 100%;
  }

  /* ===== Review table → stacked cards (step 2) ========================
     Five/six columns don't fit a phone, so each group folds into a card:
     the ticker (or a sub-row's note) heads it, and every other cell drops
     onto its own line prefixed with the column name (from data-label),
     value pushed to the right edge so all values line up. */
  .review__table {
    display: block;  /* stop the table box from sizing to content and overflowing */
  }

  .review__table thead {
    display: none;
  }

  .review__table tbody {
    display: block;
    padding: 6px 0 12px;
  }

  .review__table tbody + tbody {
    border-top: 1px solid var(--border);
  }

  .review__table tr {
    display: flex;
    flex-direction: column;
  }

  .review__table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 2px 16px;
    border-top: 0;
    text-align: right;
  }

  .review__table tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted-2);
  }

  /* Blank cells (e.g. the date on a withholding sub-row) carry no value —
     drop them rather than print a lone label. */
  .review__table tbody td:empty {
    display: none;
  }

  /* The ticker heads its card; the sub-row's note heads its block. Pull both
     to the top, span the full width, and drop the column-name prefix — they
     ARE the heading, not a labelled value. */
  .review__table td.ticker,
  .review__table .review__subrow td.sublabel {
    order: -1;
    display: block;
    text-align: left;
    padding-top: 8px;
    padding-bottom: 3px;
  }

  .review__table td.ticker {
    font-size: 15px;
  }

  .review__table td.ticker::before,
  .review__table .review__subrow td.sublabel::before {
    content: none;
  }
}
