/* styles.css - 預約平台核心樣式表 (Unified UI/UX) */

/* =========================================
   1. CSS 變數定義 (主題系統)
   ========================================= */
:root {
    /* 核心品牌色 (藍紫色系) */
    --brand: #3b82f6;
    --brand-hover: #2563eb;
    --brand-light: #eff6ff;
    
    /* 輔助色 */
    --brand-2: #8e44ad; /* 漸層用 */
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --warning: #f59e0b;

    /* 介面顏色 (Light Mode 預設) */
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --ring: rgba(59, 130, 246, 0.4); /* 聚焦光圈 */
    
    /* 陰影與圓角 */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.1);
    --radius: 12px;
}

/* 深色模式覆寫 */
[data-theme="dark"] {
    --brand: #60a5fa;
    --brand-hover: #3b82f6;
    --brand-light: rgba(96, 165, 250, 0.15);
    
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --ring: rgba(96, 165, 250, 0.3);
    
    --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
}

/* =========================================
   2. 基礎重置 (Reset & Base)
   ========================================= */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', 'Noto Sans TC', system-ui, -apple-system, sans-serif;
    background: linear-gradient(180deg, var(--bg) 0%, rgba(255,255,255,0.05) 100%);
    background-color: var(--bg); /* Fallback */
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 60px; /* 預留底部空間 */
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
}

/* 容器限制 */
.container, .table-container, .wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    width: 100%;
}

/* =========================================
   3. 標題與排版 (Typography)
   ========================================= */
h1 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    margin: 10px 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    color: var(--text);
}

h1::before {
    content: "";
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--brand);
    box-shadow: 0 0 0 6px var(--brand-light);
}

h2 {
    font-size: 1.25rem;
    margin-bottom: 16px;
    color: var(--text);
    font-weight: 600;
}

/* =========================================
   4. 元件：按鈕 (Buttons)
   ========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 999px; /* Pill shape */
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border);
    background: var(--brand);
    color: #fff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
    white-space: nowrap;
    text-decoration: none;
}

.btn:hover {
    background: var(--brand-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.35);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 幽靈按鈕 (透明背景) */
.btn--ghost {
    background: transparent;
    color: var(--text);
    box-shadow: none;
}

.btn--ghost:hover {
    background: var(--bg);
    border-color: var(--brand);
    color: var(--brand);
    box-shadow: none;
}

/* 危險按鈕 */
.btn--danger {
    background: var(--danger);
    border-color: var(--danger);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.btn--danger:hover {
    background: var(--danger-hover);
}

/* 次要按鈕 */
.btn--secondary {
    background: var(--bg);
    color: var(--text);
    box-shadow: none;
}

.btn--secondary:hover {
    background: var(--border);
}

/* 小型按鈕 */
.btn--sm {
    padding: 6px 12px;
    font-size: 13px;
    min-width: auto;
}

/* 提交按鈕 (全寬) */
.submit-button, .btn--submit {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    border-radius: 12px;
    background: var(--brand);
    color: white;
    border: none;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.2s;
    box-shadow: 0 4px 12px var(--ring);
}
.submit-button:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

/* =========================================
   5. 元件：卡片與容器 (Cards & Layouts)
   ========================================= */
.card, .form-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* =========================================
   6. 元件：表單輸入 (Forms & Inputs)
   ========================================= */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

label {
    font-size: 14px;
    color: var(--muted);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 帶圖標的輸入框容器 */
.input-wrapper, .input {
    position: relative;
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    transition: all 0.2s ease;
    overflow: hidden;
}

.input-wrapper:focus-within, .input:focus-within {
    border-color: var(--brand);
    background: var(--card);
    box-shadow: 0 0 0 3px var(--ring);
}

.input-wrapper i, .input i {
    padding-left: 14px;
    color: var(--muted);
    font-size: 1rem;
    flex-shrink: 0;
}

.input-wrapper input, .input-wrapper select, .input-wrapper textarea,
.input input, .input select, .input textarea {
    width: 100%;
    border: none;
    padding: 12px 14px;
    background: transparent;
    color: var(--text);
    font-size: 15px;
    outline: none;
    font-family: inherit;
    appearance: none; /* 移除預設樣式 */
}

textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}

/* 篩選器樣式 */
.filters {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    align-items: end;
}

/* =========================================
   7. 元件：置頂工具列 (Toolbar)
   ========================================= */
.toolbar {
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 10px 0;
    margin-bottom: 20px;
    /* 玻璃擬態效果 */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.toolbar-inner {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    flex: 1;
}

/* =========================================
   8. 元件：表格與 RWD 卡片化 (Tables)
   ========================================= */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

th {
    background: var(--bg);
    color: var(--muted);
    font-weight: 600;
    padding: 14px 16px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background-color: var(--brand-light);
}

/* =========================================
   9. 小元件：標籤、提示、Toast (Utilities)
   ========================================= */
/* Chips / Badges */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
}

.chip--active { background: #f0f9ff; color: #0ea5e9; border-color: #e0f2fe; }
.chip--closed { background: #fef2f2; color: #ef4444; border-color: #fee2e2; }
.chip--date { background: #eff6ff; color: #3b82f6; border-color: #dbeafe; }

/* Alerts */
.alert, .alert-error, .alert-info {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    line-height: 1.5;
}
.alert-error, .danger { background: #fef2f2; color: #b91c1c; border: 1px solid #fca5a5; }
.alert-info, .ok-message { background: #eff6ff; color: #1d4ed8; border: 1px solid #dbeafe; }
.alert-success { background: #ecfdf5; color: #047857; border: 1px solid #6ee7b7; }

/* Toast (浮動通知) */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--text);
    color: var(--bg);
    padding: 12px 24px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    pointer-events: none;
    font-weight: 500;
    white-space: nowrap;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* 浮動操作列 (手機批次刪除用) */
.sticky-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(150px);
    background: var(--text);
    color: var(--bg);
    padding: 10px 20px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    transition: transform 0.3s ease;
    z-index: 100;
}
.sticky-bar.show { transform: translateX(-50%) translateY(0); }

/* =========================================
   10. 響應式設計 (Mobile Adaptations)
   ========================================= */
@media (max-width: 900px) {
    .grid, .form-grid {
        grid-template-columns: 1fr; /* 強制單欄 */
    }

    .header-actions {
        justify-content: center;
    }
    
    .toolbar-inner {
        flex-direction: column;
        align-items: stretch;
    }
    
    .btn {
        width: 100%; /* 手機按鈕滿版 */
    }
    
    .theme-toggle {
        position: absolute;
        top: 10px;
        right: 10px;
        width: auto;
        padding: 8px;
        border-radius: 50%;
    }

    /* 手機版：表格轉卡片 (Table to Card) */
    /* 必須配合 HTML 中的 data-label 屬性 */
    thead { display: none; }
    table, tbody, tr, td { display: block; width: 100%; }
    
    tr {
        margin-bottom: 16px;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: 16px;
        box-shadow: var(--shadow-sm);
        padding: 8px 0;
    }
    
    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        padding: 10px 16px;
        border-bottom: 1px dashed var(--border);
        position: relative;
    }
    
    td:last-child {
        border-bottom: none;
        justify-content: flex-end;
        gap: 8px;
    }
    
    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        font-size: 13px;
        text-align: left;
    }
    
    /* 針對核取方塊的特殊處理 */
    td[data-label="選取"] {
        justify-content: flex-start;
        background: var(--brand-light);
        margin-top: -8px;
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        border-bottom: 1px solid var(--border);
    }
    td[data-label="選取"]::before { content: none; }
}

/* =========================================
   11. 其他通用類別 (Utilities)
   ========================================= */
.text-center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.view-toggle { display: flex; gap: 4px; background: var(--border); padding: 4px; border-radius: 10px; width: fit-content; margin: 0 auto 16px; }
.view-toggle button { background: transparent; border: none; padding: 6px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.view-toggle button.active { background: var(--card); color: var(--brand); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }

footer {
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    margin-top: 30px;
}