/**
 * PhotoManager - 共用照片/影片管理樣式
 * 版本：3.0.0
 *
 * 新增功能：
 * - 影片標記與播放
 * - 下載進度條
 * - 展開功能（+N）
 * - PhotoSwipe v5.4.4 整合樣式
 */

/* ========== 照片網格 ========== */
.pm-photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

@media (min-width: 768px) {
    .pm-photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* ========== 照片卡片 ========== */
.pm-photo-card {
    position: relative;
    background: #1e293b;
    border-radius: 10px;
    overflow: hidden;
    border: none;
    padding: 0;
    cursor: pointer;
    text-align: left;
    color: inherit;
    width: 100%;
    display: block;
    transition: transform 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: rgba(59, 130, 246, 0.3);
}

.pm-photo-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.pm-photo-card:active {
    transform: scale(0.98);
}

/* 縮圖 */
.pm-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    background: #334155;
}

/* 資訊區 */
.pm-info {
    padding: 10px;
}

.pm-title {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #f1f5f9;
}

.pm-meta {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 4px;
}

/* ========== 選取模式 ========== */
.pm-checkbox {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid white;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: bold;
    z-index: 10;
    transition: background 0.15s, border-color 0.15s;
}

.pm-photo-card.select-mode .pm-checkbox {
    display: flex;
}

.pm-photo-card.selected {
    outline: 3px solid #3b82f6;
    outline-offset: -3px;
}

.pm-photo-card.selected .pm-checkbox {
    background: #3b82f6;
    border-color: #3b82f6;
}

/* ========== 批次操作列 ========== */
.pm-batch-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #1e293b;
    padding: 12px 16px;
    display: none;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid #475569;
    z-index: 9999;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
}

.pm-batch-bar.show {
    display: flex;
}

.pm-batch-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pm-batch-count {
    font-size: 0.95rem;
    color: #f1f5f9;
}

.pm-batch-count strong {
    color: #3b82f6;
}

.pm-batch-actions {
    display: flex;
    gap: 8px;
}

/* ========== 按鈕 ========== */
.pm-btn {
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.pm-btn:active {
    transform: scale(0.96);
}

.pm-btn-primary {
    background: #3b82f6;
    color: white;
}

.pm-btn-primary:hover {
    background: #2563eb;
}

.pm-btn-secondary {
    background: #475569;
    color: white;
}

.pm-btn-secondary:hover {
    background: #64748b;
}

.pm-btn-danger {
    background: #ef4444;
    color: white;
}

.pm-btn-danger:hover {
    background: #dc2626;
}

.pm-btn-text {
    background: transparent;
    color: #3b82f6;
    padding: 8px 12px;
}

.pm-btn-text:hover {
    background: rgba(59, 130, 246, 0.1);
}

/* ========== Modal ========== */
.pm-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: none;
    flex-direction: column;
}

.pm-modal.show {
    display: flex;
}

.pm-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.5);
}

.pm-modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pm-modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
}

.pm-modal-close:hover {
    opacity: 1;
}

.pm-modal-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.pm-modal-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* 導航按鈕 */
.pm-modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 3rem;
    color: white;
    background: rgba(0, 0, 0, 0.3);
    padding: 20px 15px;
    cursor: pointer;
    z-index: 10;
    transition: background 0.15s;
    user-select: none;
}

.pm-modal-nav:hover {
    background: rgba(0, 0, 0, 0.6);
}

.pm-modal-nav.prev {
    left: 0;
    border-radius: 0 8px 8px 0;
}

.pm-modal-nav.next {
    right: 0;
    border-radius: 8px 0 0 8px;
}

.pm-modal-nav.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pm-modal-footer {
    background: #1e293b;
    padding: 16px 20px;
}

.pm-modal-counter {
    text-align: center;
    font-size: 0.85rem;
    color: #94a3b8;
    margin-bottom: 8px;
}

.pm-modal-info {
    font-size: 0.9rem;
    color: #f1f5f9;
    margin-bottom: 12px;
}

.pm-modal-info div {
    margin-bottom: 4px;
}

.pm-modal-actions {
    display: flex;
    gap: 10px;
}

.pm-modal-actions .pm-btn {
    flex: 1;
}

/* ========== 載入與空狀態 ========== */
.pm-loading,
.pm-empty {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
    font-size: 0.95rem;
}

.pm-loading::before {
    content: '';
    display: block;
    width: 40px;
    height: 40px;
    border: 3px solid #334155;
    border-top-color: #3b82f6;
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: pm-spin 0.8s linear infinite;
}

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

/* ========== Toast ========== */
.pm-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #10b981;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 90%;
    text-align: center;
}

.pm-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.pm-toast.info {
    background: #3b82f6;
}

.pm-toast.success {
    background: #10b981;
}

.pm-toast.warning {
    background: #f59e0b;
}

.pm-toast.error {
    background: #ef4444;
}

/* ========== 響應式調整 ========== */
@media (max-width: 480px) {
    .pm-modal-nav {
        font-size: 2rem;
        padding: 15px 10px;
    }

    .pm-modal-footer {
        padding: 12px 16px;
    }

    .pm-modal-actions {
        flex-direction: column;
    }

    .pm-batch-bar {
        flex-direction: column;
        gap: 12px;
        padding: 16px;
    }

    .pm-batch-left {
        width: 100%;
        justify-content: space-between;
    }

    .pm-batch-actions {
        width: 100%;
    }

    .pm-batch-actions .pm-btn {
        flex: 1;
    }
}

/* ========== 選取模式按鈕（供外部使用）========== */
.pm-select-btn {
    background: #8b5cf6;
    color: white;
}

.pm-select-btn.active {
    background: #a78bfa;
}

/* ========== v2.0：影片支援 ========== */
.pm-photo-card.is-video .pm-thumb {
    background: #1e293b;
}

/* 影片標記 */
.pm-video-badge {
    position: absolute;
    bottom: 50px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    z-index: 5;
    pointer-events: none;
}

/* Modal 影片 */
.pm-modal-video {
    max-width: 100%;
    max-height: 100%;
    background: black;
}

.pm-video-tag {
    display: inline-block;
    background: #3b82f6;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-top: 4px;
}

/* ========== v2.0：下載進度條 ========== */
.pm-download-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pm-download-overlay.hidden {
    display: none;
}

.pm-download-modal {
    background: #1e293b;
    padding: 32px 40px;
    border-radius: 16px;
    text-align: center;
    min-width: 280px;
    max-width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.pm-download-status {
    font-size: 1rem;
    color: #f1f5f9;
    margin-bottom: 20px;
}

.pm-progress-bar {
    height: 8px;
    background: #334155;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.pm-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    width: 0%;
    transition: width 0.2s ease-out;
    border-radius: 4px;
}

.pm-progress-text {
    font-size: 1.2rem;
    font-weight: 600;
    color: #3b82f6;
}

/* ========== v2.0：展開功能 ========== */
.pm-expand-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s;
}

.pm-expand-indicator:hover {
    background: rgba(0, 0, 0, 0.5);
}

.pm-expand-count {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* 展開後的容器 */
.pm-expanded-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

.pm-expanded-container .pm-photo-card {
    width: 120px;
    height: auto;
}

.pm-expanded-container .pm-thumb {
    width: 120px;
    height: 120px;
}

/* 全選按鈕（每筆紀錄） */
.pm-select-all-record {
    background: #475569;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}

.pm-select-all-record:hover {
    background: #64748b;
}

/* ========== v3.0：PhotoSwipe 覆蓋樣式 ========== */

/* PhotoSwipe 自訂主題 */
.pm-pswp .pswp__bg {
    background: rgba(0, 0, 0, 0.95);
}

/* 關閉按鈕 */
.pm-pswp .pswp__button--close {
    background: rgba(0, 0, 0, 0.5) !important;
    border-radius: 50%;
    margin: 8px;
}

.pm-pswp .pswp__button--close:hover {
    background: rgba(0, 0, 0, 0.7) !important;
}

/* 箭頭按鈕 */
.pm-pswp .pswp__button--arrow--prev,
.pm-pswp .pswp__button--arrow--next {
    background: rgba(0, 0, 0, 0.3) !important;
    border-radius: 8px;
    margin: 8px;
}

.pm-pswp .pswp__button--arrow--prev:hover,
.pm-pswp .pswp__button--arrow--next:hover {
    background: rgba(0, 0, 0, 0.6) !important;
}

/* 自訂下載按鈕 */
.pm-pswp .pswp__button[title="下載"],
.pm-pswp .pswp__button[title="刪除"] {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
}

.pm-pswp .pswp__button[title="下載"]:hover {
    background: rgba(59, 130, 246, 0.8);
}

.pm-pswp .pswp__button[title="刪除"]:hover {
    background: rgba(239, 68, 68, 0.8);
}

.pm-pswp .pswp__button svg {
    color: white;
}

/* 計數器樣式 */
.pm-pswp .pswp__counter {
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.9rem;
}

/* 縮放提示 */
.pm-pswp .pswp__zoom-wrap {
    will-change: transform;
}

/* 載入指示器 */
.pm-pswp .pswp__preloader {
    background: rgba(30, 41, 59, 0.9);
    border-radius: 8px;
}

/* 錯誤訊息 */
.pm-pswp .pswp__error-msg {
    background: rgba(239, 68, 68, 0.9);
    padding: 16px 24px;
    border-radius: 8px;
    color: white;
}

/* 頂部工具列 */
.pm-pswp .pswp__top-bar {
    background: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%, transparent 100%);
    padding: 8px 12px;
}

/* 底部說明（如果啟用） */
.pm-pswp .pswp__caption {
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%);
    padding: 16px 20px;
}

.pm-pswp .pswp__caption__center {
    color: #f1f5f9;
    font-size: 0.9rem;
    text-align: center;
}

/* 手機版優化 */
@media (max-width: 480px) {
    .pm-pswp .pswp__button--arrow--prev,
    .pm-pswp .pswp__button--arrow--next {
        display: none !important;
    }

    .pm-pswp .pswp__top-bar {
        padding: 4px 8px;
    }

    .pm-pswp .pswp__button {
        width: 40px;
        height: 40px;
    }

    .pm-pswp .pswp__counter {
        font-size: 0.8rem;
        padding: 3px 10px;
    }
}

/* 縮放動畫 */
.pm-pswp .pswp__img {
    transition: opacity 0.15s;
}

/* 手勢提示（首次使用） */
.pm-pswp-hint {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    text-align: center;
    pointer-events: none;
    animation: pm-hint-fade 3s ease-out forwards;
}

@keyframes pm-hint-fade {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; visibility: hidden; }
}

/* ========== 相容舊樣式 ========== */
/* line-photos-admin 相容 */
.photo-card.select-mode { position: relative; }
.photo-card.select-mode .checkbox { display: flex; }
.photo-card.selected { outline: 3px solid #3b82f6; }
.photo-card.selected .checkbox { background: #3b82f6; border-color: #3b82f6; }
