/* Business Insight Pro — premium, strict, client-side only */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #0f172a;
    --primary-hover: #1e293b;
    --accent: #3b82f6;
    --radius: 12px;
    --radius-lg: 20px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 40px -12px rgba(0,0,0,0.12);
    --font: 'DM Sans', system-ui, -apple-system, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px 48px;
}

/* Header */
.header {
    padding: 48px 0 40px;
    border-bottom: 1px solid var(--border);
}

.header-inner {
    text-align: center;
}

.logo {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.tagline {
    font-size: 0.9375rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Steps nav */
.steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px 0;
    font-size: 0.875rem;
}

.step-sep {
    color: var(--border);
}

.step-link {
    color: var(--text-muted);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: var(--radius);
    transition: all 0.2s ease;
}

.step-link:hover {
    background: var(--bg);
    color: var(--primary);
}

.step-link.active {
    background: var(--primary);
    color: white;
    font-weight: 600;
}

/* Main */
.main {
    padding: 32px 0;
}

.step-section {
    animation: fadeIn 0.25s ease;
}

.step-section.hidden {
    display: none !important;
}

.section-inner {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 40px;
}

.section-title {
    font-size: 1.375rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 8px;
}

.section-desc {
    font-size: 0.9375rem;
    color: #475569; /* Улучшенный контраст вместо #64748b */
    margin-bottom: 32px;
}

/* Form */
.audit-form .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-group label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text);
}

.tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: var(--accent); /* Изменено с var(--border) */
    color: white; /* Изменено с var(--text-muted) для лучшей видимости */
    border-radius: 50%;
    font-size: 11px;
    cursor: help;
    transition: background 0.2s ease;
}

.tooltip-icon:hover {
    background: var(--primary);
}

.field-group input,
.field-group select {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-family: var(--font);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s;
}

.field-group input:focus,
.field-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); /* Усилена тень */
}

.field-group input[type=number]::-webkit-inner-spin-button,
.field-group input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.field-group input[type=number] {
    -moz-appearance: textfield;
}

.form-actions {
    margin-top: 8px;
}

.error-msg {
    font-size: 0.875rem;
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 20px;
    max-width: 480px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: var(--font);
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15); /* Добавлена тень для выделения */
    font-size: 1rem; /* Увеличено с 0.9375rem */
    padding: 14px 28px; /* Увеличено для большей заметности */
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2); /* Усиленная тень при hover */
    transform: translateY(-1px); /* Легкое поднятие для интерактивности */
    transition: all 0.2s ease;
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.15);
}

.btn-primary:disabled {
    opacity: 0.5; /* Уменьшено с 0.8 для более явного состояния */
    background: #94a3b8; /* Серый цвет вместо черного */
    cursor: not-allowed;
    position: relative;
}

.btn-primary:disabled:hover {
    transform: none; /* Убрать hover эффект для disabled */
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15);
}

.btn-secondary:disabled {
    opacity: 0.8;
    cursor: not-allowed;
    position: relative;
}

/* Loading spinner animation */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-primary:disabled .loading-spinner {
    border-color: rgba(255, 255, 255, 0.3);
    border-top-color: white;
}

.btn-secondary:disabled .loading-spinner {
    border-color: rgba(15, 23, 42, 0.3);
    border-top-color: var(--text);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg);
}

.btn-block {
    width: 100%;
}

/* Modules toolbar */
.modules-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    justify-content: flex-start;  /* Элементы слева, рядом друг с другом */
}

.select-all {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
}

.select-all input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.total-cost {
    font-size: 1.125rem; /* Уменьшено с 1.25rem */
    font-weight: 600; /* Уменьшено с 700 */
    color: var(--text-muted); /* Изменено с var(--text) для снижения внимания */
    padding: 8px 20px;
    background: var(--surface); /* Изменено с var(--bg) для меньшего контраста */
    border-radius: 999px;
    border: 1px solid var(--border);
}

/* Module cards */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.module-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.module-card {
    cursor: pointer; /* Указать, что карточка кликабельна */
    transition: all 0.2s ease;
}

.module-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
    transform: translateY(-2px);
}

.module-card:active {
    transform: translateY(0);
}

/* Визуальное выделение выбранных модулей */
.module-card:has(input:checked) {
    border-color: var(--accent);
    background: #f0f7ff; /* Легкий голубой фон */
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.module-check {
    margin-top: 2px;
}

.module-check input {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
    cursor: pointer;
}

.module-content {
    flex: 1;
    min-width: 0;
}

.module-title {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text);
    margin-bottom: 6px;
    line-height: 1.35;
}

.module-insight {
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 8px;
    line-height: 1.4;
}

.module-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    background: var(--bg);
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    margin-bottom: 6px;
}

.module-price {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Payment step */
.section-inner.payment-box {
    max-width: 420px;
    margin: 0 auto;
}

.payment-form .field-group {
    margin-bottom: 20px;
}

.payment-amount {
    margin: 24px 0;
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.payment-label {
    display: block;
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.payment-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

.payment-note {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.5;
}

#completePaymentBtn {
    margin-top: 8px;
}

/* Full report */
.report-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
}

.full-report {
    font-size: 0.9375rem;
    line-height: 1.4;  /* Уменьшено с 1.6 до 1.4 для более компактного размещения текста */
    background: white;
    color: #0f172a;
}

/* Обеспечиваем видимость для PDF генерации */
.step-section:not(.hidden) .full-report,
.full-report[data-pdf-ready="true"] {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.full-report .input-summary {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
    font-size: 0.875rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    page-break-after: avoid;  /* Изменено с always на avoid - разрыв создается первым модулем */
}

.full-report .input-summary h3 {
    grid-column: 1 / -1;
    font-size: 1rem;
    margin-bottom: 8px;
}

/* Первый модуль — начинается на новой странице после блока исходных данных */
.full-report .pdf-module:first-of-type {
    page-break-before: always;  /* Первый модуль создает разрыв страницы перед собой */
    padding-top: 15px;  /* Уменьшено с 12px до 15px - колонтитулы теперь на краях страницы */
    margin-top: 0;
}

.full-report .pdf-module {
    margin-bottom: 0;  /* Уменьшено с 28px до 0 для предотвращения пустых страниц */
    padding-bottom: 20px;  /* Уменьшено с 24px до 20px для более компактного размещения */
    padding-top: 18px;
    border-bottom: 1px solid var(--border);
    page-break-inside: avoid;  /* Модуль не разрывается посередине - переносится целиком на новую страницу если не помещается */
    orphans: 3;  /* Минимум 3 строки в начале страницы */
    widows: 3;   /* Минимум 3 строки в конце страницы */
}

/* Со 2-го модуля — каждый модуль начинается на новой странице */
.full-report .pdf-module:not(:first-of-type) {
    page-break-before: always;  /* Каждый модуль начинается на новой странице */
    padding-top: 25px;  /* Уменьшено с 40px до 25px - колонтитулы теперь на краях страницы */
    margin-top: 0;
}

.full-report .pdf-module:last-child {
    border-bottom: none;
    page-break-after: auto;  /* Последний модуль не создает разрыв страницы после себя */
}

.full-report .pdf-title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.full-report .pdf-insight {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 4px;
    margin-bottom: 10px;
    padding-left: 12px;
    border-left: 3px solid var(--border);
}

.full-report .pdf-desc {
    font-size: 0.9375rem;
    color: var(--text);
    margin-top: 8px;
    line-height: 1.4;  /* Уменьшено с 1.55 до 1.4 для более компактного размещения */
}

.full-report .pdf-formula {
    font-size: 0.8125rem;
    background: #f1f5f9;
    padding: 14px;
    border-radius: var(--radius);
    margin: 12px 0;
    color: #334155;
    font-family: ui-monospace, monospace;
    white-space: pre-wrap;
    overflow-x: auto;
}

.full-report .pdf-benchmark {
    font-size: 0.8125rem;
    background: #eff6ff;
    padding: 14px;
    border-radius: var(--radius);
    margin: 10px 0;
    color: #1e40af;
    white-space: pre-wrap;
}

.full-report .pdf-recommendation {
    font-size: 0.9375rem;
    background: #f0fdf4;
    padding: 14px;
    border-radius: var(--radius);
    margin: 12px 0;
    color: #166534;
    border-left: 4px solid #22c55e;
    line-height: 1.4;  /* Уменьшено с 1.5 до 1.4 для более компактного размещения */
}

.full-report .pdf-ref {
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 8px;
}

.full-report .pdf-ref a {
    color: var(--accent);
    text-decoration: none;
}

.full-report .pdf-ref a:hover {
    text-decoration: underline;
}

/* Print section (for PDF) — ширина под A4 (210mm), контент на всю страницу */
.print-report {
    padding: 24px;
    font-family: var(--font);
    background: white;
    color: #111;
    display: none;
    box-sizing: border-box;
    width: 794px; /* A4 210mm @ 96dpi */
    max-width: 100%;
}

.print-report .input-summary {
    background: #f9fafb;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
    font-size: 0.875rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    page-break-after: always;
}

.print-report .input-summary h3 {
    grid-column: 1 / -1;
    font-size: 1rem;
    margin-bottom: 8px;
    font-weight: 700;
}

.print-report .pdf-module:first-of-type {
    page-break-before: avoid;
    padding-top: 4px;
}

.print-report .pdf-module {
    margin-bottom: 0;  /* Уменьшено с 28px до 0 для предотвращения пустых страниц */
    padding-bottom: 24px;
    padding-top: 18px;
    border-bottom: 1px solid #e5e7eb;
    page-break-inside: avoid;  /* Модуль не разрывается посередине - переносится целиком на новую страницу если не помещается */
    page-break-after: avoid;  /* Предотвращает пустые страницы после коротких модулей */
    orphans: 3;
    widows: 3;
}

.print-report .pdf-module:not(:first-of-type) {
    page-break-before: always;  /* Каждый модуль начинается на новой странице */
    padding-top: 24px;
}

.print-report .pdf-title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 6px;
}

.print-report .pdf-insight {
    font-size: 0.875rem;
    color: #64748b;
    font-style: italic;
    margin-top: 4px;
    margin-bottom: 10px;
    padding-left: 12px;
    border-left: 3px solid #e2e8f0;
}

.print-report .pdf-desc {
    font-size: 0.9375rem;
    color: #0f172a;
    margin-top: 8px;
    line-height: 1.55;
}

.print-report .pdf-formula {
    font-size: 0.8125rem;
    background: #f1f5f9;
    padding: 14px;
    border-radius: 8px;
    margin: 12px 0;
    color: #334155;
    font-family: ui-monospace, monospace;
    white-space: pre-wrap;
    overflow-x: auto;
}

.print-report .pdf-benchmark {
    font-size: 0.8125rem;
    background: #eff6ff;
    padding: 14px;
    border-radius: 8px;
    margin: 10px 0;
    color: #1e40af;
    white-space: pre-wrap;
}

.print-report .pdf-recommendation {
    font-size: 0.9375rem;
    background: #f0fdf4;
    padding: 14px;
    border-radius: 8px;
    margin: 12px 0;
    color: #166534;
    border-left: 4px solid #22c55e;
    line-height: 1.5;
}

.print-report .pdf-ref {
    font-size: 0.8125rem;
    color: #64748b;
    font-style: italic;
    margin-top: 8px;
}

.print-report .pdf-ref a {
    color: #3b82f6;
    text-decoration: none;
}

/* Footer */
.footer {
    padding: 32px 0;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Плавная прокрутка */
html {
    scroll-behavior: smooth;
}

/* Улучшение видимости ошибок */
.error-msg {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Улучшение загрузки */
.loading-spinner {
    border-width: 3px; /* Увеличено для лучшей видимости */
}

/* Мобильные устройства (640px и меньше) */
@media (max-width: 640px) {
    body {
        font-size: 16px; /* Увеличен базовый размер для лучшей читаемости */
    }
    
    .app {
        padding: 0 16px 32px;
    }
    .header {
        padding: 32px 0 24px;
    }
    .logo {
        font-size: 1.5rem;
    }
    .section-inner {
        padding: 24px;
    }
    .modules-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .report-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    /* Улучшение типографики на мобильных */
    .field-group label {
        font-size: 0.875rem; /* Увеличено с 0.8125rem */
    }
    
    .tooltip-icon {
        font-size: 12px; /* Увеличено с 11px */
        width: 18px;
        height: 18px;
    }
    
    .section-title {
        font-size: 1.25rem;
    }
    
    /* Улучшение читаемости отчета */
    .full-report {
        line-height: 1.6; /* Увеличено с 1.4 */
    }
    
    .full-report .pdf-desc {
        line-height: 1.6;
        margin-bottom: 12px;
    }
}

/* Маленькие мобильные устройства (375px и меньше) */
@media (max-width: 375px) {
    .app {
        padding: 0 12px 24px;
    }
    
    .header {
        padding: 24px 0 20px;
    }
    
    .logo {
        font-size: 1.375rem;
    }
    
    .tagline {
        font-size: 0.875rem;
    }
    
    .section-inner {
        padding: 16px; /* Уменьшено с 24px */
    }
    
    .form-grid {
        grid-template-columns: 1fr; /* Одна колонка на маленьких экранах */
        gap: 16px;
    }
    
    .modules-grid {
        grid-template-columns: 1fr; /* Убрано minmax(320px, 1fr) */
        gap: 12px;
    }
    
    .modules-toolbar {
        gap: 12px;
    }
    
    .total-cost {
        font-size: 1.125rem; /* Уменьшено с 1.25rem */
        padding: 6px 16px;
    }
    
    .steps {
        font-size: 0.8125rem;
        gap: 4px;
        padding: 16px 0;
    }
    
    .btn {
        padding: 14px 20px; /* Увеличены для лучшей кликабельности */
        font-size: 1rem;
    }
}

/* Планшеты (641px - 1024px) */
@media (min-width: 641px) and (max-width: 1024px) {
    .app {
        padding: 0 32px 40px;
    }
    
    .form-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
    
    .modules-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

/* Большие экраны (1400px+) */
@media (min-width: 1400px) {
    .app {
        max-width: 1400px;
    }
    
    .section-inner {
        padding: 48px;
    }
}
