/* ==================== 全域主題系統 v15 ==================== */
/* 最後更新: 統一所有頁面風格 */

/* ==================== Reset ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ==================== CSS 變數 ==================== */

/* Dark Mode (預設) */
:root {
    /* 主色 */
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #818cf8;
    --accent: #06b6d4;
    
    /* 語意色 */
    --success: #10b981;
    --success-light: #34d399;
    --danger: #ef4444;
    --danger-light: #f87171;
    --warning: #f59e0b;
    --warning-light: #fbbf24;
    
    /* 背景 */
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-surface: #334155;
    
    /* 文字 */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* 邊框與陰影 */
    --border: #475569;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-hover: rgba(0, 0, 0, 0.5);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.2);
}

/* Light Mode */
[data-theme="light"] {
    /* 背景 */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-surface: #f1f5f9;
    
    /* 文字 */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    
    /* 邊框與陰影 */
    --border: #e2e8f0;
    --shadow: rgba(15, 23, 42, 0.08);
    --shadow-hover: rgba(15, 23, 42, 0.15);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 6px rgba(15, 23, 42, 0.07);
    --shadow-lg: 0 10px 15px rgba(15, 23, 42, 0.1);
    --shadow-xl: 0 20px 25px rgba(15, 23, 42, 0.15);
}

/* ==================== 基礎樣式 ==================== */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
    background: linear-gradient(135deg, var(--bg-main) 0%, var(--bg-card) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    padding-top: 80px;
    line-height: 1.5;
}

/* ==================== 容器 ==================== */

.container {
    max-width: 672px;
    margin: 0 auto;
    padding: 0 20px;
}

.container-wide {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* ==================== Header ==================== */

.header {
    background: rgba(30, 41, 59, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 4px 6px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    transition: all 0.3s ease;
}

[data-theme="light"] .header {
    background: rgba(255, 255, 255, 0.85);
}

.header-content {
    max-width: 672px;
    margin: 0 auto;
    padding: 20px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ==================== 頁面標題 ==================== */

.page-title {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: var(--primary); /* Firefox fallback */
    margin: 0;
}

/* ==================== 區塊標題 ==================== */

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(79, 70, 229, 0.15);
    color: var(--primary);
    border-radius: 6px;
}

/* ==================== 卡片系統 ==================== */

.card,
.app-card,
.glass-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

[data-theme="light"] .card,
[data-theme="light"] .app-card,
[data-theme="light"] .glass-card {
    box-shadow: 0 2px 8px var(--shadow);
}

/* 頂部漸層線條 */
.card::before,
.app-card::before,
.glass-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Hover 效果 */
.card:hover,
.app-card:hover,
.glass-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px var(--shadow-hover);
    border-color: var(--primary-light);
}

.card:hover::before,
.app-card:hover::before,
.glass-card:hover::before {
    opacity: 1;
}

/* Portal 專用卡片 */
.app-card {
    display: flex;
    flex-direction: column;
    min-height: 240px;
    height: 100%;
    text-decoration: none;
    color: inherit;
}

/* ==================== 按鈕系統 ==================== */

/* 基礎按鈕 */
.btn {
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    font-family: inherit;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-hover);
}

/* 主要按鈕 */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
}

/* 次要按鈕 */
.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 2px solid var(--border);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-hover);
}

/* 成功按鈕 */
.btn-success {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

/* 危險按鈕 */
.btn-danger {
    background: linear-gradient(135deg, var(--danger), #dc2626);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

/* Header 專用新增按鈕 */
.btn-add {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 12px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-add:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
}

.btn-add svg {
    width: 20px;
    height: 20px;
}

/* Header 次要 icon 按鈕 */
.btn-icon-secondary {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-hover);
    border-color: var(--primary-light);
    color: var(--primary-light);
}

.btn-icon-secondary svg {
    width: 20px;
    height: 20px;
}

/* 小型 Icon 按鈕 */
.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-surface);
    color: var(--text-secondary);
}

.btn-icon:hover {
    transform: scale(1.08);
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

.btn-icon-primary {
    background: rgba(79, 70, 229, 0.15);
    color: var(--primary);
}

.btn-icon-primary:hover {
    background: var(--primary);
    color: white;
}

.btn-icon-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.btn-icon-success:hover {
    background: var(--success);
    color: white;
}

.btn-icon-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.btn-icon-danger:hover {
    background: var(--danger);
    color: white;
}

/* 顯示/隱藏切換按鈕 */
.btn-reveal {
    background: rgba(79, 70, 229, 0.2);
    border: none;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-light);
}

.btn-reveal:hover {
    background: rgba(79, 70, 229, 0.4);
}

[data-theme="light"] .btn-reveal {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary);
}

[data-theme="light"] .btn-reveal:hover {
    background: rgba(79, 70, 229, 0.2);
}

.btn-reveal svg {
    width: 18px;
    height: 18px;
}

/* 小型文字按鈕 */
.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 8px;
}

/* ==================== 表單系統 ==================== */

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
    background: var(--bg-card);
}

[data-theme="light"] .form-input:focus,
[data-theme="light"] .form-select:focus,
[data-theme="light"] .form-textarea:focus {
    background: white;
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

[data-theme="light"] .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

/* ==================== Modal 系統 ==================== */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.modal-backdrop.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 20px;
    box-shadow: 0 20px 60px var(--shadow);
    max-width: 480px;
    width: calc(100% - 2rem);
    max-height: calc(100vh - 2rem);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.25s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.modal-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-icon svg {
    width: 20px;
    height: 20px;
    stroke: white;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
    margin: 0;
}

.modal-close {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.modal-close svg {
    width: 20px;
    height: 20px;
    stroke: white;
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
    flex: 1;
}

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

.modal-footer .btn {
    flex: 1;
}

/* ==================== Badge 標籤系統 ==================== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-primary {
    background: rgba(79, 70, 229, 0.15);
    color: var(--primary);
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.badge-muted {
    background: var(--bg-surface);
    color: var(--text-muted);
}

/* ==================== 狀態顏色 ==================== */

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

.status-warning {
    color: var(--warning-light);
}

.status-danger {
    color: var(--danger-light);
}

/* ==================== Toggle 開關 ==================== */

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-surface);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border);
}

.toggle.active {
    background: var(--success);
    border-color: var(--success);
}

.toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.toggle.active .toggle-knob {
    left: 22px;
}

/* ==================== Info Banner ==================== */

.info-banner {
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1), rgba(6, 182, 212, 0.1));
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.info-banner-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.info-banner-icon svg {
    width: 20px;
    height: 20px;
}

.info-banner-content h3 {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
    margin-bottom: 0.125rem;
}

.info-banner-content p {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 0;
}

/* ==================== List Item ==================== */

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-surface);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.list-item:hover {
    background: var(--bg-main);
}

.list-item:last-child {
    margin-bottom: 0;
}

.list-item-content {
    flex: 1;
}

.list-item-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.list-item-meta {
    font-size: 12px;
    color: var(--text-muted);
}

/* ==================== 搜尋框 ==================== */

.search-box {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 14px 14px 14px 48px;
    background: var(--bg-surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.3s ease;
}

[data-theme="light"] .search-input {
    box-shadow: 0 1px 2px var(--shadow);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
    background: var(--bg-card);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 20px;
    height: 20px;
    pointer-events: none;
}

/* ==================== Empty State ==================== */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    background: var(--bg-surface);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.empty-state-icon svg {
    width: 32px;
    height: 32px;
}

.empty-state p {
    margin: 0;
}

.empty-state p + p {
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

/* ==================== Toast 通知 ==================== */

.toast {
    position: fixed;
    top: 100px;
    right: 1rem;
    padding: 0.875rem 1.25rem;
    border-radius: 12px;
    font-weight: 500;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    box-shadow: var(--shadow-lg);
    z-index: 10000;
    animation: toastSlideIn 0.25s ease-out;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast-success {
    background: var(--success);
    color: white;
}

.toast-error {
    background: var(--danger);
    color: white;
}

.toast-info {
    background: var(--primary);
    color: white;
}

.toast-warning {
    background: var(--warning);
    color: white;
}

/* Inline Toast (卡片內提示) */
.inline-toast {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    font-weight: 600;
    font-size: 15px;
    animation: fadeIn 0.2s ease;
}

.inline-toast-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.95), rgba(5, 150, 105, 0.95));
    color: white;
}

/* ==================== 動畫 ==================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

.slide-in {
    animation: slideIn 0.25s ease-out;
}

/* ==================== Utility Classes ==================== */

.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

.text-secondary {
    color: var(--text-secondary);
}

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }

.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

/* ==================== 捲軸樣式 ==================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-surface);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border);
}

/* ==================== 響應式 ==================== */

@media (max-width: 768px) {
    body {
        padding-top: 70px;
    }
    
    .header-content {
        padding: 16px;
    }
    
    .page-title {
        font-size: 24px;
    }
    
    .btn-add {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .modal-content {
        width: calc(100% - 1rem);
        max-height: calc(100vh - 1rem);
    }
    
    .container {
        padding: 0 16px;
    }
}
