/* ============================================================
 * u25-dashboard — terminal-style dark theme
 * Dependency-free. Mobile-friendly. CSS Grid layout.
 * ============================================================ */

:root {
  --bg-0: #07090c;
  --bg-1: #0b0f14;
  --bg-2: #11161d;
  --bg-3: #161d27;
  --line: #1f2731;
  --line-2: #2a3340;
  --text: #e6edf3;
  --muted: #7c8898;
  --muted-2: #5b6573;

  --green: #2ecc71;
  --green-dim: #1e7a44;
  --yellow: #e4c441;
  --yellow-dim: #8a7a1a;
  --red: #ff5c5c;
  --red-dim: #8a2222;
  --blue: #58a6ff;
  --magenta: #b07cff;

  --accent: #2ee6c5;
  --accent-dim: #126b5e;

  --mono: "JetBrains Mono", "SFMono-Regular", "Menlo", "Monaco", Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;

  --radius: 8px;
  --pad: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body.theme-terminal {
  font-family: var(--sans);
  background:
    radial-gradient(1100px 600px at 80% -10%, #112030 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 0%, #08152a 0%, transparent 55%),
    var(--bg-0);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  min-height: 100vh;
}

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

button, input {
  font: inherit;
  color: inherit;
}

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 10px 50px rgba(0,0,0,0.5);
}
.login-card h1 {
  font-family: var(--mono);
  font-size: 18px;
  margin: 0 0 6px;
  color: var(--accent);
  letter-spacing: 1px;
}
.login-card .lead, .login-sub { color: var(--muted); margin: 0 0 18px; font-size: 12px; }
.login-header { margin-bottom: 16px; }
.login-header .brand-mark { display: block; margin-bottom: 8px; font-size: 22px; }
.login-card form, .login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form label { color: var(--muted); font-size: 11px; font-family: var(--mono); letter-spacing: 1px; text-transform: uppercase; }
.login-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; gap: 8px; flex-wrap: wrap; }
.login-footer .muted { font-size: 10px; font-family: var(--mono); }
.login-card input {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
  background: var(--accent);
  color: #04181a;
  font-weight: 600;
  border: 0;
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
}
.login-card button:hover { filter: brightness(1.1); }
.login-card .err, .login-error {
  background: rgba(255,92,92,0.1);
  border: 1px solid var(--red-dim);
  color: var(--red);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
}

/* ---------- Top bar ---------- */
.top-bar {
  display: grid;
  grid-template-columns: minmax(220px, auto) 1fr minmax(320px, auto);
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: 2px;
}
.brand-name { color: var(--muted); font-size: 12px; }

.bot-health {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.5px;
  justify-self: center;
  transition: all 200ms ease;
}
.bot-health .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green), 0 0 14px var(--green-dim);
  animation: pulse 1.4s ease-in-out infinite;
}
.bot-health-green { border-color: var(--green-dim); }
.bot-health-yellow { border-color: var(--yellow-dim); }
.bot-health-yellow .dot { background: var(--yellow); box-shadow: 0 0 6px var(--yellow), 0 0 14px var(--yellow-dim); }
.bot-health-red { border-color: var(--red-dim); }
.bot-health-red .dot { background: var(--red); box-shadow: 0 0 6px var(--red), 0 0 14px var(--red-dim); }
.bh-label { color: var(--muted); }
.bh-verdict { color: var(--text); font-weight: 700; }
.bh-reason { color: var(--muted); font-style: normal; }
.bh-meta { color: var(--muted-2); margin-left: 8px; }

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.7; }
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: end;
}
.top-actions input[type="text"] {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 6px 10px;
  width: 180px;
  font-family: var(--mono);
  font-size: 11px;
}
.top-actions input:focus { outline: none; border-color: var(--accent); }
.top-actions button.primary {
  background: linear-gradient(180deg, #2ee6c5, #19a98e);
  color: #03161a;
  font-weight: 700;
  border: 0;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--mono);
  letter-spacing: 1px;
}
.top-actions button.primary:hover { filter: brightness(1.1); }
.top-actions button.primary:disabled { opacity: 0.5; cursor: wait; }
.user-tag { font-family: var(--mono); font-size: 11px; }
.logout { color: var(--muted); font-size: 11px; }

/* ---------- Grid layout ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  padding: 14px;
}
.panel {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 160px;
  overflow: hidden;
}
.panel > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.panel h2 {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 1px;
  color: var(--text);
  text-transform: uppercase;
}
.src { font-family: var(--mono); font-size: 10px; }
.muted { color: var(--muted); }

/* Span definitions */
.panel-money    { grid-column: span 4; }
.panel-trades   { grid-column: span 8; min-height: 260px; }
.panel-health   { grid-column: span 8; min-height: 220px; }
.panel-cycle    { grid-column: span 4; min-height: 220px; }
.panel-ssh      { grid-column: span 6; min-height: 220px; }
.panel-learning { grid-column: span 6; min-height: 220px; }
.panel-policy   { grid-column: span 4; }
.panel-backtest { grid-column: span 8; }
.panel-scanner  { grid-column: span 8; }
.panel-agent    { grid-column: span 4; min-height: 280px; }
.panel-credits  { grid-column: span 4; }
.panel-sandbox  { grid-column: span 8; }

@media (max-width: 1100px) {
  .panel-money, .panel-trades, .panel-health, .panel-cycle,
  .panel-ssh, .panel-learning, .panel-policy, .panel-backtest,
  .panel-scanner, .panel-agent, .panel-credits, .panel-sandbox {
    grid-column: span 12;
  }
}

/* ---------- Money panel ---------- */
.big-stat { display: flex; flex-direction: column; gap: 2px; }
.big-label { color: var(--muted); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; font-family: var(--mono); }
.big-value {
  font-family: var(--mono);
  font-size: 36px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: color 200ms ease;
}
.big-value.flash-up { color: var(--green); }
.big-value.flash-down { color: var(--red); }
.big-sub { font-family: var(--mono); font-size: 12px; }
.big-sub.up { color: var(--green); }
.big-sub.down { color: var(--red); }

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
}
.kv-grid > div {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--line);
  padding: 4px 0;
}
.kv-grid .k { color: var(--muted); }
.kv-grid .v { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Trades tape ---------- */
.trades-head, .signals-head {
  display: grid;
  grid-template-columns: 90px 80px 60px 60px 100px 90px 110px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding: 4px 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.signals-head { grid-template-columns: 90px 80px 130px 60px 80px 70px; }
.trades-tape, .signals-tape {
  font-family: var(--mono);
  font-size: 11px;
  overflow-y: auto;
  max-height: 240px;
  display: flex;
  flex-direction: column-reverse;
}
.trade-row, .signal-row {
  display: grid;
  grid-template-columns: 90px 80px 60px 60px 100px 90px 110px;
  padding: 3px 0;
  border-bottom: 1px solid var(--bg-2);
  animation: slide-in 350ms ease;
  font-variant-numeric: tabular-nums;
}
.signal-row { grid-template-columns: 90px 80px 130px 60px 80px 70px; }
.trade-row .side-buy, .signal-row .dir-long { color: var(--green); }
.trade-row .side-sell, .signal-row .dir-short { color: var(--red); }
.trade-row .status-filled { color: var(--green); }
.trade-row .status-rejected { color: var(--red); }
.trade-row .status-new, .trade-row .status-canceled { color: var(--yellow); }
.trade-row .venue { color: var(--muted); }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-4px); background: rgba(46,230,197,0.08); }
  to { opacity: 1; transform: translateY(0); background: transparent; }
}

/* ---------- Health grid (module dials) ---------- */
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}
.dial {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--mono);
  font-size: 10px;
  position: relative;
  transition: border-color 200ms ease;
}
.dial.green { border-color: var(--green-dim); }
.dial.yellow { border-color: var(--yellow-dim); }
.dial.red { border-color: var(--red-dim); }
.dial .dial-top {
  display: flex; align-items: center; justify-content: space-between;
}
.dial .name { color: var(--text); font-weight: 600; letter-spacing: 0.5px; }
.dial .mode {
  font-size: 9px; padding: 1px 5px; border-radius: 999px;
  background: var(--bg-3); color: var(--muted); border: 1px solid var(--line-2);
}
.dial .mode.live { color: var(--accent); border-color: var(--accent-dim); }
.dial .reason { color: var(--muted); font-style: normal; font-size: 10px; }
.dial .latency { color: var(--muted-2); font-size: 9px; }
.dial::before {
  content: ""; position: absolute; top: 6px; right: 8px;
  width: 6px; height: 6px; border-radius: 50%;
}
.dial.green::before  { background: var(--green); box-shadow: 0 0 5px var(--green); }
.dial.yellow::before { background: var(--yellow); box-shadow: 0 0 5px var(--yellow); }
.dial.red::before    { background: var(--red); box-shadow: 0 0 5px var(--red); }

/* ---------- Cycle trace ---------- */
.cycle-trace {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 240px;
}
.cycle-trace li {
  padding: 4px 8px;
  border-left: 2px solid var(--line-2);
  background: var(--bg-2);
  animation: slide-in 300ms ease;
}
.cycle-trace li.ok { border-left-color: var(--green); }
.cycle-trace li.warn { border-left-color: var(--yellow); }
.cycle-trace li.err { border-left-color: var(--red); }
.cycle-trace li .step { color: var(--accent); font-weight: 700; margin-right: 6px; }
.cycle-trace li .detail { color: var(--muted); }

/* ---------- Readouts (SSH, Learning Loop) ---------- */
.readout {
  background: #04070a;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  color: #c9d4e0;
  overflow-y: auto;
  max-height: 240px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.readout .line-ok { color: #9ce0b1; }
.readout .line-warn { color: var(--yellow); }
.readout .line-err { color: var(--red); }
.readout .line-info { color: var(--blue); }
.readout .ts { color: var(--muted-2); }

/* ---------- Policy bars ---------- */
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar {
  display: grid;
  grid-template-columns: 110px 1fr 50px;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10px;
}
.bar .lbl { color: var(--muted); }
.bar .track {
  background: var(--bg-2);
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  transition: width 250ms ease;
}
.bar.warn .fill { background: linear-gradient(90deg, var(--yellow), var(--red)); }
.bar .val { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Backtest table ---------- */
.bt-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 11px;
}
.bt-table th, .bt-table td {
  padding: 4px 8px;
  text-align: left;
  border-bottom: 1px solid var(--bg-2);
}
.bt-table th {
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--line);
}
.bt-table td { font-variant-numeric: tabular-nums; }
.bt-table td.status-ok { color: var(--green); }
.bt-table td.status-warn { color: var(--yellow); }
.bt-table td.status-err { color: var(--red); }
.bt-table tr.new-row { animation: slide-in 350ms ease; }

/* ---------- Agent ---------- */
.agent-history {
  flex: 1;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}
.agent-msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--bg-2);
  border-left: 2px solid var(--line-2);
  animation: slide-in 250ms ease;
}
.agent-msg .meta { color: var(--muted-2); font-size: 9px; }
.agent-msg .cmd { color: var(--accent); }
.agent-msg .reply { color: var(--text); margin-top: 2px; }
.agent-msg.err { border-left-color: var(--red); }
.agent-msg.err .reply { color: var(--red); }

.agent-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}
.agent-form input {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11px;
}
.agent-form input:focus { outline: none; border-color: var(--accent); }
.agent-form button {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
}
.agent-form button:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Sandbox tiles ---------- */
.sandbox-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}
.sb-tile {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11px;
}
.sb-tile .sb-name { color: var(--text); font-weight: 600; font-size: 10px; }
.sb-tile .sb-meta { color: var(--muted); font-size: 10px; margin-top: 4px; }
.sb-tile.ok { border-color: var(--green-dim); }

/* ---------- Footer ---------- */
.sim-footer {
  position: sticky;
  bottom: 0;
  background: var(--bg-1);
  border-top: 1px solid var(--line);
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 10px;
  z-index: 50;
}
.badge {
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 1px;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10px;
}
.badge-sim {
  background: rgba(228,196,65,0.08);
  border: 1px solid var(--yellow-dim);
  color: var(--yellow);
}
.badge-live {
  background: rgba(255,92,92,0.12);
  border: 1px solid var(--red-dim);
  color: var(--red);
  animation: pulse-red 1.5s ease-in-out infinite;
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,92,92,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(255,92,92,0); }
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }
