.stats-page {
  min-height: 100vh;
  background: var(--bg);
}

[hidden],
.is-hidden {
  display: none !important;
}

.stats-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.stats-login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
}

.stats-login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.35rem;
}

.stats-login-card > p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.stats-login-card label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.password-field {
  position: relative;
  margin-bottom: 1rem;
}

.password-field input {
  width: 100%;
  padding: 0.75rem 4.5rem 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.password-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.password-toggle {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.password-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

.login-error {
  color: #ff6b6b;
  font-size: 0.85rem;
  margin: -0.25rem 0 0.75rem;
  line-height: 1.4;
}

.stats-back {
  display: block;
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stats-back:hover {
  color: var(--accent);
}

.stats-dashboard {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.stats-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

.stats-header h1 {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}

.stats-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.stats-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.setup-notice {
  background: rgba(255, 92, 26, 0.1);
  border: 1px solid rgba(255, 92, 26, 0.3);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.setup-notice code {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.status-banner {
  background: rgba(61, 214, 195, 0.1);
  border: 1px solid rgba(61, 214, 195, 0.25);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.error-banner {
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.35);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  color: var(--text);
}

.error-banner strong {
  display: block;
  margin-bottom: 0.35rem;
  color: #ff8a8a;
}

.error-banner p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
}

.error-details {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: #ffb4b4;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}

.stats-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stats-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stats-panel h2 {
  font-size: 0.85rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.stats-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.stats-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.stats-list li span:last-child {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.stats-table-wrap {
  margin-bottom: 2.5rem;
}

.stats-table-wrap h2 {
  font-size: 1rem;
  margin-bottom: 0.35rem;
}

.stats-table-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: var(--surface-hover, #1c2532) !important;
}

.visitor-detail {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.25rem;
}

.visitor-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.visitor-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem 1rem;
}

.visitor-detail-grid dt {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.visitor-detail-grid dd {
  font-size: 0.88rem;
  word-break: break-word;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.stats-table th,
.stats-table td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.stats-table th {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--surface);
}

.stats-table tbody tr:hover {
  background: var(--surface);
}

.stats-table td {
  color: var(--text-muted);
}

.stats-table .event-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent);
}

.stats-empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  .stats-header {
    flex-direction: column;
  }
}
