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

/* 相册弹窗 */
#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%;
    max-width: 350px;
    aspect-ratio: 1;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    /* 确保卡片居中，防止歪斜 */
    margin: 0 auto;
}

.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;
    /* 正面不需要旋转 */
    transform: translateZ(1px);
    -webkit-transform: translateZ(1px);
}

.viewer-back {
    /* 🔧 关键：背面需要 rotateY(180deg) 才能正确显示 */
    transform: rotateY(180deg) translateZ(1px);
    -webkit-transform: rotateY(180deg) translateZ(1px);
}

.viewer-front img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* .viewer-back 的背景和布局（transform 已在上方定义） */
.viewer-back {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.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: 14px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 16px;
}

.impression-text p {
    font-size: 16px;
    line-height: 1.8;
    margin: 0;
    white-space: pre-wrap;
}

/* 印象空状态 */
.impression-empty {
    color: rgba(255, 255, 255, 0.6);
}

.impression-empty p {
    margin-bottom: 20px;
}

.impression-generate-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 24px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.impression-generate-btn:active {
    transform: scale(0.95);
}

/* 印象生成中 */
.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);
    }
}
