/* ============================================================
   Magpie dashboard — design-token stylesheet (#49 redesign).
   "Instrumentation for a quiet robot trader."
   Accent colour is reserved for meaning, never decoration.
   ============================================================ */

:root {
  /* palette */
  --bg:          #0a0c12;
  --surface:     #12151d;
  --surface-2:   #181c26;
  --border:      #252b3a;
  --border-soft: #1b2030;
  --text:        #e7e9ed;
  --text-muted:  #8a92a0;
  --text-dim:    #586072;
  --accent:      #45c8e0;
  --accent-ink:  #07222b;
  --pos:         #3fb950;
  --neg:         #f0584f;
  --warn:        #d6a13a;
  /* spacing */
  --s1: 4px;  --s2: 8px;  --s3: 12px;
  --s4: 16px; --s6: 24px; --s8: 32px;
  /* shape + type */
  --radius:    7px;
  --radius-sm: 4px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { color: var(--text); font-weight: 600; margin: 0; }
h1 { font-size: 20px; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

hr { border: 0; border-top: 1px solid var(--border-soft); margin: var(--s6) 0; }

::selection { background: rgba(69, 200, 224, 0.25); color: var(--text); }

/* ---------- header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--s6);
  height: 52px;
  padding: 0 var(--s4) 0 var(--s6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
}
.wordmark:hover { text-decoration: none; }
.wordmark-icon { height: 26px; width: auto; display: block; }

.app-nav {
  display: flex;
  align-items: center;
  gap: var(--s6);
  flex: 1;
}
.app-nav a {
  position: relative;
  color: var(--text-muted);
  font-size: 13px;
  padding: var(--s2) 0;
  text-decoration: none;
  transition: color 120ms ease;
}
.app-nav a:hover { color: var(--text); text-decoration: none; }
.app-nav a.active { color: var(--text); }
.app-nav a.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.logout-form { display: inline-flex; margin: 0; }
.logout-form button {
  background: none;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: var(--s1) var(--s2);
  transition: color 120ms ease;
}
.logout-form button:hover { color: var(--text); }

/* ---------- layout ---------- */
main {
  margin: 0 auto;
  padding: var(--s4) var(--s6) var(--s8);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  margin-bottom: var(--s4);
}
.page-head h1 { font-size: 20px; }
.page-head .page-head-controls {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

/* ---------- KPI strip ---------- */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--s3);
  margin-bottom: var(--s4);
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s3) var(--s4);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.kpi-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.kpi-value {
  font-size: clamp(20px, 1.8vw, 24px);
  font-weight: 500;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-delta {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}
.kpi-delta.pos { color: var(--pos); }
.kpi-delta.neg { color: var(--neg); }

/* ---------- panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel + .panel { margin-top: var(--s4); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.panel-head h2,
.panel-head .panel-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0;
}
.panel-head .panel-actions {
  display: flex;
  align-items: center;
  gap: var(--s3);
  font-size: 13px;
}

.panel-body { padding: var(--s4); }
.panel-body.flush { padding: 0; }

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: var(--s3);
}
.panel-grid + .panel-grid { margin-top: var(--s3); }
.panel-grid.even {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
@media (max-width: 860px) {
  .panel-grid { grid-template-columns: 1fr; }
}

/* ---------- tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
}
tbody td {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }

th.num, td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Tables inside a flush panel-body get rounded bottom corners visually
   because the .panel itself clips overflow. No further work needed. */

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

/* ---------- pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pill-pos {
  background: rgba(63, 185, 80, 0.12);
  color: var(--pos);
  border-color: rgba(63, 185, 80, 0.25);
}
.pill-neg {
  background: rgba(240, 88, 79, 0.12);
  color: var(--neg);
  border-color: rgba(240, 88, 79, 0.25);
}
.pill-warn {
  background: rgba(214, 161, 58, 0.12);
  color: var(--warn);
  border-color: rgba(214, 161, 58, 0.25);
}
.pill-muted {
  background: var(--surface-2);
  color: var(--text-muted);
  border-color: var(--border);
}

/* ---------- text helpers ---------- */
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-mono { font-family: var(--mono); }

/* ---------- empty state ---------- */
.empty {
  color: var(--text-muted);
  text-align: center;
  padding: var(--s8);
  font-size: 13px;
}

/* ---------- forms ---------- */
input[type="text"],
input[type="password"],
input[type="date"],
input[type="search"],
input[type="number"],
input[type="email"],
select,
textarea {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input::placeholder { color: var(--text-dim); }

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

label {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 120ms ease, transform 80ms ease;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); filter: none; }

.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-bottom: var(--s4);
}
.filter-bar .field {
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.filter-bar .clear {
  color: var(--text-muted);
  font-size: 13px;
  margin-left: var(--s2);
}
.filter-bar .clear:hover { color: var(--text); }

/* ---------- code / json ---------- */
pre.json,
pre.reasoning {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--s3) var(--s4);
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text);
  overflow-x: auto;
}

/* ---------- retros ---------- */
article.retro {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s4) var(--s6);
  margin-bottom: var(--s4);
}
article.retro .retro-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: var(--s3);
  margin-bottom: var(--s4);
}
article.retro .retro-head h3 {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
article.retro .retro-meta {
  display: flex;
  align-items: center;
  gap: var(--s3);
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.retro-md { color: var(--text); font-size: 14px; line-height: 1.6; }
.retro-md h2 {
  font-size: 15px;
  font-weight: 600;
  margin: var(--s6) 0 var(--s2);
  color: var(--text);
}
.retro-md h2:first-child { margin-top: 0; }
.retro-md h3 {
  font-size: 13px;
  font-weight: 600;
  margin: var(--s4) 0 var(--s2);
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.retro-md p { margin: 0 0 var(--s3); }
.retro-md ul, .retro-md ol { margin: 0 0 var(--s3); padding-left: var(--s6); }
.retro-md li { margin-bottom: var(--s1); }
.retro-md code {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 12.5px;
}
.retro-md strong { color: var(--text); }
.retro-md em { color: var(--text-muted); }

/* ---------- login ---------- */
.login-card {
  max-width: 360px;
  margin: 18vh auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s8) var(--s6);
  text-align: center;
}
.login-card .wordmark {
  justify-content: center;
  margin-bottom: var(--s6);
  font-size: 18px;
}
.login-card h1 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: var(--s4);
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.login-card input,
.login-card .btn {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
}
.login-error {
  color: var(--neg);
  font-size: 13px;
  margin-top: var(--s2);
}

/* ---------- chart canvas wrapper ---------- */
.chart-wrap {
  position: relative;
  height: 320px;
}
.chart-legend {
  display: flex;
  align-items: center;
  gap: var(--s4);
  font-size: 12px;
  color: var(--text-muted);
  padding: var(--s2) 0 0;
}
.chart-legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -1px;
}
.chart-legend .dot-buy { background: var(--pos); }
.chart-legend .dot-sell { background: var(--neg); }

/* ---------------- Trading Floor (/floor) ---------------- */
.floor-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: var(--s3);
  margin-top: var(--s4);
  /* Fit the viewport: total height minus header (~56px), page-head (~52px),
     and the main padding (top var(--s4) = 16px + bottom var(--s8) = 32px).
     Sidebar scrolls internally; chart panel stays in view. */
  height: calc(100vh - 56px - 52px - 16px - 32px);
  min-height: 480px;
}
@media (max-width: 900px) {
  .floor-layout {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
  }
}

/* sidebar */
.floor-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.floor-kpi-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s1);
  padding: var(--s2);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.floor-kpi { padding: var(--s1) var(--s2); }
.floor-kpi-label {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.floor-kpi-value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.floor-sym-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
}
.floor-sym-row {
  padding: var(--s2);
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-left: 3px solid transparent;
}
.floor-sym-row:hover { background: var(--surface-2); }
.floor-sym-position { border-left-color: var(--pos); }
.floor-sym-pending  { border-left-color: var(--warn); }
.floor-sym-closed   { border-left-color: var(--accent); opacity: 0.85; }
.floor-sym-cancelled{ border-left-color: var(--text-dim); opacity: 0.6; }
.floor-sym-rejected { border-left-color: var(--neg); opacity: 0.7; }
.floor-sym-watchlist{ border-left-color: var(--border-soft); }

/* #227 "traded today" — any row with fills today. The teal accent + tint win
   over the state-color left border (higher specificity: .floor-sym-row.traded-today
   is two classes vs the single-class .floor-sym-{state} rules). State stays
   legible via the pill text. */
.floor-sym-row.traded-today {
  border-left-color: var(--accent);
  background: rgba(69, 200, 224, 0.07);
}
/* Keep a hover affordance on traded rows — the tint above is same-specificity
   as .floor-sym-row:hover and later in source order, so it would otherwise
   swallow the hover state on exactly the rows a user most wants to click. */
.floor-sym-row.traded-today:hover { background: rgba(69, 200, 224, 0.13); }
.floor-sym-badge {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--accent);
  background: rgba(69, 200, 224, 0.12);
  padding: 1px 6px;
  border-radius: 9px;
  font-variant-numeric: tabular-nums;
}

.floor-sym-row-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.floor-sym-row-name { font-weight: 700; font-size: 13px; }
.floor-sym-row-state {
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}
.state-position { color: var(--pos); }
.state-pending  { color: var(--warn); }
.state-closed   { color: var(--accent); }
.state-cancelled{ color: var(--text-dim); }
.state-rejected { color: var(--neg); }

.floor-sym-row-price {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.floor-sym-row-last { font-size: 14px; font-variant-numeric: tabular-nums; }
.floor-sym-row-chg  { font-size: 11px; font-variant-numeric: tabular-nums; }
.floor-sym-row-chg.pos { color: var(--pos); }
.floor-sym-row-chg.neg { color: var(--neg); }
.floor-sym-row-pnl  { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.floor-sym-row-pnl.pos { color: var(--pos); }
.floor-sym-row-pnl.neg { color: var(--neg); }

/* chart area */
.floor-chart-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--s3);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  /* Override the global `main { margin: 0 auto }` rule that would otherwise
     center this grid item within its track when it's a <main> element. We
     switched to <section> to avoid the inheritance, but keep this guard. */
  margin: 0;
  width: 100%;
}
.floor-chart-panel { display: flex; flex-direction: column; height: 100%; gap: var(--s3); min-height: 0; }
.floor-chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.floor-chart-title { display: flex; align-items: baseline; gap: var(--s2); }
.floor-chart-sym { font-size: 26px; font-weight: 700; }
.floor-chart-state {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.floor-chart-price { text-align: right; }
.floor-chart-last { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.floor-chart-chg  { font-size: 14px; font-variant-numeric: tabular-nums; }
.floor-chart-chg.pos { color: var(--pos); }
.floor-chart-chg.neg { color: var(--neg); }

.floor-chart-canvas {
  flex: 1;
  min-height: 0;
  background: var(--bg);
  border-radius: var(--radius-sm);
  position: relative;
}

.floor-chart-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--bg);
  border-radius: var(--radius-sm);
  min-height: 0;
  padding: var(--s4);
}
.floor-chart-empty p { margin: var(--s1) 0; }

.floor-chart-meta {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--s2);
  padding-top: var(--s3);
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.floor-chart-meta-label {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 2px;
}
.floor-chart-meta-wide { grid-column: 1 / -1; }

/* OHLC + Volume hover tooltip — floats inside the chart container (#235). */
.floor-chart-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: rgba(13, 16, 22, 0.94);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}
.floor-chart-tip .tl { color: var(--text-muted); margin: 0 2px 0 6px; }
.floor-chart-tip .tl:first-child { margin-left: 0; }

.floor-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: var(--s8);
}

