/**
 * Маркетинговые калькуляторы — /tools/calc/*, /tools/utm-generator (#22072).
 * Токены home-v2 (--mg-*): тёмная тема приходит оттуда. Без теней и градиентов.
 * Самодостаточен: нужен и на /features (встройка), где tools-shell не грузится.
 */

.mg-calc,
.mg-calc * {
  box-sizing: border-box;
}

.mg-calc {
  margin-top: 28px;
  color: var(--mg-black, #000);
  font-family: inherit;
}

.mg-calc [hidden] {
  display: none !important;
}

/* —— карточка: поля слева, результат справа —— */
.mg-calc__box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  border: 1px solid var(--mg-border, #e3e5ea);
  border-radius: var(--mg-radius-ui, 4px);
  background: var(--mg-cream, #f2eeeb);
  overflow: hidden;
}

.mg-calc__main {
  display: grid;
  gap: 20px;
  align-content: start;
  min-width: 0;
  padding: clamp(18px, 3vw, 32px);
}

.mg-calc__res {
  min-width: 0;
  padding: clamp(18px, 3vw, 28px);
  background: var(--mg-white, #fff);
  border-left: 1px solid var(--mg-border, #e3e5ea);
}

.mg-calc__res-inner {
  display: grid;
  gap: 14px;
  align-content: start;
}

@media (min-width: 1024px) {
  .mg-calc__res-inner {
    position: sticky;
    top: 16px;
  }
}

/* —— режимы и пресеты —— */
.mg-calc__modes,
.mg-calc__presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}

.mg-calc__modes-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--mg-muted, #555);
}

.mg-calc__seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--mg-border, #e3e5ea);
  border-radius: var(--mg-radius, 3px);
  background: var(--mg-white, #fff);
}

.mg-calc__seg-btn,
.mg-calc__chip {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--mg-radius, 3px);
  background: transparent;
  color: var(--mg-black, #000);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  cursor: pointer;
}

.mg-calc__seg-btn[aria-pressed="true"] {
  background: var(--mg-black, #000);
  color: var(--mg-white, #fff);
}

.mg-calc__chip {
  border: 1px solid var(--mg-border, #e3e5ea);
  background: var(--mg-white, #fff);
}

.mg-calc__seg-btn:hover:not([aria-pressed="true"]),
.mg-calc__chip:hover {
  border-color: var(--mg-blue, #0263ad);
  color: var(--mg-blue-link, #0062ad);
}

.mg-calc__seg-btn:focus-visible,
.mg-calc__chip:focus-visible,
.mg-calc__act:focus-visible,
.mg-calc__input:focus-visible,
.mg-calc__cur select:focus-visible {
  outline: 2px solid var(--mg-blue, #0263ad);
  outline-offset: 2px;
}

/* —— поля —— */
.mg-calc__fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 20px;
}

.mg-calc--table .mg-calc__fields {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.mg-calc__field {
  min-width: 0;
}

.mg-calc__field--full {
  grid-column: 1 / -1;
}

.mg-calc__field label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.mg-calc__opt {
  margin-left: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--mg-muted, #555);
}

.mg-calc__inp {
  display: flex;
  align-items: center;
  min-height: 52px;
  border: 1px solid var(--mg-border, #e3e5ea);
  border-radius: var(--mg-radius, 3px);
  background: var(--mg-white, #fff);
}

.mg-calc__inp:focus-within {
  border-color: var(--mg-blue, #0263ad);
  box-shadow: 0 0 0 3px rgba(2, 99, 173, 0.18);
}

.mg-calc__input {
  flex: 1;
  min-width: 0;
  min-height: 50px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--mg-black, #000);
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.mg-calc__input::placeholder {
  color: var(--mg-muted, #555);
  opacity: 0.55;
  font-weight: 400;
}

.mg-calc__input:focus {
  outline: none;
}

.mg-calc__unit {
  padding-right: 14px;
  color: var(--mg-muted, #555);
  font-size: 15px;
  white-space: nowrap;
}

.mg-calc__hint {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.3;
  color: var(--mg-muted, #555);
}

.mg-calc--embed .mg-calc__hint {
  display: none;
}

.mg-calc__field.is-err .mg-calc__inp {
  border-color: #c8321e;
}

.mg-calc__field.is-err .mg-calc__hint {
  color: #c8321e;
}

.mg-calc__check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 15px;
  line-height: 1.35;
  cursor: pointer;
}

.mg-calc__check input {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
}

.mg-calc__formula {
  margin: 0;
  padding: 10px 14px;
  border: 1px dashed var(--mg-border, #e3e5ea);
  border-radius: var(--mg-radius, 3px);
  background: var(--mg-white, #fff);
  font-family: var(--mg-tool-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: 13px;
  line-height: 1.45;
  color: var(--mg-muted, #555);
  overflow-wrap: anywhere;
}

/* —— результат —— */
.mg-calc__res-label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mg-muted, #555);
}

.mg-calc__big {
  margin: 0;
  font-size: clamp(34px, 4.4vw, 48px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.mg-calc__big output {
  font: inherit;
}

.mg-calc__big .is-empty,
.mg-calc__url.is-empty {
  color: var(--mg-muted, #555);
  opacity: 0.55;
}

.mg-calc__per {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--mg-muted, #555);
}

.mg-calc__url {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--mg-border, #e3e5ea);
  border-radius: var(--mg-radius, 3px);
  background: var(--mg-cream, #f2eeeb);
  font-family: var(--mg-tool-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.mg-calc__interp {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
}

.mg-calc__interp:empty {
  display: none;
}

.mg-calc__interp.is-err {
  color: #c8321e;
  font-weight: 600;
}

.mg-calc__extras {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 16px;
  margin: 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--mg-border, #e3e5ea);
  font-size: 14px;
}

.mg-calc__extras dt {
  color: var(--mg-muted, #555);
}

.mg-calc__extras dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mg-calc__year {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.mg-calc__year:empty {
  display: none;
}

/* ориентир (конверсия) */
.mg-calc__bench {
  display: grid;
  gap: 8px;
}

.mg-calc__bench.is-off {
  display: none;
}

.mg-calc__bench-text {
  margin: 0;
  font-size: 13px;
  color: var(--mg-muted, #555);
}

.mg-calc__bar {
  --min: 10%;
  --max: 40%;
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--mg-border, #e3e5ea);
}

.mg-calc__bar::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--min);
  width: calc(var(--max) - var(--min));
  border-radius: 4px;
  background: var(--mg-blue, #0263ad);
  opacity: 0.45;
}

.mg-calc__bar i {
  position: absolute;
  top: -5px;
  width: 4px;
  height: 18px;
  margin-left: -2px;
  border-radius: 2px;
  background: var(--mg-black, #000);
  transition: left 0.2s ease;
}

/* действия */
.mg-calc__acts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.mg-calc__act {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--mg-border, #e3e5ea);
  border-radius: var(--mg-radius, 3px);
  background: var(--mg-white, #fff);
  color: var(--mg-black, #000);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  cursor: pointer;
}

.mg-calc__act:first-child {
  border-color: var(--mg-blue, #0263ad);
  background: var(--mg-blue, #0263ad);
  color: var(--mg-on-accent, #fff);
}

.mg-calc__act:hover {
  border-color: var(--mg-blue-hover, #2b8ed9);
}

.mg-calc__act:first-child:hover {
  background: var(--mg-blue-hover, #2b8ed9);
}

.mg-calc__cur select {
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--mg-border, #e3e5ea);
  border-radius: var(--mg-radius, 3px);
  background: var(--mg-white, #fff);
  color: var(--mg-black, #000);
  font: inherit;
  font-size: 15px;
}

.mg-calc__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.mg-calc__toast {
  min-height: 20px;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #1f8a4c;
}

.mg-calc__trg-cta {
  justify-self: start;
  background: var(--mg-blue, #0263ad);
  border-color: var(--mg-blue, #0263ad);
  color: var(--mg-on-accent, #fff);
}

/* —— таблица сценариев (триггеры): поля на всю ширину, ниже таблица и результат —— */
.mg-calc--table .mg-calc__box {
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas:
    "fields fields"
    "formula formula"
    "table res";
}

.mg-calc--table .mg-calc__main {
  display: contents;
}

.mg-calc--table .mg-calc__fields {
  grid-area: fields;
  padding: clamp(18px, 3vw, 32px) clamp(18px, 3vw, 32px) 0;
}

.mg-calc--table .mg-calc__formula {
  grid-area: formula;
  margin: 18px clamp(18px, 3vw, 32px) 0;
}

.mg-calc--table .mg-calc__table-wrap {
  grid-area: table;
  padding: 24px clamp(18px, 3vw, 32px) clamp(18px, 3vw, 32px);
}

.mg-calc--table .mg-calc__res {
  grid-area: res;
  margin-top: 24px;
  border-top: 1px solid var(--mg-border, #e3e5ea);
}

.mg-calc__table-wrap {
  min-width: 0;
  overflow-x: auto;
}

.mg-calc__table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.mg-calc__caption {
  padding: 0 0 10px;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: var(--mg-muted, #555);
}

.mg-calc__table th,
.mg-calc__table td {
  padding: 12px 8px;
  border-top: 1px solid var(--mg-border, #e3e5ea);
  text-align: right;
}

.mg-calc__table thead th {
  border-top: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--mg-muted, #555);
}

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

.mg-calc__table tbody th {
  font-weight: 700;
}

.mg-calc__table .is-key {
  font-weight: 700;
  color: var(--mg-blue-link, #0062ad);
}

.mg-calc__assume {
  margin-top: 12px;
  font-size: 14px;
  color: var(--mg-muted, #555);
}

.mg-calc__assume summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--mg-black, #000);
}

.mg-calc__assume p {
  margin: 8px 0 0;
  line-height: 1.5;
}

/* на /features: белая карточка на кремовой секции */
.mg-calc--embed {
  margin-top: 0;
}

.mg-calc--embed .mg-calc__box {
  background: var(--mg-white, #fff);
}

.mg-calc--embed .mg-calc__formula {
  display: none;
}

.mg-calc--embed .mg-calc__res {
  background: var(--mg-cream, #f2eeeb);
}

/* —— SEO-блок страницы —— */
.mg-calc__seo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: clamp(24px, 4vw, 56px);
  align-items: start;
}

.mg-calc__seo-body {
  max-width: 760px;
  font-size: 17px;
  line-height: 1.55;
}

.mg-calc__seo-body h2 {
  margin: 34px 0 12px;
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.04em;
  scroll-margin-top: 80px;
}

.mg-calc__seo-body > .mg-calc__about + h2 {
  margin-top: 28px;
}

.mg-calc__seo-body p {
  margin: 0 0 12px;
}

.mg-calc__about {
  font-size: 19px;
  font-weight: 600;
}

.mg-calc__eq {
  display: inline-block;
  max-width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--mg-border, #e3e5ea);
  border-radius: var(--mg-radius, 3px);
  background: var(--mg-white, #fff);
  font-family: var(--mg-tool-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.mg-calc__ex {
  padding: 4px 0 4px 16px;
  border-left: 3px solid var(--mg-blue, #0263ad);
}

.mg-calc__muted {
  font-size: 15px;
  color: var(--mg-muted, #555);
}

.mg-calc__seo-body ul {
  margin: 0 0 12px;
  padding-left: 22px;
}

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

.mg-calc__seo-body code {
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

.mg-calc__toc {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 4px;
  font-size: 15px;
}

.mg-calc__toc-title {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mg-muted, #555);
}

.mg-calc__toc a {
  padding: 4px 0;
  color: var(--mg-blue-link, #0062ad);
}

/* —— карточки (хаб и «другие калькуляторы») —— */
.mg-calc__tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mg-calc__tile {
  position: relative;
  display: grid;
  gap: 8px;
  align-content: start;
  height: 100%;
  min-height: 150px;
  padding: 20px;
  border: 1px solid var(--mg-border, #e3e5ea);
  border-radius: var(--mg-radius-ui, 4px);
  background: var(--mg-white, #fff);
  color: var(--mg-black, #000);
  text-decoration: none;
}

.mg-calc__tile:hover,
.mg-calc__tile:focus-visible {
  border-color: var(--mg-blue, #0263ad);
  color: var(--mg-black, #000);
}

.mg-calc__tile-tag {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--mg-radius, 3px);
  background: rgba(2, 99, 173, 0.1);
  color: var(--mg-blue-link, #0062ad);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.mg-calc__tile-name {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.mg-calc__tile-lead {
  font-size: 14px;
  line-height: 1.35;
  color: var(--mg-muted, #555);
}

.mg-calc__tile-new {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(31, 138, 76, 0.14);
  color: #1f8a4c;
  font-size: 12px;
  font-weight: 700;
}

/* —— узкие экраны —— */
@media (max-width: 960px) {
  .mg-calc__box,
  .mg-calc--table .mg-calc__box {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-calc--table .mg-calc__box {
    grid-template-areas:
      "fields"
      "formula"
      "table"
      "res";
  }

  .mg-calc--table .mg-calc__res {
    margin-top: 0;
  }

  .mg-calc__res {
    border-top: 1px solid var(--mg-border, #e3e5ea);
    border-left: 0;
  }

  .mg-calc--table .mg-calc__fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mg-calc__seo {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-calc__toc {
    display: none;
  }
}

/* таблица триггеров превращается в карточки сценариев */
@media (max-width: 640px) {
  .mg-calc__fields,
  .mg-calc--table .mg-calc__fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-calc__table {
    min-width: 0;
  }

  .mg-calc__caption {
    display: block;
    width: 100%;
  }

  .mg-calc__table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .mg-calc__table,
  .mg-calc__table tbody,
  .mg-calc__table tr,
  .mg-calc__table th,
  .mg-calc__table td {
    display: block;
    width: 100%;
  }

  .mg-calc__table tr {
    margin-bottom: 12px;
    padding: 12px 14px;
    border: 1px solid var(--mg-border, #e3e5ea);
    border-radius: var(--mg-radius, 3px);
    background: var(--mg-white, #fff);
  }

  .mg-calc__table th,
  .mg-calc__table td {
    padding: 4px 0;
    border: 0;
    text-align: left;
  }

  .mg-calc__table tbody th {
    margin-bottom: 4px;
    font-size: 16px;
  }

  .mg-calc__table td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }

  .mg-calc__table td::before {
    content: attr(data-label);
    color: var(--mg-muted, #555);
  }

  .mg-calc__acts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mg-calc__act:first-child {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mg-calc__bar i {
    transition: none;
  }
}
