/**
 * Universal Attachment Viewer Styles
 * 通用附件檢視器樣式
 * 版本: 2.1.0 (簡化版)
 */

/* ===== 基礎變數 ===== */
:root {
    --attachment-primary-color: #3b82f6;
    --attachment-success-color: #10b981;
    --attachment-warning-color: #f59e0b;
    --attachment-danger-color: #ef4444;
    --attachment-text-primary: #374151;
    --attachment-text-secondary: #6b7280;
    --attachment-bg-secondary: #f8fafc;
    --attachment-border-color: #e5e7eb;
    --attachment-border-radius: 12px;
    --attachment-shadow-sm: 0 4px 15px rgba(0, 0, 0, 0.1);
    --attachment-shadow-md: 0 10px 30px rgba(0, 0, 0, 0.15);
    --attachment-shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.2);
}

/* ===== 附件區塊 ===== */
.attachments-section {
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    padding: 20px;
    border-radius: 16px;
    margin: 15px 0;
    border: 1px solid #0ea5e9;
    transition: all 0.3s ease;
}

.attachments-section:hover {
    box-shadow: var(--attachment-shadow-md);
}

.attachments-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.attachments-label-container {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.attachments-label {
    font-weight: 700;
    color: #0c4a6e;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== 摺疊按鈕 ===== */
.attachment-toggle-btn {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
    position: relative;
    z-index: 10;
    pointer-events: auto;
}

.attachment-toggle-btn:hover {
    background: linear-gradient(135deg, #2563eb, #1e40af);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
}

.attachment-toggle-btn.expanded {
    background: linear-gradient(135deg, #059669, #047857);
}

.attachment-toggle-btn.expanded:hover {
    background: linear-gradient(135deg, #047857, #065f46);
}

.attachment-toggle-btn * {
    pointer-events: none;
}

.toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    pointer-events: none;
}

.toggle-text {
    font-size: 11px;
    font-weight: 600;
    pointer-events: none;
}

/* ===== 下載全部按鈕 ===== */
.btn-download-all {
    background: linear-gradient(135deg, #059669, #047857);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-download-all:hover {
    background: linear-gradient(135deg, #047857, #065f46);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
}

/* ===== 附件網格容器 ===== */
.attachments-grid-container {
    transition: all 0.3s ease;
    overflow: hidden;
}

.attachments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
}

.attachments-grid.single-attachment {
    grid-template-columns: minmax(200px, 300px);
    justify-content: start;
}

/* ===== 附件項目 ===== */
.attachment-item {
    background: white;
    border-radius: var(--attachment-border-radius);
    padding: 12px;
    border: 2px solid #e2e8f0;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.attachment-item:hover {
    border-color: var(--attachment-primary-color);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.15);
}

/* ===== 圖片附件 ===== */
.image-attachment .attachment-image-container {
    position: relative;
    margin-bottom: 10px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: var(--attachment-bg-secondary);
}

.attachment-image {
    width: 100%;
    height: 120px;
    border-radius: 8px;
    object-fit: cover;
    transition: all 0.3s ease;
    display: block;
}

.attachment-image.loading {
    opacity: 0.6;
    filter: blur(1px);
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: attachmentShimmer 1.5s infinite;
}

.attachment-image.image-success {
    animation: imageSuccess 0.5s ease-out;
}

.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 8px;
}

.attachment-image-container:hover .image-overlay {
    opacity: 1;
}

.zoom-icon {
    font-size: 24px;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* ===== 檔案附件 ===== */
.file-attachment .attachment-file {
    font-size: 48px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--attachment-bg-secondary);
    border-radius: 8px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
}

.attachment-item:hover .attachment-file {
    background: #e0f2fe;
    transform: scale(1.05);
}

/* ===== 附件資訊 ===== */
.attachment-info {
    text-align: center;
}

.attachment-name {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #475569;
}

.attachment-size {
    font-size: 11px;
    color: #64748b;
    margin-bottom: 8px;
    opacity: 0.8;
}

.attachment-download {
    background: var(--attachment-primary-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.attachment-download:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* ===== 圖片錯誤處理 ===== */
.attachment-image.image-error {
    border: 2px dashed var(--attachment-danger-color) !important;
    background: #f8d7da !important;
    opacity: 0.8;
    transition: all 0.3s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
    padding: 10px;
    position: relative;
}

.attachment-image.image-error:hover {
    opacity: 1;
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.attachment-image.image-error::before {
    content: '🚫';
    font-size: 32px;
    margin-bottom: 8px;
    display: block;
}

.attachment-image.image-error::after {
    content: '圖片已失效\A點擊重試';
    white-space: pre-line;
    font-size: 11px;
    color: #721c24;
    font-weight: 600;
    line-height: 1.2;
}

/* ===== 圖片模態框 ===== */
.attachment-image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(2px);
    padding: 20px;
    box-sizing: border-box;
}

.attachment-image-modal__content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: modalSlideIn 0.3s ease-out;
}

.attachment-image-modal__close {
    position: absolute;
    top: -40px;
    right: -10px;
    color: white;
    font-size: 36px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10001;
    transition: all 0.3s ease;
    background: none;
    border: none;
    padding: 5px;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-image-modal__close:hover {
    color: var(--attachment-danger-color);
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

.attachment-image-modal__img {
    max-width: 100%;
    max-height: calc(90vh - 80px);
    object-fit: contain;
    border-radius: var(--attachment-border-radius);
    box-shadow: var(--attachment-shadow-lg);
    transition: all 0.3s ease;
}

.attachment-image-modal__img.image-error {
    border-radius: 12px;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
    background: #f8d7da;
    color: #721c24;
    padding: 40px;
}

.attachment-image-modal__img.image-error::before {
    content: '🚫';
    font-size: 64px;
    margin-bottom: 16px;
    display: block;
}

.attachment-image-modal__img.image-error::after {
    content: '圖片載入失敗\ADiscord 圖片連結可能已過期\A點擊重試或嘗試下載原圖';
    white-space: pre-line;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}

.attachment-image-modal__info {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    border-radius: var(--attachment-border-radius);
    margin-top: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: var(--attachment-shadow-lg);
    max-width: 100%;
}

.attachment-image-modal__filename {
    font-weight: 600;
    color: var(--attachment-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.attachment-image-modal__download {
    background: var(--attachment-primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.attachment-image-modal__download:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* ===== 通知系統 ===== */
.attachment-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    font-size: 14px;
    font-weight: 500;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    max-width: 400px;
    word-wrap: break-word;
}

.attachment-notification--success {
    background: var(--attachment-success-color);
    color: white;
}

.attachment-notification--error {
    background: var(--attachment-danger-color);
    color: white;
}

.attachment-notification--info {
    background: var(--attachment-primary-color);
    color: white;
}

.attachment-notification--warning {
    background: var(--attachment-warning-color);
    color: white;
}

/* ===== 動畫 ===== */
@keyframes attachmentShimmer {
    0%, 100% { background-position: 200% 0; }
    50% { background-position: -200% 0; }
}

@keyframes imageSuccess {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== 響應式設計 ===== */
@media (max-width: 768px) {
    .attachments-section {
        padding: 15px;
        margin: 10px 0;
    }

    .attachments-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .attachments-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }

    .attachments-grid.single-attachment {
        grid-template-columns: 1fr;
        max-width: 250px;
    }

    .attachment-image {
        height: 100px;
    }

    .file-attachment .attachment-file {
        height: 100px;
        font-size: 40px;
    }

    .attachment-image-modal {
        padding: 10px;
    }

    .attachment-image-modal__close {
        top: -35px;
        right: -5px;
        font-size: 28px;
        width: 40px;
        height: 40px;
    }

    .attachment-image-modal__img {
        max-height: calc(90vh - 60px);
    }

    .attachment-image-modal__info {
        flex-direction: column;
        gap: 10px;
        text-align: center;
        padding: 12px 16px;
    }

    .attachment-image-modal__filename {
        max-width: 250px;
    }

    .attachment-notification {
        right: 10px;
        left: 10px;
        max-width: none;
        transform: translateY(-100%);
        top: 10px;
    }
}

@media (max-width: 480px) {
    .attachments-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }

    .attachment-image {
        height: 80px;
    }

    .file-attachment .attachment-file {
        height: 80px;
        font-size: 32px;
    }

    .attachment-name {
        font-size: 11px;
    }

    .attachment-size {
        font-size: 10px;
    }

    .attachment-download {
        font-size: 10px;
        padding: 4px 8px;
    }

    .btn-download-all {
        font-size: 11px;
        padding: 6px 12px;
    }

    .attachment-toggle-btn {
        font-size: 10px;
        padding: 4px 8px;
    }

    .toggle-text {
        font-size: 10px;
    }
}