/*
 * АВПКО - Исправленные CSS стили с правильной подсветкой опасных отказов
 */

/* ===== ОСНОВНЫЕ СТИЛИ ДЛЯ СЕЛЕКТОРА МЕТОДОВ ===== */
.method-selector {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.method-selector label {
    font-weight: 600;
    font-size: 16px;
    color: #495057;
    margin-bottom: 10px;
    display: block;
}

.method-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.method-btn {
    padding: 10px 20px;
    border: 2px solid #dee2e6;
    background: #ffffff;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 500;
    color: #495057;
    position: relative;
    overflow: hidden;
}

.method-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.method-btn.active {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border-color: #007bff;
    box-shadow: 0 4px 12px rgba(0,123,255,0.3);
}

.method-btn.active:hover {
    background: linear-gradient(135deg, #0056b3, #004085);
    transform: translateY(-1px);
}

/* ===== СТИЛИ ДЛЯ КОНТЕЙНЕРА С ФИКСИРОВАННЫМИ ЗАГОЛОВКАМИ ===== */
.table-container-fixed {
    max-height: 600px;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    position: relative;
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Фиксированные заголовки */
.avpko-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    background: white;
    position: relative;
}

.avpko-table .fixed-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.avpko-table th {
    padding: 8px 6px;
    text-align: left;
    border-bottom: 2px solid #dee2e6;
    font-size: 10px;
    font-weight: 600;
    color: #495057;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: white;
    position: sticky;
    top: 0;
    z-index: 100;
    white-space: nowrap;
    min-width: 100px;
}

.avpko-table td {
    padding: 6px 4px;
    border-bottom: 1px solid #dee2e6;
    font-size: 12px;
    vertical-align: middle;
    min-width: 100px;
    position: relative;
}

/* ===== ИСПРАВЛЕННЫЕ СТИЛИ ДЛЯ ПОДСВЕТКИ ОПАСНЫХ ОТКАЗОВ ===== */

/* Критические отказы - красная подсветка всей строки */
.critical-row {
    position: relative;
}

.critical-row td {
    background-color: #f8d7da !important;
    border-left: 4px solid #dc3545 !important;
    font-weight: bold !important;
    color: #721c24 !important;
}

.critical-row td:first-child {
    position: relative;
}

.critical-row td:first-child::before {
    content: '⚠️ КРИТИЧЕСКИЙ';
    position: absolute;
    top: 2px;
    right: 2px;
    background: #dc3545;
    color: white;
    padding: 1px 4px;
    border-radius: 2px;
    font-size: 8px;
    font-weight: bold;
    z-index: 10;
    white-space: nowrap;
}

/* Опасные отказы - красная рамка и подчеркивание */
.danger-row td {
    background-color: #ffe6e6 !important;
    border-left: 2px solid #dc3545 !important;
    font-weight: 500 !important;
}

.danger-row .failure-mode-cell,
.danger-row .failure-cause-cell,
.danger-row .end-effect-cell {
    text-decoration: underline !important;
    color: #721c24 !important;
}

/* Предупреждения - желтая подсветка */
.warning-row td {
    background-color: #fff3cd !important;
    border-left: 2px solid #ffc107 !important;
    color: #856404 !important;
}

.warning-row .failure-mode-cell,
.warning-row .failure-cause-cell {
    color: #856404 !important;
}

/* ===== СТИЛИ ЗАГОЛОВКОВ ДЛЯ РАЗНЫХ МЕТОДОВ ===== */
.original-header th {
    background: linear-gradient(135deg, #f8e8f4, #f3d4e8) !important;
    border-bottom: 2px solid #e83e8c !important;
}

.qualitative-header th {
    background: linear-gradient(135deg, #e8f4f8, #d1ecf1) !important;
    border-bottom: 2px solid #17a2b8 !important;
}

.quantitative-header th {
    background: linear-gradient(135deg, #f8f4e8, #f0f3d1) !important;
    border-bottom: 2px solid #28a745 !important;
}

.severity-b123-header th {
    background: linear-gradient(135deg, #fff3e0, #ffe0b2) !important;
    border-bottom: 2px solid #ff9800 !important;
}

.gost-27310-header th {
    background: linear-gradient(135deg, #f3e5f5, #e1bee7) !important;
    border-bottom: 2px solid #9c27b0 !important;
}

/* ===== СТИЛИ ДЛЯ МОДАЛЬНОГО ОКНА ===== */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 12px;
    width: 80%;
    max-width: 1000px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: slideDown 0.3s ease;
    max-height: 90vh;
    overflow: hidden;
}

@keyframes slideDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 20px 30px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
}

.modal-header h4 {
    margin: 0;
    color: #495057;
    font-weight: 600;
    font-size: 18px;
}

.modal-body {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

/* ===== СТИЛИ ДЛЯ СЕЛЕКТОРА МЕРОПРИЯТИЙ ===== */
.measures-selector {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
}

.measures-selector h5 {
    margin-bottom: 15px;
    color: #495057;
    font-weight: 600;
    font-size: 16px;
}

.measures-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 10px;
    background: #f8f9fa;
}

.measure-item {
    padding: 8px;
    margin-bottom: 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    font-size: 13px;
    line-height: 1.4;
}

.measure-item:hover {
    background-color: #e9ecef;
    border-color: #007bff;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.measure-item.selected {
    background-color: #e3f2fd;
    border-color: #2196f3;
    box-shadow: 0 2px 8px rgba(33,150,243,0.2);
}

.measure-item strong {
    color: #495057;
    font-size: 12px;
    display: block;
    margin-bottom: 4px;
}

.measure-item small {
    color: #6c757d;
    font-size: 11px;
}

/* ===== СТИЛИ ДЛЯ ФОРМЫ ДОБАВЛЕНИЯ МЕРОПРИЯТИЙ ===== */
.add-new-measure h5 {
    margin-bottom: 15px;
    color: #495057;
    font-weight: 600;
    font-size: 16px;
}

.measure-form {
    padding: 15px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #f8f9fa;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.measure-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #495057;
    font-size: 13px;
}

.measure-form input,
.measure-form select,
.measure-form textarea {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 13px;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.measure-form input:focus,
.measure-form select:focus,
.measure-form textarea:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.1);
    outline: none;
}

/* ===== СТИЛИ ДЛЯ КНОПОК ===== */
.btn-add, .btn-apply {
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 80px;
}

.btn-add:hover, .btn-apply:hover {
    background: linear-gradient(135deg, #20c997, #17a2b8);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(40,167,69,0.3);
}

.btn-measures {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    font-weight: 500;
    margin-bottom: 5px;
    width: 100%;
    transition: all 0.2s ease;
}

.btn-measures:hover {
    background: linear-gradient(135deg, #0056b3, #004085);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,123,255,0.3);
}

.btn-calculate {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    margin-top: 20px;
    transition: all 0.2s ease;
}

.btn-calculate:hover {
    background: linear-gradient(135deg, #0056b3, #004085);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,123,255,0.3);
}

.close {
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #aaa;
    transition: color 0.2s ease;
    padding: 5px;
    border-radius: 50%;
}

.close:hover {
    color: #000;
    background: rgba(0,0,0,0.1);
}

/* ===== СТИЛИ ДЛЯ ПОЛЕЙ ВВОДА В ТАБЛИЦЕ ===== */
.avpko-table input,
.avpko-table select,
.avpko-table textarea {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid #ced4da;
    border-radius: 2px;
    font-size: 11px;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.avpko-table input:focus,
.avpko-table select:focus,
.avpko-table textarea:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 1px rgba(0,123,255,0.1);
    outline: none;
}

.avpko-table input[readonly] {
    background-color: #f8f9fa;
    color: #6c757d;
}

.avpko-table textarea {
    min-height: 40px;
    resize: vertical;
    font-family: inherit;
}

/* ===== СПЕЦИАЛЬНЫЕ СТИЛИ ДЛЯ ЯЧЕЕК ===== */
.failure-mode-cell,
.failure-cause-cell {
    font-weight: 500;
    max-width: 200px;
    word-wrap: break-word;
}

.end-effect-cell {
    font-weight: 600;
    text-align: center;
}

.criticality,
.cm-value,
.cr-value,
.k-value,
.criticality-score {
    font-weight: 600;
    text-align: center;
    color: #495057;
}

.severity-category,
.severity-category-b123 {
    font-weight: 600;
    text-align: center;
    font-size: 14px;
}

.criticality-matrix {
    font-weight: 600;
    text-align: center;
    font-family: monospace;
}

/* ===== АДАПТИВНОСТЬ ===== */
@media (max-width: 1200px) {
    .modal-content {
        width: 90%;
        margin: 3% auto;
    }

    .measures-selector {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .method-buttons {
        flex-direction: column;
    }

    .method-btn {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 2% auto;
    }

    .modal-body {
        padding: 15px;
    }

    .measure-form {
        padding: 10px;
    }

    .table-container-fixed {
        max-height: 400px;
    }

    .avpko-table th,
    .avpko-table td {
        padding: 4px 2px;
        font-size: 10px;
        min-width: 80px;
    }

    .avpko-table th {
        font-size: 9px;
    }

    .critical-row td:first-child::before {
        font-size: 7px;
        padding: 1px 2px;
    }
}

/* ===== УЛУЧШЕННАЯ ПРОКРУТКА ===== */
.table-container-fixed::-webkit-scrollbar,
.measures-list::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-container-fixed::-webkit-scrollbar-track,
.measures-list::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-container-fixed::-webkit-scrollbar-thumb,
.measures-list::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.table-container-fixed::-webkit-scrollbar-thumb:hover,
.measures-list::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ===== АНИМАЦИИ ===== */
@keyframes highlight {
    0% { background-color: #fff3cd; }
    100% { background-color: transparent; }
}

.avpko-table input:focus,
.avpko-table select:focus,
.avpko-table textarea:focus {
    animation: highlight 0.5s ease;
}

/* ===== ИНДИКАТОРЫ ЭФФЕКТИВНОСТИ ===== */
.effectiveness-indicator {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
    margin-left: 5px;
}

.effectiveness-high {
    background: #d4edda;
    color: #155724;
}

.effectiveness-medium {
    background: #fff3cd;
    color: #856404;
}

.effectiveness-low {
    background: #f8d7da;
    color: #721c24;
}

/* ===== КОНТРАСТ ДЛЯ ВАЖНЫХ ЭЛЕМЕНТОВ ===== */
.critical-row input,
.critical-row select,
.critical-row textarea {
    border-color: #dc3545 !important;
    background-color: rgba(248, 215, 218, 0.5) !important;
}

.danger-row input,
.danger-row select,
.danger-row textarea {
    border-color: #dc3545 !important;
    background-color: rgba(255, 230, 230, 0.5) !important;
}

.warning-row input,
.warning-row select,
.warning-row textarea {
    border-color: #ffc107 !important;
    background-color: rgba(255, 243, 205, 0.5) !important;
}

/* ===== ДОПОЛНИТЕЛЬНЫЕ УЛУЧШЕНИЯ UX ===== */
.loading {
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Выделение активных элементов */
.avpko-table tr:hover {
    background-color: rgba(0,123,255,0.05) !important;
}

.avpko-table tr:hover td {
    background-color: rgba(0,123,255,0.05) !important;
}

/* Сохраняем подсветку опасности при hover */
.critical-row:hover td {
    background-color: #f5c6cb !important;
}

.danger-row:hover td {
    background-color: #ffd6d6 !important;
}

.warning-row:hover td {
    background-color: #ffeaa7 !important;
}