/* ==========================================
   AI 台股自動模擬交易平台 - Premium Dark Theme
   ========================================== */
:root {
    /* 色彩系統 */
    --bg-primary: #0b1017;
    --bg-secondary: #111827;
    --bg-card: #171f2b;
    --bg-card-hover: #1c2533;
    --bg-input: #0f1722;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-active: rgba(59, 130, 246, 0.38);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-primary: #3b82f6;
    --accent-primary-glow: rgba(59, 130, 246, 0.18);
    --accent-success: #ef4444;
    --accent-success-soft: rgba(239, 68, 68, 0.12);
    --accent-danger: #22c55e;
    --accent-danger-soft: rgba(34, 197, 94, 0.12);
    --accent-warning: #f59e0b;
    --accent-info: #3b82f6;
    --accent-buy: #ef4444;
    --accent-sell: #22c55e;
    --gradient-primary: linear-gradient(135deg, #2563eb, #3b82f6);
    --gradient-success: linear-gradient(135deg, #ef4444, #f97316);
    --gradient-danger: linear-gradient(135deg, #22c55e, #06d6a0);
    --surface-1: rgba(255, 255, 255, 0.02);
    --surface-2: rgba(255, 255, 255, 0.04);
    --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.22);
    --card-outline: rgba(148, 163, 184, 0.16);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 22px rgba(0, 0, 0, 0.35);
    --shadow-glow: 0 0 0 rgba(0, 0, 0, 0);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 淺色模式主題變數 */
[data-theme="light"] {
    --bg-primary: #f6f8fb;
    --bg-secondary: #eef2f7;
    --bg-card: #ffffff;
    --bg-card-hover: #f4f7fb;
    --bg-input: #ffffff;
    --border-color: #e5eaf2;
    --border-active: #bfdbfe;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 0 rgba(0, 0, 0, 0);
    --surface-1: rgba(15, 23, 42, 0.02);
    --surface-2: rgba(15, 23, 42, 0.05);
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.18);
    --card-outline: rgba(148, 163, 184, 0.28);
}

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

body {
    font-family: var(--font-sans);
    background:
        radial-gradient(circle at 12% -10%, rgba(59, 130, 246, 0.18), transparent 44%),
        radial-gradient(circle at 88% -12%, rgba(16, 185, 129, 0.12), transparent 40%),
        var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

/* ==========================================
   Header
   ========================================== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.header-left,
.header-center,
.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.theme-toggle:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.1));
    color: var(--text-primary);
}

[data-theme="light"] .theme-toggle:hover {
    background: #e2e8f0;
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
}

.btn-primary {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 24px;
    filter: none;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.logo-badge {
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    background: transparent;
    color: var(--accent-primary);
    border: 1px solid var(--border-active);
    border-radius: 4px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.market-ticker {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.ticker-label {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
}

.ticker-value {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.ticker-change {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 4px;
}

.ticker-change.up {
    color: var(--accent-success);
    background: var(--accent-success-soft);
}

.ticker-change.down {
    color: var(--accent-danger);
    background: var(--accent-danger-soft);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    /* 預設顏色 (來自 CasualTrader bg-gray-500) */
    background: #6b7280;
}

/* CasualTrader 的狀態樣式 */
.status-running {
    background: #10b981;
    /* Tailwind emerald-500 */
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.status-stopped {
    background: #ef4444;
    /* Tailwind red-500 */
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.bg-gray-500 {
    background: #6b7280;
    box-shadow: none;
}

.blinking {
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* ==========================================
   Main
   ========================================== */
.main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 20px 24px;
}

/* ==========================================
   Metrics Cards
   ========================================== */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--gradient-primary);
    opacity: 0;
    transition: var(--transition);
}

.metric-card:hover {
    border-color: var(--border-active);
    transform: none;
    box-shadow: var(--shadow-sm);
}

.metric-card:hover::before {
    opacity: 1;
}

.metric-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.metric-value {
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.metric-sub {
    font-size: 13px;
    font-weight: 500;
    margin-top: 4px;
    font-family: var(--font-mono);
}

.metric-sub.positive {
    color: var(--accent-success);
}

.metric-sub.negative {
    color: var(--accent-danger);
}

/* ==========================================
   Control Panel
   ========================================== */
.control-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
}

.control-left,
.control-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    outline: none;
}

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

.btn-icon {
    font-size: 16px;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    border: 1px solid rgba(59, 130, 246, 0.45);
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.22);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    filter: brightness(1.04);
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
}

.btn-glow {
    animation: none;
}

@keyframes glow-pulse {

    0%,
    100% {
        box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
    }

    50% {
        box-shadow: 0 2px 20px rgba(99, 102, 241, 0.5);
    }
}

.btn-secondary {
    background: var(--surface-1);
    color: var(--text-primary);
    border: 1px solid var(--card-outline);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--border-active);
    background: var(--surface-2);
}

.btn-outline {
    background: transparent;
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--accent-primary-glow);
}

.btn-outline.active {
    background: var(--accent-primary);
    color: white;
}

.btn-danger {
    background: var(--accent-danger-soft);
    color: var(--accent-danger);
    border: 1px solid rgba(34, 197, 94, 0.35);
}

.btn-danger:hover:not(:disabled) {
    background: rgba(34, 197, 94, 0.2);
}

.btn:focus-visible,
.btn-share:focus-visible,
.market-switch:focus-visible,
.screener-tab:focus-visible,
.filter-chip:focus-visible,
.simple-filter-chip:focus-visible,
.btn-group-more:focus-visible {
    box-shadow: var(--focus-ring);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
}

/* ==========================================
   Content Grid
   ========================================== */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

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

.card-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 16px 20px;
}

.card-body-compact {
    padding: 0;
}

.card-chart .card-body {
    padding: 16px 20px 8px;
    height: 360px;
}

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-family: var(--font-mono);
}
.btn-share {
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    background: var(--surface-1);
    color: var(--text-secondary);
    border: 1px solid var(--card-outline);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-share:hover {
    background: var(--surface-2);
    color: var(--text-primary);
    border-color: var(--border-active);
}
.market-switch {
    font-size: 13px;
    font-weight: 600;
    padding: 6px 18px;
    background: var(--surface-1);
    color: var(--text-secondary);
    border: 1px solid var(--card-outline);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.market-switch.active {
    background: var(--gradient-primary);
    color: #fff;
    border-color: var(--accent-primary);
    box-shadow: 0 8px 22px rgba(37, 99, 235, 0.24);
}
.market-switch:hover:not(.active) {
    background: var(--surface-2);
    color: var(--text-primary);
}

.badge-ai {
    background: var(--accent-primary-glow);
    color: var(--accent-primary);
}

/* ==========================================
   Tables
   ========================================== */
.table-wrapper {
    overflow-x: auto;
    border-top: 1px solid var(--border-color);
}

.table-scroll {
    max-height: 300px;
    overflow-y: auto;
}

.table-scroll::-webkit-scrollbar {
    width: 4px;
}

.table-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.table-scroll::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead th {
    text-align: left;
    padding: 11px 12px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.data-table tbody td {
    padding: 11px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    font-family: var(--font-mono);
    font-size: 12.5px;
}

.data-table tbody tr {
    transition: var(--transition);
}

.data-table tbody tr:hover {
    background: var(--bg-card-hover);
}

.empty-state {
    text-align: center !important;
    color: var(--text-muted) !important;
    padding: 30px 12px !important;
    font-family: var(--font-sans) !important;
    font-style: italic;
}

.tag-buy {
    color: var(--accent-buy);
    background: var(--accent-success-soft);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 11px;
}

.tag-sell {
    color: var(--accent-sell);
    background: var(--accent-danger-soft);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 11px;
}

.positive {
    color: var(--accent-success) !important;
}

.negative {
    color: var(--accent-danger) !important;
}

/* ==========================================
   AI Log
   ========================================== */
.card-ai {
    position: sticky;
    top: 80px;
}

.ai-log {
    max-height: calc(100vh - 320px);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-log::-webkit-scrollbar {
    width: 4px;
}

.ai-log::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.ai-empty {
    text-align: center;
    padding: 40px 20px;
}

.ai-empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.6;
}

.ai-empty-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.ai-empty-sub {
    font-size: 12px;
    color: var(--text-muted);
}

.ai-entry {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px;
    animation: slideIn 0.3s ease;
}

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

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

.ai-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.ai-entry-time {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.ai-entry-model {
    font-size: 10px;
    color: var(--accent-primary);
    background: var(--accent-primary-glow);
    padding: 1px 6px;
    border-radius: 4px;
}

.ai-entry-summary {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 8px;
}

.ai-entry-decisions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-decision-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
}

.ai-decision-item .action {
    font-weight: 700;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 3px;
}

.ai-decision-item .action.buy {
    color: var(--accent-buy);
    background: var(--accent-success-soft);
}

.ai-decision-item .action.sell {
    color: var(--accent-sell);
    background: var(--accent-danger-soft);
}

.ai-decision-item .detail {
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.ai-decision-item .reason {
    color: var(--text-muted);
    font-size: 11px;
    flex: 1;
    text-align: right;
}

/* 可展開的 AI 日誌 */
.ai-entry-expandable {
    cursor: pointer;
    transition: border-color 0.2s;
}

.ai-entry-expandable:hover {
    border-color: var(--border-active);
}

.ai-expand-icon {
    font-size: 10px;
    color: var(--accent-primary);
    background: var(--accent-primary-glow);
    padding: 2px 7px;
    border-radius: 4px;
    display: inline-block;
    transition: opacity 0.15s;
}

.ai-entry-expandable:hover .ai-expand-icon {
    opacity: 0.75;
}


/* 各分析師報告區塊 */
.ai-report-section {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border-left: 3px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
}

.ai-report-section:last-child {
    margin-bottom: 0;
}

.ai-report-technical {
    border-left-color: #6366f1;
}

.ai-report-sentiment {
    border-left-color: #a855f7;
}

.ai-report-risk {
    border-left-color: #f59e0b;
}

.ai-report-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.ai-report-content {
    font-size: 12px;
    color: var(--text-primary);
    line-height: 1.6;
    word-break: break-word;
}

/* ==========================================
   AI 決策詳情 Modal
   ========================================== */
.ai-detail-modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 780px;
    max-width: 95vw;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.25s ease;
    overflow: hidden;
}

.ai-detail-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.ai-detail-modal-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-detail-modal-phase {
    font-size: 11px;
    background: var(--accent-primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: 8px;
    font-weight: 600;
}

.ai-detail-modal-time {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.ai-detail-modal-body {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
    min-height: 0;
}

.ai-detail-modal-body::-webkit-scrollbar { width: 4px; }
.ai-detail-modal-body::-webkit-scrollbar-track { background: transparent; }
.ai-detail-modal-body::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

.ai-modal-summary-box {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.ai-modal-decisions-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-modal-section-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.ai-modal-no-trade {
    font-size: 12px;
    color: var(--text-muted);
    padding: 8px 0;
}

@media (max-width: 600px) {
    .ai-detail-modal-content {
        max-height: 95vh;
    }
    .ai-detail-modal-body {
        padding: 14px 14px;
    }
}

/* ==========================================
   Loading Overlay
   ========================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 14, 23, 0.85);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay.active {
    display: flex;
}

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

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.loading-sub {
    font-size: 13px;
    color: var(--text-muted);
}

/* ==========================================
   Toast Notifications
   ========================================== */
.toast-container {
    position: fixed;
    top: 72px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9998;
}

.toast {
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 3.7s forwards;
    max-width: 360px;
    border: 1px solid var(--border-color);
}

.toast-success {
    background: var(--bg-card);
    color: var(--accent-success);
    border-left: 3px solid var(--accent-success);
}

.toast-error {
    background: var(--bg-card);
    color: var(--accent-danger);
    border-left: 3px solid var(--accent-danger);
}

.toast-info {
    background: var(--bg-card);
    color: var(--accent-info);
    border-left: 3px solid var(--accent-info);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(60px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
        transform: translateX(60px);
    }
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 1200px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .card-ai {
        position: static;
    }

    .ai-log {
        max-height: 400px;
    }
}

@media (max-width: 768px) {
    .metrics-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .header {
        padding: 8px 12px;
        height: auto;
        min-height: 48px;
        gap: 8px;
        flex-wrap: wrap;
    }

    .header-center {
        display: none;
    }

    .header-left {
        flex: 1;
        min-width: 0;
    }

    .header-right {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 6px;
    }

    .logo-text {
        font-size: 15px;
    }

    .logo-badge {
        font-size: 8px;
        padding: 1px 4px;
    }

    .status-text {
        font-size: 11px;
    }

    .header-left,
    .header-right {
        gap: 8px;
    }

    .main {
        padding: 12px;
    }

    .control-panel {
        flex-direction: column;
        gap: 10px;
    }

    .control-left,
    .control-right {
        width: 100%;
        flex-wrap: wrap;
    }

    .btn {
        flex: 1;
        justify-content: center;
        min-width: 120px;
    }
}

@media (max-width: 480px) {
    .metrics-row {
        grid-template-columns: 1fr;
    }

    .metric-value {
        font-size: 22px;
    }

    .header {
        padding: 6px 10px;
    }

    .header-left {
        min-width: 0;
    }

    .logo-text {
        display: none;
    }

    .logo-badge {
        display: none;
    }

    .header-nav {
        margin-left: 4px;
    }

    .nav-link {
        font-size: 11px;
        padding: 4px 6px;
    }

    /* 交易平台：隱藏 API Key 狀態文字，只留圓點 */
    #apiKeyStatus .status-text {
        display: none;
    }

    .status-text {
        font-size: 10px;
        max-width: 60px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* 按鈕縮小 */
    .btn {
        min-width: 0;
        padding: 8px 10px;
        font-size: 12px;
    }

    .btn-icon {
        font-size: 14px;
    }

    /* 設定按鈕只顯示圖示 */
    #btnSettings .btn-icon {
        margin: 0;
    }
    #btnSettings {
        padding: 6px 8px;
        font-size: 0;
    }
    #btnSettings .btn-icon {
        font-size: 16px;
    }

    /* 控制面板按鈕自適應 */
    .control-left .btn,
    .control-right .btn {
        font-size: 11px;
        padding: 8px 8px;
    }
}

/* ==========================================
   Settings Modal
   ========================================== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    overscroll-behavior: contain;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 500px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.25s ease;
}

.modal-content::-webkit-scrollbar { width: 4px; }
.modal-content::-webkit-scrollbar-track { background: transparent; }
.modal-content::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }
.modal-content::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

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

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border-color);
}

.settings-group {
    margin-bottom: 16px;
}

.settings-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.settings-hint {
    font-weight: 400;
    color: var(--accent-primary);
    font-size: 12px;
    margin-left: 8px;
}

.settings-hint a {
    color: var(--accent-primary);
    text-decoration: none;
}

.settings-hint a:hover {
    text-decoration: underline;
}

.settings-input {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--font-mono);
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    outline: none;
    transition: var(--transition);
}

.settings-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-glow);
}

.settings-input option {
    background: var(--bg-card);
    color: var(--text-primary);
}

.settings-note {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    line-height: 1.5;
}

.settings-row {
    display: flex;
    gap: 16px;
}

.settings-provider-toggle {
    display: flex; gap: 8px;
}
.provider-option {
    flex: 1; display: flex; align-items: center; justify-content: center;
    gap: 6px; padding: 10px 14px;
    background: var(--bg-input); border: 1px solid var(--border-color);
    border-radius: var(--radius-md); cursor: pointer;
    font-size: 13px; font-weight: 600; color: var(--text-secondary);
    transition: var(--transition);
}
.provider-option:has(input:checked) {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-primary-soft, rgba(99,102,241,0.08));
}
.provider-option input { display: none; }

.settings-textarea {
    resize: vertical;
    min-height: 80px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
}

/* Watchlist Editor */
.watchlist-editor {
    margin-top: 4px;
}

.watchlist-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.watchlist-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.watchlist-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

.watchlist-tag .tag-remove {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    margin-left: 2px;
}

.watchlist-tag .tag-remove:hover {
    color: #ef4444;
}

/* Indicator Signals */
.signal-bullish {
    color: #ef4444;
}

.signal-bearish {
    color: #22c55e;
}

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

.indicator-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
}

.indicator-badge.bullish {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.indicator-badge.bearish {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.indicator-badge.neutral {
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-muted);
}

.indicator-mini {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    font-family: var(--font-mono);
    line-height: 1.4;
}

/* Watchlist Indicator Panel */
.watchlist-list {
    max-height: 60vh;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

.watchlist-list::-webkit-scrollbar {
    width: 4px;
}

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

.watchlist-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.watchlist-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.watchlist-item {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

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

.watchlist-item:hover {
    background: var(--bg-tertiary);
}

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

.watchlist-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.watchlist-price {
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-mono);
}

/* K-line Chart Expandable Box */
.kline-chart-box {
    max-height: 0; overflow: hidden; opacity: 0;
    transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.25s ease;
    padding: 0 10px; background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}
.kline-chart-box.active {
    max-height: 260px; opacity: 1; padding: 8px 10px;
}
.kline-chart-box canvas { width: 100% !important; }

/* K線圖 Modal */
.kline-modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 960px;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.25s ease;
    overflow: hidden;
    transition: width 0.3s ease, height 0.3s ease, max-width 0.3s ease, max-height 0.3s ease, border-radius 0.3s ease;
    height: 80vh;
}
.kline-modal-content.fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0;
    border: none;
}
.kline-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.kline-modal-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.kline-modal-name { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.kline-modal-price { font-size: 18px; font-weight: 700; font-family: var(--font-mono); color: var(--text-primary); }
.kline-modal-change { font-size: 13px; font-weight: 600; font-family: var(--font-mono); }
.kline-modal-change.positive { color: var(--accent-success); }
.kline-modal-change.negative { color: var(--accent-danger); }
.kline-modal-date {
    flex-basis: 100%;
    margin-top: 2px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}
.kline-modal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-fullscreen-kline {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}
.btn-fullscreen-kline:hover {
    border-color: var(--border-active);
    color: var(--text-primary);
}
.kline-modal-body { display: flex; flex-direction: column; flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: var(--border-color) transparent; }
.kline-modal-body::-webkit-scrollbar { width: 4px; }
.kline-modal-body::-webkit-scrollbar-track { background: transparent; }
.kline-modal-body::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }
.kline-modal-body::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.kline-chart-area { flex-shrink: 0; position: relative; padding: 10px 12px; min-width: 0; height: 55vh; }
#klineModalCanvas { display: block; }
.kline-modal-loading {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; color: var(--text-muted); font-size: 13px;
}
.kline-loading-spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 指標面板 — 圖表下方水平排列 */
.kline-modal-indicators {
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
    padding: 10px 16px 12px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0 14px;
    font-size: 11px;
}
.kline-ind-group {
    min-width: 0;
}
.kline-ind-section-title {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--accent-primary);
    padding-bottom: 4px; margin-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}
.kline-ind-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 2px 0; gap: 4px;
}
.kline-ind-label { color: var(--text-muted); font-size: 10px; white-space: nowrap; }
.kline-ind-value { color: var(--text-primary); font-family: var(--font-mono); font-size: 10px; text-align: right; flex: 1; }
.kline-ind-signal { font-size: 9px; padding: 1px 4px; border-radius: 3px; font-weight: 600; white-space: nowrap; }
.kline-ind-signal.bullish { background: var(--accent-success-soft); color: var(--accent-success); }
.kline-ind-signal.bearish { background: var(--accent-danger-soft); color: var(--accent-danger); }
.kline-ind-signal.neutral { background: rgba(148,163,184,0.1); color: var(--text-secondary); }

@media (max-width: 700px) {
    .kline-modal-content { max-width: 100vw; max-height: 98vh; width: 100vw; height: 90vh; border-radius: var(--radius-md); }
    .kline-modal-content.fullscreen { border-radius: 0; }
    .kline-chart-area { height: 50vh; }
    .kline-modal-indicators { grid-template-columns: repeat(3, 1fr); gap: 8px 10px; padding: 8px 10px; }
    .kline-modal-header { padding: 10px 14px; }
    .kline-modal-name { font-size: 14px; }
}
@media (max-width: 480px) {
    .kline-modal-indicators { grid-template-columns: repeat(2, 1fr); }
    .kline-modal-content { height: 95vh; }
}

/* ==========================================
   Floating AI Status Bar (non-blocking)
   ========================================== */
.ai-status-bar {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    width: 380px;
    max-width: calc(100vw - 48px);
    background: var(--bg-card);
    border: 1px solid var(--border-active);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: statusSlideIn 0.3s ease;
}

.ai-status-bar.active {
    display: block;
}

@keyframes statusSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.ai-status-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.ai-status-header:hover {
    background: var(--bg-card-hover);
}

.ai-status-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.ai-status-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.ai-status-toggle {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.ai-status-bar.collapsed .ai-status-toggle {
    transform: rotate(180deg);
}

.ai-status-logs {
    max-height: 200px;
    overflow-y: auto;
    padding: 8px 12px;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.ai-status-bar.collapsed .ai-status-logs {
    max-height: 0;
    padding: 0 12px;
    overflow: hidden;
}

.ai-status-logs::-webkit-scrollbar {
    width: 3px;
}

.ai-status-logs::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.ai-status-log-item {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    padding: 2px 0;
    line-height: 1.4;
}

.ai-status-progress {
    height: 2px;
    background: var(--border-color);
    overflow: hidden;
}

.ai-status-progress-bar {
    height: 100%;
    background: var(--gradient-primary);
    animation: progressPulse 2s ease-in-out infinite;
}

@keyframes progressPulse {
    0% {
        width: 15%;
        margin-left: 0;
    }

    50% {
        width: 40%;
        margin-left: 30%;
    }

    100% {
        width: 15%;
        margin-left: 85%;
    }
}

/* ==========================================
   Toast Notifications
   ========================================== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 3.5s forwards;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    max-width: 400px;
}

.toast-success {
    border-left: 3px solid var(--accent-success);
}

.toast-error {
    border-left: 3px solid var(--accent-danger);
}

.toast-info {
    border-left: 3px solid var(--accent-info);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(50px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* ==========================================
   登入區塊 + 登入 Modal
   ========================================== */
.auth-area {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-login {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
    white-space: nowrap;
}
.btn-login:hover { opacity: 0.85; }

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}
.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-color);
}
.user-email {
    color: var(--text-secondary);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
}
.btn-logout {
    padding: 3px 8px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
}
.btn-logout:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* 登入提示 Modal */
.login-modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 32px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    position: relative;
    animation: modalIn 0.2s ease;
}
.login-modal-body { padding: 8px 0; }
.login-modal-icon { font-size: 36px; margin-bottom: 12px; }
.login-modal-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 4px;
    color: var(--text-primary);
}
.login-modal-desc {
    color: var(--text-secondary);
    font-size: 13px;
    margin: 8px 0 24px;
    line-height: 1.6;
}
.btn-google-login {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 24px;
    background: #fff;
    color: #333;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: box-shadow 0.2s;
    width: 100%;
    justify-content: center;
}
.btn-google-login:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.login-modal-footer {
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 12px;
}

/* 進階篩選鎖定 */
.chip-locked {
    opacity: 0.5;
    cursor: not-allowed !important;
    position: relative;
}
.chip-locked .lock-icon {
    font-size: 10px;
    margin-left: 3px;
}

/* 手機版登入區塊 */
@media (max-width: 768px) {
    .user-email { max-width: 100px; font-size: 10px; }
    .btn-login { padding: 4px 10px; font-size: 11px; }
    .btn-logout { font-size: 10px; padding: 2px 6px; }
}

/* ==========================================
   Footer
   ========================================== */
.site-footer {
    max-width: 1440px;
    margin: 40px auto 0;
    padding: 24px 24px 32px;
    border-top: 1px solid var(--border-color);
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.footer-brand {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary);
}

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

.footer-copy {
    font-size: 13px;
    color: var(--text-secondary);
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.footer-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
}

.footer-link:hover {
    color: var(--accent-primary);
}

.footer-link svg {
    opacity: 0.7;
    transition: var(--transition);
}

.footer-link:hover svg {
    opacity: 1;
}

.footer-disclaimer {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
}

/* ==========================================
   Header Navigation (shared)
   ========================================== */
.header-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 16px;
}

.nav-link {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    white-space: nowrap;
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="light"] .nav-link:hover {
    background: #e2e8f0;
}

.nav-link.active {
    color: var(--accent-primary);
    background: var(--accent-primary-glow);
    font-weight: 600;
}

@media (max-width: 768px) {
    .header-nav {
        margin-left: 8px;
        gap: 2px;
    }
    .nav-link {
        font-size: 12px;
        padding: 4px 8px;
    }
}

/* ==========================================
   Screener — Tabs
   ========================================== */
.screener-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin: -2px -2px 0;
}

.screener-tab {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.screener-tab:hover {
    color: var(--text-secondary);
    background: var(--bg-card-hover);
}

.screener-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: linear-gradient(180deg, transparent 0%, var(--accent-primary-glow) 130%);
}

.screener-tab-content {
    display: none;
}

.screener-tab-content.active {
    display: block;
}

/* ==========================================
   Screener — Filter Chips
   ========================================== */
.filter-grid {
    display: block;
}

.filter-groups {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-group {
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-md);
    background: var(--surface-1);
    overflow: clip;
}

.filter-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    list-style: none;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.filter-group-header::-webkit-details-marker {
    display: none;
}

.filter-group-title {
    font-size: 13px;
    color: var(--text-primary);
}

.filter-group-note {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.filter-group-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    padding: 0 10px 10px;
}

.filter-more {
    margin: 0 10px 10px;
}

.btn-group-more {
    border: 1px dashed var(--card-outline);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    list-style: none;
}

.btn-group-more::-webkit-details-marker {
    display: none;
}

.filter-more[open] .btn-group-more {
    color: var(--text-primary);
    border-color: var(--border-active);
    background: var(--bg-card-hover);
}

.filter-more[open] .filter-group-grid {
    padding-top: 10px;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
}

.filter-chip {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    min-height: 66px;
    padding: 10px 12px;
    background: var(--surface-1);
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
    color: var(--text-secondary);
    user-select: none;
}

.filter-chip:hover {
    border-color: var(--border-active);
    background: var(--bg-card-hover);
}

.filter-chip input[type="checkbox"] {
    display: none;
}

.filter-chip.checked {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-primary-glow);
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2);
}

.filter-chip-icon {
    font-size: 15px;
    flex-shrink: 0;
}

.filter-chip-text {
    font-weight: 500;
    line-height: 1.3;
}

.filter-chip-desc {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    font-weight: 400;
    line-height: 1.35;
}

@media (max-width: 768px) {
    .filter-group {
        background: transparent;
    }

    .filter-group:not([open]) {
        background: var(--bg-input);
    }

    .filter-group-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 480px) {
    .filter-group-grid {
        grid-template-columns: 1fr;
        gap: 6px;
        padding: 0 8px 8px;
    }

    .filter-chip {
        min-height: 58px;
        padding: 8px 10px;
        font-size: 12px;
    }

    .filter-more {
        margin: 0 8px 8px;
    }
}

/* ==========================================
   Screener — Progress Bar
   ========================================== */
.screener-progress {
    display: none;
    margin-top: 16px;
}

.screener-progress.active {
    display: block;
}

.screener-progress-bar-bg {
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.screener-progress-bar {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.screener-progress-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    font-family: var(--font-mono);
}

/* ==========================================
   Screener — Result Filter Tags
   ========================================== */
.filter-tag {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    margin-right: 3px;
    margin-bottom: 2px;
    white-space: nowrap;
}

.filter-tag.bullish {
    background: var(--accent-success-soft);
    color: var(--accent-success);
}

.filter-tag.bearish {
    background: var(--accent-danger-soft);
    color: var(--accent-danger);
}

.filter-tag.neutral {
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-secondary);
}

.matched-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    max-width: 260px;
}

/* ==========================================
   Screener — Table Enhancements
   ========================================== */
.screener-table tbody tr {
    cursor: pointer;
}

.screener-table tbody tr:hover {
    background: linear-gradient(90deg, var(--surface-1), transparent 65%);
}

.screener-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 24px;
}

.screener-main > div:first-child {
    display: flex !important;
    justify-content: center;
    gap: 10px !important;
    padding: 8px 0 4px !important;
}

#dataSourceNote {
    text-align: center !important;
    font-size: 12px !important;
    color: var(--text-secondary) !important;
    padding: 0 0 8px !important;
    opacity: 0.95 !important;
}

.screener-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.membership-card {
    grid-column: 1 / -1;
    padding: 10px 12px;
}

.membership-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.membership-badge {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    font-weight: 700;
    color: #7c3aed;
    background: rgba(124, 58, 237, 0.12);
    border: 1px solid rgba(124, 58, 237, 0.28);
    border-radius: 999px;
    padding: 4px 10px;
}

.membership-badge.member {
    color: #065f46;
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.35);
}

.membership-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-right: auto;
}

.membership-usage {
    font-size: 11px;
    color: var(--text-muted);
    padding: 3px 8px;
    border: 1px dashed var(--card-outline);
    border-radius: 999px;
}

.auth-message {
    margin: 8px 0;
    font-size: 13px;
}

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

.auth-message.success {
    color: #16a34a;
}

.auth-message.error {
    color: #dc2626;
}

.toolbar-card {
    background: var(--surface-1);
    border: 1px solid var(--card-outline);
    border-radius: 12px;
    padding: 12px;
    box-shadow: none;
}

.toolbar-title {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: 0.4px;
}

.template-toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
    user-select: none;
}

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

.template-toggle-arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.template-toggle.expanded .template-toggle-arrow {
    transform: rotate(180deg);
}

.template-toggle.expanded {
    margin-bottom: 8px;
}

.save-condition-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.inline-tpl-input {
    width: 140px;
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-primary);
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.toolbar-row:last-of-type {
    margin-bottom: 0;
}

.toolbar-row input[type="text"],
.toolbar-row input[type="password"],
.toolbar-row select {
    flex: 1;
    min-width: 120px;
    padding: 8px 10px;
    background: var(--bg-card);
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-mono);
}

.toolbar-row input[type="text"]:focus,
.toolbar-row input[type="password"]:focus,
.toolbar-row select:focus {
    border-color: var(--border-active);
    outline: none;
    box-shadow: var(--focus-ring);
}

.toolbar-row .btn-add-ticker {
    padding: 8px 12px;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.toolbar-row .btn-add-ticker:hover {
    opacity: 0.9;
}

.toolbar-note {
    margin: 8px 0 0;
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.45;
}

.custom-ticker-tag-locked {
    opacity: 0.8;
    border-style: dashed;
}

.screener-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
    padding: 10px;
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-md);
    background: var(--surface-1);
}

#btnScreenScan,
#btnBacktestScan {
    min-width: 148px;
    justify-content: center;
}

#tabBacktest > h3 {
    font-size: 13px !important;
    color: var(--text-secondary) !important;
    font-weight: 700 !important;
    margin-bottom: 4px !important;
    letter-spacing: 0.02em;
}

#tabBacktest > p {
    font-size: 11px !important;
    color: var(--text-muted) !important;
    margin: 0 0 10px !important;
}

.screener-result-count {
    font-size: 13px;
    color: var(--text-secondary);
    margin-left: auto;
    font-family: var(--font-mono);
    padding: 2px 8px;
    border: 1px solid var(--card-outline);
    border-radius: 999px;
    background: var(--surface-1);
}

.result-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* RWD: 手機版調整 */
@media (max-width: 640px) {
    .screener-main {
        padding: 12px;
    }
    .screener-toolbar {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .toolbar-card {
        padding: 10px;
    }
    .membership-row {
        align-items: flex-start;
    }
    .membership-hint {
        width: 100%;
        margin-right: 0;
    }
    .membership-usage {
        order: 3;
    }
    .toolbar-row {
        flex-wrap: wrap;
    }
    .toolbar-row input[type="text"],
    .toolbar-row input[type="password"],
    .toolbar-row select {
        width: 100%;
        min-width: 100%;
    }
    .filter-mode-toggle {
        flex-direction: column;
        align-items: flex-start;
    }
    .btn-advanced-toggle {
        width: 100%;
    }
    .screener-tabs {
        margin: -2px -2px 0;
    }
    .screener-tab {
        font-size: 13px;
        padding: 10px 8px;
    }
    .screener-table .col-signal,
    .screener-table .col-price {
        display: none;
    }
    .matched-tags {
        max-width: 140px;
    }
    .backtest-mode-row {
        flex-wrap: wrap;
    }
    .backtest-mode-row select {
        width: 100%;
    }
    .screener-actions {
        flex-wrap: wrap;
        position: sticky;
        bottom: 8px;
        z-index: 20;
        backdrop-filter: blur(8px);
    }
}

/* ==========================================
   Screener — Custom Ticker Input
   ========================================== */
.custom-ticker-input-area {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.custom-ticker-input-area input[type="text"] {
    width: 180px;
    min-width: 140px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-mono);
}

.custom-ticker-input-area input[type="text"]:focus {
    border-color: var(--border-active);
    outline: none;
}

.custom-ticker-input-area .btn-add-ticker {
    padding: 6px 12px;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.custom-ticker-input-area .btn-add-ticker:hover {
    opacity: 0.85;
}

.custom-ticker-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.custom-ticker-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--accent-primary-glow);
    border: 1px solid var(--accent-primary);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-primary);
    font-family: var(--font-mono);
}

.custom-ticker-tag .remove-ticker {
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    opacity: 0.7;
}

.custom-ticker-tag .remove-ticker:hover {
    opacity: 1;
}

/* ==========================================
   Screener — Filter Mode Toggle
   ========================================== */
.filter-mode-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0;
}

.filter-control-stack {
    display: grid;
    gap: 8px;
    margin-top: 10px;
    margin-bottom: 8px;
}

.control-row {
    padding: 8px 10px;
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-md);
    background: var(--surface-1);
}

.filter-hint {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.3;
}

.btn-advanced-toggle {
    white-space: nowrap;
}

.filter-mode-toggle button {
    padding: 7px 12px;
    background: var(--surface-1);
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.filter-mode-toggle button:hover {
    border-color: var(--border-active);
    background: var(--surface-2);
}

.filter-advanced {
    display: none;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.06), rgba(59, 130, 246, 0.02));
}

.filter-advanced.show {
    display: block;
}

/* ==========================================
   Screener — Simple Filter Chips
   ========================================== */
.simple-filter-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

#simpleFilterGrid.compact .simple-filter-chip.simple-extra {
    display: none;
}

.simple-filter-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0;
}

.btn-simple-more {
    padding: 6px 10px;
    background: var(--surface-1);
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-simple-more:hover {
    border-color: var(--border-active);
    background: var(--surface-2);
}

.btn-simple-more,
.btn-advanced-toggle {
    min-width: 140px;
}

.simple-filter-summary {
    font-size: 12px;
    color: var(--text-muted);
}

.simple-filter-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--surface-1);
    border: 1px solid var(--card-outline);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
    color: var(--text-secondary);
    user-select: none;
}

.simple-filter-chip:hover {
    border-color: var(--border-active);
    background: var(--bg-card-hover);
}

.simple-filter-chip input[type="checkbox"] {
    display: none;
}

.simple-filter-chip.checked {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-primary-glow);
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2);
}

.simple-filter-chip .chip-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.simple-filter-chip .chip-label {
    font-weight: 600;
    line-height: 1.3;
}

.simple-filter-chip .chip-desc {
    font-size: 10px;
    color: var(--text-muted);
    display: block;
    font-weight: 400;
}

@media (max-width: 768px) {
    .simple-filter-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .simple-filter-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .filter-mode-toggle {
        flex-direction: column;
        align-items: flex-start;
    }

    .filter-control-stack {
        gap: 10px;
    }

    .btn-simple-more,
    .btn-advanced-toggle {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .simple-filter-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================
   Screener — Backtest Mode
   ========================================== */
.backtest-mode-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.backtest-mode-row select {
    padding: 4px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 12px;
}

/* ==========================================
   Screener — Backtest Return Column
   ========================================== */
.backtest-return {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
}

.backtest-return.positive {
    color: var(--accent-success);
}

.backtest-return.negative {
    color: var(--accent-danger);
}

/* ==========================================
   Screener — Backtest Summary in K-line Modal
   ========================================== */
.backtest-summary-group .backtest-summary-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.backtest-summary-group .bt-positive {
    color: var(--accent-success);
}

.backtest-summary-group .bt-negative {
    color: var(--accent-danger);
}

/* ==========================================
   Screener — Operation Advice Column
   ========================================== */
.op-advice {
    font-size: 12px;
    font-weight: 600;
    white-space: normal;
    line-height: 1.4;
}

.inst-note {
    font-size: 11px;
    margin-top: 3px;
    opacity: 0.86;
    line-height: 1.35;
}

/* ==========================================
   Screener — Filter Type Badges (買入/賣出/篩選)
   ========================================== */
.chip-type {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    margin-left: 4px;
    vertical-align: middle;
    letter-spacing: 0.02em;
}

.chip-type-buy {
    background: var(--accent-success-soft);
    color: var(--accent-success);
}

.chip-type-sell {
    background: var(--accent-danger-soft);
    color: var(--accent-danger);
}

.chip-type-neutral {
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-muted);
}

/* 在線人數 */
.online-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 8px;
}
.online-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    animation: online-pulse 2s ease-in-out infinite;
}
@keyframes online-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.online-count {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-secondary);
}

/* ==========================================
   Phase 1: 摘要 / 排行榜 / 歷史紀錄
   ========================================== */

/* 篩選摘要 */
.screen-summary-box {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 12px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary);
}
.screen-summary-box .summary-copy-btn {
    margin-top: 8px;
}

/* Badge */
.badge-sm {
    display: inline-block;
    background: var(--accent-primary);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 8px;
    margin-left: 4px;
    vertical-align: middle;
}

/* 排行榜 Modal */
.ranking-modal-content,
.history-modal-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.ranking-modal-header,
.history-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}
.ranking-modal-header h3,
.history-modal-header h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text-primary);
}
.ranking-modal-body,
.history-modal-body {
    padding: 12px 20px;
    overflow-y: auto;
    flex: 1;
}
.ranking-modal-footer,
.history-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    text-align: right;
}
.ranking-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 20px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border-color);
}
.ranking-tab {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.ranking-tab:hover {
    background: var(--bg-primary);
}
.ranking-tab.active {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}
.ranking-table {
    width: 100%;
    font-size: 13px;
}
.ranking-table tr[data-ticker]:hover {
    background: var(--bg-tertiary);
}

/* 歷史紀錄 */
.history-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}
.history-item:last-child {
    border-bottom: none;
}
.history-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.history-stocks {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}
