:root {
  --bg: #0b0e12;
  --bg-2: #12161c;
  --bg-3: #1a2029;
  --fg: #e8edf4;
  --fg-dim: #9aa4b1;
  --border: #262d36;
  --accent: #5b9dff;
  --green: #2ecc71;
  --red: #ff5a5f;
  --amber: #ffb454;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --content-max: 1100px;
  --sidebar-w: 300px;
  --header-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); font-family: -apple-system, "Inter", sans-serif; }

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 10;
}
header h1 { margin: 0; font-size: 1.1rem; letter-spacing: .02em; }
header .subtitle { color: var(--fg-dim); margin-left: .75rem; font-size: .85rem; }
header .status {
  font-family: var(--mono); font-size: .8rem; color: var(--fg-dim);
  padding: .25rem .75rem; border: 1px solid var(--border); border-radius: 999px;
}
header .status.running { color: var(--amber); border-color: var(--amber); }
header .status.done { color: var(--green); border-color: var(--green); }
header .status.error { color: var(--red); border-color: var(--red); }

/* TWO-COLUMN LAYOUT
   left: sticky history sidebar  |  right: stacked content panels */
main {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 1rem;
  padding: 1.25rem 1.5rem 2rem;
  width: 100%;
}
.main-col {
  display: flex; flex-direction: column; gap: 1rem;
  min-width: 0;
  max-width: var(--content-max);
}
section.upload-panel,
section.market-card,
section.backtest-card,
section.results-panel,
section.history-panel {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.25rem;
}

aside.history-panel {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - 2rem);
  display: flex; flex-direction: column; min-height: 0;
}
.history-panel .history-head {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem;
}
.history-panel h2 { margin: 0; font-size: 1rem; }
.history-panel button.ghost {
  padding: .25rem .55rem; background: transparent; border: 1px solid var(--border);
  color: var(--fg-dim); font-size: .9rem; line-height: 1;
}
.history-panel button.ghost:hover { color: var(--fg); border-color: var(--accent); }
.history-list {
  display: flex; flex-direction: column; gap: .35rem;
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
}
.history-empty { color: var(--fg-dim); font-size: .85rem; margin: .25rem 0; }
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .15rem .75rem;
  padding: .55rem .75rem; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  font-family: var(--mono); font-size: .8rem;
}
.history-item:hover { border-color: var(--accent); }
.history-item.active { border-color: var(--accent); background: rgba(91,157,255,.07); }
.history-item .h-decision { grid-column: 1; grid-row: 1; font-weight: 700; }
.history-item .h-when     { grid-column: 2; grid-row: 1; justify-self: end; }
.history-item .h-symbol   { grid-column: 1; grid-row: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .h-meta     { grid-column: 2; grid-row: 2; justify-self: end; }
.history-item .h-decision.LONG { color: var(--green); }
.history-item .h-decision.SHORT { color: var(--red); }
.history-item .h-decision.FLAT { color: var(--fg-dim); }
.history-item .h-symbol { color: var(--fg); }
.history-item .h-meta { color: var(--fg-dim); font-size: .72rem; white-space: nowrap; }
.history-item .h-when { color: var(--fg-dim); font-size: .72rem; white-space: nowrap; }

.dropzone {
  border: 2px dashed var(--border); border-radius: 10px;
  min-height: 140px; display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, background .15s; cursor: pointer;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: rgba(91,157,255,.05); }
.dropzone-inner { text-align: center; color: var(--fg-dim); }
.dropzone .big { color: var(--fg); margin: 0; }
.dropzone .small { margin: .25rem 0; }
.dropzone .hint { font-size: .8rem; color: var(--fg-dim); margin-top: .5rem; }
.file-button {
  display: inline-block; padding: .5rem 1rem; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer; color: var(--fg);
}
.file-button input { display: none; }

.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .5rem; margin: 1rem 0; }
.preview {
  position: relative; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: .25rem; overflow: hidden;
}
.preview img { display: block; width: 100%; height: 100px; object-fit: cover; border-radius: 4px; }
.preview .name { font-size: .7rem; color: var(--fg-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: .25rem; }
.preview button {
  position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.65);
  color: var(--fg); border: none; border-radius: 4px; padding: 2px 6px; cursor: pointer; font-size: .75rem;
}

/* Symbol + as-of date row */
.form-grid { display: grid; grid-template-columns: 2fr 1fr; gap: .75rem; margin-bottom: .75rem; }
.form-grid .form-row { margin-bottom: 0; }
.form-grid .form-row.hidden { display: none; }

.form-row { margin-bottom: .75rem; }
.form-row label { display: block; font-size: .85rem; color: var(--fg-dim); margin-bottom: .25rem; }
.form-row input, .form-row textarea {
  width: 100%; background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px;
  color: var(--fg); padding: .5rem .75rem; font: inherit;
}
.form-row textarea { resize: vertical; font-family: var(--mono); font-size: .85rem; }
.form-row .hint { color: var(--fg-dim); font-weight: 400; font-size: .75rem; }

.actions { display: flex; gap: .5rem; margin-top: 1rem; }
button {
  padding: .55rem 1rem; border: 1px solid var(--border); background: var(--bg-3); color: var(--fg);
  border-radius: 8px; cursor: pointer; font: inherit;
}
button.primary { background: var(--accent); color: #0a0f18; border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Timeline — full-width, ample message column */
.results-panel h2 { margin: 0 0 .75rem 0; font-size: 1rem; }
.timeline { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.timeline .event {
  display: grid; grid-template-columns: 140px 1fr auto; gap: 1rem;
  padding: .65rem .9rem; background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px;
  font-family: var(--mono); font-size: .85rem; line-height: 1.4;
  align-items: start;
}
.timeline .stage { color: var(--fg-dim); white-space: nowrap; }
.timeline .message { white-space: pre-wrap; word-break: break-word; min-width: 0; }
.timeline .badge { padding: 0 .5rem; border-radius: 4px; font-size: .75rem; font-weight: 600; height: fit-content; }
.timeline .LONG  { background: rgba(46,204,113,.18); color: var(--green); }
.timeline .SHORT { background: rgba(255,90,95,.18); color: var(--red); }
.timeline .FLAT  { background: rgba(154,164,177,.18); color: var(--fg-dim); }

.judgment-card, .market-card, .backtest-card { border-radius: 10px; }
.judgment-card { background: var(--bg-3); border: 1px solid var(--border); padding: 1rem; }
.judgment-card.hidden, .market-card.hidden, .backtest-card.hidden, .form-row.hidden, .sltp.hidden { display: none; }

.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tabs.sub-tabs { margin-top: -.5rem; margin-bottom: 1rem; }
.tabs.sub-tabs .tab { font-size: .85rem; padding: .35rem .85rem; }
.tabs .tab {
  background: transparent; border: none; color: var(--fg-dim);
  padding: .5rem 1rem; border-bottom: 2px solid transparent; border-radius: 0;
  font: inherit; cursor: pointer;
}
.tabs .tab.active { color: var(--fg); border-bottom-color: var(--accent); }

.backtest-card h2 { margin: 0 0 .5rem 0; font-size: 1rem; }
.backtest-card .decision.correct { color: var(--green); }
.backtest-card .decision.wrong   { color: var(--red); }
.backtest-card .decision.pending { color: var(--fg-dim); }
.market-card h2 { margin: 0 0 .75rem 0; font-size: 1rem; display: flex; align-items: center; gap: .5rem; }
.market-card .frame-pill {
  font-size: .7rem; color: var(--fg-dim); border: 1px solid var(--border);
  padding: .15rem .5rem; border-radius: 999px; font-weight: 400;
}
.market-card details { margin-top: .75rem; }
.market-card summary { cursor: pointer; color: var(--fg-dim); font-size: .8rem; }
.market-card pre {
  max-height: 420px; overflow: auto; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: .75rem;
  font-family: var(--mono); font-size: .75rem; white-space: pre; color: var(--fg);
  margin-top: .5rem;
}
.sltp { margin-top: 1rem; padding: .75rem 1rem; background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; }
.sltp h3 { margin: 0 0 .5rem 0; font-size: .85rem; color: var(--fg); display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.sltp h3 .hint { font-weight: 400; color: var(--fg-dim); font-size: .7rem; }
.judgment-card h2 { margin: 0 0 .5rem 0; font-size: 1rem; }
.judgment-card h3 { font-size: .85rem; color: var(--fg-dim); margin: 1rem 0 .5rem; }
.decision { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; margin-bottom: .5rem; }
.decision.LONG { color: var(--green); }
.decision.SHORT { color: var(--red); }
.decision.FLAT { color: var(--fg-dim); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: .25rem .75rem; font-family: var(--mono); font-size: .85rem; margin: 0; }
.kv dt { color: var(--fg-dim); }
.kv dd { margin: 0; word-break: break-word; }
.reasoning { font-size: .9rem; color: var(--fg); white-space: pre-wrap; }

ul#failures { padding-left: 1.25rem; margin: 0; }
ul#failures li { font-size: .85rem; color: var(--fg); }

footer {
  text-align: center; color: var(--fg-dim); font-size: .75rem;
  padding: .75rem 1rem; border-top: 1px solid var(--border); background: var(--bg-2);
}

/* Compact view on narrow screens */
@media (max-width: 960px) {
  main { grid-template-columns: 1fr; }
  aside.history-panel {
    position: static; max-height: 280px;
  }
}
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .timeline .event { grid-template-columns: 110px 1fr; row-gap: .35rem; }
  .timeline .badge { grid-column: 2; justify-self: start; }
  .kv { grid-template-columns: 130px 1fr; }
}
