:root {
  --bg: #16171a;
  --bg-elevated: #1c1d21;
  --panel: #222327;
  --panel-hover: #2a2b31;
  --border: #34353c;
  --border-soft: #2a2b31;
  --text: #f4f5f7;
  --muted: #9da3ae;
  --accent: #6c7cff;
  --accent-soft: rgba(108, 124, 255, 0.14);
  --accent-hover: #5a6bf0;
  --ok: #3ecf8e;
  --ok-soft: rgba(62, 207, 142, 0.12);
  --warn: #f5b942;
  --warn-soft: rgba(245, 185, 66, 0.12);
  --bad: #f06767;
  --bad-soft: rgba(240, 103, 103, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  --sidebar-width: 250px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: #7eb8ff; text-decoration: none; }
a:hover { color: #a8d0ff; }

/* App layout */
.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
  width: 100%;
}

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

.content {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 2rem 1.75rem 3rem;
  flex: 1;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.5rem 1.25rem;
}

.brand-mark { font-size: 1.35rem; }
.brand-title { font-weight: 700; font-size: 1rem; }
.brand-sub { color: var(--muted); font-size: 0.8rem; }

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding-top: 1rem;
  margin-top: auto;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.nav-item {
  display: block;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(108, 124, 255, 0.25);
}

.user-panel {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
}

.user-name {
  font-weight: 600;
  font-size: 0.92rem;
}

.role-badge {
  display: inline-block;
  margin-top: 0.15rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.role-cryysys {
  background: var(--accent-soft);
  color: #b8c2ff;
}

.role-tracker {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.logout-link {
  color: var(--muted);
  font-size: 0.88rem;
}

/* Typography */
h1 {
  margin: 0;
  font-size: 1.85rem;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

h3 {
  margin: 0 0 0.75rem;
  font-size: 0.98rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  max-width: 52ch;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Cards & grids */
.grid {
  display: grid;
  gap: 1rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 1.5rem;
}
.two-col { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.three-col { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow);
}

.section-card { margin-bottom: 1.25rem; }
.section-card-header { margin-bottom: 1rem; }

.stat-card .stat-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 0.35rem;
  letter-spacing: -0.02em;
}

.stat-card .stat-detail {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.stat-value.ok { color: var(--ok); }
.stat-value.bad { color: var(--bad); }

.section { margin-top: 1.5rem; }

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border-soft);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255, 255, 255, 0.02);
}

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

/* Buttons */
.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.62rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.button:hover, button:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.button:active, button:active { transform: translateY(1px); }
.button.discord { margin-top: 1rem; width: 100%; }

.btn-secondary {
  background: var(--panel-hover);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: #32333a; }

.btn-sm {
  padding: 0.38rem 0.7rem;
  font-size: 0.84rem;
}

.btn-danger { background: var(--bad); }
.btn-danger:hover { background: #d95555; }

/* Forms */
.search-panel {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  margin-bottom: 1.25rem;
}

.search-panel input,
.form-input,
.settings-form input[type="text"],
.settings-form input[type="number"],
select.form-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.72rem 0.85rem;
  font: inherit;
}

.search-panel input { flex: 1; }

.field-grid {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field label {
  font-weight: 600;
  font-size: 0.92rem;
}

.field-hint {
  color: var(--muted);
  font-size: 0.82rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border-soft);
}

.toggle-row:last-child { border-bottom: none; }

.toggle {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #3a3b42;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-soft);
}

.admin-action-card h3 { margin-bottom: 0.35rem; }
.admin-action-card p { margin: 0 0 0.85rem; }

.action-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.6rem;
}

.action-row.stacked {
  grid-template-columns: 1fr;
}

.inline-form { display: inline; margin: 0; }

/* Alerts */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
}

.alert-icon {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.alert-ok {
  background: var(--ok-soft);
  border: 1px solid rgba(62, 207, 142, 0.28);
  color: #b8f0d4;
}

.alert-ok .alert-icon {
  background: rgba(62, 207, 142, 0.25);
}

.alert-warn {
  background: var(--warn-soft);
  border: 1px solid rgba(245, 185, 66, 0.28);
  color: #ffe2a8;
}

.alert-warn .alert-icon {
  background: rgba(245, 185, 66, 0.25);
}

/* Badges & tags */
.badge, .tag {
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-exotic, .badge-celestial, .badge-legendary, .badge-epic,
.badge-rare, .badge-uncommon, .badge-common {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text);
}

.tag {
  background: var(--panel-hover);
  border: 1px solid var(--border);
  color: var(--muted);
}

.tag.warn {
  color: #ffe2a8;
  border-color: rgba(245, 185, 66, 0.35);
}

.tag.irl {
  color: #ffc9c9;
  border-color: rgba(240, 103, 103, 0.35);
}

.tag.gold {
  color: #ffe6a8;
  border-color: rgba(245, 185, 66, 0.35);
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading h2 {
  margin: 0;
}

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

.live-card h3 {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
}

.live-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.live-card-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.meta-label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
}

.live-card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.activity-item {
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-soft);
}

.activity-item:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.activity-main {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.25rem;
}

.activity-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.35rem;
}

.activity-price {
  font-weight: 600;
}

.entity-link {
  color: var(--text);
  font-weight: 600;
}

.entity-link:hover {
  color: #a8d0ff;
  text-decoration: none;
}

.entity-name {
  border-bottom: 1px solid rgba(126, 184, 255, 0.35);
}

/* Profile */
.profile-hero {
  display: flex;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.profile-id {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.profile-id code {
  font-size: 0.95rem;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  flex: 1;
  min-width: 280px;
}

.profile-stats div {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.profile-stats strong {
  display: block;
  font-size: 1.15rem;
  margin-top: 0.2rem;
}

.kv { list-style: none; padding: 0; margin: 0; }
.kv li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border-soft);
}
.kv li:last-child { border-bottom: none; }

.list { margin: 0; padding-left: 1.1rem; }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.empty-icon {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

.quick-links {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.quick-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--panel-hover);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}

.quick-link:hover {
  background: #32333a;
  text-decoration: none;
}

code {
  background: var(--bg-elevated);
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  font-size: 0.86em;
}

.login-page .content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-card h1 { margin-bottom: 0.5rem; }

@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-soft);
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 0;
  }

  .sidebar-footer {
    display: none;
  }

  .content {
    padding: 1.25rem 1rem 2.5rem;
  }

  .action-row {
    grid-template-columns: 1fr;
  }

  .live-card-meta {
    grid-template-columns: 1fr;
  }
}

/* Stats dashboard */
.stats-toolbar,
.stats-metrics-panel,
.stats-chart-card {
  margin-bottom: 1.25rem;
}

.stats-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
}

.stats-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preset-btn,
.btn-secondary {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font: inherit;
}

.preset-btn:hover,
.btn-secondary:hover {
  background: var(--panel-hover);
}

.preset-btn.active {
  background: var(--accent-soft);
  border-color: rgba(108, 124, 255, 0.45);
}

.stats-custom-range {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
}

.stats-custom-range label,
.stats-granularity label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.stats-date-input,
.stats-select {
  min-width: 10rem;
}

.stats-metric-groups {
  display: grid;
  gap: 1rem;
}

.stats-metric-group-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.stats-metric-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.metric-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--bg);
  cursor: pointer;
  font-size: 0.9rem;
}

.metric-chip:has(input:checked) {
  border-color: rgba(108, 124, 255, 0.45);
  background: var(--accent-soft);
}

.metric-chip input {
  accent-color: var(--accent);
}

.stats-toolbar-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

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

.stats-chart-wrap {
  position: relative;
  height: 360px;
}

.stats-chart-wrap-short {
  height: 280px;
}

@media (max-width: 768px) {
  .stats-toolbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .stats-chart-wrap {
    height: 280px;
  }
}
