/* PaperTrader — stark minimalist, accessible, responsive. */

:root {
  --ink: #000;
  --paper: #fff;
  --muted: #444;
  --line: #000;
  --green: #006400;
  --red: #8b0000;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}

h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 1.6rem; margin: 1.5rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }

a { color: var(--ink); }
a:hover { text-decoration-thickness: 2px; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 1rem; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 0.5rem 1rem;
  z-index: 10;
}
.skip-link:focus { left: 0; }

.site-header {
  border-bottom: 2px solid var(--line);
  background: var(--paper);
}
.header-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; align-items: baseline; padding: 0.75rem 1rem; }
.brand { font-size: 1.25rem; font-weight: 700; margin: 0; letter-spacing: 0.02em; }
.brand-sub { font-size: 0.85rem; font-weight: 400; color: var(--muted); }

.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
.nav a {
  display: inline-block;
  padding: 0.35rem 0.1rem;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  font-weight: 600;
}
.nav a:hover { border-bottom-color: var(--ink); }
.nav a[aria-current="page"] { border-bottom-color: var(--ink); }
.nav a:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

main { padding-bottom: 3rem; }

.status-line {
  min-height: 1.5rem;
  padding: 0.35rem 0;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.muted { color: var(--muted); }
.error { color: var(--red); font-weight: 600; }

/* KPI row */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); margin-bottom: 1.5rem; }
.kpi { background: var(--paper); padding: 0.75rem 1rem; }
.kpi-label { margin: 0; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.kpi-value { margin: 0.15rem 0 0; font-family: var(--mono); font-size: 1.5rem; font-weight: 700; }

/* Panels */
.panel { border: 1px solid var(--line); padding: 1rem; margin-bottom: 1.5rem; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 0.75rem; }
.panel-head h2 { margin: 0; }

/* Chart */
#chart-wrap { border: 1px solid var(--line); padding: 0.5rem; }
#equity-chart { width: 100%; height: auto; display: block; }
.chart-fallback { font-family: var(--mono); font-size: 0.85rem; margin: 0.5rem 0 0; }
.chart-stats { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; margin: 0.75rem 0 0; }
.chart-stats div { display: flex; gap: 0.5rem; font-family: var(--mono); font-size: 0.85rem; }
.chart-stats dt { color: var(--muted); }
.chart-stats dd { margin: 0; }

/* Key-value list */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.5rem 1.5rem; margin: 0 0 1rem; }
.kv div { display: flex; gap: 0.5rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }

/* Actions */
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* Buttons */
.btn {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: 0.55rem 1rem;
  min-height: 44px;
  cursor: pointer;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--paper); color: var(--ink); }
.btn-small { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 0.9rem; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; min-width: 640px; }
th, td { border-bottom: 1px solid var(--line); padding: 0.5rem 0.6rem; text-align: left; vertical-align: top; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
td.num, th.num { font-family: var(--mono); text-align: right; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

.up { color: var(--green); font-weight: 700; }
.down { color: var(--red); font-weight: 700; }
.flat { color: var(--muted); }
.tag { font-family: var(--mono); font-size: 0.8rem; border: 1px solid var(--ink); padding: 0.05rem 0.35rem; }

/* Trade dialog */
dialog {
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: 1.25rem;
  max-width: 480px;
  width: calc(100% - 2rem);
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
.dialog-form { display: flex; flex-direction: column; gap: 0.75rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field select, .field input {
  font-family: var(--sans);
  font-size: 1rem;
  padding: 0.5rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  min-height: 44px;
}
.field select:focus-visible, .field input:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

/* Footer */
.site-footer { border-top: 2px solid var(--line); padding: 1rem 0; font-size: 0.85rem; color: var(--muted); }

/* Prose */
.prose p { max-width: 65ch; }

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Responsive */
@media (max-width: 720px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: 1.35rem; }
  .kpi-value { font-size: 1.25rem; }
  .header-row { flex-direction: column; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

/* Bars (P&L, exposure) */
.bars { display: flex; flex-direction: column; gap: 0.4rem; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.5rem; align-items: center; font-size: 0.85rem; }
.bar-row .bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-value { font-family: var(--mono); white-space: nowrap; }
.bar-track { height: 14px; background: #eee; border: 1px solid var(--ink); }
.bar-fill { height: 100%; background: var(--ink); }
.bar-fill.neg { background: repeating-linear-gradient(45deg, var(--paper) 0 4px, #d9d9d9 4px 8px); border-right: 2px solid var(--ink); }
.bar-track .sr-only { position: absolute; }

/* Depth chart */
.depth-wrap { border: 1px solid var(--line); padding: 0.5rem; overflow-x: auto; }
#detail-depth svg { width: 100%; min-width: 420px; height: auto; display: block; }
.depth-legend { font-family: var(--mono); font-size: 0.8rem; margin: 0.4rem 0 0; }

/* Sparkline */
.spark-wrap { border: 1px solid var(--line); padding: 0.5rem; }
#detail-spark svg { width: 100%; height: auto; display: block; }
.spark-stats { display: flex; gap: 1rem; font-family: var(--mono); font-size: 0.8rem; margin: 0.4rem 0 0; }

/* Patterns */
.patterns { display: flex; flex-direction: column; gap: 0.6rem; max-height: 420px; overflow-y: auto; }
.pattern { border: 1px solid var(--line); padding: 0.5rem 0.6rem; font-size: 0.85rem; }
.pattern-head { display: flex; justify-content: space-between; gap: 0.5rem; font-family: var(--mono); }
.pattern p { margin: 0.25rem 0 0; }
.status-hypothesis { background: #fff; border: 1px solid var(--ink); padding: 0.05rem 0.35rem; font-size: 0.75rem; }
.status-tested { background: #eee; border: 1px solid var(--ink); padding: 0.05rem 0.35rem; font-size: 0.75rem; }
.status-confirmed { background: var(--ink); color: var(--paper); border: 1px solid var(--ink); padding: 0.05rem 0.35rem; font-size: 0.75rem; }
.status-refuted { background: var(--paper); color: var(--red); border: 1px solid var(--red); padding: 0.05rem 0.35rem; font-size: 0.75rem; }

textarea {
  font-family: var(--sans);
  font-size: 1rem;
  padding: 0.5rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  min-height: 88px;
  resize: vertical;
}
textarea:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
