:root {
  --bg: #0d0d0d;
  --card: #1a1a1a;
  --card-2: #141414;
  --grid: #2a2a2a;
  --fg: #e6e6e6;
  --muted: #9e9e9e;
  --green: #00c853;
  --green-dim: rgba(0, 200, 83, 0.16);
  --green-edge: rgba(0, 200, 83, 0.45);
  --red: #ff3b30;
  --red-dim: rgba(255, 59, 48, 0.16);
  --red-edge: rgba(255, 59, 48, 0.45);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--grid);
}
.topbar .logo { width: 54px; height: 54px; margin-right: -8px; position: relative; top: -2px; }
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: 0.5px; font-weight: 800; }
.topbar h1 span { color: var(--green); }
.subtitle { color: var(--muted); font-size: 13px; }

.tz-picker { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.tz-picker label { color: var(--muted); font-size: 11px; letter-spacing: 0.6px; text-transform: uppercase; }
.tz-picker select {
  background: var(--card); color: var(--fg); border: 1px solid var(--grid);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; cursor: pointer;
}
.tz-picker select:hover { border-color: var(--green-edge); }
.tz-picker select:focus { outline: none; border-color: var(--green-edge); }

.decks { max-width: 1500px; margin: 24px auto; padding: 0 20px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

/* ---- deck (accordion) ---- */
.deck {
  background: var(--card);
  border: 1px solid var(--grid);
  border-radius: var(--radius);
  margin-bottom: 14px;
  /* no overflow:hidden — it would clip param tooltips that extend past the card */
}
.deck-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 22px;
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius) var(--radius) 0 0;  /* keep hover bg inside rounded corners */
}
.deck:not(.open) .deck-head { border-radius: var(--radius); }
.deck-head:hover { background: #1f1f1f; }
.chevron { color: var(--muted); transition: transform 0.18s ease; font-size: 13px; width: 14px; }
.deck.open .chevron { transform: rotate(90deg); }
.deck-title { flex: 1; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.deck-name { font-size: 18px; font-weight: 700; }
.badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.6px;
  padding: 4px 10px; border-radius: 999px; text-transform: uppercase;
}
.badge.on { background: var(--green-dim); color: var(--green); border: 1px solid var(--green-edge); }
.badge.off { background: #222; color: var(--muted); border: 1px solid var(--grid); }
.badge.neutral { background: #1f2937; color: #cbd5e1; border: 1px solid #374151; }

/* 3-state run-mode selector (Enabled / Demo / Disabled) in the deck header. */
.mode-select {
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 4px 26px 4px 10px; border-radius: 999px; cursor: pointer; appearance: none;
  background-repeat: no-repeat; background-position: right 9px center; background-size: 8px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239e9e9e' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
}
.mode-select:focus { outline: none; }
.mode-select.mode-live { background-color: var(--green-dim); color: var(--green); border: 1px solid var(--green-edge); }
.mode-select.mode-demo { background-color: rgba(255, 176, 32, 0.16); color: #ffb020; border: 1px solid rgba(255, 176, 32, 0.45); }
.mode-select.mode-disabled { background-color: #222; color: var(--muted); border: 1px solid var(--grid); }
.mode-select option { background: var(--card); color: var(--fg); }
.mode-select:disabled { opacity: 0.5; cursor: default; }

.deck-sub { color: var(--muted); font-size: 13px; margin-left: -6px; }
.deck-overall .deck-name { color: var(--green); }
.head-pnl { font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
/* Live account balance pill in the combined header (ENABLED-style):
   green at/above the $1,000 starting capital, red below. */
.balance-pill { font-variant-numeric: tabular-nums; margin-right: 4px; }
.badge.down { background: var(--red-dim); color: var(--red); border: 1px solid var(--red-edge); }

.deck-body { display: none; padding: 4px 22px 24px; }
.deck.open .deck-body { display: block; }

/* ---- Live | Backtest tabs ---- */
.tabs { display: flex; gap: 6px; margin: 8px 0 18px; border-bottom: 1px solid var(--grid); }
.tab {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 9px 16px; font-size: 14px; font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--green); border-bottom-color: var(--green); }
.tab-panel.hidden { display: none; }

.bt-summary { margin-bottom: 18px; overflow-x: auto; }
.bt-summary-table { border-collapse: collapse; font-size: 13px; }
.bt-summary-table th, .bt-summary-table td { border: 1px solid var(--grid); padding: 7px 12px; text-align: center; white-space: nowrap; }
.bt-summary-table thead th { color: var(--muted); font-weight: 500; font-size: 11px; letter-spacing: 0.4px; }
.bt-sum-corner { color: var(--muted); text-transform: uppercase; font-size: 10px; letter-spacing: 0.6px; text-align: left; background: var(--card); }
.bt-sum-period { cursor: pointer; }
.bt-sum-val { cursor: pointer; font-variant-numeric: tabular-nums; font-weight: 600; }
.bt-sum-period:hover, .bt-sum-val:hover { background: var(--card); }
.bt-sum-period.active, .bt-sum-val.active { background: var(--card); position: relative; outline: 1px solid var(--green-edge); outline-offset: -1px; }

.bt-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.bt-controls label { color: var(--muted); font-size: 11px; letter-spacing: 0.6px; text-transform: uppercase; }
.bt-controls select { background: var(--card); color: var(--fg); border: 1px solid var(--grid); border-radius: 8px; padding: 7px 10px; font-size: 13px; cursor: pointer; }
.bt-controls select:hover, .bt-controls select:focus { border-color: var(--green-edge); outline: none; }
.bt-range { color: var(--muted); font-size: 13px; }
.bt-stats { margin-bottom: 18px; }
.bt-chart-slot { min-height: 60px; }
.bt-chart-slot .loading, .bt-chart-slot .empty { color: var(--muted); padding: 30px; text-align: center; }
.bt-img { width: 100%; border: 1px solid var(--grid); border-radius: 10px; display: block; cursor: zoom-in; }
.bt-empty { color: var(--muted); padding: 24px; text-align: center; }
.bt-empty code { color: var(--fg); background: var(--card-2); padding: 2px 6px; border-radius: 5px; }

/* ---- stat tiles ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 8px 0 22px;
}
.tile {
  background: var(--card-2);
  border: 1px solid var(--grid);
  border-radius: 10px;
  padding: 14px 16px;
}
.tile .label { font-size: 11px; letter-spacing: 0.7px; text-transform: uppercase; color: var(--muted); }
.tile .value { font-size: 22px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile .value.sm { font-size: 18px; }   /* longer values, e.g. PnL > 9,999 */
.tile .value.xs { font-size: 15px; }   /* very long, e.g. 7-figure PnL */

.section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: stretch; }
.section-grid > div { min-width: 0; }
@media (max-width: 880px) { .section-grid { grid-template-columns: 1fr; } }

.panel-title { font-size: 13px; letter-spacing: 0.6px; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
/* Performance column stretches to the calendar's height; the bordered slot fills
   the row and the equity image is contained within it (top/bottom aligned). */
.perf, .calendar { display: flex; flex-direction: column; }
.calendar { overflow-x: auto; }   /* cells have a min-width; scroll rather than wrap */
.perf-slot {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--grid); border-radius: 10px; background: var(--card-2); overflow: hidden;
}
.perf-slot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.perf .empty { color: var(--muted); padding: 40px; text-align: center; }

/* ---- calendar ---- */
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.cal-head .month { font-weight: 700; flex: 1; }
.cal-nav {
  background: var(--card-2); border: 1px solid var(--grid); color: var(--fg);
  border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 16px;
}
.cal-nav:hover { background: #222; }
.dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.dow span { text-align: center; font-size: 10px; color: var(--muted); letter-spacing: 0.5px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cell {
  /* min-width sized so "9/9 trades" always fits on ONE line at 11px */
  min-height: 62px; min-width: 78px; border-radius: 8px; border: 1px solid var(--grid);
  background: var(--card-2); padding: 6px; position: relative; font-size: 11px;
}
.cell.empty { background: transparent; border-color: transparent; }
.cell .num { color: var(--muted); }
.cell.profit { background: var(--green-dim); border-color: var(--green-edge); cursor: pointer; }
.cell.loss { background: var(--red-dim); border-color: var(--red-edge); cursor: pointer; }
.cell.profit:hover, .cell.loss:hover { filter: brightness(1.25); }
.cell .day-pnl { font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }
.cell.profit .day-pnl { color: var(--green); }
.cell.loss .day-pnl { color: var(--red); }
.cell .day-count { color: var(--muted); margin-top: 2px; white-space: nowrap; }

/* ---- configuration panel (below performance/calendar) ---- */
.config { margin-top: 24px; }
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.cfg-item {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  background: var(--card-2); border: 1px solid var(--grid); border-radius: 8px;
  padding: 9px 12px; font-size: 13px;
  position: relative; cursor: help;
}
.cfg-item:hover, .cfg-item:focus { border-color: var(--green-edge); outline: none; }
.cfg-k { color: var(--muted); }
.cfg-v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; word-break: break-word; }

/* whole-box hover/focus tooltip — the plain-language explanation of the param */
.cfg-item::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: 260px;
  background: #000; color: var(--fg); border: 1px solid var(--grid); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; font-weight: 400;
  line-height: 1.4; text-align: left; white-space: normal;
  opacity: 0; visibility: hidden; transition: opacity 0.12s ease; pointer-events: none; z-index: 60;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
.cfg-item::before {
  content: ""; position: absolute; bottom: calc(100% + 2px); left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--grid);
  opacity: 0; visibility: hidden; transition: opacity 0.12s ease; z-index: 60;
}
.cfg-item:hover::after, .cfg-item:focus::after,
.cfg-item:hover::before, .cfg-item:focus::before { opacity: 1; visibility: visible; }
.config .empty { color: var(--muted); padding: 18px; border: 1px dashed var(--grid); border-radius: 10px; }

.legend { display: flex; gap: 16px; margin-top: 12px; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.legend .p { background: var(--green); }
.legend .l { background: var(--red); }
.legend .n { background: var(--card-2); border: 1px solid var(--grid); }

.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---- modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.66);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card); border: 1px solid var(--grid); border-radius: var(--radius);
  width: min(620px, 100%); max-height: 84vh; overflow: auto;
}
.modal-head { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--grid); }
.modal-head h2 { margin: 0; font-size: 16px; flex: 1; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 26px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--fg); }
.modal-body { padding: 12px 22px 22px; }

.trade-card { border: 1px solid var(--grid); border-radius: 10px; padding: 14px 16px; margin-top: 12px; background: var(--card-2); }
.trade-card .row1 { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.side { font-weight: 800; font-size: 12px; padding: 3px 9px; border-radius: 6px; }
.side.BUY { background: var(--green-dim); color: var(--green); }
.side.SELL { background: var(--red-dim); color: var(--red); }
.trade-card .asset { font-weight: 700; }
.trade-strat { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: #1f2937; color: #cbd5e1; border: 1px solid #374151; }

/* combined day modal: one summary block per strategy (totals + asset/tf/exit) */
.ov-strat { padding: 11px 4px; border-bottom: 1px solid var(--grid); font-size: 14px; }
.ov-strat:last-of-type { border-bottom: none; }
.ov-strat .ov-line { display: flex; align-items: center; gap: 12px; }
.ov-strat .ov-count { color: var(--muted); font-size: 12px; }
.ov-strat .tpnl { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.ov-strat .ov-meta { display: flex; align-items: center; gap: 12px; margin-top: 5px; font-size: 12px; color: var(--muted); }
.ov-strat .ov-asset { font-weight: 600; color: #cbd5e1; }
.ov-strat .ov-reason { margin-left: auto; font-variant-numeric: tabular-nums; }
.ov-hint { color: var(--muted); font-size: 12px; padding: 14px 4px 2px; font-style: italic; }

/* compact one-line trade row (combined "all strategies" day modal) */
.trade-line {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid var(--grid); font-size: 14px;
}
.trade-line:last-child { border-bottom: none; }
.trade-line .asset { font-weight: 700; }
.trade-line .tpnl { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.trade-line .reason { color: var(--muted); font-size: 12px; min-width: 34px; text-align: right; }
.trade-card .tpnl { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 18px; }
.kv div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--grid); padding: 4px 0; font-size: 13px; }
.kv .k { color: var(--muted); }
.kv .v { font-variant-numeric: tabular-nums; }

/* ---- trade row: summary + events/chart panel (auto-expanded) ---- */
.trade-events { display: none; padding: 4px 0 8px 4px; }
.trade-wrap.open .trade-events { display: block; }
.trade-wrap + .trade-wrap { margin-top: 4px; }
.ev-empty { color: var(--muted); font-size: 13px; padding: 10px 0; }
.ev-chart { position: relative; margin: 6px 0 14px; }
.ev-chart img { width: 100%; border: 1px solid var(--grid); border-radius: 10px; display: block; background: #fff; cursor: zoom-in; }
.ev-zoom {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px;
  border: none; border-radius: 7px; background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 16px; cursor: zoom-in; display: flex; align-items: center; justify-content: center;
}
.ev-zoom:hover { background: rgba(0, 0, 0, 0.8); }

/* full-size chart viewer */
.lightbox {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.85); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6); background: #fff; }

.ev-list { display: flex; flex-direction: column; gap: 8px; }
.ev-item { border: 1px solid var(--grid); border-radius: 8px; background: var(--card-2); padding: 8px 12px; }
.ev-head { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.ev-icon { font-size: 15px; }
.ev-label { font-weight: 700; }
.ev-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.ev-pdf { margin-left: auto; color: var(--green); text-decoration: none; font-size: 12px; font-weight: 700; }
.ev-pdf:hover { text-decoration: underline; }
.ev-toggle { margin-left: auto; background: none; border: 1px solid var(--grid); color: var(--muted); border-radius: 6px; padding: 3px 8px; font-size: 11px; cursor: pointer; }
.ev-pdf + .ev-toggle { margin-left: 8px; }
.ev-toggle:hover { color: var(--fg); border-color: var(--green-edge); }
.ev-body { display: none; margin-top: 10px; }
.ev-item.open .ev-body { display: block; }

/* WhatsApp-style bubble — white background, icons + breaks kept */
.wa-bubble {
  position: relative; max-width: 460px;
  background: #ffffff; color: #111b21; border-radius: 8px 8px 8px 2px;
  padding: 8px 12px 18px; font-size: 13.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
  font-family: -apple-system, "Segoe UI", "Noto Color Emoji", Roboto, sans-serif;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}
.wa-time { position: absolute; right: 10px; bottom: 4px; font-size: 10px; color: #667781; }

/* keep separators between combined compact lines even when each is in a wrap */
.trade-wrap .trade-line { border-bottom: 1px solid var(--grid); }
.trade-wrap:last-child .trade-line { border-bottom: none; }

/* ---- password gate --------------------------------------------------------- */
.login-gate {
  min-height: 70vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px;
}
.login-gate h1 { margin: 0; font-size: 30px; letter-spacing: 0.5px; font-weight: 800; }
.login-gate h1 span { color: var(--green); }
.login-gate form { display: flex; gap: 10px; }
.login-gate input {
  background: var(--card); color: var(--fg);
  border: 1px solid var(--grid); border-radius: var(--radius);
  padding: 12px 16px; font-size: 15px; width: 240px; outline: none;
}
.login-gate input:focus { border-color: var(--green-edge); }
.login-gate button {
  background: var(--green-dim); color: var(--green);
  border: 1px solid var(--green-edge); border-radius: var(--radius);
  padding: 12px 22px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.login-gate button:hover { background: var(--green); color: #04140a; }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; margin: 0; }

/* eye toggle inside the password input */
.pass-wrap { position: relative; display: inline-block; }
.pass-wrap input { padding-right: 46px; }
#pass-eye {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; padding: 6px; cursor: pointer;
  color: var(--muted);
}
#pass-eye:hover { color: var(--fg); }
