:root {
  color-scheme: light;
  --ink: #17201d;
  --muted: #64706b;
  --line: #dfe5e2;
  --line-strong: #cbd4d0;
  --surface: #ffffff;
  --surface-soft: #f5f7f6;
  --page: #eef2f0;
  --green: #087f5b;
  --green-soft: #e6f5ef;
  --red: #c73b4d;
  --red-soft: #fbeaec;
  --amber: #a66300;
  --amber-soft: #fff4dc;
  --blue: #2166b1;
  --shadow: 0 8px 24px rgba(25, 45, 37, 0.07);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.progress {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: var(--green);
  opacity: 0;
  transition: width 180ms ease, opacity 180ms ease;
}

.progress.active { width: 72%; opacity: 1; }
.progress.complete { width: 100%; opacity: 0; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
  background: var(--surface);
}
.auth-panel { width: min(100%, 390px); }
.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line-strong);
}
.auth-brand h1 { margin-top: 2px; font-size: 21px; }
.auth-form { display: grid; gap: 16px; padding-top: 24px; }
.auth-form .field { margin: 0; }
.auth-form .field input { height: 44px; }
.auth-form .button { height: 42px; margin-top: 2px; }
.signed-in-account {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.signed-in-account strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.form-error {
  margin: -4px 0 0;
  padding: 9px 10px;
  border-left: 3px solid var(--red);
  background: var(--red-soft);
  color: #922d3a;
  font-size: 12px;
}

.topbar {
  height: 76px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: white;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

h1, h2, p { margin: 0; }
h1 { font-size: 18px; line-height: 1.25; font-weight: 720; }
h2 { font-size: 17px; line-height: 1.3; font-weight: 700; }
.market-state { margin-top: 4px; color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

.top-actions { display: flex; align-items: center; gap: 8px; }
.button, .icon-button {
  border: 1px solid transparent;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.button { height: 38px; padding: 0 14px; font-weight: 650; }
.button svg, .icon-button svg { width: 16px; height: 16px; stroke-width: 2; }
.button.primary { background: var(--ink); color: white; }
.button.primary:hover { background: #2b3733; }
.button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.button.secondary:hover { background: var(--surface-soft); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }
.button.full { width: 100%; }
.icon-button { width: 34px; height: 34px; padding: 0; background: transparent; color: var(--muted); }
.icon-button:hover { background: var(--surface-soft); color: var(--ink); }
.icon-button.danger:hover { color: var(--red); background: var(--red-soft); }

main { width: min(1480px, calc(100% - 48px)); margin: 0 auto; padding-bottom: 48px; }

.summary-band {
  min-height: 78px;
  display: grid;
  grid-template-columns: 160px 160px 160px minmax(220px, 1fr);
  align-items: center;
  border-bottom: 1px solid var(--line-strong);
}
.metric { min-height: 42px; padding: 0 24px; border-left: 1px solid var(--line-strong); display: flex; flex-direction: column; justify-content: center; }
.metric:first-child { border-left: 0; padding-left: 0; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { margin-top: 3px; font-size: 21px; font-weight: 730; }
.metric.wide strong { font-size: 15px; }
.normal-text { color: var(--green); }
.alert-text { color: var(--red); }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; padding: 28px 0 0; }
.watchlist-section, .settings-section, .history-section { min-width: 0; }
.section-heading { min-height: 46px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-heading.compact { align-items: center; }
.eyebrow { color: var(--green); font-size: 10px; font-weight: 800; margin-bottom: 4px; }

.stock-search { position: relative; width: 280px; }
.stock-search > svg { position: absolute; left: 11px; top: 11px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.stock-search input { width: 100%; height: 38px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 12px 0 36px; background: var(--surface); color: var(--ink); outline: none; }
.stock-search input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.11); }
.search-results { position: absolute; z-index: 20; top: 43px; left: 0; right: 0; max-height: 300px; overflow-y: auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: var(--shadow); }
.search-option { width: 100%; min-height: 46px; border: 0; border-bottom: 1px solid var(--line); background: white; padding: 7px 12px; display: flex; justify-content: space-between; align-items: center; text-align: left; color: var(--ink); }
.search-option:last-child { border-bottom: 0; }
.search-option:hover { background: var(--green-soft); }
.search-option small { color: var(--muted); font-variant-numeric: tabular-nums; }

.table-tool, .settings-tool, .history-tool { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; box-shadow: var(--shadow); }
.watch-header, .watch-row { display: grid; grid-template-columns: minmax(170px, 1.6fr) 110px 118px 78px 88px 88px 40px; gap: 12px; align-items: center; }
.watch-header { min-height: 38px; padding: 0 14px; background: var(--surface-soft); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 700; }
.watch-row { min-height: 76px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.watch-row:last-child { border-bottom: 0; }
.stock-id { min-width: 0; }
.stock-name { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stock-code { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.quote-value, .rsi-value { font-variant-numeric: tabular-nums; }
.quote-value strong { display: block; font-size: 15px; }
.quote-value small { color: var(--muted); font-size: 11px; }
.rsi-value { display: flex; flex-direction: column; gap: 5px; }
.rsi-top { display: flex; justify-content: space-between; align-items: baseline; }
.rsi-top strong { font-size: 16px; }
.zone-label { font-size: 10px; font-weight: 750; }
.zone-label.normal { color: var(--green); }
.zone-label.below, .zone-label.above { color: var(--red); }
.rsi-track { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.rsi-fill { height: 100%; background: var(--green); border-radius: 2px; }
.rsi-fill.below, .rsi-fill.above { background: var(--red); }
.cell-input { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 5px; padding: 0 8px; color: var(--ink); background: white; outline: none; font-variant-numeric: tabular-nums; }
.cell-input:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(8, 127, 91, 0.1); }
.cell-input.invalid { border-color: var(--red); background: var(--red-soft); }

.connection-badge { border-radius: 4px; padding: 4px 7px; font-size: 11px; font-weight: 750; color: var(--amber); background: var(--amber-soft); }
.connection-badge.connected { color: var(--green); background: var(--green-soft); }
.settings-tool { padding: 18px; overflow: visible; }
.field { display: block; margin-bottom: 16px; }
.field > span, .setting-row > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .field select { width: 100%; height: 38px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 10px; background: white; color: var(--ink); outline: none; }
.field input:focus, .field select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.1); }
.setting-row { margin-bottom: 18px; }
.setting-row code { display: block; overflow-wrap: anywhere; padding: 9px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-soft); color: var(--blue); font-size: 11px; }
.zone-legend { margin-top: 14px; display: grid; gap: 8px; color: var(--muted); font-size: 11px; }
.zone-legend span { display: flex; align-items: center; gap: 7px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.legend-dot.low, .legend-dot.high { background: var(--red); }
.legend-dot.normal { background: var(--green); }

.history-section { padding-top: 32px; }
.history-header, .history-row { display: grid; grid-template-columns: 190px minmax(170px, 1fr) 110px 90px 90px 110px; gap: 16px; align-items: center; }
.history-header { min-height: 38px; padding: 0 16px; background: var(--surface-soft); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 700; }
.history-row { min-height: 52px; padding: 8px 16px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.history-row:last-child { border-bottom: 0; }
.history-stock strong { display: block; }
.history-stock small { color: var(--muted); }
.direction { font-weight: 700; }
.direction.below { color: var(--blue); }
.direction.above { color: var(--red); }

.empty-state { min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.empty-state svg { width: 22px; height: 22px; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 50; display: grid; gap: 8px; width: min(360px, calc(100vw - 44px)); }
.toast { padding: 12px 14px; border-radius: 6px; background: var(--ink); color: white; box-shadow: var(--shadow); animation: toast-in 180ms ease; }
.toast.error { background: #922d3a; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 1080px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .settings-section { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; }
  .settings-section .section-heading { grid-column: 1 / -1; }
  .zone-legend { margin-top: 0; align-self: center; }
}

@media (max-width: 820px) {
  .topbar { height: auto; min-height: 76px; padding: 14px 18px; align-items: flex-start; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .top-actions .button span { display: none; }
  .top-actions .button { width: 38px; padding: 0; }
  main { width: min(100% - 28px, 1480px); }
  .summary-band { grid-template-columns: repeat(3, 1fr); }
  .metric { padding: 0 12px; }
  .metric:first-child { padding-left: 0; }
  .metric.wide { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line-strong); padding: 10px 0; min-height: 54px; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .section-heading.compact { flex-direction: row; align-items: center; }
  .stock-search { width: 100%; }
  .watch-header { display: none; }
  .watch-row { grid-template-columns: minmax(120px, 1fr) 84px 98px 34px; gap: 10px; min-height: 0; padding: 14px; }
  .watch-row .period-cell, .watch-row .below-cell, .watch-row .above-cell { margin-top: 2px; }
  .watch-row .period-cell::before, .watch-row .below-cell::before, .watch-row .above-cell::before { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; }
  .watch-row .period-cell::before { content: "周期"; }
  .watch-row .below-cell::before { content: "下阈值"; }
  .watch-row .above-cell::before { content: "上阈值"; }
  .watch-row .period-cell { grid-column: 1; }
  .watch-row .below-cell { grid-column: 2; }
  .watch-row .above-cell { grid-column: 3; }
  .watch-row .delete-cell { grid-column: 4; align-self: end; }
  .settings-section { display: block; }
  .zone-legend { margin-top: 14px; }
  .history-header { display: none; }
  .history-row { grid-template-columns: 1fr auto auto; gap: 7px 12px; }
  .history-row .history-time { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }
  .history-row .history-close { display: none; }
}

@media (max-width: 480px) {
  .brand-mark { width: 38px; height: 38px; }
  h1 { font-size: 16px; }
  .summary-band { min-height: 70px; }
  .metric strong { font-size: 18px; }
  .workspace-grid { padding-top: 22px; }
  .watch-row { grid-template-columns: minmax(110px, 1fr) 82px 90px 34px; }
  .quote-value small { display: none; }
}
