/* crypto-bot admin console.
   Dark, dense, and entirely self-hosted: the CSP forbids every external
   origin, so no webfonts, no CDN, no icon set. System stack only.
   Layout is fluid throughout and collapses to a single column under 720px,
   because the kill switch has to be usable one-handed from a phone. */

:root {
  --bg:      #0d1117;
  --panel:   #151b23;
  --panel-2: #1c232d;
  --line:    #2a323d;
  --text:    #d6dde6;
  --dim:     #7d8896;
  --accent:  #4b9fd5;
  --ok:      #3fb950;
  --warn:    #d29922;
  --bad:     #f0574d;
  --live:    #e5484d;
  --radius:  6px;
  --tap:     44px;   /* minimum touch target */
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
}

code, .mono, td, th, .v, .feed-ts {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
}

h1, h2, h3 { font-weight: 600; line-height: 1.25; }
h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: .02em; }
h3 { font-size: 13px; margin: 0 0 6px; text-transform: uppercase;
     letter-spacing: .06em; color: var(--dim); }

a { color: var(--accent); }
.dim { color: var(--dim); font-weight: 400; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

.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;
}

/* ---------- mode accent -------------------------------------------------
   The one mistake that costs real money is acting on a LIVE bot believing it
   is paper. The accent bar spans the full viewport at every width. */
.accent { height: 4px; background: var(--panel-2); }
body.mode-live .accent { height: 6px; background: var(--live); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; margin-right: auto; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }

.badge {
  display: inline-block; padding: 5px 10px; border-radius: var(--radius);
  font-size: 12px; font-weight: 700; letter-spacing: .07em;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--dim);
  white-space: nowrap;
}
.badge-mode { color: var(--text); }
body.mode-live .badge-mode {
  background: var(--live); border-color: var(--live); color: #fff;
  font-size: 14px; padding: 6px 14px;
}
body.mode-paper .badge-mode { border-color: var(--accent); color: var(--accent); }
.badge-on  { color: var(--ok);  border-color: rgba(63,185,80,.45); }
.badge-off { color: var(--warn); border-color: rgba(210,153,34,.45); }
.badge-live-ok      { color: var(--ok); }
.badge-live-warn    { color: var(--warn); }
.badge-live-bad     { color: #fff; background: var(--bad); border-color: var(--bad); }
.badge-live-unknown { color: var(--dim); }

main { max-width: 1180px; margin: 0 auto; padding: 16px; }

/* ---------- messages ---------- */
.flash, .alert {
  padding: 12px 14px; border-radius: var(--radius); margin: 0 0 14px;
  border: 1px solid var(--line); background: var(--panel);
  border-left-width: 4px;
}
.flash-ok,  .alert-ok   { border-left-color: var(--ok); }
.flash-err, .alert-bad  { border-left-color: var(--bad); }
.alert-warn { border-left-color: var(--warn); }

/* ---------- stat grid ---------- */
.stats {
  display: grid; gap: 10px; margin: 0 0 16px;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
           color: var(--dim); }
.stat .v { font-size: 22px; font-weight: 600; line-height: 1.2; }
.stat .s { font-size: 11px; color: var(--dim); }
.stat-hot { border-color: var(--warn); }
.stat-hot .s { color: var(--warn); }

/* ---------- panels ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 0 0 16px;
}
.note { font-size: 12px; color: var(--dim); margin: 0 0 10px; }
.empty { color: var(--dim); font-style: italic; margin: 0; }

/* ---------- controls ---------- */
.controls {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}
.control {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; min-width: 0;
}
.inline { margin: 0; }

input[type=text], input[type=email], input[type=password] {
  display: block; width: 100%; min-height: var(--tap);
  padding: 10px 12px; margin: 0 0 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  /* 16px minimum: anything smaller makes iOS Safari zoom on focus. */
  font-size: 16px;
}
input:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); min-width: var(--tap); padding: 10px 16px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer; width: 100%;
}
.btn:hover { border-color: var(--dim); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #06121c; }
.btn-ok      { background: var(--ok); border-color: var(--ok); color: #04140a; }
.btn-warn    { background: var(--warn); border-color: var(--warn); color: #1c1400; }
.btn-danger  { background: var(--live); border-color: var(--live); color: #fff; }
.btn-quiet   { background: transparent; color: var(--dim); width: auto; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 8px 10px; color: var(--dim); font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: none; }
.row-hot { background: rgba(63,185,80,.08); }

.side { font-weight: 700; font-size: 11px; letter-spacing: .06em; }
.side-buy  { color: var(--ok); }
.side-sell { color: var(--bad); }

/* Proximity meter. Widths are classes, not inline styles, so the CSP can stay
   `style-src 'self'` — widening it for a progress bar is a bad trade. */
.meter {
  display: block; width: 100%; min-width: 70px; height: 8px;
  background: var(--bg); border-radius: 4px; overflow: hidden;
}
.meter-fill { display: block; height: 100%; background: var(--accent); }
.bar-0{width:0}      .bar-5{width:5%}    .bar-10{width:10%}  .bar-15{width:15%}
.bar-20{width:20%}   .bar-25{width:25%}  .bar-30{width:30%}  .bar-35{width:35%}
.bar-40{width:40%}   .bar-45{width:45%}  .bar-50{width:50%}  .bar-55{width:55%}
.bar-60{width:60%}   .bar-65{width:65%}  .bar-70{width:70%}  .bar-75{width:75%}
.bar-80{width:80%}   .bar-85{width:85%}  .bar-90{width:90%}  .bar-95{width:95%}
.bar-100{width:100%}
.bar-80, .bar-85, .bar-90, .bar-95, .bar-100 { background: var(--ok); }

/* ---------- equity sparkline ---------- */
.spark {
  display: block; width: 100%; height: auto; min-height: 120px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2;
              vector-effect: non-scaling-stroke; }
.spark-area { fill: rgba(75,159,213,.14); stroke: none; }
.spark-up   .spark-line { stroke: var(--ok); }
.spark-up   .spark-area { fill: rgba(63,185,80,.12); }
.spark-down .spark-line { stroke: var(--bad); }
.spark-down .spark-area { fill: rgba(240,87,77,.12); }
.sparkmeta {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--dim); margin-top: 6px;
}

/* ---------- activity feed ---------- */
.feed { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.feed li {
  display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 8px 0 8px 10px;
  border-bottom: 1px solid var(--line); border-left: 3px solid var(--line);
}
.feed li:last-child { border-bottom: none; }
.feed-buy  { border-left-color: var(--ok); }
.feed-sell { border-left-color: var(--bad); }
.feed-halt { border-left-color: var(--live); background: rgba(229,72,77,.08); }
.feed-ts { color: var(--dim); font-size: 12px; white-space: nowrap; }
.feed-text { flex: 1 1 260px; min-width: 0; }

/* ---------- key/value ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px;
      margin: 0 0 10px; font-size: 13px; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; }

.foot {
  display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between;
  padding: 14px 0 28px; font-size: 11px; color: var(--dim);
  border-top: 1px solid var(--line);
}

/* ---------- login ---------- */
.login-page { display: flex; align-items: center; justify-content: center;
              min-height: 100vh; padding: 20px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--dim); font-size: 13px; margin: 0 0 20px; }
.login-card label {
  display: block; font-size: 12px; color: var(--dim); margin: 0 0 5px;
  text-transform: uppercase; letter-spacing: .06em;
}
.fineprint { font-size: 11px; color: var(--dim); margin: 16px 0 0; }

/* ---------- narrow screens ---------------------------------------------
   Tables become stacked cards. A 7-column table on a 380px phone is either a
   horizontal scroll hunt or unreadable text; neither is acceptable when the
   thing being read decides whether to halt a live account. */
@media (max-width: 720px) {
  main { padding: 12px; }
  .panel { padding: 13px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .stat .v { font-size: 19px; }
  .controls { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; }
  .brand { width: 100%; margin-right: 0; }
  .badges { width: 100%; }
  .badge-mode { flex: 1 1 100%; text-align: center; }
  body.mode-live .badge-mode { font-size: 16px; padding: 10px; }
  .btn-quiet { width: 100%; }

  .tablewrap { overflow-x: visible; }
  table.stacked, table.stacked tbody, table.stacked tr, table.stacked td {
    display: block; width: 100%;
  }
  table.stacked thead { display: none; }
  table.stacked tr {
    background: var(--panel-2); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 4px 10px; margin: 0 0 10px;
  }
  table.stacked td {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line);
    text-align: right;
  }
  table.stacked td:last-child { border-bottom: none; }
  table.stacked td::before {
    content: attr(data-label);
    color: var(--dim); font-size: 11px; text-transform: uppercase;
    letter-spacing: .06em; text-align: left; flex: 0 0 auto;
  }
  .meter { min-width: 120px; }
  .kv { grid-template-columns: 1fr; gap: 0 0; }
  .kv dd { margin: 0 0 8px; }
  .feed-ts { flex: 1 1 100%; }
}

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