/* --- 1. Базовые настройки --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background-color: #f0f2f5;
    color: #1f2937;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Скроллбары */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

/* --- 2. ГЛАВНАЯ СЕТКА (LAYOUT) --- */
.beam-calc-container {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    max-width: 100%;
    align-items: stretch; /* Растягиваем колонки по высоте */
}

/* ВНЕШНЯЯ обертка сайдбара */
.sidebar {
    flex: 0 0 360px;
    width: 360px;
    position: relative; /* Нужно для позиционирования внутреннего блока */
    min-height: 450px; /* Минимальная высота, чтобы не схлопывался */
}

/* ВНУТРЕННИЙ блок сайдбара, который будет скроллиться */
.sidebar-inner-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    overflow-y: auto; /* Включаем внутренний скролл */
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 3px; /* Место для скроллбара и теней */
}

/* ПРАВАЯ КОЛОНКА (Холст) */
.main-content {
    flex: 1; 
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* НИЖНИЙ БЛОК (Отчет) */
#result, #result1 {
    flex: 0 0 100%; 
    order: 100;
    width: 100%;
    margin-top: 20px;
    background-color: #fff;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e7eb;
}

/* --- 3. Карточки и Заголовки --- */
.parameters-section,
.load-section,
.distance-controls-wrapper,
#canvasContainer,
.header-description {
    background-color: #fff;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    border: 1px solid #e5e7eb;
}

.header-description { margin-bottom: 30px; }
.header-description h2 { text-align: center; font-size: 28px !important; margin-bottom: 15px; color: #111827; }
.header-description p { text-align: center; color: #4b5563; max-width: 800px; margin: 0 auto 30px auto; }

.features-title { font-weight: 700; color: #374151; border-bottom: 2px solid #f3f4f6; padding-bottom: 10px; margin-bottom: 15px; }
.features-list { 
    list-style: none; 
    padding: 0; 
    display: grid; 
    grid-template-columns: 1fr; /* Одна колонка на всю ширину */
    gap: 12px; 
}
.features-list li { position: relative; padding-left: 28px; color: #4b5563; }
.features-list li::before { content: '✔'; position: absolute; left: 0; color: #10b981; font-weight: bold; }

h3 {
    font-size: 18px !important;
    font-weight: 700 !important;
    color: #1f2937;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f3f4f6;
}

/* --- 4. Элементы управления --- */
.parameter-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}
.parameter-item label { font-size: 14px; font-weight: 500; color: #374151; flex: 1; }
input[type="text"], input[type="number"], select {
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    background-color: #fff;
    transition: all 0.2s;
    width: 100%;
}
.parameter-item input { max-width: 120px; }
#custom_q, #custom_F, #custom_M, #custom_RA, #custom_RB, #custom_MA, #custom_MB, #custom_PointA, #custom_PointB, #custom_RAx, #custom_RBx { max-width: 100%; }
input:focus, select:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }
input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: #3b82f6; }

/* --- 5. ФОРМА НАГРУЗОК --- */
.load-group-accordion { border: 1px solid #e5e7eb; border-radius: 10px; margin-bottom: 12px; overflow: hidden; }
.load-group-summary { padding: 14px; background-color: #f9fafb; cursor: pointer; list-style: none; font-weight: 600; color: #374151; display: flex; justify-content: space-between; align-items: center; }
.load-group-summary:hover { background-color: #f3f4f6; }
.load-group-summary h3 { margin: 0; border: none; padding: 0; font-size: 15px !important; }
.load-group-summary h3::after { content: '▼'; font-size: 12px; color: #9ca3af; margin-left: 10px; display: inline-block; transition: transform 0.2s;}
.load-group-accordion[open] .load-group-summary h3::after { transform: rotate(180deg); }
.load-item { padding: 20px; background: #fff; border-top: 1px solid #e5e7eb; display: flex; flex-direction: column; gap: 15px; }
.load-field { display: flex; align-items: flex-start; gap: 15px; width: 100%; }
.load-field > label { flex: 0 0 auto; min-width: 30px; width: auto; padding-top: 10px; font-weight: 700; font-size: 15px; color: #111827; text-align: right; }
.load-field .input-container { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.load-field input { max-width: 100%; padding: 10px; font-size: 15px; }
.load-field small { font-size: 13px; color: #6b7280; line-height: 1.4; }
.load-field small b { color: #374151; }
.load-field small code { background: #f3f4f6; padding: 2px 4px; border-radius: 4px; font-family: monospace; }

/* --- 6. Кнопки --- */
button { display: inline-flex; justify-content: center; align-items: center; padding: 10px 20px; border-radius: 8px; border: none; font-weight: 600; font-size: 14px; cursor: pointer; transition: transform 0.1s, background-color 0.2s; }
button:active { transform: scale(0.98); }
.add-btn { background-color: #10b981; color: white; width: 100%; margin-top: 10px; }
.add-btn:hover { background-color: #059669; }
.remove-btn { background-color: #ef4444; color: white; padding: 8px 12px; font-size: 13px; align-self: flex-end; width: auto;}
.remove-btn:hover { background-color: #dc2626; }
.info-btn { background-color: #3b82f6; color: white; width: 100%; }
.info-btn:hover { background-color: #2563eb; }
.rotate-btn { background-color: #6b7280; color: white; padding: 6px 12px; font-size: 12px;}
.distance-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-start; /* Выравниваем по левому краю */
    align-items: center;
    margin-bottom: 15px;
}

/* Ограничиваем ширину инпута только внутри этого блока */
.distance-controls input[type="number"] {
    width: 120px !important; /* Фиксированная небольшая ширина */
    flex: 0 0 auto;
}

.distance-controls label {
    flex: 0 0 auto; /* Чтобы текст не растягивался */
    margin-right: 5px;
}

.distance-controls button {
    width: auto;
    margin: 0;
    flex: 0 0 auto;
}

/* --- 7. Выбор типа балки --- */
/* Делаем так, чтобы label был сверху */
.beam-selector-container {
    flex-direction: column !important;
    align-items: flex-start !important;
}

.beam-type-selector { 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
    margin-top: 5px; 
    width: 100%; /* Кнопки на всю ширину */
}
.beam-type-button { display: flex; align-items: center; gap: 15px; padding: 12px; background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; cursor: pointer; color: #4b5563; transition: all 0.2s; }
.beam-type-button:hover { background-color: #f9fafb; border-color: #9ca3af; }
.beam-type-button.active { border-color: #3b82f6; background-color: #eff6ff; color: #1d4ed8; box-shadow: 0 0 0 1px #3b82f6; }
.beam-type-button svg { width: 60px; height: auto; }

/* --- 8. Канвас --- */
#canvasContainer { display: flex; justify-content: center; align-items: center; min-height: 450px; padding: 10px; overflow: hidden; }
canvas { max-width: 100%; height: auto !important; }

/* --- 9. Нижняя панель действий --- */
#main-controls-container { background: #fff; padding: 24px; border-radius: 16px; border: 1px solid #e5e7eb; display: flex; justify-content: center; align-items: center; flex-wrap: wrap; }
#action-buttons-wrapper { display: flex; gap: 15px; flex-wrap: wrap; justify-content: center; }
#action-buttons-wrapper button { padding: 12px 24px; font-size: 16px; width: auto; }

/* --- 10. Попап --- */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999; display: none; justify-content: center; align-items: center; }
.modal.modal-active { display: flex; animation: fadeIn 0.2s ease-out; }
.modal-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }
.modal-content { position: relative; background: #fff; padding: 40px; width: 90%; max-width: 800px; max-height: 85vh; overflow-y: auto; border-radius: 16px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); z-index: 10000; }
.modal-close-btn { position: absolute; top: 15px; right: 20px; font-size: 28px; background: transparent; border: none; color: #9ca3af; cursor: pointer; }
.modal-close-btn:hover { color: #111827; }

/* --- 11. Валидация --- */
.input-error { border-color: #ef4444 !important; background-color: #fef2f2; }
.error-message { color: #ef4444; font-size: 12px; margin-top: 4px; display: block; width: 100%; }

/* --- 12. Адаптивность --- */
@media (max-width: 900px) {
    .beam-calc-container { 
        display: flex; /* На мобильном возвращаем flex для простоты */
        flex-direction: column; 
    }
    
    .sidebar { 
        flex: 0 0 auto; 
        width: 100%; 
        height: auto; 
        max-height: none; /* Убираем ограничение высоты */
        overflow: visible; /* Убираем скролл */
        position: static;
    }
    
    /* --- ИСПРАВЛЕНИЕ ДЛЯ МОБИЛЬНЫХ --- */
    .sidebar-inner-wrapper {
        position: static; /* Возвращаем в поток */
        overflow: visible;
        height: auto;
        padding: 0;
    }
    
    .main-content { 
        width: 100%; 
    }
    
    .features-list { grid-template-columns: 1fr; }
    #action-buttons-wrapper button { width: 100%; }
    #distance-controls-section {
        display: none !important; /* Скрываем блок на мобильных */
    }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Таблица Верещагина */
.vereshchagin-table { width: 100%; border-collapse: collapse; margin-top: 20px; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; }
.vereshchagin-table th, .vereshchagin-table td { padding: 12px; border-bottom: 1px solid #e5e7eb; text-align: center; }
.vereshchagin-table thead th { background-color: #f9fafb; font-weight: 600; color: #374151; }

/* --- СТИЛИ ДЛЯ СТИКИ-БЛОКА --- */
#sticky-beam-container {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 140px; /* Высота плашки */
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid #ccc;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    display: none; /* Скрыт по умолчанию */
    justify-content: center;
    align-items: center;
    transition: transform 0.3s ease-in-out;
    transform: translateY(100%); /* Спрятан вниз */
    padding-bottom: 10px; /* Учет safe-area на iPhone */
}

/* Показываем только на мобильных и когда добавлен класс active */
@media (max-width: 900px) {
    #sticky-beam-container.active {
        display: flex;
        transform: translateY(0);
    }
}

/* Иконка вопроса */
.help-icon {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 20px;
    height: 20px;
    background-color: #9ca3af; /* Серый цвет */
    color: white;
    border-radius: 50%;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
}

.help-icon:hover {
    background-color: #3b82f6; /* Синий при наведении */
}

/* Стили для контейнера лейбла и иконки, чтобы они стояли в ряд */
.label-with-icon {
    display: flex; 
    align-items: center; 
    gap: 8px; 
    margin-bottom: 4px;
}
/* Добавить в секцию <style> */
button:disabled {
    background-color: #d1d5db !important; /* Серый цвет */
    color: #6b7280 !important;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Добавить в секцию <style> */
.global-validation-error {
    display: none; /* Скрыто по умолчанию */
    margin-top: 15px;
    padding: 10px 20px;
    background-color: #f8d7da; /* Светло-красный фон */
    color: #721c24;            /* Темно-красный текст */
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    width: 100%;
    max-width: 600px; /* Чтобы не растягивалось слишком сильно */
    animation: fadeIn 0.3s ease-in-out;
}

    /* Стиль для заблокированных кнопок */
    button:disabled {
        background-color: #d1d5db !important; /* Серый фон */
        color: #9ca3af !important;           /* Серый текст */
        cursor: not-allowed !important;      /* Курсор запрета */
        transform: none !important;          /* Убираем эффект нажатия */
        box-shadow: none !important;
    }
    
    /* Стиль сообщения об ошибке под кнопками */
    .global-validation-error {
        color: #ef4444;
        background-color: #fef2f2;
        border: 1px solid #fee2e2;
        padding: 10px;
        border-radius: 6px;
        margin-top: 10px;
        text-align: center;
        font-weight: 500;
        display: none; /* Скрыто по умолчанию */
        animation: fadeIn 0.3s ease-out;
    }

/* --- СТИЛИ ДЛЯ КОМПАКТНОГО ОТЧЕТА (Вставить в конец <style>) --- */
#result1 h2, 
#result1 h3, 
#result1 h4, 
#result1 p {
    margin-top: 5px !important;
    margin-bottom: 5px !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    line-height: 1.2 !important;
}

		.calc-step-row {
			display: flex;
			align-items: center;
			gap: 20px;
			page-break-inside: avoid; /* Не разрывать строку */
		}
.calc-step-math {
    flex: 1;
    min-width: 400px;
}
		.calc-step-canvas img {
			max-width: 800px !important; /* Ограничиваем ширину картинки */
			height: auto;
		}

@media (max-width: 768px) {
    .calc-step-row { flex-direction: column; }
    .calc-step-canvas { flex: 1; width: 100%; }
}

/* Убираем гигантские отступы у самих формул MathJax */
#result1 mjx-container {
    margin: 2px 0 !important;
}
#result1 mjx-container[display="true"] {
    margin: 5px 0 !important;
}

/* Убираем лишние отступы у блоков отчета */
.report-beam-block {
    margin-bottom: 15px !important;
    padding-bottom: 15px !important;
    border-bottom: 1px dashed #ccc;
}

.container_5 {
            max-width: 800px;
            width: 100%;
        }
        .equation {
            text-align: center;
            font-size: 1.25em;
            margin-bottom: 40px;
        }
        .definitions {
            margin: 0 auto 50px auto;
            font-size: 16px;
            line-height: 1.6;
        }
        .definitions table {
            border-collapse: collapse;
        }
        .definitions td {
            vertical-align: top;
            padding-bottom: 12px;
        }
        .definitions td:first-child {
            padding-right: 20px;
        }
        .diagram-container {
            text-align: center;
        }

/* --- НОВЫЙ ДИЗАЙН КАРТОЧЕК НАГРУЗОК И ПОПАПОВ --- */
.loads-summary-container { display: flex; flex-direction: column; gap: 10px; margin-bottom: 15px; }
.load-card { display: flex; justify-content: space-between; align-items: center; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px; transition: all 0.2s; }
.load-card:hover { border-color: #cbd5e1; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.load-card-info { display: flex; flex-direction: column; gap: 4px; }
.load-card-title { font-weight: 700; font-size: 14px; color: #1e293b; }
.load-card-desc { font-size: 13px; color: #64748b; }
.load-card-actions { display: flex; gap: 8px; }
.icon-btn { background: none; border: none; cursor: pointer; padding: 6px; border-radius: 4px; display: flex; align-items: center; justify-content: center; transition: background 0.2s; }
.icon-btn.edit:hover { background: #e0f2fe; color: #2563eb; }
.icon-btn.delete:hover { background: #fee2e2; color: #dc2626; }
.add-load-buttons { display: grid; grid-template-columns: 1fr; gap: 8px; }
.add-load-btn { background: #fff; border: 1px dashed #94a3b8; color: #475569; padding: 10px; border-radius: 8px; font-weight: 500; transition: all 0.2s; cursor: pointer;}
.add-load-btn:hover { background: #f1f5f9; border-color: #3b82f6; color: #2563eb; }
.modal-form-grid { display: grid; grid-template-columns: 1fr; gap: 15px; margin-top: 20px; }
.modal-form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; padding-top: 15px; border-top: 1px solid #e5e7eb; }
	
