:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --green: #2ea043;
  --green-bright: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --blue: #2f81f7;
  --grey: #6e7681;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
               Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.muted { color: var(--muted); }

/* ── TOP BAR ── */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 16px; font-weight: 600; letter-spacing: .3px; }
.topbar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.svc-dots { display: flex; gap: 12px; }
.dot-wrap { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; transition: background .4s; }
.dot-green { background: var(--green-bright); box-shadow: 0 0 6px var(--green-bright); }
.dot-red { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot-grey { background: var(--grey); }
.feed-badge { font-size: 12px; color: var(--muted); }
.feed-badge.stale { color: var(--red); font-weight: 600; }
.updated { font-size: 12px; color: var(--muted); }
.btn-logout {
  color: var(--text); text-decoration: none; font-size: 13px;
  border: 1px solid var(--border); padding: 5px 12px; border-radius: 6px;
  background: var(--panel-2); transition: background .2s;
}
.btn-logout:hover { background: #283041; }

/* ── LAYOUT ── */
.layout {
  display: grid; gap: 16px; padding: 18px;
  grid-template-columns: 1fr;
  max-width: 1280px; margin: 0 auto;
}
@media (min-width: 900px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .score-card, .emergency-card { grid-column: 1 / -1; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-h {
  margin: 0 0 12px; font-size: 13px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted); font-weight: 600;
}

/* ── SCORE CARD ── */
.score-card { display: flex; flex-wrap: wrap; align-items: center; gap: 28px; }
.score-main { display: flex; flex-direction: column; align-items: flex-start; }
.score-big { font-size: 56px; font-weight: 700; line-height: 1; }
.score-direction {
  margin-top: 6px; font-size: 20px; font-weight: 700; letter-spacing: 1px;
  padding: 2px 10px; border-radius: 6px;
}
.dir-bull { color: var(--green-bright); background: rgba(63,185,80,.12); }
.dir-bear { color: var(--red); background: rgba(248,81,73,.12); }
.dir-grey { color: var(--muted); background: rgba(110,118,129,.12); }
.score-meta { display: flex; flex-direction: column; gap: 10px; }
.score-session #score-session { font-weight: 600; }
.score-counts { display: flex; gap: 8px; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 20px; }
.pill-bull { background: rgba(63,185,80,.15); color: var(--green-bright); }
.pill-bear { background: rgba(248,81,73,.15); color: var(--red); }
.gates { display: flex; gap: 16px; }
.gate-badge { font-size: 12px; color: var(--muted); }
.badge { font-weight: 700; }

/* ── LAYER GRID ── */
.layer-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.layer { background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; border-left: 4px solid var(--grey); }
.layer.sig-bull { border-left-color: var(--green-bright); }
.layer.sig-bear { border-left-color: var(--red); }
.layer.sig-neutral { border-left-color: var(--grey); }
.layer-name { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.layer-sig { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.layer-sig .ldot { width: 8px; height: 8px; border-radius: 50%; }
.sig-bull .ldot { background: var(--green-bright); }
.sig-bear .ldot { background: var(--red); }
.sig-neutral .ldot { background: var(--grey); }
.sig-bull .layer-sig { color: var(--green-bright); }
.sig-bear .layer-sig { color: var(--red); }
.sig-neutral .layer-sig { color: var(--muted); }
.layer-val { font-size: 12px; color: var(--text); margin-top: 6px; word-break: break-word; }

/* ── ACTIVE TRADE ── */
.active-trade .at-grid {
  display: grid; gap: 10px 18px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}
.at-item .at-label { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.at-item .at-value { font-size: 15px; font-weight: 600; }
.at-pnl-big { font-size: 30px; font-weight: 700; }
.pnl-pos { color: var(--green-bright); }
.pnl-neg { color: var(--red); }
.at-dir { font-weight: 700; }

/* ── FUNDS ── */
.funds-panel .f-row { display: flex; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid var(--border); }
.funds-panel .f-row:last-child { border-bottom: none; }
.f-label { color: var(--muted); }
.f-value { font-weight: 600; }

/* ── ACTIVITY FEED ── */
.activity-feed { max-height: 280px; overflow-y: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.feed-row { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.feed-row:last-child { border-bottom: none; }
.feed-ts { color: var(--muted); white-space: nowrap; }
.feed-msg { color: var(--text); word-break: break-word; }

/* ── EMERGENCY ── */
.emergency-card { border: 2px solid var(--red); }
.emergency-h { color: var(--red); }
.emergency-btns { display: flex; gap: 12px; flex-wrap: wrap; }
.btn-emerg { flex: 1 1 140px; padding: 16px; font-size: 15px; font-weight: 700;
  border: none; border-radius: 8px; cursor: pointer; color: #fff;
  letter-spacing: .5px; transition: transform .1s, filter .2s; }
.btn-emerg:hover { filter: brightness(1.12); }
.btn-emerg:active { transform: scale(.98); }
.btn-paper { background: var(--amber); color: #1a1a1a; }
.btn-live { background: var(--blue); }
.btn-close { background: var(--red); flex-basis: 200px; }

/* ── MODAL ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; width: 90%; max-width: 380px; }
.modal h3 { margin: 0 0 8px; }
.modal-text { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.modal input { width: 100%; }
.modal-error { color: var(--red); font-size: 13px; margin-top: 10px; }
.modal-error.hidden { display: none; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }
.btn-cancel, .btn-confirm { padding: 9px 18px; border-radius: 6px; cursor: pointer;
  font-weight: 600; border: 1px solid var(--border); }
.btn-cancel { background: var(--panel-2); color: var(--text); }
.btn-confirm { background: var(--red); color: #fff; border-color: var(--red); }

/* ── TOAST ── */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 12px 22px; border-radius: 8px; font-weight: 600; z-index: 200;
  box-shadow: var(--shadow); }
.toast.hidden { display: none; }
.toast.ok { background: var(--green); color: #fff; }
.toast.err { background: var(--red); color: #fff; }

/* ── FORM INPUTS ── */
input[type=text], input[type=password] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 6px; font-size: 14px; width: 100%;
  margin: 4px 0 14px;
}
input:focus { outline: none; border-color: var(--blue); }

/* ── LOGIN ── */
.login-body { display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 36px 30px; width: 100%; max-width: 360px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.login-title { font-size: 22px; text-align: center; margin: 0 0 24px; line-height: 1.3; }
.login-title span { color: var(--blue); }
.login-card label { font-size: 12px; color: var(--muted); }
.btn-login { width: 100%; padding: 12px; background: var(--blue); color: #fff;
  border: none; border-radius: 6px; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-top: 6px; }
.btn-login:hover { filter: brightness(1.1); }
.login-error { background: rgba(248,81,73,.12); color: var(--red);
  border: 1px solid var(--red); padding: 10px; border-radius: 6px;
  font-size: 13px; margin-bottom: 16px; text-align: center; }
.login-foot { text-align: center; color: var(--muted); font-size: 11px; margin: 18px 0 0; }
