:root {
    --bg: #f8fafc;
    --fg: #0f172a;
    --muted: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --border: #cbd5e1;
    --error: #dc2626;
    --ok: #16a34a;
    --card: #ffffff;
    --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
    --radius: 15px;
    --radius-input: 8px;
    font-size: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui,
        "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 0 2rem;
}

.container {
    width: 100%;
    max-width: 720px;
    padding: 0 1rem;
}

/* === SITE HEADER === */
.site-header {
    width: 100%;
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 6px rgba(15, 23, 42, 0.04);
}

.site-header .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--fg);
    font-weight: 700;
    font-size: 1rem;
}

.site-header .brand img {
    width: 32px;
    height: 32px;
    display: block;
}

.site-header .contact {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.1;
}
.site-header .contact-phone {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
}
.site-header .contact-phone:hover { text-decoration: underline; }
.site-header .contact-sub {
    color: var(--muted);
    font-size: 0.72rem;
    margin-top: 0.1rem;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .site-header .brand span { display: none; }
    .site-header .contact-phone { font-size: 0.875rem; }
    .site-header .contact-sub { font-size: 0.68rem; }
}

/* === Info-block (обоснование 245-ФЗ на главном экране) === */
.info-block {
    background: #eff6ff;
    border: 1px solid #d6e6fb;
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin: 0 0 1.25rem;
}
.info-block h3 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    color: #1e3a8a;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.info-block .info-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    animation: pulse-soft 2.5s ease-in-out infinite;
}
.info-block ul {
    margin: 0 0 0.5rem;
    padding-left: 1.25rem;
    font-size: 0.92rem;
    color: var(--fg);
    line-height: 1.5;
}
.info-block li { margin-bottom: 0.3rem; }
.info-block button.more {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 500;
    padding: 0.25rem 0;
    text-decoration: underline;
}
.info-block button.more:hover { color: var(--accent-hover); }

/* === Modal (общий шаблон, info + потенциально другие) === */
.modal {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal.hidden { display: none; }
.modal-card {
    background: #fff;
    border-radius: var(--radius);
    width: 100%; max-width: 720px;
    max-height: 90vh;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.modal-card header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-card header h2 { margin: 0; font-size: 1.15rem; }
.modal-card .close {
    background: none; border: none;
    font-size: 1.5rem; line-height: 1;
    cursor: pointer; color: var(--muted);
    padding: 0 0.25rem;
}
.modal-card .modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}
.modal-card footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex; gap: 0.5rem; justify-content: flex-end;
}

/* Текст в legal-modal */
.legal-text h4 {
    margin: 1.25rem 0 0.5rem;
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--fg);
}
.legal-text h4:first-child { margin-top: 0; }
.legal-text p { margin: 0 0 0.6rem; line-height: 1.55; font-size: 0.92rem; }
.legal-text ul, .legal-text ol {
    margin: 0 0 0.6rem;
    padding-left: 1.25rem;
    font-size: 0.92rem;
    line-height: 1.55;
}
.legal-text li { margin-bottom: 0.25rem; }
.legal-text a { color: var(--accent); }

/* === Subtitle на screen 2 (введённые данные с экрана 1) === */
.form-subtitle {
    font-size: 1rem;
    color: var(--muted);
    margin: 0 0 1rem;
    font-weight: 500;
    line-height: 1.4;
}
.form-subtitle b { color: var(--fg); font-weight: 600; }

/* === Citizenship radio (РФ / Иностранец) === */
.citizenship-toggle {
    display: inline-flex;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem;
    margin-bottom: 0.75rem;
    gap: 0.25rem;
}
.cz-option {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.85rem;
    border-radius: calc(var(--radius) - 4px);
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.15s;
}
.cz-option input { margin: 0; }
.cz-option:has(input:checked) {
    background: var(--accent);
    color: #fff;
}
/* Fallback для браузеров без :has() — прячем нативные радио поверх */
.cz-option input:checked + span { font-weight: 500; }

.hidden { display: none !important; }

/* === Address grid (структурные поля адреса) === */
.address-title {
    margin: 0.5rem 0 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--fg);
}
.address-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.address-grid.hidden { display: none; }

/* Чекбокс «адрес услуг отличается» — отдельная вертикальная строфа.
   Сверху 8px (плотно к полям Дом/Квартира), снизу 24px — отделяет от поля Телефон. */
.consent.srv-toggle {
    margin: 8px 0 24px;
    align-items: center;
}
/* Пустой error-плейсхолдер у скрытого registration_address не должен раздвигать gap. */
.field-error[data-error-for="registration_address"]:empty {
    min-height: 0;
    margin-top: 0;
}
/* Если показан srv-grid — уменьшаем зазор после чекбокса (8px), а после grid — 24px */
.consent.srv-toggle:has(+ .address-grid:not(.hidden)) {
    margin-bottom: 8px;
}
.address-grid.srv-grid:not(.hidden) {
    margin-bottom: 24px;
}
@media (min-width: 640px) {
    .address-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    .address-grid .address-region { grid-column: span 6; }
    .address-grid .address-city   { grid-column: span 6; }
    .address-grid .address-street { grid-column: span 6; }
    .address-grid .address-house  { grid-column: span 4; }
    .address-grid .address-flat   { grid-column: span 2; }
}
.address-grid .field { margin-bottom: 0; }
.address-grid .field label {
    font-size: 0.78rem;
    margin-bottom: 0.2rem;
    color: var(--muted);
    font-weight: 400;
}

/* === Form group: пастельная подложка + поля внутри + кнопки внизу === */
.form-group {
    margin-top: 1.25rem;
    padding: 1rem 1.1rem;
    border-radius: var(--radius);
    background: #f8fafc;
    border: 1px solid #eef2f7;
    transition: background 0.2s, border-color 0.2s;
}
.form-group:first-of-type { margin-top: 0; }

/* Разные пастели для визуального разделения */
.form-group[data-group="personal"] {
    background: #f5f3ff;
    border-color: #e0d8fb;
}
.form-group[data-group="passport"] {
    background: #fef9e7;
    border-color: #fcefb4;
}
.form-group[data-group="contacts"] {
    background: #eff6ff;
    border-color: #d6e6fb;
}

/* Подтверждённая группа — мягкий зелёный оттенок */
.form-group.confirmed {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.group-header {
    margin: 0 0 0.75rem;
}
.group-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
}
.group-icon {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    animation: float-soft 4s ease-in-out infinite;
}

/* === Иконки в label полей контактов === */
.lbl-icon {
    width: 18px;
    height: 18px;
    vertical-align: -4px;
    margin-right: 0.35rem;
    transition: transform 0.3s ease-out;
}
/* Лёгкое покачивание телефона на hover */
.field:hover .icon-phone {
    animation: wiggle 0.6s ease-in-out;
}
.field:hover .icon-mail {
    transform: translateY(-3px);
}

/* === Большой checkmark на «Спасибо» === */
.thanks-card {
    text-align: center;
}
.success-icon {
    width: 96px;
    height: 96px;
    display: block;
    margin: 0.5rem auto 0.25rem;
}
.success-icon .success-circle {
    transform-origin: center;
    transform: scale(0);
    opacity: 0;
}
.success-icon .success-check {
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
}
/* Анимация запускается только когда добавлен класс .animate (после show('done')) */
.success-icon.animate .success-circle {
    animation: scale-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.success-icon.animate .success-check {
    animation: draw-check 0.45s 0.4s ease-out forwards;
}

@keyframes scale-in {
    from { transform: scale(0); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
@keyframes draw-check {
    to { stroke-dashoffset: 0; }
}
@keyframes float-soft {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-3px); }
}
@keyframes pulse-soft {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}
@keyframes wiggle {
    0%, 100% { transform: rotate(0); }
    20%      { transform: rotate(-12deg); }
    40%      { transform: rotate(10deg); }
    60%      { transform: rotate(-6deg); }
    80%      { transform: rotate(4deg); }
}

/* Уважение к prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .group-icon, .info-icon { animation: none !important; }
    .lbl-icon { transition: none; }
    .success-icon .success-circle { transform: scale(1); opacity: 1; animation: none !important; }
    .success-icon .success-check { stroke-dashoffset: 0; animation: none !important; }
}

/* Кнопки группы — внизу, справа */
.group-actions {
    display: flex;
    gap: 0.4rem;
    justify-content: flex-end;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px dashed rgba(15, 23, 42, 0.08);
}

button.btn-confirm,
button.btn-edit {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--fg);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
button.btn-confirm:hover { background: #f1f5f9; }
button.btn-edit:hover    { background: #f1f5f9; }

button.btn-confirm.confirmed {
    background: var(--ok);
    border-color: var(--ok);
    color: #fff;
    cursor: default;
}
button.btn-confirm.confirmed:hover { background: var(--ok); }
button.btn-confirm.confirmed::before {
    content: "✓";
    font-weight: 700;
}

button.btn-edit.hidden { display: none; }

/* Заблокированная группа: визуальный индикатор */
.form-group.confirmed .field input:read-only,
.form-group.confirmed .field textarea:read-only {
    background: #fff;
    color: #475569;
    cursor: default;
    border-color: #e2e8f0;
}

h1 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    margin: 0 0 0.5rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.lead {
    color: var(--muted);
    margin: 0 0 1.5rem;
    font-size: 0.95rem;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.screen { display: none; }
.screen.active { display: block; }

.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.35rem;
    color: var(--fg);
    font-weight: 500;
}

.field .hint {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.field input,
.field textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    padding: 0.65rem 0.75rem;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.field.invalid input,
.field.invalid textarea {
    border-color: var(--error);
}

.field-error {
    color: var(--error);
    font-size: 0.8rem;
    margin-top: 0.25rem;
    min-height: 1rem;
}

.row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

@media (min-width: 640px) {
    .row.cols-2 { grid-template-columns: 1fr 1fr; }
    .row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
}

.actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    flex-direction: column;
}

@media (min-width: 480px) {
    .actions { flex-direction: row; }
}

button.primary,
button.secondary {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

button.primary {
    background: var(--accent);
    color: #fff;
}

button.primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

button.primary:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

button.secondary {
    background: #fff;
    color: var(--fg);
    border-color: var(--border);
}

button.secondary:hover {
    background: #f1f5f9;
}

.honeypot {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.consent {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    margin: 1rem 0;
    font-size: 0.875rem;
}

/* Сжать зазор между двумя соседними галочками согласия (consent_truthful + consent_pdn). */
.consent + .field-error:empty {
    min-height: 0;
    margin-top: 0;
}
.consent + .field-error + .consent {
    margin-top: 0.5rem;
}

.consent input[type="checkbox"] {
    margin-top: 0.2rem;
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.consent a {
    color: var(--accent);
    text-decoration: underline;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert.error {
    background: #fef2f2;
    color: var(--error);
    border: 1px solid #fecaca;
}

.alert.ok {
    background: #f0fdf4;
    color: var(--ok);
    border: 1px solid #bbf7d0;
}

.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-right: 0.5rem;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

footer {
    margin-top: 1.5rem;
    color: var(--muted);
    font-size: 0.8rem;
    text-align: center;
}
footer .client-ip {
    margin-top: 0.5rem;
    font-size: 0.7rem;
    color: #94a3b8;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* === Multi-phone block === */
.phones-list .field { margin-bottom: 0.5rem; }

.phone-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.phone-row input {
    flex: 1;
    min-width: 0;
}

.icon-btn {
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: #fff;
    color: var(--fg);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover { background: #f1f5f9; }
.icon-btn.add { color: var(--accent); border-color: var(--accent); }
.icon-btn.add:hover { background: rgba(37, 99, 235, 0.08); }
.icon-btn.remove:hover { color: var(--error); border-color: var(--error); }

/* === Bot CTA === */
.bot-cta {
    margin-top: 1.5rem;
    padding: 1.25rem;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #eef2ff 0%, #ddeafe 100%);
    border: 1px solid #c7d2fe;
    text-align: left;
}

.bot-cta h3 {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
    color: var(--fg);
}

.bot-cta p {
    margin: 0 0 0.75rem;
    color: var(--fg);
    font-size: 0.9rem;
}

.bot-cta ul {
    margin: 0 0 1rem;
    padding-left: 1.25rem;
    font-size: 0.9rem;
    color: var(--fg);
}

.bot-cta ul li { margin-bottom: 0.25rem; }

.bot-cta .btn-tg {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #229ED9;
    color: #fff;
    text-decoration: none;
    padding: 0.65rem 1.1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}

.bot-cta .btn-tg:hover { background: #1a87bb; }
.bot-cta .btn-tg svg { width: 1.1rem; height: 1.1rem; flex-shrink: 0; }
