:root {
    --bg: #edf2f8;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --text: #10213b;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --positive: #e5484d;
    --negative: #16a34a;
    --sidebar: #0b1220;
    --sidebar-muted: #92a0b5;
    --shadow: 0 10px 30px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    min-width: 320px;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

button, input { font: inherit; }

button {
    border: 0;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    transition: background .18s ease, transform .18s ease, box-shadow .18s ease;
}

button:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 5px 14px rgba(37, 99, 235, .2); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid rgba(37, 99, 235, .3); outline-offset: 2px; }
button:disabled { cursor: wait; opacity: .6; transform: none; box-shadow: none; }

.app { display: flex; min-height: 100vh; }
.app-view { display: none; }
.app-view.active { display: block; animation: view-enter .2s ease-out; }
@keyframes view-enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex: 0 0 244px;
    flex-direction: column;
    min-height: 100vh;
    padding: 28px 16px;
    background: radial-gradient(circle at top left, #172c4e, var(--sidebar) 58%);
    color: #fff;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 10px 36px;
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -.5px;
}

.logo::before {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    box-shadow: 0 8px 16px rgba(37, 99, 235, .34);
    content: "Q";
    font-size: 15px;
}

nav { display: flex; flex-direction: column; gap: 5px; }

.menu-item {
    display: block;
    padding: 11px 13px;
    border: 1px solid transparent;
    border-radius: 9px;
    color: var(--sidebar-muted);
    text-decoration: none;
    transition: color .18s ease, background .18s ease;
}

.menu-item:hover { background: rgba(148, 163, 184, .12); color: #fff; }
.menu-item.active { border-color: rgba(96, 165, 250, .22); background: rgba(37, 99, 235, .28); color: #fff; }

.menu-title {
    margin: 20px 13px 6px;
    color: #718198;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

#watchlist { display: grid; gap: 4px; }
.watch-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 8px; color: #cbd5e1; font-size: 13px; }
.watch-item:hover { background: rgba(148, 163, 184, .10); }
.watch-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-item .delete-btn { padding: 3px 6px; background: transparent; color: #94a3b8; font-size: 12px; font-weight: 400; }
.watch-item .delete-btn:hover { background: rgba(239, 68, 68, .15); color: #fca5a5; box-shadow: none; }
.watch-empty { padding: 8px 13px; color: #64748b; font-size: 13px; }

.main { width: min(1440px, 100%); margin: 0 auto; padding: 38px 42px 64px; }

.header { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 27px; }
.header h1 { margin: 3px 0 5px; font-size: clamp(29px, 3vw, 37px); letter-spacing: -.05em; }
.header p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .12em; }

.market-overview {
    display: grid;
    grid-template-columns: 2fr repeat(3, 1fr);
    gap: 1px;
    overflow: hidden;
    margin: 0 0 20px;
    border: 1px solid #1e3a5f;
    border-radius: 14px;
    background: #1e3a5f;
    box-shadow: 0 12px 26px rgba(15, 23, 42, .12);
}

.overview-intro, .overview-stat { min-height: 76px; padding: 16px 19px; background: #10213b; color: #fff; }
.overview-intro { display: flex; flex-wrap: wrap; align-content: center; align-items: center; gap: 9px; font-weight: 700; }
.overview-intro strong { margin-left: 4px; padding: 3px 8px; border-radius: 999px; background: rgba(96, 165, 250, .18); color: #93c5fd; font-size: 11px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 5px rgba(34, 197, 94, .12); }
.overview-stat { display: grid; align-content: center; gap: 4px; background: #142b49; }
.overview-stat span { color: #9fb2c9; font-size: 11px; }
.overview-stat strong { font-size: 15px; letter-spacing: -.01em; }

.search { display: flex; min-width: min(100%, 350px); gap: 8px; padding: 5px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.search input, .watch-form input, .backtest-form input { min-width: 0; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); transition: border-color .18s ease, box-shadow .18s ease; }
.search input { flex: 1; width: 240px; padding: 9px 11px; border-color: transparent; }
.search input:focus, .watch-form input:focus, .backtest-form input:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(59, 130, 246, .12); outline: none; }
.search button { padding: 0 18px; }

.stock-card, .card { border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
.stock-card { position: relative; display: flex; align-items: center; justify-content: space-between; overflow: hidden; margin-bottom: 20px; padding: 25px 28px; border-radius: 15px; }
.stock-card::after { position: absolute; top: 0; right: 0; width: 220px; height: 100%; background: linear-gradient(135deg, transparent, rgba(37, 99, 235, .06)); content: ""; pointer-events: none; }
.stock-card h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.stock-card p { margin: 6px 0 0; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.price { color: var(--positive); font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.change { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.card { margin-bottom: 20px; padding: 25px 28px; border-radius: 15px; }
.card h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 18px; font-size: 18px; letter-spacing: -.02em; }
.card h2::before { width: 4px; height: 19px; border-radius: 4px; background: linear-gradient(#3b82f6, #2563eb); content: ""; }
.card h3 { margin: 27px 0 12px; font-size: 15px; }

.watch-form { display: flex; flex-wrap: wrap; gap: 10px; }
.watch-form input { flex: 1 1 190px; padding: 10px 11px; }
.watch-form button { padding: 10px 16px; }

.period-btn { padding: 7px 12px; border: 1px solid var(--border); background: var(--surface-muted); color: var(--muted); font-size: 13px; box-shadow: none; }
.period-btn:hover, .period-btn.active { border-color: #bfdbfe; background: #eff6ff; color: var(--primary); box-shadow: none; }

#klineChart { min-height: 480px; border-radius: 12px; background: linear-gradient(180deg, #fff, #fcfdff); }

.indicators { gap: 14px !important; }
.indicators > div { border-color: var(--border) !important; border-radius: 11px !important; background: var(--surface-muted) !important; }
.indicators span { color: var(--muted); font-size: 13px; }
.indicators strong { color: var(--text); font-variant-numeric: tabular-nums; }

#strategySignal { border-color: var(--border) !important; border-left: 4px solid var(--primary) !important; background: linear-gradient(90deg, #f8fbff, #fff) !important; }

.backtest-note, .backtest-status { color: var(--muted); }
.backtest-note { margin: -8px 0 17px; }
.backtest-status { min-height: 20px; margin: 13px 0 0; font-size: 13px; }
.backtest-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 17px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-muted); }
.backtest-form label { display: grid; flex: 1 1 130px; gap: 6px; color: #475569; font-size: 12px; font-weight: 600; }
.backtest-form input { width: 100%; padding: 9px 10px; }
.backtest-form button { min-height: 39px; padding: 10px 17px; }
.backtest-heading { align-items: center; }
.backtest-heading h2 { margin-top: 2px; }
.research-badge { padding: 7px 10px; border: 1px solid #bfdbfe; border-radius: 999px; background: #eff6ff; color: #1d4ed8; font-size: 12px; font-weight: 700; white-space: nowrap; }
.backtest-assumptions { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 14px; }
.backtest-assumptions span { padding: 5px 9px; border-radius: 999px; background: #f1f5f9; color: #475569; font-size: 12px; }
.chart-section-heading { display: flex; align-items: end; justify-content: space-between; margin: 28px 0 10px; }
.chart-section-heading h3 { margin: 0 0 3px; font-size: 16px; }
.chart-section-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.backtest-disclaimer { margin: 18px 0 0; padding: 11px 13px; border-left: 3px solid #f59e0b; border-radius: 4px; background: #fffbeb; color: #92400e; font-size: 12px; }
.backtest-metrics { display: grid; grid-template-columns: repeat(7, minmax(115px, 1fr)); gap: 12px; margin: 21px 0; }
.backtest-metrics div { padding: 15px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-muted); }
.backtest-metrics span, .backtest-metrics strong { display: block; }
.backtest-metrics span { color: var(--muted); font-size: 12px; }
.backtest-metrics strong { margin-top: 8px; color: var(--text); font-size: 19px; font-variant-numeric: tabular-nums; }
.equity-chart { width: 100%; height: 320px; border: 1px solid var(--border); border-radius: 12px; }

.trade-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.trade-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.trade-table th, .trade-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.trade-table th { background: var(--surface-muted); color: var(--muted); font-size: 12px; font-weight: 600; }
.trade-table tr:last-child td { border-bottom: 0; }
.trade-table tbody tr:hover { background: #f8fbff; }
.trade-buy { color: var(--positive); font-weight: 700; }
.trade-sell { color: var(--negative); font-weight: 700; }

.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.section-heading h2 { margin-bottom: 7px; }
.section-heading p { margin: 0; color: var(--muted); }
.secondary-button { padding: 9px 13px; border: 1px solid var(--border); background: var(--surface-muted); color: var(--primary); box-shadow: none; }
.secondary-button:hover { background: #eff6ff; box-shadow: none; }
.data-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 21px 0; }
.data-summary div, .data-tool { border: 1px solid var(--border); border-radius: 11px; background: var(--surface-muted); }
.data-summary div { padding: 15px; }
.data-summary span, .data-summary strong { display: block; }
.data-summary span { color: var(--muted); font-size: 12px; }
.data-summary strong { margin-top: 7px; font-size: 23px; font-variant-numeric: tabular-nums; }
.data-tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.data-tool { display: flex; flex-direction: column; padding: 17px; }
.data-tool h3 { margin: 0 0 7px; font-size: 15px; }
.data-tool p { min-height: 43px; margin: 0 0 13px; color: var(--muted); font-size: 12px; }
.data-tool code { padding: 1px 4px; border-radius: 3px; background: #e2e8f0; color: #334155; }
.data-tool input[type="file"] { width: 100%; margin: auto 0 11px; color: var(--muted); font-size: 12px; }
.data-tool button { min-height: 38px; margin-top: auto; padding: 9px 12px; }
.order-gateway-card { border-color: #bfdbfe; background: linear-gradient(135deg, #eff6ff, #f8fafc); }
.gateway-link { display: inline-flex; align-items: center; min-height: 38px; margin-top: auto; color: #1d4ed8; font-size: 13px; font-weight: 700; text-decoration: none; }
.gateway-link:hover { color: var(--primary-dark); text-decoration: underline; }
.inline-field { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: auto 0 11px; }
.inline-field label { color: var(--muted); font-size: 11px; }
.inline-field input { width: 100%; margin-top: 4px; padding: 7px; border: 1px solid var(--border); border-radius: 7px; }
.paper-order-form { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: auto 0 11px; }
.paper-order-form input, .paper-order-form select, .data-tool label input { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 7px; background: #fff; }
.data-tool label { margin: auto 0 11px; color: var(--muted); font-size: 12px; }
.danger-button { background: #dc2626; }
.danger-button:hover { background: #b91c1c; }
.workflow-banner { margin: 18px 0; padding: 12px 14px; border: 1px solid #bfdbfe; border-radius: 9px; background: #eff6ff; color: #1e3a8a; font-size: 13px; }
.risk-dashboard { margin: 18px 0; padding: 16px; border: 1px solid #bbf7d0; border-radius: 11px; background: #f0fdf4; }
.risk-dashboard .section-heading { margin-bottom: 0; }
.risk-dashboard .section-heading h3 { margin: 0 0 4px; }
.risk-dashboard .section-heading p, .risk-limits-text { margin: 0; color: var(--muted); font-size: 12px; }
.risk-summary { margin: 14px 0 10px; }
.proposal-grid { margin-top: 16px; }
.full-width-input { width: 100%; margin: 0 0 11px; padding: 8px; border: 1px solid var(--border); border-radius: 7px; }
.proposal-status { font-weight: 700; }
.proposal-pending { color: #b45309; font-weight: 700; }
.proposal-rejected { color: #dc2626; font-weight: 700; }
.proposal-executed_paper { color: #16a34a; font-weight: 700; }
.approve-button { padding: 6px 10px; background: #16a34a; font-size: 12px; }
.approve-button:hover { background: #15803d; }
.signal-proposal { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 17px; padding-top: 15px; border-top: 1px solid var(--border); }
.signal-proposal label { display: grid; gap: 3px; color: var(--muted); font-size: 12px; }
.signal-proposal input { width: 120px; padding: 7px; border: 1px solid var(--border); border-radius: 7px; }
.signal-proposal button { padding: 9px 12px; }
.signal-proposal p { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 12px; }
.sync-failures { margin: 15px 0; padding: 12px 15px; border: 1px solid #fed7aa; border-radius: 10px; background: #fff7ed; color: #9a3412; font-size: 12px; }
.sync-failures ul { margin: 7px 0 0; padding-left: 18px; }
.quality-panel { margin: 18px 0; padding: 16px; border: 1px solid #cbd5e1; border-radius: 11px; background: #fff; }
.quality-panel h3 { margin: 0 0 4px; }
.quality-panel .section-heading p { font-size: 12px; }
.quality-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.quality-summary div { padding: 12px; border-radius: 9px; background: var(--surface-muted); }
.quality-summary span, .quality-summary strong { display: block; }
.quality-summary span { color: var(--muted); font-size: 12px; }
.quality-summary strong { margin-top: 5px; font-size: 20px; }
.quality-issues { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: #fff7ed; color: #9a3412; font-size: 12px; }
.quality-issues ul { margin: 6px 0 0; padding-left: 18px; }
.candidate-section { margin-top: 24px; }
.candidate-section h3 { margin: 0 0 4px; }
.candidate-section .section-heading p { font-size: 12px; }
.candidate-proposal-button { padding: 6px 10px; font-size: 12px; }

@media (max-width: 1050px) {
    .sidebar { flex-basis: 200px; }
    .main { padding: 30px 28px 52px; }
    .indicators { grid-template-columns: repeat(2, 1fr) !important; }
    .backtest-metrics { grid-template-columns: repeat(3, minmax(115px, 1fr)); }
    .data-tool-grid { grid-template-columns: 1fr; }
    .data-summary { grid-template-columns: repeat(2, 1fr); }
    .quality-summary { grid-template-columns: repeat(2, 1fr); }
    .market-overview { grid-template-columns: repeat(3, 1fr); }
    .overview-intro { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
    .app { display: block; }
    .sidebar { position: static; min-height: auto; padding: 15px 16px; }
    .logo { margin: 0 0 13px; }
    nav { display: none; }
    .main { padding: 22px 16px 40px; }
    .header, .stock-card { align-items: flex-start; flex-direction: column; }
    .header { gap: 17px; }
    .market-overview { grid-template-columns: 1fr 1fr; }
    .overview-intro { grid-column: 1 / -1; }
    .search { width: 100%; }
    .stock-card { gap: 10px; }
    .change { text-align: left; }
    .card, .stock-card { padding: 20px; border-radius: 13px; }
    #klineChart { height: 500px !important; min-height: 400px; }
    .indicators, .backtest-metrics { grid-template-columns: repeat(2, minmax(110px, 1fr)) !important; }
    .backtest-form { padding: 13px; }
    .section-heading { flex-direction: column; }
}

@media (max-width: 420px) {
    .indicators, .backtest-metrics { grid-template-columns: 1fr !important; }
    .search button { padding: 0 13px; }
}
