:root {
  --bg: #e8f4f8;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f9ff;
  --bg-input: #f0f9ff;
  --border: #bae6fd;
  --border-focus: #0284c7;
  --text: #0c4a6e;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-glow: rgba(2, 132, 199, 0.15);
  --primary-subtle: rgba(2, 132, 199, 0.06);
  --primary-gradient: linear-gradient(135deg, #0ea5e9, #0284c7);
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --live: #dc2626;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.view { display: none; }
.view.active { display: flex; }

/* -- Auth -------------------------------------------------- */

#view-login, #view-totp-setup {
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 4px 24px rgba(2, 132, 199, 0.08);
}

.auth-header { text-align: center; margin-bottom: 32px; }

.logo {
  font-size: 26px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.subtitle { color: var(--text-muted); font-size: 14px; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}

.tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.tab.active {
  background: var(--primary);
  color: white;
}

.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }

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

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.field input {
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.btn {
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary-gradient);
  color: white;
}
.btn-primary:hover {
  opacity: 0.9;
  box-shadow: 0 0 16px var(--primary-glow);
}
.btn-full { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.error-msg {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: center;
}

.info-box {
  background: var(--primary-subtle);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 20px;
  color: var(--text-muted);
}

.info-box strong { color: var(--primary); }

.totp-icon { font-size: 48px; text-align: center; margin-bottom: 16px; }

.totp-boxes {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 16px 0;
}

.totp-box {
  width: 48px;
  height: 58px;
  text-align: center;
  font-size: 26px;
  font-family: monospace;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
  caret-color: transparent;
}

.totp-box:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
  transform: scale(1.08);
}

.totp-box.filled {
  border-color: var(--primary);
  background: var(--primary-subtle);
  animation: liquidPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes liquidPop {
  0% { transform: scale(1); }
  30% { transform: scale(1.25) rotate(-3deg); }
  50% { transform: scale(0.92) rotate(2deg); }
  70% { transform: scale(1.06) rotate(-1deg); }
  100% { transform: scale(1); }
}

@keyframes liquidRipple {
  0% { box-shadow: 0 0 0 0 var(--primary-glow); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.totp-box.ripple {
  animation: liquidPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), liquidRipple 0.6s ease-out;
}

.totp-box.error-shake {
  animation: totpShake 0.5s ease;
  border-color: var(--danger) !important;
}

@keyframes totpShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.totp-box::placeholder {
  color: var(--text-dim);
  opacity: 0.4;
}

.secret-display {
  background: var(--bg-input);
  padding: 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.secret-display label {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 8px;
}

.secret-code {
  display: block;
  font-size: 16px;
  color: var(--warning);
  letter-spacing: 2px;
  word-break: break-all;
  margin-bottom: 10px;
}

.qr-container {
  text-align: center;
  margin: 20px 0;
}

.qr-container img {
  width: 200px;
  height: 200px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
}

.instruction {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

/* -- Dashboard --------------------------------------------- */

#view-dashboard {
  flex-direction: column;
  min-height: 100vh;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left .logo { font-size: 20px; }

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

.user-email {
  color: var(--text-muted);
  font-size: 13px;
}

.status-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.status-badge.connected {
  background: #dcfce7;
  color: var(--success);
}

.status-badge.disconnected {
  background: #fee2e2;
  color: var(--danger);
}

.dashboard-main {
  flex: 1;
  padding: 32px 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.dashboard-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.dashboard-toolbar h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn-refresh {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all 0.2s ease;
}
.btn-refresh:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* -- Loading ----------------------------------------------- */

.loading {
  text-align: center;
  padding: 60px;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--primary-subtle);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-icon svg {
  width: 32px;
  height: 32px;
  stroke: var(--primary);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state h3 { margin-bottom: 8px; color: var(--text); }

/* -- Events Grid ------------------------------------------- */

.events-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

/* -- Hero Section ------------------------------------------ */

.hero-section {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.hero-section:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(2, 132, 199, 0.2);
}

.hero-cover {
  width: 100%;
  height: 340px;
  overflow: hidden;
}

.hero-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-cover .event-cover-placeholder {
  width: 100%;
  height: 100%;
}

.hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.3) 50%, transparent 100%);
  display: flex;
  align-items: flex-end;
}

.hero-content {
  padding: 32px;
  width: 100%;
}

.hero-badge {
  display: inline-block;
  background: var(--primary-gradient);
  color: white;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.hero-title {
  font-size: 28px;
  font-weight: 700;
  color: white;
  margin-bottom: 8px;
  line-height: 1.3;
}

.hero-date {
  font-size: 15px;
  color: rgba(255,255,255,0.8);
  margin-bottom: 16px;
}

.hero-play {
  width: 56px;
  height: 56px;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.hero-section:hover .hero-play {
  background: var(--primary);
}

/* -- Sunday Grid ------------------------------------------- */

.sunday-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

/* -- Collapsible ------------------------------------------- */

.collapsible-section {
  margin-top: 8px;
}

.collapsible-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.collapsible-toggle:hover {
  border-color: var(--primary);
  background: var(--bg-card-hover);
}

.collapsible-toggle.active {
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom-color: transparent;
}

.collapsible-label {
  flex: 1;
  text-align: left;
}

.collapsible-chevron {
  transition: transform 0.3s ease;
  color: var(--text-muted);
}

.collapsible-toggle.active .collapsible-chevron {
  transform: rotate(180deg);
}

.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--bg-card);
}

.collapsible-content.open {
  max-height: 50000px;
}

.collapsible-content .events-grid {
  padding: 20px;
}

/* -- Event Card -------------------------------------------- */

.event-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  cursor: pointer;
  opacity: 0;
  animation: fadeSlideUp 0.4s ease forwards;
}

.event-card:hover {
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: 0 8px 32px rgba(2, 132, 199, 0.12);
}

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* -- Cover ------------------------------------------------- */

.event-cover-wrapper {
  position: relative;
}

.event-cover {
  width: 100%;
  height: 180px;
  object-fit: cover;
  background: var(--bg-input);
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.event-cover-placeholder {
  width: 100%;
  height: 180px;
  background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 50%, #e0f2fe 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.event-cover-placeholder svg {
  width: 48px;
  height: 48px;
  stroke: var(--primary);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.4;
}

/* -- Card Body --------------------------------------------- */

.event-body { padding: 16px; }

.event-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  color: var(--text);
}

.event-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.event-badge {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-finished {
  background: #dcfce7;
  color: var(--success);
}

.badge-duration {
  background: var(--primary-subtle);
  color: var(--primary);
}

.event-date {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}

/* -- Admin Panel ------------------------------------------- */

.admin-table-wrapper {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.admin-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.admin-table tr:hover {
  background: var(--bg-subtle);
}

.badge-root {
  background: #fee2e2;
  color: #dc2626;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-user {
  background: #e0f2fe;
  color: #0284c7;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-ok {
  color: var(--success);
  font-weight: 500;
  font-size: 13px;
}

.badge-off {
  color: var(--text-muted);
  font-size: 13px;
}

/* -- Responsive -------------------------------------------- */

@media (max-width: 768px) {
  .dashboard-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .header-right { flex-wrap: wrap; }

  .dashboard-toolbar {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .toolbar-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .events-grid {
    grid-template-columns: 1fr;
  }

  .sunday-grid {
    grid-template-columns: 1fr;
  }

  .hero-cover {
    height: 240px;
  }

  .hero-content {
    padding: 20px;
  }

  .hero-title {
    font-size: 22px;
  }

  .auth-card { padding: 24px; }

  .dashboard-main { padding: 20px 16px; }
}

/* -- Reduced Motion ---------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .event-card {
    animation: none;
    opacity: 1;
  }

  .event-card.featured {
    animation: none;
  }

  .spinner {
    animation-duration: 1.5s;
  }

  * {
    transition-duration: 0.01ms !important;
  }
}

/* -- Video Modal ------------------------------------------- */

.video-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: modalFadeIn 0.25s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.video-modal-content {
  background: var(--bg-card);
  border-radius: 16px;
  width: 100%;
  max-width: 900px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
  animation: modalSlideUp 0.3s ease;
  position: relative;
}

@keyframes modalSlideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.video-modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  line-height: 1;
}

.video-modal-close:hover {
  background: rgba(0, 0, 0, 0.75);
}

.video-modal-body {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-modal-body video {
  width: 100%;
  height: 100%;
  outline: none;
}

.video-modal-body .video-loading {
  text-align: center;
  color: #94a3b8;
  padding: 40px;
}

.video-modal-body .video-loading .spinner {
  border-color: rgba(255, 255, 255, 0.15);
  border-top-color: var(--primary);
}

.video-modal-body .video-error {
  text-align: center;
  color: #94a3b8;
  padding: 40px;
}

.video-modal-body .video-error svg {
  width: 48px;
  height: 48px;
  stroke: #64748b;
  fill: none;
  stroke-width: 1.5;
  margin-bottom: 12px;
}

.video-modal-info {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.video-modal-info .modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.video-modal-info .modal-date {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

@media (max-width: 768px) {
  .video-modal {
    padding: 0;
  }

  .video-modal-content {
    border-radius: 0;
    max-width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .video-modal-body {
    flex: 1;
    aspect-ratio: unset;
  }
}
