/* Playbook — web edition. Palette carried over from the desktop app. */
:root {
  --ink: #0B0F14;
  --panel: #121820;
  --panel2: #171F28;
  --line: #232B35;
  --text: #E7ECEF;
  --muted: #7C8A96;
  --gain: #00C853;
  --loss: #FF1744;
  --amber: #E8A33D;
  --sma1: #5B8FF9;
  --sma2: #E8823D;
  --sma3: #E8D23D;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --nav-w: 160px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink);
  color: var(--text);
  font: 13px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
[hidden] { display: none !important; }
h2 { font-size: 20px; margin: 0 0 4px; font-weight: 700; }
code { font-family: var(--mono); font-size: 11px; background: var(--ink); padding: 1px 4px; border-radius: 3px; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.tiny { font-size: 10px; }
.mt6 { margin-top: 6px; }
.pad8 { padding: 8px; }
.error-text { color: var(--loss); font-size: 11px; }
.text { font-size: 12px; word-break: break-all; }

/* ── controls ─────────────────────────────────────────── */
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 7px 8px;
  min-width: 0;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--amber); }
input[type="date"] { color-scheme: dark; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%; background-size: 4px 4px; background-repeat: no-repeat; padding-right: 24px; }
textarea { resize: vertical; min-height: 90px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  font: inherit; font-size: 12px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
}
.btn:hover { background: var(--line); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--amber); color: var(--ink); border-color: var(--amber); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn.square { border-radius: 0; padding: 12px; border: none; }
.btn.danger-text { color: var(--loss); }
.btn.danger-outline { background: var(--ink); color: var(--loss); border-color: var(--loss); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn { position: relative; }

.tb-btn {
  font: inherit; font-size: 11px;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--line); border-radius: 3px;
  padding: 5px 8px; cursor: pointer; white-space: nowrap;
}
.tb-btn.tf { min-width: 36px; }
.tb-btn.on { background: var(--amber); color: var(--ink); font-weight: 600; border-color: var(--amber); }
.tb-btn:disabled { opacity: .4; cursor: default; }

/* ── login ─────────────────────────────────────────────── */
.login { position: fixed; inset: 0; display: flex; flex-direction: column; padding: 16px; overflow-y: auto; }
.login .login-card { margin: auto; }
.login-card { width: 100%; max-width: 320px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 28px 24px; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.login-card h1 { margin: 6px 0 0; font-size: 20px; }
.login-card p { margin: 0 0 8px; }
.logo { width: 30px; height: 30px; border-radius: 3px; background: var(--amber); color: var(--ink); font-weight: 700; display: grid; place-items: center; flex: none; }
.logo.big { width: 44px; height: 44px; font-size: 20px; margin: 0 auto; }

/* ── shell ─────────────────────────────────────────────── */
.app { display: flex; height: 100vh; height: 100dvh; }
.nav {
  width: var(--nav-w); flex: none;
  background: var(--panel2); border-right: 1px solid var(--line);
  padding: 16px 8px; display: flex; flex-direction: column; gap: 4px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  text-align: left; background: transparent; color: var(--muted);
  border: none; border-radius: 4px; padding: 10px; font: inherit; font-size: 12px; cursor: pointer;
  text-decoration: none;
}
.nav-btn:hover { background: var(--ink); }
.nav-btn.on { background: var(--panel); color: var(--amber); font-weight: 600; }
.nav-btn .ico { width: 18px; text-align: center; }
.main { flex: 1; min-width: 0; position: relative; overflow: hidden; }
.page { position: absolute; inset: 0; overflow: auto; display: flex; flex-direction: column; }
.page.padded { padding: 20px 24px; gap: 14px; display: block; }
.page.padded > * + * { margin-top: 14px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 8px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 12px; }
.panel-head { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 8px; }
.danger-title { color: var(--loss); font-size: 12px; font-weight: 700; margin-bottom: 8px; }

/* level / metric cards */
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 8px 10px; min-width: 0; }
.card .lbl { font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.card .val { font: 600 16px/1.3 var(--mono); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Playbook page ─────────────────────────────────────── */
.pb-header { display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--line); flex: none; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-title { font-size: 15px; font-weight: 700; }
.brand-sub { color: var(--muted); font-size: 10px; }
.head-stats { display: flex; gap: 18px; }
.stat { text-align: right; }
.stat .lbl { color: var(--muted); font-size: 9px; letter-spacing: 1px; text-transform: uppercase; }
.stat .val { font-size: 13px; font-weight: 600; }
.pb-body, .track-body { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 300px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--ink); min-height: 0; }
.track-list { width: 260px; }
.sidebar-top { padding: 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.filter-row { display: flex; gap: 6px; }
.add-row { flex-direction: row; }
.add-btn { width: 36px; padding: 0; font-size: 16px; font-weight: 700; }
.list { flex: 1; overflow: auto; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-item:hover { background: var(--panel); }
.list-item.on { background: var(--panel2); }
.list-item .name { font-weight: 600; font-size: 13px; }
.list-item .sub { color: var(--muted); font-size: 10px; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .rtag { font-weight: 600; font-size: 11px; font-family: var(--mono); }
.list-item .rm { background: transparent; border: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 0 4px; }
.list-empty { color: var(--muted); padding: 16px 12px; font-size: 12px; }
.pb-right { flex: 1; min-width: 0; overflow: auto; }
#pb-dashboard { padding: 20px 24px; }
#pb-dashboard > * + * { margin-top: 14px; }

/* ── trade detail ──────────────────────────────────────── */
.detail { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.detail-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.title-box { margin-right: auto; min-width: 0; }
.detail-title { font-size: 22px; font-weight: 700; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.r-badge { background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 7px 14px; font: 700 16px var(--mono); }
.back-btn { display: none; padding-left: 0; }
.live-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 12px; align-items: start; }
.detail-left { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.detail-right { display: flex; flex-direction: column; gap: 12px; }
.thumb { height: 100px; display: grid; place-items: center; background: var(--ink); border: 1px dashed var(--line); border-radius: 3px; color: var(--muted); font-size: 10px; margin-bottom: 8px; overflow: hidden; text-align: center; padding: 4px; }
.thumb img { max-height: 96px; max-width: 100%; cursor: zoom-in; display: block; }
.notes-text { font-size: 11px; margin-top: 8px; white-space: pre-wrap; word-break: break-word; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.stat-grid .sep { grid-column: 1 / -1; border-top: 1px solid var(--line); }
.stat-grid .lbl { font-size: 9px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.stat-grid .val { font: 12px var(--mono); }
.stat-grid .note { grid-column: 1 / -1; color: var(--muted); font-size: 9px; }
.ask-log { background: var(--ink); border: 1px solid var(--line); border-radius: 3px; height: 120px; overflow: auto; font-size: 11px; padding: 6px 8px; margin: 6px 0; }
.ask-log p { margin: 0 0 6px; }
.ask-row { display: flex; gap: 6px; }
.timeline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 10px 12px; }
.timeline .ttl { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 1px; margin-right: 4px; }
.chip { background: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; font-size: 10px; }

/* ── chart panel ───────────────────────────────────────── */
.chart-toolbar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.chart-toolbar .gap { width: 8px; }
.chart-toolbar .tf-label { margin-left: auto; color: var(--muted); font-size: 11px; }
.tool-hint { color: var(--amber); font-size: 10px; min-height: 14px; margin-top: 6px; }
.chart-card { background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 10px; }
.chart-card-head { display: flex; align-items: baseline; gap: 10px; }
.chart-card-head .t { font-size: 13px; font-weight: 600; }
.chart-card-head .status { margin-left: auto; color: var(--muted); font-size: 10px; text-align: right; }
.info-bar { font-size: 11px; padding: 4px 0 4px; min-height: 18px; }
.info-bar .k { color: var(--muted); }
.cross-lbl { color: var(--muted); font-size: 11px; min-height: 16px; padding-bottom: 4px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-wrap { position: relative; height: 440px; }
.chart-wrap.tall { height: 560px; }
.chart-wrap .lwc, .chart-wrap .tv { position: absolute; inset: 0; }
.chart-wrap .overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.chart-wrap.drawing .lwc { cursor: crosshair; }
.note-lbl { position: absolute; color: var(--sma2); font-size: 11px; white-space: nowrap; transform: translateY(-100%); text-shadow: 0 0 3px var(--panel), 0 0 3px var(--panel); }
.pending-dot { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--sma2); box-shadow: 0 0 0 2px var(--panel); }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); font-size: 13px; padding: 24px; text-align: center; }

/* ── track ─────────────────────────────────────────────── */
.track-main { flex: 1; min-width: 0; overflow: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.track-head { display: flex; align-items: center; gap: 10px; }
.track-head .detail-title { margin-right: auto; }

/* ── stats / studies / simulator ───────────────────────── */
.equity-wrap { position: relative; height: 300px; }
.equity-wrap svg { width: 100%; height: 100%; display: block; }
.equity-tip { position: absolute; pointer-events: none; background: var(--ink); border: 1px solid var(--line); border-radius: 3px; padding: 4px 8px; font-size: 11px; white-space: nowrap; transform: translate(-50%, -120%); }
.equity-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; }
.study-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.study-row .name { font-size: 13px; font-weight: 600; width: 160px; overflow: hidden; text-overflow: ellipsis; }
.study-row .cell .lbl { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.study-row .cell .val { font-size: 13px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; }
.form-grid label, .tf-form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 10px; letter-spacing: .5px; text-transform: uppercase; }
.out-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.out-grid .lbl { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.out-grid .val { font-size: 18px; font-weight: 700; }

/* ── modal / toast ─────────────────────────────────────── */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; width: 100%; max-width: 440px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.modal.wide { max-width: 560px; }
.modal.image { max-width: min(1100px, 100%); }
.modal-head { padding: 14px 16px 0; font-weight: 700; font-size: 14px; }
.modal-body { padding: 12px 16px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 16px 14px; }
.modal-body img { max-width: 100%; display: block; margin: 0 auto; }
.tf-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.tf-form .full { grid-column: 1 / -1; }
.preview { font-weight: 600; font-size: 12px; min-height: 18px; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 8px 14px; z-index: 60; max-width: calc(100% - 32px); font-size: 12px; }
.toast.err { border-color: var(--loss); }

/* ── phones / narrow windows ───────────────────────────── */
@media (max-width: 1100px) {
  .detail-body { grid-template-columns: minmax(0, 1fr); }
  .detail-right { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 820px) {
  :root { --nav-h: 58px; }
  .app { flex-direction: column-reverse; }
  .nav {
    width: 100%; flex-direction: row; justify-content: space-around; gap: 0;
    padding: 4px 2px calc(4px + var(--safe-b)); border-right: none; border-top: 1px solid var(--line);
  }
  .nav-btn { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 9px; flex: 1; text-align: center; align-items: center; }
  .nav-btn .ico { font-size: 16px; width: auto; }
  .page.padded { padding: 16px; }
  .pb-header { padding: 10px 16px; }
  .head-stats { gap: 12px; width: 100%; justify-content: space-between; }
  .stat { text-align: left; }
  .sidebar, .track-list { width: 100%; border-right: none; }
  #page-playbook.show-detail .pb-header { display: none; }
  .pb-body.show-detail .sidebar, .track-body.show-detail .track-list { display: none; }
  .pb-body:not(.show-detail) .pb-right, .track-body:not(.show-detail) .track-main { display: none; }
  .back-btn { display: inline-flex; }
  .detail, .track-main { padding: 12px 16px 16px; }
  .detail-title { font-size: 20px; }
  .head-actions { width: 100%; }
  .head-actions .r-badge { margin-right: auto; }
  .chart-wrap, .chart-wrap.tall { height: 380px; }
  .cards-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tf-form { grid-template-columns: 1fr; }
  .chart-toolbar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .chart-toolbar .tf-label { display: none; }
  input, select, textarea { font-size: 16px; } /* stops iOS zooming into inputs */
  .study-row .name { width: 100%; }
}

/* ── admin console ─────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { font: inherit; font-size: 12px; background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; margin-bottom: -1px; }
.tab.on { color: var(--amber); border-bottom-color: var(--amber); font-weight: 600; }
.adm-filters { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.adm-filters input { flex: 1 1 240px; }
.adm-filters select { flex: 0 0 auto; width: auto; min-width: 150px; }
.panel.flush { padding: 0; overflow: visible; }
.utable { width: 100%; border-collapse: collapse; font-size: 12px; }
.utable th { text-align: left; color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.utable td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.utable tr:last-child td { border-bottom: none; }
.utable tr.inactive td { opacity: .55; }
.utable tr.inactive td.act { opacity: 1; }
.utable .num { text-align: right; font-family: var(--mono); }
.utable td.act { text-align: right; white-space: nowrap; }
.utable .uname { font-weight: 600; font-size: 13px; }
.utable .usub { color: var(--muted); font-size: 11px; }
.utable .empty { color: var(--muted); text-align: center; padding: 24px; }
.badge { display: inline-block; font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--line); white-space: nowrap; }
.badge.admin { color: var(--amber); border-color: rgba(232,163,61,.5); }
.badge.user { color: var(--muted); }
.badge.active { color: var(--gain); border-color: rgba(0,200,83,.45); }
.badge.inactive { color: var(--loss); border-color: rgba(255,23,68,.45); }
.badge.pw { color: var(--sma3); border-color: rgba(232,210,61,.4); }
.badge.you { color: var(--sma1); border-color: rgba(91,143,249,.5); margin-left: 6px; }
.menu-wrap { position: relative; display: inline-block; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); min-width: 200px; background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 4px; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,.45); text-align: left; }
.menu button { display: block; width: 100%; text-align: left; background: transparent; border: none; color: var(--text); font: inherit; font-size: 12px; padding: 8px 10px; border-radius: 3px; cursor: pointer; }
.menu button:hover:not(:disabled) { background: var(--line); }
.menu button:disabled { color: var(--muted); opacity: .5; cursor: default; }
.menu button.danger { color: var(--loss); }
.menu hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }
.log-list { max-height: 60vh; overflow: auto; }
.log-row { display: grid; grid-template-columns: 150px 120px 150px 1fr; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 12px; align-items: baseline; }
.log-row .when { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.log-row .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.log-row .what.bad { color: var(--loss); }
.log-row .what.good { color: var(--gain); }
.log-row .ldetail { color: var(--muted); overflow-wrap: anywhere; }
.pw-row { display: flex; gap: 6px; }
.pw-row input { font-family: var(--mono); }
.check { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; text-transform: none !important; letter-spacing: 0 !important; font-size: 12px !important; color: var(--text) !important; }
.check input { width: auto; }
.cred-box { background: var(--ink); border: 1px solid var(--line); border-radius: 3px; padding: 10px 12px; font-family: var(--mono); font-size: 13px; line-height: 1.7; margin: 8px 0; user-select: all; }
@media (max-width: 820px) {
  .utable thead { display: none; }
  .utable, .utable tbody, .utable tr, .utable td { display: block; width: 100%; }
  .utable tr { padding: 10px 12px; border-bottom: 1px solid var(--line); position: relative; }
  .utable td { border: none; padding: 2px 0; }
  .utable td.act { position: absolute; top: 10px; right: 12px; width: auto; }
  .utable td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); font-size: 11px; }
  .utable td.badges { display: flex; gap: 6px; padding: 4px 0; }
  .utable .num { text-align: left; font-family: inherit; }
  .log-row { grid-template-columns: 1fr; gap: 2px; }
}
.admin-only { display: none !important; }
body.is-admin .admin-only { display: inline-flex !important; }

/* ── chart focus mode ──────────────────────────────────── */
.chart-focus { position: fixed; inset: 0; z-index: 40; background: var(--ink); display: flex; flex-direction: column; gap: 4px; padding: 8px 10px calc(8px + var(--safe-b)); }
.chart-focus > .chart-slot { flex: 1; min-height: 0; display: flex; }
.chart-focus .chart-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chart-focus .chart-wrap { flex: 1; min-height: 0; height: auto !important; }
.chart-focus .tool-hint { margin-top: 2px; }
.chart-focus .tool-hint:empty { min-height: 0; margin: 0; }
.chart-focus .chart-toolbar .tf-label { display: inline; }
.chart-focus .chart-toolbar { flex-wrap: wrap; overflow: visible; }
