:root {
  color-scheme: dark;
  --bg: #0f1114;
  --panel: #171b20;
  --panel-2: #1e242b;
  --line: #303842;
  --text: #edf2f7;
  --muted: #95a0ad;
  --green: #47d18c;
  --red: #ff6464;
  --amber: #f4b942;
  --cyan: #4db7d8;
  --ink: #101318;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
.boot { padding: 24px; color: var(--muted); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: rgba(15, 17, 20, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand-block { display: flex; align-items: baseline; gap: 10px; min-width: 260px; }
.brand { font-weight: 800; font-size: 18px; letter-spacing: 0; }
.subtle { color: var(--muted); }
.status-line { display: flex; align-items: center; gap: 10px; color: var(--muted); flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel);
  white-space: nowrap;
}
.pill.good { color: var(--green); border-color: rgba(71,209,140,.35); background: rgba(71,209,140,.08); }
.pill.warn { color: var(--amber); border-color: rgba(244,185,66,.35); background: rgba(244,185,66,.08); }
.pill.bad { color: var(--red); border-color: rgba(255,100,100,.35); background: rgba(255,100,100,.08); }
.shell { padding: 18px; max-width: 1720px; margin: 0 auto; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--panel);
  cursor: pointer;
}
.tab.active { color: var(--text); background: var(--panel-2); border-color: #54616f; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
}
.card.pad { padding: 14px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}
.card-title { font-weight: 750; color: var(--text); }
.card-body { padding: 12px 14px 14px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.metric { display: flex; flex-direction: column; gap: 4px; }
.metric-label { color: var(--muted); font-size: 12px; }
.metric-value { font-size: 24px; font-weight: 800; letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-note { color: var(--muted); min-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.good-text { color: var(--green); }
.bad-text { color: var(--red); }
.warn-text { color: var(--amber); }
.cyan-text { color: var(--cyan); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; }
.mini-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.mini {
  min-width: 0;
  border: 1px solid rgba(48,56,66,.75);
  border-radius: 7px;
  padding: 10px;
  background: rgba(255,255,255,.02);
}
.mini .metric-value { font-size: 20px; }
.panel {
  min-width: 0;
  border: 1px solid rgba(48,56,66,.75);
  border-radius: 7px;
  background: rgba(255,255,255,.02);
  overflow: hidden;
}
.panel-head {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid rgba(48,56,66,.75);
  color: var(--text);
  font-weight: 700;
}
.stat { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid rgba(48,56,66,.65); padding-bottom: 6px; min-width: 0; }
.stat span:first-child { color: var(--muted); white-space: nowrap; }
.stat span:last-child { font-weight: 700; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { overflow: auto; max-height: 420px; }
table { width: 100%; border-collapse: collapse; min-width: 620px; }
th, td { padding: 8px 10px; border-bottom: 1px solid rgba(48,56,66,.7); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 650; font-size: 12px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
td { color: var(--text); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; }
.small { font-size: 12px; }
.truncate { max-width: 340px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar {
  height: 8px;
  border-radius: 999px;
  background: #2a313a;
  overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--cyan); width: 0; }
.pnl-chart {
  display: grid;
  gap: 8px;
  padding: 12px;
}
.pnl-svg {
  display: block;
  width: 100%;
  height: 260px;
  border: 1px solid rgba(48,56,66,.75);
  border-radius: 7px;
  background: rgba(255,255,255,.018);
}
.pnl-axis { stroke: rgba(149,160,173,.38); stroke-width: .7; }
.pnl-zero { stroke: rgba(237,242,247,.24); stroke-width: .8; stroke-dasharray: 4 4; }
.pnl-fill { fill: rgba(77,183,216,.08); }
.pnl-line,
.pnl-cashflow-line {
  fill: none;
  stroke-width: 2.2;
  vector-effect: non-scaling-stroke;
}
.pnl-line { stroke: var(--cyan); }
.pnl-cashflow-line { stroke: rgba(244,185,66,.85); stroke-dasharray: 5 5; }
.pnl-dot { stroke: var(--panel); stroke-width: 1.5; }
.pnl-dot.good { fill: var(--green); }
.pnl-dot.bad { fill: var(--red); }
.pnl-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-line {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 2px solid var(--cyan);
}
.legend-line.cashflow { border-top-color: rgba(244,185,66,.85); border-top-style: dashed; }
.empty-chart {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px solid rgba(48,56,66,.75);
  border-radius: 7px;
  background: rgba(255,255,255,.018);
}
.template-note {
  margin-bottom: 12px;
  color: var(--muted);
}
.source-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.source {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: rgba(255,255,255,.02);
}
.source-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.recent-list { display: grid; gap: 8px; }
.recent-item {
  padding: 9px 10px;
  border: 1px solid rgba(48,56,66,.65);
  border-radius: 7px;
  background: rgba(255,255,255,.02);
}
.recent-item .line { display: flex; justify-content: space-between; gap: 10px; }
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login {
  width: min(380px, 100%);
  display: grid;
  gap: 12px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.login h1 { margin: 0 0 6px; font-size: 22px; }
.login input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--ink);
  color: var(--text);
  padding: 0 10px;
}
.login button {
  min-height: 40px;
  border: 1px solid #2f7d58;
  background: #215f43;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}
.login-error { color: var(--red); }
body.template-research .ops-only,
body.template-capital .ops-only { display: none; }
body.template-ops .research-priority { order: 5; }
body.template-research .research-priority { grid-column: span 12; order: -3; }
body.template-research .research-wide { grid-column: span 8; }
body.template-capital .capital-priority { grid-column: span 12; order: -3; }
body.template-capital .capital-wide { grid-column: span 8; }
body.template-pnl .pnl-priority { grid-column: span 12; order: -3; }
body.template-alerts .alerts-priority { grid-column: span 12; order: -3; }
@media (max-width: 1100px) {
  .span-2, .span-3, .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 6; }
  .source-grid { grid-template-columns: 1fr; }
  .pnl-svg { height: 230px; }
}
@media (max-width: 720px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .status-line { justify-content: flex-start; }
  .shell { padding: 12px; }
  .span-2, .span-3, .span-4, .span-5, .span-6, .span-7, .span-8, .span-12 { grid-column: span 12; }
  .stats { grid-template-columns: 1fr; }
  .mini-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-value { font-size: 21px; }
  .pnl-chart { padding: 10px; }
  .pnl-svg { height: 210px; }
}
