/* frontend/css/audit.css */
.audit-container {
    animation: fadeIn 0.3s ease;
}

/* Вкладки */
.audit-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--white);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    padding: 0 20px;
}

.audit-tabs .tab-btn {
    padding: 14px 24px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-gray);
    transition: all 0.3s;
    position: relative;
}

.audit-tabs .tab-btn:hover {
    color: var(--primary-color);
}

.audit-tabs .tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.audit-tabs .tab-btn .badge {
    position: absolute;
    top: 6px;
    right: 8px;
    background: var(--danger-color);
    color: white;
    font-size: 10px;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* Карточка проверки */
.inspection-card {
    background: var(--white);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 16px;
}

.inspection-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

.inspection-card .card-header {
    padding: 16px 20px;
    background: var(--bg-light);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.inspection-card .card-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
    flex: 1;
}

.inspection-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-draft {
    background: #e3f2fd;
    color: #1565c0;
}

.status-in_progress {
    background: #fff3e0;
    color: #e65100;
}

.status-completed {
    background: #e8f5e9;
    color: #2e7d32;
}

.inspection-card .card-body {
    padding: 16px 20px;
}

.inspection-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    font-size: 13px;
    color: var(--text-gray);
    margin-bottom: 12px;
}

.inspection-meta i {
    width: 16px;
    margin-right: 6px;
    color: var(--primary-color);
}

.inspection-stats {
    display: flex;
    gap: 20px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    margin-bottom: 12px;
}

.stat-badge {
    font-size: 13px;
    color: var(--text-dark);
}

.stat-badge i {
    margin-right: 6px;
}

.stat-badge.violations {
    color: var(--danger-color);
}

.progress-section {
    margin-top: 8px;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-gray);
    margin-bottom: 4px;
}

.progress-bar-container {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
    border-radius: 4px;
    transition: width 0.5s ease;
}

.inspection-card .card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-light);
    display: flex;
    gap: 12px;
}

/* Кнопки */
.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #219a52;
    transform: translateY(-2px);
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-warning:hover {
    background: #e67e22;
}

/* Экран заполнения */
.fill-screen {
    animation: fadeIn 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: calc(100vh - 120px);
    width: 100%;
}

.fill-header {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    position: sticky;
    top: 70px;
    z-index: 10;
}

.fill-header-info h2 {
    font-size: 20px;
    margin: 0 0 16px 0;
    color: var(--text-dark);
}

.stats-row {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.stat-card-small {
    background: var(--bg-light);
    border-radius: 12px;
    padding: 12px 20px;
    text-align: center;
    min-width: 100px;
    border: 1px solid var(--border-color);
    flex: 1;
}

.stat-card-small .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-card-small .stat-value.violations {
    color: var(--danger-color);
}

.stat-card-small .stat-label {
    font-size: 12px;
    color: var(--text-gray);
    margin-top: 4px;
}

.stat-card-small small {
    font-size: 10px;
    color: var(--text-light);
}

.fill-progress {
    margin: 16px 0;
}

.fill-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 16px;
    flex-wrap: wrap;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-outline:hover {
    background: var(--bg-light);
    border-color: var(--primary-color);
}

/* Дерево заполнения */
.fill-tree {
    background: var(--white);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: 24px;
    min-height: calc(100vh - 280px);
    /* Занимает всю доступную высоту за вычетом шапок */
    width: 100%;
    box-sizing: border-box;
}

.fill-tree-root {
    list-style: none;
    padding-left: 0;
    margin: 0;
    width: 100%;
}

.fill-node {
    margin: 0;
    padding: 0;
    width: 100%;
}

.fill-node-content {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    transition: background 0.2s;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
}

.fill-node-content:hover {
    background: var(--bg-light);
}

.toggle-icon {
    cursor: pointer;
    width: 20px;
    text-align: center;
    color: var(--text-gray);
    flex-shrink: 0;
    margin-top: 2px;
}

.node-icon {
    width: 24px;
    color: var(--primary-color);
    flex-shrink: 0;
}

.node-text {
    flex: 1;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-dark);
}

.node-number {
    font-weight: 600;
    color: var(--primary-color);
    margin-right: 8px;
}

.node-badge {
    font-size: 10px;
    padding: 2px 6px;
    background: var(--bg-light);
    border-radius: 4px;
    color: var(--text-gray);
    flex-shrink: 0;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    margin-left: 8px;
    flex-shrink: 0;
}

.status-badge.success {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-badge.danger {
    background: #ffebee;
    color: #c62828;
}

.status-badge.warning {
    background: #fff3e0;
    color: #e65100;
}

.btn-attachments {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--primary-light);
    border: none;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 8px;
    flex-shrink: 0;
}

.btn-attachments:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
}

.btn-attachments i {
    font-size: 11px;
}

/* Кнопка Инструкция/СОП */
.sop-button {
    background: #e8f4f8;
    border: 1px solid #2e8bd5;
    color: #2e8bd5;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    flex-shrink: 0;
}

.sop-button:hover {
    background: #2e8bd5;
    color: white;
    transform: translateY(-1px);
}

/* Кнопка прикрепленных файлов */
.btn-documents {
    background: #e8f5e9;
    border: 1px solid #4caf50;
    color: #2e7d32;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    flex-shrink: 0;
}

.btn-documents:hover {
    background: #4caf50;
    color: white;
}

.fill-node-children {
    padding-left: 0;
    width: 100%;
}

/* Оценка компонента */
.assessment-component {
    padding: 10px 0 0 0 !important;
    margin: 0 !important;
    background: transparent !important;
    width: 100%;
}

.assessment-options {
    display: flex;
    gap: 8px;
    margin-bottom: 0 !important;
    width: 100%;
}

.assessment-option {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    background: #ffffff !important;
    font-weight: 600 !important;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    user-select: none;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.assessment-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.assessment-option:has(input[type="radio"]:checked).yes {
    background: #f0fdf4 !important;
    border-color: #22c55e !important;
    color: #15803d !important;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.15) !important;
}

.assessment-option:has(input[type="radio"]:checked).no {
    background: #fef2f2 !important;
    border-color: #ef4444 !important;
    color: #b91c1c !important;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.15) !important;
}

.assessment-option:has(input[type="radio"]:checked).na {
    background: #f8fafc !important;
    border-color: #64748b !important;
    color: #334155 !important;
    box-shadow: 0 2px 8px rgba(100, 116, 139, 0.15) !important;
}

.comment-field {
    width: 100%;
    margin-top: 8px;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    resize: vertical;
    font-family: inherit;
    box-sizing: border-box;
}

.comment-field:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(46, 139, 213, 0.1);
}

/* Отчет */
.report-header {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.report-info p {
    margin: 8px 0;
    font-size: 14px;
}

.report-stats {
    display: flex;
    gap: 20px;
}

.report-stats .stat-item {
    text-align: center;
    padding: 12px 20px;
    background: var(--bg-light);
    border-radius: 12px;
    min-width: 100px;
}

.report-stats .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-color);
}

.report-stats .stat-label {
    font-size: 12px;
    color: var(--text-gray);
}

.violations-section {
    margin-top: 20px;
}

.violations-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--danger-color);
}

.violations-list {
    background: var(--bg-light);
    border-radius: 12px;
    overflow: hidden;
}

.violation-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
}

.violation-item:last-child {
    border-bottom: none;
}

.violation-number {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 60px;
}

.violation-text {
    flex: 1;
    font-size: 14px;
}

.violation-comment {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-gray);
    padding-left: 12px;
    border-left: 2px solid var(--border-color);
}

.recommendations-section {
    margin-top: 24px;
    padding: 16px;
    background: #e8f4f8;
    border-radius: 12px;
}

.recommendations-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--primary-color);
}

/* Кнопка фильтра в активном состоянии */
#filterUnansweredBtn.active {
    background: #9b59b6;
    color: white;
    border-color: #9b59b6;
    box-shadow: 0 2px 8px rgba(155, 89, 182, 0.2);
}

/* Оформление уровней иерархии */
.fill-node.level-requirement {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.fill-node.level-requirement>.fill-node-content {
    background: #f1f5f9;
    font-weight: 700;
    font-size: 15px;
    color: #1e293b;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.fill-node.level-criterion {
    margin: 8px 12px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    box-sizing: border-box;
}

.fill-node.level-criterion>.fill-node-content {
    font-weight: 600;
    font-size: 14px;
    color: #334155;
    padding: 10px 14px;
}

/* Карточки-вопросы (Оцениваемые компоненты) */
.fill-node.level-component {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin: 8px 16px;
    padding: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.fill-node.level-component:hover,
.fill-node.level-component:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.08);
    background: #fcfdfe;
}

.fill-node.level-component>.fill-node-content {
    padding: 0 0 10px 0;
    border-bottom: 1px solid #f1f5f9;
    cursor: default;
}

/* Блок с деталями несоответствия (комментарии и фото) */
.non-compliance-block {
    margin-top: 12px;
    padding: 12px;
    background: #fff5f5;
    border-radius: 8px;
    border: 1px dashed #feb2b2;
    animation: slideDownAudit 0.25s ease-out;
    box-sizing: border-box;
}

@keyframes slideDownAudit {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Секция загрузки доказательств (фотофиксация) */
.evidence-section {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
    align-items: center;
}

.evidence-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Элемент прикрепленного фото */
.evidence-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #fc8181;
    font-size: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.evidence-name {
    color: #c53030;
    cursor: pointer;
    font-weight: 500;
}

.evidence-name:hover {
    text-decoration: underline;
}

.delete-evidence-btn {
    background: none;
    border: none;
    color: #a0aec0;
    cursor: pointer;
    padding: 2px 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.delete-evidence-btn:hover {
    color: #e53e3e;
    background: #fff5f5;
}

/* Область клика для запуска Камеры/Галереи */
.evidence-upload-zone {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border: 1px dashed #fc8181;
    border-radius: 6px;
    background: #fff;
    color: #e53e3e;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

.evidence-upload-zone:hover {
    background: #fff5f5;
    border-color: #e53e3e;
}

.evidence-upload-zone i {
    font-size: 14px;
}

/* Оптимизация textarea комментариев под блок несоответствия */
.non-compliance-block .comment-field {
    border-color: #feb2b2;
    background: #fff;
}

.non-compliance-block .comment-field:focus {
    border-color: #e53e3e;
    box-shadow: 0 0 0 2px rgba(229, 62, 62, 0.1);
}

/* Стилизация скроллбара дерева */
.fill-tree::-webkit-scrollbar {
    width: 6px;
}

.fill-tree::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.fill-tree::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.fill-tree::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Состояния */
.loading-state {
    text-align: center;
    padding: 60px;
    color: var(--text-gray);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

.loading-spinner-small {
    width: 30px;
    height: 30px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.empty-state {
    text-align: center;
    padding: 60px;
    color: var(--text-gray);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--border-color);
}

.error-state {
    text-align: center;
    padding: 60px;
    color: #c62828;
}

.access-denied {
    text-align: center;
    padding: 60px;
}

/* Свернутая шапка */
.fill-header {
    position: sticky;
    top: 70px;
    z-index: 100;
    background: var(--white);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: 14px 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fill-mini-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: #f1f5f9;
    display: none;
    overflow: hidden;
}

.fill-mini-progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.fill-header-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
}

.fill-header-title-container {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.fill-title-text {
    font-size: 18px !important;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fill-compact-stats-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    white-space: nowrap;
    display: inline-block;
}

.fill-header-expandable-content {
    margin-top: 15px;
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 600px;
    opacity: 1;
    overflow: hidden;
}

.fill-header.stats-collapsed .fill-header-expandable-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    margin-top: 0;
    border-top-color: transparent;
    pointer-events: none;
}

.fill-header.stats-collapsed .fill-mini-progress-bar {
    display: block;
}

.fill-header .toggle-arrow {
    transition: transform 0.3s ease;
    margin-left: 4px;
}

.fill-header.stats-collapsed .toggle-arrow {
    transform: rotate(-180deg);
}

/* Адаптивность под планшеты и мобильные устройства */
@media (max-width: 992px) {
    .fill-header {
        top: 60px;
        padding: 10px 14px;
        border-radius: 0;
        border-left: none;
        border-right: none;
        margin-left: -16px;
        margin-right: -16px;
    }

    .fill-title-text {
        font-size: 15px !important;
    }

    .hide-mobile {
        display: none !important;
    }

    .stats-row {
        gap: 8px;
        margin-bottom: 12px;
    }

    .stat-card-small {
        padding: 10px;
        min-width: 80px;
    }

    .stat-card-small .stat-value {
        font-size: 18px;
    }

    .fill-actions {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-top: 12px;
    }

    .fill-actions .btn {
        width: 100%;
        justify-content: center;
        font-size: 12px;
        padding: 8px;
    }

    #completeInspectionBtn {
        grid-column: span 2;
    }

    .fill-node.level-criterion {
        margin: 8px;
    }

    .fill-node.level-component {
        margin: 6px 8px;
        padding: 10px;
    }

    .assessment-option {
        padding: 10px 8px !important;
        font-size: 11px !important;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}