:root {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #202021;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:        #2c2c2a;
  --border:      rgba(255, 255, 255, 0.10);
  --accent:      #3987e5;
  --accent-dim:  #1c5cab;
  --good:        #0ca30c;
  --critical:    #d03b3b;
  --warning:     #fab219;
  --radius:      14px;
  --radius-sm:   8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  background-image:
    radial-gradient(circle at 15% 0%, rgba(57, 135, 229, 0.08), transparent 45%),
    radial-gradient(circle at 85% 20%, rgba(28, 92, 171, 0.06), transparent 40%);
  background-attachment: fixed;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #6cb4ff; }

/* ---------- layout shell ---------- */

.shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.75rem 4rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px 2px rgba(57, 135, 229, 0.65);
}

.crumb {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.crumb a { color: var(--text-secondary); }
.crumb a:hover { color: var(--accent); }

.tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.tab {
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.tab:hover { color: var(--text-primary); background: var(--surface-2); }
.tab.active {
  color: var(--text-primary);
  background: var(--surface-2);
  border-color: var(--border);
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 1.75rem;
}

/* ---------- cards / grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.card.link-card {
  display: block;
  color: inherit;
}
.card.link-card:hover {
  border-color: rgba(57, 135, 229, 0.45);
  transform: translateY(-2px);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.account-id {
  font-size: 1.05rem;
  font-weight: 700;
}

.card-links {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.9rem;
  font-size: 0.85rem;
}

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-demo {
  color: var(--good);
  background: rgba(12, 163, 12, 0.12);
}
.badge-demo::before { background: var(--good); }

.badge-live {
  color: var(--critical);
  background: rgba(208, 59, 59, 0.14);
}
.badge-live::before { background: var(--critical); }

.badge-neutral {
  color: var(--text-secondary);
  background: var(--surface-2);
}
.badge-neutral::before { background: var(--text-muted); }

/* ---------- stat tiles ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
}

.stat-value.accent { color: var(--accent); }
.stat-value.pos-long { color: var(--good); }
.stat-value.pos-short { color: var(--critical); }

/* ---------- table ---------- */

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  padding: 0.65rem 1rem;
  text-align: left;
  font-size: 0.87rem;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

.side-buy { color: var(--good); font-weight: 600; }
.side-sell { color: var(--critical); font-weight: 600; }

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

.state-pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.state-filled { color: var(--good); }
.state-canceled { color: var(--text-muted); }

.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .icon {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  opacity: 0.6;
}

/* ---------- buttons ---------- */

.page-header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn-danger {
  background: rgba(208, 59, 59, 0.12);
  color: var(--critical);
  border: 1px solid rgba(208, 59, 59, 0.35);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
}
.btn-danger:hover {
  background: rgba(208, 59, 59, 0.2);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary:hover {
  background: #4f97e8;
}

.link-button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
}
.link-button:hover {
  color: var(--accent);
}

/* ---------- forms ---------- */

.form-row {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-row label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.form-row input[type="text"],
.form-row input[type="password"],
.form-row input[type="number"],
.form-row select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}
.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.form-row-checkbox label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.form-warning {
  font-size: 0.82rem;
  color: var(--warning);
  background: rgba(250, 178, 25, 0.1);
  border: 1px solid rgba(250, 178, 25, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  margin-bottom: 1rem;
}

/* ---------- raw payload modal ---------- */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1.5rem;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.modal-body {
  margin: 0;
  padding: 1.1rem;
  overflow: auto;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- login page ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    radial-gradient(circle at 15% 0%, rgba(57, 135, 229, 0.08), transparent 45%),
    radial-gradient(circle at 85% 20%, rgba(28, 92, 171, 0.06), transparent 40%);
}

.login-card {
  width: 320px;
  padding: 2rem;
}
