:root {
  --bg: #0d0d0d;
  --panel: #141414;
  --card: #181818;
  --line: #2a2a2a;
  --fg: #e6e6e6;
  --muted: #8a8a8a;
  --pos: #2ecc71;
  --neg: #ff6b6b;
  --amber: #f1c40f;
  --blue: #5dade2;
  --call: #7effb8;
  --put: #f081ff;
  --btn: #262626;
  --book: #2f3b4a;
  --exit: #4a2f3b;
  --add: #2f4a36;
  --danger: #7a1f1f;
  --top-safe: calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom-safe: calc(var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.flat { color: var(--fg); }
.call { color: var(--call); }
.put { color: var(--put); }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100%; }
#top { flex: 0 0 auto; background: var(--panel); border-bottom: 1px solid var(--line);
  padding: calc(8px + var(--top-safe)) 12px 8px; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .06em; padding: 2px 8px; border-radius: 99px;
  background: #1f3a2a; color: var(--pos); }
.badge.live { background: #4a1414; color: #ff8a8a; }
.conn { font-size: 12px; color: var(--muted); }
.conn.ok { color: var(--pos); } .conn.warn { color: var(--amber); } .conn.bad { color: var(--neg); }
.icon { background: none; border: 0; font-size: 22px; padding: 0 6px; min-width: 40px; min-height: 36px; }
.kpis { display: grid; grid-template-columns: 1.2fr 1.2fr 1fr; gap: 8px; margin-top: 6px; }
.label { font-size: 11px; color: var(--muted); }
.kpi { font-size: 20px; font-weight: 700; }
.kpi.small { font-size: 15px; font-weight: 600; padding-top: 4px; }
.banner { margin-top: 8px; padding: 6px 10px; border-radius: 8px; background: #3a300c; color: var(--amber); font-size: 13px; }
.banner.bad { background: #3a1212; color: #ff9d9d; }
.banner.info { background: #16263a; color: var(--blue); }

main { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 10px 16px; }
.pane-head { display: flex; align-items: center; gap: 8px; margin: 2px 2px 8px; color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 28px 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.card.pending { border-style: dashed; }
.title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qty { color: var(--blue); font-weight: 700; }
.pnl { font-size: 20px; font-weight: 800; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; border-radius: 6px; padding: 0 4px; }
.sub { margin-top: 2px; justify-content: space-between; font-size: 13px; }
.flash-up { animation: flashUp .9s ease-out; }
.flash-down { animation: flashDown .9s ease-out; }
@keyframes flashUp { from { background: rgba(46, 204, 113, .28); } to { background: transparent; } }
@keyframes flashDown { from { background: rgba(255, 107, 107, .28); } to { background: transparent; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: #1e1e1e; border-radius: 99px; padding: 5px 10px; font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; min-height: 30px; }
.chip.sl { border-color: #5a2a2a; color: #ff9d9d; }
.chip.tp { border-color: #24503a; color: #8ff0b5; }
.chip.entry { border-color: #2a4a6a; color: var(--blue); }
.chip.order { border-color: #444; }
.chip.none { color: var(--amber); border-color: #5a4a14; }
.warn { color: var(--amber); margin-top: 6px; }
.actions { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }

.btn { background: var(--btn); border: 1px solid #333; border-radius: 10px; min-height: 44px; padding: 0 6px; font-weight: 600; }
.btn:disabled { opacity: .38; }
.btn.small { min-height: 34px; font-size: 13px; padding: 0 10px; }
.btn.active { background: #34506e; border-color: #4a70a0; }
.btn.book { background: var(--book); }
.btn.exit { background: var(--exit); }
.btn.add { background: var(--add); }
.btn.danger { background: var(--danger); border-color: #a33; color: #fff; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.busy { position: relative; color: transparent; }
.btn.busy::after { content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #aaa; border-top-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.list { display: flex; flex-direction: column; gap: 6px; }
.line { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.line.static { cursor: default; }
.line .row { margin-bottom: 2px; }
.role-stop { color: #ff9d9d; } .role-target { color: #8ff0b5; } .role-entry { color: var(--blue); } .role-master { color: var(--amber); }
.event { font: 12px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace; padding: 6px 8px; border-bottom: 1px solid #1f1f1f; white-space: pre-wrap; }
.event.fill { color: var(--pos); } .event.exit { color: var(--put); } .event.cancel { color: var(--muted); }
.event.error { color: var(--neg); } .event.trigger { color: var(--blue); }

#tabs { flex: 0 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: var(--bottom-safe); }
#tabs button { background: none; border: 0; min-height: 50px; color: var(--muted); font-size: 13px; }
#tabs button.active { color: var(--fg); box-shadow: inset 0 2px 0 var(--blue); }
.count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 99px; background: #2a2a2a; font-size: 11px; color: var(--fg); }
.count:empty { display: none; }

.shade { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 88%; overflow-y: auto; background: var(--panel);
  border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 12px 14px calc(16px + var(--bottom-safe));
  transform: translateY(100%); transition: transform .18s ease-out; }
.sheet.open { transform: translateY(0); }
.sheet-head { display: flex; align-items: center; margin-bottom: 6px; }
.sheet-title { font-weight: 700; font-size: 16px; }
.stats { color: var(--muted); margin-bottom: 4px; }
.summary { font-size: 15px; background: #1d1d1d; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 6px 0; }
.editor { margin-top: 6px; }
.price-input { width: 100%; font: 700 30px ui-monospace, "SF Mono", Menlo, Consolas, monospace; text-align: center; padding: 8px;
  background: #0f0f0f; color: var(--fg); border: 1px solid #333; border-radius: 10px; margin: 6px 0; }
.small-input { width: 80px; font: 14px ui-monospace, Menlo, Consolas, monospace; background: #0f0f0f; color: var(--fg);
  border: 1px solid #333; border-radius: 8px; padding: 6px; }
.nudges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0; }
.nudges .btn { flex: 1 1 0; }
.nudges.price { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.nudges.price .btn { padding: 0; font-size: 12px; }
.preview { min-height: 36px; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 6px; margin: 8px 0; color: var(--muted); font-size: 14px; }
.check input[type=checkbox] { width: 20px; height: 20px; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 10px 0; }
.stepper .btn { min-width: 56px; font-size: 20px; }
.big { font-size: 28px; font-weight: 800; min-width: 70px; text-align: center; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hold { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.hold-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(255, 255, 255, .22); }
.hold-label { position: relative; }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(66px + var(--bottom-safe)); z-index: 20; padding: 10px 12px;
  border-radius: 10px; background: #222; border: 1px solid #333; font-size: 14px; opacity: 0; pointer-events: none;
  transform: translateY(8px); transition: opacity .15s, transform .15s; }
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-color: #24503a; color: #8ff0b5; }
.toast.error { border-color: #6a2424; color: #ff9d9d; }
.toast.warn { border-color: #5a4a14; color: var(--amber); }
.fatal { padding: calc(40px + var(--top-safe)) 24px; text-align: center; color: var(--muted); }
.fatal h1 { color: var(--fg); font-size: 20px; }
