/* Интерактив «От данных к решению». Использует токены из site.css. */

.demo {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---------- статический пример (без JavaScript) ---------- */

.demo-static {
  display: grid;
  gap: 16px;
  padding: clamp(20px, 3vw, 32px);
}

.demo-static h2,
.demo-static h3 {
  font-size: 1.375rem;
}

.demo-static .badge {
  justify-self: start;
}

.static-path {
  display: grid;
  gap: 10px;
  padding-left: 1.4em;
  max-width: 76ch;
}

/* ---------- верхняя строка ---------- */

.demo-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 24px;
  align-items: center;
  padding: 18px clamp(16px, 2.4vw, 28px);
  border-bottom: 1px solid var(--line);
}

.demo-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.demo-name {
  font-size: 1.375rem;
}

.demo-object {
  color: var(--ink-2);
  font-size: 0.9375rem;
}

.demo-sample {
  grid-column: 1 / -1;
  justify-self: start;
  font: 600 0.875rem/1.3 var(--font-sans);
}

/* Переключатель объяснения — вторичный: без заливки акцентом, выбранное
   состояние видно по отметке, рамке и начертанию, а не только по цвету. */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}

.seg button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font: 500 0.9375rem/1.2 var(--font-sans);
  cursor: pointer;
}

.seg button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.seg-mark {
  display: none;
  flex: none;
  width: 10px;
  height: 6px;
  margin-top: -3px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

.seg button[aria-pressed="true"] {
  background: var(--surface-2);
  border-color: var(--ink);
  color: var(--ink);
  font-weight: 600;
}

.seg button[aria-pressed="true"] .seg-mark {
  display: block;
}

.demo-object .mono {
  white-space: nowrap;
}

/* До широкого экрана заголовок и переключатель идут друг под другом:
   на планшете рядом им тесно, и заголовок переносится. */
@media (max-width: 1023px) {
  .demo-top {
    grid-template-columns: minmax(0, 1fr);
  }
  .seg {
    justify-self: start;
  }
}

@media (max-width: 760px) {
  .seg {
    justify-self: stretch;
    display: flex;
  }
  .seg button {
    flex: 1 1 auto;
    justify-content: center;
    padding: 0 12px;
  }
}

/* ---------- шаги: один индикатор ---------- */

/* Телефон: ряд из шести номеров. Название и состояние шага читает диктор,
   видимое название стоит в заголовке шага ниже. */
.demo-steps {
  list-style: none;
  margin: 0;
  padding: 8px clamp(16px, 2.4vw, 28px);
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 4px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.demo-steps::before {
  content: "";
  position: absolute;
  top: 29px;
  left: calc(clamp(16px, 2.4vw, 28px) + 22px);
  right: calc(clamp(16px, 2.4vw, 28px) + 22px);
  height: 2px;
  background: var(--line);
}

.demo-steps li {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
}

.demo-steps button {
  width: 100%;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  grid-template-columns: auto;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  font: 500 0.9375rem/1.3 var(--font-sans);
  text-align: left;
  cursor: pointer;
}

.demo-steps .n {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 600;
}

.demo-steps .t,
.demo-steps .v {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.demo-steps button:hover:not(:disabled) {
  color: var(--ink);
}

.demo-steps button:hover:not(:disabled) .n {
  border-color: var(--ink);
}

.flow-node.is-done .n {
  border-color: var(--accent-text);
  color: var(--accent-text);
}

.flow-node.is-current .n {
  background: var(--accent-bg);
  border-color: var(--accent-bg);
  color: var(--on-accent);
}

/* Закрытый шаг не бледнеет до «сломанного»: пунктирная рамка и объяснение причины. */
.flow-node.is-locked button {
  cursor: not-allowed;
}

.flow-node.is-locked .n {
  border-style: dashed;
  background: var(--surface-2);
  color: var(--ink-2);
  font-weight: 500;
}

.flow-node.is-missing .v {
  color: var(--warn-text);
}

/* Планшет: сетка 3 × 2 с номерами и названиями шагов. То, что известно на шаге,
   видно с 1024 px: в узкой колонке планшета подпись распадалась по слову в строке. */
@media (min-width: 600px) {
  .demo-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 10px;
    padding-block: 12px;
  }
  .demo-steps::before {
    display: none;
  }
  .demo-steps button {
    grid-template-columns: 30px minmax(0, 1fr);
    align-items: center;
    justify-items: start;
    column-gap: 10px;
    row-gap: 1px;
    min-height: 52px;
    padding: 6px 10px;
  }
  .demo-steps .t {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
    white-space: normal;
    overflow-wrap: normal;
    hyphens: manual;
  }
  .demo-steps .t {
    color: var(--ink);
    font-weight: 600;
  }
  /* Текущий шаг отмечен заливкой и номером, а не рамкой цвета фокуса. */
  .flow-node.is-current button {
    background: var(--surface);
    border-color: var(--line-strong);
  }
  .flow-node.is-locked .t {
    color: var(--ink-2);
    font-weight: 500;
  }
}

/* ---------- тело: индикатор и шаг ---------- */

.demo-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 14px;
  min-width: 0;
  padding: 18px clamp(16px, 2.4vw, 28px) 22px;
}

/* Широкий экран: индикатор становится колонкой слева и показывает, что известно
   на каждом шаге, — так карточка не пустеет справа от короткого текста. */
@media (min-width: 1024px) {
  .demo-body {
    display: grid;
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  }
  .demo-steps {
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: 0;
    padding: 16px 14px;
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }
  .demo-steps button {
    position: relative;
    z-index: 1;
    grid-template-rows: auto auto;
    align-items: start;
    min-height: 64px;
    padding: 10px 12px;
  }
  .demo-steps .n {
    grid-row: 1 / span 2;
  }
  .demo-steps .v {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
    white-space: normal;
    overflow-wrap: normal;
    hyphens: manual;
    font-size: 0.875rem;
    line-height: 1.35;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
  }
  .flow-node.is-missing .v {
    color: var(--warn-text);
  }
  /* линия пути между номерами */
  .flow-node:not(:last-child)::after {
    content: "";
    position: absolute;
    left: 27px;
    top: 44px;
    bottom: -6px;
    width: 2px;
    background: var(--line-strong);
  }
  .flow-node.is-done:not(:last-child)::after {
    background: var(--accent-text);
  }
  .demo-stage {
    padding: 22px clamp(20px, 2.6vw, 36px) 26px;
  }
}

/* Шаг «Источники»: суммы двух источников за период. */
.sources {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 12px;
  max-width: 640px;
}

.source {
  display: grid;
  gap: 2px;
  padding: 14px 16px;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
}

.source-name {
  font-weight: 600;
}

.source-value {
  font-size: 1.5rem;
  line-height: 1.25;
}

.source-what {
  color: var(--ink-2);
  font-size: 0.9375rem;
}

.stage-count {
  font-size: 0.875rem;
  color: var(--ink-2);
}

.detail-h {
  font-size: clamp(1.375rem, 1.2rem + 0.6vw, 1.75rem);
  margin-top: -8px;
}

.detail-h:focus-visible {
  outline-offset: 6px;
}

.detail-lead {
  max-width: 68ch;
  color: var(--ink-2);
}

.facts {
  display: grid;
  grid-template-columns: minmax(120px, auto) minmax(0, 1fr);
  gap: 8px 18px;
  margin: 0;
  max-width: 760px;
}

.facts div {
  display: contents;
}

.facts dt {
  color: var(--ink-2);
}

.facts dd {
  margin: 0;
}

@media (max-width: 520px) {
  .facts {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
  .facts dd {
    margin-bottom: 8px;
  }
}

.more {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.more summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

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

.more summary::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s;
}

.more[open] summary::before {
  transform: rotate(45deg);
}

.more[open] {
  padding-bottom: 14px;
}

.more > :not(summary) {
  margin: 10px 14px 0;
}

.formula {
  font-size: 0.9375rem;
  font-weight: 500;
}

.table-scroll {
  overflow-x: auto;
}

.calc {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.calc th,
.calc td {
  padding: 10px 0 10px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}

.calc th:first-child,
.calc td:first-child {
  padding-left: 0;
  text-align: left;
}

.calc thead th {
  font: 500 0.875rem/1.3 var(--font-sans);
  color: var(--ink-2);
  vertical-align: bottom;
  border-bottom-color: var(--line-strong);
}

.calc tbody th,
.calc td {
  font-size: 0.9375rem;
  font-weight: 400;
}

.calc tr.total th,
.calc tr.total td {
  font-weight: 700;
  border-bottom: 0;
}

.calc .missing {
  font-weight: 600;
  color: var(--warn-text);
}

.alert {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--warn-line);
  border-radius: 10px;
  max-width: 760px;
}

.alert strong {
  color: var(--warn-text);
}

.big-line {
  font-size: clamp(1.25rem, 1.05rem + 0.7vw, 1.75rem);
  line-height: 1.3;
}

.weeks {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
}

.note {
  font-size: 0.875rem;
  color: var(--ink-2);
  max-width: 72ch;
}

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
}

.stage-actions .btn {
  min-height: 48px;
}

.decide-group,
.edit-options {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 10px;
}

.decide-group legend,
.edit-options legend {
  padding: 0;
  margin-bottom: 10px;
  font-weight: 600;
}

.decide {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 180px));
  gap: 10px;
}

.btn-choice {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line-strong);
  min-height: 52px;
}

.btn-choice:hover {
  border-color: var(--accent-text);
}

@media (max-width: 520px) {
  .decide {
    grid-template-columns: minmax(0, 1fr);
  }
}

.edit-options label {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  cursor: pointer;
}

.edit-options input {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent-bg);
}

.result {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  max-width: 760px;
}

.result-ok {
  border-color: var(--accent-text);
}

.text-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: 500 0.9375rem/1.2 var(--font-sans);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 0.22em;
  cursor: pointer;
}

.text-btn:hover:not(:disabled) {
  color: var(--ink);
}

.text-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  text-decoration: none;
}

.text-btn[aria-pressed="true"] {
  color: var(--warn-text);
  text-decoration-color: currentColor;
}

/* ---------- нижняя строка ---------- */

.demo-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 6px clamp(16px, 2.4vw, 28px);
  border-top: 1px solid var(--line);
}

.demo-foot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0 14px;
}

.demo-cta {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 600;
}

.demo-aux {
  display: grid;
  gap: 8px;
  padding: 0 clamp(16px, 2.4vw, 28px);
}

.demo-aux:has(.copy-status:empty):has(.copy-fallback[hidden]) {
  display: none;
}

.demo-aux .copy-status {
  padding-top: 4px;
}

.copy-fallback {
  display: grid;
  gap: 6px;
  padding-bottom: 16px;
}

.copy-fallback input {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: 0.9375rem var(--font-sans);
}
