/* Stock Quant Web — light editorial fintech theme */

:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --card-2: #f7f9fd;
  --line: #e4e8f2;
  --line-strong: #d3d9e8;
  --ink: #182136;
  --ink-2: #3f4a66;
  --muted: #8791a9;
  --accent: #3155d8;
  --accent-ink: #2445b8;
  --accent-soft: #edf1fe;
  --up: #d9314f;      /* A股红涨/买入 */
  --down: #0d9c72;    /* 绿跌/卖出 */
  --avg: #c07c0e;
  --warn: #b45309;
  --shadow-sm: 0 1px 2px rgba(24, 33, 54, 0.06);
  --shadow: 0 1px 2px rgba(24, 33, 54, 0.05), 0 12px 32px -14px rgba(24, 33, 54, 0.14);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

body {
  position: relative;
  overflow-x: hidden;
}

::selection {
  background: color-mix(in oklab, var(--accent) 22%, transparent);
}

.app-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(820px 420px at 8% -6%, rgba(49, 85, 216, 0.07), transparent 60%),
    radial-gradient(700px 380px at 96% -4%, rgba(13, 156, 114, 0.05), transparent 55%),
    linear-gradient(180deg, #f6f8fc 0%, var(--bg) 260px);
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, #ffffff 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--accent), #6f8df1 65%, #0d9c72 130%);
  box-shadow: 0 6px 16px -6px rgba(49, 85, 216, 0.55);
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 10px 8px;
  border-radius: 3px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.95);
  border-left: 2px solid transparent;
  border-right: 2px solid transparent;
  transform: skewX(-12deg);
}

.brand h1 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-sub {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.top-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid color-mix(in oklab, var(--down) 35%, var(--line));
  background: color-mix(in oklab, var(--down) 7%, #ffffff);
  color: color-mix(in oklab, var(--down) 80%, black);
}

.pill.live::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--down);
  animation: pulse 1.8s var(--ease) infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(13, 156, 114, 0.4); }
  70% { box-shadow: 0 0 0 7px rgba(13, 156, 114, 0); }
  100% { box-shadow: 0 0 0 0 rgba(13, 156, 114, 0); }
}

.meta-time {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 0.82rem;
}

/* ---------- Layout ---------- */

.wrap {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 28px 8px;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  animation: rise 0.5s var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head h2,
.chart-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: 0.01em;
}

.card-head h2::before,
.chart-head h2::before {
  content: "";
  width: 4px;
  height: 15px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--accent), #7fa0f5);
}

.hint {
  color: var(--muted);
  font-size: 0.74rem;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 14px;
}

.tb-field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.tb-field > label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.tb-code { flex: 1 1 190px; max-width: 260px; }
.tb-custom { flex: 0 1 150px; }

.tb-dates {
  display: flex;
  gap: 10px;
  transition: opacity 0.2s var(--ease);
}

.tb-dates.is-disabled {
  opacity: 0.4;
  pointer-events: none;
}

.tb-run {
  margin-left: auto;
  align-self: flex-end;
}

input,
select {
  width: 100%;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

input:hover,
select:hover {
  border-color: color-mix(in oklab, var(--accent) 38%, var(--line-strong));
}

input:focus-visible,
select:focus-visible,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 16%, transparent);
}

input[type="date"] {
  color-scheme: light;
  font-family: var(--mono);
  font-size: 0.82rem;
}

select {
  cursor: pointer;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  height: 40px;
  padding: 0 16px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s var(--ease), filter 0.2s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn.primary {
  background: linear-gradient(180deg, #3e63e8, var(--accent-ink));
  color: #ffffff;
  min-width: 118px;
  box-shadow: 0 8px 18px -6px rgba(49, 85, 216, 0.5);
}

.btn.primary:hover { filter: brightness(1.06); }

.btn.primary:disabled,
.btn.primary.is-loading {
  opacity: 0.7;
  cursor: wait;
  filter: none;
}

.btn.ghost {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--ink-2);
  height: 32px;
  padding: 0 12px;
  font-size: 0.8rem;
}

.btn.ghost:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  display: none; /* default hidden — [hidden] alone loses to display:inline-block */
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-left: 8px;
}

.btn-spinner.is-on,
.btn.primary.is-loading .btn-spinner {
  display: inline-block;
}

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

/* ---------- Toolbar foot: chips + rules ---------- */

.toolbar-foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 18px;
}

.hot-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1 1 480px;
}

.chip {
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--ink-2);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s, background 0.18s, box-shadow 0.18s;
}

.chip:hover,
.chip.active {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 10%, transparent);
}

.rules {
  flex: 0 1 auto;
  max-width: 560px;
  font-size: 0.78rem;
  color: var(--muted);
}

.rules summary {
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 600;
  font-size: 0.78rem;
  user-select: none;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--card-2);
  transition: border-color 0.18s, color 0.18s;
}

.rules summary::-webkit-details-marker { display: none; }

.rules summary::before {
  content: "?";
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}

.rules summary:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.rules[open] summary {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.rules ul {
  margin: 10px 0 0;
  padding: 10px 12px 10px 28px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-2);
  line-height: 1.6;
}

.rules li { margin: 2px 0; }
.rules .buy { color: var(--up); }
.rules .sell { color: var(--down); }
.rules em { color: var(--ink-2); font-style: normal; font-weight: 600; }

/* ---------- Quote strip ---------- */

.quote-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 26px;
  padding: 12px 16px;
  margin-bottom: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, var(--accent-soft) 0%, #ffffff 45%);
}

.qs-id { min-width: 120px; }

.quote-name {
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.2;
}

.quote-code {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
}

.qs-price { text-align: left; }

.quote-price {
  font-family: var(--mono);
  font-size: 1.7rem;
  font-weight: 650;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.quote-chg {
  font-family: var(--mono);
  font-size: 0.82rem;
  margin-top: 2px;
}

.qs-metrics {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
}

.qs-metrics div {
  display: grid;
  gap: 1px;
  min-width: 64px;
}

.qs-metrics span {
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.03em;
}

.qs-metrics b {
  font-family: var(--mono);
  font-weight: 550;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--ink-2); }

/* ---------- Chart ---------- */

.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 12px;
}

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px 16px;
  flex: 1;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 0.75rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
  background: var(--accent);
}

.swatch.avg { background: var(--avg); }

.swatch.buy,
.swatch.sell {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.swatch.buy { background: var(--up); }
.swatch.sell { background: var(--down); }

.zoom-btns {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.zoom-hint {
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
  margin-left: 4px;
}

.chart-wrap {
  position: relative;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  overflow: hidden;
  min-height: 380px;
}

#chart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 380px;
  cursor: crosshair;
}

.chart-wrap.is-zoomable #chart { cursor: grab; }
.chart-wrap.is-zoomable.is-dragging #chart,
.chart-wrap.is-dragging { cursor: grabbing; }

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.9rem;
  pointer-events: none;
  padding: 24px;
  text-align: center;
}

.chart-empty.hidden { display: none; }

.tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 168px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 10px 28px -8px rgba(24, 33, 54, 0.25);
  font-size: 0.78rem;
  color: var(--ink-2);
  transform: translate(-20%, -110%);
}

.tooltip b {
  color: var(--ink);
  font-family: var(--mono);
  font-weight: 550;
}

.tooltip b.up { color: var(--up); }
.tooltip b.down { color: var(--down); }

.tooltip .row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 3px 0;
}

.status-bar {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px dashed var(--line-strong);
  background: var(--card-2);
  color: var(--muted);
  font-size: 0.76rem;
  font-family: var(--mono);
}

/* ---------- Results row: KPI / compare / days ---------- */

.results-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 16px;
  align-items: start;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.stat {
  position: relative;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card-2);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.stat:hover {
  border-color: color-mix(in oklab, var(--accent) 35%, var(--line));
  box-shadow: var(--shadow-sm);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}

.stat b {
  font-family: var(--mono);
  font-size: 1.22rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.open-pos {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px dashed color-mix(in oklab, var(--warn) 45%, transparent);
  background: color-mix(in oklab, var(--warn) 7%, #ffffff);
  color: var(--ink-2);
  font-size: 0.82rem;
}

.open-pos strong {
  color: var(--warn);
  font-family: var(--mono);
}

/* Compare */

.compare-card {
  border-color: color-mix(in oklab, var(--accent) 26%, var(--line));
  background: linear-gradient(160deg, var(--accent-soft) 0%, #ffffff 55%);
}

.compare-title { white-space: nowrap; }

.compare-sub { white-space: normal; }

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

.compare-item {
  padding: 11px 12px 10px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #ffffff;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.compare-item-excess {
  border-color: color-mix(in oklab, var(--accent) 45%, var(--line));
  background: var(--accent-soft);
}

.compare-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.compare-item b {
  font-family: var(--mono);
  font-size: 1.24rem;
  font-weight: 650;
  line-height: 1.25;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.compare-item small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

/* Day list */

.day-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 8px;
  font-size: 0.76rem;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.day-list .day-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 4px 8px;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card-2);
  font-family: var(--mono);
  min-width: 0;
}

.day-list .day-date {
  color: var(--ink-2);
  white-space: nowrap;
  font-size: 0.74rem;
}

.day-list .day-meta {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.68rem;
}

.day-list .day-pnl {
  font-weight: 650;
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- Trades table ---------- */

.table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  max-height: 560px;
}

.trades-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
  font-size: 0.85rem;
}

.trades-table th,
.trades-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.trades-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.trades-table tbody tr {
  transition: background 0.12s var(--ease);
}

.trades-table tbody tr:nth-child(even) {
  background: #fafbfe;
}

.trades-table tbody tr:hover {
  background: var(--accent-soft);
}

.trades-table td {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.trades-table td.up { color: var(--up); }
.trades-table td.down { color: var(--down); }

.trades-table .empty-row td {
  text-align: center;
  color: var(--muted);
  font-family: var(--font);
  padding: 30px 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-family: var(--font);
  border: 1px solid transparent;
}

.badge.closed {
  color: var(--ink-2);
  border-color: var(--line-strong);
  background: var(--card-2);
}

/* ---------- Footer & toast ---------- */

.footer {
  max-width: 1440px;
  margin: 0 auto;
  padding: 8px 28px 26px;
  color: color-mix(in oklab, var(--muted) 85%, transparent);
  font-size: 0.72rem;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid color-mix(in oklab, var(--up) 35%, var(--line));
  background: #fff6f7;
  color: #8f2137;
  font-size: 0.84rem;
  box-shadow: var(--shadow);
  animation: rise 0.3s var(--ease);
}

/* ---------- Scrollbars ---------- */

.day-list::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.day-list::-webkit-scrollbar-track,
.table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.day-list::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 999px;
}

.day-list::-webkit-scrollbar-thumb:hover,
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: color-mix(in oklab, var(--muted) 55%, transparent);
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .wrap { padding: 16px 16px 6px; }
  .topbar-inner { padding: 10px 16px; }
  .footer { padding: 6px 16px 22px; }
  .brand-sub { display: none; }
  .tb-run { margin-left: 0; flex: 1 1 100%; }
  .qs-metrics { margin-left: 0; }
  .compare-grid { grid-template-columns: 1fr; }
  .day-list { max-height: 280px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
