/* File Modal Styles */
.file-modal {
    display: none;
}


.file-modal-content {
    background-color: white;
    position: relative !important;
    padding: 0;
    border-radius: var(--radius);
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    box-shadow: var(--shadow);
    animation: none !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    z-index: 10001;
    line-height: normal !important;
    font-size: initial !important;
}

.file-modal-header {
    padding: 20px 30px;
    border-bottom: 2px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.2);
}

.file-modal-header h3 {
    margin: 0;
    color: white;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-modal-header h3::before {
    content: '';
    width: 4px;
    height: 20px;
    background: white;
    border-radius: 2px;
}

.file-modal-close {
    color: var(--gray);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.file-modal-close:hover {
    background: var(--danger);
    color: white;
}

.file-modal-body {
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    min-height: 0;
}

.file-modal-body > div[style*="margin-top: 20px"] {
    width: 100% !important;
    max-width: 100%;
}

/* File Modal Image */
.file-modal-image {
    max-width: 100%;
    max-height: 70vh;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: var(--transition);
}

.file-modal-image:hover {
    transform: scale(1.02);
}

/* File Modal Video */
.file-modal-video {
    max-width: 100%;
    max-height: 70vh;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

/* File Modal Document */
.file-modal-document {
    text-align: center;
    padding: 40px;
}

.file-modal-document-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.file-modal-document-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 30px;
    word-break: break-all;
}

.file-modal-download {
    display: inline-block;
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: var(--transition);
    margin: 0 10px;
}

.file-modal-download:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

/* Fullscreen Modal */
#fullscreenModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20000;
    cursor: pointer;
}

.fullscreen-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    font-size: 20px;
    backdrop-filter: blur(10px);
    transition: var(--transition);
}

.fullscreen-close-btn:hover {
    background: rgba(255,255,255,0.3);
}

.fullscreen-info {
    position: absolute;
    bottom: 20px;
    left: 20px;
    color: white;
    background: rgba(0,0,0,0.7);
    padding: 10px 15px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    font-size: 14px;
}

/* Checklist Answers Styles */
.checklist-answers {
    margin-top: 10px;
    border: 1px solid var(--light);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.checklist-answers-header {
    background: var(--light);
    padding: 10px 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
    font-weight: 500;
    color: var(--dark);
}

.checklist-answers-header:hover {
    background: #e5e7eb;
}

.checklist-answers-header .toggle-icon {
    transition: transform 0.3s ease;
    font-size: 12px;
}

.checklist-answers-header.expanded .toggle-icon {
    transform: rotate(180deg);
}

.checklist-answers-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: white;
}

.checklist-answers-content.expanded {
    max-height: 500px;
    overflow-y: auto;
}

.checklist-item {
    padding: 12px 15px;
    border-bottom: 1px solid #f3f4f6;
}

.checklist-item:last-child {
    border-bottom: none;
}

.checklist-question {
    font-weight: 500;
    color: var(--dark);
    margin-bottom: 8px;
    font-size: 14px;
}

.checklist-answer {
    color: var(--gray);
    font-size: 13px;
    line-height: 1.4;
    padding: 8px 12px;
    background: #f9fafb;
    border-radius: 6px;
    border-left: 3px solid var(--primary);
}

.checklist-answer.empty {
    color: #999;
    font-style: italic;
    border-left-color: #ddd;
}

.checklist-answer-file {
    margin-top: 5px;
}

.checklist-answer-file a {
    color: var(--primary);
    text-decoration: none;
    font-size: 12px;
    padding: 4px 8px;
    background: var(--light);
    border-radius: 4px;
    display: inline-block;
    transition: var(--transition);
}

.checklist-answer-file a:hover {
    background: var(--primary);
    color: white;
}

/* Responsive Modals */
@media (max-width: 768px) {
    .file-modal-content {
        width: 95% !important;
        margin: 0 !important;
        max-height: 95vh !important;
    }
    
    .file-modal-header {
        padding: 15px 20px;
    }
    
    .file-modal-header h3 {
        font-size: 16px;
    }
    
    .file-modal-body {
        padding: 15px !important;
        box-sizing: border-box !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Забезпечуємо правильну ширину для всіх елементів всередині body */
    .file-modal-body > * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Адаптація grid на мобільних - одна колонка замість двох */
    .file-modal-body [style*="grid-template-columns: repeat(2"] {
        grid-template-columns: 1fr !important;
    }
    
    .file-modal-body div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Таблиці та контейнери */
    .file-modal-body .table-container {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
    }
    
    .file-modal-body table {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Зображення та відео */
    .file-modal-body img,
    .file-modal-body video {
        max-width: 100% !important;
        height: auto !important;
        box-sizing: border-box !important;
    }
    
    /* Всі div всередині body */
    .file-modal-body div {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Контейнери з width: 100% - забезпечуємо правильну ширину */
    .file-modal-body div[style*="width: 100%"] {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        min-width: 0 !important;
    }
    
    /* Списки елементів (scheduleItemsList, executionItemsList) */
    #scheduleItemsList,
    #executionItemsList {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Кнопки "Переглянути" та "Завантажити" вертикально на мобільних */
    /* Знаходимо div з кнопками через селектор за стилем margin-top: 8px */
    .file-modal-body div[style*="margin-top: 8px"] {
        flex-direction: column !important;
    }
    
    /* Також для контейнерів без margin-top, але з gap: 8px */
    .file-modal-body div[style*="gap: 8px"]:not([style*="grid-template-columns"]) {
        flex-direction: column !important;
    }
    
    .file-modal-body div[style*="margin-top: 8px"] button,
    .file-modal-body div[style*="margin-top: 8px"] a.btn,
    .file-modal-body div[style*="gap: 8px"]:not([style*="grid-template-columns"]) button,
    .file-modal-body div[style*="gap: 8px"]:not([style*="grid-template-columns"]) a.btn {
        width: 100% !important;
        flex: none !important;
        margin-bottom: 8px !important;
    }
    
    .file-modal-body div[style*="margin-top: 8px"] button:last-child,
    .file-modal-body div[style*="margin-top: 8px"] a.btn:last-child,
    .file-modal-body div[style*="gap: 8px"]:not([style*="grid-template-columns"]) button:last-child,
    .file-modal-body div[style*="gap: 8px"]:not([style*="grid-template-columns"]) a.btn:last-child {
        margin-bottom: 0 !important;
    }
    
    .file-modal-document {
        padding: 20px;
    }
    
    .file-modal-document-icon {
        font-size: 48px;
    }
    
    .file-modal-document-name {
        font-size: 16px;
    }
    
    .file-modal-download {
        padding: 10px 20px;
        font-size: 14px;
        margin: 5px;
        display: block;
        width: 100%;
        text-align: center;
    }
    
    .checklist-answers-header {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .checklist-question {
        font-size: 13px;
    }
    
    .checklist-answer {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .fullscreen-close-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
        top: 15px;
        right: 15px;
    }
    
    .fullscreen-info {
        font-size: 12px;
        padding: 8px 12px;
    }
}

/* Chat Modal Styles */
/* Используем ту же логику центрирования, что и в истории (.file-modal) */
/* Отключаем все конфликтующие свойства из .modal-content для чата */
#chatModal .modal-content.chat-modal-content,
#chatModal .chat-modal-content {
    max-width: 600px !important;
    width: 95% !important;
    height: 85vh !important;
    max-height: 85vh !important;
    display: flex !important;
    flex-direction: column !important;
    margin: 2% auto !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    position: relative !important;
    background-color: white !important;
    box-shadow: var(--shadow) !important;
    animation: none !important;
    transform: none !important;
    /* Переопределяем базовые стили из .modal-content */
    padding: 0 !important;
    border: none !important;
}

.chat-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    flex-shrink: 0;
    min-height: 50px;
}

.chat-modal-header h2 {
    margin: 0;
    color: white;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
}

.chat-modal-header .close {
    color: white;
    background: rgba(255, 255, 255, 0.2);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.2s;
}

.chat-modal-header .close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* КРИТИЧНО: Полное переопределение стилей .modal-content > form, .modal-content > div:not(.close) для чата */
/* Используем ID родителя #chatModal для максимальной специфичности (1,0,0) > (0,2,1) */

/* Для контейнера сообщений - используем ID родителя для максимальной специфичности */
#chatModal .modal-content.chat-modal-content > #chatMessages,
#chatModal .chat-modal-content > #chatMessages.chat-messages-container,
#chatModal #chatMessages.chat-messages-container {
    padding: 16px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    flex: 1 !important;
    background: #f5f7fa !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
}

/* Для контейнера формы - используем ID родителя для максимальной специфичности */
#chatModal .modal-content.chat-modal-content > .chat-form-container,
#chatModal .chat-modal-content > .chat-form-container,
#chatModal .chat-form-container {
    padding: 16px !important;
    overflow: visible !important;
    overflow-y: visible !important;
    overflow-x: visible !important;
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    background: white !important;
    box-sizing: border-box !important;
}

/* Для формы внутри контейнера */
#chatModal .modal-content.chat-modal-content form.chat-form,
#chatModal .chat-modal-content form.chat-form,
#chatModal #chatForm.chat-form,
#chatModal form.chat-form {
    padding: 0 !important;
    overflow: visible !important;
    overflow-y: visible !important;
    overflow-x: visible !important;
    flex: none !important;
    flex-grow: 0 !important;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
}

.chat-messages-container {
    flex: 1 !important;
    overflow-y: auto !important;
    overflow-x: hidden;
    padding: 16px !important;
    background: #f5f7fa;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-form-container {
    padding: 16px !important;
    border-top: 2px solid #e2e8f0;
    background: white;
    flex-shrink: 0 !important;
    flex: 0 0 auto !important;
    overflow: visible !important;
}

.chat-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    padding: 0 !important;
    margin: 0 !important;
}

.chat-form .form-control {
    flex: 1;
    margin: 0;
    min-width: 0;
    padding: 12px 16px;
    font-size: 15px;
    border: 2px solid #e2e8f0;
    border-radius: 24px;
    background: #f9fafb;
    transition: all 0.2s;
}

.chat-form .form-control:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.chat-modal-content .btn {
    width: auto !important;
    margin: 0 !important;
    margin-top: 0 !important;
    white-space: nowrap;
    padding: 12px 20px !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    min-width: 50px;
    height: 48px;
    border-radius: 24px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-modal-content .btn:hover {
    transform: translateY(-2px) !important;
}

.chat-form .btn-attach {
    width: auto !important;
    margin: 0 !important;
    margin-top: 0 !important;
    padding: 12px !important;
    font-size: 18px !important;
    font-weight: 500 !important;
    min-width: 48px;
    height: 48px;
    border-radius: 24px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#chatFilePreview {
    display: none;
    margin-top: 10px;
    padding: 10px 14px;
    background: #f0f4ff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13px;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

#chatFilePreview[style*="display: block"],
#chatFilePreview[style*="display: flex"] {
    display: flex !important;
}

#chatFilePreview span {
    flex: 1;
    color: var(--dark);
    word-break: break-all;
}

#chatFilePreview button {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

#chatFilePreview button:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Chat Message Styles */
.chat-message {
    display: flex;
    margin-bottom: 0;
}

.chat-message.admin {
    justify-content: flex-end;
}

.chat-message.employee {
    justify-content: flex-start;
}

.chat-message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    word-wrap: break-word;
    position: relative;
}

.chat-message.admin .chat-message-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.employee .chat-message-bubble {
    background: white;
    color: var(--dark);
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.chat-message-sender {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 13px;
    opacity: 0.9;
}

.chat-message-text {
    margin-bottom: 4px;
    line-height: 1.5;
    font-size: 14px;
    word-break: break-word;
}

.chat-message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

/* Стили для ссылок на файлы в сообщениях */
.chat-message.admin .chat-message-bubble a {
    color: white !important;
    text-decoration: underline !important;
}

.chat-message.employee .chat-message-bubble a {
    color: var(--primary) !important;
    text-decoration: underline !important;
}

/* Стилі для прев'ю медіа в чаті */
.chat-message-bubble img {
    display: block;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-message-bubble img:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
}

.chat-message-bubble video {
    display: block;
    background: #000;
}

.chat-message-bubble video:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
}

@media (max-width: 768px) {
    .chat-modal-content {
        width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
    
    .chat-modal-header {
        padding: 10px 16px;
        min-height: 48px;
    }
    
    .chat-modal-header h2 {
        font-size: 16px;
    }
    
    .chat-messages-container {
        padding: 12px;
    }
    
    .chat-form-container {
        padding: 12px;
    }
    
    .chat-message-bubble {
        max-width: 85%;
    }
    
    .chat-form .form-control {
        font-size: 14px;
        padding: 10px 14px;
    }
    
    .chat-form .btn,
    .chat-form .btn-attach {
        height: 44px;
        min-width: 44px;
        padding: 10px;
    }
    
    /* Адаптивність для прев'ю медіа на мобільних */
    .chat-message-bubble img {
        max-width: 250px !important;
        max-height: 250px !important;
    }
    
    .chat-message-bubble video {
        max-width: 250px !important;
        max-height: 250px !important;
    }
}
