:root {
  color-scheme: light;
  --bg: #f2f4f1;
  --surface: #ffffff;
  --surface-soft: #f7f8f6;
  --ink: #17201b;
  --muted: #68736d;
  --border: #d9dfdb;
  --header: #202722;
  --header-muted: #b8c3bc;
  --green: #12714b;
  --green-soft: #e4f2eb;
  --red: #b13c32;
  --red-soft: #f8e8e5;
  --amber: #925d0c;
  --amber-soft: #f7eedc;
  --blue: #2d6294;
  --blue-soft: #e5eef6;
  --shadow: 0 1px 2px rgba(23, 32, 27, 0.06);
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(45, 98, 148, 0.25); outline-offset: 2px; }

.tabular { font-variant-numeric: tabular-nums; }

.app-header {
  background: var(--header);
  color: #ffffff;
  border-bottom: 3px solid #d7a532;
}

.header-inner {
  width: min(1480px, calc(100% - 40px));
  min-height: 76px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand-block, .header-actions, .identity-line, .portfolio-id-row, .section-toolbar,
.side-heading-row, .metric-label, .button, .icon-button, .tab-button, .status-badge {
  display: flex;
  align-items: center;
}

.brand-block { gap: 12px; }
.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: #f1c453;
}
.brand-mark svg { width: 28px; height: 28px; }
.brand-block h1 { margin: 0; font-size: 18px; font-weight: 500; line-height: 1.25; }
.brand-block p { margin: 3px 0 0; color: var(--header-muted); font-size: 12px; }
.header-actions { gap: 10px; }

.status-badge {
  min-height: 34px;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 999px;
  color: #eef4f0;
  background: rgba(255,255,255,0.06);
  white-space: nowrap;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #e0ad39; }
.status-badge.is-live .status-dot { background: #52c98a; box-shadow: 0 0 0 4px rgba(82,201,138,0.13); }
.status-badge.is-error .status-dot { background: #ed6a5e; }
.status-badge.is-paused .status-dot { background: #aab4ae; }

.button, .icon-button, .tab-button {
  border: 1px solid var(--border);
  border-radius: 6px;
  justify-content: center;
  color: var(--ink);
  background: var(--surface);
}
.button { min-height: 36px; padding: 0 13px; gap: 8px; font-weight: 500; }
.button svg, .icon-button svg, .tab-button svg { width: 16px; height: 16px; }
.button:hover, .icon-button:hover, .tab-button:hover { background: var(--surface-soft); }
.button-secondary { color: #ffffff; border-color: rgba(255,255,255,0.2); background: rgba(255,255,255,0.08); }
.button-secondary:hover { background: rgba(255,255,255,0.14); }
.button-ghost { background: transparent; }
.icon-button { width: 34px; height: 34px; padding: 0; }

.app-shell { width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0 36px; }

.portfolio-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 22px;
}

.portfolio-link {
  min-width: 0;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  text-decoration: none;
}
.portfolio-link:hover { border-color: #aeb9b2; background: var(--surface-soft); }
.portfolio-link.is-active { border-color: var(--green); box-shadow: inset 3px 0 0 var(--green); }
.portfolio-link strong { overflow-wrap: anywhere; font-size: 13px; font-weight: 500; }
.portfolio-link span { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

.identity-band {
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(260px, auto) 1fr auto;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 20px;
}

.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 12px; }
.identity-line { gap: 10px; min-width: 0; }
.identity-line strong { font-size: 20px; font-weight: 500; overflow-wrap: anywhere; }
.inline-status { color: var(--green); font-size: 12px; font-weight: 500; }
.portfolio-id-row { gap: 6px; margin-top: 5px; }
.portfolio-id-row code { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.portfolio-id-row .icon-button { width: 28px; height: 28px; border-color: transparent; background: transparent; color: var(--muted); }
.notice { color: var(--green); text-align: right; min-height: 20px; }
.notice.is-error { color: var(--red); }

.time-reference {
  display: grid;
  grid-template-columns: minmax(310px, 1.35fr) minmax(220px, 1fr) minmax(190px, .8fr);
  align-items: center;
  gap: 24px;
  margin: 16px 0 0;
  padding: 13px 16px;
  border-left: 3px solid #d7a532;
  background: #ecefeb;
}
.time-reference > div { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.time-reference-primary { align-items: center !important; }
.time-reference-label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.time-reference-label svg { width: 15px; height: 15px; }
.time-reference strong { font-size: 15px; font-weight: 500; white-space: nowrap; }
.time-reference-primary strong { font-size: 18px; }
.time-zone { color: var(--muted); font-size: 11px; white-space: nowrap; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0 24px;
}

.metric-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.metric-label { gap: 7px; color: var(--muted); font-size: 12px; }
.metric-label svg { width: 15px; height: 15px; }
.metric-value { margin-top: 12px; font-size: 22px; font-weight: 500; overflow-wrap: anywhere; }
.metric-context { margin-top: 5px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 24px; align-items: start; }
.trade-workspace, .side-rail { min-width: 0; }
.account-pnl-section { margin-bottom: 24px; }
.account-pnl-frame { min-height: 170px; }
.account-pnl-table { min-width: 1500px; }
.account-history-section { margin-bottom: 24px; }
.account-history-frame { min-height: 150px; }
.account-history-table { min-width: 1250px; }
.section-toolbar { justify-content: space-between; gap: 20px; margin-bottom: 14px; }
h2 { margin: 0; font-size: 15px; font-weight: 500; }
.section-caption { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.switch-control { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--muted); }
.switch-control input { width: 16px; height: 16px; accent-color: var(--green); }

.tabs {
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  gap: 2px;
  padding: 3px;
  margin-bottom: 12px;
  border-radius: 7px;
  background: #e5e9e6;
}
.tab-button { min-height: 34px; padding: 0 12px; gap: 7px; border-color: transparent; background: transparent; color: var(--muted); }
.tab-button.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.tab-label { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 0 12px; color: var(--muted); white-space: nowrap; }
.tab-label svg { width: 16px; height: 16px; }
.tab-label.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.table-frame {
  min-height: 260px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.data-table { width: 100%; border-collapse: collapse; table-layout: auto; }
.data-table th, .data-table td { padding: 11px 12px; border-bottom: 1px solid #e7ebe8; text-align: left; vertical-align: middle; }
.data-table th { color: var(--muted); font-size: 12px; font-weight: 500; background: var(--surface-soft); white-space: nowrap; }
.data-table td { font-size: 13px; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr.is-new { background: #f4faf6; }
.positions-table { min-width: 850px; }
.number-cell { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.check-cell { text-align: center !important; }
.event-time { min-width: 126px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.symbol-cell { font-weight: 500; white-space: nowrap; }
.sub-value { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.margin-history-cell { min-width: 220px; color: var(--ink); font-size: 12px !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.action-badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.action-badge.long { color: var(--green); background: var(--green-soft); }
.action-badge.short { color: var(--red); background: var(--red-soft); }
.action-badge.reduce { color: var(--blue); background: var(--blue-soft); }
.signal-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.signal-badge.eligible { color: var(--green); background: var(--green-soft); }
.signal-badge.blocked { color: var(--red); background: var(--red-soft); }
.signal-badge.warning { color: var(--amber); background: var(--amber-soft); }
.signal-badge.neutral { color: var(--muted); background: #edf0ee; }
.execution-badge { display: flex; width: fit-content; margin-top: 6px; }
.lag-baseline { color: var(--muted); }
.lag-live { color: var(--amber); font-variant-numeric: tabular-nums; white-space: nowrap; }
.age-value { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink); }
.age-value.is-recent { color: var(--green); font-weight: 500; }
.age-value.is-future { color: var(--red); font-weight: 500; }
.profit-positive { color: var(--green); }
.profit-negative { color: var(--red); }
.row-check { width: 17px; height: 17px; accent-color: var(--green); }
.empty-state { min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--muted); }
.empty-state[hidden] { display: none; }
.empty-state svg { width: 24px; height: 24px; }

.side-rail { border-left: 1px solid var(--border); padding-left: 24px; }
.side-section { padding: 2px 0 22px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.side-section:last-child { border-bottom: 0; }
.side-heading-row { justify-content: space-between; gap: 12px; }
.count-label { color: var(--muted); font-size: 12px; }
.delta-list { margin-top: 12px; }
.delta-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 9px 0; border-bottom: 1px solid #e2e7e3; }
.delta-item:last-child { border-bottom: 0; }
.delta-symbol { font-weight: 500; }
.delta-side { margin-top: 2px; color: var(--muted); font-size: 11px; }
.delta-quantity { align-self: center; font-weight: 500; font-variant-numeric: tabular-nums; }
.delta-quantity.positive { color: var(--green); }
.delta-quantity.negative { color: var(--red); }
.rail-empty { margin-top: 12px; padding: 12px 0; color: var(--muted); font-size: 12px; }
.execution-section { padding-top: 0; }
.execution-position-list { margin-top: 10px; }
.execution-position-item { padding: 9px 0; border-top: 1px solid #e2e7e3; }
.execution-position-item strong, .execution-position-item span { display: block; }
.execution-position-item strong { font-size: 12px; font-weight: 500; }
.execution-position-item span { margin-top: 3px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.execution-position-item span.profit-positive { color: var(--green); }
.execution-position-item span.profit-negative { color: var(--red); }
.execution-position-item span.margin-flow { color: var(--ink); }
.execution-position-item span.trailing-active { color: var(--amber); }
.execution-decision-list { margin-top: 10px; }
.execution-decision-item { padding: 8px 0; border-top: 1px solid #e2e7e3; }
.execution-decision-item strong, .execution-decision-item span { display: block; }
.execution-decision-item strong { font-size: 11px; font-weight: 500; }
.execution-decision-item span { margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.execution-decision-item.is-planned strong { color: var(--green); }
.execution-decision-item.is-pending strong { color: var(--amber); }
.execution-decision-item.is-skipped strong { color: var(--muted); }
.control-mode-grid { display: grid; grid-template-columns: 1fr; gap: 7px; margin-top: 12px; }
.mode-button { justify-content: flex-start; min-height: 38px; }
.mode-button.is-selected { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.warning-text { color: var(--amber); }
.pending-list { margin-top: 12px; }
.pending-item { padding: 8px 0; border-top: 1px solid #e2e7e3; color: var(--amber); font-size: 12px; }
.reentry-item { color: var(--green); }
.detail-list { margin: 10px 0 0; }
.detail-list div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; text-align: right; }
.visibility-hidden { color: var(--amber); }
.visibility-public { color: var(--green); }
.activity-list { list-style: none; padding: 0; margin: 10px 0 0; }
.activity-list li { position: relative; padding: 7px 0 7px 18px; color: var(--muted); font-size: 12px; }
.activity-list li::before { content: ""; position: absolute; left: 2px; top: 12px; width: 6px; height: 6px; border-radius: 50%; background: #8c9891; }
.activity-list li.trade::before { background: var(--green); }
.activity-list li.error::before { background: var(--red); }
.activity-time { display: block; margin-top: 2px; color: #8b958f; font-variant-numeric: tabular-nums; }

@media (max-width: 1050px) {
  .time-reference { grid-template-columns: 1fr 1fr; }
  .time-reference-primary { grid-column: 1 / -1; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace-grid { grid-template-columns: 1fr; }
  .side-rail { border-left: 0; border-top: 1px solid var(--border); padding: 22px 0 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
  .side-section { border-bottom: 0; margin: 0; padding: 0 0 0 20px; border-left: 1px solid var(--border); }
  .side-section:first-child { border-left: 0; padding-left: 0; }
}

@media (max-width: 720px) {
  .header-inner, .app-shell { width: min(100% - 24px, 1480px); }
  .header-inner { min-height: 68px; gap: 12px; }
  .brand-block p { display: none; }
  .button-secondary span { display: none; }
  .button-secondary { width: 38px; padding: 0; }
  .portfolio-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 18px; }
  .identity-band { grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
  .notice { grid-column: 1 / -1; grid-row: 2; text-align: left; min-height: 0; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .time-reference { grid-template-columns: 1fr; gap: 8px; }
  .time-reference-primary { grid-column: auto; flex-wrap: wrap; }
  .time-reference > div { justify-content: space-between; }
  .time-reference-primary { justify-content: flex-start !important; }
  .metric-card { padding: 13px; }
  .metric-value { font-size: 18px; }
  .side-rail { grid-template-columns: 1fr; }
  .side-section, .side-section:first-child { border-left: 0; border-bottom: 1px solid var(--border); padding: 0 0 18px; }
  .section-toolbar { align-items: flex-start; }
  .data-table th, .data-table td { padding: 10px; }
}

@media (max-width: 430px) {
  .brand-block h1 { font-size: 16px; }
  .status-badge { padding: 0 9px; }
  .metric-grid { grid-template-columns: 1fr; }
  .time-reference-primary strong { font-size: 16px; }
  .identity-band { grid-template-columns: 1fr; }
  .identity-band > .button { justify-self: start; }
  .notice { grid-column: auto; grid-row: auto; }
  .section-toolbar { flex-direction: column; gap: 10px; }
}
