/* ─── Reset & Base ─────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-100: #dbeafe;
  --blue-50: #eff6ff;
  --green-600: #16a34a;
  --green-100: #dcfce7;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --amber-600: #d97706;
  --amber-100: #fef3c7;
  --gray-900: #111827;
  --gray-700: #374151;
  --gray-600: #4b5563;
  --gray-500: #6b7280;
  --gray-400: #9ca3af;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50: #f9fafb;
  --white: #ffffff;

  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background-color: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}

/* ─── Layout ────────────────────────────────────────────────────────────────── */

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ─── Header ────────────────────────────────────────────────────────────────── */

.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  background: var(--blue-600);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-mark svg {
  width: 18px;
  height: 18px;
  fill: var(--white);
}

.site-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-900);
  line-height: 1.2;
}

.tenant-name {
  font-size: 0.8125rem;
  color: var(--gray-500);
  font-weight: 400;
  margin-top: 1px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.last-updated {
  font-size: 0.8125rem;
  color: var(--gray-500);
}

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.refresh-btn:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.refresh-btn svg {
  width: 14px;
  height: 14px;
}

.refresh-btn.loading svg {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Main content ──────────────────────────────────────────────────────────── */

.main-content {
  padding: 24px 0 48px;
}

.section {
  margin-bottom: 28px;
}

.section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

/* ─── Cards ─────────────────────────────────────────────────────────────────── */

.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 640px) {
  .card-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.2;
}

.stat-value.highlight {
  color: var(--blue-600);
}

/* ─── Auth error ────────────────────────────────────────────────────────────── */

#auth-error {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#auth-error.visible {
  display: flex;
}

.auth-error-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.auth-error-icon {
  width: 48px;
  height: 48px;
  background: var(--amber-100);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.auth-error-icon svg {
  width: 24px;
  height: 24px;
  color: var(--amber-600);
}

.auth-error-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.auth-error-body {
  font-size: 0.9375rem;
  color: var(--gray-600);
  line-height: 1.6;
}

.auth-error-hint {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--gray-50);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--gray-700);
  font-family: monospace;
  letter-spacing: 0.01em;
}

/* ─── Loading overlay ───────────────────────────────────────────────────────── */

#loading {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

#loading.visible {
  display: flex;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--blue-600);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.loading-text {
  font-size: 0.875rem;
  color: var(--gray-500);
}

/* ─── Helper status card ────────────────────────────────────────────────────── */

.helper-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 540px) {
  .helper-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  .helper-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.helper-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.helper-item-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.helper-item-value {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--gray-900);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.green { background: var(--green-600); }
.status-dot.red { background: var(--red-600); }
.status-dot.gray { background: var(--gray-400); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
}

.badge-green {
  background: var(--green-100);
  color: var(--green-600);
}

.badge-red {
  background: var(--red-100);
  color: var(--red-600);
}

.badge-gray {
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge-amber {
  background: var(--amber-100);
  color: var(--amber-600);
}

.badge-blue {
  background: var(--blue-100);
  color: var(--blue-700);
}

/* ─── Balance card ──────────────────────────────────────────────────────────── */

.balance-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.balance-hero {
  padding: 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.balance-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.balance-amount {
  font-size: 2rem;
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1.1;
}

.balance-amount.settled {
  color: var(--green-600);
}

.settled-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 4px 10px;
  background: var(--green-100);
  color: var(--green-600);
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 600;
}

.balance-details {
  padding: 16px 24px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  border-bottom: 1px solid var(--gray-200);
}

@media (max-width: 480px) {
  .balance-details {
    grid-template-columns: 1fr;
  }
}

.balance-detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.balance-detail-label {
  font-size: 0.75rem;
  color: var(--gray-500);
  font-weight: 500;
}

.balance-detail-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-900);
}

.payments-section {
  padding: 16px 24px;
}

.payments-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 10px;
}

.payment-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.payment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--gray-50);
  border-radius: var(--radius);
  font-size: 0.875rem;
  gap: 8px;
}

.payment-date {
  color: var(--gray-500);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.payment-note {
  color: var(--gray-700);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.payment-amount {
  font-weight: 600;
  color: var(--green-600);
  white-space: nowrap;
}

.payments-empty {
  font-size: 0.875rem;
  color: var(--gray-400);
  font-style: italic;
}

/* ─── Active games ──────────────────────────────────────────────────────────── */

.game-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.game-item {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.game-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.game-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--gray-900);
}

.game-id {
  font-size: 0.75rem;
  color: var(--gray-400);
  font-family: monospace;
  margin-top: 2px;
}

.game-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.game-price {
  font-size: 0.8125rem;
  color: var(--gray-600);
}

.game-revenue {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--blue-600);
}

.fill-bar-wrapper {
  margin-top: 4px;
}

.fill-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-bottom: 4px;
}

.fill-bar-track {
  height: 6px;
  background: var(--gray-200);
  border-radius: 9999px;
  overflow: hidden;
}

.fill-bar-fill {
  height: 100%;
  background: var(--blue-600);
  border-radius: 9999px;
  transition: width 0.4s ease;
}

.fill-bar-fill.full {
  background: var(--green-600);
}

/* ─── Players table ─────────────────────────────────────────────────────────── */

.players-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.search-input {
  padding: 7px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font);
  color: var(--gray-900);
  background: var(--white);
  width: 220px;
  max-width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-input::placeholder {
  color: var(--gray-400);
}

.player-count {
  font-size: 0.8125rem;
  color: var(--gray-500);
}

.table-wrapper {
  overflow-x: auto;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

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

thead {
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-900);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--gray-50);
}

.player-name {
  font-weight: 500;
  color: var(--gray-900);
}

.td-number {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.empty-row td {
  text-align: center;
  color: var(--gray-400);
  font-style: italic;
  padding: 24px;
}

/* ─── Error banner ──────────────────────────────────────────────────────────── */

.error-banner {
  display: none;
  background: var(--red-100);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.875rem;
  color: var(--red-600);
  margin-bottom: 16px;
}

.error-banner.visible {
  display: block;
}

/* ─── Utilities ─────────────────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

.text-muted {
  color: var(--gray-400);
  font-style: italic;
}

/* ─── Skeleton loaders ──────────────────────────────────────────────────────── */

.skeleton {
  background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
