/*
 * Thermal calculator page (templates/calculator/teplotekhnicheskiy-raschet-steny.html.twig): the city selector, the manual
 * climate, the layer cards, the verdicts, the hints and the tables of the result. On top of engine.css, site.css and roof.css
 * (presets, folded sections, tabs, tables, drawing frames) and thermal.css (the classes of the figures); tokens only.
 * Colours of the verdicts: the text stays --c-text on --c-surface, the status is told by a word and a sign, the colour only helps.
 */
:root {
    --th-ok: #1b6e3c;
    --th-on-ok: #fff;
    --th-warn: #8a5a00;
    --th-on-warn: #fff;
    --th-ok-soft: #e9f4ed;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --th-ok: #6fd39a;
        --th-on-ok: #06210f;
        --th-warn: #e6b84f;
        --th-on-warn: #261a00;
        --th-ok-soft: #14291d;
    }
}
@media not print {
    :root[data-theme="dark"] {
        --th-ok: #6fd39a;
        --th-on-ok: #06210f;
        --th-warn: #e6b84f;
        --th-on-warn: #261a00;
        --th-ok-soft: #14291d;
    }
}

/* ---------- Form: city, climate, room ---------- */
.th-city select { width: 100%; }
.th-city-filter { width: 100%; margin-bottom: var(--s-2); }
.th-city-filter[hidden], .th-city-count[hidden] { display: none; }
.th-city-count { margin: var(--s-1) 0 0; }
.th-climate { margin-top: var(--s-2); }
.th-climate__grid { margin-top: var(--s-2); }
.th-months { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--s-5); margin: var(--s-2) 0 var(--s-3); }
.th-month { display: grid; grid-template-columns: 2.6rem minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: var(--s-2); }
.th-month__name { padding-top: 11px; font-weight: 600; font-size: var(--fs-sm); color: var(--c-muted); }
.th-month .field { position: relative; margin-bottom: var(--s-2); }
.th-month .field input { width: 100%; padding-right: 3.4rem; }
.th-month .field::after { position: absolute; right: 12px; top: 11px; font-size: var(--fs-xs); color: var(--c-muted); pointer-events: none; }
.th-month .field:nth-of-type(1)::after { content: '°C'; }
.th-month .field:nth-of-type(2)::after { content: 'гПа'; }

/* ---------- Form: the layer editor ---------- */
.th-layers .help { max-width: none; }
.th-layer-list { display: grid; gap: var(--s-3); margin: var(--s-3) 0; padding: 0; list-style: none; }
.th-layer { min-width: 0; }
.th-layer__box { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-2); min-width: 0; margin: 0; padding: var(--s-3); border: 1px solid var(--c-border-strong); border-left: 4px solid var(--c-accent); border-radius: var(--radius); background: var(--c-surface); }
.th-layer:target .th-layer__box { box-shadow: 0 0 0 2px var(--c-focus); }
.th-layer { scroll-margin-top: var(--s-4); }
.th-layer__box legend { float: left; width: 100%; margin: 0 0 var(--s-1); padding: 0; font-weight: 700; font-size: var(--fs-sm); }
.th-layer__box legend + * { clear: both; }
.th-layer__no { display: inline-flex; align-items: center; justify-content: center; min-width: 1.75rem; height: 1.75rem; border-radius: 999px; background: var(--c-accent); color: var(--c-on-accent); font-size: var(--fs-sm); }
.th-layer__side { font-weight: 400; color: var(--c-muted); }
.th-layer__main { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-2) var(--s-3); }
.th-layer .field { margin-bottom: var(--s-2); min-width: 0; }
.th-layer__material select, .th-layer__thickness input { width: 100%; max-width: 100%; }
/* «Толщина, мм»: the unit follows the word (the engine pushes a unit to the far edge, which tore the comma off the label) */
.calc-form .th-layer__thickness > label { justify-content: flex-start; gap: 0; }
.th-layer__r { margin: var(--s-1) 0 0; font-size: var(--fs-xs); color: var(--c-muted); font-variant-numeric: tabular-nums; }
.th-info { margin: var(--s-1) 0 0; font-size: var(--fs-xs); color: var(--c-muted); }
.th-info[hidden] { display: none; }
.th-layer__tools { display: flex; gap: var(--s-2); }
.th-tool { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 var(--s-2); border: 1px solid var(--c-border-strong); background: var(--c-surface); color: var(--c-text); font-size: 1.15rem; line-height: 1; }
.th-tool:hover { border-color: var(--c-accent); background: var(--c-accent-soft); color: var(--c-link); filter: none; }
.th-tool[disabled] { opacity: .4; cursor: default; }
.th-tool--toggle { font-size: var(--fs-sm); }
.th-tool[disabled]:hover { border-color: var(--c-border-strong); background: var(--c-surface); color: var(--c-text); }
.th-tool--danger:hover { border-color: var(--c-error); color: var(--c-error); background: var(--c-surface); }
.th-layer__more { margin: 0; }
.th-layer__more > summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; font-size: var(--fs-sm); font-weight: 600; color: var(--c-link); }
.th-layer__more > summary:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.th-layer__changed { margin-left: var(--s-1); font-weight: 400; color: var(--c-muted); }
.th-layer__grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--s-3); padding-top: var(--s-2); }
.th-layer__help { grid-column: 1 / -1; margin: 0 0 var(--s-2); }
.th-layer__grid .field input, .th-layer__grid .field select { width: 100%; }
.th-add { margin: 0 0 var(--s-3); }
.th-add .btn { min-width: 12rem; }
.th-add .btn[disabled] { opacity: .5; cursor: default; }
.th-default { position: absolute !important; left: -9999px; }

@media (min-width: 560px) {
    .th-layer__main { grid-template-columns: minmax(0, 1fr) 9rem; align-items: start; }
    .th-layer__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .th-months { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 720px) {
    .th-layer__box { grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
    .th-layer__box legend, .th-layer__more { grid-column: 1 / -1; }
    .th-layer__main { grid-column: 1; }
    .th-layer__tools { grid-column: 2; grid-row: 2; padding-top: 1.6rem; }
    .th-layer__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 960px) {
    .th-months { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .th-layer__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* The way to the button is short on a phone: the actions stay at the bottom of the screen while the form is long. */
@media (max-width: 719px) {
    .th-actions { position: sticky; bottom: 0; z-index: 5; margin: var(--s-3) calc(-1 * var(--s-3)) calc(-1 * var(--s-3)); padding: var(--s-2) var(--s-3); border-top: 1px solid var(--c-border); background: var(--c-surface); box-shadow: 0 -4px 12px rgba(16, 24, 32, .08); }
    .th-actions button { flex: 1 1 auto; }
}

/* ---------- Result: the verdicts ---------- */
.th-verdicts { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-3); margin: 0 0 var(--s-4); }
.th-verdict { min-width: 0; padding: var(--s-3) var(--s-4); border: 1px solid var(--c-border); border-left: 4px solid var(--c-border-strong); border-radius: var(--radius); background: var(--c-surface); }
.th-verdict--ok { border-left-color: var(--th-ok); }
.th-verdict--fail { border-left-color: var(--c-error); }
.th-verdict--warn { border-left-color: var(--th-warn); }
.th-verdict > p { margin: 0 0 var(--s-2); font-size: var(--fs-sm); }
.th-verdict > p:last-child { margin-bottom: 0; }
.th-verdict__label { font-size: var(--fs-xs) !important; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--c-muted); }
.th-verdict__headline { margin: 0 0 var(--s-2); font-family: var(--font); font-size: var(--fs-base); font-weight: 700; line-height: 1.35; }
.th-verdict__detail { padding-left: var(--s-3); border-left: 2px solid var(--c-border-strong); }
.th-compare { padding-top: var(--s-2); border-top: 1px dashed var(--c-border); }
.th-badge { display: inline-block; margin-right: var(--s-1); padding: 1px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 700; white-space: nowrap; background: var(--c-surface-alt); color: var(--c-text); }
.th-badge--ok { background: var(--th-ok); color: var(--th-on-ok); }
.th-badge--fail { background: var(--c-error); color: var(--c-surface); }
.th-badge--warn { background: var(--th-warn); color: var(--th-on-warn); }
.th-norm { color: var(--c-muted); white-space: nowrap; }
.th-warn__norm { display: inline-block; margin-left: var(--s-1); color: var(--c-muted); font-size: var(--fs-xs); white-space: nowrap; }
.th-main { margin-top: var(--s-4); }
.th-disclaimer { max-width: none; }

/* The big headline number of the verdict card: label on top (small), value in a large size, the unit as a muted suffix. */
.th-verdict__metric { display: block; margin: 0 0 var(--s-2) !important; line-height: 1.1; }
.th-verdict__metric-label { display: block; font-size: var(--fs-xs); font-weight: 600; color: var(--c-muted); text-transform: uppercase; letter-spacing: .03em; }
.th-verdict__metric-value { display: block; margin-top: 2px; font-family: var(--font); font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--c-text); line-height: 1.1; }
.th-verdict--fail .th-verdict__metric-value { color: var(--c-error); }
.th-verdict--ok .th-verdict__metric-value { color: var(--th-ok); }
.th-verdict--warn .th-verdict__metric-value { color: var(--th-warn); }
.th-verdict--na .th-verdict__metric-value { color: var(--c-muted); }
.th-verdict__metric-unit { font-size: var(--fs-sm); font-weight: 400; color: var(--c-muted); white-space: nowrap; }
.th-verdict__plain { margin: 0 0 var(--s-2) !important; font-weight: 600; }
.th-verdict__text { font-variant-numeric: tabular-nums; }
.th-limits > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: var(--s-1); flex-wrap: wrap; list-style: none; }
.th-limits > summary::-webkit-details-marker { display: none; }
.th-limits > summary::before { content: '▸'; display: inline-block; width: 1em; color: var(--c-muted); transition: transform .2s ease; }
.th-limits[open] > summary::before { transform: rotate(90deg); }
.th-limits > summary:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; border-radius: var(--radius); }
.th-table tr.is-pass td, .th-table tr.is-pass th { background: var(--th-ok-soft); }
.th-table tr.is-fail td, .th-table tr.is-fail th { background: rgba(201, 42, 42, .08); color: var(--c-error); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .th-table tr.is-fail td,
    :root:not([data-theme="light"]) .th-table tr.is-fail th { background: rgba(230, 90, 90, .14); }
}
@media not print {
    :root[data-theme="dark"] .th-table tr.is-fail td,
    :root[data-theme="dark"] .th-table tr.is-fail th { background: rgba(230, 90, 90, .14); }
}
@media (prefers-reduced-motion: reduce) {
    .th-limits > summary::before { transition: none; }
}
@media print {
    .th-limits > summary { display: none; }
    .th-limits[open] > summary + * { display: block; }
}

@media (min-width: 960px) {
    .th-verdicts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Result: hints ---------- */
.th-hints { display: grid; gap: var(--s-4); margin: 0 0 var(--s-4); padding: 0; list-style: none; counter-reset: hint; }
.th-hint { padding: var(--s-3) var(--s-4); border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface); counter-increment: hint; }
.th-hint__title { margin: 0 0 var(--s-2); font-weight: 600; }
.th-hint__title::before { content: counter(hint) '. '; color: var(--c-muted); }
.th-hint__table { max-width: 38rem; }
.th-hint .btn { display: inline-flex; align-items: center; }

/* ---------- Result: tables ---------- */
.th-table td { white-space: normal; vertical-align: top; }
.th-table td:last-child { min-width: 0; }
.th-table .num { text-align: right; white-space: nowrap; }
.th-table tr.is-ignored td, .th-table tr.is-ignored th { color: var(--c-muted); font-style: italic; }
.th-table tr.is-sub td, .th-table tr.is-sub th { color: var(--c-muted); font-size: var(--fs-xs); }
.th-table tr.is-marked td, .th-table tr.is-marked th { color: var(--c-error); font-weight: 600; }
.th-table tr.is-total th, .th-table tr.is-total td { background: var(--c-surface-alt); font-weight: 600; }
.th-table-wrap { max-width: 100%; }
.th-table[data-table="moisture"] td:nth-child(2), .th-table[data-table="heat"] td:nth-child(2) { min-width: 14rem; }
.th-table[data-table="layers"] td:nth-child(2) { min-width: 10rem; }
.th-table[data-table="boundaries"] td:nth-child(2) { min-width: 11rem; }
.th-fig { margin-bottom: var(--s-4); }
.th-fig svg { min-width: 720px; }

/* ---------- Print of the page itself ---------- */
@media print {
    .th-layer__tools, .th-add, .th-actions, .th-presets { display: none !important; }
    .th-verdicts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- UX T4: live summary strip (sticky bar above the form) ---------- */
.th-strip {
    position: sticky; top: 0; z-index: 10;
    margin: 0 0 var(--s-3);
    padding: var(--s-2) var(--s-3);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
    backdrop-filter: saturate(1.2);
}
.th-strip__caption { margin: 0 0 var(--s-2); font-size: var(--fs-sm); }
.th-strip__title { font-weight: 700; color: var(--c-text); }
.th-strip__object { margin-left: var(--s-1); color: var(--c-muted); }
.th-strip__grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }
.th-strip__cell {
    min-width: 0; padding: var(--s-2) var(--s-3);
    border: 1px solid var(--c-border);
    border-left: 4px solid var(--c-border-strong);
    border-radius: var(--radius);
    background: var(--c-surface-alt);
}
.th-strip__cell--ok { border-left-color: var(--th-ok); }
.th-strip__cell--fail { border-left-color: var(--c-error); }
.th-strip__cell--warn { border-left-color: var(--th-warn); }
.th-strip__cell--na, .th-strip__cell--neutral { border-left-color: var(--c-border-strong); }
.th-strip__head { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin: 0 0 var(--s-1); }
.th-strip__label { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--c-muted); }
.th-strip__text { margin: 0; font-size: var(--fs-sm); color: var(--c-text); line-height: 1.35; }
.th-badge--neutral, .th-badge--na { background: var(--c-surface-alt); color: var(--c-muted); border: 1px solid var(--c-border); }
.th-strip__scale { margin: 0 0 var(--s-1); }
.th-strip__bar {
    position: relative; display: block;
    width: 100%; height: 10px;
    border-radius: 999px; background: var(--c-surface);
    border: 1px solid var(--c-border);
    overflow: hidden;
}
.th-strip__bar-fill {
    display: block; height: 100%;
    width: clamp(0%, calc(var(--th-strip-fill, 0) * 1%), 100%);
    background: var(--c-border-strong);
    transition: width .25s ease, background-color .25s ease;
}
.th-strip__cell--ok .th-strip__bar-fill { background: var(--th-ok); }
.th-strip__cell--fail .th-strip__bar-fill { background: var(--c-error); }
.th-strip__cell--warn .th-strip__bar-fill { background: var(--th-warn); }
.th-strip__bar-mark {
    position: absolute; top: -3px; bottom: -3px; left: 50%;
    width: 2px; background: var(--c-text); opacity: .35;
}
.th-strip__hint { margin: var(--s-2) 0 0; }
.th-strip__hint[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
    .th-strip__bar-fill { transition: none; }
}

@media (min-width: 720px) {
    .th-strip__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 719px) {
    /* On a phone the strip is a one-line condensed bar: badges only, the text goes under on tap. */
    .th-strip { padding: var(--s-2); }
    .th-strip__text { font-size: var(--fs-xs); }
}

/* ---------- UX T4: collapsible form sections ---------- */
.form-section-fold { margin: 0 0 var(--s-3); }
.form-section-fold > summary {
    display: flex; align-items: baseline; gap: var(--s-2); flex-wrap: wrap;
    min-height: 44px;
    padding: var(--s-2) 0;
    cursor: pointer;
    font-weight: 700;
    color: var(--c-text);
    list-style: none;
}
.form-section-fold > summary::-webkit-details-marker { display: none; }
.form-section-fold > summary::before {
    content: '▸';
    display: inline-block;
    width: 1em; margin-right: var(--s-1);
    color: var(--c-muted);
    transition: transform .2s ease;
}
.form-section-fold[open] > summary::before { transform: rotate(90deg); }
.form-section-fold__title { font-size: var(--fs-base); }
.form-section-fold__hint { color: var(--c-muted); font-weight: 400; font-size: var(--fs-sm); }
.form-section-fold > summary:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; border-radius: var(--radius); }
.form-section--body { border: 0; margin: 0; padding: 0; }
.form-section--body > legend { padding: 0; }
/* the hidden legend is positioned absolutely: without a positioned fieldset its static position stretched the page sideways */
.form-section--body { position: relative; }
.form-section--body > legend.visually-hidden { left: 0; top: 0; }

@media (prefers-reduced-motion: reduce) {
    .form-section-fold > summary::before { transition: none; }
}

/* ---------- UX T4: live update visual cue ---------- */
.th-live-pending .th-strip { opacity: .9; }
.th-live-error .th-strip { outline: 2px solid var(--c-error); }

.btn--changed { background-color: var(--c-warn-border); border-color: var(--c-warn-border); color: #000; }
.th-layer--off .th-layer__box { opacity: 0.6; background: var(--c-bg); border-left-color: var(--c-border-strong); }
.th-layer--off .th-layer__no { background: var(--c-muted); color: var(--c-surface); }
.th-layer--off .th-layer__box { opacity: 0.6; background: var(--c-bg); border-left-color: var(--c-border-strong); }
.th-layer--off .th-layer__no { background: var(--c-muted); color: var(--c-surface); }
