:root {
  color-scheme: light;
  --surface-1: #ffffff;
  --page-plane: #f5f6f8;
  --text-primary: #14151a;
  --text-secondary: #5b5f6b;
  --text-muted: #8b8f99;
  --gridline: #e7e8ec;
  --border: rgba(20, 21, 26, 0.08);
  --series-blue: #2a63d6;
  --series-blue-soft: rgba(42, 99, 214, 0.1);
  --series-green: #008300;
  --status-good: #0ca30c;
  --status-critical: #d03b3b;
  --status-warning: #b8790a;
  --shadow-sm: 0 1px 2px rgba(20, 21, 26, 0.05);
  --shadow-md: 0 8px 24px rgba(20, 21, 26, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1c1e24;
    --page-plane: #131418;
    --text-primary: #f4f5f7;
    --text-secondary: #b3b6c0;
    --text-muted: #7c8090;
    --gridline: #2b2d34;
    --border: rgba(255, 255, 255, 0.08);
    --series-blue: #5b8ded;
    --series-blue-soft: rgba(91, 141, 237, 0.16);
    --series-green: #2fa62f;
    --status-good: #24c624;
    --status-critical: #e66767;
    --status-warning: #e0a736;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1c1e24;
  --page-plane: #131418;
  --text-primary: #f4f5f7;
  --text-secondary: #b3b6c0;
  --text-muted: #7c8090;
  --gridline: #2b2d34;
  --border: rgba(255, 255, 255, 0.08);
  --series-blue: #5b8ded;
  --series-blue-soft: rgba(91, 141, 237, 0.16);
  --status-good: #24c624;
  --status-critical: #e66767;
  --status-warning: #e0a736;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Sidebar is always dark, independent of content theme - brand identity */
:root {
  --sidebar-bg: #14161c;
  --sidebar-bg-raised: #1b1e26;
  --sidebar-text: #e7e8ec;
  --sidebar-text-muted: #8b8f9e;
  --sidebar-border: rgba(255, 255, 255, 0.07);
  --sidebar-active: #2a63d6;
}

* { box-sizing: border-box; }

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

/* ---------- Shell / Sidebar layout ---------- */

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--sidebar-active);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--sidebar-text-muted);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item:hover {
  background: var(--sidebar-bg-raised);
  color: var(--sidebar-text);
}

.nav-item.is-active {
  background: var(--sidebar-active);
  color: #fff;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--sidebar-bg-raised);
  color: var(--sidebar-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  text-transform: uppercase;
}

.sidebar-user-info { min-width: 0; }

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--sidebar-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-sub {
  font-size: 11.5px;
  color: var(--sidebar-text-muted);
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 1px solid var(--sidebar-border);
  background: transparent;
  color: var(--sidebar-text-muted);
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.logout-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.logout-btn:hover {
  background: rgba(208, 59, 59, 0.12);
  border-color: rgba(208, 59, 59, 0.3);
  color: #e66767;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  display: flex;
  align-items: center;
  gap: 14px;
}

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.menu-toggle svg { width: 18px; height: 18px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.45);
  z-index: 40;
}

.sidebar-overlay.is-open { display: block; }

.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.content {
  padding: 28px 32px;
  max-width: 1180px;
  width: 100%;
}

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ---------- Filters ---------- */

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px;
  margin-bottom: 20px;
  padding: 16px 18px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.filter-row label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  min-width: 0;
}

.filter-row input, .filter-row select {
  min-width: 0;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.filter-row input:focus, .filter-row select:focus {
  border-color: var(--series-blue);
  box-shadow: 0 0 0 3px var(--series-blue-soft);
}

.range-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.range-inputs { display: flex; gap: 6px; min-width: 0; }

.range-inputs input {
  width: 78px;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.range-inputs input:focus {
  border-color: var(--series-blue);
  box-shadow: 0 0 0 3px var(--series-blue-soft);
}

.date-presets { display: flex; gap: 6px; }

.date-presets button {
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-secondary);
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
}

.date-presets button:hover { color: var(--text-primary); border-color: var(--series-blue); }

.date-inputs { display: flex; align-items: end; gap: 10px; }

.btn-primary {
  background: var(--series-blue);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-block { width: 100%; padding: 11px 18px; font-size: 14px; }

.status-msg {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
  margin-bottom: 14px;
}

.status-msg.is-error { color: var(--status-critical); }

/* ---------- Stat tiles ---------- */

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.stat-tile .label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 8px;
}

.stat-tile .value {
  font-size: 23px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat-tile .value.positive { color: var(--status-good); }
.stat-tile .value.negative { color: var(--status-critical); }

/* ---------- Panel card / category chart ---------- */

.panel-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.panel-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.panel-card-header h2 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.chart-legend { display: flex; gap: 16px; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

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

.swatch-stake { background: var(--series-blue); }
.swatch-gain { background: var(--series-green); }

.category-chart {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 14px;
  align-items: center;
}

.chart-row-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.chart-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chart-bar-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chart-bar-track {
  flex: 1;
  height: 10px;
  background: var(--page-plane);
  border-radius: 4px;
  overflow: hidden;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 0 4px 4px 0;
  min-width: 2px;
}

.chart-bar-fill.stake { background: var(--series-blue); }
.chart-bar-fill.gain { background: var(--series-green); }

.chart-bar-value {
  width: 92px;
  flex-shrink: 0;
  text-align: right;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Category cards ---------- */

.category-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

.category-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}

.category-card-title {
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.category-card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}

.category-card-metrics div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.category-card-metrics span {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.category-card-metrics strong {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.category-card-metrics strong.positive { color: var(--status-good); }
.category-card-metrics strong.negative { color: var(--status-critical); }

.mini-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--gridline);
  font-size: 12px;
}

.mini-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-bottom: 6px;
}

.mini-table td {
  padding: 4px 0;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.mini-table td:first-child { color: var(--text-primary); font-weight: 500; }

/* ---------- Table ---------- */

.table-wrap {
  overflow-x: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th, .data-table td {
  padding: 11px 16px;
  text-align: left;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.data-table thead th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--gridline);
}

.data-table tbody tr {
  border-bottom: 1px solid var(--gridline);
}

.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--page-plane); }

.data-table tr.is-total td { font-weight: 700; }

.pager {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.pager button {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
}

.pager button:hover:not(:disabled) { border-color: var(--series-blue); }
.pager button:disabled { opacity: 0.4; cursor: not-allowed; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: capitalize;
}

.badge.active { background: color-mix(in srgb, var(--status-good) 16%, transparent); color: var(--status-good); }
.badge.passive { background: color-mix(in srgb, var(--status-warning) 18%, transparent); color: var(--status-warning); }
.badge.banned { background: color-mix(in srgb, var(--status-critical) 16%, transparent); color: var(--status-critical); }

/* ---------- Login page ---------- */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, var(--series-blue-soft), transparent 40%),
    radial-gradient(circle at 85% 85%, var(--series-blue-soft), transparent 40%),
    var(--page-plane);
  padding: 20px;
}

.login-screen { width: 100%; display: flex; justify-content: center; }

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 36px 32px 32px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.login-logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--series-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}

.login-logo-text {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 13.5px;
  margin: 0 0 26px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.field input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.field input:focus {
  border-color: var(--series-blue);
  box-shadow: 0 0 0 3px var(--series-blue-soft);
}

.login-error {
  background: color-mix(in srgb, var(--status-critical) 12%, transparent);
  color: var(--status-critical);
  border: 1px solid color-mix(in srgb, var(--status-critical) 30%, transparent);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 500;
}

/* ---------- Responsive / mobile ---------- */

@media (max-width: 860px) {
  .menu-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-md);
  }

  .sidebar.is-open { transform: translateX(0); }

  .topbar { padding: 16px 18px; }

  .content { padding: 20px 18px; }
}

@media (max-width: 560px) {
  .filter-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px;
  }

  .filter-row label { width: 100%; }

  .filter-row input,
  .filter-row select,
  .date-inputs,
  .range-inputs { width: 100%; }

  .range-inputs input { flex: 1; width: auto; }

  .date-inputs { flex-wrap: wrap; }

  .date-presets { flex-wrap: wrap; }

  .btn-primary { width: 100%; }

  .stat-tiles { grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; }

  .stat-tile { padding: 13px 14px; }

  .stat-tile .value { font-size: 19px; }

  .panel-card { padding: 15px 14px; }

  .chart-row {
    grid-template-columns: 1fr;
    row-gap: 6px;
  }

  .category-cards { grid-template-columns: 1fr; }

  .pager { flex-wrap: wrap; justify-content: center; }
}
