:root {
  --bg: #0b0e11;
  --card: #181a20;
  --card2: #1e2329;
  --border: #2b3139;
  --text: #eaecef;
  --muted: #848e9c;
  --yellow: #f0b90b;
  --green: #0ecb81;
  --red: #f6465d;
  --purple: #a78bfa;
  --blue: #60a5fa;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
b { font-weight: 600; }

/* ------- topbar ------- */
.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 0 20px; height: 56px;
  background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.brand { font-size: 18px; font-weight: 700; color: var(--yellow); letter-spacing: .3px; }
.brand span { color: var(--text); }
.ticker { display: flex; align-items: baseline; gap: 16px; flex: 1; min-width: 0; }
.ticker-pair { font-weight: 600; }
.ticker-price { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ticker-chg { font-weight: 600; font-variant-numeric: tabular-nums; }
.ticker-hl { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.ticker-hl b { color: var(--text); font-weight: 500; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.feed-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.feed-dot.ok { background: var(--green); box-shadow: 0 0 6px var(--green); }
.feed-dot.bad { background: var(--red); box-shadow: 0 0 6px var(--red); }

.up { color: var(--green) !important; }
.down { color: var(--red) !important; }

/* ------- layout ------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 330px;
  grid-template-areas: "chart modes" "equity modes" "table table";
  gap: 14px;
  padding: 14px 20px 30px;
  max-width: 1600px;
  margin: 0 auto;
}
.chart-card { grid-area: chart; }
.modes { grid-area: modes; display: flex; flex-direction: column; gap: 14px; }
.equity-card { grid-area: equity; }
.table-card { grid-area: table; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "chart" "modes" "equity" "table"; }
  .modes { flex-direction: row; flex-wrap: wrap; }
  .mode-card { flex: 1 1 280px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; gap: 12px; flex-wrap: wrap;
}
.card-title { font-weight: 600; font-size: 15px; }
.head-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.chart-wrap { height: 420px; width: 100%; position: relative; }
.chart-wrap-sm { height: 260px; }

/* ------- segmented buttons ------- */
.seg { display: flex; background: var(--card2); border-radius: 6px; padding: 2px; }
.seg button {
  background: transparent; border: 0; color: var(--muted);
  padding: 4px 10px; font-size: 12px; cursor: pointer; border-radius: 5px; font-weight: 600;
}
.seg button.on { background: var(--border); color: var(--yellow); }
.seg-sm button { padding: 3px 8px; }

.marker-filters { display: flex; gap: 10px; font-size: 12px; }
.mk { display: flex; align-items: center; gap: 4px; cursor: pointer; color: var(--muted); }
.mk input { accent-color: var(--yellow); }
.mk-sim { color: var(--yellow); }
.mk-ai { color: var(--purple); }
.mk-live { color: var(--green); }

/* ------- mode cards ------- */
.mode-card { display: flex; flex-direction: column; gap: 10px; position: relative; }
.mode-head { display: flex; align-items: center; justify-content: space-between; }
.mode-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mode-sub { color: var(--muted); font-size: 11px; font-weight: 400; }
.mode-pip { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.pip-sim { background: var(--yellow); }
.pip-ai { background: var(--purple); }
.pip-live { background: var(--green); }

.mode-equity { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 10px; }
.mode-equity small { font-size: 13px; font-weight: 600; }
.mode-balances { display: flex; gap: 18px; color: var(--muted); font-size: 13px; }
.mode-balances b { color: var(--text); font-variant-numeric: tabular-nums; }

.mode-pos {
  font-size: 12px; border-left: 3px solid var(--border);
  padding: 6px 10px; background: var(--card2); border-radius: 4px; line-height: 1.6;
}
.mode-pos:empty { display: none; }
.mode-pos .pos-pnl { font-weight: 700; }
.mode-stats { display: flex; gap: 14px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.mode-stats b { color: var(--text); }

.ai-decision {
  font-size: 12px; color: var(--muted); background: var(--card2);
  border-radius: 4px; padding: 6px 10px; line-height: 1.5;
  border-left: 3px solid var(--purple);
}
.ai-decision:empty { display: none; }
.ai-decision .act { font-weight: 700; text-transform: uppercase; }

.live-warn { color: var(--yellow); font-size: 12px; }
.live-warn:empty { display: none; }

.btn-reset { align-self: flex-end; }

/* ------- switch ------- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border); border-radius: 22px; transition: .15s;
}
.slider:before {
  content: ""; position: absolute; height: 16px; width: 16px;
  left: 3px; bottom: 3px; background: var(--muted); border-radius: 50%; transition: .15s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider:before { transform: translateX(18px); background: #fff; }

/* ------- legend ------- */
.legend { display: flex; align-items: center; gap: 14px; font-size: 12px; }
.lg { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.lg:before { content: ""; width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.lg-sim:before { background: var(--yellow); }
.lg-ai:before { background: var(--purple); }
.lg-live:before { background: var(--green); }

/* ------- tables ------- */
.tabs { display: flex; gap: 4px; }
.tabs button {
  background: transparent; border: 0; color: var(--muted); font-weight: 600;
  padding: 6px 12px; cursor: pointer; border-radius: 6px; font-size: 13px;
}
.tabs button.on { color: var(--yellow); background: var(--card2); }

.table-scroll { overflow-x: auto; max-height: 420px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 11.5px;
  padding: 7px 10px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--card); z-index: 2;
}
td { padding: 7px 10px; border-bottom: 1px solid rgba(43,49,57,.5); font-variant-numeric: tabular-nums; white-space: nowrap; }
td.wrap { white-space: normal; max-width: 420px; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 4px;
  font-size: 11px; font-weight: 700;
}
.badge-sim { background: rgba(240,185,11,.12); color: var(--yellow); }
.badge-ai { background: rgba(167,139,250,.12); color: var(--purple); }
.badge-live { background: rgba(14,203,129,.12); color: var(--green); }
.badge-via { background: var(--card2); color: var(--muted); font-weight: 500; }
.side-buy { color: var(--green); font-weight: 700; }
.side-sell { color: var(--red); font-weight: 700; }

.activity { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.7; padding: 6px 4px; }
.activity .ts { color: var(--muted); margin-right: 8px; }

/* ------- buttons ------- */
.btn {
  background: var(--card2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--yellow); color: #181a20; border-color: var(--yellow); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: transparent; }
.btn-mini { padding: 3px 9px; font-size: 11px; color: var(--muted); font-weight: 500; }
.btn-block { width: 100%; }

/* ------- modal ------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: flex-start; justify-content: center; z-index: 100;
  padding: 40px 16px; overflow-y: auto;
}
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 640px;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 17px; }
.modal-x { background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; }
.modal-body { padding: 18px 20px 24px; }
.modal-body h3 { font-size: 13px; color: var(--yellow); margin: 18px 0 10px; text-transform: uppercase; letter-spacing: .5px; }
.modal-body h3:first-child { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.form-grid input {
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 8px 10px; font-size: 13px; outline: none;
}
.form-grid input:focus { border-color: var(--yellow); }
.form-grid .check-label { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.form-grid .check-label input { accent-color: var(--yellow); width: 16px; height: 16px; }
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 14px; }
.settings-msg { font-size: 12px; }
.settings-msg.ok { color: var(--green); }
.settings-msg.err { color: var(--red); }

/* ------- modal scroll lock ------- */
body.modal-open { overflow: hidden; }
.modal-bg { overscroll-behavior: contain; }

/* ------- phone layout ------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 6px 14px; }
  .ticker { flex-basis: 100%; order: 3; gap: 10px; }
  .ticker-price { font-size: 17px; }
  .ticker-hl { display: none; }
  .top-actions { margin-left: auto; }
  .layout { padding: 10px 10px 24px; gap: 10px; }
  .chart-wrap { height: 320px; }
  .chart-wrap-sm { height: 220px; }
  /* one-column settings form; 16px inputs stop iOS focus-zoom */
  .form-grid { grid-template-columns: 1fr; }
  .form-grid input, .login-card input { font-size: 16px; }
  /* bigger touch targets */
  .seg button { padding: 8px 12px; }
  .seg-sm button { padding: 7px 10px; }
  .modal-x { padding: 8px 12px; font-size: 18px; }
  .btn-mini { padding: 7px 12px; }
  .mk { padding: 4px 2px; }
  .modal-bg { padding: 12px 8px; }
  .login-body { padding: 16px; }
}
.form-grid input { width: 100%; min-width: 0; }

/* ------- footer ------- */
.page-foot {
  text-align: center; color: var(--muted); font-size: 11px;
  padding: 4px 20px 18px; opacity: .7;
}
.page-foot a { color: var(--muted); }

/* ------- login ------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 36px 32px; width: 100%; max-width: 380px; text-align: center;
}
.login-logo { font-size: 26px; font-weight: 800; color: var(--yellow); }
.login-logo span { color: var(--text); }
.login-sub { color: var(--muted); font-size: 12px; margin: 8px 0 24px; }
.login-card input {
  width: 100%; background: var(--card2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 11px 12px; font-size: 14px; margin-bottom: 12px; outline: none;
}
.login-card input:focus { border-color: var(--yellow); }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }
