@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Palantir Dark Theme Colors */
    --bg-primary: #0a0b0f;
    --bg-secondary: #141722;
    --bg-tertiary: #1c1f2e;
    --bg-quaternary: #252a3e;
    --accent-blue: #2196f3;
    --accent-cyan: #00bcd4;
    --accent-green: #4caf50;
    --accent-orange: #ff9800;
    --accent-red: #f44336;
    --text-primary: #ffffff;
    --text-secondary: #b3b8db;
    --text-muted: #6c7293;
    --border-primary: #2c3348;
    --border-secondary: #404559;
    --shadow-primary: rgba(0, 0, 0, 0.6);
    --shadow-secondary: rgba(33, 150, 243, 0.2);
    --gradient-primary: linear-gradient(135deg, #0a0b0f 0%, #1c1f2e 100%);
    --gradient-accent: linear-gradient(135deg, #2196f3 0%, #00bcd4 100%);
    --gradient-card: linear-gradient(135deg, #141722 0%, #1c1f2e 100%);
}

/* Light Theme Colors */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-quaternary: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-primary: #e2e8f0;
    --border-secondary: #cbd5e1;
    --shadow-primary: rgba(0, 0, 0, 0.1);
    --shadow-secondary: rgba(33, 150, 243, 0.15);
    --gradient-primary: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    --gradient-card: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gradient-primary);
    min-height: 100vh;
    color: var(--text-primary);
    overflow-x: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(33, 150, 243, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(0, 188, 212, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(76, 175, 80, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

/* 側邊欄樣式 */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 250px;
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    transition: all 0.3s ease;
    z-index: 2000;
    overflow-y: auto;
}

.sidebar-collapsed {
    width: 60px;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
}

.sidebar-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-nav {
    padding: 20px 0;
}

.sidebar-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-icon {
    font-size: 1.2rem;
    margin-right: 12px;
}

.nav-text {
    font-weight: 500;
}

.nav-arrow {
    margin-left: auto;
    font-size: 10px;
    transition: transform 0.3s ease;
}

.nav-arrow.rotated {
    transform: rotate(180deg);
}

.submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: var(--bg-tertiary);
    border-left: 2px solid var(--border-primary);
    margin-left: 20px;
}

.submenu.open {
    max-height: 500px;
}

.submenu a {
    padding: 8px 20px 8px 40px;
    font-size: 14px;
}

.submenu-icon {
    font-size: 1rem;
    margin-right: 8px;
}

/* 主要內容區域 */
.main-content {
    margin-left: 250px;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
    padding: 20px;
}

.main-header {
    text-align: right;
    padding: 10px 20px 0;
}

/* Theme Toggle：固定於左下角，不再佔用頂部空間 */
.theme-toggle {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 60;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    background: var(--bg-card, var(--bg-secondary));
    border: 1px solid var(--border-primary);
    border-radius: 999px;
    padding: 6px 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.theme-toggle-track {
    width: 60px;
    height: 30px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-primary);
    border-radius: 20px;
    position: relative;
}

.theme-toggle-thumb {
    width: 22px;
    height: 22px;
    background: var(--gradient-accent);
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: all 0.3s ease;
}

[data-theme="light"] .theme-toggle-thumb {
    transform: translateX(30px);
}

.theme-toggle-label {
    font-size: 20px;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 20px;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Config Section */
.config-section {
    background: var(--gradient-card);
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 20px 40px var(--shadow-primary);
    border: 1px solid var(--border-primary);
}

.config-section h2 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1.5rem;
    font-weight: 700;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

/* Stock Grid */
.stock-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.stock-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: all 0.3s ease;
    animation: fadeInUp 0.5s ease forwards;
    animation-delay: var(--animation-delay, 0s);
    opacity: 0;
}

.stock-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 30px var(--shadow-secondary);
    border-color: var(--accent-blue);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stock-rank {
    width: 40px;
    height: 40px;
    background: var(--gradient-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
}

.stock-info {
    flex: 1;
}

.stock-code {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stock-name {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.stock-count {
    text-align: right;
}

.count-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-green);
}

.count-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Info Box */
.info-box {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 20px;
    border-left: 4px solid var(--accent-blue);
}

.info-box p {
    margin: 8px 0;
    color: var(--text-secondary);
}

.info-box strong {
    color: var(--text-primary);
}

/* Buttons */
.btn-primary {
    background: var(--gradient-accent);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px var(--shadow-secondary);
}

.btn-secondary {
    background: var(--bg-quaternary);
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-primary);
}

.data-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
}

.data-table td {
    color: var(--text-primary);
}

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-quaternary);
    font-weight: 600;
}

.rank-badge.rank-1 {
    background: linear-gradient(135deg, #ffd700, #ffb800);
    color: #000;
}

.rank-badge.rank-2 {
    background: linear-gradient(135deg, #c0c0c0, #a8a8a8);
    color: #000;
}

.rank-badge.rank-3 {
    background: linear-gradient(135deg, #cd7f32, #b8712d);
    color: #fff;
}

.code-cell {
    font-weight: 700;
    color: var(--accent-blue) !important;
}

.mention-count {
    background: var(--accent-green);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 600;
}

/* Article List */
.article-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.article-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 20px;
    transition: all 0.2s ease;
}

.article-card:hover {
    border-color: var(--accent-blue);
}

.article-meta {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
}

.article-date {
    color: var(--text-muted);
    font-size: 13px;
}

.article-push {
    font-size: 13px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
}

.article-push.push-hot {
    background: var(--accent-red);
    color: white;
}

.article-push.push-positive {
    background: var(--accent-green);
    color: white;
}

.article-push.push-neutral {
    background: var(--bg-quaternary);
    color: var(--text-muted);
}

.article-title {
    display: block;
    color: var(--text-primary);
    font-weight: 500;
    text-decoration: none;
    margin-bottom: 8px;
}

.article-title:hover {
    color: var(--accent-blue);
}

.article-author {
    color: var(--text-muted);
    font-size: 13px;
}

/* Search Form */
.search-form {
    display: flex;
    gap: 15px;
    align-items: end;
}

.search-input {
    flex: 1;
    max-width: 300px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 14px;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.form-group {
    margin-bottom: 0;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-primary);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading p {
    color: var(--text-secondary);
}

/* ============ 今日熱門股儀表板 ============ */
/* 漲跌色（台股慣例：紅漲綠跌） */
.up { color: var(--accent-red); }
.down { color: var(--accent-green); }
.flat, .muted { color: var(--text-muted); }
.num { text-align: right; }
/* 現價後方的「與昨收相比漲跌」括號標示 */
.chg-paren { font-size: 0.82em; font-weight: 600; margin-left: 0.25rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chg-paren.flat { color: var(--text-muted); }

/* KPI 總覽 */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--gradient-card);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 0 10px 24px var(--shadow-primary);
}

.kpi-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.kpi-value { font-size: 1.6rem; font-weight: 800; color: var(--text-primary); }
.kpi-value small { font-size: 0.9rem; font-weight: 600; }
.kpi-sub { font-size: 0.8rem; color: var(--text-secondary); }

.mode-badge { padding: 0.25rem 0.7rem; border-radius: 8px; font-size: 0.95rem; font-weight: 700; color: #fff; display: inline-block; }
.mode-badge.live { background: linear-gradient(135deg, #f44336, #e53935); }
.mode-badge.eod { background: linear-gradient(135deg, #64748b, #475569); }

/* Top 熱門股卡片 */
.hot-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.hot-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    padding: 16px 18px;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all 0.25s ease;
    animation: fadeInUp 0.4s ease forwards;
    animation-delay: var(--d, 0s);
    opacity: 0;
    border-left: 4px solid var(--border-secondary);
}

.hot-card.up { border-left-color: var(--accent-red); }
.hot-card.down { border-left-color: var(--accent-green); }
.hot-card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px var(--shadow-secondary); border-color: var(--accent-blue); }

.hot-card-top { display: flex; align-items: center; gap: 10px; }
.hot-rank {
    width: 28px; height: 28px; flex: 0 0 28px;
    background: var(--gradient-accent); color: #fff;
    border-radius: 8px; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.9rem;
}
.hot-id { flex: 1; min-width: 0; }
.hot-code { display: block; font-weight: 700; color: var(--accent-blue); font-size: 1.05rem; }
.hot-name { display: block; font-size: 0.85rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hot-name small { color: var(--text-muted); }
.hot-ptt { background: var(--bg-quaternary); color: var(--accent-blue); padding: 3px 8px; border-radius: 8px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }

.hot-card-mid { display: flex; align-items: baseline; justify-content: space-between; }
.hot-price { font-size: 1.7rem; font-weight: 800; color: var(--text-primary); }
.hot-change { font-size: 1.05rem; font-weight: 700; }

.hot-card-bot { display: flex; align-items: center; justify-content: space-between; font-size: 0.8rem; color: var(--text-muted); }
.hot-tags { display: flex; gap: 4px; }
.hot-tags .tag { background: var(--bg-quaternary); color: var(--text-secondary); padding: 2px 7px; border-radius: 6px; font-weight: 600; }
.hot-tags .tag.hot { background: rgba(244, 67, 54, 0.15); color: var(--accent-red); }

/* 綜合榜總表 */
.table-wrap { overflow-x: auto; }
.hot-table td { vertical-align: middle; }
.cell-id { display: flex; flex-direction: column; }
.name-link { color: var(--text-secondary); text-decoration: none; font-size: 0.85rem; }
.name-link:hover { color: var(--accent-blue); }

.change-pill { display: inline-block; padding: 4px 10px; border-radius: 8px; font-weight: 700; color: #fff; }
.change-pill.up { background: linear-gradient(135deg, #f44336, #e53935); }
.change-pill.down { background: linear-gradient(135deg, #4caf50, #43a047); }
.change-pill.flat { background: var(--bg-quaternary); color: var(--text-secondary); }

/* 現價漲停/跌停徽章：漲停紅底白字、跌停綠底白字（同漲跌幅樣式，不顯示「漲停/跌停」字樣） */
.price-pill { display: inline-block; padding: 4px 10px; border-radius: 8px; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price-pill.up { background: linear-gradient(135deg, #f44336, #e53935); }
.price-pill.down { background: linear-gradient(135deg, #4caf50, #43a047); }
.price-pill small { font-weight: 600; font-size: 0.82em; margin-left: 0.25rem; opacity: 0.95; }

/* 非漲跌停時的現價／漲跌幅文字色（漲紅跌綠平灰）；現價數字與後方括號同色 */
.price-val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price-val small { font-weight: 600; font-size: 0.82em; margin-left: 0.25rem; }
.price-val.up, .pct-val.up { color: var(--accent-red); }
.price-val.down, .pct-val.down { color: var(--accent-green); }
.price-val.flat, .pct-val.flat { color: var(--text-muted); }
.pct-val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Top 卡片現價數字漲跌色 */
.hot-price.up { color: var(--accent-red); }
.hot-price.down { color: var(--accent-green); }

.ptt-pill { display: inline-block; padding: 3px 9px; border-radius: 8px; background: var(--bg-quaternary); color: var(--accent-blue); font-weight: 600; }

.score-bar { background: var(--bg-quaternary); border-radius: 4px; height: 6px; overflow: hidden; margin-bottom: 3px; min-width: 60px; }
.score-bar span { display: block; height: 100%; background: var(--gradient-accent); }

/* 官方榜 */
/* 卡片放寬到 ~400px 起跳：四榜在寬螢幕排 3 張/列、中螢幕 2 張、窄螢幕 1 張，
   避免「價(含漲跌停徽章) + 成交值 + 漲跌%」三欄擠在 300px 內被截斷。 */
.ranking-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 16px; margin-top: 8px; }
@media (max-width: 460px) { .ranking-grid { grid-template-columns: 1fr; } }
.rank-card { background: var(--gradient-card); border: 1px solid var(--border-primary); border-radius: 16px; padding: 18px; box-shadow: 0 10px 24px var(--shadow-primary); }
.rank-card h3 { margin: 0 0 12px; font-size: 1.05rem; color: var(--text-primary); }
.mini-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.mini-table td { padding: 7px 6px; border-bottom: 1px solid var(--border-primary); color: var(--text-primary); }
.mini-rank { color: var(--text-muted); width: 1.6rem; }
.mini-link { color: var(--accent-blue); text-decoration: none; }
.mini-link:hover { text-decoration: underline; }
.mini-price { text-align: right; color: var(--text-secondary); }
.mini-change { text-align: right; font-weight: 700; }
.mini-change.up { color: var(--accent-red); }
.mini-change.down { color: var(--accent-green); }
.mini-empty { color: var(--text-muted); text-align: center; padding: 1rem; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0;
    }

    .stock-grid {
        grid-template-columns: 1fr;
    }

    .section-header {
        flex-direction: column;
        gap: 15px;
    }

    .search-form {
        flex-direction: column;
    }

    .search-input {
        max-width: 100%;
    }

    .container { padding: 20px 12px; }
    header h1 { font-size: 1.8rem; }
    .kpi-value { font-size: 1.3rem; }
}
