* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
    background: var(--color-bg); color: var(--color-text); min-height: 100vh; overflow-x: hidden;
}
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; }

/* ── 侧边栏 ── */
.sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 210px;
    background: var(--color-surface); border-right: 1px solid var(--color-border);
    z-index: 100; display: flex; flex-direction: column;
    transition: transform 0.25s ease, width 0.25s ease;
    overflow: hidden;
}
.sidebar.collapsed { width: 52px; }
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 14px; height: 48px; border-bottom: 1px solid var(--color-border-subtle);
    flex-shrink: 0;
}
.sidebar.collapsed .sidebar-header { padding: 0 12px; justify-content: center; }
.sidebar-header .brand {
    font-weight: bold; font-size: 15px; color: var(--color-link); white-space: nowrap;
    overflow: hidden; transition: opacity 0.2s;
}
.sidebar.collapsed .sidebar-header .brand { opacity: 0; width: 0; }
.sidebar-toggle {
    background: none; border: none; color: var(--color-text-muted); font-size: 20px;
    cursor: pointer; padding: 4px 6px; border-radius: var(--radius-sm); line-height: 1;
    flex-shrink: 0;
}
.sidebar-toggle:hover { color: var(--color-text); background: var(--color-border-subtle); }
.sidebar-nav {
    flex: 1; padding: var(--space-2) 0; overflow-y: auto;
    display: flex; flex-direction: column; gap: 2px;
}
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--color-border-subtle); }
.nav-group-title {
    padding: 4px 14px 3px; color: var(--color-text-dim); font-size: 11px;
    font-weight: 600; letter-spacing: .08em;
}
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    min-height: 44px; padding: 10px 14px; color: var(--color-text-muted); text-decoration: none;
    font-size: 13px; white-space: nowrap; border-left: 2px solid transparent;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.sidebar.collapsed .sidebar-nav a { padding: 10px 14px; justify-content: center; }
.sidebar.collapsed .sidebar-nav a .nav-label { display: none; }
.sidebar.collapsed .nav-group-title { padding: 3px 0; font-size: 0; }
.sidebar-nav a:hover { color: var(--color-text); background: var(--color-surface-raised); }
.sidebar-nav a.active { color: var(--color-link); background: rgba(88,166,255,0.08); border-left-color: var(--color-link); }
.sidebar-nav a .nav-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.sidebar-footer {
    padding: 10px 14px; border-top: 1px solid var(--color-border-subtle); flex-shrink: 0;
    font-size: 12px; color: var(--color-text-dim);
}
.sidebar.collapsed .sidebar-footer { padding: 10px 8px; text-align: center; }
.sidebar.collapsed .sidebar-footer .footer-text { display: none; }
.sidebar-footer a { color: var(--color-link); text-decoration: none; }
.sidebar-footer a:hover { text-decoration: underline; }
.sidebar-user-icon { font-size: 11px; color: #484f58; }

/* ── 市场交通灯 ── */
.traffic-light-wrap {
    display: flex; align-items: center; gap: var(--space-2);
    padding: var(--space-2) 0; margin-bottom: 6px; border-bottom: 1px solid var(--color-border-subtle);
}
.sidebar.collapsed .traffic-light-wrap { justify-content: center; padding: 6px 0; }
.sidebar.collapsed .traffic-light-wrap .tl-label { display: none; }
.traffic-light-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
    transition: background 0.5s, box-shadow 0.5s;
}
.tl-green  { background: #3fb950; color: #3fb950; }
.tl-yellow { background: #d29922; color: #d29922; }
.tl-red    { background: #f85149; color: #f85149; animation: tl-pulse 2s infinite; }
.tl-gray   { background: #484f58; color: #484f58; }
@keyframes tl-pulse { 0%, 100% { box-shadow: 0 0 6px currentColor; } 50% { box-shadow: 0 0 14px currentColor; } }
.tl-label { font-size: 12px; color: var(--color-text-muted); white-space: nowrap; }
.tl-detail { font-size: 10px; color: var(--color-text-dim); }

/* ── 主内容区 ── */
.main-wrap { margin-left: 210px; transition: margin-left 0.25s ease; min-height: 100vh; min-width: 0; display: flex; flex-direction: column; }
.main-wrap.expanded { margin-left: 52px; }
.container { max-width: 1400px; margin: 0 auto; padding: var(--space-4) var(--space-5); width: 100%; min-width: 0; flex: 1; }
.footer { text-align: center; font-size: 11px; color: var(--color-text-dim); padding: 12px var(--space-5) 16px; }

/* ── 移动端顶部条 ── */
.mobile-topbar {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 44px;
    background: var(--color-surface); border-bottom: 1px solid var(--color-border); z-index: 99;
    align-items: center; padding: 0 12px; gap: 10px;
}
.mobile-topbar .brand { font-weight: bold; font-size: 14px; color: var(--color-link); }
.mobile-topbar .menu-btn {
    background: none; border: none; color: var(--color-text-muted); font-size: 22px;
    cursor: pointer; padding: 2px 6px; line-height: 1;
}
.mobile-topbar .tl-dot-mobile { margin-left: auto; }
.mobile-topbar .tl-label-mobile { font-size: 11px; color: var(--color-text-muted); }

/* ── 移动端遮罩 ── */
.sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.55); z-index: 98;
}
.sidebar-overlay.show { display: block; }

/* ── 通用组件 ── */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-4); margin-bottom: var(--space-4); }
.card h2 { font-size: 15px; color: var(--color-link); margin-bottom: var(--space-3); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--color-border-subtle); }
th { color: var(--color-text-muted); font-weight: 500; }
td { color: var(--color-text-strong); }
.market-up { color: var(--color-market-up); }
.market-down { color: var(--color-market-down); }
.status-success { color: var(--color-status-success); }
.status-error, .status-failed { color: var(--color-status-error); }
.status-pending { color: var(--color-status-pending); }
.status-running { color: var(--color-status-running); }
.status-warning { color: var(--color-status-warning); }
.status-indicator { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-success { background: var(--color-status-success); }
.dot-failed { background: var(--color-status-error); }
.dot-pending { background: var(--color-status-pending); }
.dot-running { background: var(--color-status-running); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
pre { background: var(--color-surface-raised); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 12px; font-size: 13px; overflow-x: auto; max-height: 400px; overflow-y: auto; line-height: 1.7; color: var(--color-text-strong); white-space: pre-wrap; word-break: break-all; }
.stats { display: flex; gap: var(--space-3); margin-bottom: var(--space-4); }
.stat { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 12px var(--space-4); flex: 1; text-align: center; }
.stat .num { font-size: 28px; font-weight: bold; }
.stat .label { font-size: 12px; color: var(--color-text-muted); margin-top: var(--space-1); }
.login-box { max-width: 360px; margin: 100px auto; }
.login-box input[type=password] { width: 100%; padding: 10px; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-sm); color: var(--color-text); font-size: 15px; margin: 8px 0; }
.login-box button { width: 100%; padding: 10px; background: #238636; border: none; border-radius: var(--radius-sm); color: #fff; font-size: 15px; cursor: pointer; }
.login-box button:hover { background: #2ea043; }
.error { color: var(--color-status-error); font-size: 13px; margin-bottom: var(--space-2); }

/* Tab 导航（页面内嵌用） */
.tab-nav { display: flex; gap: 0; margin-bottom: var(--space-5); border-bottom: 1px solid var(--color-border); }
.tab-nav a { display: inline-block; padding: var(--space-2) var(--space-4); color: var(--color-text-muted); text-decoration: none; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color 0.15s, border-color 0.15s; }
.tab-nav a:hover { color: var(--color-text); border-bottom-color: var(--color-border); }
.tab-nav a.active { color: var(--color-link); border-bottom-color: var(--color-link); font-weight: 500; }
/* Chart 容器 */
.chart-wrap { position: relative; height: 300px; margin-bottom: var(--space-4); }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); margin-bottom: var(--space-4); }
.stale-badge { display: inline-block; background: #d29922; color: var(--color-bg); font-size: 11px; padding: 1px 6px; border-radius: 3px; margin-left: 6px; }
.table-wide { min-width: 900px; }
.table-wide th, .table-wide td { white-space: nowrap; }

/* ── response_meta 可信状态 ── */
.trust-status { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; width: 100%; margin: 6px 0; padding: 6px 8px; border: 1px solid var(--color-border); border-radius: 5px; background: rgba(13,17,23,.72); color: var(--color-text-muted); font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.trust-status[hidden] { display: none !important; }
.trust-status__states { display: inline-flex; flex-wrap: wrap; gap: 5px; }
.trust-state { display: inline-flex; align-items: center; min-height: 24px; padding: 1px 7px; border: 1px solid #484f58; border-radius: var(--radius-sm); white-space: nowrap; font-weight: 600; }
.trust-state--loading { color: #d29922; border-color: #d29922; }
.trust-state--empty { color: var(--color-text-faint); border-color: var(--color-text-dim); }
.trust-state--partial { color: #f0883e; border-color: #f0883e; }
.trust-state--stale { color: #d29922; border-color: #d29922; }
.trust-state--error { color: var(--color-status-error); border-color: var(--color-status-error); }
.trust-status__summary { min-width: 0; color: var(--color-text-muted); }
.trust-status__details { display: flex; flex-wrap: wrap; gap: 4px 10px; width: 100%; color: var(--color-text-faint); }
.trust-status__detail { overflow-wrap: anywhere; }
.trust-status--error { border-color: rgba(248,81,73,.55); }
.trust-status__retry { margin-left: auto; padding: 4px 10px; border: 1px solid var(--color-status-error); border-radius: var(--radius-sm); background: transparent; color: var(--color-status-error); cursor: pointer; }

/* ── 手机竖屏 (< 600px) ── */
@media (max-width: 600px) {
    .sidebar {
        transform: translateX(-100%); width: 220px !important;
        box-shadow: 2px 0 12px rgba(0,0,0,0.4);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.collapsed { width: 220px !important; }
    .sidebar.collapsed .sidebar-header { padding: 0 14px; justify-content: space-between; }
    .sidebar.collapsed .sidebar-header .brand { opacity: 1; width: auto; }
    .sidebar.collapsed .sidebar-nav a { padding: 10px 14px; justify-content: flex-start; }
    .sidebar.collapsed .sidebar-nav a .nav-label { display: inline; }
    .sidebar.collapsed .sidebar-footer { padding: 10px 14px; text-align: left; }
    .sidebar.collapsed .sidebar-footer .footer-text { display: block; }
    .main-wrap { margin-left: 0 !important; padding-top: 44px; }
    .mobile-topbar { display: flex; }
    .container { padding: 10px; }
    .card { padding: 12px; margin-bottom: 10px; }
    .card h2 { font-size: 14px; }
    .stats { flex-wrap: wrap; gap: 8px; }
    .stat { flex: none; width: calc(50% - 4px); padding: 10px 12px; }
    .stat .num { font-size: 22px; }
    .stat .label { font-size: 11px; }
    #outputModal > div {
        max-width: 100% !important; width: 100% !important;
        margin: 0 !important; max-height: 100vh !important;
        border-radius: 0 !important; padding: 12px !important;
    }
    #modalOutput { max-height: 55vh !important; font-size: 11px !important; }
    .chart-wrap { height: 200px; }
    .chart-row { grid-template-columns: 1fr; gap: 10px; }
    .track-row { grid-template-columns: 1fr !important; gap: 10px; }
    .table-wide { min-width: 600px; }
    table { font-size: 12px; }
    th, td { padding: 6px 8px; }
    .history-controls { flex-direction: column; align-items: stretch; gap: 8px; }
    .history-controls select, .history-controls button { width: 100%; }
    #versionSelect { width: 100%; }
    .backtest-version-bar { flex-direction: column !important; align-items: stretch !important; gap: 8px; }
    button, .tab-nav a, select, input[type="text"], input[type="password"] { min-height: 44px; }
    input[type="date"] { min-height: 44px; }
    .login-box { max-width: 100% !important; margin: 30px auto; }
    .refresh-bar { flex-wrap: wrap; gap: 6px; }
    .refresh-bar button { font-size: 12px; padding: 6px 10px; }
}
/* ── 手机横屏 / 小平板 (600-768px) ── */
@media (min-width: 601px) and (max-width: 768px) {
    .sidebar { width: 52px; }
    .sidebar .sidebar-header { padding: 0 12px; justify-content: center; }
    .sidebar .sidebar-header .brand { opacity: 0; width: 0; }
    .sidebar .sidebar-nav a { padding: 10px 14px; justify-content: center; }
    .sidebar .sidebar-nav a .nav-label { display: none; }
    .sidebar .sidebar-footer { padding: 10px 8px; text-align: center; }
    .sidebar .sidebar-footer .footer-text { display: none; }
    .sidebar.open { width: 210px !important; }
    .sidebar.open .sidebar-header { padding: 0 14px; justify-content: space-between; }
    .sidebar.open .sidebar-header .brand { opacity: 1; width: auto; }
    .sidebar.open .sidebar-nav a { padding: 10px 14px; justify-content: flex-start; }
    .sidebar.open .sidebar-nav a .nav-label { display: inline; }
    .sidebar.open .sidebar-footer { padding: 10px 14px; text-align: left; }
    .sidebar.open .sidebar-footer .footer-text { display: block; }
    .main-wrap { margin-left: 52px; }
    .main-wrap.expanded { margin-left: 210px; }
    .container { padding: 14px; }
    .chart-row { grid-template-columns: 1fr; gap: 12px; }
    .chart-wrap { height: 250px; }
    .stat .num { font-size: 24px; }
    .mobile-topbar { display: none; }
    .sidebar-overlay { display: none !important; }
    .table-wide { min-width: 700px; }
}
/* ── 平板 (769-1024px) ── */
@media (min-width: 769px) and (max-width: 1024px) {
    .mobile-topbar { display: none; }
    .sidebar-overlay { display: none !important; }
    .chart-row { grid-template-columns: 1fr 1fr; }
    .container { padding: 16px; }
}
/* ── 桌面 (>1024px) ── */
@media (min-width: 1025px) {
    .mobile-topbar { display: none; }
    .sidebar-overlay { display: none !important; }
}
/* ── 表格转卡片（需配 data-label 属性）── */
@media (max-width: 600px) {
    .responsive-table-wrap { overflow-x: visible !important; }
    table.responsive-table {
        display: block; min-width: 0 !important; width: 100% !important;
    }
    table.responsive-table thead, table.responsive-table tbody,
    table.responsive-table th, table.responsive-table td, table.responsive-table tr {
        display: block;
    }
    table.responsive-table thead tr { position: absolute; top: -9999px; left: -9999px; }
    table.responsive-table tr {
        border: 1px solid var(--color-border); border-radius: var(--radius-lg);
        margin-bottom: 10px; padding: 6px 0; background: var(--color-surface);
    }
    table.responsive-table td {
        position: relative; padding: 6px 12px 6px 42% !important;
        border-bottom: 1px solid var(--color-border-subtle); min-height: 30px;
        text-align: left !important; font-size: 13px; color: var(--color-text-strong);
        white-space: normal !important; max-width: none !important;
    }
    table.responsive-table td:last-child { border-bottom: none; }
    /* colspan 单元格(空占位/详情面板)不受 42% 标签位影响 */
    table.responsive-table td[colspan] { padding: 12px !important; }
    table.responsive-table td::before {
        content: attr(data-label);
        position: absolute; left: 12px; width: 36%;
        font-weight: 500; color: var(--color-text-muted); font-size: 11px;
        white-space: nowrap; text-align: left;
        overflow: hidden; text-overflow: ellipsis;
    }
}
/* 全局移动端触摸优化 */
button, [role="button"], a {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ── 折叠卡（低频区块默认收起）── */
details.card > summary.collapse-h2 {
    font-size: 15px; color: var(--color-link); cursor: pointer; font-weight: 600;
    list-style: none; user-select: none; min-height: 44px;
    display: flex; align-items: center;
}
details.card > summary.collapse-h2::-webkit-details-marker { display: none; }
details.card > summary.collapse-h2::before { content: '▸ '; color: var(--color-text-dim); }
details.card[open] > summary.collapse-h2::before { content: '▾ '; }
details.card > summary.collapse-h2 ~ * { margin-top: 10px; }

/* ── 手机端列表手风琴：次要字段默认收起，点行展开 ── */
@media (max-width: 600px) {
    table.responsive-table td[data-minor] { display: none; }
    table.responsive-table tr.open td[data-minor] { display: block; }
    table.responsive-table tr:has(> td[data-minor]):not(.open)::after {
        content: '⋯ 点按展开更多'; display: block; text-align: center;
        color: #484f58; font-size: 11px; padding: 2px 0 8px;
    }
}
