/* ---------------------------------- */
/* МОДАЛЬНЫЕ ОКНА, БОКОВОЕ МЕНЮ, КМ   */
/* ---------------------------------- */

.modal-content {
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text);
    box-shadow: var(--shadow-md);
}

.modal-header,
.modal-footer {
    border-color: var(--border);
}

.btn-close {
    filter: invert(1);
    opacity: 0.7;
}

body.light-theme .btn-close {
    filter: invert(0);
}

body.light-theme .modal-content {
    background: #ffffff;
    backdrop-filter: none;
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: var(--text);
}

body.light-theme .modal-header,
body.light-theme .modal-footer {
    border-color: rgba(0, 0, 0, 0.1);
}

/* --- Боковое меню --- */
.side-menu {
    position: fixed;
    top: 0;
    left: -320px;
    width: 320px;
    height: 100%;
    background: var(--bg-surface);
    backdrop-filter: blur(24px);
    z-index: var(--z-modal);
    transition: left var(--transition-slow) cubic-bezier(0.2, 0.9, 0.4, 1.1), opacity var(--transition);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    opacity: 0;
    pointer-events: none;
}

body.light-theme .side-menu {
    background: #ffffff;
    backdrop-filter: none;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
}

.side-menu.open {
    left: 0;
    opacity: 1;
    pointer-events: auto;
}

.side-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: calc(var(--z-modal) - 50);
    display: none;
    animation: fadeIn var(--animation-duration) ease;
    pointer-events: auto;
}

.side-menu-overlay.active {
    display: block;
}

.side-menu-header {
    padding: 28px 20px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

body.light-theme .side-menu-header {
    border-bottom-color: rgba(0, 0, 0, 0.1);
}

.side-menu-avatar {
    width: 96px;
    height: 96px;
    margin: 0 auto 16px;
    background: linear-gradient(145deg, var(--primary), var(--primary-dark));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    background-size: cover;
    box-shadow: var(--shadow-md);
}

.side-menu-item {
    padding: 14px 24px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

body.light-theme .side-menu-item {
    color: var(--text);
}

.side-menu-item:hover {
    background: var(--bg-elevated);
    padding-left: 28px;
}

body.light-theme .side-menu-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* --- Кастомные модалки (modal-custom) --- */
.modal-custom-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(8px);
    z-index: calc(var(--z-modal) + 1000);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn var(--animation-duration) ease;
}

.modal-custom-container {
    background: var(--bg-surface);
    backdrop-filter: blur(24px);
    border-radius: var(--radius-2xl);
    padding: 28px;
    min-width: 320px;
    max-width: 90%;
    width: 400px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-2xl);
    animation: fadeSlideUp var(--animation-duration-slow) cubic-bezier(0.2, 0.9, 0.4, 1.1);
    color: var(--text);
}

body.light-theme .modal-custom-container {
    background: #ffffff;
    backdrop-filter: none;
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: var(--text);
}

/* --- Drag overlay --- */
.drag-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    border-radius: var(--radius-lg);
    pointer-events: none;
}

.drag-overlay-content {
    text-align: center;
    color: white;
    background: rgba(0, 0, 0, 0.6);
    padding: 24px 48px;
    border-radius: var(--radius-2xl);
    border: 2px dashed white;
}

.drag-overlay-content i {
    margin-bottom: 16px;
    display: block;
}
.drag-overlay-content p {
    font-size: 18px;
    margin: 0;
}

/* --- Кнопка опасного действия --- */
.btn-danger {
    background: var(--danger);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.btn-danger:hover {
    background: var(--danger-dark);
}

/* ===== Панель действий над сообщением ===== */
.message {
    transition: transform var(--transition), box-shadow var(--transition);
}
.message.action-open {
    transform: translateY(-4px);
    filter: drop-shadow(var(--shadow-sm));
}
.message-action-bar {
    display: flex;
    gap: 6px;
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    padding: 5px 10px;
    border-radius: 28px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    animation: fadeSlideUp 0.12s ease-out;
}
body.light-theme .message-action-bar {
    background: #ffffff;
    backdrop-filter: none;
    border: 1px solid rgba(0, 0, 0, 0.1);
}
.action-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    color: var(--text);
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
body.light-theme .action-btn {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text);
}
.action-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}
.action-btn:active {
    transform: scale(0.95);
}
.message.action-open .message-bubble {
    box-shadow: 0 0 0 2px var(--primary), var(--shadow-md);
}
.message {
    touch-action: manipulation;
}

/* Уважение prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .side-menu,
    .side-menu-overlay,
    .modal-custom-overlay,
    .modal-custom-container,
    .message-action-bar,
    .action-btn,
    .message {
        animation: none;
        transition: none;
    }
    .action-btn:hover {
        transform: none;
    }
}

/* ================================== */
/* ПЕРЕОПРЕДЕЛЕНИЕ Z-INDEX ДЛЯ ВСЕХ МОДАЛОК ПОВЕРХ ЛЕВОЙ ПАНЕЛИ */
/* ================================== */

/* Bootstrap модалки */
.modal {
    z-index: calc(var(--z-modal) + 1000) !important;
}
.modal-backdrop {
    z-index: calc(var(--z-modal) + 999) !important;
}

/* Оверлей прикрепления файлов (attach-drawer) */
.attach-mobile-overlay,
.attach-desktop-drawer {
    z-index: calc(var(--z-modal) + 1000) !important;
}

/* Просмотрщик историй */
.story-viewer-overlay {
    z-index: calc(var(--z-modal) + 1000) !important;
}
.story-viewer-modal-overlay {
    z-index: calc(var(--z-modal) + 1001) !important;
}

/* Предпросмотр файлов */
.file-preview-overlay {
    z-index: calc(var(--z-modal) + 1000) !important;
}
.media-preview-overlay {
    z-index: calc(var(--z-modal) + 1000) !important;
}

/* Вызов (CallModal) уже имеет z-index: var(--z-max) = 10000, что достаточно */
/* Но на всякий случай можно добавить:
.call-modal-overlay {
    z-index: calc(var(--z-modal) + 2000) !important;
}
*/