/* ============ Design tokens ============ */
:root {
  --c-bg: #070a0f;
  --c-bg-soft: #0a0e15;
  --c-surface: #0f141d;
  --c-surface-2: #131a25;
  --c-surface-3: #1a2231;
  --c-primary: #e3b558;
  --c-primary-strong: #c8953a;
  --c-primary-soft: rgba(227, 181, 88, 0.12);
  --c-text: #e8ecf4;
  --c-text-2: #98a2b6;
  --c-text-3: #5d687c;
  --c-border: rgba(255, 255, 255, 0.07);
  --c-border-strong: rgba(255, 255, 255, 0.13);
  --c-up: #f3575f;
  --c-up-soft: rgba(243, 87, 95, 0.12);
  --c-down: #2ebd8e;
  --c-down-soft: rgba(46, 189, 142, 0.12);
  --c-info: #6aa9ff;
  --c-danger: #f3575f;
  --c-warn: #e3b558;
  --c-success: #2ebd8e;

  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
    "Segoe UI", "Noto Sans SC", sans-serif;
  --font-num: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;

  --t-xs: 11px;
  --t-sm: 12.5px;
  --t-base: 14px;
  --t-md: 16px;
  --t-lg: 20px;
  --t-xl: 27px;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  --shadow-primary: 0 6px 20px rgba(227, 181, 88, 0.22);

  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  --dur-fast: 150ms;
  --dur-base: 220ms;

  --sidebar-w: 216px;
  --topbar-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: var(--t-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 480px at 78% -10%, rgba(227, 181, 88, 0.06), transparent 60%),
    radial-gradient(700px 420px at 6% 110%, rgba(106, 169, 255, 0.04), transparent 65%);
  z-index: 0;
}

button, input, select { font-family: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--c-primary); text-decoration: none; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }
::-webkit-scrollbar-track { background: transparent; }

.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.up { color: var(--c-up); }
.down { color: var(--c-down); }
.warn { color: var(--c-warn); }
.muted { color: var(--c-text-2); }
.dim { color: var(--c-text-3); }
.hidden { display: none !important; }

/* ============ Shell ============ */
.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  padding: var(--s-5) var(--s-3) var(--s-4);
  border-right: 1px solid var(--c-border);
  background: linear-gradient(180deg, rgba(15, 20, 29, 0.9), rgba(8, 11, 16, 0.95));
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-2); }
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 15px;
  color: #191207;
  background: linear-gradient(145deg, #f0cd8a, #c8953a);
  box-shadow: 0 4px 14px rgba(227, 181, 88, 0.28);
}
.brand-name { font-size: var(--t-base); font-weight: 600; letter-spacing: 0.04em; }
.brand-sub { font-size: var(--t-xs); color: var(--c-text-3); letter-spacing: 0.12em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: var(--s-1); }
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: 40px;
  padding: 0 var(--s-3);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--c-text-2);
  font-size: var(--t-sm);
  text-align: left;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.nav-item svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.6; flex: none; }
.nav-item:hover { color: var(--c-text); background: rgba(255, 255, 255, 0.03); }
.nav-item.active {
  color: var(--c-primary);
  background: var(--c-primary-soft);
  border-color: rgba(227, 181, 88, 0.18);
  font-weight: 500;
}
.nav-item .nav-extra { margin-left: auto; font-size: var(--t-xs); color: var(--c-text-3); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--s-2); padding: 0 var(--s-2); }
.source-chip {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
  font-size: var(--t-xs);
  color: var(--c-text-2);
}
.source-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--c-success); box-shadow: 0 0 0 3px rgba(46, 189, 142, 0.12); }
.source-chip .dot.warn { background: var(--c-warn); box-shadow: 0 0 0 3px rgba(227, 181, 88, 0.12); }
.source-chip .dot.err { background: var(--c-danger); box-shadow: 0 0 0 3px rgba(243, 87, 95, 0.12); }
.source-note { font-size: 10.5px; color: var(--c-text-3); line-height: 1.5; }

.main { overflow-y: auto; overflow-x: hidden; height: 100dvh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: 0 var(--s-6);
  border-bottom: 1px solid var(--c-border);
  background: rgba(7, 10, 15, 0.78);
  backdrop-filter: blur(16px);
}
.page-head { display: flex; align-items: baseline; gap: var(--s-3); min-width: 0; }
.page-title { font-size: var(--t-md); font-weight: 600; letter-spacing: 0.01em; }
.page-sub { font-size: var(--t-xs); color: var(--c-text-3); white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: var(--s-4); }

.market-pill {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 5px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-full);
  background: var(--c-surface);
  font-size: var(--t-xs);
  color: var(--c-text-2);
}
.market-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--c-text-3); }
.market-pill.open .dot { background: var(--c-success); animation: pulse 2.4s infinite; }
.market-pill.break .dot { background: var(--c-warn); }
.market-pill .clock { font-family: var(--font-num); color: var(--c-text); }

.mini-account { display: flex; align-items: baseline; gap: var(--s-2); font-size: var(--t-xs); color: var(--c-text-3); }
.mini-account strong { font-family: var(--font-num); font-size: var(--t-base); font-weight: 600; color: var(--c-text); }
.mini-account .delta { font-family: var(--font-num); font-size: var(--t-xs); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
  color: var(--c-text-2);
  font-size: var(--t-sm);
  transition: all var(--dur-fast) var(--ease);
}
.icon-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.icon-btn:hover { color: var(--c-text); border-color: var(--c-border-strong); }
.icon-btn:active { transform: scale(0.97); }
.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }

.content { padding: var(--s-5) var(--s-6) var(--s-10); max-width: 1560px; margin: 0 auto; }

/* ============ Banner ============ */
.banner {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin: 0 var(--s-6);
  margin-top: var(--s-4);
  padding: 10px 14px;
  border: 1px solid rgba(227, 181, 88, 0.22);
  border-radius: var(--r-md);
  background: rgba(227, 181, 88, 0.07);
  color: #f0d39a;
  font-size: var(--t-sm);
}
.banner svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; flex: none; }

/* ============ Cards & grids ============ */
.view { display: none; }
.view.active { display: block; animation: fadeUp 0.32s var(--ease) both; }

.grid { display: grid; gap: var(--s-4); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.split-2 { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

.card {
  position: relative;
  padding: var(--s-5);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--c-surface-2), var(--c-surface));
  box-shadow: var(--shadow-sm);
}
.card.flush { padding: 0; overflow: hidden; }
.card.pad-sm { padding: var(--s-4); }
.card-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.card-title { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-sm); font-weight: 600; letter-spacing: 0.02em; color: var(--c-text); }
.card-title .mark { width: 3px; height: 13px; border-radius: var(--r-full); background: var(--c-primary); }
.card-title .sub { font-weight: 400; color: var(--c-text-3); font-size: var(--t-xs); letter-spacing: 0; }
.card-extra { font-size: var(--t-xs); color: var(--c-text-3); }

/* ============ Index cards ============ */
.index-card { padding: var(--s-4) var(--s-5); min-height: 130px; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.index-name { font-size: var(--t-sm); color: var(--c-text-2); display: flex; align-items: center; gap: var(--s-2); }
.index-name .tag { font-size: 10px; padding: 1px 6px; border-radius: var(--r-full); background: rgba(255, 255, 255, 0.05); color: var(--c-text-3); }
.index-price { font-family: var(--font-num); font-size: 25px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.index-meta { display: flex; align-items: center; gap: var(--s-2); font-family: var(--font-num); font-size: var(--t-sm); }
.index-stats { display: flex; gap: 12px; margin-top: auto; padding-top: 8px; font-size: 10.5px; color: var(--c-text-3); border-top: 1px solid rgba(255, 255, 255, 0.04); }
.index-stats b { font-family: var(--font-num); font-weight: 500; color: var(--c-text-2); }
.index-spark { position: absolute; right: 0; bottom: 0; width: 45%; height: 54px; opacity: 0.85; pointer-events: none; }
.index-spark-note { position: absolute; right: var(--s-5); bottom: var(--s-4); font-size: 10px; color: var(--c-text-3); opacity: 0.75; }

/* ============ Sentiment ============ */
.sentiment-card { display: flex; flex-direction: column; gap: var(--s-3); }
.sentiment-top { display: flex; align-items: flex-end; justify-content: space-between; }
.sentiment-value { font-family: var(--font-num); font-size: var(--t-xl); font-weight: 600; line-height: 1.1; }
.sentiment-sign { font-size: var(--t-xs); color: var(--c-warn); background: var(--c-primary-soft); border-radius: var(--r-full); padding: 2px 8px; }
.breadth-bar { display: flex; height: 6px; border-radius: var(--r-full); overflow: hidden; background: rgba(255, 255, 255, 0.06); }
.breadth-bar .up-part { background: linear-gradient(90deg, #c9474f, var(--c-up)); }
.breadth-bar .down-part { background: linear-gradient(90deg, var(--c-down), #1d8f6c); }
.breadth-legend { display: flex; justify-content: space-between; font-size: var(--t-xs); color: var(--c-text-2); }
.breadth-legend b { font-family: var(--font-num); font-weight: 600; }
.sentiment-stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }
.sentiment-stat { padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); background: rgba(255, 255, 255, 0.03); border: 1px solid var(--c-border); }
.sentiment-stat span { display: block; font-size: var(--t-xs); color: var(--c-text-3); }
.sentiment-stat strong { font-family: var(--font-num); font-size: var(--t-md); font-weight: 600; }

/* ============ Tables ============ */
.tbl-wrap { overflow: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.tbl th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px var(--s-3);
  text-align: right;
  font-weight: 500;
  font-size: var(--t-xs);
  color: var(--c-text-3);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
.tbl th:first-child, .tbl td:first-child { text-align: left; padding-left: var(--s-5); }
.tbl th:last-child, .tbl td:last-child { padding-right: var(--s-5); }
.tbl td {
  padding: 10px var(--s-3);
  text-align: right;
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
  white-space: nowrap;
}
.tbl tbody tr { transition: background var(--dur-fast) var(--ease); }
.tbl tbody tr:hover { background: rgba(255, 255, 255, 0.028); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .num { font-size: var(--t-sm); }
.tbl .code { font-family: var(--font-num); color: var(--c-text-3); font-size: var(--t-xs); }
.stock-cell { display: flex; flex-direction: column; gap: 1px; text-align: left; }
.stock-cell .name { font-weight: 500; color: var(--c-text); }
.stock-cell .code { font-size: 10.5px; color: var(--c-text-3); }
.stock-cell .name button { background: none; border: 0; padding: 0; color: inherit; font: inherit; }
.stock-cell .name button:hover { color: var(--c-primary); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: var(--r-full);
  font-size: 10.5px;
  line-height: 1.6;
  background: rgba(255, 255, 255, 0.055);
  color: var(--c-text-2);
  white-space: nowrap;
}
.tag.gold { background: var(--c-primary-soft); color: var(--c-primary); }
.tag.up { background: var(--c-up-soft); color: var(--c-up); }
.tag.down { background: var(--c-down-soft); color: var(--c-down); }
.tag.info { background: rgba(106, 169, 255, 0.12); color: var(--c-info); }
.tag.dim { color: var(--c-text-3); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 var(--s-4);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: var(--t-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.9; }
.btn-primary { background: linear-gradient(160deg, #efc874, var(--c-primary)); color: #1b1204; box-shadow: var(--shadow-primary); }
.btn-primary:hover { background: linear-gradient(160deg, #f3d38d, #e0b04e); }
.btn-primary:disabled { opacity: 0.45; box-shadow: none; cursor: not-allowed; transform: none; }
.btn-ghost { background: var(--c-surface-2); border-color: var(--c-border); color: var(--c-text-2); }
.btn-ghost:hover { color: var(--c-text); border-color: var(--c-border-strong); }
.btn-soft { background: var(--c-primary-soft); color: var(--c-primary); }
.btn-soft:hover { background: rgba(227, 181, 88, 0.18); }
.btn-buy { background: var(--c-up); color: #fff; }
.btn-buy:hover { background: #f76c73; }
.btn-sell { background: var(--c-down); color: #06241b; }
.btn-sell:hover { background: #45d0a2; }
.btn-danger-ghost { background: transparent; border-color: rgba(243, 87, 95, 0.35); color: var(--c-danger); }
.btn-danger-ghost:hover { background: var(--c-up-soft); }
.btn-sm { height: 28px; padding: 0 10px; font-size: var(--t-xs); border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ============ Forms ============ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: var(--t-xs); color: var(--c-text-2); display: flex; justify-content: space-between; }
.field-label .hint { color: var(--c-text-3); font-family: var(--font-num); }
.input, .select {
  width: 100%;
  height: 38px;
  padding: 0 var(--s-3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.22);
  color: var(--c-text);
  font-size: var(--t-sm);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder { color: var(--c-text-3); }
.input:focus, .select:focus {
  outline: none;
  border-color: rgba(227, 181, 88, 0.55);
  box-shadow: 0 0 0 3px rgba(227, 181, 88, 0.1);
}
.input.num { font-family: var(--font-num); }
.select { appearance: none; cursor: pointer; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute;
  right: 13px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--c-text-3);
  border-bottom: 1.5px solid var(--c-text-3);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: rgba(0, 0, 0, 0.24); border: 1px solid var(--c-border); border-radius: var(--r-md); }
.segmented button {
  border: 0;
  background: transparent;
  color: var(--c-text-2);
  font-size: var(--t-xs);
  padding: 5px 11px;
  border-radius: 7px;
  white-space: nowrap;
  transition: all var(--dur-fast) var(--ease);
}
.segmented button:hover { color: var(--c-text); }
.segmented button.active { background: var(--c-surface-3); color: var(--c-text); box-shadow: var(--shadow-sm); }
.segmented.buy-sell button.active.buy { background: var(--c-up-soft); color: var(--c-up); }
.segmented.buy-sell button.active.sell { background: var(--c-down-soft); color: var(--c-down); }

.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.1);
  transition: background var(--dur-base) var(--ease);
  cursor: pointer;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #9aa4b6;
  transition: all var(--dur-base) var(--ease);
}
.switch input:checked + .track { background: rgba(227, 181, 88, 0.9); }
.switch input:checked + .track::after { transform: translateX(18px); background: #1b1204; }

.slider { width: 100%; accent-color: var(--c-primary); }

/* ============ KPI ============ */
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi-label { font-size: var(--t-xs); color: var(--c-text-3); }
.kpi-value { font-family: var(--font-num); font-size: var(--t-xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; }
.kpi-sub { font-size: var(--t-xs); color: var(--c-text-3); display: flex; gap: 6px; align-items: center; }
.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-4); }

/* ============ Layout: trade ============ */
.trade-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr) 300px; gap: var(--s-4); align-items: start; }
.stock-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-4) var(--s-5); }
.stock-title { display: flex; flex-direction: column; gap: 2px; }
.stock-title .name { font-size: var(--t-lg); font-weight: 600; letter-spacing: 0.01em; }
.stock-title .meta { display: flex; gap: var(--s-2); font-size: var(--t-xs); color: var(--c-text-3); font-family: var(--font-num); }
.stock-price { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.stock-price .last { font-family: var(--font-num); font-size: 30px; font-weight: 600; line-height: 1.15; letter-spacing: -0.02em; }
.stock-price .delta { font-family: var(--font-num); font-size: var(--t-sm); }
.quote-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-2) var(--s-4); padding: 0 var(--s-5) var(--s-4); }
.quote-grid .q { display: flex; justify-content: space-between; font-size: var(--t-xs); color: var(--c-text-3); }
.quote-grid .q b { font-family: var(--font-num); font-weight: 500; color: var(--c-text-2); }

.chart-shell { position: relative; padding: 0 var(--s-3) var(--s-2); }
.chart-canvas { width: 100%; display: block; }
.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 132px;
  padding: 8px 10px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  background: rgba(10, 14, 21, 0.94);
  box-shadow: var(--shadow-md);
  font-size: var(--t-xs);
  pointer-events: none;
  backdrop-filter: blur(8px);
}
.chart-tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; color: var(--c-text-2); font-family: var(--font-num); }
.chart-tooltip .tt-date { color: var(--c-text-3); margin-bottom: 3px; font-family: var(--font-num); }

.chart-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: 0 var(--s-5) var(--s-2); flex-wrap: wrap; }
.legend { display: flex; gap: var(--s-3); font-size: var(--t-xs); color: var(--c-text-3); font-family: var(--font-num); flex-wrap: wrap; }
.legend span { white-space: nowrap; }
.legend i { display: inline-block; width: 8px; height: 2px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* watchlist */
.watch-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s-2);
  align-items: center;
  padding: 9px var(--s-3);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.watch-item:hover { background: rgba(255, 255, 255, 0.035); }
.watch-item.active { background: var(--c-primary-soft); }
.watch-item .w-name { font-size: var(--t-sm); font-weight: 500; }
.watch-item .w-code { font-size: 10.5px; color: var(--c-text-3); font-family: var(--font-num); }
.watch-item .w-price { text-align: right; font-family: var(--font-num); font-size: var(--t-sm); }
.watch-item .w-pct { text-align: right; font-family: var(--font-num); font-size: 10.5px; }
.watch-head { padding: 0 var(--s-3) var(--s-2); font-size: var(--t-xs); color: var(--c-text-3); display: flex; justify-content: space-between; }

/* order ticket */
.ticket { display: flex; flex-direction: column; gap: var(--s-4); }
.ticket-summary { border: 1px solid var(--c-border); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); background: rgba(0, 0, 0, 0.18); display: flex; flex-direction: column; gap: 6px; }
.ticket-line { display: flex; justify-content: space-between; font-size: var(--t-xs); color: var(--c-text-3); }
.ticket-line b { font-family: var(--font-num); font-weight: 500; color: var(--c-text-2); }
.ticket-line.total b { color: var(--c-text); font-size: var(--t-sm); }
.quick-pct { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.quick-pct button {
  height: 28px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text-2);
  font-size: var(--t-xs);
  transition: all var(--dur-fast) var(--ease);
}
.quick-pct button:hover { border-color: rgba(227, 181, 88, 0.4); color: var(--c-primary); }
.quick-pct button.active { background: var(--c-primary-soft); color: var(--c-primary); border-color: rgba(227, 181, 88, 0.35); }
.avail-line { font-size: var(--t-xs); color: var(--c-text-3); display: flex; justify-content: space-between; }
.avail-line b { font-family: var(--font-num); color: var(--c-text-2); font-weight: 500; }
.position-hint { font-size: var(--t-xs); color: var(--c-text-3); line-height: 1.6; padding: 8px 10px; border-radius: var(--r-sm); background: rgba(106, 169, 255, 0.06); border: 1px solid rgba(106, 169, 255, 0.12); }

/* tabs */
.tabs { display: flex; gap: var(--s-5); border-bottom: 1px solid var(--c-border); padding: 0 var(--s-5); }
.tabs button {
  padding: 11px 0;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--c-text-3);
  font-size: var(--t-sm);
  transition: color var(--dur-fast) var(--ease);
}
.tabs button:hover { color: var(--c-text-2); }
.tabs button.active { color: var(--c-text); border-bottom-color: var(--c-primary); }
.tabs .count { font-family: var(--font-num); font-size: 10px; color: var(--c-text-3); margin-left: 4px; }

/* strategy cards */
.strategy-list { display: flex; flex-direction: column; gap: 6px; }
.strategy-opt {
  text-align: left;
  padding: 10px var(--s-3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: transparent;
  transition: all var(--dur-fast) var(--ease);
}
.strategy-opt:hover { border-color: var(--c-border-strong); background: rgba(255, 255, 255, 0.02); }
.strategy-opt.active { border-color: rgba(227, 181, 88, 0.45); background: var(--c-primary-soft); }
.strategy-opt .s-name { font-size: var(--t-sm); font-weight: 500; display: flex; align-items: center; justify-content: space-between; }
.strategy-opt .s-desc { font-size: 10.5px; color: var(--c-text-3); margin-top: 2px; line-height: 1.5; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 9px;
  border-radius: var(--r-full);
  background: var(--c-surface-3);
  border: 1px solid var(--c-border);
  font-size: var(--t-xs);
  color: var(--c-text-2);
}
.chip button { border: 0; background: none; color: var(--c-text-3); padding: 0 3px; font-size: 13px; line-height: 1; }
.chip button:hover { color: var(--c-danger); }

/* signals */
.signal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px 64px auto;
  gap: 4px var(--s-3);
  align-items: center;
  padding: 10px var(--s-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
  font-size: var(--t-sm);
}
.signal-row:last-child { border-bottom: 0; }
.signal-badge { display: inline-flex; justify-content: center; padding: 2px 8px; border-radius: var(--r-full); font-size: 10.5px; font-weight: 500; }
.signal-badge.BUY { background: var(--c-up-soft); color: var(--c-up); }
.signal-badge.SELL { background: var(--c-down-soft); color: var(--c-down); }
.signal-badge.HOLD { background: rgba(255, 255, 255, 0.05); color: var(--c-text-3); }
.signal-badge.ERROR { background: rgba(243, 87, 95, 0.1); color: var(--c-danger); }
.signal-reason { grid-column: 1 / -1; font-size: var(--t-xs); color: var(--c-text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.log-list { display: flex; flex-direction: column; max-height: 300px; overflow: auto; }
.log-item { display: flex; gap: var(--s-3); padding: 8px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.04); font-size: var(--t-xs); }
.log-item:last-child { border-bottom: 0; }
.log-item time { color: var(--c-text-3); font-family: var(--font-num); white-space: nowrap; }
.log-item .log-act { color: var(--c-primary); font-weight: 500; }
.log-item .log-act.SELL { color: var(--c-down); }
.log-item .log-act.ERROR { color: var(--c-danger); }
.log-item .log-text { color: var(--c-text-2); }

/* account */
.curve-card { padding-bottom: var(--s-2); }
.donut-wrap { display: flex; align-items: center; gap: var(--s-5); }
.donut-legend { display: flex; flex-direction: column; gap: var(--s-2); flex: 1; min-width: 0; }
.donut-legend .dl { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-xs); color: var(--c-text-2); }
.donut-legend .dl i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.donut-legend .dl b { margin-left: auto; font-family: var(--font-num); color: var(--c-text); font-weight: 500; }

/* backtest */
.bt-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: var(--s-4); align-items: start; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--c-border); border: 1px solid var(--c-border); border-radius: var(--r-md); overflow: hidden; }
.metric { padding: var(--s-3) var(--s-4); background: var(--c-surface); }
.metric .m-label { font-size: var(--t-xs); color: var(--c-text-3); }
.metric .m-value { font-family: var(--font-num); font-size: var(--t-md); font-weight: 600; margin-top: 2px; }

/* skeleton */
.skeleton { position: relative; overflow: hidden; background: rgba(255, 255, 255, 0.05); border-radius: var(--r-sm); }
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  animation: shimmer 1.4s infinite;
}
.sk-line { height: 11px; margin-bottom: 9px; }
.sk-line.w40 { width: 40%; } .sk-line.w60 { width: 60%; } .sk-line.w80 { width: 80%; }
.sk-block { height: 90px; border-radius: var(--r-md); }

/* empty */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s-2); padding: var(--s-8) var(--s-4); text-align: center; }
.empty .emoji { font-size: 34px; opacity: 0.6; }
.empty .e-title { font-size: var(--t-sm); color: var(--c-text-2); font-weight: 500; }
.empty .e-desc { font-size: var(--t-xs); color: var(--c-text-3); max-width: 260px; line-height: 1.6; }
.empty .btn { margin-top: var(--s-2); }

/* toast */
#toast-root { position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--r-md);
  background: #e8ecf4;
  color: #10141b;
  font-size: var(--t-sm);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.24s var(--ease) both;
}
.toast.err { background: #f3575f; color: #fff; }
.toast.ok { background: #2ebd8e; color: #041f17; }
.toast.out { animation: toastOut 0.2s var(--ease) both; }

/* modal */
.modal-mask { position: fixed; inset: 0; z-index: 150; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: var(--s-4); animation: fade 0.18s var(--ease); }
.modal { width: 100%; max-width: 400px; padding: var(--s-5); border: 1px solid var(--c-border-strong); border-radius: var(--r-lg); background: var(--c-surface-2); box-shadow: var(--shadow-lg); animation: modalIn 0.22s var(--ease); }
.modal h3 { margin: 0 0 var(--s-2); font-size: var(--t-md); }
.modal p { margin: 0 0 var(--s-5); font-size: var(--t-sm); color: var(--c-text-2); line-height: 1.65; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s-2); }

/* search dropdown */
.search-wrap { position: relative; }
.search-drop {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  box-shadow: var(--shadow-lg);
}
.search-drop button { display: flex; width: 100%; justify-content: space-between; align-items: center; padding: 7px 10px; border: 0; border-radius: var(--r-sm); background: none; text-align: left; font-size: var(--t-sm); color: var(--c-text-2); }
.search-drop button:hover { background: rgba(255, 255, 255, 0.05); color: var(--c-text); }
.search-drop .sd-code { font-family: var(--font-num); font-size: var(--t-xs); color: var(--c-text-3); }
.search-drop .sd-empty { padding: 12px; font-size: var(--t-xs); color: var(--c-text-3); }

/* scroll areas */
.scroll-y { overflow-y: auto; }
.h-330 { max-height: 330px; }
.h-240 { max-height: 240px; }

/* animations */
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }

/* ============ Responsive ============ */
@media (max-width: 1440px) {
  .trade-layout { grid-template-columns: 230px minmax(0, 1fr) 280px; }
}
@media (max-width: 1280px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.split-2 { grid-template-columns: 1fr; }
  .trade-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .trade-layout .ticket-card { grid-column: 1 / -1; }
}
@media (max-width: 1080px) {
  .bt-layout { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  :root { --sidebar-w: 66px; }
  .brand-name, .brand-sub, .nav-item span, .source-note, .source-chip span { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .brand { justify-content: center; padding: 0; }
  .source-chip { justify-content: center; padding: var(--s-2); }
  .content { padding: var(--s-4); }
  .topbar { padding: 0 var(--s-4); }
  .trade-layout { grid-template-columns: 1fr; }
  .trade-layout .watch-card { order: 2; }
  .trade-layout .ticket-card { order: 3; }
  .page-sub { display: none; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; padding-bottom: 62px; }
  .sidebar { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 100; flex-direction: row; gap: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--c-border); background: rgba(10, 14, 21, 0.96); backdrop-filter: blur(14px); }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; justify-content: space-around; width: 100%; }
  .nav-item { flex-direction: column; gap: 2px; height: 48px; font-size: 10px; flex: 1; }
  .nav-item span { display: block; }
  .topbar { height: 54px; }
  .mini-account { display: none; }
  .grid.cols-3, .grid.cols-4, .grid.cols-2 { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .quote-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stock-header { flex-direction: column; align-items: flex-start; }
  .stock-price { align-items: flex-start; }
  .tabs { padding: 0 var(--s-4); gap: var(--s-4); }
  .signal-row { grid-template-columns: minmax(0, 1fr) 64px 64px auto; }
  .signal-row .signal-reason { display: none; }
  .content { padding: var(--s-3); }
  .card { padding: var(--s-4); }
}
