:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #101820;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #004b8d;
  --accent-2: #ffd200;
  --warn: #b86e00;
  --danger: #b42318;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: #f3f5f8;
  color: var(--ink);
}
.brand,
h1,
h2,
h3,
h4,
h5,
h6,
button,
.nav a,
.button-link {
  font-family: inherit;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: #003b71;
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.brand { color: white; font-size: 1.25rem; font-weight: 700; }
.nav {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}
.nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0.55rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: white;
  text-decoration: none;
  font-weight: 600;
  touch-action: manipulation;
}
.nav a:hover {
  background: rgba(255, 255, 255, 0.16);
}
.nav a.active {
  color: #101820;
  background: var(--accent-2);
  border-color: var(--accent-2);
  font-weight: 700;
}
.muted { color: var(--muted); }
.error { color: var(--danger); }
.container {
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}
.grid { display: grid; gap: 1rem; }
.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.two-col { grid-template-columns: 1fr 1fr; }
.nested-grid { align-items: start; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  box-shadow: 0 8px 18px rgba(16, 24, 32, 0.05);
}
.feedback-card {
  border-left: 6px solid var(--accent);
}
.alerts-card {
  border-left: 6px solid var(--warn);
}
.compact-card {
  padding-top: 0.8rem;
  padding-bottom: 0.8rem;
}
.banner {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.chip {
  display: inline-block;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: #eef4fb;
  border: 1px solid var(--line);
}
.chip.ok { color: var(--accent); }
.chip.warn { color: var(--warn); }
.chip.danger { color: var(--danger); }
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #eef4fb;
  white-space: nowrap;
}
.badge.filled,
.badge.protected,
.badge.buy,
.badge.ok {
  color: var(--accent);
}
.badge.active,
.badge.hold {
  color: var(--accent);
}
.badge.closed,
.badge.unprotected,
.badge.reject {
  color: var(--danger);
}
.alert-stack {
  display: grid;
  gap: 0.6rem;
}
.alert-row {
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f8f2e9;
}
.alert-row.warn {
  color: var(--warn);
  border-color: #e3c49d;
}
.alert-row.danger {
  color: var(--danger);
  border-color: #d8aaa4;
}
.controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.inline-form {
  display: inline;
}
.filter-bar {
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
  align-items: end;
}
.filter-bar label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.95rem;
}
.filter-bar input,
.filter-bar select {
  min-width: 140px;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}
.staged-order-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}
.staged-order-form label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
}
.staged-order-form input,
.staged-order-form select {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}
.bulk-text {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  resize: vertical;
  font-family: "SFMono-Regular", Menlo, monospace;
}
.staged-order-form .wide {
  grid-column: 1 / -1;
}
.compact-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbf7ef;
}
button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.7rem 1rem;
  cursor: pointer;
}
button.warn { background: var(--warn); }
button.danger { background: var(--danger); }
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  background: transparent;
}
.mini-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.92rem;
}
.mini-link:hover {
  text-decoration: underline;
}
.bottom-nav {
  display: none;
}
.link-cluster {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.stacked-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }
.positive { color: var(--accent); }
.negative { color: var(--danger); }
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(480px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: 0 16px 38px rgba(70, 49, 22, 0.08);
}
.login-form {
  display: grid;
  gap: 0.8rem;
}
.login-form input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}
code {
  font-family: "SFMono-Regular", Menlo, monospace;
  font-size: 0.9em;
  background: #f3eee5;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
}
.summary-box {
  white-space: pre-wrap;
  background: #fbf7ef;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  overflow-x: auto;
  font-family: "SFMono-Regular", Menlo, monospace;
  font-size: 0.9rem;
}
.inline-metrics {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.plain-list {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.45rem;
}
.badge.tradable,
.badge.entry,
.badge.match,
.row-tradable td:first-child {
  color: var(--accent);
}
.badge.liquidity-risk,
.badge.spread-risk,
.badge.mismatch,
.row-liquidity-risk,
.row-spread-risk {
  color: var(--warn);
}
.badge.halted,
.badge.data-error,
.row-halted,
.row-data-error {
  color: var(--danger);
}
.row-liquidity-risk,
.row-spread-risk,
.row-mismatch,
.row-halted,
.row-data-error,
.row-protective-stop {
  background: rgba(255, 253, 247, 0.7);
}
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .nav {
    gap: 0.75rem;
    flex-wrap: wrap;
  }
  .filter-bar { align-items: stretch; }
  .staged-order-form { grid-template-columns: 1fr; }
}

.mobile-shell {
  display: grid;
  gap: 1rem;
  max-width: 760px;
  margin: 0 auto;
}

.scanner-shell {
  max-width: 680px;
}

.mobile-trading {
  max-width: 520px;
  gap: 0.75rem;
}

.mobile-market-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  padding: 1rem;
  color: white;
  background: #003b71;
  border-radius: 8px;
  border-bottom: 4px solid var(--accent-2);
}

.mobile-market-bar h2 {
  margin: 0.1rem 0 0;
  font-size: 1.45rem;
  line-height: 1.1;
}

.mobile-kicker {
  display: block;
  color: #ffd200;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.trade-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0.65rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--accent-2);
  color: #101820;
  background: var(--accent-2);
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}

.trade-action.secondary {
  color: white;
  border-color: #004b8d;
  background: #004b8d;
}

.mobile-account-panel,
.mobile-status-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.95rem;
}

.daily-pnl-card {
  display: flex;
  align-items: stretch;
  gap: 0.9rem;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: white;
  box-shadow: 0 10px 22px rgba(16, 24, 32, 0.07);
}

.pnl-block {
  display: grid;
  gap: 0.2rem;
  flex: 1 1 0;
  min-width: 0;
}

.pnl-block.total {
  align-content: center;
  border-left: 1px solid var(--line);
  padding-left: 0.9rem;
  text-align: right;
}

.daily-pnl-card span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.daily-pnl-card strong {
  font-size: 2.25rem;
  line-height: 1;
  overflow-wrap: anywhere;
}

.daily-pnl-card small {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.daily-pnl-card.gain {
  border-left: 6px solid #027a48;
}

.daily-pnl-card.gain strong {
  color: #027a48;
}

.daily-pnl-card.loss {
  border-left: 6px solid var(--danger);
}

.daily-pnl-card.loss strong {
  color: var(--danger);
}

.pnl-block.total.gain strong {
  color: #027a48;
}

.pnl-block.total.loss strong {
  color: var(--danger);
}

.scanner-top-pick {
  border-left-color: var(--accent-2);
}

.scanner-top-pick strong {
  color: #003b71;
}

.scanner-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.scanner-summary div {
  display: grid;
  gap: 0.2rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.scanner-summary span,
.scanner-score span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.scanner-summary strong {
  color: #003b71;
  font-size: 1.2rem;
}

.account-line {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.account-line span,
.mobile-stat-strip span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.account-line strong {
  font-size: 1.65rem;
  line-height: 1;
}

.mobile-stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  padding-top: 0.85rem;
}

.mobile-stat-strip.compact {
  padding-top: 0;
}

.mobile-stat-strip div {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.mobile-stat-strip strong {
  font-size: 1.15rem;
}

.mobile-status-card {
  display: grid;
  gap: 0.7rem;
}

.mobile-status-card p,
.mobile-status-card small {
  margin: 0;
}

.trading-card {
  padding: 0;
  overflow: hidden;
}

.trading-card .section-head {
  min-height: 48px;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.trading-card h3 {
  margin: 0;
  font-size: 1rem;
}

.quote-list {
  display: grid;
}

.quote-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  min-height: 58px;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.quote-row:last-child {
  border-bottom: 0;
}

.quote-row div {
  min-width: 0;
  display: grid;
  gap: 0.15rem;
}

.quote-row strong {
  font-size: 1rem;
}

.symbol-with-score {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.inline-ai-score {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid rgba(0, 59, 113, 0.18);
  border-radius: 6px;
  background: rgba(0, 114, 206, 0.08);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  padding: 0.18rem 0.38rem;
  white-space: nowrap;
}

.quote-row span {
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.quote-row .inline-ai-score {
  color: var(--accent);
  font-size: 0.72rem;
}

.quote-row b {
  white-space: nowrap;
}

.position-row {
  min-height: 64px;
}

.position-change {
  display: grid;
  justify-items: end;
  gap: 0.15rem;
  font-size: 1rem;
  line-height: 1.05;
}

.position-change small {
  color: inherit;
  font-size: 0.78rem;
  font-weight: 800;
}

.quote-row .day-move {
  font-weight: 800;
}

.quote-row .day-move.positive {
  color: #027a48;
}

.quote-row .day-move.negative {
  color: var(--danger);
}

.compact-order-row {
  min-height: 52px;
}

.ai-supervisor-body {
  display: grid;
  gap: 0.65rem;
  padding: 0.85rem 0.9rem;
}

.ai-supervisor-body p {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
}

.ai-supervisor-body small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.trade-detail-body {
  display: grid;
  gap: 0.85rem;
  padding: 0.85rem 0.9rem;
}

.trade-position-line {
  display: grid;
  gap: 0.2rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.trade-position-line span {
  color: var(--muted);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.trade-detail-list {
  display: grid;
  border-top: 1px solid var(--line);
}

.trade-detail-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}

.trade-detail-row div {
  display: grid;
  gap: 0.18rem;
  min-width: 0;
}

.trade-detail-row span {
  color: var(--muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.scanner-list {
  display: grid;
}

.ai-ranking-note {
  display: grid;
  gap: 0.25rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  background: #f6f8fb;
}

.ai-ranking-note strong {
  color: #003b71;
}

.ai-ranking-note span {
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.scanner-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 56px;
  gap: 0.75rem;
  min-height: 96px;
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.scanner-row:last-child {
  border-bottom: 0;
}

.scanner-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: start;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: white;
  background: #003b71;
  font-weight: 900;
}

.scanner-main {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.scanner-title,
.scanner-metrics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.scanner-title strong {
  font-size: 1.05rem;
}

.scanner-metrics span {
  font-size: 0.86rem;
}

.scanner-main p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.scanner-score {
  display: grid;
  gap: 0.15rem;
  align-content: start;
  justify-items: end;
}

.scanner-score strong {
  color: #003b71;
  font-size: 1.15rem;
}

.empty-state {
  margin: 0;
  padding: 0.9rem;
}

.quick-trade-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}
.mobile-shell-compact {
  gap: 0.8rem;
}
.mobile-hero {
  background: linear-gradient(145deg, #fffdf7 0%, #f4ecdd 100%);
}
.mobile-hero-compact {
  padding: 1rem 1.05rem;
}
.mobile-hero-top,
.section-head,
.mobile-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.mobile-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.mobile-stat-grid-compact {
  margin-bottom: 0;
}
.mobile-stat {
  background: #fbf7ef;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.9rem;
  display: grid;
  gap: 0.2rem;
}
.mobile-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.8rem;
}
.mobile-subline {
  margin: 0.35rem 0 0;
}
.mobile-note {
  margin: 0.75rem 0 0;
}
.mobile-list {
  display: grid;
  gap: 0.75rem;
}
.mobile-list-compact {
  gap: 0.55rem;
}
.mobile-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.9rem;
  background: #fbf7ef;
}
.mobile-row-compact {
  padding: 0.7rem 0.8rem;
}
.mobile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.8rem;
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.controls-compact {
  gap: 0.55rem;
}

@media (max-width: 640px) {
  .daily-pnl-card {
    gap: 0.65rem;
    padding: 0.85rem;
  }

  .daily-pnl-card strong {
    font-size: 1.55rem;
  }

  .daily-pnl-card span {
    font-size: 0.72rem;
  }

  .daily-pnl-card small {
    font-size: 0.76rem;
  }

  .pnl-block.total {
    padding-left: 0.65rem;
  }

  .scanner-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .scanner-row {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .scanner-score {
    grid-column: 2;
    justify-items: start;
    grid-auto-flow: column;
    align-items: center;
    justify-content: start;
  }

  .container {
    padding: 1rem;
    padding-bottom: 5.5rem;
  }
  .topbar {
    padding: 0.85rem 1rem;
  }
  .nav {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.2rem;
  }
  .nav a {
    white-space: nowrap;
    flex: 0 0 auto;
  }
  .mobile-stat-grid {
    grid-template-columns: 1fr 1fr;
  }
  th, td {
    padding: 0.6rem 0.35rem;
    font-size: 0.92rem;
  }
  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.45rem;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.7rem 0.85rem calc(0.7rem + env(safe-area-inset-bottom));
    background: rgba(255, 253, 247, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
    z-index: 80;
  }
  .bottom-nav a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0.55rem 0.4rem;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: white;
    color: var(--ink);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    touch-action: manipulation;
  }
  .bottom-nav a.active {
    background: #003b71;
    border-color: #003b71;
    color: white;
  }
}
