/* AATL workspace — paper-only laboratory UI. No external assets. */

:root {
  --navy: #142634;
  --navy-soft: #1d3446;
  --navy-line: rgba(255, 255, 255, 0.12);
  --teal: #2369b4;
  --teal-dark: #18518d;
  --teal-soft: #e8f1fc;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2430;
  --text-muted: #5b6672;
  --line: #e2e6ea;
  --warn-bg: #fff7e6;
  --warn-text: #7a4b00;
  --error-bg: #fdecec;
  --error-text: #8a1c1c;
  --radius: 8px;
  --sidebar-w: 264px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
p { margin: 0; }
ul, dl { margin: 0; padding: 0; }
li { list-style: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: 8px; top: -40px;
  background: var(--teal); color: #fff; padding: 6px 10px;
  border-radius: var(--radius); z-index: 10;
}
.skip-link:focus { top: 8px; }

:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.sidebar :focus-visible { outline-color: #8fd6ce; }

/* Layout */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  background: var(--navy);
  color: #e6edf2;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 16px;
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 20px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Sidebar */
.brand { display: flex; flex-direction: column; gap: 2px; padding: 4px 8px 12px; border-bottom: 1px solid var(--navy-line); }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: 0.04em; }
.brand-sub { font-size: 13px; color: #b7c4cf; }
.brand-logo { display: block; width: 100%; height: auto; }
.welcome-brand { display: flex; justify-content: center; padding: 16px; background: #0b1927; border-radius: var(--radius); }
.welcome-brand img { display: block; width: min(100%, 400px); height: auto; }

.badge {
  display: inline-block; margin-top: 6px; align-self: flex-start;
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  padding: 2px 8px; border-radius: 999px;
}
.badge-paper { background: var(--teal); color: #fff; }

.sidebar-section { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.sidebar-heading { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #9fb0bd; padding: 0 8px; }

.search { display: block; padding: 0 4px; }
.search input {
  width: 100%; padding: 7px 10px; font: inherit;
  background: var(--navy-soft); color: #e6edf2;
  border: 1px solid var(--navy-line); border-radius: var(--radius);
}
.search input::placeholder { color: #8fa0ad; }

.run-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; max-height: 50vh; }
.run-item {
  width: 100%; text-align: left; font: inherit; color: inherit;
  background: transparent; border: 0; border-radius: var(--radius);
  padding: 8px 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.run-item:hover { background: var(--navy-soft); }
.run-item[aria-current="true"] { background: var(--navy-soft); box-shadow: inset 3px 0 0 var(--teal); }
.run-item-title { font-weight: 600; }
.run-item-sub { font-size: 12px; color: #a9b8c4; font-family: var(--mono); }

.sidebar-note { font-size: 12px; color: #a9b8c4; padding: 0 8px; min-height: 1em; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: #8fa0ad; padding: 12px 8px 0; border-top: 1px solid var(--navy-line); }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 22px; }

.safety-notice {
  background: var(--warn-bg); color: var(--warn-text);
  border: 1px solid #f1dcb0; border-radius: var(--radius);
  padding: 8px 12px; font-weight: 500;
}

.status { min-height: 1.2em; color: var(--text-muted); }
.status.is-error { color: var(--error-text); }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; border-radius: var(--radius);
  padding: 8px 14px; cursor: pointer; border: 1px solid transparent;
  background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--teal-dark); }
.btn-secondary { border-color: var(--teal); color: var(--teal); }
.btn-secondary:not(:disabled):hover { background: var(--teal-soft); }
.btn-ghost { border-color: var(--line); color: var(--text); }
.btn-ghost:not(:disabled):hover { background: var(--bg); }

/* Cards and states */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin-bottom: 8px; }
.empty-state, .error-state { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.error-state { background: var(--error-bg); border-color: #f3c6c6; color: var(--error-text); }
.error-state .btn { background: #fff; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; margin-top: 10px; }
.mono { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

/* Run header */
.run-view { display: flex; flex-direction: column; gap: 14px; }
.run-header { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.run-header-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.run-title { font-size: 18px; }
.run-subtitle { color: var(--text-muted); }
.run-meta { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 4px; }
.run-meta dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.run-meta dd { margin: 0; }
.run-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs [role="tab"] {
  font: inherit; font-weight: 500; background: transparent; border: 0; cursor: pointer;
  padding: 8px 12px; color: var(--text-muted); border-bottom: 2px solid transparent;
  margin-bottom: -1px; border-radius: var(--radius) var(--radius) 0 0;
}
.tabs [role="tab"][aria-selected="true"] { color: var(--teal); border-bottom-color: var(--teal); font-weight: 600; }
[role="tabpanel"] { display: flex; flex-direction: column; gap: 14px; }
[role="tabpanel"][hidden] { display: none; }

/* Metrics */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.metric-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.metric-value { font-size: 20px; font-weight: 600; margin-top: 2px; word-break: break-all; }
.metric-note { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.metric.is-halted .metric-value { color: var(--warn-text); }

.overview-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 14px; }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { font-size: 11px; fill: var(--text-muted); font-family: var(--font); }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-candidate { stroke: var(--teal); }
.chart .series-buy_and_hold { stroke: var(--navy); }
.chart .series-cash { stroke: #9aa5b1; stroke-dasharray: 4 4; }
.chart .point { stroke: #fff; stroke-width: 1.5; }
.chart .point-candidate { fill: var(--teal); }
.chart .point-buy_and_hold { fill: var(--navy); }
.chart .point-cash { fill: #9aa5b1; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--text-muted); }
.legend-swatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend-swatch.candidate { background: var(--teal); }
.legend-swatch.buy_and_hold { background: var(--navy); }
.legend-swatch.cash { background: #9aa5b1; }

.curve-details { margin-top: 10px; }
.curve-details summary { cursor: pointer; color: var(--teal); font-weight: 500; }

/* Tables */
.table-wrap { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; min-width: 480px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: 12.5px; }
caption { text-align: left; padding: 0 0 6px; color: var(--text-muted); font-size: 12px; }

/* Lists */
.check-list { display: flex; flex-direction: column; gap: 8px; }
.check-item { display: flex; gap: 8px; align-items: flex-start; }
.check-mark { flex: 0 0 auto; width: 18px; height: 18px; border-radius: 50%; background: var(--teal-soft); color: var(--teal); font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-top: 1px; }
.check-text { display: flex; flex-direction: column; }
.check-text .mono { color: var(--text-muted); }

.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; }
.fact-false { color: var(--warn-text); font-weight: 600; }

.limits { display: flex; flex-direction: column; gap: 10px; }
.limit-item { padding-left: 12px; border-left: 2px solid var(--teal); }
.limit-raw { display: block; color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* Responsive */
@media (max-width: 900px) {
  .overview-grid { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dt { margin-top: 8px; }
}

@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: 0 0 auto; padding: 12px; }
  .run-list { max-height: 30vh; }
  .sidebar-foot { margin-top: 0; }
  .main { padding: 16px 12px 32px; }
  .page-title { font-size: 19px; }
  .topbar .btn { width: 100%; }
  .run-actions { width: 100%; }
  .run-actions .btn { flex: 1 1 auto; }
  .tabs { overflow-x: auto; }
}

/* Hidden states must win over grid/flex component display rules. */
[hidden] { display: none !important; }
.brand-name { font-size: 32px; }
.brand-sub { font-size: 16px; }
.sidebar-heading { font-size: 16px; text-transform: none; letter-spacing: 0; color: #ecf3f7; }
.page-title { font-size: 30px; letter-spacing: -.025em; }
.run-title { font-size: 23px; }
h3 { font-size: 17px; }
.metric { border: 0; border-radius: 0; border-right: 1px solid var(--line); background: transparent; padding: 12px 16px; }
.metric:last-child { border-right: 0; }
.metric-label { font-size: 13px; text-transform: none; letter-spacing: 0; }
.metric-value { font-size: 27px; color: var(--navy); }
.metric.is-halted .metric-value { color: var(--navy); }
.orders-preview { margin-top: 16px; }
.series-buy_and_hold { stroke: #327bea !important; }
.point-buy_and_hold { fill: #327bea !important; }
.legend-swatch.buy_and_hold { background: #327bea; }
@media (max-width: 640px) {
  .page-title { font-size: 23px; }
  .metric-value { font-size: 23px; }
  .metric:nth-child(2) { border-right: 0; }
}

@media (min-width: 1100px) {
  .run-view { gap: 12px; }
  .metric { padding: 8px 16px; }
  .metric-note { max-width: 23ch; }
  .chart svg { max-height: 260px; }
  .overview-grid { grid-template-columns: minmax(0, 2.15fr) minmax(290px, 1fr); }
}
tbody th { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); }

/* ---------- View navigation (paper runs / historical research) ---------- */
.view-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.view-tab[aria-pressed="true"] { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-dark); }
/* The synthetic-run action and the saved-run list belong to the paper section only. */
body[data-view="research"] #new-run, body[data-view="home"] #new-run { display: none; }
.paper-view { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Historical research section ---------- */
.research-view { display: flex; flex-direction: column; gap: 14px; }
.research-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); gap: 14px; align-items: start; }
.history-help { margin-bottom: 12px; }
.history-error {
  background: var(--error-bg); color: var(--error-text);
  border: 1px solid #f3c6c6; border-radius: var(--radius);
  padding: 8px 12px; font-weight: 500;
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span:first-child { font-size: 12px; color: var(--text-muted); }
.field-wide { grid-column: 1 / -1; }
.field input[type="text"], .field input[type="search"], .field select {
  font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); width: 100%; min-width: 0;
}
.field input[inputmode="decimal"], .field input[inputmode="numeric"], .field input[placeholder^="20"] { font-family: var(--mono); font-size: 12.5px; }
.field input[type="file"] { font: inherit; padding: 4px 0; }
.field select:disabled, .field input:disabled { opacity: 0.6; }

.fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; margin: 12px 0; display: flex; flex-direction: column; gap: 10px; }
.fieldset legend { font-weight: 600; padding: 0 4px; }
.fieldset:disabled { opacity: 0.55; }

.check { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; cursor: pointer; }
.check input { margin-top: 3px; flex: 0 0 auto; }
.research-view .run-actions { margin-top: 12px; }

.history-results { display: flex; flex-direction: column; gap: 14px; }
.history-results .metrics { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.result-block h4 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.history-results .limit-item { color: var(--text-muted); font-size: 12px; }

@media (max-width: 900px) {
  .research-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .view-nav { width: 100%; }
  .view-nav .btn { flex: 1 1 42%; width: auto; }
  .form-grid { grid-template-columns: 1fr; }
}

body[data-view="research"] .sidebar-section, body[data-view="home"] .sidebar-section { display: none; }
.research-view, .history-results, .result-block, .research-grid > .card { min-width: 0; max-width: 100%; }
.fieldset { min-inline-size: 0; }
.field input[type="file"] { max-width: 100%; }
@media (max-width: 900px) { .research-grid { grid-template-columns: minmax(0, 1fr); } }

.history-results .metrics { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.history-results .metric-value { font-size: 22px; overflow-wrap: anywhere; word-break: normal; }

.research-view td.mono, .research-view th { white-space: nowrap; word-break: normal; }

/* ---------- Corporate actions: mode selector, preview and event tables ---------- */
.mode-group { display: flex; flex-direction: column; gap: 2px; }
.mode-group .check { margin: 4px 0; }
.mode-group input[type="radio"] { accent-color: var(--teal); }
.check input[type="checkbox"] { accent-color: var(--teal); }
#history-actions-mode .history-help { margin: 4px 0 8px; }
#history-actions-mode .field { margin-bottom: 4px; }

.events-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.events-block { min-width: 0; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); }
.events-block h5 { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--navy); }
.events-block .table-wrap { margin-top: 4px; }
.receivable-note { color: var(--warn-text); }

/* Tables inside the research view scroll within their card instead of
 * widening the page; the wrapper, not the table, owns the horizontal scroll. */
.research-view .table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.research-view .table-wrap table caption { white-space: normal; }
.history-results .result-block, .history-results .overview-grid > .result-block { min-width: 0; }

@media (max-width: 720px) {
  .events-block { padding: 8px; }
  .research-view th, .research-view td { padding: 6px 8px; }
}

/* Long provenance keys must not consume the entire value column. */
.research-view .facts { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.research-view .facts dt { overflow-wrap: anywhere; }
@media (max-width: 900px) { .research-view .facts { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Home / welcome ---------- */
.home-view { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 14px; }
.home-card { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.home-card h3 { margin-bottom: 0; }
.home-card .btn { align-self: flex-start; margin-top: auto; }
.quick-start { padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }
.quick-start li { list-style: decimal; }
.home-view .run-actions { margin-top: 12px; }

/* ---------- Research steps (Data -> Configure -> Results) ---------- */
.steps { min-width: 0; }
.step-list { display: flex; gap: 8px; flex-wrap: wrap; }
.step-tab {
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); color: var(--text-muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px 5px 5px;
}
.step-tab:not(:disabled):hover { background: var(--bg); }
.step-tab:disabled { opacity: 0.55; cursor: not-allowed; }
.step-tab[aria-current="step"] { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-dark); }
.step-num {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
  background: var(--navy); color: #fff; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}
.step-tab[aria-current="step"] .step-num { background: var(--teal); }
.step-panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.step-heading { font-size: 15px; font-weight: 600; color: var(--text-muted); }
.data-grid { grid-template-columns: minmax(280px, 1fr) minmax(0, 1.6fr); }
.research-view .template-actions { margin-top: 0; margin-bottom: 8px; }
.disclosure { margin: 8px 0; }
.disclosure summary { cursor: pointer; color: var(--teal); font-weight: 500; }
.disclosure .history-help { margin: 8px 0 4px; }
.config-heading { margin: 14px 0 8px; font-size: 14px; font-weight: 600; }
.step-actions { justify-content: flex-start; }
#history-dataset-summary { margin-bottom: 8px; }
.result-summary {
  font-size: 15px; line-height: 1.5; color: var(--navy);
  background: var(--teal-soft); border: 1px solid #c9e4e0; border-radius: var(--radius);
  padding: 12px 14px; overflow-wrap: anywhere;
}

/* ---------- Saved experiments ---------- */
.saved-toolbar { grid-template-columns: minmax(200px, 1fr) minmax(0, 2fr); }
.saved-toolbar .field-wide { grid-column: auto; }
@media (max-width: 900px) {
  .data-grid { grid-template-columns: minmax(0, 1fr); }
  .saved-toolbar { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Help dialog (native <dialog>, no external assets) ---------- */
.help-dialog {
  border: 0; padding: 0; color: var(--text);
  width: min(720px, calc(100vw - 32px)); max-width: none;
  max-height: calc(100vh - 32px); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(20, 38, 52, 0.35); background: var(--surface);
}
.help-dialog::backdrop { background: rgba(20, 38, 52, 0.55); }
.help-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 20px; background: var(--navy); color: #fff;
}
.help-head h2 { color: #fff; }
.help-head .btn { background: transparent; color: #fff; border-color: var(--navy-line); }
.help-head .btn:not(:disabled):hover { background: var(--navy-soft); }
.help-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 14px; overflow: auto; max-height: calc(100vh - 32px - 60px); }
.help-body h3 { margin-bottom: 4px; }
.help-body p + p { margin-top: 6px; }
.help-list { padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.help-list li { list-style: disc; }
@media (max-width: 720px) {
  .help-head { padding: 12px 14px; }
  .help-body { padding: 12px 14px 16px; }
}
