/* Базовые стили и компоненты De Facto Portal. Mobile-first: базовые правила — для телефона, десктоп через min-width. */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--text-m);
    line-height: 1.55;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1,
h2,
h3,
h4 {
    font-family: var(--font-heading);
    font-weight: 600;
    line-height: 1.25;
    margin: 0 0 var(--gap-m);
    color: var(--text);
}

h1 {
    font-size: var(--text-xxl);
}

h2 {
    font-size: var(--text-xl);
}

h3 {
    font-size: var(--text-l);
}

p {
    margin: 0 0 var(--gap-m);
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
}

[x-cloak] {
    display: none !important;
}

/* --- каркас --- */

.container {
    width: 100%;
    max-width: 64rem;
    margin: 0 auto;
    padding: 0 var(--gap-m);
}

.site-main {
    flex: 1 0 auto;
    padding: var(--gap-l) 0 var(--gap-xl);
}

/* --- шапка --- */

.site-header {
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.site-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap-m);
    padding: var(--gap-m) 0;
}

.site-logo {
    font-family: var(--font-heading);
    font-size: var(--text-l);
    color: var(--text);
    white-space: nowrap;
}

.site-logo span {
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: var(--text-s);
    display: block;
}

.site-header__phone {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

/* --- подвал --- */

.site-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--line);
    background: var(--surface);
    padding: var(--gap-l) 0;
    color: var(--text-muted);
    font-size: var(--text-s);
}

.site-footer__grid {
    display: grid;
    gap: var(--gap-l);
}

.site-footer h3 {
    font-size: var(--text-m);
    color: var(--text);
}

.site-footer ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: var(--gap-s);
}

/* --- блок «напишите нам» --- */

.write-us {
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    padding: var(--gap-l);
    display: grid;
    gap: var(--gap-m);
}

.write-us__title {
    margin: 0;
}

.write-us__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-s);
}

/* --- кнопки --- */

.c-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--gap-s);
    min-height: var(--control-height);
    padding: 0 var(--control-padding-x);
    border-radius: var(--radius-m);
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    width: 100%; /* mobile-first: кнопка на всю ширину */
}

.c-btn:hover {
    text-decoration: none;
}

.c-btn--primary {
    background: var(--accent);
    color: var(--accent-contrast);
}

.c-btn--primary:hover {
    filter: brightness(1.08);
}

.c-btn--ghost {
    background: transparent;
    border-color: var(--line);
    color: var(--text);
}

.c-btn--ghost:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* --- поле формы --- */

.c-field {
    display: grid;
    gap: var(--gap-xs);
    margin-bottom: var(--gap-m);
}

.c-field__label {
    font-size: var(--text-s);
    color: var(--text-muted);
}

.c-field__input {
    min-height: var(--control-height);
    padding: 0 var(--control-padding-x);
    border-radius: var(--radius-m);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    width: 100%;
}

.c-field__input:focus {
    outline: none;
    border-color: var(--accent);
}

.c-field__input::placeholder {
    color: var(--text-faint);
}

.c-field__error {
    display: none;
    font-size: var(--text-s);
    color: var(--danger);
}

.c-field--error .c-field__input {
    border-color: var(--danger);
}

.c-field--error .c-field__error {
    display: block;
}

/* --- чекбокс оферты --- */

.c-offer {
    display: flex;
    gap: var(--gap-s);
    align-items: flex-start;
    font-size: var(--text-s);
    color: var(--text-muted);
}

.c-offer input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.15rem;
    accent-color: var(--accent);
    flex-shrink: 0;
}

/* --- карточка --- */

.c-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    padding: var(--gap-l);
    display: grid;
    gap: var(--gap-s);
}

.c-card__title {
    margin: 0;
}

.c-card__meta {
    color: var(--text-faint);
    font-size: var(--text-s);
}

/* --- степпер --- */

.c-stepper {
    display: flex;
    align-items: center;
    gap: var(--gap-s);
    margin-bottom: var(--gap-l);
}

.c-stepper__step {
    display: flex;
    align-items: center;
    gap: var(--gap-s);
    color: var(--text-faint);
    font-size: var(--text-s);
}

.c-stepper__num {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    border: 1px solid var(--line);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.c-stepper__step--done {
    color: var(--success);
}

.c-stepper__step--done .c-stepper__num {
    border-color: var(--success);
}

.c-stepper__step--current {
    color: var(--text);
}

.c-stepper__step--current .c-stepper__num {
    border-color: var(--accent);
    color: var(--accent);
}

.c-stepper__line {
    flex: 1;
    height: 1px;
    background: var(--line);
    min-width: 0.75rem;
}

/* --- плашка-статус --- */

.c-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--gap-xs);
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    font-size: var(--text-s);
    font-weight: 600;
    border: 1px solid var(--line);
    color: var(--text-muted);
}

.c-badge--success {
    color: var(--success);
    border-color: var(--success);
}

.c-badge--accent {
    color: var(--accent);
    border-color: var(--accent);
}

.c-badge--danger {
    color: var(--danger);
    border-color: var(--danger);
}

/* --- модалка (Alpine) --- */

.c-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end; /* mobile-first: шторка снизу */
    justify-content: center;
    padding: var(--gap-m);
}

.c-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgb(0 0 0 / 60%);
}

.c-modal__dialog {
    position: relative;
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    padding: var(--gap-l);
    width: 100%;
    max-width: 28rem;
    display: grid;
    gap: var(--gap-m);
}

.c-modal__close {
    position: absolute;
    top: var(--gap-s);
    right: var(--gap-s);
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: var(--text-l);
    cursor: pointer;
    padding: var(--gap-s);
    line-height: 1;
}

/* --- барабан выбора: на мобильном нативный select --- */

.c-select {
    min-height: var(--control-height);
    width: 100%;
    padding: 0 var(--control-padding-x);
    border-radius: var(--radius-m);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

/* --- экран ошибки --- */

.c-error-screen {
    min-height: 50vh;
    display: grid;
    place-content: center;
    gap: var(--gap-m);
    text-align: center;
    padding: var(--gap-xl) var(--gap-m);
}

.c-error-screen__code {
    font-family: var(--font-heading);
    font-size: 4rem;
    color: var(--text-faint);
    line-height: 1;
}

.c-error-screen__title {
    margin: 0;
}

.c-error-screen__text {
    color: var(--text-muted);
}

/* --- страница отсрочки и калькулятор --- */

.cms-section {
    margin-bottom: var(--gap-xl);
}

.cms-section ul {
    padding-left: var(--gap-l);
    color: var(--text-muted);
}

.cms-section p {
    color: var(--text-muted);
}

.deferral-columns {
    display: grid;
    gap: var(--gap-m);
}

.calc-scale {
    display: flex;
    justify-content: space-between;
    color: var(--text-faint);
    font-size: var(--text-s);
}

.calc-max {
    margin: var(--gap-m) 0;
}

.calc-hidden {
    display: none;
}

.calc-lines {
    display: grid;
    gap: var(--gap-s);
    margin: var(--gap-m) 0;
}

.calc-lines > div {
    display: flex;
    justify-content: space-between;
    gap: var(--gap-m);
}

.calc-lines dt {
    color: var(--text-muted);
}

.calc-lines dd {
    margin: 0;
    white-space: nowrap;
}

.calc-total {
    border-top: 1px solid var(--line);
    padding-top: var(--gap-s);
    font-weight: 700;
    font-size: var(--text-l);
}

.calc-total dd {
    color: var(--accent);
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

/* --- страница дела и юр. тексты --- */

.case-facts {
    display: grid;
    gap: var(--gap-xs);
    margin: 0;
}

.case-facts dt {
    color: var(--text-faint);
    font-size: var(--text-s);
}

.case-facts dd {
    margin: 0 0 var(--gap-s);
}

.legal-text {
    color: var(--text-muted);
}

/* --- каталог и карточка юриста --- */

.catalog-grid {
    display: grid;
    gap: var(--gap-m);
}

.lawyer-grid {
    display: grid;
    gap: var(--gap-m);
}

.lawyer-grid__item {
    display: grid;
    gap: var(--gap-s);
}

.lawyer-card__head {
    display: flex;
    align-items: center;
    gap: var(--gap-m);
}

.lawyer-card__photo {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.lawyer-card__photo--stub {
    background: var(--surface-raised);
    border: 1px solid var(--line);
    color: var(--accent);
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.lawyer-card__price {
    font-weight: 600;
    font-size: var(--text-l);
    color: var(--accent);
}

/* --- десктоп --- */

@media (min-width: 48rem) {
    :root {
        --text-xxl: 2.5rem;
        --text-xl: 1.75rem;
    }

    .c-btn {
        width: auto;
    }

    .site-footer__grid {
        grid-template-columns: 1fr 1fr;
    }

    .c-modal {
        align-items: center;
    }

    .catalog-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .lawyer-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .deferral-columns {
        grid-template-columns: 1fr 1fr;
    }
}

/* Русский выбор файлов (components/file_picker.html, js/file-picker.js); цвета — токены текущей темы */
.file-picker { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-s) var(--gap-m); min-width: 0; padding: var(--gap-s); border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface); }
.file-picker__input { position: absolute; width: 1px; height: 1px; padding: 0; opacity: 0; overflow: hidden; clip-path: inset(50%); }
.file-picker__button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.75rem; max-width: 100%; padding: .5rem .85rem; border: 1px solid var(--accent); border-radius: var(--radius-s); background: var(--surface-raised); color: var(--accent); font-weight: 700; cursor: pointer; }
.file-picker__input:focus-visible + .file-picker__button { outline: 3px solid var(--accent); outline-offset: 3px; }
.file-picker__input[aria-invalid="true"] + .file-picker__button { border-color: var(--danger); }
.file-picker__status { min-width: 0; max-width: 100%; color: var(--text-muted); font-size: var(--text-s); overflow-wrap: anywhere; }
@media (max-width: 40rem) {
    .file-picker__button { width: 100%; }
}

/* Поток Б, B1: главная «Что случилось?», карточки вариантов (F-096), страница услуги (F-100) */
.entries { list-style: none; padding: 0; display: grid; gap: var(--gap-s); }
.entries__link { display: block; text-decoration: none; color: inherit; font-size: 1.15rem; }
.entries__link .c-card__meta { display: block; font-size: .9rem; }
.answers-row { display: flex; flex-wrap: wrap; gap: var(--gap-s); }
.situation-card__benefits { padding-left: 1.2em; }
.situation-card__price { font-size: 1.2rem; font-weight: 600; }
.c-btn--wide { display: block; width: 100%; text-align: center; box-sizing: border-box; }
.preview-rows { list-style: none; padding: 0; }
.service-page { display: grid; gap: var(--gap-m); }
.price-bar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: var(--gap-s); }
.price-bar__amount { font-size: 1.4rem; font-weight: 600; margin: 0; }
@media (min-width: 900px) {
    .service-page { grid-template-columns: 1fr 320px; align-items: start; }
    .price-bar { top: var(--gap-m); bottom: auto; border: 1px solid var(--line); border-radius: var(--radius-m); }
}

/* --- Помощник DeFacto (поток K, F-128) --- */
.assistant-fab {
    position: fixed;
    z-index: 90;
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 18px 0 14px;
    border-radius: 999px;
    border: 1px solid var(--ai);
    background: var(--ai-soft);
    color: var(--ai-ink);
    text-decoration: none;
}
body:has(.price-bar) .assistant-fab { display: none; }
.assistant-bar { display: inline-flex; margin-top: var(--gap-s); color: var(--ai-ink); }
@media (max-width: 560px) { .assistant-fab__label { display: none; } .assistant-fab { padding: 0 14px; } }
.assistant-sheet:empty { display: none; }
.assistant-sheet {
    position: fixed;
    z-index: 95;
    right: 16px;
    bottom: 20px;
    width: min(390px, calc(100vw - 32px));
    max-height: calc(100dvh - 120px);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
}
@media (max-width: 560px) { .assistant-sheet { left: 0; right: 0; bottom: 0; width: auto; border-radius: 20px 20px 0 0; } }
.assistant-panel { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; }
.assistant-panel__head { display: flex; align-items: center; gap: 10px; }
.assistant-panel__head div { flex: 1; display: flex; flex-direction: column; }
.assistant-panel__head b { color: var(--ai-ink); }
.assistant-panel__head span { font-size: var(--text-s); color: var(--text-muted); }
.assistant-badge { color: var(--ai); }
.assistant-close { background: none; border: 0; color: var(--text-muted); font-size: 1.5rem; }
.assistant-msg { padding: 10px 12px; border-radius: 14px; white-space: normal; }
.assistant-msg--answer { background: var(--ai-soft); }
.assistant-msg--user { background: var(--surface-raised); align-self: flex-end; }
.assistant-qs { display: flex; flex-wrap: wrap; gap: 6px; }
.assistant-q { border: 1px solid var(--ai); border-radius: 999px; padding: 6px 10px; color: var(--ai-ink); text-decoration: none; }
.assistant-note { font-size: var(--text-s); color: var(--text-muted); }
