/**
 * 🗂️ MODALS CSS ДЛЯ TELEGRAM MINI APP
 * Стили модальных окон, диалогов и всплывающих элементов
 */

/* ============================================================================
   🗂️ БАЗОВЫЕ СТИЛИ МОДАЛЬНЫХ ОКОН
   ============================================================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-index-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    opacity: 0;
    visibility: hidden;
    transition: all var(--duration-normal) var(--ease-out);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: opacity var(--duration-normal) var(--ease-out);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: transform var(--duration-normal) var(--ease-back);
}

.modal.active .modal-content {
    transform: scale(1) translateY(0);
}

/* ============================================================================
   📋 СТРУКТУРА МОДАЛЬНОГО ОКНА
   ============================================================================ */

.modal-header {
    padding: var(--spacing-lg) var(--spacing-lg) 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.modal-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0;
    flex: 1;
}

.modal-close {
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: var(--radius-round);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-normal) var(--ease-out);
    margin-left: var(--spacing-md);
}

.modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-close .icon {
    width: 20px;
    height: 20px;
}

.modal-body {
    padding: var(--spacing-lg);
    overflow-y: auto;
    max-height: calc(90vh - 140px);
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    padding: 0 var(--spacing-lg) var(--spacing-lg);
    display: flex;
    gap: var(--spacing-sm);
    justify-content: flex-end;
    border-top: 1px solid var(--bg-secondary);
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
}

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

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

/* ============================================================================
   📐 РАЗМЕРЫ МОДАЛЬНЫХ ОКОН
   ============================================================================ */

/* Маленькое модальное окно */
.modal-sm .modal-content {
    max-width: 320px;
}

/* Среднее модальное окно (по умолчанию) */
.modal-md .modal-content {
    max-width: 480px;
}

/* Большое модальное окно */
.modal-lg .modal-content {
    max-width: 600px;
}

/* Полноэкранное модальное окно */
.modal-fullscreen .modal-content {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    margin: 0;
}

.modal-fullscreen {
    padding: 0;
}

/* ============================================================================
   🎨 СТИЛИ МОДАЛЬНЫХ ОКОН
   ============================================================================ */

/* Модальное окно с градиентным заголовком */
.modal-gradient {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: var(--text-inverse);
}

.modal-gradient .modal-title {
    color: var(--text-inverse);
}

.modal-gradient .modal-close {
    color: rgba(255, 255, 255, 0.8);
}

.modal-gradient .modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-inverse);
}

/* Модальное окно с тенью */
.modal-shadow .modal-content {
    box-shadow: var(--shadow-primary-lg);
}

/* Модальное окно успеха */
.modal-success .modal-content {
    border-top: 6px solid var(--success-color);
}

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

/* Модальное окно предупреждения */
.modal-warning .modal-content {
    border-top: 6px solid var(--warning-color);
}

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

/* Модальное окно ошибки */
.modal-error .modal-content {
    border-top: 6px solid var(--error-color);
}

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

/* ============================================================================
   📱 DRAWER (ВЫДВИЖНЫЕ ПАНЕЛИ)
   ============================================================================ */

.drawer {
    position: fixed;
    z-index: var(--z-index-modal);
    background: var(--bg-card);
    box-shadow: var(--shadow-xl);
    transition: transform var(--duration-normal) var(--ease-out);
}

.drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-index-modal) - 1);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all var(--duration-normal) var(--ease-out);
}

.drawer.active + .drawer-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Выдвижение снизу */
.drawer-bottom {
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    transform: translateY(100%);
    max-height: 80vh;
    overflow-y: auto;
}

.drawer-bottom.active {
    transform: translateY(0);
}

/* Выдвижение сверху */
.drawer-top {
    left: 0;
    right: 0;
    top: 0;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    transform: translateY(-100%);
    max-height: 80vh;
    overflow-y: auto;
}

.drawer-top.active {
    transform: translateY(0);
}

/* Выдвижение слева */
.drawer-left {
    top: 0;
    bottom: 0;
    left: 0;
    width: 300px;
    max-width: 80vw;
    border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
    transform: translateX(-100%);
}

.drawer-left.active {
    transform: translateX(0);
}

/* Выдвижение справа */
.drawer-right {
    top: 0;
    bottom: 0;
    right: 0;
    width: 300px;
    max-width: 80vw;
    border-radius: var(--radius-xl) 0 0 var(--radius-xl);
    transform: translateX(100%);
}

.drawer-right.active {
    transform: translateX(0);
}

/* ============================================================================
   🍃 BOTTOM SHEET
   ============================================================================ */

.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-index-modal);
    background: var(--bg-card);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-xl);
    transform: translateY(100%);
    transition: transform var(--duration-normal) var(--ease-out);
    max-height: 90vh;
    overflow: hidden;
}

.bottom-sheet.active {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 2px;
    margin: var(--spacing-sm) auto;
    opacity: 0.5;
}

.bottom-sheet-content {
    padding: 0 var(--spacing-lg) var(--spacing-lg);
    overflow-y: auto;
    max-height: calc(90vh - 60px);
    -webkit-overflow-scrolling: touch;
}

/* ============================================================================
   💬 TOOLTIP И POPOVER
   ============================================================================ */

.tooltip {
    position: absolute;
    z-index: calc(var(--z-index-modal) + 10);
    background: var(--text-primary);
    color: var(--text-inverse);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--duration-fast) var(--ease-out);
    pointer-events: none;
}

.tooltip.active {
    opacity: 1;
    visibility: visible;
}

.tooltip::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border: 4px solid transparent;
}

.tooltip-top::after {
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-top-color: var(--text-primary);
}

.tooltip-bottom::after {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-bottom-color: var(--text-primary);
}

.tooltip-left::after {
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border-left-color: var(--text-primary);
}

.tooltip-right::after {
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border-right-color: var(--text-primary);
}

/* ============================================================================
   📋 ACTION SHEET
   ============================================================================ */

.action-sheet {
    position: fixed;
    left: var(--spacing-md);
    right: var(--spacing-md);
    bottom: var(--spacing-md);
    z-index: var(--z-index-modal);
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    transform: translateY(100%);
    transition: transform var(--duration-normal) var(--ease-back);
}

.action-sheet.active {
    transform: translateY(0);
}

.action-sheet-title {
    padding: var(--spacing-lg) var(--spacing-lg) var(--spacing-sm);
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    border-bottom: 1px solid var(--bg-secondary);
}

.action-sheet-item {
    display: flex;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background-color var(--duration-normal) var(--ease-out);
}

.action-sheet-item:hover {
    background: var(--bg-secondary);
}

.action-sheet-item.destructive {
    color: var(--error-color);
}

.action-sheet-item .icon {
    width: 24px;
    height: 24px;
    margin-right: var(--spacing-sm);
}

.action-sheet-separator {
    height: 8px;
    background: var(--bg-secondary);
}

/* ============================================================================
   🔔 УВЕДОМЛЕНИЯ И АЛЕРТЫ
   ============================================================================ */

.alert {
    position: fixed;
    top: var(--spacing-md);
    right: var(--spacing-md);
    left: var(--spacing-md);
    z-index: calc(var(--z-index-modal) + 20);
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--spacing-md);
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
    transform: translateY(-100%);
    transition: transform var(--duration-normal) var(--ease-back);
}

.alert.active {
    transform: translateY(0);
}

.alert.success {
    border-left: 4px solid var(--success-color);
}

.alert.warning {
    border-left: 4px solid var(--warning-color);
}

.alert.error {
    border-left: 4px solid var(--error-color);
}

.alert.info {
    border-left: 4px solid var(--info-color);
}

.alert-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--spacing-xs);
    color: var(--text-primary);
}

.alert-message {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    line-height: var(--line-height-normal);
}

.alert-close {
    width: 24px;
    height: 24px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
}

/* ============================================================================
   📱 МОБИЛЬНАЯ АДАПТАЦИЯ
   ============================================================================ */

@media (max-width: 480px) {
    .modal {
        padding: var(--spacing-sm);
    }
    
    .modal-content {
        max-height: 95vh;
        border-radius: var(--radius-lg);
    }
    
    .modal-header {
        padding: var(--spacing-md) var(--spacing-md) 0;
    }
    
    .modal-body {
        padding: var(--spacing-md);
        max-height: calc(95vh - 120px);
    }
    
    .modal-footer {
        padding: 0 var(--spacing-md) var(--spacing-md);
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
    }
    
    .drawer-left,
    .drawer-right {
        width: 280px;
        max-width: 85vw;
    }
    
    .action-sheet {
        left: var(--spacing-sm);
        right: var(--spacing-sm);
        bottom: var(--spacing-sm);
    }
    
    .alert {
        left: var(--spacing-sm);
        right: var(--spacing-sm);
        top: var(--spacing-sm);
    }
}

/* ============================================================================
   🎭 АНИМАЦИИ И ЭФФЕКТЫ
   ============================================================================ */

/* Анимация появления модального окна */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(40px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-animated .modal-content {
    animation: modalFadeIn var(--duration-normal) var(--ease-back);
}

/* Анимация закрытия */
@keyframes modalFadeOut {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.8) translateY(40px);
    }
}

.modal-closing .modal-content {
    animation: modalFadeOut var(--duration-fast) var(--ease-in);
}

/* Эффект встряски */
@keyframes modalShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.modal-shake .modal-content {
    animation: modalShake 0.5s ease-in-out;
}

/* ============================================================================
   🎯 СПЕЦИАЛЬНЫЕ МОДАЛЬНЫЕ ОКНА ДЛЯ MINI APP
   ============================================================================ */

/* Модальное окно профиля */
.profile-modal .modal-content {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-secondary));
}

.profile-modal .modal-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: var(--text-inverse);
    margin: calc(-1 * var(--spacing-lg)) calc(-1 * var(--spacing-lg)) var(--spacing-md);
    padding: var(--spacing-lg);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

/* Модальное окно достижений */
.achievements-modal .modal-body {
    text-align: center;
}

.achievements-modal .achievement-icon {
    font-size: 64px;
    margin-bottom: var(--spacing-md);
    animation: achievementBounce 1s ease-out;
}

@keyframes achievementBounce {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Модальное окно настроек */
.settings-modal .modal-body {
    padding: 0;
}

.settings-section {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--bg-secondary);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-md);
}

/* ============================================================================
   🔧 УТИЛИТАРНЫЕ КЛАССЫ
   ============================================================================ */

/* Отключение скроллинга body при открытом модальном окне */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Затемнение фона */
.modal-blur {
    filter: blur(2px);
    transition: filter var(--duration-normal) var(--ease-out);
}

/* Состояния модальных окон */
.modal-loading .modal-content {
    position: relative;
}

.modal-loading .modal-content::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.modal-disabled {
    pointer-events: none;
    opacity: 0.6;
}

/* ============================================================================
   🖼️ PROFILE MODAL AVATAR STYLES
   ============================================================================ */

.profile-avatar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.profile-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(210, 69, 44, 0.3);
    border: 4px solid var(--bg-card);
    transition: all var(--duration-normal) var(--ease-out);
    background: linear-gradient(135deg,
        var(--primary-color, #D2452C),
        var(--primary-light, #E5674F)
    );
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
}

.profile-avatar:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(210, 69, 44, 0.4);
}

/* Profile avatar image */
.profile-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
}

/* Profile avatar fallback */
.profile-avatar-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg,
        var(--primary-color, #D2452C),
        var(--primary-light, #E5674F)
    );
    color: white;
    font-weight: 700;
    font-size: 36px;
    text-transform: uppercase;
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* Show fallback when avatar has fallback class or image is hidden */
.profile-avatar.fallback .profile-avatar-img,
.profile-avatar .profile-avatar-img[style*="display: none"] {
    display: none !important;
}

/* Change avatar button */
.change-avatar-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    transition: all var(--duration-normal) var(--ease-out);
    min-height: var(--touch-target-min);
}

.change-avatar-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(210, 69, 44, 0.3);
}

.change-avatar-btn:active {
    transform: translateY(0);
}

.change-avatar-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.change-avatar-btn .btn-icon {
    font-size: var(--font-size-base);
}

/* Hidden file input */
.avatar-file-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}
