* { box-sizing: border-box; margin: 0; padding: 0; }

:root[data-theme="dark"] {
  --bg: #0a0b10;
  --bg-soft: #0e1018;
  --card: #131520;
  --card-2: #171a27;
  --border: #232636;
  --text: #eceefb;
  --text-dim: #9296ad;
  --text-faint: #5d6178;
  --green: #2dd4a0;
  --red: #f7596d;
  --brand: #8b6bff;
  --brand-2: #36cfe0;
  --row-hover: #1a1d2c;
  --shadow: 0 12px 28px -12px rgba(0, 0, 0, 0.55);
}

:root[data-theme="light"] {
  --bg: #f1f2f8;
  --bg-soft: #e8eaf2;
  --card: #ffffff;
  --card-2: #f6f7fb;
  --border: #e1e3ee;
  --text: #161826;
  --text-dim: #5d6178;
  --text-faint: #9a9db0;
  --green: #14a87f;
  --red: #d6304a;
  --brand: #6a47e8;
  --brand-2: #0ea5b8;
  --row-hover: #f1f2fb;
  --shadow: 0 12px 28px -14px rgba(40, 44, 80, 0.18);
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  height: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-weight: 700; letter-spacing: -0.01em; }
.num, .kpi-value, .totals-value, .info-price, .info-ohlc { font-family: "JetBrains Mono", monospace; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------------- App shell ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 196px;
  flex: 0 0 auto;
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 26px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; color: #0a0b10; flex: none;
}
.brand-name { font-size: 12.5px; line-height: 1.25; color: var(--text-dim); }
.brand-name b { color: var(--text); font-size: 14px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  border: none; background: transparent; color: var(--text-dim);
  padding: 10px 12px; border-radius: 10px; font-size: 13px; font-weight: 500;
  text-align: left; transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--card-2); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(139, 107, 255, 0.16), rgba(54, 207, 224, 0.08));
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--brand);
}
.nav-icon { width: 16px; text-align: center; font-size: 13px; }

.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }
.mode-pill {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em;
  padding: 6px 10px; border-radius: 8px; text-align: center;
  background: var(--card-2); color: var(--text-dim); border: 1px solid var(--border);
}
.live-pill {
  display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-dim);
  padding: 6px 10px; border-radius: 8px; font-weight: 600;
}
.live-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(45, 212, 160, 0.18); }
.live-pill.offline .dot { background: var(--red); box-shadow: 0 0 0 3px rgba(247, 89, 109, 0.18); }
.live-pill.offline #liveLabel::after { content: ""; }

.main { flex: 1; min-width: 0; padding: 22px 28px 36px; }

/* ---------------- Topbar ---------------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 21px; }
.halt-badge {
  font-size: 11px; font-weight: 700; color: var(--red);
  background: rgba(247, 89, 109, 0.12); border: 1px solid rgba(247, 89, 109, 0.35);
  padding: 5px 10px; border-radius: 8px;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.world-clock {
  display: flex; align-items: center; gap: 7px; font-size: 12px;
  padding: 7px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text-dim); font-weight: 600;
}
.world-clock .clock-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--green); flex: none;
  box-shadow: 0 0 0 3px rgba(45, 212, 160, 0.18);
  animation: clock-pulse 2s ease-in-out infinite;
}
.world-clock .clock-time { font-family: "JetBrains Mono", monospace; color: var(--text); font-size: 12.5px; letter-spacing: 0.02em; }
.world-clock .clock-tz { font-size: 9.5px; color: var(--text-faint); letter-spacing: 0.04em; }
.world-clock .clock-sep { color: var(--border); margin-right: 7px; }
.world-clock .clock-utc-group { display: flex; align-items: center; gap: 7px; }
@keyframes clock-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.theme-toggle {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text-dim); font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.theme-toggle .theme-icon-light { display: none; }
:root[data-theme="light"] .theme-toggle .theme-icon-dark { display: none; }
:root[data-theme="light"] .theme-toggle .theme-icon-light { display: inline; }

/* ---------------- KPI cards ---------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 18px; display: flex; gap: 13px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--brand), var(--brand-2));
}
.kpi-icon {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  background: var(--card-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 15px; color: var(--brand-2);
}
.kpi-body { min-width: 0; flex: 1; }
.kpi-label { font-size: 11px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value-row { margin-top: 3px; }
.kpi-value { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }
.kpi-delta { font-size: 12px; font-weight: 600; margin-top: 4px; color: var(--text-dim); }
.kpi-delta.muted { color: var(--text-faint); font-weight: 500; }
.up { color: var(--green) !important; }
.down { color: var(--red) !important; }
.flat { color: var(--text-dim) !important; }

/* ---------------- Content grid ---------------- */
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 332px; gap: 16px; align-items: start; }
.content-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.content-side { display: flex; flex-direction: column; gap: 16px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0; }
.card-header h2 { font-size: 14.5px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; padding: 4px 6px 14px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th { text-align: left; color: var(--text-faint); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th.num, td.num { text-align: right; }
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.empty-row td { text-align: center; color: var(--text-faint); padding: 26px 12px; }

.coin-cell { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.coin-badge { border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }

.badge { font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.badge.long { background: rgba(45, 212, 160, 0.14); color: var(--green); }
.badge.short { background: rgba(247, 89, 109, 0.14); color: var(--red); }
.badge.market { background: var(--card-2); color: var(--text-dim); }
.badge.open { background: rgba(139, 107, 255, 0.14); color: var(--brand); }

/* ---------------- Performance list ---------------- */
.perf-list { display: flex; flex-direction: column; padding: 12px 16px 16px; gap: 12px; }
.perf-row { display: flex; flex-direction: column; gap: 6px; }
.perf-row-top { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; }
.perf-pnl { font-weight: 700; }
.perf-meta { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--text-faint); }
.perf-bar-track { height: 6px; border-radius: 4px; background: var(--card-2); overflow: hidden; }
.perf-bar-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.perf-empty { color: var(--text-faint); padding: 4px 0 14px; text-align: center; }

/* ---------------- Totals strip ---------------- */
.totals-strip { display: grid; grid-template-columns: repeat(3, 1fr); padding: 16px; gap: 10px; }
.totals-item { text-align: center; padding: 8px 4px; border-radius: 10px; background: var(--card-2); }
.totals-value { font-size: 16px; font-weight: 700; margin-top: 4px; }

/* ---------------- Timeline ---------------- */
.timeline { display: flex; flex-direction: column; padding: 8px 16px 16px; }
.timeline-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.timeline-dot.up { background: var(--green); box-shadow: 0 0 0 4px rgba(45, 212, 160, 0.14); }
.timeline-dot.down { background: var(--red); box-shadow: 0 0 0 4px rgba(247, 89, 109, 0.14); }
.timeline-dot.flat { background: var(--text-faint); }
.timeline-body { flex: 1; min-width: 0; }
.timeline-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; font-weight: 600; }
.timeline-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.timeline-pnl { font-weight: 700; font-size: 12.5px; white-space: nowrap; }
.timeline-empty { color: var(--text-faint); text-align: center; padding: 18px 0; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translate(-50%, 16px);
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 12.5px; font-weight: 600;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s;
  z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- Responsive ---------------- */
@media (max-width: 1180px) {
  .content-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar { width: 64px; padding: 18px 10px; }
  .brand-name, .nav-label, .mode-pill, .live-pill span:not(.dot) { display: none; }
  .sidebar-brand { justify-content: center; padding-bottom: 18px; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-item.active { box-shadow: none; background: linear-gradient(135deg, rgba(139,107,255,0.18), rgba(54,207,224,0.1)); }
  .sidebar-foot { align-items: center; }
}
@media (max-width: 620px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
  .world-clock .clock-utc-group { display: none; }
}
