/* 9g · Страница калькуляторов /baza/kalkulyatory/.
   Подключается после style.css, knowledge.css и article.css.

   Интерфейс — таблицы. Три решения, на которых держится вёрстка:
   1. Размеры ведутся переменными --t-*: на узком экране ужимается вся
      таблица разом, а не отдельные куски, поэтому строки не разъезжаются.
   2. Шапка липнет к верху своей коробки (top: 0), а не к шапке сайта.
      Внутри overflow-контейнера sticky отсчитывается от коробки, и top со
      значением высоты хедера просто сдвигал шапку вниз, на данные.
   3. Подписи столбцов переносятся по словам. Обрезанное многоточием
      «Из них целе…» — это потеря смысла, а не экономия места. */

.tools-hero { padding: 32px var(--gutter) 0; }
.tools-hero .h1 { margin-top: 20px; max-width: 20ch; }
.tools-hero__lead { margin-top: 20px; max-width: 62ch; color: var(--muted); text-wrap: pretty; }
.tools-hero__meta { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px 20px; color: var(--muted); }

/* Оглавление: четыре инструмента страницы */
.tool-toc { margin-top: 32px; border-top: 1px solid var(--ink); }
.tool-toc__list { display: grid; grid-template-columns: 1fr; }
.tool-toc a { display: grid; grid-template-columns: 2.5rem 1fr; gap: 12px; align-items: baseline; padding: 14px 0; border-bottom: 1px solid var(--line); }
.tool-toc a:hover .tool-toc__name { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; }
.tool-toc a.is-on .tool-toc__n { color: var(--ink); }
.tool-toc__n { font: 400 14px/20px var(--sans); color: var(--muted-2); letter-spacing: .08em; }
.tool-toc__name { font: 600 17px/24px var(--sans); }
.tool-toc__desc { grid-column: 2; font: 400 14px/20px var(--sans); color: var(--muted); }

/* ---------- Блок одного инструмента ---------- */

.tool { padding: 44px var(--gutter); border-top: 1px solid var(--line); }
.tool:first-of-type { border-top: 0; }
.tool--paper { background: var(--paper); }
.tool__head { max-width: 62ch; }
.tool__head .h2 { margin-top: 10px; }
.tool__lead { margin-top: 14px; color: var(--muted); text-wrap: pretty; }
.tool__head + .tool__scroll, .tool__head + .tool__pair { margin-top: 24px; }

/* ---------- Размеры таблицы ---------- */
/* Один набор переменных на всю страницу: шрифт значений, высота строки,
   боковые поля ячейки, шрифт подписей. Растут тремя ступенями вместе
   с шириной контейнера (20px гаттера до 1024px, 80px после). */

.tool__table {
  --t-fs: 13px;      /* значения */
  --t-lh: 18px;
  --t-h: 42px;       /* высота строки */
  --t-pad: 8px;      /* боковые поля ячейки */
  --t-head: 10px;    /* подписи столбцов */
  --t-hls: .05em;    /* разрядка подписей */
  --t-grp: 28px;     /* строка «вы вводите / страница считает» */
  --t-hint: 12px;    /* пояснения в третьем столбце */
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-variant-numeric: lining-nums tabular-nums;
  border-top: 1px solid var(--ink);
}

/* ---------- Коробка таблицы ---------- */
/* Прокрутка вбок для широких таблиц и вниз — для длинных: без своей
   коробки липкая шапка работать не может. Высота ограничивается только
   на длинном списке каналов, короткие таблицы живут в потоке страницы. */

.tool__scroll {
  overflow: auto; -webkit-overflow-scrolling: touch;
  max-height: 560px;
  max-height: max(420px, calc(100svh - var(--header-h) - 132px));
  overscroll-behavior: contain;
  /* тень у края подсказывает, что таблица прокручивается вбок */
  background:
    linear-gradient(to right, var(--white) 30%, rgba(255,255,255,0)) left center,
    linear-gradient(to left, var(--white) 30%, rgba(255,255,255,0)) right center,
    radial-gradient(farthest-side at 0 50%, rgba(11,11,12,.14), rgba(11,11,12,0)) left center,
    radial-gradient(farthest-side at 100% 50%, rgba(11,11,12,.14), rgba(11,11,12,0)) right center;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}
.tool--paper .tool__scroll {
  background-image:
    linear-gradient(to right, var(--paper) 30%, rgba(248,248,250,0)),
    linear-gradient(to left, var(--paper) 30%, rgba(248,248,250,0)),
    radial-gradient(farthest-side at 0 50%, rgba(11,11,12,.14), rgba(11,11,12,0)),
    radial-gradient(farthest-side at 100% 50%, rgba(11,11,12,.14), rgba(11,11,12,0));
}

/* ---------- Шапка ---------- */

.tool__table thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--white); padding: 8px var(--t-pad) 7px;
  font: 400 var(--t-head)/13px var(--sans); letter-spacing: var(--t-hls);
  text-transform: uppercase; color: var(--muted);
  text-align: right; vertical-align: bottom; white-space: normal; overflow-wrap: anywhere;
  border-bottom: 1px solid var(--ink); border-right: 1px solid var(--line);
}
.tool--paper .tool__table thead th { background: var(--paper); }
.tool__table thead th:first-child { text-align: left; }
.tool__table thead th:last-child { border-right: 0; }

/* Надстрочная строка: что заполняет человек, что считает страница */
.tool__table .tool__table-group th, .tool__table .tool__table-group td {
  position: sticky; top: 0; z-index: 3;
  height: var(--t-grp); padding: 0 var(--t-pad);
  background: var(--white); border-bottom: 1px solid var(--line); border-right: 0;
  font: 400 var(--t-head)/13px var(--sans); letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted-2); text-align: center; white-space: nowrap;
}
.tool--paper .tool__table .tool__table-group th, .tool--paper .tool__table .tool__table-group td { background: var(--paper); }
/* Вторая строка шапки липнет ровно под первой — высота взята из той же
   переменной, что задаёт первую, поэтому они не могут разъехаться. */
.tool__table--channels thead tr:last-child th { top: var(--t-grp); }

/* ---------- Строки ---------- */

.tool__table tbody tr:nth-child(odd) { background: var(--white); }
.tool__table tbody tr:nth-child(even) { background: var(--paper); }
.tool--paper .tool__table tbody tr:nth-child(odd) { background: var(--paper); }
.tool--paper .tool__table tbody tr:nth-child(even) { background: var(--white); }
.tool__table tbody tr:hover { background: #EFEFF2; }

.tool__table td, .tool__table tbody th, .tool__table tfoot th {
  vertical-align: middle;
}
.tool__table td, .tool__table tbody th {
  height: var(--t-h); padding: 5px var(--t-pad);
  border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
  text-align: right; font: 500 var(--t-fs)/var(--t-lh) var(--sans); color: var(--ink);
}
.tool__table td:last-child, .tool__table tbody th:last-child { border-right: 0; }
.tool__table tbody th[scope="row"] { text-align: left; font-weight: 600; text-wrap: pretty; }

/* Первый столбец держится на месте при прокрутке вбок */
.tool__table tbody th[scope="row"], .tool__table tfoot th[scope="row"] {
  position: sticky; left: 0; z-index: 2; background: inherit;
}
.tool__table thead th:first-child, .tool__table .tool__table-group td:first-child { position: sticky; left: 0; z-index: 4; }
/* У строки итогов фон задан ячейкам, а не строке: inherit дал бы прозрачность,
   и при прокрутке вбок под «Итого» поехали бы цифры. */
.tool__table tfoot th[scope="row"] { background: var(--ink); }

/* ---------- Ячейки, которые заполняет человек ---------- */

/* Селекторы с тегом: у .tool__table td вес выше, чем у одного класса,
   и padding: 0 на ячейке с полем ввода иначе не срабатывает.
   Подчёркивание нарисовано на ячейке, а не на поле: в высокой строке
   (на телефоне пояснение занимает четыре строки) подчёркивание поля
   повисало посреди ячейки отдельной серой полосой. */
.tool__table .is-in, .tool__table th.tool__table-name, .tool__table td.tool__table-del { padding: 0; }
.tool__table .is-in, .tool__table th.tool__table-name { box-shadow: inset 0 -2px 0 var(--line); }
.tool__table .is-in:hover, .tool__table th.tool__table-name:hover { box-shadow: inset 0 -2px 0 var(--muted-light); }
.tool__table .is-in:focus-within, .tool__table th.tool__table-name:focus-within { box-shadow: inset 0 -2px 0 var(--ink); }
.tool__table .is-in input, .tool__table .tool__table-name input {
  display: block; width: 100%; height: calc(var(--t-h) - 4px); padding: 0 var(--t-pad);
  border: 0; background: none; border-radius: 0; appearance: none; box-shadow: none;
  font: 500 var(--t-fs)/var(--t-lh) var(--sans); color: var(--ink); text-align: right;
  font-variant-numeric: lining-nums tabular-nums;
}
.tool__table .is-in input::placeholder { color: var(--muted-light); }
.tool__table .is-in input:focus { outline: none; }
.tool__table .is-in input:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.tool__table .tool__table-name input { text-align: left; font-weight: 600; }
.tool__table .is-empty { color: var(--muted-2); }

/* ---------- Считаемые значения ---------- */

.tool__table td[data-o] { color: var(--ink); }
.tool__table td[data-o].is-bad { color: var(--muted-2); }
.tool__table tr.is-key td[data-o] { font: 400 calc(var(--t-fs) + 4px)/calc(var(--t-lh) + 4px) var(--serif); }
.tool__table tr.is-best th[scope="row"] { box-shadow: inset 3px 0 0 var(--ink); }
.tool__table tr.is-worst th[scope="row"] { box-shadow: inset 3px 0 0 var(--muted-light); }
.tool__table tr.is-worst td { background: rgba(11, 11, 12, .04); }

/* Пояснение: единственный столбец, где текст набран как текст */
.tool__table td.tool__table-hint {
  text-align: left; white-space: normal; text-wrap: pretty;
  font: 400 var(--t-hint)/calc(var(--t-hint) + 6px) var(--sans); color: var(--muted);
}

/* ---------- Итоги ---------- */

.tool__table tfoot th, .tool__table tfoot td {
  background: var(--ink); color: var(--white); border-bottom: 0;
  border-right: 1px solid var(--line-dark); height: calc(var(--t-h) + 6px); padding: 6px var(--t-pad);
  text-align: right; font: 600 var(--t-fs)/var(--t-lh) var(--sans);
}
.tool__table tfoot th[scope="row"] { text-align: left; }
/* Ячейка во всю ширину под итогом — это фраза, а не колонка цифр */
.tool__table tfoot td[colspan] { text-align: left; white-space: normal; }
.tool__table tfoot td:last-child { border-right: 0; }
.tool__table tfoot td[data-o], .tool__table tfoot b { color: var(--white); }
.tool__table tfoot td[data-o].is-bad { color: var(--muted-light); }
.tool__table tfoot .is-in { box-shadow: inset 0 -2px 0 var(--line-dark); }
.tool__table tfoot .is-in:hover, .tool__table tfoot .is-in:focus-within { box-shadow: inset 0 -2px 0 var(--white); }
.tool__table tfoot .is-in input { color: var(--white); }
.tool__table tfoot .is-empty { color: var(--muted-2); }
/* Строка-подпись под итогом: это фраза, а не цифра, — переносится по словам */
.tool__table tfoot .tool__table-sub td { text-align: left; white-space: normal; font-weight: 400; color: var(--muted-light); }
.tool__table-sub b { color: var(--white); font-weight: 600; }

/* ---------- Таблица каналов: двенадцать столбцов ---------- */
/* Ширина каждого столбца равна его подписи: подпись не переносится и не
   обрезается. Числа ниже — измеренная ширина текста подписи (10px, разрядка
   .03em) или значения в ячейке (14px), смотря что шире, плюс поля 10+10;
   у столбцов с полем ввода — ещё несколько пикселей: поле резервирует место
   под курсор, и текст в нём начинает ползти раньше, чем кончается ячейка.
   Отсюда два следствия:
   1. Кегль таблицы зафиксирован — он задан на двух классах сразу, чтобы
      ступени размеров из медиавыражений ниже его не перебивали. Поедет
      кегль — поедут и ширины, посчитанные под него.
   2. Таблица не ужимается: её минимум 1015px. На окне от 1180px она влезает
      целиком, на узком — прокручивается вбок внутри своей коробки. Это цена
      подписей в одну строку, и она заплачена сознательно. */

.tool__table.tool__table--channels {
  --t-fs: 14px; --t-lh: 20px; --t-h: 44px; --t-pad: 10px;
  --t-head: 10px; --t-hls: .03em; --t-grp: 30px;
  table-layout: fixed; min-width: 1015px;
}
.tool__table--channels thead th { white-space: nowrap; overflow-wrap: normal; }
.tool__table--channels td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tool__col--name   { width: 127px; }  /* «Яндекс Директ» — 104 */
.tool__col--spend  { width: 96px; }   /* «Расход, ₽» — 55, но сумма в итоге семизначна */
.tool__col--leads  { width: 88px; }   /* «Обращений» — 68 */
.tool__col--qual   { width: 74px; }   /* «Целевых» — 50, значение до пяти цифр */
.tool__col--deals  { width: 63px; }   /* «Сделок» — 43 */
.tool__col--avg    { width: 96px; }   /* «Чек, ₽» — 34, но чек бывает семизначным */
.tool__col--margin { width: 73px; }   /* «Маржа, %» — 53 */
.tool__col--cpl    { width: 100px; }  /* «Обращение, ₽» — 80 */
.tool__col--cpql   { width: 90px; }   /* «Целевое, ₽» — 62, значение до 70 */
.tool__col--cpo    { width: 90px; }   /* «Сделка, ₽» — 56, значение до 70 */
.tool__col--romi   { width: 76px; }   /* «ROMI, %» — 41, значение до шести знаков */
.tool__col--del    { width: 42px; }   /* подпись скрыта, ширину задаёт кнопка */

/* ширина колонки задана в colgroup, кнопка центрируется в ней */
.tool__table td.tool__table-del { text-align: center; }
.tool__table-del button {
  width: 28px; height: 28px; border: 1px solid var(--line); background: none;
  color: var(--muted); font: 400 16px/1 var(--sans); cursor: pointer; border-radius: 0;
}
.tool__table-del button:hover { border-color: var(--ink); color: var(--ink); }
.tool__table tbody tr:only-child .tool__table-del button { display: none; }

/* ---------- Воронка: семь столбцов ---------- */

.tool__table--wide { table-layout: fixed; min-width: 680px; }
.tool__table--wide col:first-child { width: 22%; }
.tool__table--wide .tool__col-in { width: 13%; }
.tool__table--wide .tool__col-out { width: 12%; }
/* последний <col> стоит со span="2": 14% достаются обоим правым столбцам */
.tool__table--wide col:last-child { width: 14%; }
.tool__table--wide tbody th[scope="row"] { white-space: normal; }

/* ---------- Пара «вы вводите» / «страница считает» ---------- */

.tool__pair { display: grid; gap: 28px; }
.tool__pair .tool__table { table-layout: fixed; }
/* На телефоне столбец значения шире: «306 818 ₽» крупным шрифтом
   в 26% ширины не помещалось. */
.tool__pair .tool__table th[scope="col"]:first-child, .tool__pair .tool__table tbody th[scope="row"] { width: 38%; }
.tool__pair .tool__table th[scope="col"]:nth-child(2) { width: 30%; }
.tool__table caption {
  caption-side: top; text-align: left; padding: 0 0 8px;
  font: 500 12px/16px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}
.tool__table--res tbody th[scope="row"] { font-weight: 400; }
.tool__table--res tr.is-key { background: var(--ink) !important; }
.tool__table--res tr.is-key th, .tool__table--res tr.is-key td { color: var(--white); border-right-color: var(--line-dark); }
.tool__table--res tr.is-key .tool__table-hint { color: var(--muted-light); }
.tool__table--res tr.is-key td[data-o].is-bad { color: var(--muted-light); }

/* ---------- Ответ, кнопки, сноска ---------- */
/* Кнопки под таблицей — это панель инструмента, а не призыв к действию:
   у общего .btn поля 18/24 и кегль 16, четыре таких подряд перевешивают
   саму таблицу. */

.tool__verdict {
  margin-top: 16px; padding: 12px 16px; background: var(--paper);
  border-left: 3px solid var(--muted-light);
  font: 400 15px/22px var(--sans); color: var(--muted); text-wrap: pretty;
}
.tool--paper .tool__verdict { background: var(--white); }
.tool__verdict--ok { border-left-color: var(--ink); color: var(--ink); }
.tool__verdict--bad { border-left-color: var(--ink); color: var(--ink); font-weight: 600; }

.tool__actions { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.tool__actions .btn { font: 600 14px/20px var(--sans); padding: 10px 16px; }

.tool__note {
  margin-top: 20px; max-width: 78ch; padding-top: 14px; border-top: 1px solid var(--line);
  font: 400 14px/21px var(--sans); color: var(--muted); text-wrap: pretty;
}
.tool__note b { color: var(--ink); }
.tool__note a { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.tool__note a:hover { text-decoration-thickness: 2px; }

/* Полоска «считается в браузере» */
.tool-privacy { margin-top: 28px; padding: 16px 20px; border: 1px solid var(--line); color: var(--muted); font: 400 15px/22px var(--sans); max-width: 62ch; }

/* ---------- Ступени размеров ---------- */

@media (min-width: 640px) {
  .tool__table { --t-hint: 13px; }
  .tool__actions .btn { padding: 12px 20px; }
  .tool__pair .tool__table th[scope="col"]:first-child, .tool__pair .tool__table tbody th[scope="row"] { width: 40%; }
  .tool__pair .tool__table th[scope="col"]:nth-child(2) { width: 26%; }
  .tool__table tr.is-key td[data-o] { font-size: calc(var(--t-fs) + 6px); line-height: calc(var(--t-lh) + 6px); }
}

@media (min-width: 1100px) {
  .tool__table { --t-fs: 14px; --t-lh: 20px; --t-h: 44px; --t-pad: 10px; --t-hls: .07em; --t-grp: 30px; }
}

@media (min-width: 1024px) {
  .tool { padding: 64px var(--gutter); }
  .tool-toc__list { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 40px; }
  .tool__pair { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; }
}

@media (min-width: 1280px) {
  .tool__table { --t-fs: 15px; --t-lh: 21px; --t-h: 48px; --t-pad: 12px; --t-head: 11px; --t-hls: .09em; --t-grp: 32px; --t-hint: 14px; }
  .tool__table-del button { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .tool-toc a { transition: none; }
}
