/* admin.css — Tyag Streak Admin Panel
   Dark-mode-first internal ops dashboard. Palette capped at 3 accents
   (gold / saffron / maroon) + 1 neutral, reused consistently across UI
   chrome and charts (see charts.js CHART_COLORS — keep both in sync). */

:root {
  --bg: #0b0d12;
  --bg-elevated: #12151c;
  --bg-elevated-2: #181c26;
  --bg-hover: #1e2330;
  --border: #232836;
  --border-soft: #1a1e29;

  --text-primary: #e8e6e1;
  --text-secondary: #9aa0ac;
  --text-muted: #666d7c;

  --accent-gold: #d4a548;
  --accent-gold-soft: rgba(212, 165, 72, 0.14);
  --accent-saffron: #e8823a;
  --accent-saffron-soft: rgba(232, 130, 58, 0.14);
  --accent-maroon: #a8434e;
  --accent-maroon-soft: rgba(168, 67, 78, 0.16);
  --accent-neutral: #5b6472;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.24);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--accent-saffron); }

.hidden { display: none !important; }

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

#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 10%, rgba(212, 165, 72, 0.07), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(168, 67, 78, 0.08), transparent 45%),
    var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px 28px 28px;
}

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

.login-brand .mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-maroon));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #16110a;
  font-size: 15px;
}

.mark-logo {
  background: none !important;
  object-fit: contain;
  padding: 2px;
}

.login-brand .brand-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}

.login-card h1 {
  font-size: 19px;
  margin: 18px 0 2px;
}

.login-card .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0 0 22px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent-gold);
}

.field textarea { resize: vertical; min-height: 72px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-gold);
  color: #16110a;
}
.btn-primary:hover { background: #e0b25c; }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-elevated-2);
  border-color: var(--border);
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
  background: transparent;
  border-color: var(--accent-maroon);
  color: #ef8b93;
}
.btn-danger:hover { background: var(--accent-maroon-soft); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.btn .spinner { display: none; }
.btn.is-loading .spinner { display: inline-block; }
.btn.is-loading .btn-label { opacity: 0.7; }

.spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.inline-error {
  background: var(--accent-maroon-soft);
  border: 1px solid rgba(168, 67, 78, 0.4);
  color: #f0a3ab;
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13px;
  margin-bottom: 14px;
}

.inline-success {
  background: rgba(90, 168, 100, 0.12);
  border: 1px solid rgba(90, 168, 100, 0.35);
  color: #8fd19e;
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13px;
  margin-bottom: 14px;
}

.login-hint {
  margin-top: 18px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* ---------------------------------------------------------------------- */
/* App shell                                                               */
/* ---------------------------------------------------------------------- */

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
}

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

.sidebar-brand .mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-maroon));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #16110a;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-brand .titles { line-height: 1.25; }
.sidebar-brand .brand-name { font-weight: 600; font-size: 14px; }
.sidebar-brand .brand-sub { font-size: 11px; color: var(--text-muted); }

.nav-list {
  list-style: none;
  margin: 0;
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13.5px;
  margin-bottom: 2px;
  text-decoration: none;
  border: 1px solid transparent;
}

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

.nav-item.active {
  background: var(--accent-gold-soft);
  border-color: rgba(212, 165, 72, 0.3);
  color: var(--accent-gold);
  font-weight: 600;
}

.nav-icon { width: 16px; text-align: center; flex-shrink: 0; opacity: 0.9; }

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

.session-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated-2);
  margin-bottom: 8px;
}

.session-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-saffron-soft);
  color: var(--accent-saffron);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.session-meta { min-width: 0; }
.session-username {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.role-badge {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 58px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  padding: 0 28px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.topbar .topbar-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 12px;
}

#main-content {
  padding: 24px 28px 60px;
  flex: 1;
}

/* ---------------------------------------------------------------------- */
/* Shared building blocks                                                  */
/* ---------------------------------------------------------------------- */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
}

.card + .card { margin-top: 16px; }

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

.card-header h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}

.card-header .card-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.section-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--accent-saffron-soft);
  border: 1px solid rgba(232, 130, 58, 0.28);
  color: #f2b686;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  margin-bottom: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.stat-tiles {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 16px;
}

.stat-tile {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}

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

.stat-tile .stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stat-tile .stat-value.accent-gold { color: var(--accent-gold); }
.stat-tile .stat-value.accent-saffron { color: var(--accent-saffron); }
.stat-tile .stat-value.accent-maroon { color: var(--accent-maroon); }

.charts-grid {
  grid-template-columns: 1.1fr 1fr;
}
@media (max-width: 980px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.chart-canvas-wrap { width: 100%; height: 220px; }
.chart-canvas-wrap canvas { width: 100%; height: 100%; display: block; }

.donut-layout {
  display: flex;
  align-items: center;
  gap: 20px;
}
.donut-layout .chart-canvas-wrap { width: 150px; height: 150px; flex-shrink: 0; }

.legend { list-style: none; margin: 0; padding: 0; flex: 1; }
.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  padding: 5px 0;
  color: var(--text-secondary);
}
.legend .swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
}
.legend .legend-value { margin-left: auto; color: var(--text-primary); font-weight: 600; }

/* ---------------------------------------------------------------------- */
/* Tables                                                                  */
/* ---------------------------------------------------------------------- */

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.table-toolbar .spacer { flex: 1; }

.search-input {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-width: 220px;
  color: var(--text-primary);
  outline: none;
}
.search-input:focus { border-color: var(--accent-gold); }

.table-wrap { overflow-x: auto; }

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

.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text-secondary); }
.data-table th .sort-arrow { margin-left: 4px; opacity: 0.7; }

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-primary);
  white-space: nowrap;
}

.data-table tbody tr:hover { background: var(--bg-elevated-2); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-gold { background: var(--accent-gold-soft); color: var(--accent-gold); }
.badge-saffron { background: var(--accent-saffron-soft); color: var(--accent-saffron); }
.badge-maroon { background: var(--accent-maroon-soft); color: #ef8b93; }
.badge-neutral { background: rgba(255,255,255,0.06); color: var(--text-secondary); }

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

.state-row {
  padding: 30px 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.today-badge {
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-saffron));
  color: #16110a;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 4px;
  margin-left: 8px;
}

.row-actions { display: flex; gap: 6px; }

.confirm-inline { display: flex; align-items: center; gap: 6px; font-size: 12px; }

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-row .field { flex: 1; min-width: 160px; margin-bottom: 0; }

.list-order-controls { display: flex; flex-direction: column; gap: 2px; }
.list-order-controls button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 4px;
  width: 22px;
  height: 18px;
  line-height: 1;
  cursor: pointer;
  font-size: 10px;
}
.list-order-controls button:hover { background: var(--bg-hover); color: var(--text-primary); }
.list-order-controls button:disabled { opacity: 0.3; cursor: not-allowed; }

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 5px 3px 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated-2);
  cursor: pointer;
  font-size: 11px;
}
.toggle-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-neutral);
}
.toggle-pill.on .toggle-dot { background: var(--accent-gold); }
.toggle-pill.on { color: var(--accent-gold); border-color: rgba(212,165,72,0.35); }

.divider { height: 1px; background: var(--border-soft); margin: 18px 0; border: none; }

.result-summary {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  font-size: 13px;
}
.result-summary .n { font-size: 20px; font-weight: 700; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

.muted { color: var(--text-muted); }
.small { font-size: 12px; }

.skeleton-line {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--bg-elevated-2) 25%, var(--bg-hover) 37%, var(--bg-elevated-2) 63%);
  background-size: 400% 100%;
  animation: skeleton 1.4s ease infinite;
  margin-bottom: 8px;
}
@keyframes skeleton {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---------------------------------------------------------------------- */
/* User detail modal                                                       */
/* ---------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h2 { font-size: 16px; margin: 0; }
.modal-header .card-caption { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin-bottom: 16px;
  font-size: 13px;
}
.detail-grid dt { color: var(--text-muted); }
.detail-grid dd { margin: 0; }
.history-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.history-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 12px;
  border-bottom: 1px solid var(--border-soft);
}
.history-row:last-child { border-bottom: none; }
.history-row.muted { color: var(--text-muted); justify-content: center; }

.row-banned { opacity: 0.55; }

/* ---------------------------------------------------------------------- */
/* City distribution (Overview page)                                      */
/* ---------------------------------------------------------------------- */
.view-toggle {
  display: inline-flex;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.view-toggle-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
}
.view-toggle-btn:hover { color: var(--text-primary); }
.view-toggle-btn.active {
  background: var(--accent-gold);
  color: #1a1206;
}

.city-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.city-card {
  position: relative;
  text-align: left;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, transform 0.15s;
}
.city-card:hover {
  border-color: var(--accent-gold);
  transform: translateY(-2px);
}
.city-card-top {
  border-color: var(--accent-gold);
  background: linear-gradient(160deg, var(--accent-gold-soft), var(--bg-elevated-2) 60%);
}
.city-card-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-gold);
  background: rgba(212, 165, 72, 0.16);
  padding: 3px 6px;
  border-radius: 4px;
}
.city-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  padding-right: 50px;
}
.city-card-count {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent-gold);
}
.city-card-count-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.city-card-stats {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-soft);
  padding-top: 8px;
}
.flame-mini { margin-right: 4px; }

tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover { background: var(--bg-hover); }

/* ---------------------------------------------------------------------- */
/* Automation toggle switch + reach/speed status                          */
/* ---------------------------------------------------------------------- */
.switch { position: relative; display: inline-block; flex-shrink: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  display: block;
  width: 42px;
  height: 24px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s;
}
.switch-thumb {
  display: block;
  width: 18px;
  height: 18px;
  margin: 2px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent-gold-soft); border-color: var(--accent-gold); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); background: var(--accent-gold); }
.switch input:disabled + .switch-track { opacity: 0.5; }

.reach-status {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.reach-status strong { color: var(--text-primary); }

/* ---------------------------------------------------------------------- */
/* Toasts (used by the new-signup watcher)                                */
/* ---------------------------------------------------------------------- */
.admin-toast-region {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}
.admin-toast {
  background: var(--bg-elevated);
  border: 1px solid var(--accent-gold);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-primary);
  animation: admin-toast-in 0.25s ease-out;
}
.admin-toast strong { color: var(--accent-gold); }
@keyframes admin-toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}
