/* Калькулятор фундамента «что если» (CRM). Только токены app.css — страница
   собрана через crm_base.html → base.html, где home.css не подключён, поэтому
   --r-8/--r-12/--r-16/--shadow-1 здесь не резолвятся (известное расхождение,
   см. docs/design-system.md): радиусы ниже — в px, теней нет вовсе. */

/* Полноширинный «выход» за стандартный .container (960px): двум колонкам
   калькулятора в нём тесно. Классический приём full-bleed — left:50% плюс
   отрицательный margin в половину вьюпорта — не зависит от паддингов предка.
   Сама ширина контента снова ограничена ниже, у .fd-page-inner. */
.fd-page {
    position: relative;
    left: 50%;
    width: 100vw;
    margin-left: -50vw;
}

/* 100vw формально включает полосу прокрутки (так работает единица vw во всех
   движках) — на высокой странице это даёт лишние ~15px горизонтального
   скролла. Правило страничное (foundation.css подключён только здесь), сайт
   в целом не трогает. */
body {
    overflow-x: hidden;
}

.fd-page-inner {
    max-width: 1280px;
    margin: 0 auto;
}

.fd-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin: 12px 0 16px;
}

.fd-object-link {
    color: var(--ink-soft);
    font-size: 14px;
}

/* --- Переключатель типа фундамента ------------------------------------- */

.fd-kind-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.fd-kind-tile {
    padding: 8px 14px;
    font-size: 14px;
}

.fd-kind-tile span {
    margin-top: 0;
}

/* --- Раскладка: параметры / результат ----------------------------------- */

.fd-body {
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.fd-params {
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}

.fd-group {
    margin: 0;
    padding: 0 0 16px;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
}

.fd-group:last-child {
    border-bottom: 0;
}

.fd-group legend {
    padding: 0 0 8px;
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .02em;
}

.fd-field {
    margin-top: 12px;
}

.fd-field:first-of-type {
    margin-top: 0;
}

.fd-field-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.fd-field-head label {
    font-size: 14px;
    color: var(--ink);
}

.fd-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.fd-input-row input[type="number"] {
    width: 100%;
    height: 36px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    font-variant-numeric: tabular-nums;
}

.fd-input-row input[aria-invalid="true"] {
    border-color: var(--danger);
}

.fd-unit {
    flex-shrink: 0;
    color: var(--ink-soft);
    font-size: 13px;
}

.fd-field select {
    width: 100%;
    height: 36px;
    margin-top: 6px;
    padding: 0 8px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
}

.fd-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-size: 14px;
    color: var(--ink);
}

.fd-source {
    margin: 4px 0 0;
    color: var(--ink-dim);
    font-size: 12px;
}

.fd-field-error {
    margin: 2px 0 0;
    color: var(--danger);
    font-size: 12px;
}

/* --- Подсказка (?) — details, не tooltip -------------------------------- */

.fd-hint summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--ink-soft);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    list-style: none;
}

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

.fd-hint[open] summary {
    border-color: var(--clay);
    color: var(--clay-deep);
}

.fd-hint-body {
    margin-top: 8px;
    padding: 12px;
    background: var(--clay-tint);
    border: 1px solid var(--clay-line);
    border-radius: 8px;
    font-size: 13px;
}

.fd-hint-body p {
    margin: 0 0 6px;
}

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

.fd-hint-body strong {
    color: var(--ink-soft);
    font-weight: 600;
}

.fd-hint-figure {
    margin: 8px 0 0;
}

.fd-hint-figure img {
    display: block;
    width: 100%;
    max-width: 360px;
    border-radius: 8px;
}

/* --- Результат ----------------------------------------------------------- */

.fd-result {
    transition: opacity 180ms;
}

.fd-result.htmx-request {
    opacity: .55;
}

.fd-calc-error {
    color: var(--danger);
    font-size: 15px;
}

.fd-summary {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 4px 0 16px;
    background: var(--sand);
}

.fd-summary-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.fd-summary-label {
    color: var(--ink-soft);
    font-size: 13px;
}

.fd-summary-value {
    font-size: 28px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.fd-partial {
    margin: 4px 0 0;
    color: var(--danger);
    font-size: 13px;
    text-align: right;
}

.fd-field-errors {
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
    color: var(--danger);
    font-size: 13px;
}

.fd-warning {
    margin: 0 0 8px;
    color: var(--ink-soft);
    font-size: 13px;
}

.fd-section {
    margin-top: 24px;
}

.fd-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.fd-section-total {
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.fd-items {
    table-layout: fixed;
}

.fd-items td {
    vertical-align: top;
}

/* Явные ширины колонкам с числами — иначе длинные названия позиций отжимают
   «Сумма» до двух строк вместо одной */
.fd-items th:nth-child(1),
.fd-items td:nth-child(1) {
    width: auto;
}

.fd-items th:nth-child(2),
.fd-items td:nth-child(2) {
    width: 104px;
}

.fd-items th:nth-child(3),
.fd-items td:nth-child(3) {
    width: 48px;
}

.fd-items th:nth-child(4),
.fd-items td:nth-child(4) {
    width: 120px;
}

.fd-items th:nth-child(5),
.fd-items td:nth-child(5) {
    width: 96px;
    white-space: nowrap;
}

.fd-items th:nth-child(6),
.fd-items td:nth-child(6) {
    width: 36px;
}

.fd-col-unit {
    white-space: nowrap;
}

.fd-mobile-unit {
    display: none;
}

.fd-qty-input {
    width: 72px;
    height: 32px;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    font-variant-numeric: tabular-nums;
}

.fd-price-input {
    width: 88px;
    height: 32px;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    font-variant-numeric: tabular-nums;
}

/* Ручная правка подчёркнута акцентом — а не залита, чтобы таблица не рябила */
.fd-qty-input:not(:placeholder-shown),
.fd-price-input:not(:placeholder-shown) {
    border-bottom: 2px solid var(--clay);
}

.fd-no-price {
    margin-top: 2px;
    color: var(--danger);
    font-size: 12px;
}

.fd-removed {
    margin-top: 8px;
}

.fd-removed summary {
    color: var(--ink-soft);
    font-size: 13px;
    cursor: pointer;
}

.fd-removed-list {
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
    font-size: 13px;
}

.fd-removed-list li {
    padding: 4px 0;
}

.fd-derived {
    margin-top: 24px;
    font-size: 14px;
}

.fd-derived summary {
    color: var(--ink-soft);
    cursor: pointer;
}

.fd-derived-list {
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
    color: var(--ink-soft);
    font-size: 13px;
}

.fd-derived-list li {
    padding: 2px 0;
}

/* --- Варианты -------------------------------------------------------------- */

.fd-variants-box {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.fd-save-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.fd-variant-name-input {
    flex: 1;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
}

.fd-variant-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.fd-variant-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line-soft);
    font-size: 14px;
}

.fd-variant-name {
    flex: 1;
}

.fd-variant-total {
    font-variant-numeric: tabular-nums;
}

.fd-variant-date {
    font-size: 12px;
}

.fd-variant-delete {
    padding: 0;
    background: none;
    border: 0;
    color: var(--ink-soft);
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}

.fd-compare-link {
    display: inline-block;
    margin-top: 12px;
    color: var(--clay-deep);
    font-size: 14px;
}

.fd-compare-link[aria-disabled="true"] {
    color: var(--ink-dim);
    pointer-events: none;
}

/* --- Сравнение вариантов (отдельная страница) ------------------------------ */

.fd-compare td,
.fd-compare th {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.fd-compare td:first-child,
.fd-compare th:first-child {
    text-align: left;
    font-variant-numeric: normal;
}

/* Не жирным — в ячейках таблицы это запрещено дизайн-системой; строку
   «Итого» отделяет плотная верхняя граница */
.fd-compare-total td {
    border-top: 1px solid var(--line);
}

.fd-compare-diff td {
    color: var(--ink-soft);
}

/* --- Адаптив --------------------------------------------------------------- */

@media (max-width: 1099px) {
    .fd-body {
        grid-template-columns: 320px minmax(0, 1fr);
    }
}

@media (max-width: 767px) {
    .fd-body {
        grid-template-columns: 1fr;
    }

    .fd-params {
        position: static;
        max-height: none;
        overflow: visible;
    }

    .fd-summary {
        position: sticky;
        top: auto;
        bottom: 0;
        padding: 10px 0;
        border-top: 1px solid var(--line);
    }

    .fd-summary-value {
        font-size: 20px;
    }

    /* app.css на этой ширине превращает .card-items в стопку блоков
       (карточный вид норм/объектов) — для плотной таблицы результата это не
       подходит, тикет явно просит настоящую таблицу без колонки «Ед.», а не
       карточки. Возвращаем табличное отображение только для .fd-items. */
    .fd-items {
        display: table;
    }

    .fd-items thead {
        display: table-header-group;
    }

    .fd-items tbody {
        display: table-row-group;
    }

    .fd-items tr {
        display: table-row;
    }

    .fd-items td,
    .fd-items th {
        display: table-cell;
    }

    /* Специфичность выше, чем у ".fd-items td" из блока выше, иначе та
       побеждает и колонка остаётся видимой несмотря на display:none здесь */
    .fd-items td.fd-col-unit,
    .fd-items th.fd-col-unit {
        display: none;
    }

    .fd-mobile-unit {
        display: inline;
        margin-left: 4px;
        color: var(--ink-soft);
        font-size: 12px;
    }

    .fd-qty-input,
    .fd-price-input {
        width: 64px;
    }

    .fd-items th:nth-child(2),
    .fd-items td:nth-child(2) {
        width: 72px;
    }

    .fd-items th:nth-child(4),
    .fd-items td:nth-child(4) {
        width: 72px;
    }

    .fd-items th:nth-child(5),
    .fd-items td:nth-child(5) {
        width: 76px;
    }

    .fd-items th:nth-child(6),
    .fd-items td:nth-child(6) {
        width: 28px;
    }
}

/* Раскрытая подсказка занимает всю ширину под подписью, а кнопка «?»
   остаётся справа в строке подписи: строка переносится, details встаёт
   отдельной строкой, summary прижимается к правому краю абсолютно. */
.fd-field-head {
    position: relative;
    flex-wrap: wrap;
    padding-right: 28px;
}

.fd-field-head .fd-hint {
    flex-basis: 100%;
}

.fd-field-head .fd-hint summary {
    position: absolute;
    top: 0;
    right: 0;
}
