:root {
  color-scheme: dark;
  --bg: #2b2b2b;
  --bg-soft: #313335;
  --panel: #323232;
  --panel-elevated: #3c3f41;
  --accent: #cc7832;
  --accent-strong: #ff9a3c;
  --text: #e6e1dc;
  --muted: #a9b7c6;
  --outline: rgba(255, 255, 255, 0.08);
  --shadow: 0 18px 32px rgba(0, 0, 0, 0.4);
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-secondary-color: var(--muted);
  --bs-border-color: var(--outline);
  --bs-card-bg: var(--panel);
  --bs-card-cap-bg: var(--panel-elevated);
  --bs-primary: var(--accent-strong);
  --bs-primary-rgb: 255, 154, 60;
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent-strong);
  font-family: "Spline Sans", sans-serif;
}

body.app-body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

h1,
h2,
h3,
h4,
.topbar-title,
.sidebar-title {
  font-family: "Space Grotesk", sans-serif;
}

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  background: var(--panel);
  border-radius: 24px;
  padding: 2.5rem;
  width: min(460px, 90vw);
  box-shadow: var(--shadow);
  border: 1px solid var(--outline);
}

.auth-switch {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.auth-switch .btn-link {
  color: var(--accent);
  font-weight: 600;
  padding: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand h1 {
  font-size: 2rem;
  margin-bottom: 0.2rem;
}

.brand p {
  margin: 0;
  color: var(--muted);
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--accent);
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.25);
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--outline);
  padding: 1rem 1.5rem;
}

.topbar-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.main-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 72px);
}

.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--outline);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
}

.sidebar-title {
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

.sidebar .nav-link {
  color: var(--muted);
  font-weight: 500;
  text-align: left;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid transparent;
}

.sidebar .nav-link.active,
.sidebar .nav-link:hover {
  color: var(--text);
  background: var(--panel-elevated);
  border-color: var(--outline);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1.5rem;
}

.admin-badge {
  display: inline-flex;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: rgba(204, 120, 50, 0.18);
  color: var(--accent);
  font-size: 0.85rem;
}

.content {
  padding: 2rem 2.5rem 3rem;
}

.section-header h2 {
  font-size: 2rem;
  margin-bottom: 0.3rem;
}

.section-header p {
  color: var(--muted);
}

.stat-card,
.panel-card {
  background: var(--panel);
  border-radius: 20px;
  padding: 1.5rem;
  border: 1px solid var(--outline);
  box-shadow: var(--shadow);
}

.stat-label {
  color: var(--muted);
  font-size: 0.95rem;
}

.stat-value {
  font-size: 2.4rem;
  font-weight: 600;
  margin-top: 0.6rem;
}

.stat-sub {
  color: var(--muted);
  margin-top: 0.4rem;
}

.panel-card h3 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
}

.quick-actions {
  display: grid;
  gap: 0.6rem;
}

.note {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.dashboard-tile {
  border-radius: 18px;
  border: 1px solid var(--outline);
  padding: 1.25rem;
  background: var(--panel-elevated);
  width: 100%;
}

.dashboard-tile h4 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.05rem;
  margin: 0;
}

.mini-stat {
  border-radius: 14px;
  border: 1px solid var(--outline);
  padding: 0.75rem 0.9rem;
  background: var(--bg-soft);
  text-align: center;
}

.mini-stat .stat-value {
  font-size: 1.4rem;
  margin-top: 0.35rem;
}

.active-account-list {
  margin-top: 0.5rem;
  display: grid;
  gap: 0.5rem;
}

.active-account-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--outline);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  background: var(--panel-elevated);
  font-size: 0.9rem;
}

.active-account-item .meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.accounts-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.accounts-actions .btn {
  height: 34px;
  padding: 0 0.85rem;
  line-height: 1;
}

.accounts-actions .btn:disabled {
  opacity: 0.5;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: lowercase;
  margin-right: 0.35rem;
  margin-bottom: 0.2rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--outline);
  gap: 0.4rem;
  padding-right: 0.9rem;
}

.tag-pill .tag-remove {
  display: inline-flex;
  width: 0.8rem;
  justify-content: center;
  visibility: hidden;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.tag-pill:hover .tag-remove {
  visibility: visible;
}

input[data-tags-input] {
  max-width: 10ch;
}

.tag-input-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: nowrap;
}

.tag-input-left {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

[data-tag-pills] {
  flex: 0 0 220px;
  max-width: 220px;
  overflow-x: auto;
  white-space: nowrap;
}

.tag-pill.dead_cookie {
  background: rgba(218, 80, 80, 0.22);
  color: #f0b0b0;
  border-color: rgba(218, 80, 80, 0.35);
}

.tag-pill.proof_of_work_required {
  background: rgba(204, 120, 50, 0.25);
  color: #f5d2b0;
  border-color: rgba(204, 120, 50, 0.4);
}

.tag-pill.generic_join_game_http_error {
  background: rgba(255, 178, 90, 0.22);
  color: #f6dfb8;
  border-color: rgba(255, 178, 90, 0.35);
}

.tag-pill.other {
  background: rgba(104, 151, 187, 0.2);
  color: #c3d7e8;
  border-color: rgba(104, 151, 187, 0.35);
}

.stats-bar-wrap {
  margin-top: 1rem;
}

.stats-bar {
  display: flex;
  height: 20px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--outline);
}

.stats-bar-seg {
  height: 100%;
  min-width: 0;
}

.stats-all {
  background: rgba(204, 120, 50, 0.5);
}

.stats-joining {
  background: rgba(104, 151, 187, 0.65);
}

.stats-active {
  background: rgba(106, 135, 89, 0.75);
}

.stats-connected {
  background: rgba(86, 156, 214, 0.65);
}

.stats-unstable {
  background: rgba(189, 99, 64, 0.75);
}

.stats-bar-legend {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.8rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.4rem;
}

.stats-bar-meta {
  margin-top: 0.6rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.placeholder-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.placeholder-grid span {
  display: block;
  height: 60px;
  border-radius: 12px;
  background: rgba(204, 120, 50, 0.16);
}

.token-pill {
  background: rgba(204, 120, 50, 0.2);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.token-value {
  font-weight: 600;
  color: var(--text);
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

.form-control,
.form-select {
  background: #2a2a2a;
  border: 1px solid var(--outline);
  color: var(--text);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.2rem rgba(204, 120, 50, 0.25);
  background: #2a2a2a;
  color: var(--text);
}

.btn-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #231b12;
  font-weight: 600;
}

.btn-outline-light {
  border-color: var(--outline);
  color: var(--text);
}

.table {
  margin-bottom: 0;
}

.table-dark {
  --bs-table-bg: var(--panel);
  --bs-table-border-color: var(--outline);
}

.table-hover tbody tr:hover {
  background: rgba(204, 120, 50, 0.12);
}

.config-list {
  display: grid;
  gap: 1rem;
}

.script-list {
  display: grid;
  gap: 0.6rem;
}

.script-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  background: var(--panel-elevated);
  border: 1px solid var(--outline);
}

.script-item button {
  white-space: nowrap;
}

.script-preview {
  color: var(--muted);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--outline);
  color: var(--text);
}

.config-card {
  background: var(--panel-elevated);
  border-radius: 16px;
  padding: 1rem 1.2rem;
  border: 1px solid var(--outline);
}

.config-card h4 {
  margin-bottom: 0.3rem;
}

.config-card p {
  margin-bottom: 0.6rem;
  color: var(--muted);
}

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

.bulk-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.6rem;
}

.bulk-tag-controls {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.bulk-tag-controls .form-control,
.bulk-tag-controls .form-select {
  flex: 1 1 220px;
  min-width: 200px;
}

.bulk-tag-controls .btn {
  flex: 0 0 auto;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  font-size: 0.85rem;
}

.toast-box {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--outline);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: all 0.2s ease;
  pointer-events: none;
}

.toast-box.show {
  opacity: 1;
  transform: translateY(0);
}

.device-detail-row td {
  padding: 0;
  border-top: none;
}

.device-detail-card {
  background: var(--panel-elevated);
  border-top: 1px solid var(--outline);
  padding: 1.25rem 1.5rem;
}

.device-detail-card h5 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.device-detail-card .detail-subtle {
  color: var(--muted);
  font-size: 0.85rem;
}

.device-log-entry {
  border: 1px solid var(--outline);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  background: var(--panel);
}

.device-log-entry + .device-log-entry {
  margin-top: 0.75rem;
}

.device-log-entry summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}

.device-log-entry pre {
  background: #2a2a2a;
  border-radius: 12px;
  padding: 0.75rem;
  color: var(--text);
  max-height: 240px;
  overflow: auto;
  margin-top: 0.5rem;
}

.live-log-body {
  background: #1d1f22;
  border-radius: 12px;
  border: 1px solid var(--outline);
  color: var(--text);
  max-height: 360px;
  overflow: auto;
  padding: 0.75rem;
  white-space: pre;
}

.modal-log {
  max-width: min(92vw, 1400px);
}

.trackstats-pet-cell {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.trackstats-pet-image {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--outline);
}

.card {
  background: var(--panel);
  border: 1px solid var(--outline);
  color: var(--text);
}

.card-header {
  background: var(--panel-elevated);
  border-bottom: 1px solid var(--outline);
  color: var(--text);
}

.navbar .nav-link,
.navbar .navbar-brand {
  color: var(--text);
}

.navbar .nav-link:hover,
.navbar .nav-link:focus {
  color: var(--accent);
}

.dropdown-menu {
  background: var(--panel);
  border: 1px solid var(--outline);
}

.dropdown-item {
  color: var(--text);
}

.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--panel-elevated);
  color: var(--text);
}

.btn-outline-primary {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-outline-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #231b12;
}

.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.toggle-label {
  margin: 0;
  color: var(--text);
  font-weight: 500;
}

.apple-switch {
  position: relative;
  width: 46px;
  height: 26px;
  display: inline-flex;
  align-items: center;
}

.apple-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #5a5a5a;
  transition: background 0.2s ease;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f5f5f5;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.apple-switch input:checked + .switch-track {
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.apple-switch input:checked + .switch-track::after {
  transform: translateX(20px);
  background: #fff0e3;
}

.apple-switch input:focus-visible + .switch-track {
  outline: 2px solid rgba(204, 120, 50, 0.6);
  outline-offset: 3px;
}

@media (max-width: 991px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    overflow-x: auto;
    gap: 1rem;
    padding: 1rem;
  }

  .sidebar-title,
  .sidebar-footer {
    display: none;
  }

  .sidebar .nav {
    flex-direction: row;
    gap: 0.5rem;
  }

  .content {
    padding: 1.5rem;
  }
}

@media (max-width: 575px) {
  .login-card {
    padding: 2rem;
  }

  .token-pill {
    display: none;
  }
}
