/**
 * 聊天相册样式
 */

/* 相册弹窗 */
#chat-gallery-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

#chat-gallery-modal.show {
    opacity: 1;
    visibility: visible;
}

/* 相册头部 */
.gallery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    padding-top: calc(env(safe-area-inset-top, 16px) + 8px);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.gallery-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.gallery-back-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-title {
    color: white;
    font-size: 18px;
    font-weight: 600;
}

.gallery-count {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

/* 相册内容 */
.gallery-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

/* 日期分组 */
.gallery-date-group {
    margin-bottom: 24px;
}

.gallery-date-label {
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    margin-bottom: 12px;
    padding-left: 4px;
}

/* 图片网格 */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.gallery-item:active img {
    transform: scale(0.95);
}

.gallery-item-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    padding: 2px 4px;
    font-size: 10px;
}

/* 图片查看器 */
#chat-gallery-viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

#chat-gallery-viewer.show {
    opacity: 1;
    visibility: visible;
}

/* 查看器头部 */
.viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    padding-top: calc(env(safe-area-inset-top, 16px) + 8px);
}

.viewer-close-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.viewer-index {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

/* 查看器内容 - 翻转卡片 */
.viewer-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    perspective: 1200px;
    -webkit-perspective: 1200px;
}

.viewer-card {
    position: relative;
    width: 100%;
    height: 100%;
    /* 移除固定宽高比和宽度限制，让卡片自适应屏幕空间 */
    max-width: 100%;
    aspect-ratio: auto;
    
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    /* 确保卡片居中，防止歪斜 */
    margin: 0 auto;
    transform-origin: center center;
    will-change: transform;
}

.viewer-card.flipped {
    transform: rotateY(180deg);
    -webkit-transform: rotateY(180deg);
}

.viewer-front,
.viewer-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 16px;
    overflow: hidden;
}

.viewer-front {
    background: #000;
    /* 确保正面默认在最前 */
    z-index: 2;
    transform: rotateY(0deg);
    -webkit-transform: rotateY(0deg);
    /* 使用 Flex 布局确保图片完美居中 */
    display: flex;
    align-items: center;
    justify-content: center;
}

.viewer-back {
    /* 🔧 关键：背面需要 rotateY(180deg) 才能正确显示 */
    /* 升级为 iOS 风格深色背景：深空灰渐变，更具质感 */
    background: linear-gradient(180deg, #2c2c2e 0%, #1c1c1e 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    transform: rotateY(180deg);
    -webkit-transform: rotateY(180deg);
    z-index: 1;
    /* 确保内容不溢出 */
    box-sizing: border-box;
}

.viewer-back-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* 印象文字 */
.impression-text {
    color: white;
    width: 100%;
}

.impression-label {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.impression-text p {
    font-size: 16px;
    line-height: 1.7;
    margin: 0;
    white-space: pre-wrap;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 400;
}

/* 印象空状态 */
.impression-empty {
    color: rgba(255, 255, 255, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.impression-empty p {
    margin: 0;
    font-size: 15px;
    opacity: 0.8;
}

/* 升级后的“生成描述”按钮 - 液态玻璃风格 */
.impression-generate-btn {
    padding: 12px 28px;
    /* 玻璃态背景 */
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    /* 细边框和高光 */
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-radius: 30px;
    
    color: white;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    
    display: flex;
    align-items: center;
    gap: 8px;
}

.impression-generate-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
    box-shadow: 
        0 6px 16px rgba(0, 0, 0, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.impression-generate-btn:active {
    transform: scale(0.96) translateY(0);
    background: rgba(255, 255, 255, 0.08);
}

/* 印象生成中 */
.impression-pending {
    color: rgba(255, 255, 255, 0.8);
}

.impression-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 查看器控制区 */
.viewer-controls {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.viewer-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.viewer-nav-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.viewer-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.viewer-flip-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 20px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 底部操作按钮 */
.viewer-actions-front,
.viewer-actions-back {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding-bottom: env(safe-area-inset-bottom, 20px);
}

.viewer-action-btn {
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 24px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.viewer-action-btn:active {
    background: rgba(255, 255, 255, 0.25);
}

/* 响应式 */
@media (max-width: 400px) {
    .gallery-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* 触摸滑动提示 */
.viewer-swipe-hint {
    position: absolute;
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
    color: rgba(255, 255, 255, 0.3);
    font-size: 12px;
    pointer-events: none;
}

/* ==================== 聊天快捷菜单 ==================== */
.chat-quick-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 12px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.95);
    transform-origin: top right;
    transition: all 0.2s ease;
    min-width: 140px;
}

.chat-quick-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.chat-quick-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    color: #333;
    font-size: 15px;
}

.chat-quick-menu-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.chat-quick-menu-item:active {
    background: rgba(0, 0, 0, 0.1);
}

.chat-quick-menu-item svg {
    width: 18px;
    height: 18px;
    color: #666;
    flex-shrink: 0;
}

.chat-quick-menu-item + .chat-quick-menu-item {
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

/* 深色主题适配 */
@media (prefers-color-scheme: dark) {
    .chat-quick-menu {
        background: rgba(40, 40, 45, 0.95);
    }

    .chat-quick-menu-item {
        color: #fff;
    }

    .chat-quick-menu-item svg {
        color: #aaa;
    }

    .chat-quick-menu-item:hover {
        background: rgba(255, 255, 255, 0.08);
    }

    .chat-quick-menu-item + .chat-quick-menu-item {
        border-top-color: rgba(255, 255, 255, 0.08);
    }
}
