:root {
  --bg: #0d1218;
  --panel: #151c25;
  --panel-2: #1b2430;
  --line: #2a3544;
  --text: #edf3f8;
  --muted: #95a4b5;
  --quiet: #687789;
  --blue: #55a8ff;
  --blue-soft: rgba(85, 168, 255, .14);
  --green: #42dc89;
  --red: #ff6868;
  --amber: #e7b64b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-width: 320px; margin: 0; background: radial-gradient(circle at 88% -10%, #19324a 0, transparent 32rem), var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }

.topbar {
  position: sticky; top: 0; z-index: 20; min-height: 66px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 10px max(22px, calc((100vw - 1480px) / 2));
  background: rgba(13, 18, 24, .92); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand > span:last-child { display: flex; flex-direction: column; line-height: 1.05; }
.brand small { margin-top: 5px; color: var(--muted); font-size: 11px; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: #08111b; background: var(--blue); font-weight: 850; }
.session-actions { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

main { max-width: 1480px; margin: 0 auto; padding: 28px 22px 64px; }
h1, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(28px, 3vw, 40px); letter-spacing: -.04em; }
.eyebrow { margin-bottom: 8px; color: var(--blue); font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.muted { color: var(--muted); }

.login-card { width: min(430px, 100%); margin: 8vh auto; padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: rgba(21, 28, 37, .96); box-shadow: 0 24px 65px rgba(0, 0, 0, .28); }
form label, .control-bar label { display: flex; flex-direction: column; gap: 7px; margin: 18px 0; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select { min-height: 40px; padding: 8px 11px; color: var(--text); background: #111821; border: 1px solid #344254; border-radius: 8px; outline: none; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(85, 168, 255, .14); }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.8); }
.button { min-height: 38px; padding: 8px 13px; color: var(--text); background: var(--panel-2); border: 1px solid #3a4859; border-radius: 8px; font-weight: 700; font-size: 13px; text-decoration: none; white-space: nowrap; }
.button:hover { border-color: #60748a; background: #232e3b; }
.button.primary { color: #07111b; border-color: var(--blue); background: var(--blue); }
.button.primary:hover { background: #7bbaff; }
.button.ghost { background: transparent; }
.button.wide { width: 100%; min-height: 43px; }
.button:disabled { cursor: wait; opacity: .55; }
.form-error { min-height: 20px; margin: 12px 0 0; color: var(--red); font-size: 13px; }
.form-link { margin: 5px 0 0; color: var(--muted); text-align: center; font-size: 13px; }

.dashboard-head { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.connection-state { display: inline-flex; align-items: center; gap: 8px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--panel); font-size: 12px; }
.connection-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 7px currentColor; }
.connection-state[data-state="connected"] { color: var(--green); }
.connection-state[data-state="connected"] i { background: var(--green); }
.connection-state[data-state="error"] { color: var(--red); }
.connection-state[data-state="error"] i { background: var(--red); }

.control-bar { display: flex; align-items: end; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.control-bar label { min-width: 215px; margin: 0; }
.control-bar label:nth-child(2) { min-width: 155px; }
.data-status { margin-left: auto; align-self: center; color: var(--muted); font-size: 12px; text-align: right; }

.data-tabs { display: flex; gap: 5px; width: fit-content; max-width: 100%; margin-top: 15px; padding: 5px; overflow-x: auto; border: 1px solid var(--line); border-radius: 11px; background: #111821; }
.data-tab { min-width: 126px; padding: 9px 16px; color: var(--muted); background: transparent; border: 0; border-radius: 7px; font-weight: 750; }
.data-tab:hover { color: var(--text); background: rgba(255, 255, 255, .04); }
.data-tab.active, .data-tab[aria-selected="true"] { color: var(--blue); background: var(--blue-soft); box-shadow: inset 0 0 0 1px rgba(85, 168, 255, .3); }
.data-tab:focus-visible { outline: 3px solid rgba(85, 168, 255, .2); }
.tab-date { display: flex; align-items: center; margin: 0; }
.tab-date input { width: auto; height: 29px; min-height: 0; padding: 3px 8px; border-radius: 6px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.tab-date input:hover { border-color: var(--blue); }
.tab-date input.latest { color: var(--blue); border-color: rgba(85, 168, 255, .4); }
.tab-date input::-webkit-calendar-picker-indicator { filter: invert(.72); cursor: pointer; }
.deferred-tab { margin-left: 12px; }

.summary-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 9px; margin-top: 12px; }
.summary-grid.stock-summary { grid-template-columns: repeat(2, minmax(190px, 260px)); }
.summary-card { min-width: 0; padding: 13px 15px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.summary-card span, .summary-card small { display: block; color: var(--muted); font-size: 11px; }
.summary-card strong { display: block; margin: 3px 0 1px; overflow: hidden; color: var(--text); font-size: 24px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.summary-card strong.summary-time { font-size: 16px; line-height: 1.8; }
.summary-grid.minute-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.minute-summary .summary-card { min-width: 0; min-height: 40px; padding: 5px 9px; display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.minute-summary .summary-card span, .minute-summary .summary-card small { display: inline; font-size: 10px; }
.minute-summary .summary-card strong { display: inline; margin: 0; font-size: 18px; line-height: 1.2; }
.minute-summary .summary-card strong.summary-time { font-size: 13px; line-height: 1.2; }
.positive { color: var(--red) !important; }
.negative { color: var(--green) !important; }
.empty { color: var(--quiet) !important; }

.table-card { margin-top: 10px; overflow: hidden; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.table-head { min-height: 49px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 13px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.table-head div { display: flex; flex-direction: column; }
.table-head .table-head-actions { flex-direction: row; align-items: center; gap: 12px; }
.minute-stock-filter { position: absolute; right: 6px; width: 30px; height: 28px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: #151e28; cursor: pointer; }
.minute-stock-filter .stock-arrow { color: var(--blue); font-size: 22px; line-height: 1; pointer-events: none; }
.minute-stock-filter select { position: absolute; inset: 0; width: 100%; height: 100%; appearance: none; color: transparent; background: transparent; border: 0; padding: 0; font-size: 0; cursor: pointer; }
.minute-stock-filter select option { color: var(--text); background: #151e28; font-size: 13px; }
.minute-stock-filter:hover { border-color: var(--blue); }
.minute-stock-filter:focus-within { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(85, 168, 255, .18); }
.minute-compact-head { position: relative; min-height: 41px; padding: 4px 7px; justify-content: center; }
.minute-table-title { color: var(--text); font-size: 12px; font-weight: 750; }
.minute-table-layout { display: grid; grid-template-columns: max-content 190px; align-items: start; justify-content: start; gap: 8px; }
.minute-market-card { width: max-content; max-width: 100%; min-width: 0; }
.minute-stock-card { width: 190px; justify-self: start; }
.minute-table { width: auto; max-width: 100%; line-height: 1.5; }
.minute-table th { padding: 8px 6px; font-size: 14px; font-weight: 600; text-transform: none; letter-spacing: 0; }
.minute-table td { padding: 5px 6px; border-bottom: 1.5px dashed #4d5d72; font-size: 18px; }
.minute-market-table th:first-child, .minute-market-table td:first-child { width: 70px; }
.minute-market-table th:last-child, .minute-market-table td:last-child { width: 90px; }
.minute-stock-scroll { min-height: 340px; }
.minute-stock-table { width: 100%; }
.minute-stock-table th:first-child { left: auto; width: 88px; text-align: right; }
.minute-stock-table td:empty::after { content: "\00a0"; visibility: hidden; }
.minute-stock-table td:first-child { position: static; width: 88px; text-align: right; }
.minute-stock-table tr:nth-child(even) td:first-child { background-color: rgba(255, 255, 255, .018); }
.minute-stock-table th:last-child, .minute-stock-table td:last-child { text-align: right; }
.minute-table tr.five-minute td { background-color: rgba(231, 182, 75, .22); }
.table-head span { color: var(--muted); font-size: 11px; }
.legend { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 7px; height: 7px; border-radius: 50%; }
.positive-dot { background: var(--red); }
.negative-dot { margin-left: 7px; background: var(--green); }
.table-scroll { max-height: calc(100vh - 330px); min-height: 340px; overflow: auto; }
.stock-scroll { min-height: 220px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; z-index: 2; padding: 9px 8px; color: var(--muted); background: #1b2430; border-bottom: 1px solid var(--line); font-size: 11px; text-align: right; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td { padding: 6px 8px; border-bottom: 1px dashed #344255; font-size: 16px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { position: sticky; left: 0; z-index: 1; text-align: center; background: var(--panel); }
thead th:first-child { z-index: 3; background: var(--panel-2); }
tr:nth-child(even) td { background-color: rgba(255, 255, 255, .018); }
tr:nth-child(even) td:first-child { background-color: #171e27; }
tr:hover td { background-color: rgba(85, 168, 255, .06); }
tr.five-minute td { border-top: 1px dashed rgba(231, 182, 75, .72); background-color: rgba(231, 182, 75, .11); }
tr.five-minute td:first-child { color: var(--amber); font-weight: 750; }
.minute-table tr.five-minute td:first-child { background-color: rgba(231, 182, 75, .22); }
td.minute-spike { color: white !important; background: rgba(255, 104, 104, .62) !important; font-weight: 800; }
.stock-table th:first-child, .stock-table td:first-child { text-align: left; }
.stock-table td { padding-block: 10px; font-size: 14px; }
.stock-table td:first-child { color: var(--blue); font-weight: 800; }
.daily-table th:last-child, .daily-table td:last-child { text-align: left; }
.daily-statistics-card { width: max-content; max-width: 100%; }
.daily-statistics-card .daily-table { width: auto; max-width: none; }
.stock-statistics-card { width: max-content; max-width: 100%; }
/* Statistics tables shrink to their contents and scroll within the remaining page height. */
body:has(#workspace:not([hidden]) > :is(#daily-panel, #stock-statistics-panel):not([hidden])) {
  height: 100vh; height: 100dvh; display: flex; flex-direction: column;
}
body:has(#workspace:not([hidden]) > :is(#daily-panel, #stock-statistics-panel):not([hidden])) > .topbar { flex-shrink: 0; }
main:has(#workspace:not([hidden]) > :is(#daily-panel, #stock-statistics-panel):not([hidden])) {
  display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; padding-bottom: 22px;
}
#workspace:has(#daily-panel:not([hidden]), #stock-statistics-panel:not([hidden])) {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
}
#workspace > .data-tabs { flex-shrink: 0; }
#daily-panel, #stock-statistics-panel {
  display: flex; flex-direction: column; align-items: flex-start; flex: 1; min-height: 0;
}
#daily-panel > .summary-grid { align-self: stretch; flex-shrink: 0; }
.daily-statistics-card, .stock-statistics-card {
  display: flex; flex-direction: column; min-height: 0;
}
.daily-statistics-card > .table-head, .stock-statistics-card > .table-head { flex-shrink: 0; }
.daily-statistics-card > .table-scroll, .stock-statistics-card > .table-scroll {
  min-height: 0; max-height: none;
}
.stock-statistics-head { position: relative; min-height: 41px; padding: 4px 7px; justify-content: center; }
.stock-statistics-title { color: var(--text); font-size: 13px; font-weight: 750; }
.stock-statistics-filter { top: 6px; }
.stock-statistics-table {
  width: auto; min-width: 0; max-width: none;
  --stock-group-line: rgba(129, 151, 179, .38);
}
.stock-statistics-table col.stat-date { width: 90px; }
.stock-statistics-table col.stat-close { width: 64px; }
.stock-statistics-table col.stat-net { width: 82px; }
.stock-statistics-table col.stat-pct { width: 70px; }
.stock-statistics-table th {
  padding: 8px 6px; font-size: 14px; font-weight: 600;
  text-transform: none; letter-spacing: 0;
}
.stock-statistics-table thead tr:first-child th { top: 0; height: 34px; }
.stock-statistics-table thead tr:first-child th[colspan] {
  color: var(--text); background: #202b38; text-align: center;
  box-shadow: inset 1px 0 0 var(--stock-group-line);
}
.stock-statistics-table thead tr:nth-child(2) th { top: 34px; }
.stock-statistics-table thead tr:nth-child(2) th:nth-child(odd) {
  box-shadow: inset 1px 0 0 var(--stock-group-line);
}
.stock-statistics-table thead th[rowspan] { vertical-align: middle; }
.stock-statistics-table td { padding: 5px 6px; font-size: 15px; }
.stock-statistics-table td:nth-child(4),
.stock-statistics-table td:nth-child(6),
.stock-statistics-table td:nth-child(8),
.stock-statistics-table td:nth-child(10),
.stock-statistics-table td:nth-child(12) {
  box-shadow: inset 1px 0 0 var(--stock-group-line);
}
.stock-statistics-table td:first-child { color: inherit; font-size: 14px; font-weight: 400; }
.no-data { padding: 38px 12px; color: var(--muted); text-align: center !important; }
.security-note { margin: 14px 2px 0; color: var(--quiet); font-size: 11px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: min(430px, calc(100vw - 32px)); padding: 12px 15px; color: white; background: #253242; border: 1px solid #43546a; border-radius: 9px; box-shadow: 0 16px 42px rgba(0, 0, 0, .35); }
.toast.error { background: #6d292d; border-color: #ad444b; }

@media (max-width: 1050px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .minute-table-layout { grid-template-columns: minmax(0, max-content) 190px; }
  .minute-market-card { width: 100%; }
}
@media (max-width: 720px) {
  main { padding: 20px 10px 46px; }
  .topbar { padding-inline: 12px; }
  .session-actions > span { display: none; }
  .dashboard-head { align-items: stretch; flex-direction: column; }
  .connection-state { align-self: flex-start; }
  .data-tabs { width: 100%; }
  .data-tab { flex: 1; min-width: 96px; padding-inline: 8px; font-size: 12px; }
  .summary-grid, .summary-grid.stock-summary { grid-template-columns: repeat(2, 1fr); }
  .summary-card:last-child { grid-column: 1 / -1; }
  .table-head { align-items: flex-start; flex-direction: column; }
  .minute-compact-head, .stock-statistics-head { align-items: center; flex-direction: row; }
  .table-head .table-head-actions { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .minute-table-layout { display: block; }
  .minute-stock-card { width: min(190px, 100%); margin: 10px 0 0; }
  .table-scroll { max-height: calc(100vh - 360px); }
  td { font-size: 14px; }
}
