:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --ink: #15191f;
  --muted: #67707d;
  --faint: #8e97a3;
  --line: #dfe3e8;
  --line-strong: #c9cfd7;
  --surface: #ffffff;
  --surface-soft: #f5f6f8;
  --surface-hover: #eef1f4;
  --sidebar: #171a1f;
  --sidebar-muted: #aeb5bf;
  --blue: #1769e0;
  --blue-soft: #e8f1ff;
  --green: #16794b;
  --green-soft: #e5f5ec;
  --red: #b53a3a;
  --red-soft: #faeaea;
  --amber: #93630c;
  --amber-soft: #fbf1d8;
  --purple: #6b4db5;
  --shadow: 0 12px 32px rgba(18, 22, 28, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--surface-soft); color: var(--ink); font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select, input { min-height: 36px; }
button { border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--ink); cursor: pointer; padding: 0 13px; }
button:hover { background: var(--surface-hover); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
select, input, textarea { border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--ink); padding: 0 10px; }
textarea { min-height: 88px; padding-top: 9px; resize: vertical; }
.primary-action { border-color: var(--blue); background: var(--blue); color: white; font-weight: 650; }
.primary-action:hover { background: #0c59c6; }
.danger-action { border-color: var(--red); color: var(--red); }
.danger-action:hover { background: var(--red-soft); }
.noscript { margin: 40px auto; max-width: 640px; padding: 24px; background: white; border: 1px solid var(--line); }

.paper-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.paper-sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--sidebar); color: white; border-right: 1px solid #0c0e11; }
.paper-brand { min-height: 68px; display: flex; align-items: center; gap: 10px; padding: 0 18px; color: white; text-decoration: none; border-bottom: 1px solid #2a2f36; }
.paper-brand-mark { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 6px; background: #f0f4fa; }
.paper-brand-mark img { width: 19px; height: 19px; }
.paper-brand span:last-child { display: grid; gap: 1px; }
.paper-brand strong { font-size: 15px; }
.paper-brand small { color: var(--sidebar-muted); font-size: 11px; }
.paper-nav { display: grid; gap: 3px; padding: 14px 10px; }
.paper-nav button, .paper-sidebar-foot a, .paper-sidebar-foot button { width: 100%; min-height: 39px; display: flex; align-items: center; gap: 10px; border: 0; border-radius: 5px; background: transparent; color: var(--sidebar-muted); text-align: left; text-decoration: none; padding: 0 10px; }
.paper-nav button:hover, .paper-sidebar-foot a:hover, .paper-sidebar-foot button:hover { background: #242930; color: white; }
.paper-nav button.active { background: #2d333b; color: white; }
.paper-nav img, .paper-sidebar-foot img { width: 17px; height: 17px; filter: brightness(0) invert(1); opacity: 0.78; }
.paper-sidebar-foot { margin-top: auto; padding: 10px; border-top: 1px solid #2a2f36; }
.paper-sidebar-foot button { height: auto; padding-top: 8px; padding-bottom: 8px; }
.paper-sidebar-foot button > span:last-child { display: grid; }
.paper-sidebar-foot small { color: var(--sidebar-muted); font-size: 11px; }
.connection-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.paper-sidebar-foot button.connected .connection-dot { background: #35c985; }

.paper-main { min-width: 0; padding-bottom: 44px; }
.paper-topbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 26px; background: var(--surface); border-bottom: 1px solid var(--line); }
.paper-topbar h1 { margin: 2px 0 0; font-size: 21px; line-height: 1.2; }
.section-kicker { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: end; gap: 8px; }
.account-picker { display: grid; gap: 3px; }
.account-picker span, .export-controls label span, .resource-toolbar label span, .paper-dialog label span { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.account-picker select { min-width: 210px; }

.account-context { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 10px 26px; background: #fafbfc; border-bottom: 1px solid var(--line); }
.account-context > div:first-child { min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1px 9px; align-items: center; }
.account-context strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-context small { grid-column: 2; color: var(--muted); }
.status-pill, .quality-label, .quality-chip { display: inline-flex; align-items: center; width: max-content; min-height: 23px; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 750; text-transform: uppercase; white-space: nowrap; }
.status-pill.neutral, .quality-label { color: #59616c; background: #e8ebef; }
.status-pill.good, .quality-label.good, .quality-chip.good { color: var(--green); background: var(--green-soft); }
.status-pill.warn, .quality-label.warn, .quality-chip.warn { color: var(--amber); background: var(--amber-soft); }
.status-pill.bad, .quality-label.bad, .quality-chip.bad { color: var(--red); background: var(--red-soft); }
.quality-chip.info { color: var(--blue); background: var(--blue-soft); }
.export-controls { display: flex; align-items: end; gap: 7px; }
.export-controls label { display: grid; gap: 3px; }
.export-controls select { min-width: 105px; }
.export-controls button { display: inline-flex; align-items: center; gap: 7px; }
.export-controls button img { width: 15px; height: 15px; }

.paper-view { padding: 22px 26px 0; }
.metric-band { display: grid; grid-template-columns: repeat(8, minmax(112px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.metric-cell { min-width: 0; min-height: 82px; display: grid; align-content: center; gap: 5px; padding: 12px 14px; border-right: 1px solid var(--line); }
.metric-cell:last-child { border-right: 0; }
.metric-cell span { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.metric-cell strong { overflow: hidden; font-size: 18px; text-overflow: ellipsis; white-space: nowrap; }
.metric-cell small { color: var(--faint); font-size: 10px; }
.metric-cell .positive { color: var(--green); }
.metric-cell .negative { color: var(--red); }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(280px, 0.7fr); gap: 14px; margin-top: 14px; }
.workspace-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.workspace-panel > header { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.workspace-panel > header > div { display: grid; gap: 2px; }
.workspace-panel > header span { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.workspace-panel > header strong { font-size: 13px; }
.workspace-panel > header button { min-height: 30px; }
.nav-chart-wrap { position: relative; height: 228px; padding: 14px; }
.nav-chart-wrap.large { height: 320px; }
.nav-chart-wrap canvas { width: 100%; height: 100%; display: block; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.nav-legend { min-height: 36px; display: flex; align-items: center; gap: 16px; padding: 0 14px 10px; color: var(--muted); font-size: 11px; }
.nav-legend span { display: inline-flex; align-items: center; gap: 6px; }
.nav-legend i { width: 18px; height: 2px; background: var(--blue); }
.nav-legend span:nth-child(2) i { background: var(--green); }
.quality-summary { margin: 0; }
.quality-summary > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.quality-summary > div:last-child { border-bottom: 0; }
.quality-summary dt { color: var(--muted); }
.quality-summary dd { margin: 0; font-weight: 650; }
.quality-summary small { grid-column: 1 / -1; color: var(--faint); }
.table-panel { margin-top: 14px; overflow: hidden; }
.paper-table-wrap { width: 100%; overflow: auto; }
.paper-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.paper-table th { position: sticky; top: 0; z-index: 1; height: 34px; padding: 0 12px; background: #f7f8fa; color: var(--muted); border-bottom: 1px solid var(--line); text-align: left; font-size: 10px; text-transform: uppercase; }
.paper-table td { height: 44px; padding: 7px 12px; border-bottom: 1px solid #edf0f3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.paper-table tr:last-child td { border-bottom: 0; }
.paper-table tbody tr[data-order-id], .paper-table tbody tr[data-replay-id] { cursor: pointer; }
.paper-table tbody tr[data-order-id]:hover, .paper-table tbody tr[data-replay-id]:hover { background: #f5f8fc; }
.paper-table .numeric { text-align: right; font-variant-numeric: tabular-nums; }
.paper-table .positive { color: var(--green); }
.paper-table .negative { color: var(--red); }
.paper-table .empty-row { height: 88px; color: var(--muted); text-align: center; }
.cell-main { display: grid; gap: 2px; }
.cell-main small { color: var(--faint); }
.side-buy { color: var(--green); font-weight: 750; }
.side-sell { color: var(--red); font-weight: 750; }

.resource-toolbar { min-height: 54px; display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.resource-toolbar > div { display: grid; gap: 3px; }
.resource-toolbar > div strong { font-size: 16px; }
.resource-toolbar > div span { color: var(--muted); }
.resource-toolbar label { display: grid; gap: 3px; }
.resource-toolbar input { width: min(310px, 38vw); }
.resource-panel { margin-top: 12px; }
.full-width { width: 100%; }

.replay-list-panel { margin-top: 12px; }
.replay-detail { display: grid; gap: 14px; margin-top: 14px; }
.replay-detail-head { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.replay-detail-head > div:first-child { min-width: 0; display: grid; gap: 2px; }
.replay-detail-head span { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.replay-detail-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.replay-detail-head small { color: var(--faint); }
.replay-actions { display: flex; gap: 7px; }
.replay-metrics { grid-template-columns: repeat(5, minmax(120px, 1fr)); }
.replay-report-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.quality-summary.compact > div { padding: 8px 12px; }
.dialog-field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.admin-toolbar { align-items: center; }
.admin-control-band { display: grid; grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr) auto; align-items: center; gap: 16px; margin-top: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.admin-control-band > div:not(.admin-action-group) { min-width: 0; display: grid; gap: 3px; }
.admin-control-band span { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.admin-control-band strong, .admin-control-band small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-control-band small { color: var(--muted); }
.admin-action-group { display: flex; flex-wrap: wrap; gap: 7px; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.admin-panel { min-width: 0; }
.admin-panel .paper-table { min-width: 640px; }
.admin-table-actions { display: flex; justify-content: flex-end; gap: 5px; }
.admin-table-actions button { min-height: 28px; padding: 0 8px; font-size: 11px; }
.retention-control { display: grid; grid-template-columns: 74px 88px; align-items: center; justify-content: end; gap: 6px; }
.retention-control input[type="number"] { width: 74px; min-height: 30px; }
.retention-control input[type="checkbox"] { width: 16px; min-height: 16px; }

.paper-empty { margin: 52px auto; width: min(520px, calc(100% - 40px)); padding: 30px; text-align: center; background: white; border: 1px solid var(--line); border-radius: 6px; }
.paper-empty strong { font-size: 18px; }
.paper-empty p { color: var(--muted); }

.paper-toast { position: fixed; right: 20px; bottom: 20px; z-index: 40; max-width: min(420px, calc(100vw - 40px)); padding: 11px 14px; border-radius: 5px; background: #1d2228; color: white; box-shadow: var(--shadow); }
.paper-toast.error { background: #8e2929; }

.paper-dialog { width: min(520px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line-strong); border-radius: 7px; box-shadow: var(--shadow); }
.paper-dialog::backdrop { background: rgba(20, 24, 30, 0.48); }
.paper-dialog form, .audit-dialog-content { display: grid; gap: 16px; padding: 18px; }
.paper-dialog header, .paper-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.paper-dialog header > div { display: grid; gap: 2px; }
.paper-dialog header span { color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.paper-dialog h2, .paper-dialog h3 { margin: 0; }
.paper-dialog h2 { font-size: 20px; }
.paper-dialog h3 { font-size: 13px; }
.paper-dialog label { display: grid; gap: 5px; }
.paper-dialog footer { padding-top: 4px; border-top: 1px solid var(--line); }
.audit-dialog { width: min(920px, calc(100vw - 28px)); max-height: calc(100vh - 36px); }
.audit-dialog-content { max-height: calc(100vh - 38px); overflow: auto; }
.audit-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 5px; }
.audit-summary > div { min-width: 0; display: grid; gap: 3px; padding: 10px; border-right: 1px solid var(--line); }
.audit-summary > div:last-child { border-right: 0; }
.audit-summary span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.audit-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quality-chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.disclosure-status { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 5px; }
.model-limit-list { display: grid; margin: 0; border: 1px solid var(--line); border-radius: 5px; }
.model-limit-list > div { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 14px; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.model-limit-list > div:last-child { border-bottom: 0; }
.model-limit-list dt { color: var(--muted); font-weight: 700; }
.model-limit-list dd { margin: 0; line-height: 1.45; }
.audit-timeline { margin: 10px 0 0 8px; padding: 0 0 0 22px; border-left: 2px solid var(--line); list-style: none; }
.audit-timeline li { position: relative; display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px; padding: 0 0 17px; }
.audit-timeline li::before { content: ""; position: absolute; left: -28px; top: 4px; width: 10px; height: 10px; border: 2px solid white; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.audit-timeline time { color: var(--muted); font-size: 11px; }
.timeline-event { display: grid; gap: 3px; }
.timeline-event small { color: var(--muted); }
.audit-evidence { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 10px 0 0; border: 1px solid var(--line); border-radius: 5px; }
.audit-evidence > div { min-width: 0; display: grid; gap: 3px; padding: 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.audit-evidence dt { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.audit-evidence dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1180px) {
  .metric-band { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
  .metric-cell:nth-child(4) { border-right: 0; }
  .metric-cell:nth-child(-n+4) { border-bottom: 1px solid var(--line); }
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .replay-metrics { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
  .replay-report-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-control-band { grid-template-columns: minmax(180px, 1fr) minmax(240px, auto); }
  .admin-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .replay-report-grid { grid-template-columns: minmax(0, 1fr); }
  .paper-shell { display: block; padding-bottom: 62px; }
  .paper-sidebar { position: fixed; inset: auto 0 0; z-index: 30; width: 100%; height: 58px; display: block; border: 0; border-top: 1px solid #30353c; }
  .paper-brand, .paper-sidebar-foot { display: none; }
  .paper-nav { height: 100%; display: flex; gap: 1px; overflow-x: auto; padding: 5px 4px; }
  .paper-nav button { flex: 0 0 62px; min-width: 62px; height: 48px; display: grid; justify-items: center; align-content: center; gap: 2px; padding: 0 2px; font-size: 9px; }
  .paper-nav img { width: 16px; height: 16px; }
  .paper-topbar { align-items: flex-start; padding: 12px 14px; }
  .paper-topbar h1 { font-size: 18px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .account-picker { order: -1; width: 100%; }
  .account-picker select { width: 100%; min-width: 0; }
  .account-context { align-items: flex-start; flex-direction: column; padding: 10px 14px; }
  .export-controls { width: 100%; overflow-x: auto; }
  .paper-view { padding: 14px 14px 0; }
  .metric-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-cell, .metric-cell:nth-child(4) { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .metric-cell:nth-child(even) { border-right: 0; }
  .metric-cell:nth-last-child(-n+2) { border-bottom: 0; }
  .resource-toolbar { align-items: stretch; flex-direction: column; }
  .resource-toolbar input { width: 100%; }
  .replay-detail-head { align-items: flex-start; flex-direction: column; }
  .replay-actions { width: 100%; }
  .replay-actions button { flex: 1; }
  .replay-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-control-band { grid-template-columns: minmax(0, 1fr); }
  .admin-action-group button { flex: 1 1 auto; }
  .audit-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .audit-summary > div:nth-child(even) { border-right: 0; }
  .audit-summary > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .audit-timeline li { grid-template-columns: 1fr; gap: 3px; }
  .audit-evidence { grid-template-columns: 1fr; }
  .audit-evidence > div { border-right: 0; }
}

@media (max-width: 520px) {
  .paper-topbar { display: block; }
  .topbar-actions { margin-top: 10px; justify-content: flex-start; }
  .topbar-actions button { flex: 1 1 auto; }
  .export-controls label:first-child { min-width: 128px; }
  .export-controls button { flex: 0 0 auto; }
  .nav-chart-wrap { height: 196px; }
  .paper-table { min-width: 720px; }
  .dialog-field-grid { grid-template-columns: minmax(0, 1fr); }
}
