@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Light Theme Variables */
  --bg-app: #f0f2f5;
  --bg-gradient: linear-gradient(135deg, #e0e7ff 0%, #f3e8ff 100%);
  --bg-card: rgba(255, 255, 255, 0.85);
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --success: #059669;
  --success-light: #d1fae5;
  --error: #dc2626;
  --error-light: #fee2e2;
  --border: #cbd5e1;
  --input-bg: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --glass-blur: blur(20px);
  --glass-border: rgba(255, 255, 255, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-app: #090d16;
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --bg-card: rgba(15, 23, 42, 0.8);
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.15);
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.15);
    --error: #ef4444;
    --error-light: rgba(239, 68, 68, 0.15);
    --border: #334155;
    --input-bg: #1e293b;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
    --glass-border: rgba(255, 255, 255, 0.08);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
}

body {
  background: var(--bg-app);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  overflow-x: hidden;
}

/* App Container */
#app-container {
  width: 100%;
  max-width: 520px;
  position: relative;
  perspective: 1000px;
}

#app-container.admin-mode {
  max-width: 900px;
}

/* Base Card Style */
.card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 0;
  overflow: hidden;
  display: none;
  animation: cardEntrance 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  will-change: transform, opacity;
}

.card.active {
  display: block;
}

@keyframes cardEntrance {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Card Header */
.card-header-img {
  width: 100%;
  height: 160px;
  overflow: hidden;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.card-header-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.8s ease;
}

.card-header-img:hover img {
  transform: scale(1.05);
}

.card-content {
  padding: 2rem;
}

.card-header-text {
  margin-bottom: 2rem;
  text-align: center;
}

.card-header-text h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.card-header-text p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Forms */
.form-group {
  margin-bottom: 1.5rem;
  position: relative;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  padding: 5px 0; /* Expanded tap target helper */
  margin: -5px 0;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 500;
  transition: var(--transition);
  box-sizing: border-box;
  outline: none;
}

input[type="text"]:focus,
input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* User-invalid CSS selector to respect the form guide */
input.touched:invalid {
  border-color: var(--error);
}

input.touched:invalid:focus {
  box-shadow: 0 0 0 3px var(--error-light);
}

.error-message {
  display: block;
  color: var(--error);
  font-size: 0.8rem;
  font-weight: 500;
  margin-top: 0.4rem;
  opacity: 0;
  transform: translateY(-5px);
  transition: var(--transition);
}

input.touched:invalid + .error-message {
  opacity: 1;
  transform: translateY(0);
}

/* Custom Checkbox */
.checkbox-container {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 1.5rem 0;
  cursor: pointer;
  user-select: none;
}

/* Visually Hidden Checkbox helper class from guide */
.visually-hidden {
  position: absolute;
  clip-path: inset(50%);
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  white-space: nowrap;
}

.checkbox-custom {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

input[type="checkbox"]:focus-visible + .checkbox-custom {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

input[type="checkbox"]:checked + .checkbox-custom {
  background: var(--primary);
  border-color: var(--primary);
}

.checkbox-custom::after {
  content: "";
  display: block;
  width: 6px;
  height: 10px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
  opacity: 0;
  transition: var(--transition);
}

input[type="checkbox"]:checked + .checkbox-custom::after {
  opacity: 1;
}

.checkbox-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.checkbox-text a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.checkbox-text a:hover {
  text-decoration: underline;
}

/* Legal text scrollable block */
.legal-scroll-box {
  max-height: 100px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.02);
  margin-bottom: 1rem;
  line-height: 1.4;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  border: none;
  background: var(--primary);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  gap: 0.5rem;
  text-decoration: none;
}

.btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-secondary:hover {
  background: var(--primary-light);
  color: var(--primary-hover);
  box-shadow: none;
}

.btn-danger {
  background: var(--error);
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.5rem;
  display: inline-block;
  text-decoration: none;
  text-align: center;
  margin-top: 1rem;
  width: 100%;
  transition: var(--transition);
}

.btn-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Confirmation and QR styling */
.success-check {
  width: 72px;
  height: 72px;
  background: var(--success-light);
  color: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  margin: 0 auto 1.5rem auto;
  animation: bounceIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes bounceIn {
  from {
    opacity: 0;
    transform: scale(0.3);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.qr-box {
  background: #ffffff;
  padding: 1.5rem;
  border-radius: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1.5rem auto;
  width: 200px;
  height: 200px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.qr-box canvas, .qr-box img {
  width: 100% !important;
  height: 100% !important;
}

.ticket-info {
  background: var(--primary-light);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.ticket-info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  border-bottom: 1.5px dashed rgba(79, 70, 229, 0.15);
  padding-bottom: 0.5rem;
}

.ticket-info-row:last-child {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}

.ticket-info-row span:first-child {
  font-weight: 500;
  color: var(--text-secondary);
}

.ticket-info-row span:last-child {
  font-weight: 600;
}

/* Password Toggle Wrapper */
.password-wrapper {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.password-toggle:hover {
  color: var(--text-secondary);
}

/* Dashboard & Tabs */
.admin-navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  background: rgba(255, 255, 255, 0.02);
}

.admin-title {
  font-weight: 700;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.admin-title .badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-weight: 600;
}

.btn-logout {
  min-height: auto;
  width: auto;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border-radius: 8px;
}

.admin-tabs {
  display: flex;
  background: var(--bg-app);
  border-radius: 12px;
  padding: 0.3rem;
  margin: 1.5rem;
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  min-height: 40px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.tab-btn.active {
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  color: var(--primary);
  border: 1px solid var(--glass-border);
}

.tab-pane {
  display: none;
  padding: 0 1.5rem 1.5rem 1.5rem;
}

.tab-pane.active {
  display: block;
}

/* Scanner Area */
.scanner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.camera-box {
  width: 100%;
  max-width: 320px;
  height: 320px;
  border-radius: 20px;
  border: 2px solid var(--border);
  overflow: hidden;
  position: relative;
  background: #000;
  box-shadow: var(--shadow-md);
  margin-bottom: 1.5rem;
}

#reader {
  width: 100% !important;
  height: 100% !important;
}

/* Hide standard html5-qrcode styles we don't want */
#reader video {
  object-fit: cover !important;
}
#reader img {
  display: none !important;
}
#reader__dashboard {
  display: none !important;
}
#reader__header {
  display: none !important;
}

.scanner-laser {
  position: absolute;
  top: 10%;
  left: 5%;
  width: 90%;
  height: 3px;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: laserSweep 2s ease-in-out infinite;
  z-index: 10;
  pointer-events: none;
}

@keyframes laserSweep {
  0%, 100% { top: 10%; }
  50% { top: 90%; }
}

.scan-result-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  color: #ffffff;
  animation: fadeIn 0.3s ease forwards;
}

.scan-result-overlay.success {
  background: rgba(5, 150, 105, 0.95);
  display: flex;
}

.scan-result-overlay.error {
  background: rgba(220, 38, 38, 0.95);
  display: flex;
}

.result-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  animation: popScale 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popScale {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.result-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.result-details {
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
  line-height: 1.4;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.75rem;
  border-radius: 12px;
  width: 100%;
}

.result-btn {
  background: #ffffff;
  color: #111827;
  border-radius: 8px;
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  min-height: auto;
  width: auto;
}

.result-btn:hover {
  background: rgba(255, 255, 255, 0.9);
  transform: translateY(-1px);
}

.manual-entry-box {
  width: 100%;
  max-width: 320px;
  text-align: center;
  margin-top: 1rem;
}

.manual-entry-box p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* User List area & table styles */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-app);
  padding: 1rem;
  border-radius: 16px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-val {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.stat-lbl {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.list-controls {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.search-wrapper {
  position: relative;
  flex: 1;
}

.search-input {
  width: 100%;
  min-height: 42px !important;
  padding-left: 2.2rem !important;
  font-size: 0.9rem !important;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Table styling: responsive behavior */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input-bg);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

th {
  background: var(--bg-app);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1.5px solid var(--border);
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

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

.badge-status {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-status.valid {
  background: var(--success-light);
  color: var(--success);
}

.badge-status.valid.btn-status-toggle {
  border: none;
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  transition: var(--transition);
}

.badge-status.valid.btn-status-toggle:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.badge-status.pending {
  background: var(--primary-light);
  color: var(--primary);
}

.badge-status.pending.btn-status-toggle {
  border: none;
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  transition: var(--transition);
}

.badge-status.pending.btn-status-toggle:hover {
  background: rgba(234, 179, 8, 0.25) !important;
  color: #ca8a04 !important;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(234, 179, 8, 0.1);
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Responsive Table layout for mobile */
@media (max-width: 600px) {
  .admin-stats {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  
  .list-controls {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  /* Mobile card-view list instead of horizontal table layout */
  .table-container {
    border: none;
    background: transparent;
  }
  
  table, thead, tbody, th, td, tr {
    display: block;
  }
  
  thead {
    display: none; /* Hide header completely on mobile */
  }
  
  tr {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 1rem;
    padding: 1rem;
    box-shadow: var(--shadow-sm);
  }
  
  td {
    border: none;
    padding: 0.25rem 0;
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
  }
  
  td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary);
  }
}

/* Modal Dialog Backdrop styles */
dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Page Footer styling */
.app-footer {
  text-align: center;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  opacity: 0.8;
  transition: var(--transition);
}

.app-footer:hover {
  opacity: 1;
}

/* Validator restricted view styles */
.role-validator .admin-navbar .badge {
  background: rgba(14, 165, 233, 0.15) !important;
  color: #0ea5e9 !important;
}

.role-validator .admin-tabs,
.role-validator #btn-open-add-user,
.role-validator #btn-export-csv,
.role-validator .admin-stats,
.role-validator #admin-capacity-settings {
  display: none !important;
}
