/* Стили модальных окон */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: var(--z-modal);
    backdrop-filter: blur(4px);
    animation: modalFadeIn var(--transition-normal);
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--card-background);
    border-radius: var(--border-radius-large);
    padding: 30px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    animation: modalScaleIn var(--transition-normal);
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}

.modal-subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-light);
    margin: 4px 0 0 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-light);
    padding: 4px;
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.close-btn:hover {
    background: var(--border-light);
    color: var(--text-color);
}

.modal-body {
    margin-bottom: 25px;
}

.modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.modal-footer.center {
    justify-content: center;
}

.modal-footer.left {
    justify-content: flex-start;
}

.modal-footer.space-between {
    justify-content: space-between;
}

/* Размеры модальных окон */
.modal-sm .modal-content {
    max-width: 400px;
}

.modal-lg .modal-content {
    max-width: 700px;
}

.modal-xl .modal-content {
    max-width: 1600px;
    max-height: 90vh;
    width: 95%;
}

.modal-fullscreen .modal-content {
    width: 95%;
    height: 90%;
    max-width: none;
    max-height: none;
}

/* Типы модальных окон */
.modal-confirm .modal-content {
    text-align: center;
    max-width: 400px;
}

.modal-confirm .modal-body {
    padding: 20px 0;
}

.modal-confirm .modal-title {
    color: var(--warning-color);
}

.modal-loading .modal-content {
    text-align: center;
    max-width: 300px;
}

.modal-loading .modal-body {
    padding: 40px 20px;
}

/* Анимации */
@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalScaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Мобильная адаптация */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        padding: 20px;
        margin: 20px;
        max-height: calc(100vh - 40px);
    }
    
    .modal-header {
        margin-bottom: 20px;
        padding-bottom: 12px;
    }
    
    .modal-title {
        font-size: var(--font-size-lg);
    }
    
    .modal-body {
        margin-bottom: 20px;
    }
    
    .modal-footer {
        flex-direction: column;
        gap: 8px;
    }
    
    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }
    
    .modal-sm .modal-content,
    .modal-lg .modal-content,
    .modal-xl .modal-content {
        max-width: none;
        width: 95%;
    }
    
    .modal-fullscreen .modal-content {
        width: 100%;
        height: 100%;
        border-radius: 0;
        margin: 0;
    }
}

/* Стили для системы комментариев */
.comments-container {
    background: var(--background-color);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-top: 16px;
}

.comments-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 20px;
    padding-right: 8px;
}

.comments-list::-webkit-scrollbar {
    width: 6px;
}

.comments-list::-webkit-scrollbar-track {
    background: var(--border-color);
    border-radius: 3px;
}

.comments-list::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 3px;
}

.comment-item {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 12px;
    transition: all var(--transition-fast);
}

.comment-item:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-sm);
}

.comment-item:last-child {
    margin-bottom: 0;
}

.comment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.comment-author {
    font-weight: 600;
    color: var(--text-dark);
    font-size: var(--font-size-sm);
}

.comment-date {
    font-size: var(--font-size-xs);
    color: var(--text-light);
}

.comment-text {
    color: var(--text-color);
    line-height: 1.5;
    white-space: pre-wrap;
}

.add-comment-section {
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
}

.comment-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.comments-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.comments-empty-icon {
    font-size: 2rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Стили модального окна в стиле AmoCRM */
.modal-xl .modal-body {
    display: flex;
    height: calc(90vh - 200px); /* Высота модального окна минус header и footer */
    padding: 0;
    gap: 0;
    min-height: 500px;
    margin-bottom: 0;
}

.modal-xl .task-detail-section {
    display: flex;
    height: 100%;
    width: 100%;
    flex: 1;
}

.modal-xl .task-detail-left {
    flex: 0 0 280px; /* Уменьшенная ширина левой панели */
    background: var(--card-background);
    border-right: 2px solid var(--border-color);
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.modal-xl .task-detail-right {
    flex: 1; /* Правая панель занимает все оставшееся место */
    background: var(--background-color);
    overflow: hidden; /* Убираем скролл с контейнера */
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Кастомные скроллбары для левой и правой панели */
.modal-xl .task-detail-left::-webkit-scrollbar,
.modal-xl .task-detail-right::-webkit-scrollbar {
    width: 8px;
}

.modal-xl .task-detail-left::-webkit-scrollbar-track,
.modal-xl .task-detail-right::-webkit-scrollbar-track {
    background: var(--border-light);
    border-radius: 4px;
}

.modal-xl .task-detail-left::-webkit-scrollbar-thumb {
    background: var(--primary-light);
    border-radius: 4px;
}

.modal-xl .task-detail-right::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 4px;
}

.modal-xl .task-detail-left::-webkit-scrollbar-thumb:hover,
.modal-xl .task-detail-right::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Убираем отступы у комментариев в общем контейнере */
.modal-xl .comments-container {
    background: transparent;
    padding: 0;
    margin: 0;
    border-radius: 0;
}

.modal-xl .comments-list {
    max-height: none;
    overflow-y: visible;
}

/* Стили для заголовков секций */
.section-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary-color);
}

/* Дополнительные стили в стиле AmoCRM */
.modal-xl .section-title {
    position: sticky;
    top: 0;
    background: inherit;
    z-index: 10;
    margin: -8px -8px 16px -8px;
    padding: 12px 8px 8px 8px;
    font-size: var(--font-size-md);
}

/* Компактные стили для левой панели */
.modal-xl .task-detail-left .detail-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-xl .task-detail-left .detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.modal-xl .task-detail-left .detail-item label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-xl .task-detail-left .editable-text,
.modal-xl .task-detail-left .task-status {
    font-size: var(--font-size-sm);
    padding: 6px 8px;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-xl .task-detail-left .editable-text:hover {
    border-color: var(--primary-light);
}

.modal-xl .task-detail-left .section-title {
    background: var(--card-background);
}

.modal-xl .task-detail-right .section-title {
    background: var(--background-color);
}

/* Разделители между секциями в правой панели */
.modal-xl .task-detail-right .section-divider {
    height: 1px;
    background: var(--border-color);
    margin: 24px 0;
}

/* Правая панель в стиле мессенджера */
.modal-xl .history-comments-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0;
}

/* Контент с прокруткой - занимает все место кроме поля ввода */
.modal-xl .scrollable-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: 0;
}

/* Фиксированное поле ввода внизу */
.modal-xl .fixed-input-area {
    flex-shrink: 0;
    background: var(--card-background);
    border-top: 2px solid var(--border-color);
    padding: 16px 24px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
}

/* Стили для области ввода в стиле мессенджера */
.modal-xl .messenger-input {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 8px 16px;
    transition: border-color var(--transition-fast);
}

.modal-xl .messenger-input:focus-within {
    border-color: var(--primary-color);
}

.modal-xl .messenger-input textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    min-height: 20px;
    max-height: 100px;
    padding: 8px 0;
    font-family: inherit;
    font-size: var(--font-size-sm);
    line-height: 1.4;
    color: var(--text-color);
}

.modal-xl .messenger-input textarea:focus {
    outline: none;
}

.modal-xl .messenger-input textarea::placeholder {
    color: var(--text-light);
}

.modal-xl .send-button {
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.modal-xl .send-button:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.modal-xl .send-button:disabled {
    background: var(--border-color);
    cursor: not-allowed;
    transform: none;
}

/* Стили для секций в прокручиваемой области */
.modal-xl .content-section {
    margin-bottom: 32px;
}

.modal-xl .content-section:last-child {
    margin-bottom: 16px;
}

/* Улучшенные стили для истории */
.modal-xl .detail-history {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 16px;
    border: 1px solid var(--border-color);
}

.modal-xl .history-item {
    border-bottom: 1px solid var(--border-light);
    padding: 12px 0;
}

.modal-xl .history-item:last-child {
    border-bottom: none;
}

/* Стили для комментариев в стиле мессенджера */
.modal-xl .comments-feed {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-xl .comment-bubble {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 12px 16px;
    max-width: 80%;
    align-self: flex-start;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.modal-xl .comment-bubble.own {
    background: var(--primary-light);
    border-color: var(--primary-color);
    align-self: flex-end;
}

.modal-xl .comment-bubble .comment-author {
    font-weight: 600;
    font-size: var(--font-size-xs);
    color: var(--primary-color);
    margin-bottom: 4px;
}

.modal-xl .comment-bubble .comment-text {
    color: var(--text-color);
    line-height: 1.4;
    word-wrap: break-word;
}

.modal-xl .comment-bubble .comment-time {
    font-size: var(--font-size-xs);
    color: var(--text-light);
    margin-top: 4px;
    text-align: right;
}

/* Адаптивные стили для комментариев */
@media (max-width: 768px) {
    .comments-container {
        padding: 16px;
    }
    
    .comments-list {
        max-height: 200px;
    }
    
    .comment-item {
        padding: 12px;
    }
    
    .comment-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .comment-actions {
        justify-content: stretch;
    }
    
    .comment-actions .btn {
        width: 100%;
    }
    
    /* Мобильная адаптация для больших модальных окон */
    .modal-xl .modal-body {
        flex-direction: column;
        height: auto;
    }
    
    .modal-xl .task-detail-section {
        flex-direction: column;
        height: auto;
    }
    
    .modal-xl .task-detail-left,
    .modal-xl .task-detail-right {
        overflow-y: visible;
        max-height: 50vh;
        overflow-y: auto;
    }
    
    .modal-xl .task-detail-left {
        border-right: none;
        border-bottom: 2px solid var(--border-color);
    }
}