:root {
  --bg: #161b22;
  --panel: #1c2430;
  --panel-2: #273142;
  --line: #39485d;
  --text: #ffffff;
  --muted: #9aa6b7;
  --pos: #21c36b;
  --neg: #ff5a5f;
  --accent: #f7a600;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, select, input { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* LOGIN */

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}

.login-title { font-weight: 700; letter-spacing: 1px; text-align: center; }

.login-card input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
}

.login-card button {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-weight: 700;
  cursor: pointer;
}

.login-error { color: var(--neg); font-size: 13px; min-height: 1em; text-align: center; }

/* APP */

.app {
  max-width: 900px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(4px + env(safe-area-inset-top)) 8px 4px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}

.tabs { display: flex; gap: 4px; }

.tab {
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.tab.active { background: var(--bg); color: var(--text); }

.tab-count {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  margin-left: 2px;
  border-radius: 9px;
  background: var(--line);
  font-size: 11px;
  text-align: center;
}

.topbar-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  font-size: 17px;
  cursor: pointer;
}

.icon-btn.spin { animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.ok { background: var(--pos); box-shadow: 0 0 6px var(--pos); }
.status-dot.warn { background: var(--accent); }
.status-dot.bad { background: var(--neg); box-shadow: 0 0 6px var(--neg); }

/* FILTERS */

.filters {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.chip-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  align-items: center;
}

.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
}

.chip.on { background: var(--accent); border-color: var(--accent); color: #000; font-weight: 700; }

.seg {
  flex: none;
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.seg button {
  background: transparent;
  border: none;
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.seg button.on { background: var(--line); color: var(--text); }

.sort-select {
  flex: none;
  margin-left: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
}

/* PANES: one visible at a time, or both in split mode */

.panes { flex: 1; display: flex; flex-direction: column; }

.pane { display: flex; flex-direction: column; min-height: 0; }
body:not(.split) .pane:not(.active) { display: none; }

.pane-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.pane-title {
  display: none;
  flex: none;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #c4b5fd;
}

.pane-head .sort-select { margin-left: auto; }

/* SUMMARY */

.summary {
  display: flex;
  gap: 12px;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.summary::-webkit-scrollbar { display: none; }
.summary b { color: var(--text); }
.summary b.pos { color: var(--pos); }
.summary b.neg { color: var(--neg); }

/* SPLIT MODE: fixed-height screen, each half scrolls on its own */

body.split .app { height: 100dvh; overflow: hidden; }
body.split .panes { min-height: 0; overflow: hidden; }
body.split .pane-title { display: inline; }
body.split #pane-orders { flex: 0 0 var(--split, 50%); }
body.split #pane-positions { flex: 1 1 0; }

body.split .pane .list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.splitter {
  flex: none;
  display: grid;
  place-items: center;
  height: 16px;
  background: #1a1430;
  border-top: 1px solid #3b2a63;
  border-bottom: 1px solid #3b2a63;
  cursor: row-resize;
  touch-action: none;
  user-select: none;
}

.splitter span {
  width: 46px;
  height: 4px;
  border-radius: 2px;
  background: #a855f7;
  box-shadow: 0 0 6px #a855f7;
}

.splitter.dragging span { width: 64px; box-shadow: 0 0 10px #c084fc, 0 0 18px #a855f7; }

/* SPLIT BUTTON: neon purple glow when on */

.split-btn {
  height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid #3b3f5c;
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: box-shadow 0.2s, border-color 0.2s, color 0.2s, background 0.2s;
}

.split-btn.on {
  background: #2a1650;
  border-color: #a855f7;
  color: #ede4ff;
  text-shadow: 0 0 6px #c084fc;
  box-shadow:
    0 0 6px rgba(168, 85, 247, 0.9),
    0 0 16px rgba(168, 85, 247, 0.55),
    inset 0 0 8px rgba(168, 85, 247, 0.35);
}

/* LIST: one compact line per order/position */

.list {
  font-variant-numeric: tabular-nums;
}

.row {
  display: grid;
  align-items: center;
  column-gap: 8px;
  padding: 0 10px 0 8px;
  min-height: 34px;
  border-bottom: 1px solid #222b38;
  border-left: 3px solid transparent;
  font-size: 13px;
}

.list.orders .row { grid-template-columns: minmax(0, 1fr) 12px auto 64px; }
.list.positions .row { grid-template-columns: minmax(0, 1fr) 12px auto 58px 72px; }

.row.long { border-left-color: var(--pos); }
.row.short { border-left-color: var(--neg); }
.row:nth-child(even):not(.head) { background: #1a212c; }

.row.head {
  position: sticky;
  top: 0;
  min-height: 24px;
  background: var(--bg);
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom-color: var(--line);
}

.inst {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
}

.sym {
  font-weight: 700;
  margin-left: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sym small { font-weight: 400; color: var(--muted); font-size: 10px; }

.c-side { font-weight: 800; font-size: 12px; text-align: center; }
.c-num { text-align: right; white-space: nowrap; }
.c-usd { font-weight: 700; }

.c-pnl { font-weight: 700; line-height: 1.1; }
.c-pnl small { display: block; font-size: 10px; font-weight: 400; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }

/* BADGES (colors from the desktop widget) */

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 19px;
  height: 16px;
  padding: 0 3px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  color: #000;
}

.badge.ex.binance { background: #111111; color: #f0b90b; border: 1px solid #f0b90b; }
.badge.ex.bybit { background: #f7a600; }
.badge.ex.gate { background: #2d57e5; color: #fff; }
.badge.ex.kucoin { background: #101820; color: #23af91; border: 1px solid #23af91; }
.badge.ex.mexc { background: #efb6df; }
.badge.ex.hyperliquid { background: #7c3aed; color: #fff; }
.badge.ex.htx { background: #ffffff; }
.badge.ex.bitget { background: #00f0ff; }
.badge.ex.okx { background: #ffffff; }
.badge.ex.aster { background: #f4c27a; }
.badge.ex.lighter { background: #000000; color: #ffffff; border: 1px solid #ffffff; }
.badge.ex.default { background: #58667e; color: #fff; }

.badge.mk.spot { background: #f7a600; min-width: 16px; }
.badge.mk.fut { background: #21c36b; min-width: 16px; }

/* FOOTER */

.footer {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 10px calc(4px + env(safe-area-inset-bottom));
  background: var(--panel-2);
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}

.errors-toggle {
  background: #6d1515;
  border: none;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}

.errors {
  white-space: pre-wrap;
  word-break: break-word;
  background: #2a1414;
  color: #ffb3b3;
  font-size: 11px;
  padding: 10px 12px;
  max-height: 40vh;
  overflow: auto;
}
