/* ============================================================================
   Abu Fahad — "Claude / retro-pixel" theme
   Warm cream canvas, Claude coral accent, dark warm ink. Pixel type:
   Press Start 2P (brand) + Pixelify Sans (everything, readable at data sizes).
   ========================================================================== */
:root {
  --bg:        #F0EEE6;   /* Claude cream */
  --bg-2:      #FAF9F5;
  --surface:   #FFFFFF;
  --line:      #E4E1D7;
  --line-soft: #EDEAE1;
  --ink:       #1F1E1D;   /* Claude near-black (warm) */
  --ink-dim:   #6E6D66;
  --ink-faint: #A6A49A;

  --primary:   #D97757;   /* Claude coral */
  --primary-2: #C15F3F;
  --gain:      #4E9E6A;
  --gain-soft: #E7F1E9;
  --loss:      #7A7871;   /* grey (no red), for negative P/L + Stop */
  --loss-soft: #ECEBE4;
  --live:      #D97757;
  --warn:      #E0912F;

  --radius:    14px;
  --radius-sm: 10px;
  --tap:       54px;
  --disp: "VT323", ui-monospace, monospace;
  --sans: "VT323", ui-monospace, "Courier New", monospace;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.35;
  overflow-x: hidden;
  padding-bottom: calc(28px + var(--safe-b));
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}
/* faint pixel-dot texture */
.grain { position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .6;
  background-image: radial-gradient(#dcd8cb 1px, transparent 1.5px);
  background-size: 8px 8px; mask-image: linear-gradient(180deg, transparent 55%, #000 100%); }

.mono { font-variant-numeric: tabular-nums; }
.pos { color: var(--gain); }
.neg { color: var(--loss); }
.flat { color: var(--ink-dim); }

/* ── header ──────────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-t) + 16px) 18px 18px;
  background: var(--bg);
  border-bottom: 2px solid var(--ink);
  overflow: hidden;
}
.topbar__row { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand__mark { color: var(--primary); display: inline-flex; align-items: center; }
.brand__logo { height: 36px; width: auto; display: block; }
.topbar__right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.brand__name { font-family: var(--disp); font-weight: 400; letter-spacing: .12em; font-size: 24px; color: var(--ink); }

.gw {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 0; padding: 6px 11px;
  background: var(--surface); color: var(--ink);
  font-family: var(--sans); font-weight: 600; font-size: 12px; letter-spacing: .02em;
}
.gw__dot { width: 9px; height: 9px; border-radius: 0; background: var(--ink-faint); }
.gw[data-s="live"] { color: var(--gain); border-color: var(--gain); }
.gw[data-s="live"] .gw__dot { background: var(--gain); animation: pulse 2.4s infinite; }
.gw[data-s="warn"] { color: var(--warn); border-color: var(--warn); }
.gw[data-s="warn"] .gw__dot { background: var(--warn); animation: blink 1s steps(2) infinite; }
.gw[data-s="down"] { color: var(--loss); border-color: var(--loss); }
.gw[data-s="down"] .gw__dot { background: var(--loss); }

.account { margin-top: 18px; }
.account__value { font-family: var(--sans); font-weight: 700; font-size: 56px; letter-spacing: .01em; line-height: 1; font-variant-numeric: tabular-nums; }
.account__pnl { display: flex; gap: 10px; margin-top: 12px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 8px;
  background: var(--surface); border: 2px solid var(--ink); padding: 6px 11px;
}
.chip__k { font-weight: 600; font-size: 11px; letter-spacing: .04em; color: var(--ink-dim); }
.chip__v { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }

.scanline { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--primary); opacity: 0; }
.scanline.sweep { animation: sweep 1.1s ease-out; }

/* ── view / lists ────────────────────────────────────────────────────────────── */
.view { position: relative; z-index: 1; padding: 18px 16px 8px; max-width: 640px; margin: 0 auto; }
.sect-h { display: flex; align-items: center; justify-content: space-between; margin: 6px 2px 12px; }
.sect-h__t { font-weight: 700; font-size: 12px; letter-spacing: .08em; color: var(--ink-dim); text-transform: uppercase; }

.card {
  background: var(--surface);
  border: 2px solid var(--ink); border-radius: 0;
  padding: 16px; margin-bottom: 14px; position: relative;
  box-shadow: 5px 5px 0 0 var(--ink);
  opacity: 0; transform: translateY(10px); animation: rise .45s steps(6) forwards;
}
.card[data-run="1"] { box-shadow: 5px 5px 0 0 var(--primary); }
.card__top { display: flex; align-items: center; justify-content: space-between; }
.tick { display: flex; align-items: center; gap: 10px; }
.tick__sym { font-family: var(--sans); font-weight: 700; font-size: 24px; letter-spacing: 0; }
.tick__name { font-weight: 600; font-size: 11px; letter-spacing: .06em; color: var(--ink-faint); text-transform: uppercase; }
.state { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: 11px; letter-spacing: .04em; color: var(--ink-dim);
  border: 2px solid var(--line); padding: 4px 9px; }
.state__dot { width: 9px; height: 9px; background: var(--ink-faint); }
.card[data-run="1"] .state { border-color: var(--primary); color: var(--primary); }
.card[data-run="1"] .state__dot { background: var(--primary); animation: pulse 2.4s infinite; }

.card__pnl { display: flex; gap: 26px; margin: 16px 0 4px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat__k { font-weight: 600; font-size: 11px; letter-spacing: .06em; color: var(--ink-faint); }
.stat__v { font-family: var(--sans); font-weight: 700; font-size: 24px; font-variant-numeric: tabular-nums; }

.card__meta { display: flex; align-items: center; gap: 8px; color: var(--ink-faint); font-size: 12.5px; font-weight: 500; margin-top: 8px; }
.card__meta .sep { opacity: .5; }
.card__last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-dim); }

.card__ctl { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  flex: 1; min-height: 46px; border-radius: 0;
  border: 2px solid var(--ink); background: var(--surface); color: var(--ink);
  font-family: var(--sans); font-weight: 700; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer;
  transition: transform .06s steps(2);
}
.btn:active { transform: translate(2px, 2px); }
.btn--stop { color: #fff; background: var(--loss); border-color: var(--ink); }
.btn--go { color: #fff; background: var(--gain); border-color: var(--ink); }

.agg {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 16px; margin: 8px 0 4px;
  background: var(--ink); color: var(--bg-2); border: 2px solid var(--ink);
}
.agg__k { font-family: var(--disp); font-size: 17px; letter-spacing: .06em; color: var(--primary); }
.agg__row { display: flex; gap: 22px; }
.agg .stat__k { color: #b9b7ac; }
.agg .stat__v { color: var(--bg-2); }
.agg .stat__v.pos { color: #8fe0ab; }
.agg .stat__v.neg { color: #c9c7bc; }

/* ── bot detail ──────────────────────────────────────────────────────────────── */
.back { display: inline-flex; align-items: center; gap: 8px; background: none; border: none; color: var(--primary); font-weight: 700; font-size: 14px; padding: 4px 0; margin-bottom: 10px; cursor: pointer; }
.detail-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.detail-head h1 { font-family: var(--sans); font-weight: 700; font-size: 36px; }
.panel { background: var(--surface); border: 2px solid var(--ink); box-shadow: 5px 5px 0 0 var(--ink); padding: 4px 16px; margin: 14px 0 20px; }
.kv { display: flex; align-items: center; justify-content: space-between; padding: 13px 0; border-bottom: 2px solid var(--line-soft); }
.kv:last-child { border-bottom: none; }
.kv__k { font-weight: 600; font-size: 13px; color: var(--ink-dim); }
.kv__v { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }

.log {
  font-family: var(--sans); font-size: 13px; line-height: 1.7; color: var(--ink-dim);
  background: var(--bg-2); border: 2px solid var(--line);
  padding: 14px; height: 44vh; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.log__line { display: block; }
.log__line b { color: var(--primary); font-weight: 700; }

/* ── settings ────────────────────────────────────────────────────────────────── */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 2px solid var(--line-soft); }
.toggle-row:last-child { border-bottom: none; }
.toggle-row__l { display: flex; flex-direction: column; gap: 3px; }
.toggle-row__t { font-size: 15px; font-weight: 700; }
.toggle-row__d { font-size: 12px; color: var(--ink-faint); font-weight: 500; }
.sw { --w: 52px; position: relative; width: var(--w); height: 28px; flex: 0 0 var(--w); border-radius: 0; border: 2px solid var(--ink); background: var(--surface); cursor: pointer; transition: background .12s steps(2); }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: var(--ink-faint); transition: transform .12s steps(3), background .12s; }
.sw[aria-checked="true"] { background: var(--gain-soft); }
.sw[aria-checked="true"]::after { transform: translateX(24px); background: var(--gain); }
.ghost-btn { width: 100%; min-height: var(--tap); border-radius: 0; border: 2px solid var(--ink); background: var(--primary); color: #fff; font-family: var(--sans); font-weight: 700; font-size: 16px; margin-top: 16px; cursor: pointer; box-shadow: 4px 4px 0 0 var(--ink); }
.ghost-btn:active { transform: translate(2px,2px); box-shadow: 2px 2px 0 0 var(--ink); }

.nav-tabs { display: flex; gap: 10px; margin: 2px 0 18px; }
.nav-tabs a { flex: 1; text-align: center; text-decoration: none; padding: 12px; border-radius: 0; background: var(--surface); border: 2px solid var(--ink); color: var(--ink-dim); font-weight: 700; font-size: 13px; letter-spacing: .04em; }
.nav-tabs a.on { color: #fff; background: var(--primary); }

/* ── STOP ALL (compact, in header under the gateway pill) ─────────────────────── */
.dock { display: none; }
.stopall {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: #fff;
  border: 2px solid var(--ink); background: var(--ink); padding: 6px 12px;
  box-shadow: 3px 3px 0 0 var(--primary); transition: transform .06s steps(2);
}
.stopall:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 0 var(--primary); }
.stopall__icon { font-size: 12px; color: var(--primary); }
.stopall__text { font-family: var(--disp); font-weight: 400; letter-spacing: .06em; font-size: 19px; line-height: 1; }

/* ── toast ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(102px + var(--safe-b)); transform: translate(-50%, 20px);
  z-index: 40; max-width: 88vw; padding: 13px 16px; border-radius: 0;
  bottom: calc(24px + var(--safe-b)) !important;
  background: var(--ink); color: var(--bg-2); border: 2px solid var(--ink); font-weight: 600; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  box-shadow: 4px 4px 0 0 var(--primary);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-k="warn"] { box-shadow: 4px 4px 0 0 var(--warn); }

.empty { text-align: center; color: var(--ink-faint); font-weight: 500; font-size: 13px; padding: 40px 0; }

/* ── login ──────────────────────────────────────────────────────────────────── */
.login { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 8vh 24px; max-width: 360px; margin: 0 auto; }
.login__logo { height: 76px; width: auto; }
.login__title { font-family: var(--disp); font-size: 26px; letter-spacing: .1em; margin-bottom: 4px; }
.login__input { width: 100%; min-height: 54px; border: 2px solid var(--ink); background: var(--surface); font-family: var(--sans); font-size: 22px; text-align: center; padding: 0 14px; border-radius: 0; color: var(--ink); }
.login__input:focus { outline: none; box-shadow: 4px 4px 0 0 var(--primary); }
.login__btn { width: 100%; min-height: 54px; border: 2px solid var(--ink); background: var(--primary); color: #fff; font-family: var(--disp); font-size: 16px; letter-spacing: .06em; cursor: pointer; box-shadow: 4px 4px 0 0 var(--ink); }
.login__btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 0 var(--ink); }
.login__err { color: var(--ink); background: var(--warn); padding: 9px 12px; font-weight: 600; font-size: 13px; width: 100%; text-align: center; }

/* ── open-position live P/L ──────────────────────────────────────────────────── */
.livedot { display: inline-block; width: 8px; height: 8px; background: var(--live); margin-right: 5px; vertical-align: middle; animation: blink 1s steps(2) infinite; }
.stat--open .stat__k { color: var(--primary); }
.card--static { opacity: 1 !important; transform: none !important; animation: none !important; }
.card--paused { opacity: .58; box-shadow: 5px 5px 0 0 var(--line); }
.card--paused .state { border-color: var(--line); color: var(--ink-faint); }
.card--paused .state__dot { background: var(--ink-faint); animation: none; }
.posrow { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 2px solid var(--line-soft); }
.posrow:last-child { border-bottom: none; }
.posrow__id { font-weight: 700; font-size: 15px; min-width: 96px; }
.posrow__px { font-size: 12.5px; color: var(--ink-faint); font-weight: 500; flex: 1; }
.posrow__pnl { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── motion (stepped = pixel feel) ───────────────────────────────────────────── */
@keyframes rise { to { opacity: 1; transform: none; } }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(217,119,87,.5); } 50% { box-shadow: 0 0 0 5px rgba(217,119,87,0); } }
@keyframes blink { 50% { opacity: .35; } }
@keyframes sweep { 0% { opacity: .9; transform: scaleX(.3); } 100% { opacity: 0; transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } .card { opacity: 1; transform: none; } }
