/* frontend/css/incidents.css */
.incidents-container {
    animation: fadeIn 0.3s ease;
    padding: 0;
}

/* Статистика */
.incident-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card-mini {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    border: 1px solid var(--border-color);
}

.stat-card-mini:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.stat-card-mini .stat-icon {
    width: 54px;
    height: 54px;
    background: var(--primary-light);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--primary-color);
}

.stat-card-mini .stat-icon.warning {
    background: #fff3e0;
    color: var(--warning-color);
}

.stat-card-mini .stat-icon.success {
    background: #e8f5e9;
    color: var(--success-color);
}

.stat-card-mini .stat-icon.danger {
    background: #fee2e2;
    color: var(--danger-color);
}

.stat-card-mini .stat-info h3 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 4px;
}

.stat-card-mini .stat-info p {
    font-size: 13px;
    color: var(--text-gray);
    margin: 0;
}

/* Таблица инцидентов */
.incidents-table-container {
    background: var(--white);
    border-radius: var(--border-radius);
    overflow-x: auto;
    border: 1px solid var(--border-color);
}

.incidents-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.incidents-table thead th {
    text-align: left;
    padding: 16px 20px;
    background: var(--bg-light);
    font-weight: 600;
    color: var(--text-dark);
    border-bottom: 1px solid var(--border-color);
}

.incidents-table tbody td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.incidents-table tbody tr:hover {
    background: var(--bg-light);
}

.loading-row {
    text-align: center;
    padding: 40px;
}

.loading-row td {
    text-align: center;
    padding: 40px !important;
}

.loading-spinner-small {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 12px;
    vertical-align: middle;
}

/* Бейджи статуса */
.status-badge-incident {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-badge-incident.registered {
    background: #e3f2fd;
    color: #1565c0;
}

.status-badge-incident.closed {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-badge-incident.draft {
    background: #f1f3f5;
    color: #495057;
}

.status-badge-incident.investigating {
    background: #fff3e0;
    color: #e65100;
}

.status-badge-incident.action-plan {
    background: #f3e8fd;
    color: #8e44ad;
}

/* Бейджи тяжести */
.severity-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

.severity-green {
    background: #e8f5e9;
    color: #2e7d32;
}

.severity-yellow {
    background: #fff8e1;
    color: #f57f17;
}

.severity-red {
    background: #ffebee;
    color: #c62828;
}

.incident-view-cause {
    color: #666;
    font-size: 13px;
    margin: 2px 0 8px;
}

.participants-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.participants-picker .checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
}

.participants-picker .checkbox-label input[type="checkbox"] {
    width: auto;
}

.hint-label {
    font-size: 12px;
    color: #888;
    margin-top: 4px;
}

.staff-checklist {
    display: flex;
    flex-direction: column;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 8px;
    background: var(--white, #fff);
}

.staff-checklist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s ease;
}

.staff-checklist-item:last-child {
    border-bottom: none;
}

.staff-checklist-item:hover {
    background: #f7f9fc;
}

.staff-checklist-item input[type="checkbox"] {
    width: auto;
    flex-shrink: 0;
}

.staff-checklist-item:has(input:checked) {
    background: #eef4ff;
    font-weight: 500;
}

.staff-checklist:empty::after {
    content: 'Нет доступных сотрудников';
    display: block;
    padding: 10px 12px;
    color: #999;
    font-size: 13px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
}

/* Кнопки действий */
.action-buttons-incident {
    display: flex;
    gap: 8px;
}

.action-icon {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-light);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-gray);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.action-icon:hover {
    background: var(--primary-light);
    color: var(--primary-color);
}

/* Форма */
.form-section {
    background: var(--bg-light);
    border-radius: var(--border-radius-sm);
    padding: 20px;
    margin: 20px 0;
}

.form-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 16px;
}

.form-section h4 i {
    margin-right: 8px;
    color: var(--primary-color);
}

.info-box.warning {
    background: #fff3e0;
    border-left: 4px solid var(--warning-color);
    padding: 16px;
    border-radius: 10px;
    margin: 16px 0;
    display: flex;
    gap: 12px;
}

.info-box.warning i {
    font-size: 20px;
    color: var(--warning-color);
}

.info-box.warning strong {
    color: #e65100;
}

.info-box.warning p {
    margin: 4px 0 0 0;
    font-size: 13px;
    color: #e65100;
}

/* Карточка просмотра инцидента */
.incident-view-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.incident-view-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 12px;
}

.incident-view-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    font-size: 13px;
    color: var(--text-gray);
}

.incident-view-meta i {
    width: 16px;
    margin-right: 6px;
    color: var(--primary-color);
}

.incident-view-section {
    margin-bottom: 24px;
}

.incident-view-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.incident-view-section h4 i {
    margin-right: 8px;
    color: var(--primary-color);
}

.incident-view-section p {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-dark);
    margin: 0;
}

.incident-view-patient {
    background: var(--bg-light);
    border-radius: 12px;
    padding: 16px;
}

.incident-view-patient p {
    margin: 8px 0;
    font-size: 13px;
}

.incident-view-patient strong {
    width: 100px;
    display: inline-block;
    color: var(--text-gray);
}

.inspection-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--primary-light);
    border-radius: 8px;
    color: var(--primary-color);
    text-decoration: none;
    font-size: 13px;
    transition: var(--transition);
}

.inspection-link:hover {
    background: var(--primary-color);
    color: white;
}

/* Пагинация */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 24px;
    padding: 16px;
}

.page-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--white);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-dark);
}

.page-btn:hover:not(:disabled) {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    font-size: 14px;
    color: var(--text-gray);
}

/* Адаптивность */
@media (max-width: 1024px) {
    .incident-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .incident-stats-grid {
        grid-template-columns: 1fr;
    }
    
    .filters-bar {
        flex-direction: column;
    }
    
    .filter-group {
        width: 100%;
    }
    
    .incidents-table-container {
        overflow-x: auto;
    }
    
    .incidents-table {
        min-width: 700px;
    }
    
    .action-buttons-incident {
        flex-wrap: wrap;
    }
}

/* Кнопка экстренного извещения */
.btn-emergency {
    background: #e65100;
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    margin-right: 10px;
}

.btn-emergency:hover {
    background: #bf360c;
    transform: translateY(-1px);
}

.btn-emergency i {
    margin-right: 8px;
}

.detail-section {
    margin-top: 20px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.detail-section h4 {
    margin-bottom: 10px;
    color: #2e8bd5;
}

.detail-row {
    margin-bottom: 8px;
    padding: 4px 0;
}

.type-badge {
    background: #e3f2fd;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
}

.status-badge.registered {
    background: #fff3e0;
    color: #e65100;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
}

.status-badge.closed {
    background: #e8f5e9;
    color: #2e7d32;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Разбор НС и план мероприятий - недостающие базовые классы формы */
.btn-outline {
    background: transparent;
    color: #2e8bd5;
    border: 1px solid #2e8bd5;
}

.btn-outline:hover {
    background: #e8f4f8;
}

.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.radio-group label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 400;
    font-size: 13px;
}

.analysis-subsection {
    border: 1px solid var(--border-color, #ecf0f1);
    background: var(--bg-light, #f8f9fa);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 14px;
}

.analysis-note {
    margin-top: 6px;
}

/* Кнопки Да/Нет/Неизвестно - точно тот же стиль, что у Да/Нет/Не применимо в чек-листах аудита (.assessment-option) */
.answer-btn-group {
    display: flex;
    gap: 8px;
    width: 100%;
}

.answer-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-dark, #2c3e50);
    cursor: pointer;
    text-align: center;
    user-select: none;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.answer-btn.selected[data-value="да"] {
    background: #f0fdf4;
    border-color: #22c55e;
    color: #15803d;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.15);
}

.answer-btn.selected[data-value="нет"] {
    background: #fef2f2;
    border-color: #ef4444;
    color: #b91c1c;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.15);
}

.answer-btn.selected[data-value="неизвестно"] {
    background: #f8fafc;
    border-color: #64748b;
    color: #334155;
    box-shadow: 0 2px 8px rgba(100, 116, 139, 0.15);
}

/* Загрузка файлов (разбор НС) - тот же паттерн, что в редакторе чек-листов */
.file-upload-area {
    border: 2px dashed var(--border-color, #ecf0f1);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.file-upload-area:hover,
.file-upload-area.drag-over {
    border-color: var(--primary-color, #2e8bd5);
    background: var(--primary-light, #e8f4f8);
}

.file-upload-area i {
    font-size: 26px;
    color: var(--primary-color, #2e8bd5);
    margin-bottom: 8px;
    display: block;
}

.file-upload-area p {
    color: var(--text-gray, #7f8c8d);
    font-size: 13px;
    margin: 0;
}

.selected-files-list {
    display: flex;
    flex-direction: column;
}

.selected-file {
    margin-top: 8px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: 13px;
    color: #2c3e50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.selected-file a {
    color: #2e8bd5;
    text-decoration: none;
}

.selected-file a:hover {
    text-decoration: underline;
}

.selected-file button {
    border: none;
    background: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 13px;
}

.selected-file .file-size-hint {
    color: #95a5a6;
    font-size: 11px;
    margin-left: 6px;
}

/* Разбор НС - полноэкранная страница в том же визуальном языке, что и редактор
   чек-листов/аудит (--white, --border-color, --border-radius, --primary-color) */
.investigation-page {
    background: transparent;
}

/* Ровно та же разметка шапки, что и .editor-header в редакторе чек-листов:
   кнопка "Назад" - заголовок - кнопки действий, без плашки/тени, на фоне страницы */
.investigation-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin: 0 0 24px;
    padding: 0;
    background: transparent;
    border-bottom: none;
    box-shadow: none;
}

.investigation-page-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-dark, #2c3e50);
    margin: 0;
}

.investigation-incident-ref {
    color: var(--text-gray, #7f8c8d);
    font-size: 15px;
    font-weight: 400;
    margin-left: 10px;
}

.investigation-page-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.investigation-page-body {
    padding: 0;
}

.investigation-page-body .form-section {
    background: var(--white, #fff);
    border: 1px solid var(--border-color, #ecf0f1);
    border-radius: var(--border-radius, 16px);
    padding: 14px 18px;
    margin-bottom: 14px;
}

.investigation-page-body .form-section h4 {
    display: flex;
    align-items: center;
    color: var(--text-dark, #2c3e50);
}

.investigation-page-body .form-section h4 i {
    color: var(--primary-color, #2e8bd5);
}

.investigation-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: start;
}

.investigation-two-col .form-section {
    margin-bottom: 0;
}

@media (max-width: 900px) {
    .investigation-two-col {
        grid-template-columns: 1fr;
    }
}

.investigation-page-body .form-section h4 {
    font-size: 13px;
    margin-bottom: 10px;
}

.investigation-page-body .form-group {
    margin-bottom: 10px;
}

.investigation-page-body .form-row {
    gap: 12px;
    margin-bottom: 0;
}

.investigation-page-body label {
    font-size: 12px;
    margin-bottom: 3px;
}

.investigation-page-body .form-control {
    padding: 6px 10px;
    font-size: 13px;
}

.investigation-page-body textarea.form-control {
    min-height: unset;
}

.investigation-page-body .hint-label {
    margin-top: 0;
}

.investigation-page-body .staff-checklist {
    max-height: 130px;
}

/* Участники - список строк в столбец (каждый участник на своей строке), а не одно текстовое поле */
.participants-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.participants-list-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.participants-list-row input {
    flex: 1;
}

.participants-list-row .remove-participant-row {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border: 1px solid var(--border-color, #ecf0f1);
    background: var(--white, #fff);
    border-radius: 8px;
    color: var(--text-gray, #7f8c8d);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.participants-list-row .remove-participant-row:hover {
    background: #fdecea;
    border-color: #e74c3c;
    color: #e74c3c;
}

.participants-list:empty::after {
    content: 'Участники не указаны';
    display: block;
    padding: 8px 0;
    color: var(--text-gray, #7f8c8d);
    font-size: 13px;
}

.btn-add-participant {
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px dashed var(--border-color, #ecf0f1);
    background: transparent;
    border-radius: 8px;
    color: var(--primary-color, #2e8bd5);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-add-participant:hover {
    background: var(--primary-light, #e8f4f8);
    border-style: solid;
}

/* План мероприятий - редактируемые ячейки прямо в таблице */
#incidentActionPlanTable .capa-inline-input {
    min-width: 110px;
    padding: 6px 8px;
    font-size: 13px;
}

#incidentActionPlanTable select.capa-inline-input {
    min-width: 130px;
}

#incidentActionPlanTable td {
    vertical-align: middle;
}

.investigation-page-body .analysis-subsection {
    padding: 8px 12px;
    margin-bottom: 8px;
}

.investigation-page-body .analysis-question {
    margin-bottom: 6px !important;
}

.investigation-page-body .analysis-question p {
    font-size: 12.5px !important;
}

.investigation-page-body .answer-btn {
    padding: 5px 10px;
    font-size: 12px;
    min-width: 80px;
}

.investigation-page-body .file-upload-area {
    padding: 12px;
}

.investigation-page-body .file-upload-area i {
    font-size: 20px;
    margin-bottom: 4px;
}

.investigation-page-header {
    padding: 10px 20px;
}

.investigation-page-header h2 {
    font-size: 16px;
}

/* Печать разбора НС - отдельный бланк (заполняется в JS перед печатью), а не сама интерактивная форма */
.investigation-print-document {
    display: none;
}

@media print {
    @page {
        margin: 10mm 14mm;
    }

    /* Убираем из потока все контейнеры приложения целиком (а не только
       делаем невидимыми) - иначе их высота остаётся зарезервированной и
       печать генерирует лишние пустые страницы */
    .incidents-container,
    #investigationPage,
    #actionPlanPage,
    .modal,
    .sidebar,
    .main-header {
        display: none !important;
    }

    body * {
        visibility: hidden;
    }

    #investigationPrintDocument,
    #investigationPrintDocument * {
        visibility: visible;
    }

    #investigationPrintDocument {
        display: block !important;
        position: static;
        background: #fff;
        padding: 0;
        font-size: 11.5px;
        color: #000;
        line-height: 1.4;
    }

    #investigationPrintDocument h1 {
        font-size: 16px;
        text-align: center;
        margin: 0 0 4px;
    }

    #investigationPrintDocument .print-order-ref {
        text-align: right;
        font-size: 11px;
        margin-bottom: 12px;
    }

    /* Разбивать по страницам можно свободно - "не разбивать" держим только
       на мелких, заведомо коротких блоках (см. .print-subsection/.print-question
       ниже), а не на всём разделе "5. Анализ" целиком, иначе он целиком
       перескакивает на новую страницу и оставляет пустой хвост предыдущей */
    #investigationPrintDocument .print-section {
        margin-bottom: 10px;
    }

    #investigationPrintDocument .print-subsection {
        margin-bottom: 8px;
        page-break-inside: avoid;
    }

    #investigationPrintDocument .print-section-title {
        font-weight: 700;
        margin-bottom: 5px;
    }

    #investigationPrintDocument .print-question {
        display: flex;
        justify-content: space-between;
        gap: 10px;
        border-bottom: 1px dotted #999;
        padding: 3px 0;
    }

    #investigationPrintDocument .print-question .q-answer {
        font-weight: 700;
        white-space: nowrap;
    }

    #investigationPrintDocument .print-files-list,
    #investigationPrintDocument .print-team-list {
        margin: 0;
        padding-left: 18px;
    }

    #investigationPrintDocument .print-signature {
        margin-top: 18px;
        page-break-inside: avoid;
        display: flex;
        justify-content: space-between;
    }
}

/* ФИО пациента одной строкой: поле ФИО шире даты рождения */
.form-row.patient-name-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
}

@media (max-width: 600px) {
    .form-row.patient-name-row {
        grid-template-columns: 1fr;
    }
}

/* ФИО пациента в таблице — одной строкой */
.incident-patient-cell {
    white-space: nowrap;
}
