/* Trading Agent dashboard — mobile first, light/dark aware, no meaning by color alone. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d9dee6;
  --text: #16202b;
  --muted: #5c6b7a;
  --accent: #1f5fbf;
  --accent-soft: rgba(31, 95, 191, 0.12);
  --line: #1f5fbf;
  --area: rgba(31, 95, 191, 0.10);
  --gain: #1a7f4b;
  --loss: #b3261e;
  --warn: #9a6700;
  --buy: #1a7f4b;
  --sell: #7a3db8;
  --cash: #b06d00;
  --reject: #b3261e;
  --interrupt: #445566;
  --closed: rgba(90, 105, 125, 0.10);
  --gap: rgba(179, 38, 30, 0.08);
  --ref: #6b7a8c;
  --paper: #0d6b8a;
  --demo: #8a3b0d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.10);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171d24;
    --surface-2: #1f2730;
    --border: #2c3640;
    --text: #e8edf2;
    --muted: #97a4b2;
    --accent: #6ea4ff;
    --accent-soft: rgba(110, 164, 255, 0.16);
    --line: #7db1ff;
    --area: rgba(125, 177, 255, 0.14);
    --gain: #4fc78a;
    --loss: #ff6b62;
    --warn: #e0b341;
    --buy: #4fc78a;
    --sell: #c59bff;
    --cash: #f0b352;
    --reject: #ff6b62;
    --interrupt: #a9b7c6;
    --closed: rgba(151, 164, 178, 0.10);
    --gap: rgba(255, 107, 98, 0.10);
    --ref: #97a4b2;
    --paper: #62c3e6;
    --demo: #f0a070;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.2; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; margin-top: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
pre { background: var(--surface-2); padding: 0.75rem; border-radius: 8px; overflow: auto; font-family: var(--mono); font-size: 0.85rem; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 0.5rem; z-index: 100; }
.skip-link:focus { left: 0.5rem; top: 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); }

.banner { padding: 0.5rem 1rem; font-size: 0.9rem; text-align: center; border-bottom: 1px solid var(--border); }
.banner-demo { background: #fff1e6; color: #6b2d05; }
.banner-paper { background: #e6f4fa; color: #084a60; }
@media (prefers-color-scheme: dark) {
  .banner-demo { background: #3a1d0a; color: #ffd8bf; }
  .banner-paper { background: #0a2e3a; color: #bfeaff; }
}
.mode-badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; vertical-align: middle; border: 1px solid currentColor; }
.mode-paper { color: var(--paper); }
.mode-demo { color: var(--demo); }
.tag { display: inline-block; padding: 0 0.45rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; border: 1px solid currentColor; vertical-align: middle; margin-left: 0.3rem; }
.tag-paper { color: var(--paper); }

.topbar { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; padding: 0.6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; }
.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav a { text-decoration: none; padding: 0.35rem 0.6rem; border-radius: 8px; color: var(--text); font-size: 0.9rem; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a:focus-visible, .btn:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, .chart-wrap:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.topbar-status { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }

.status-pill { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.status-pill::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--muted); }
.status-live::before { background: var(--gain); box-shadow: 0 0 0 3px rgba(26, 127, 75, 0.2); }
.status-delayed::before { background: var(--warn); }
.status-market_closed::before { background: var(--muted); }
.status-disconnected::before { background: var(--loss); }
.status-live { border-color: var(--gain); }
.status-delayed { border-color: var(--warn); }
.status-disconnected { border-color: var(--loss); }

.main { padding: 1rem; max-width: 1280px; margin: 0 auto; }
.footer { padding: 1rem; color: var(--muted); font-size: 0.8rem; text-align: center; }

.card, .chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 0.9rem; box-shadow: var(--shadow); min-width: 0; }
.metric-label { display: block; font-size: 0.78rem; color: var(--muted); }
.metric-value { display: block; font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 0.15rem; word-break: break-word; }
.metric-value-sm { font-size: 1.05rem; }
.metric-sub { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 0.1rem; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }

.chart-header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem; align-items: flex-start; }
.chart-subtitle { margin: 0; color: var(--muted); font-size: 0.85rem; }
.chart-status { display: flex; flex-direction: column; align-items: flex-end; gap: 0.2rem; }
.chart-controls { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; margin: 0.75rem 0; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.segmented button { border: 0; background: transparent; color: var(--text); padding: 0.45rem 0.75rem; font: inherit; font-size: 0.85rem; cursor: pointer; min-width: 3rem; min-height: 40px; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
.toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }
.chart-wrap { position: relative; width: 100%; height: 300px; border-radius: 10px; background: var(--surface); }
@media (min-width: 720px) { .chart-wrap { height: 380px; } }
.chart-wrap svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-wrap .axis text { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.chart-wrap .axis line, .chart-wrap .grid line { stroke: var(--border); stroke-width: 1; }
.chart-wrap .grid line { stroke-dasharray: 2 4; }
.chart-wrap path.series { fill: none; stroke: var(--line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-wrap path.series.stale { stroke-dasharray: 4 4; opacity: 0.7; }
.chart-wrap path.area { fill: var(--area); stroke: none; }
.chart-wrap rect.closed { fill: var(--closed); }
.chart-wrap rect.gap { fill: var(--gap); }
.chart-wrap text.gap-label, .chart-wrap text.closed-label { fill: var(--muted); font-size: 10px; text-anchor: middle; }
.chart-wrap line.ref { stroke: var(--ref); stroke-width: 1; stroke-dasharray: 6 4; }
.chart-wrap line.ref.pause { stroke: var(--loss); }
.chart-wrap line.ref.dayopen { stroke: var(--accent); stroke-dasharray: 2 3; }
.chart-wrap text.ref-label { fill: var(--muted); font-size: 10px; font-family: var(--mono); }
.chart-wrap .marker { cursor: pointer; }
.chart-wrap .marker text { font-size: 8px; font-weight: 700; fill: #fff; text-anchor: middle; pointer-events: none; }
.chart-wrap .marker.buy path { fill: var(--buy); }
.chart-wrap .marker.sell path { fill: var(--sell); }
.chart-wrap .marker.cash_flow path { fill: var(--cash); }
.chart-wrap .marker.rejection path { fill: var(--reject); }
.chart-wrap .marker.pause path, .chart-wrap .marker.resume path, .chart-wrap .marker.interruption path { fill: var(--interrupt); }
.chart-wrap .marker:focus { outline: none; }
.chart-wrap .marker:focus path, .chart-wrap .marker:hover path { stroke: var(--text); stroke-width: 2; }
.chart-wrap circle.last { fill: var(--line); stroke: var(--surface); stroke-width: 2; }
.chart-wrap circle.last.stale { fill: var(--surface); stroke: var(--line); }
.chart-wrap .cursor line { stroke: var(--text); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.6; }
.chart-wrap .cursor circle { fill: var(--surface); stroke: var(--line); stroke-width: 2; }
.chart-tooltip { position: absolute; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.6rem; font-size: 0.8rem; box-shadow: var(--shadow); max-width: 260px; z-index: 5; font-variant-numeric: tabular-nums; }
.chart-tooltip .tt-value { font-weight: 700; font-size: 0.95rem; }
.chart-tooltip .tt-time { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 1rem; color: var(--muted); font-size: 0.95rem; }
.chart-empty[hidden] { display: none; }
.chart-empty strong { color: var(--text); font-size: 1.4rem; display: block; margin-bottom: 0.25rem; }
.chart-text { font-size: 0.85rem; margin: 0.5rem 0 0; min-height: 1.2rem; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; font-size: 0.78rem; color: var(--muted); margin-top: 0.5rem; }
.lg { display: inline-block; width: 12px; height: 12px; margin-right: 0.3rem; vertical-align: -2px; border-radius: 2px; }
.lg-line { background: var(--line); height: 3px; vertical-align: 2px; }
.lg-buy { background: var(--buy); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.lg-sell { background: var(--sell); clip-path: polygon(0 0, 100% 0, 50% 100%); }
.lg-cash { background: var(--cash); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.lg-reject { background: var(--reject); clip-path: polygon(20% 0, 50% 30%, 80% 0, 100% 20%, 70% 50%, 100% 80%, 80% 100%, 50% 70%, 20% 100%, 0 80%, 30% 50%, 0 20%); }
.lg-int { background: var(--interrupt); clip-path: polygon(15% 0, 40% 0, 40% 100%, 15% 100%, 15% 0, 60% 0, 85% 0, 85% 100%, 60% 100%, 60% 0); }
.lg-closed { background: var(--closed); border: 1px solid var(--border); }
.lg-ref { background: repeating-linear-gradient(90deg, var(--ref) 0 4px, transparent 4px 7px); height: 2px; vertical-align: 2px; }
.event-list summary { cursor: pointer; font-size: 0.85rem; color: var(--muted); }
.event-list ol { padding-left: 1.2rem; font-size: 0.85rem; max-height: 220px; overflow: auto; }
.event-list li button { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; padding: 0.15rem 0; }

.two-col { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 900px) { .two-col { grid-template-columns: 2fr 1fr; } .metrics { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 14rem; }
.pill { display: inline-block; padding: 0 0.45rem; border-radius: 999px; font-size: 0.72rem; border: 1px solid var(--border); background: var(--surface-2); }
.pill-ok { border-color: var(--gain); color: var(--gain); }
.pill-warn { border-color: var(--warn); color: var(--warn); }
.pill-bad { border-color: var(--loss); color: var(--loss); }

.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; padding: 0.55rem 0.9rem; min-height: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: 0.9rem; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-danger { border-color: var(--loss); color: var(--loss); }
.btn-ghost { background: transparent; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.warnings { list-style: none; padding: 0; margin: 0; }
.warnings li { padding: 0.4rem 0.6rem; border-left: 3px solid var(--warn); background: var(--surface-2); border-radius: 6px; margin-bottom: 0.4rem; font-size: 0.85rem; }
.warnings li.muted { border-left-color: var(--border); }
.gates { list-style: none; padding: 0; margin: 0; }
.gates li { padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 0.4rem; font-size: 0.85rem; }
.gates .gate-status { font-weight: 700; margin-left: 0.4rem; }
.gate-external .gate-status { color: var(--loss); }
.gate-unresolved .gate-status { color: var(--warn); }
.gate-gate .gate-status { color: var(--muted); }

.form label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.6rem 0 0.2rem; }
.form input[type="text"], .form input[type="password"], .form input[type="number"], .form select, .form-actions input[type="text"] { width: 100%; padding: 0.55rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; min-height: 44px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
@media (min-width: 720px) { .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.form-grid fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.9rem 0.9rem; margin: 0 0 1rem; grid-column: span 1; min-width: 0; }
.form-grid legend { font-size: 0.85rem; font-weight: 600; padding: 0 0.3rem; }
.form-grid .help { font-size: 0.75rem; color: var(--muted); margin: 0.15rem 0 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; margin-top: 0.5rem; }
.form-actions input[type="text"] { flex: 1 1 260px; }
.form-inline { display: grid; gap: 0.25rem; }
@media (min-width: 720px) { .form-inline { grid-template-columns: repeat(4, minmax(0, 1fr)) auto auto; align-items: end; } }
.form-error { color: var(--loss); font-size: 0.85rem; }
.summary { background: var(--surface-2); padding: 0.75rem; border-radius: 8px; font-size: 0.9rem; }
.notice { padding: 0.6rem; border-radius: 8px; background: var(--accent-soft); font-size: 0.9rem; }
.filters { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; font-size: 0.85rem; }
.filters select { padding: 0.4rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); min-height: 40px; }

.login-body { display: flex; flex-direction: column; min-height: 100vh; }
.login-card { margin: 2rem auto; width: min(420px, calc(100% - 2rem)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.login-card h1 { font-size: 1.3rem; margin-bottom: 1rem; }
.login-card .btn { width: 100%; margin-top: 1rem; }
details.raw { margin-top: 0.3rem; }
details.raw pre { max-height: 240px; white-space: pre-wrap; word-break: break-word; }
@media (prefers-reduced-motion: no-preference) { .status-pill::before { transition: background 0.3s; } }
