/* =========================
   CSS Reset
========================= */

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

html, body {
  margin: 0;
  padding: 0;
}

/* =========================
   Global Design Tokens
========================= */

:root {
  /* Functional colors — independent of theme */
  --success:  #2e7d32;
  --warning:  #ef6c00;
  --error:    #c62828;
  --info:     #1565c0;

  /* Surface */
  --bg-page:  #f3f4f6;
  --bg-card:  #ffffff;
  --bg-muted: #f9fafb;

  /* Type & borders */
  --border:         #e5e7eb;
  --text-primary:   #111827;
  --text-secondary: #6b7280;

  /* Tokens */
  --radius:     10px;
  --shadow:     0 6px 18px rgba(0, 0, 0, 0.08);
  --transition: all 0.3s ease;
}

/* =========================
   Theme Palettes
   Applied via data-theme="..." on <body>.
   Each theme exposes:
     --theme-event       primary event color (header bg, buttons)
     --theme-event-dark  darker shade for footer bar
     --theme-type        type accent (stripe, card border, input border)
     --theme-type-light  very light tint of type color (hover states)
     --theme-diagonal    CSS gradient for diagonal split header
========================= */

[data-theme="regional-checkin"] {
  --theme-event:      #3A7EC6;
  --theme-event-dark: #2A6AB5;
  --theme-type:       #607D8B;
  --theme-type-light: #ECEFF1;
  --theme-diagonal:   linear-gradient(135deg, #3A7EC6 58%, #607D8B 58%);
}

[data-theme="regional-prejudge"] {
  --theme-event:      #3A7EC6;
  --theme-event-dark: #2A6AB5;
  --theme-type:       #2E7D32;
  --theme-type-light: #E8F5E9;
  --theme-diagonal:   linear-gradient(135deg, #3A7EC6 58%, #2E7D32 58%);
}

[data-theme="state-checkin"] {
  --theme-event:      #1E2A3A;
  --theme-event-dark: #141E2A;
  --theme-type:       #607D8B;
  --theme-type-light: #ECEFF1;
  --theme-diagonal:   linear-gradient(135deg, #1E2A3A 58%, #607D8B 58%);
}

[data-theme="state-prejudge"] {
  --theme-event:      #1E2A3A;
  --theme-event-dark: #141E2A;
  --theme-type:       #2E7D32;
  --theme-type-light: #E8F5E9;
  --theme-diagonal:   linear-gradient(135deg, #1E2A3A 58%, #2E7D32 58%);
}

/* Fallback — no theme set (selection screen or unknown target) */
body:not([data-theme]) {
  --theme-event:      #37474F;
  --theme-event-dark: #263238;
  --theme-type:       #607D8B;
  --theme-type-light: #ECEFF1;
  --theme-diagonal:   linear-gradient(135deg, #37474F 58%, #607D8B 58%);
}

/* =========================
   Body & Container
========================= */

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.4;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Centered column — phone fills naturally, larger screens get a focused panel */
.container {
  width: 100%;
  max-width: 520px;
  min-width: 320px;
  margin: 0 auto;
  padding: 0 0 80px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* =========================
   Header — Diagonal Split
========================= */

header {
  background: var(--theme-diagonal);
  margin-bottom: 0.75rem;
  position: relative;
  /* No border-radius — runs edge-to-edge on phone,
     gets clipped by container max-width on larger screens */
}

.header-inner {
  padding: 1rem 1rem 0.85rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

/* Logo sits on a white pill so it reads against any header color */
.header-logo {
  background: rgba(255, 255, 255, 0.93);
  border-radius: 6px;
  padding: 5px 10px;
  flex-shrink: 0;
}

.header-logo img {
  display: block;
  height: 44px;
  width: auto;
  max-width: 200px;
}

/* Chips row — event + type labels */
.header-chips {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  padding-top: 0.25rem;
}

.header-chip {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: rgba(255, 255, 255, 0.95);
  white-space: nowrap;
}

.header-chip-event {
  background: rgba(0, 0, 0, 0.2);
}

.header-chip-type {
  background: rgba(255, 255, 255, 0.25);
}

/* Camera / mode toggle — sits in the header-inner flex row */
.icon-toggle-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  transition: var(--transition);
  flex-shrink: 0;
  align-self: center;
}

.icon-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.32);
}

.icon-toggle-btn:active {
  transform: scale(0.95);
}

/* =========================
   Main Content
========================= */

main {
  flex: 1;
  padding: 0 0.75rem;
}

/* =========================
   Input Section (Manual)
========================= */

.input-section {
  background: var(--bg-card);
  padding: 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 0.75rem;
  /* Left border echoes the type color */
  border-top: 3px solid var(--theme-event);
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

/* Dual top-border — event left 62%, type right 38% */
.input-section::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 38%;
  height: 3px;
  background: var(--theme-type);
}

.input-wrapper {
  position: relative;
  width: 100%;
}

#registrantId {
  width: 100%;
  padding: 1rem;
  font-size: 2rem;
  text-align: center;
  border: 3px solid var(--theme-type);
  border-radius: 8px;
  font-family: 'Martian Mono', monospace;
  text-transform: uppercase;
  transition: all 0.3s;
}

#registrantId:focus {
  outline: none;
  border-color: var(--theme-event);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.07);
}

#registrantId.loading {
  padding-right: 50px;
  opacity: 0.6;
}

.input-spinner {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
}

.input-spinner.active {
  display: block;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(0, 0, 0, 0.12);
  border-top-color: var(--theme-event);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* =========================
   Camera Section
========================= */

.camera-section {
  background: var(--bg-card);
  padding: 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 0.75rem;
  border-top: 3px solid var(--theme-event);
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.camera-section::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 38%;
  height: 3px;
  background: var(--theme-type);
}

.camera-reader {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  position: relative;
  aspect-ratio: 1 / 1;        /* ← lock the container's shape before html5-qrcode sets it */
}

.camera-reader video {
  width: 100% !important;
  height: 100% !important;    /* ← fill the aspect-ratio box, not auto-size past it */
  max-height: 100% !important;
  border-radius: 8px;
  object-fit: cover;
}

.camera-instructions {
  text-align: center;
  margin: 1rem 0 0.5rem;
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.camera-controls {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* =========================
   Display Area
========================= */

.display-area {
  background: var(--bg-card);
  padding: 0.3rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease-out;
  margin-bottom: 0.75rem;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.display-area.hidden {
  display: none;
}

/* =========================
   Card Styles
========================= */

.success-card,
.error-card {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  padding-top: 0;
  position: relative;
}

.error-card   { border-left: 6px solid var(--error); }
.success-card { border-left: 6px solid var(--success); }

/* =========================
   Card Header
========================= */

.card-header h2,
.card-title {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--success);
}

.error-card .card-header h2,
.error-card .card-title {
  color: var(--error);
}

/* =========================
   Countdown Block
========================= */

.countdown-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.1rem;
  padding: 0.1rem 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

#countdownText {
  font-weight: 600;
}

.countdown-btn {
  background: rgba(0, 0, 0, 0.1);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.countdown-btn:hover {
  background: rgba(0, 0, 0, 0.18);
}

/* =========================
   Status Banner
========================= */

.status-banner,
.time-status {
  margin: 0.75rem 0 1rem;
  padding: 0.75rem;
  border-radius: 6px;
  font-weight: 700;
  text-align: center;
  font-size: 0.95rem;
}

.status-banner.late,    .time-status.late    { background: var(--error);   color: #fff; }
.status-banner.warning, .time-status.warning { background: var(--warning); color: #fff; }
.status-banner.early,   .time-status.early   { background: var(--info);    color: #fff; }
.status-banner.on-time, .time-status.on-time { background: var(--success); color: #fff; }

/* =========================
   Identity Block
========================= */

.identity-block {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.identity-name {
  font-size: 1.15rem;
  font-weight: 700;
}

.identity-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* =========================
   Info Grid
========================= */

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 1.5rem;
}

.info-grid dt {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.info-grid dd {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-primary);
}

/* =========================
   Partner Status
========================= */

.partner-checked-in {
  color: white;
  background-color: var(--success);
  font-weight: 600;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  display: inline-block;
  font-size: 0.9rem;
}

.partner-not-checked-in {
  color: #000;
  background-color: var(--warning);
  font-weight: 600;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  display: inline-block;
  font-size: 0.9rem;
}

.partner-not-registered {
  color: var(--text-secondary);
  font-style: italic;
}

/* =========================
   Toast Notification
========================= */

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.95rem;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: toastSlideIn 0.3s ease-out;
  max-width: 90%;
  text-align: center;
}

.toast.hidden  { display: none; }
.toast.error   { background: var(--error); }
.toast.warning { background: var(--warning); }
.toast.success { background: var(--success); }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* =========================
   Modal
========================= */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.2s ease-out;
}

.modal.hidden { display: none; }

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

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 400px;
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: var(--transition);
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
}

.modal-body { padding: 1.5rem; }

.setting-group { margin-bottom: 1.5rem; }

.setting-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.setting-note {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-style: italic;
}

.camera-select {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.95rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  cursor: pointer;
  transition: var(--transition);
}

.camera-select:hover  { border-color: var(--theme-event); }
.camera-select:focus  {
  outline: none;
  border-color: var(--theme-event);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.07);
}

.camera-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.camera-option {
  background: var(--bg-muted);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  transition: var(--transition);
  text-align: left;
}

.camera-option:hover { background: #e5e7eb; }

.camera-option.active {
  background: var(--theme-event);
  color: white;
  border-color: var(--theme-event);
  font-weight: 600;
}

.camera-option .radio-icon { font-size: 1.2rem; }

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.btn {
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--theme-event);
  color: white;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background: var(--bg-muted);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: #e5e7eb; }

/* =========================
   Status Bar (Footer)
========================= */

.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--theme-event-dark);
  padding: 0.65rem 1rem;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 1000;
}

/* Constrain footer content to same column width as .container */
.status-bar-inner {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-info {
  font-weight: 600;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.75);
}

.status-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Lookup placeholder — reserved for future registrant search */
.icon-btn-lookup {
  /* same as icon-btn, dimmed until feature is built */
  opacity: 0.45;
  cursor: not-allowed;
}

.refresh-icon {
  font-size: 1.4rem;
  display: inline-block;
  transition: transform 0.3s;
}

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

.status-version {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.4);
}

/* =========================
   Target Selection Screen
========================= */

/* Selection screen header has no diagonal — neutral fallback */
.header-inner--selection {
  justify-content: center;
  padding: 1.25rem 1rem;
}

.selection-screen {
  padding: 1.25rem 0.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.selection-title {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 0.25rem;
}

/* Each target card gets its theme diagonal as a top border */
.target-card {
  display: block;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1.1rem 0.9rem 1.25rem;
  text-decoration: none;
  color: var(--text-primary);
  border-top: 3px solid var(--border);
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

/* Dual top-border mirrors the app header diagonal */
.target-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 38%;
  height: 3px;
  background: var(--border);
}

/* Per-target overrides on the selection cards */
.target-card[data-target="regional-checkin"]              { border-top-color: #3A7EC6; }
.target-card[data-target="regional-checkin"]::after       { background: #607D8B; }
.target-card[data-target="regional-prejudge"]             { border-top-color: #3A7EC6; }
.target-card[data-target="regional-prejudge"]::after      { background: #2E7D32; }
.target-card[data-target="state-checkin"]                 { border-top-color: #1E2A3A; }
.target-card[data-target="state-checkin"]::after          { background: #607D8B; }
.target-card[data-target="state-prejudge"]                { border-top-color: #1E2A3A; }
.target-card[data-target="state-prejudge"]::after         { background: #2E7D32; }

.target-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.target-card:active {
  transform: translateY(0);
}

.target-card-label {
  font-weight: 700;
  font-size: 1rem;
}

.target-card-meta {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.3rem;
  align-items: center;
}

.target-card-chip {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  color: #fff;
}

.target-card-chip--event { background: #3A7EC6; }
.target-card-chip--event.state { background: #1E2A3A; }
.target-card-chip--type  { background: #607D8B; }
.target-card-chip--type.prejudge { background: #2E7D32; }

/* =========================
   Utilities
========================= */

.hidden {
  display: none !important;
}

/* =========================
   Responsive
========================= */

/* Larger screens — container is already max-width capped.
   Header runs edge-to-edge within that column.
   These tweaks just ensure nothing looks stretched. */
@media (min-width: 521px) {
  header {
    border-radius: var(--radius) var(--radius) 0 0;
  }

  main {
    padding: 0 0;
  }

  .container {
    padding-left: 0;
    padding-right: 0;
  }

  .input-section,
  .camera-section,
  .display-area {
    border-radius: 0;
    margin-bottom: 1px;
  }

  /* Last card before footer gets bottom radius back */
  .display-area:not(.hidden),
  .camera-section:not(.hidden),
  .input-section {
    /* Allow natural radius on the very last visible card */
  }
}

@media (max-width: 520px) {
  .container {
    padding-bottom: 70px;
  }

  .header-logo img {
    height: 38px;
  }

  .header-chip {
    font-size: 0.6rem;
    padding: 0.18rem 0.45rem;
  }

  #registrantId {
    font-size: 1.75rem;
    padding: 0.85rem;
  }

  .input-section,
  .camera-section {
    padding: 0.85rem;
  }

  .success-card,
  .error-card {
    padding: 0.5rem;
  }

  .card-header h2,
  .card-title {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
  }

  .identity-name    { font-size: 1.05rem; }
  .countdown-block  { padding: 0.4rem 0.5rem; }

  .countdown-btn {
    padding: 0.2rem 0.4rem;
    font-size: 0.7rem;
  }

  .time-status,
  .status-banner {
    padding: 0.4rem;
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
  }

  .partner-checked-in,
  .partner-not-checked-in {
    padding: 0.3rem 0.4rem;
    font-size: 0.85rem;
  }

  .modal-content { width: 95%; }

  .toast {
    font-size: 0.85rem;
    padding: 0.85rem 1.25rem;
  }

  .camera-reader {
    max-width: 100%;            /* ← let it fill the narrower container without overflow */
  }

}

@media (max-width: 380px) {
  #registrantId {
    font-size: 1.5rem;
    padding: 0.75rem;
  }

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

  .time-status,
  .status-banner {
    font-size: 0.95rem;
    padding: 0.5rem;
  }
}