/* ============================================
   Design System — UI Components 通用元件
   ============================================ */

/* ══════════════════════════════════════
   1. Buttons 按鈕系統
   ══════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    height: 40px;
    border-radius: var(--radius-btn);
    font-family: var(--font-primary);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    line-height: 1;
    cursor: pointer;
    transition: all var(--duration-base) var(--ease-default);
    text-decoration: none;
    white-space: nowrap;
    border: 1px solid transparent;
    outline: none;
}

.btn:focus-visible {
    box-shadow: var(--shadow-ring);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn i,
.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Primary */
.btn-primary {
    background: var(--color-brand);
    color: var(--color-text-inverse);
    border-color: var(--color-brand);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--color-accent-gold, #E8C872);
    border-color: var(--color-accent-gold, #E8C872);
    color: #0A0E17;
}

[data-theme="dark"] .btn-primary {
    box-shadow: none;
}

[data-theme="dark"] .btn-primary:hover {
    background: var(--color-accent-gold, #E8C872);
    border-color: var(--color-accent-gold, #E8C872);
    color: #0A0E17;
    box-shadow: 0 0 18px rgba(232, 200, 114, 0.4), 0 0 36px rgba(232, 200, 114, 0.18);
}

/* Secondary */
.btn-secondary {
    background: var(--color-bg-base);
    color: var(--color-text-secondary);
    border-color: var(--color-border);
    box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-text-primary);
    color: var(--color-text-primary);
}

/* Ghost */
.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
}

.btn-ghost:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
}

[data-theme="dark"] .btn-ghost:hover {
    background: var(--color-bg-hover);
}

/* Danger */
.btn-danger {
    background: var(--color-error);
    color: #fff;
    border-color: var(--color-error);
}

.btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
}

[data-theme="dark"] .btn-danger:hover {
    box-shadow: 0 0 18px rgba(239, 68, 68, 0.4), 0 0 36px rgba(239, 68, 68, 0.18);
}



[data-theme="dark"] .btn-secondary {
    background: var(--glass-bg);
    border: var(--glass-border);
    color: var(--color-text-primary);
}

[data-theme="dark"] .btn-secondary:hover {
    background: rgba(240, 237, 230, 0.06);
    border-color: var(--color-accent-gold, #E8C872);
    color: var(--color-accent-gold, #E8C872);
    box-shadow: var(--glow-gold);
    transform: none;
}

/* Button sizes */
.btn-sm {
    padding: var(--space-1) var(--space-3);
    height: 32px;
    font-size: var(--text-xs);
    border-radius: var(--radius-btn-sm);
}

.btn-xs {
    padding: 1px var(--space-2) 3px;
    height: 24px;
    font-size: 11px;
    line-height: 1;
    border-radius: var(--radius-sm);
    gap: var(--space-1);
}

.btn-xs i,
.btn-xs svg {
    width: 12px;
    height: 12px;
}

.btn-lg {
    padding: var(--space-3) var(--space-6);
    height: 44px;
    font-size: var(--text-base);
    border-radius: var(--radius-btn-lg);
}

/* ── Icon Buttons 圖示按鈕 ──
 * Usage:  <button class="btn-icon btn-icon-sm">
 *           <i data-lucide="trash-2"></i>
 *         </button>
 * Sizes:
 *   .btn-icon-sm  — 28×28 px, icon 14px  (tag/inline action)
 *   .btn-icon-md  — 34×34 px, icon 16px  (header actions)
 */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-tertiary);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--duration-base) var(--ease-default);
    outline: none;
}

.btn-icon:hover {
    border-color: var(--color-text-primary);
    color: var(--color-text-primary);
    background: var(--color-bg-hover);
}

.btn-icon:focus-visible {
    box-shadow: var(--shadow-ring);
}

.btn-icon-danger:hover {
    border-color: var(--color-error, #EF4444);
    color: var(--color-error, #EF4444);
    background: color-mix(in srgb, var(--color-error, #EF4444) 10%, transparent);
}

.btn-icon i,
.btn-icon svg {
    flex-shrink: 0;
    display: block;
}

/* sm — 28×28 / 14px */
.btn-icon-sm {
    width: 28px;
    height: 28px;
}

.btn-icon-sm i,
.btn-icon-sm svg {
    width: 14px;
    height: 14px;
}

/* md — 34×34 / 16px */
.btn-icon-md {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-input);
}

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

[data-theme="dark"] .btn-icon:hover {
    border-color: var(--color-accent-gold, #E8C872);
    color: var(--color-accent-gold, #E8C872);
    background: rgba(240, 237, 230, 0.06);
    box-shadow: var(--glow-gold);
}




/* ══════════════════════════════════════
   2. Cards 卡片
   ══════════════════════════════════════ */
.card {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0);
    transform: translateY(0);
    transition: box-shadow var(--duration-hover) var(--ease-smooth),
        border-color var(--duration-hover) var(--ease-smooth),
        transform var(--duration-hover) var(--ease-smooth);
}

.card:hover {
    border-color: var(--color-border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.045),
        0 12px 32px rgba(0, 0, 0, 0.035);
    transform: translateY(-2px);
}

[data-theme="dark"] .card {
    background: linear-gradient(145deg, rgba(240, 237, 230, 0.07), rgba(240, 237, 230, 0.03));
    border: var(--glass-border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

[data-theme="dark"] .card:hover {
    border-color: var(--color-border-hover);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

/* Flat card — no hover lift (use for table wrappers, form containers) */
.card-flat:hover {
    box-shadow: none;
    border-color: var(--color-border);
    transform: none;
}

[data-theme="dark"] .card-flat {
    background: color-mix(in srgb, var(--color-bg-surface) 60%, transparent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

[data-theme="dark"] .card-flat:hover {
    box-shadow: none;
    border-color: var(--color-border);
    transform: none;
}

.card-body {
    padding: var(--space-5);
}

.card-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: var(--space-2);
}

/* Stat Card — KPI 統計 */
.stat-card {
    display: flex;
    align-items: flex-start;
    gap: var(--space-4);
    padding: var(--space-5);
}

.stat-icon {
    padding: var(--space-3);
    border-radius: var(--radius-input);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon i,
.stat-icon svg {
    width: 20px;
    height: 20px;
}

.stat-icon.icon-blue {
    background: var(--color-info-light);
    color: var(--color-accent-blue);
}

.stat-icon.icon-purple {
    background: var(--color-purple-light);
    color: var(--color-accent-purple);
}

.stat-icon.icon-green {
    background: var(--color-success-light);
    color: var(--color-accent-green);
}

.stat-icon.icon-orange {
    background: var(--color-warning-light);
    color: var(--color-accent-orange);
}

.stat-icon.icon-cyan {
    background: rgba(6, 182, 212, 0.1);
    color: var(--color-accent-cyan);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-1);
    font-weight: var(--weight-medium);
}

.stat-value {
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    line-height: var(--leading-tight);
    margin-bottom: var(--space-1);
}

.stat-value-lg {
    font-size: var(--text-4xl);
    font-weight: var(--weight-bold);
}

/* Dark mode gradient text */
[data-theme="dark"] .gradient-text {
    background: linear-gradient(90deg, var(--color-accent-gold, #E8C872), var(--color-accent-cyan, #5EE7DF));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Glow accent bar */
.card-glow::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--color-brand);
    box-shadow: var(--glow-gold, 0 0 20px rgba(232, 200, 114, 0.3));
}

/* Wide card (spans full width) */
.card-wide {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ══════════════════════════════════════
   3. Trend/Change Indicator 趨勢指標
   ══════════════════════════════════════ */
.trend {
    font-size: var(--text-xs);
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-weight: var(--weight-medium);
}

.trend i,
.trend svg {
    width: 14px;
    height: 14px;
}

.trend-up {
    color: var(--color-success);
}

.trend-down {
    color: var(--color-error);
}

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


/* ══════════════════════════════════════
   4. Status Badge 狀態標籤
   ══════════════════════════════════════ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px var(--space-3);
    border-radius: var(--radius-badge);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    white-space: nowrap;
    gap: var(--space-1);
}

.badge-success {
    background: var(--color-success-light);
    color: var(--color-success);
    border: 1px solid var(--color-success-border);
}

.badge-warning {
    background: var(--color-warning-light);
    color: var(--color-warning);
    border: 1px solid var(--color-warning-border);
}

.badge-error {
    background: var(--color-error-light);
    color: var(--color-error);
    border: 1px solid var(--color-error-border);
}

.badge-info {
    background: var(--color-info-light);
    color: var(--color-info);
    border: 1px solid var(--color-info-border);
}

.badge-neutral {
    background: var(--color-bg-hover);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.category-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    white-space: nowrap;
    background-color: color-mix(in srgb, var(--cat-color) 15%, transparent);
    color: var(--cat-color);
}

[data-theme="dark"] .category-badge {
    background-color: color-mix(in srgb, var(--cat-color) 20%, transparent);
}



/* ══════════════════════════════════════
   5. Table 表格
   ══════════════════════════════════════ */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    text-align: left;
    padding: var(--space-3) var(--space-6);
    background: var(--color-bg-hover);
    color: var(--color-text-secondary);
    font-size: 14px;
    text-transform: none;
    font-weight: var(--weight-semibold);
    border-bottom: 1px solid var(--color-border);
    letter-spacing: var(--tracking-wide);
    white-space: nowrap;
}

.table td {
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    font-size: 14px;
    color: var(--color-text-primary);
}

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

.table tbody tr {
    transition: background var(--duration-fast);
}

.table tbody tr:hover {
    background: var(--color-bg-surface);
}

[data-theme="dark"] .table th {
    background: rgba(240, 237, 230, 0.10);
}

[data-theme="dark"] .table tbody tr {
    background: rgba(240, 237, 230, 0.03);
}

[data-theme="dark"] .table tbody tr:hover {
    background: rgba(240, 237, 230, 0.08);
}

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

/* Table action buttons — borderless, simple hover (mirrors modal close) */
.table .btn-icon {
    border: none;
    width: 28px;
    height: 28px;
}

.table .btn-icon:hover,
[data-theme="dark"] .table .btn-icon:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
    border-color: transparent;
    box-shadow: none;
}

/* ── Pagination (global) ── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) 0;
}

.pagination-info {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
}

.pagination-controls {
    display: flex;
    gap: var(--space-1);
}

/* Pagination page-number buttons: ensure visible text in light mode */
.pagination-controls .btn-ghost {
    color: var(--color-text-primary);
}

.pagination-controls .btn-ghost:hover {
    color: var(--color-text-primary);
}

/* Active page button: use text-primary as bg so white number is always visible */
.pagination-controls .btn-primary {
    background: var(--color-text-primary);
    border-color: var(--color-text-primary);
    color: #fff;
}

[data-theme="dark"] .pagination-controls .btn-primary {
    background: var(--color-text-primary);
    border-color: var(--color-text-primary);
    color: var(--color-bg-base);
}

/* Cell helpers */
.cell-primary {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cell-primary .cell-main {
    font-weight: var(--weight-medium);
}

.cell-primary .cell-sub {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
}


/* ══════════════════════════════════════
   6. Form Elements 表單元素
   ══════════════════════════════════════ */

/* Input */
.input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    height: 40px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-input);
    font-family: var(--font-primary);
    font-size: 14px;
    color: var(--color-text-primary);
    background: var(--color-bg-base);
    transition: all var(--duration-base) var(--ease-default);
    outline: none;
}

.input:hover {
    border-color: var(--color-border-hover);
}

.input:focus {
    border-color: var(--color-border-focus);
    box-shadow: var(--shadow-ring);
}

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

[data-theme="dark"] .input {
    background: rgba(0, 0, 0, 0.2);
    border: var(--glass-border);
    color: var(--color-text-primary);
}

/* Select dropdown hover — dark border (light), gold border (dark) */
select.input:hover {
    border-color: var(--color-text-primary);
}

[data-theme="dark"] select.input:hover {
    border-color: var(--color-accent-gold, #E8C872);
}

/* Search Bar */
.search-bar {
    position: relative;
    display: flex;
    align-items: center;
}

.search-bar .search-icon {
    position: absolute;
    left: var(--space-3);
    color: var(--color-text-tertiary);
    width: 16px;
    height: 16px;
    pointer-events: none;
}

.search-bar .input {
    padding-left: var(--space-10);
}

/* Form Group / Label / Validation */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.form-label {
    font-size: 14px;
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
}

.form-label span {
    color: var(--color-error, #ef4444);
    margin-left: 2px;
}

.form-error {
    font-size: var(--text-xs);
    color: var(--color-error, #ef4444);
    display: none;
}

.form-group.has-error .input {
    border-color: var(--color-error, #ef4444);
}

.form-group.has-error .form-error {
    display: block;
}

.form-hint {
    font-size: 13px;
    color: var(--color-text-tertiary);
    margin-top: var(--space-1);
}

/* Select inside forms — custom arrow */
select.input {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 44px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' 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 16px center;
    background-size: 14px;
    cursor: pointer;
}

[data-theme="dark"] select.input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' 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 16px center;
    background-size: 14px;
}

/* Form Row — horizontal layout for multiple fields */
.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

/* Textarea */
textarea.input {
    height: auto;
    min-height: 80px;
    resize: vertical;
    line-height: var(--leading-relaxed);
}

/* Spacing utility */
.mb-4 {
    margin-bottom: var(--space-4);
}

/* Toggle Switch */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--color-bg-active);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--duration-base);
}

.toggle.active {
    background: var(--color-accent-blue);
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-sm);
    transition: transform var(--duration-base) var(--ease-spring);
}

.toggle.active::after {
    transform: translateX(20px);
}

/* Checkbox */
.checkbox {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-xs);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
    flex-shrink: 0;
}

.checkbox.checked {
    background: var(--color-brand);
    border-color: var(--color-brand);
    color: white;
}

[data-theme="dark"] .checkbox.checked {
    color: #0A0E17;
}

/* Native checkbox — matches .checkbox design system style */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    min-width: 18px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--duration-fast);
    flex-shrink: 0;
    vertical-align: middle;
    position: relative;
    background: transparent;
}

input[type="checkbox"]:hover {
    border-color: var(--color-brand);
}

input[type="checkbox"]:checked {
    background: var(--color-brand);
    border-color: var(--color-brand);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 11px;
}

input[type="checkbox"]:focus {
    outline: none;
    box-shadow: var(--shadow-ring);
}

[data-theme="dark"] input[type="checkbox"] {
    border-color: var(--glass-border-color, rgba(255, 255, 255, 0.15));
    background: transparent;
}

[data-theme="dark"] input[type="checkbox"]:checked {
    background-color: var(--color-brand);
    border-color: var(--color-brand);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%230A0E17' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 11px;
}

/* ══════════════════════════════════════
   7. Filter Tabs 篩選標籤
   ══════════════════════════════════════ */
.filter-tabs {
    display: flex;
    gap: var(--space-1);
    background: var(--color-bg-surface);
    padding: var(--space-1);
    border-radius: var(--radius-tab-container);
    border: 1px solid var(--color-border);
}

.tab {
    padding: var(--space-2) var(--space-3);
    border: none;
    background: transparent;
    font-family: var(--font-primary);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
    border-radius: var(--radius-tab);
    cursor: pointer;
    transition: all var(--duration-fast);
}

.tab:hover {
    color: var(--color-text-primary);
}

.tab.active {
    background: var(--color-bg-base);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-xs);
}

[data-theme="dark"] .filter-tabs {
    background: rgba(240, 237, 230, 0.03);
    border: var(--glass-border);
}

[data-theme="dark"] .tab.active {
    background: rgba(240, 237, 230, 0.1);
    color: var(--color-text-primary);
}


/* ══════════════════════════════════════
   8. Avatar 頭像
   ══════════════════════════════════════ */
.avatar {
    border-radius: var(--radius-full);
    object-fit: cover;
    flex-shrink: 0;
}

.avatar-xs {
    width: 24px;
    height: 24px;
}

.avatar-sm {
    width: 32px;
    height: 32px;
}

.avatar-md {
    width: 40px;
    height: 40px;
}

.avatar-lg {
    width: 48px;
    height: 48px;
}

.avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--color-bg-hover);
    color: var(--color-text-secondary);
    font-weight: var(--weight-semibold);
    font-size: var(--text-sm);
}


/* ══════════════════════════════════════
   9. Progress Bar 進度條
   ══════════════════════════════════════ */
.progress {
    height: 6px;
    background: var(--color-bg-active);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--color-accent-blue);
    transition: width var(--duration-slow) var(--ease-default);
}

[data-theme="dark"] .progress {
    background: rgba(240, 237, 230, 0.1);
}

[data-theme="dark"] .progress-fill {
    box-shadow: var(--glow-gold);
}


/* ══════════════════════════════════════
   10. Toolbar 操作工具列
   ══════════════════════════════════════ */
.toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-6);
}

.toolbar-spacer {
    flex: 1;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}


/* ══════════════════════════════════════
   11. Modal / Dialog 對話框
   ══════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-bg-overlay);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
    animation: fade-in var(--duration-base);
}

.modal {
    background: var(--color-bg-elevated);
    border-radius: var(--radius-modal);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slide-up var(--duration-slow) var(--ease-spring);
}

[data-theme="dark"] .modal {
    border: var(--glass-border);
    background: var(--color-bg-surface);
}

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

/* Modal / panel close button — no border, simple bg hover */
.modal-header .btn-icon,
.conv-detail-header .btn-icon {
    border: none;
    width: 28px;
    height: 28px;
}

.modal-header .btn-icon i,
.modal-header .btn-icon svg,
.conv-detail-header .btn-icon i,
.conv-detail-header .btn-icon svg {
    width: 16px;
    height: 16px;
}

.modal-header .btn-icon:hover,
.conv-detail-header .btn-icon:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
    border-color: transparent;
    box-shadow: none;
}

[data-theme="dark"] .modal-header .btn-icon:hover,
[data-theme="dark"] .conv-detail-header .btn-icon:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
    border-color: transparent;
    box-shadow: none;
}

.modal-body {
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
}

@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}


/* ══════════════════════════════════════
   12. Empty State 空狀態
   ══════════════════════════════════════ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-16) var(--space-8);
    text-align: center;
    color: var(--color-text-tertiary);
}

.empty-state i,
.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-4);
    opacity: 0.5;
}

.empty-state h3 {
    font-size: var(--text-md);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-2);
}


/* ══════════════════════════════════════
   14. AI Briefing Card 智慧簡報卡
   ══════════════════════════════════════ */
.briefing {
    display: flex;
    gap: var(--space-4);
    align-items: flex-start;
}

.briefing-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #E8C872, #5EE7DF);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
}

.briefing-avatar i,
.briefing-avatar svg {
    width: 20px;
    height: 20px;
}

[data-theme="dark"] .briefing-avatar {
    background: linear-gradient(135deg, var(--color-accent-gold, #E8C872), var(--color-accent-cyan, #5EE7DF));
    box-shadow: 0 0 20px rgba(232, 200, 114, 0.3);
}

.briefing-body {
    flex: 1;
    min-width: 0;
}

.briefing-greeting {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    letter-spacing: var(--tracking-tight);
    margin-bottom: var(--space-3);
    line-height: var(--leading-tight);
}

.briefing-message {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    line-height: var(--leading-relaxed);
    margin-bottom: var(--space-4);
}

.briefing-message strong {
    color: var(--color-text-primary);
    font-weight: var(--weight-semibold);
}

.briefing-time {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
}

.briefing-time i,
.briefing-time svg {
    width: 12px;
    height: 12px;
}

.briefing-pulse {
    width: 6px;
    height: 6px;
    background: var(--color-accent-green);
    border-radius: var(--radius-full);
    animation: pulse-live 2s infinite;
}

@keyframes pulse-live {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(1.3);
    }
}


/* ══════════════════════════════════════
   15. Attention Alert 注意事項提醒
   ══════════════════════════════════════ */
.attention-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-input);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    cursor: pointer;
    transition: all var(--duration-base) var(--ease-default);
    text-decoration: none;
}

.attention-item:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-border-hover);
    transform: translateX(2px);
    text-decoration: none;
}

[data-theme="dark"] .attention-item {
    background: color-mix(in srgb, var(--color-bg-surface) 60%, transparent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
}

[data-theme="dark"] .attention-item:hover {
    background: color-mix(in srgb, var(--color-bg-elevated) 70%, transparent);
}

.attention-indicator {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.attention-indicator.urgent {
    background: var(--color-error);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

.attention-indicator.warning {
    background: var(--color-warning);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
}

.attention-indicator.info {
    background: var(--color-info);
}

.attention-indicator.success {
    background: var(--color-success);
}

.attention-text {
    flex: 1;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    min-width: 0;
    text-decoration: none;
}

.attention-action {
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    white-space: nowrap;
    flex-shrink: 0;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    transition: all var(--duration-base) var(--ease-default);
}

/* Action button color variants based on sibling indicator */
.attention-indicator.urgent~.attention-action {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-error);
}

.attention-indicator.warning~.attention-action {
    background: rgba(245, 158, 11, 0.1);
    color: var(--color-warning);
}

.attention-indicator.info~.attention-action {
    background: rgba(59, 130, 246, 0.1);
    color: var(--color-info);
}

.attention-indicator.success~.attention-action {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-success);
}

.attention-item:hover .attention-action {
    filter: brightness(1.1);
    transform: scale(1.03);
}

[data-theme="dark"] .attention-indicator.urgent~.attention-action {
    background: rgba(239, 68, 68, 0.15);
}

[data-theme="dark"] .attention-indicator.warning~.attention-action {
    background: rgba(245, 158, 11, 0.15);
}

[data-theme="dark"] .attention-indicator.info~.attention-action {
    background: rgba(59, 130, 246, 0.15);
}

[data-theme="dark"] .attention-indicator.success~.attention-action {
    background: rgba(16, 185, 129, 0.15);
}


/* ══════════════════════════════════════
   16. Todo Checklist 待辦清單
   ══════════════════════════════════════ */
.todo-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: opacity var(--duration-base);
}

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

.todo-check {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-xs);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
    cursor: pointer;
}

.todo-check:hover {
    border-color: var(--color-brand);
}

.todo-item.completed .todo-check {
    background: var(--color-brand);
    border-color: var(--color-brand);
    color: var(--color-text-inverse);
}

.todo-item.completed .todo-check i,
.todo-item.completed .todo-check svg {
    width: 12px;
    height: 12px;
}

.todo-item.completed .todo-label {
    text-decoration: line-through;
    opacity: 0.5;
}

.todo-label {
    flex: 1;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
}

.todo-tag {
    font-size: var(--text-xs);
    padding: 2px var(--space-2);
    border-radius: var(--radius-badge);
    font-weight: var(--weight-medium);
}


/* ══════════════════════════════════════
   17. KPI Compact 緊湊型數據指標
   ══════════════════════════════════════ */
.kpi-item {
    display: flex;
    flex-direction: column;
    padding: var(--space-4);
    border-radius: var(--radius-input);
    transition: background var(--duration-fast);
}

.kpi-item:hover {
    background: var(--color-bg-hover);
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-2);
}

.kpi-label {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    font-weight: var(--weight-medium);
}

.kpi-value {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-1);
    line-height: 1;
}

.kpi-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.kpi-sparkline {
    flex-shrink: 0;
}

.kpi-sparkline svg {
    display: block;
}


/* ══════════════════════════════════════
   18. Health Meter 系統健康度
   ══════════════════════════════════════ */
.health-item {
    display: flex;
    align-items: flex-end;
    gap: var(--space-3);
    padding: var(--space-3) 0;
}

.health-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.health-icon i,
.health-icon svg {
    width: 14px;
    height: 14px;
}

.health-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.health-label {
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    font-weight: var(--weight-medium);
}

.health-bar {
    height: 4px;
    background: var(--color-bg-active);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.health-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    width: 0;
    transition: width 1s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
}

.health-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(255, 255, 255, 0.3) 50%,
            transparent 100%);
    animation: healthShimmer 2.5s ease-in-out infinite;
    animation-delay: 1.5s;
}

@keyframes healthShimmer {
    0% {
        left: -100%;
    }

    100% {
        left: 200%;
    }
}

.health-value {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    flex-shrink: 0;
    min-width: 36px;
    text-align: right;
}


/* ══════════════════════════════════════
   19. Activity Timeline 活動時間線
   ══════════════════════════════════════ */
.timeline {
    display: flex;
    flex-direction: column;
}

.timeline-item {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-4) 0;
    position: relative;
}

.timeline-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 15px;
    top: calc(var(--space-4) + 32px);
    bottom: 0;
    width: 1px;
    background: var(--color-border);
}

.timeline-dot {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    z-index: 1;
}

.timeline-dot i,
.timeline-dot svg {
    width: 14px;
    height: 14px;
}

.timeline-content {
    flex: 1;
    min-width: 0;
    padding-top: var(--space-1);
}

.timeline-text {
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    margin-bottom: var(--space-1);
    line-height: var(--leading-normal);
}

.timeline-text strong {
    font-weight: var(--weight-semibold);
}

.timeline-time {
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
}


/* ══════════════════════════════════════
   13. Utility Helpers 工具類
   ══════════════════════════════════════ */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

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

.justify-between {
    justify-content: space-between;
}

.gap-1 {
    gap: var(--space-1);
}

.gap-2 {
    gap: var(--space-2);
}

.gap-3 {
    gap: var(--space-3);
}

.gap-4 {
    gap: var(--space-4);
}

.gap-6 {
    gap: var(--space-6);
}

.mt-auto {
    margin-top: auto;
}

.mb-0 {
    margin-bottom: 0;
}

.mb-4 {
    margin-bottom: var(--space-4);
}

.mb-6 {
    margin-bottom: var(--space-6);
}

.mb-8 {
    margin-bottom: var(--space-8);
}

.text-sm {
    font-size: var(--text-sm);
}

.text-xs {
    font-size: var(--text-xs);
}

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

.font-medium {
    font-weight: var(--weight-medium);
}

.font-bold {
    font-weight: var(--weight-bold);
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ── Confirm Dialog ── */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: confirmFadeIn 0.2s ease;
}

@keyframes confirmFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes confirmSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.confirm-modal {
    background: var(--color-bg-base);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 400px;
    animation: confirmSlideIn 0.25s ease;
    overflow: hidden;
}

.confirm-body {
    padding: var(--space-8) var(--space-8) var(--space-6);
    display: flex;
    gap: var(--space-4);
    align-items: flex-start;
}

.confirm-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--color-danger-light, rgba(239, 68, 68, 0.1));
    color: var(--color-danger, #ef4444);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.confirm-icon.info {
    background: var(--color-info-light, rgba(14, 165, 233, 0.1));
    color: var(--color-info, #0ea5e9);
}

.confirm-icon i,
.confirm-icon svg {
    width: 20px;
    height: 20px;
    color: inherit;
    stroke: currentColor;
}

.confirm-text h4 {
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    margin: 0 0 var(--space-1);
}

.confirm-text p {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    margin: 0;
    line-height: var(--leading-relaxed);
}

.confirm-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-8);
    background: var(--color-bg-surface);
    border-top: 1px solid var(--color-border);
}

[data-theme="dark"] .confirm-modal {
    border: 1px solid var(--color-border);
}


/* ══════════════════════════════════════
   GLOBAL SCROLLBAR STYLES 左捲軸樣式
   ══════════════════════════════════════ */

/* Webkit (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
    transition: background var(--duration-fast);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-tertiary);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

[data-theme="dark"] * {
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

/* ══════════════════════════════════════
   13. RESPONSIVE OPTIMIZATIONS (Strict Mobile-only UX)
   ══════════════════════════════════════ */
@media (max-width: 639px) {
    /* 1. Global Typography Scaling */
    h1, .h1 { font-size: calc(var(--text-2xl) * 0.85); }
    h2, .h2 { font-size: calc(var(--text-xl) * 0.85); }
    h3, .h3 { font-size: calc(var(--text-lg) * 0.85); }

    /* 2. Table Horizontal Scroll Safety (Sticky First Column) */
    .table th:first-child,
    .table td:first-child {
        position: sticky;
        left: 0;
        z-index: 10;
        background: inherit;
    }
    
    .table th:first-child {
        background: var(--color-bg-hover);
    }
    
    .table td:first-child {
        background: var(--color-bg-surface);
    }
    
    [data-theme="dark"] .table td:first-child {
        background: var(--glass-bg);
    }

    /* 3. Modal Stretch */
    .modal {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }
    .modal-footer {
        flex-wrap: wrap;
    }
    .modal-footer .btn {
        flex: 1;
        min-width: 0;
    }
    .confirm-modal {
        max-width: calc(100% - var(--space-6));
    }
    
    /* 4. Filter tabs horizontal scroll */
    .filter-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
    }
    .filter-tabs::-webkit-scrollbar {
        display: none;
    }
    .filter-tabs .tab {
        flex-shrink: 0;
    }
}