:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-start: #0f172a;
    --bg-end: #1e1b4b;
    --card-bg: rgba(30, 41, 59, 0.7);
    --card-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
}

:root[data-theme="light"] {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-start: #f8fafc;
    --bg-end: #e2e8f0;
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(255, 255, 255, 0.7);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --success: #059669;
    --error: #dc2626;
    --warning: #d97706;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 4rem;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--bg-start), var(--bg-end));
    overflow-y: auto;
    position: relative;
}

/* 動態背景 */
.background-animation {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at 50% 50%, rgba(79, 70, 229, 0.15) 0%, transparent 60%);
    z-index: 0;
    animation: pulse 8s infinite alternate;
    pointer-events: none;
}

@keyframes pulse {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 0.8;}
    100% { transform: translate(-50%, -50%) scale(1.2); opacity: 0.4;}
}

.container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 800px;
    padding: 2rem;
    padding-bottom: 4rem;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Glassmorphism Card */
.glass-panel {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* 拖曳區 */
.drop-zone {
    border: 2px dashed rgba(129, 140, 248, 0.4);
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    background: rgba(15, 23, 42, 0.3);
}

:root[data-theme="light"] .drop-zone {
    background: rgba(241, 245, 249, 0.5);
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: #818cf8;
    background: rgba(79, 70, 229, 0.1);
}

.upload-icon {
    color: #818cf8;
    margin-bottom: 1rem;
    transition: transform 0.3s ease;
}

.drop-zone:hover .upload-icon {
    transform: translateY(-5px);
}

.drop-zone h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.drop-zone p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.privacy-notice {
    margin-top: 0.5rem;
    font-size: 0.8rem !important;
    font-weight: 500;
    color: var(--success) !important;
}

/* 隱藏原生 input，覆蓋整個 zone */
.drop-zone input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.hidden {
    display: none !important;
}

/* ================================ */
/* 檔案列表區                       */
/* ================================ */
#file-list-container {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.file-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.file-list-header h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.file-count-badge {
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 24px;
    text-align: center;
}

.file-list-actions {
    display: flex;
    gap: 0.5rem;
}

.file-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    margin-bottom: 1.25rem;
}

.file-list::-webkit-scrollbar {
    width: 6px;
}

.file-list::-webkit-scrollbar-track {
    background: transparent;
}

.file-list::-webkit-scrollbar-thumb {
    background: rgba(129, 140, 248, 0.3);
    border-radius: 3px;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.15s ease;
    gap: 0.5rem;
}

:root[data-theme="light"] .file-item {
    border-bottom-color: rgba(0, 0, 0, 0.06);
}

.file-item:hover {
    background: rgba(79, 70, 229, 0.06);
}

.file-item:last-child {
    border-bottom: none;
}

.file-item-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1;
}

.file-item-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
}

.file-item-icon.photo { background: linear-gradient(135deg, #818cf8, #6366f1); }
.file-item-icon.video { background: linear-gradient(135deg, #f472b6, #ec4899); }
.file-item-icon.other { background: linear-gradient(135deg, #94a3b8, #64748b); }

.file-item-name {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-item-size {
    font-size: 0.75rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.file-item-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
}

.file-item-remove:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

/* 重複檔案警告 */
.duplicate-warning {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--warning);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

.duplicate-warning svg {
    flex-shrink: 0;
}

/* ================================ */
/* 按鈕樣式                         */
/* ================================ */
.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.4);
}

.primary-btn.full-width {
    width: 100%;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

:root[data-theme="light"] .secondary-btn {
    background: rgba(0, 0, 0, 0.04);
}

.secondary-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(79, 70, 229, 0.06);
}

.secondary-btn.small {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

.secondary-btn.danger:hover {
    border-color: var(--error);
    color: var(--error);
    background: rgba(239, 68, 68, 0.06);
}

/* ================================ */
/* 進度條                           */
/* ================================ */
#progress-container {
    margin-top: 2rem;
    text-align: center;
}

#progress-container h3 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4f46e5, #c084fc);
    border-radius: 4px;
    transition: width 0.3s ease;
}

#progress-detail {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ================================ */
/* 分類預覽區                        */
/* ================================ */
#preview-container {
    animation: fadeIn 0.3s ease;
}

.preview-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.preview-header h3 {
    font-size: 1.5rem;
    color: var(--success);
    margin-bottom: 1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

:root[data-theme="light"] .stat-card {
    background: rgba(0, 0, 0, 0.04);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-card.success .stat-value { color: var(--success); }
.stat-card.error .stat-value { color: var(--error); }

/* 樹狀結構 */
.tree-view {
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 1.25rem;
}

.tree-view::-webkit-scrollbar {
    width: 6px;
}

.tree-view::-webkit-scrollbar-track {
    background: transparent;
}

.tree-view::-webkit-scrollbar-thumb {
    background: rgba(129, 140, 248, 0.3);
    border-radius: 3px;
}

.tree-node {
    user-select: none;
}

.tree-folder {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: background 0.15s ease;
}

.tree-folder:hover {
    background: rgba(79, 70, 229, 0.08);
}

.tree-folder-icon {
    transition: transform 0.2s ease;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.tree-folder-icon.open {
    transform: rotate(90deg);
}

.tree-folder-name {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.tree-folder-count {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 6px;
    border-radius: 8px;
}

:root[data-theme="light"] .tree-folder-count {
    background: rgba(0, 0, 0, 0.06);
}

.tree-children {
    margin-left: 1.25rem;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    padding-left: 0.5rem;
}

:root[data-theme="light"] .tree-children {
    border-left-color: rgba(0, 0, 0, 0.08);
}

.tree-children.collapsed {
    display: none;
}

.tree-file {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.tree-file:hover {
    background: rgba(79, 70, 229, 0.08);
    color: var(--text-primary);
}

.tree-file-icon {
    flex-shrink: 0;
}

.tree-file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 匯出選項 */
.export-options {
    margin-bottom: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    transition: background 0.15s ease;
}

.checkbox-label:hover {
    background: rgba(79, 70, 229, 0.06);
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.preview-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}


/* ================================ */
/* 頂部按鈕區                       */
/* ================================ */
.top-controls {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    gap: 0.75rem;
    z-index: 10;
}

.icon-btn, .text-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.2s ease;
}

.text-btn {
    border-radius: 20px;
    width: auto;
    padding: 0 12px;
    font-weight: 600;
    font-size: 0.875rem;
}

.icon-btn:hover, .text-btn:hover {
    background: rgba(79, 70, 229, 0.05);
    border-color: var(--primary);
    color: var(--primary);
}

.app-version {
    position: fixed;
    bottom: 1rem;
    right: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    z-index: 10;
    font-family: monospace;
}

/* ================================ */
/* RWD                              */
/* ================================ */
@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }
    
    .glass-panel {
        padding: 1.5rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .file-list-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .preview-actions {
        flex-direction: column;
    }
    
    .preview-actions .primary-btn,
    .preview-actions .secondary-btn {
        width: 100%;
        justify-content: center;
    }
}
