/* ==========================================================================
   系統核心變數與設計語彙
   ========================================================================== */
:root {
    /* 顏色系統 - 採用 HSL 調配出優雅和諧的視覺感 */
    --primary: hsl(217, 100%, 54%);       /* 科技湛藍 (呼應圖中的藍) */
    --primary-hover: hsl(217, 100%, 45%);
    --primary-light: hsl(217, 100%, 96%);
    --excel-color: #107c41;                /* Excel 經典綠 */
    --excel-bg-light: #f1f9f5;
    --word-color: #1b5ebe;                 /* Word 經典藍 */
    --word-bg-light: #f0f5fc;
    
    --success: hsl(142, 69%, 45%);
    --success-light: hsl(142, 69%, 96%);
    --warning: hsl(38, 92%, 50%);
    --danger: hsl(354, 70%, 54%);
    
    /* 灰階與背景色 - 呼應圖中的溫潤米灰質感底色 */
    --bg-app: #f5f4ee;                     /* 米灰背景色 */
    --card-bg: rgba(255, 255, 255, 0.95);
    --border-color: hsl(210, 14%, 89%);
    
    --text-primary: hsl(210, 24%, 12%);
    --text-secondary: hsl(210, 12%, 36%);
    --text-muted: hsl(210, 8%, 55%);
    
    /* 特效 */
    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   基本樣式重設與全域設定
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
    padding: 2.5rem 1.5rem;
    position: relative;
}

/* 背景裝飾漸層球體 - 增添流動感與現代美學 */
.background-decor {
    position: fixed;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
    opacity: 0.4;
    pointer-events: none;
}
.decor-1 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, hsl(217, 100%, 75%) 0%, transparent 70%);
    top: -100px;
    right: -100px;
}
.decor-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, hsl(38, 92%, 80%) 0%, transparent 70%);
    bottom: -150px;
    left: -150px;
}
.decor-3 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, hsl(142, 69%, 85%) 0%, transparent 70%);
    top: 40%;
    left: 20%;
}

/* ==========================================================================
   版面配置
   ========================================================================== */
.app-container {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ==========================================================================
   頂部標題區 (Header)
   ========================================================================== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(255, 255, 255, 0.7);
    flex-wrap: wrap;
    gap: 1rem;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

.logo-icon {
    width: 54px;
    height: 54px;
    background: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.6rem;
    box-shadow: 0 4px 15px rgba(0, 132, 255, 0.3);
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

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

.badge {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.6rem 1rem;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.85rem;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: var(--success);
    border-radius: 50%;
    display: inline-block;
    animation: pulse-dot 1.8s infinite;
}

@keyframes pulse-dot {
    0% { transform: scale(0.9); opacity: 0.6; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(0.9); opacity: 0.6; }
}

/* ==========================================================================
   通用卡片元件 (Section Card)
   ========================================================================== */
.section-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.7);
    transition: var(--transition);
}

.section-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1.8rem;
    border-left: 4px solid var(--primary);
    padding-left: 0.8rem;
}

.section-title i {
    font-size: 1.25rem;
    color: var(--primary);
}

.section-title h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   步驟一：範本卡片網格 (Templates Grid)
   ========================================================================== */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.2rem;
}

.template-card {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    padding: 1.2rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.template-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.template-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
}

.excel-theme {
    background-color: var(--excel-bg-light);
    color: var(--excel-color);
}

.word-theme {
    background-color: var(--word-bg-light);
    color: var(--word-color);
}

.template-info {
    flex-grow: 1;
}

.template-info h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
}

.template-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.template-info code {
    background: #f1f1f1;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: monospace;
    color: var(--danger);
}

/* 按鈕樣式 */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    text-decoration: none;
}

.excel-btn {
    background-color: var(--primary);
    color: white;
}
.excel-btn:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(12, 132, 255, 0.25);
}

.word-btn {
    background-color: var(--primary);
    color: white;
}
.word-btn:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(12, 132, 255, 0.25);
}

/* ==========================================================================
   步驟二：上傳區域 (Upload Zones)
   ========================================================================== */
.upload-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.upload-zone {
    position: relative;
    border: 2px dashed var(--border-color);
    background: #ffffff;
    border-radius: var(--radius-md);
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    overflow: hidden;
}

.upload-zone:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: scale(1.02);
}

.file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.upload-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    pointer-events: none; /* 防止干擾 file-input */
}

/* 動態脈衝圖示效果 */
.pulse-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: 0.5rem;
    transition: var(--transition);
}

.word-pulse {
    background: var(--word-bg-light);
    color: var(--word-color);
}
.upload-zone:hover .word-pulse {
    animation: bounce 0.6s ease-in-out infinite alternate;
}

.excel-pulse {
    background: var(--excel-bg-light);
    color: var(--excel-color);
}
.upload-zone:hover .excel-pulse {
    animation: bounce 0.6s ease-in-out infinite alternate;
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-8px); }
}

.upload-prompt h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.file-type-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* 狀態標籤 */
.file-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.5rem;
    background: #f1f1f1;
    color: var(--text-secondary);
}

/* 已上傳狀態 */
.upload-zone.active {
    border-style: solid;
    border-color: var(--success);
    background: var(--success-light);
}

.upload-zone.active .pulse-icon {
    background: var(--success);
    color: white;
}

.upload-zone.active .file-status-badge {
    background: var(--success);
    color: white;
}

/* ==========================================================================
   步驟三：設定面板 (Settings Panel)
   ========================================================================== */
.settings-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.95rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.input-wrapper {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: #ffffff;
    overflow: hidden;
    transition: var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 132, 255, 0.15);
}

.input-wrapper input {
    flex-grow: 1;
    border: none;
    outline: none;
    padding: 0.8rem 1rem;
    font-size: 0.95rem;
    font-family: inherit;
}

.input-suffix {
    background: #f5f5f5;
    padding: 0.8rem 1rem;
    display: flex;
    align-items: center;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    border-left: 1px solid var(--border-color);
}

.help-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.help-text code {
    background: #f1f1f1;
    padding: 1px 4px;
    border-radius: 3px;
    color: var(--primary);
}

/* 欄位標籤預覽區 */
.data-preview-mini h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.data-tag {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid rgba(0, 132, 255, 0.2);
    padding: 0.3rem 0.7rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.data-tag:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.05);
}

/* 開始按鈕 */
.action-trigger-area {
    display: flex;
    justify-content: center;
    margin-top: 0.5rem;
}

.glow-btn {
    background: linear-gradient(135deg, var(--primary) 0%, #0056b3 100%);
    color: white;
    border: none;
    padding: 1rem 3rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.8rem;
    box-shadow: 0 8px 24px rgba(0, 132, 255, 0.35);
    transition: var(--transition);
}

.glow-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(0, 132, 255, 0.5);
}

.glow-btn:active {
    transform: translateY(-1px);
}

/* ==========================================================================
   步驟四：生成結果面板 (Results Panel)
   ========================================================================== */
/* 進度條 */
.progress-container {
    background: #f5f5f5;
    border-radius: var(--radius-md);
    padding: 1.2rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.6rem;
}

.progress-track {
    height: 8px;
    background: #e9e9e9;
    border-radius: 50px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary) 0%, #00bc8c 100%);
    border-radius: 50px;
    transition: width 0.1s ease;
}

/* 統計卡片 */
.results-dashboard {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.stat-num {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.stat-card.success {
    border-color: rgba(16, 124, 65, 0.3);
    background: var(--excel-bg-light);
}
.stat-card.success .stat-num {
    color: var(--excel-color);
}

.stat-card.failure {
    border-color: rgba(220, 53, 69, 0.3);
    background: hsl(354, 70%, 97%);
}
.stat-card.failure .stat-num {
    color: var(--danger);
}

/* 打包下載 */
.download-all-area {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.zip-btn {
    background: linear-gradient(135deg, #e4a11b 0%, #d67a00 100%);
    color: white;
    padding: 0.8rem 2.5rem;
    font-size: 1rem;
    border-radius: 50px;
    box-shadow: 0 4px 15px rgba(228, 161, 27, 0.3);
    width: 100%;
    max-width: 400px;
}

.zip-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(228, 161, 27, 0.45);
}

.zip-btn:disabled {
    background: #cccccc;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.7;
}

/* 結果表格 */
.results-table-container {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #ffffff;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.85rem;
}

.results-table th {
    background: #f5f5f5;
    padding: 0.9rem 1rem;
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.results-table td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.results-table tr:last-child td {
    border-bottom: none;
}

.results-table tr:hover {
    background-color: #fafafa;
}

/* 表格狀態標籤 */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 700;
}

.status-pill.success {
    background-color: var(--success-light);
    color: var(--success);
}

.status-pill.pending {
    background-color: var(--primary-light);
    color: var(--primary);
}

.status-pill.failed {
    background-color: hsl(354, 70%, 97%);
    color: var(--danger);
}

/* 操作按鈕群組 */
.cell-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
}

.icon-btn.primary-icon {
    color: var(--primary);
    border-color: rgba(0, 132, 255, 0.2);
}
.icon-btn.primary-icon:hover:not(:disabled) {
    background-color: var(--primary);
    color: white;
}

.icon-btn.secondary-icon {
    color: var(--text-secondary);
}
.icon-btn.secondary-icon:hover:not(:disabled) {
    background-color: var(--text-secondary);
    color: white;
}

.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ==========================================================================
   預覽Modal對話框
   ========================================================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
    z-index: 1000;
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #ffffff;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.8);
    transform: translateY(20px);
    transition: var(--transition);
}

.modal.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.close-btn {
    border: none;
    background: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
}

.close-btn:hover {
    color: var(--danger);
}

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.preview-data-card {
    background: var(--primary-light);
    border: 1px solid rgba(0, 132, 255, 0.15);
    border-radius: var(--radius-md);
    padding: 1.2rem;
}

.preview-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.8rem;
    border-bottom: 1px solid rgba(0, 132, 255, 0.1);
    padding-bottom: 0.4rem;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
}

.preview-item {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.preview-key {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.preview-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.preview-info-box {
    background: var(--excel-bg-light);
    border: 1px solid rgba(16, 124, 65, 0.15);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    gap: 0.8rem;
    align-items: flex-start;
}

.preview-info-box i {
    color: var(--excel-color);
    font-size: 1.1rem;
    margin-top: 0.1rem;
}

.preview-info-box p {
    font-size: 0.8rem;
    color: var(--excel-color);
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

.secondary-btn {
    background: #e9e9e9;
    color: var(--text-primary);
}
.secondary-btn:hover {
    background: #dddddd;
}

/* ==========================================================================
   腳部宣告 (Footer)
   ========================================================================== */
.app-footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ==========================================================================
   響應式設計 (Responsive Layouts)
   ========================================================================== */
@media (max-width: 768px) {
    body {
        padding: 1rem 0.5rem;
    }
    
    .app-header {
        padding: 1rem 1.2rem;
        flex-direction: column;
        align-items: flex-start;
    }
    
    .section-card {
        padding: 1.2rem;
    }
    
    .upload-grid {
        grid-template-columns: 1fr;
    }
    
    .preview-grid {
        grid-template-columns: 1fr;
    }
}
