:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #172033;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --green: #22c55e;
  --red: #ef4444;
  --accent: #38bdf8;
  --amber: #f59e0b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 24px;
}

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}

.brand .logo {
  display: flex;
  flex: none;
  color: var(--accent);
  font-size: 1.2rem;
}
.brand .logo img { width: 24px; height: 24px; display: block; }
.brand .sub { color: var(--muted); font-size: 0.78rem; font-weight: 500; }

.tabs { display: flex; gap: 6px; flex: 1; overflow-x: auto; padding: 2px 0; }

.tab {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.tab:hover { color: var(--text); }
.tab.active {
  color: #0f172a;
  background: var(--accent);
}

.logout {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.logout:hover { color: var(--red); border-color: var(--red); }

/* ---------- Runtime ---------- */
.runtime {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 16px;
  margin: 12px 14px 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.9rem;
}

.runtime .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
  flex: none;
}

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.strong { font-weight: 700; }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  padding: 12px 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 0;
}

.card.big {
  grid-column: span 2;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
}

.card .label {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.card .value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.card.big .value { font-size: 1.6rem; }

.pos { color: var(--green); }
.neg { color: var(--red); }
.neutral { color: var(--text); }

/* ---------- Panels ---------- */
.panel {
  margin: 12px 14px 0;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
}

.panel h2 .muted { font-size: 0.78rem; font-weight: 500; }

.empty { color: var(--muted); font-size: 0.9rem; }

/* ---------- Open positions ---------- */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.pos-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
}

.pos-card.side-long { border-left-color: var(--green); }
.pos-card.side-short { border-left-color: var(--red); }

.pos-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.badge {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
}

.pos-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}

.side-long { color: var(--green); font-weight: 700; }
.side-short { color: var(--red); font-weight: 700; }

/* ---------- Equity chart ---------- */
.legend-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend { display: inline-flex; align-items: center; gap: 6px; }

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.equity {
  width: 100%;
  height: auto;
  display: block;
}

.swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  margin-right: 6px;
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  min-width: 640px;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
}

tbody tr:hover { background: rgba(51, 65, 85, 0.25); }

/* ---------- Footer ---------- */
.foot {
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  margin-top: 20px;
  padding: 0 14px;
}

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px 24px;
  text-align: center;
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 6px;
}
.login-logo img { width: 48px; height: 48px; display: block; }

.login-card h1 { margin: 0; font-size: 1.4rem; }

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
  text-align: left;
}

.login-card label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
}

.login-card input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 1rem;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-card button {
  margin-top: 14px;
  background: var(--accent);
  color: #0f172a;
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.login-card button:active { transform: scale(0.99); }

.login-error {
  margin-top: 12px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: var(--red);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
}

/* ---------- Wide screens ---------- */
@media (min-width: 720px) {
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .panel { margin-left: 20px; margin-right: 20px; }
  .runtime { margin-left: 20px; margin-right: 20px; }
}
