:root {
  --ink: #1b1e33;
  --ink-soft: #5b5f7a;
  --bg: #f6f6fb;
  --surface: #ffffff;
  --brand: #252a4a;
  --brand-2: #3a4177;
  --header-grad-1: #155e75;
  --header-grad-2: #0d9488;
  --accent: #12b3a0;
  --accent-ink: #063f38;
  --danger: #c74747;
  --border: #e4e4ef;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(27, 30, 51, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* Ensure [hidden] always wins over class-level display rules (e.g. display:flex). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Screen-reader-only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 8px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--header-grad-1), var(--header-grad-2));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.2px;
}
.brand-icon { border-radius: 6px; display: block; }

.offline-pill {
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(255,255,255,0.16);
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}

main {
  flex: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.view h1 {
  font-size: 1.5rem;
  line-height: 1.3;
  margin: 0 0 10px;
}

.lede {
  color: var(--ink-soft);
  line-height: 1.55;
  margin: 0 0 24px;
}

.feature-list {
  list-style: none;
  margin: 28px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.feature-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-soft);
}
.feature-list strong { color: var(--ink); }

/* Buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 12px 22px;
  cursor: pointer;
  transition: transform 0.06s ease, opacity 0.15s ease;
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-lg { width: 100%; padding: 15px 22px; font-size: 1rem; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { opacity: 0.92; }

.btn-secondary {
  background: var(--surface);
  color: var(--brand);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--border);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border: none;
  font-weight: 500;
  padding: 10px 12px;
}

/* Form */
#cardForm {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.field em { color: var(--danger); font-style: normal; }
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); }
.field-optional { font-size: 0.78rem; font-weight: 400; color: var(--ink-soft); }
.field input,
.field textarea {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 400;
  color: var(--ink);
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
  resize: vertical;
}
.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 179, 160, 0.15);
}

/* Photo upload field */
.photo-upload-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.photo-preview-wrap {
  flex-shrink: 0;
}
.photo-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  display: block;
}
.photo-upload-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.btn-photo {
  display: inline-block;
  font-size: 0.85rem;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--ink-soft);
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  text-align: center;
  transition: opacity 0.15s;
}
.btn-photo:hover { opacity: 0.8; }

.form-error {
  background: #fdecec;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin: 0;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

/* Card view */
.card-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0 22px 26px;
  overflow: hidden; /* clips header band to card's rounded corners */
}

/* Profile photo on card view */
.card-photo-wrap {
  display: flex;
  justify-content: center;
}
.card-photo {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border);
  box-shadow: 0 2px 10px rgba(27,30,51,0.12);
  display: block;
}

.card-identity h1 {
  font-size: 1.35rem;
  margin-bottom: 2px;
}
.muted { color: var(--ink-soft); margin: 0 0 4px; font-size: 0.95rem; }

.description {
  margin: 10px 0 0;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
}

.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 22px 0;
  padding: 20px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.qr-canvas {
  background: #fff;
  padding: 10px;
  border-radius: 10px;
  line-height: 0;
  width: 220px;
  max-width: 100%;
}
.qr-canvas img, .qr-canvas canvas, .qr-canvas table, .qr-canvas svg {
  display: block;
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 1 / 1;
}
.qr-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.detail-list {
  margin: 0 0 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.detail-list div { display: flex; flex-direction: column; }
.detail-list dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ink-soft);
  font-weight: 600;
}
.detail-list dd {
  margin: 2px 0 0;
  font-size: 0.98rem;
  word-break: break-word;
}
.detail-list dd a {
  color: var(--brand-2);
  text-decoration: none;
}
.detail-list dd a:hover,
.detail-list dd a:focus {
  text-decoration: underline;
}

.card-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-actions .btn-secondary,
.card-actions .btn-danger-ghost {
  width: 100%;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  z-index: 50;
}

/* Update banner */
.update-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  background: var(--brand);
  color: #fff;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 480px;
  margin: 0 auto;
}
.update-banner:not([hidden]) { display: flex; }
.update-banner span { font-size: 0.88rem; }

/* Footer */
.app-footer {
  text-align: center;
  padding: 4px 20px 28px;
  color: var(--ink-soft);
}
.app-footer p {
  margin: 0;
  font-size: 0.78rem;
}

/* Share sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 40, 0.5);
  z-index: 80;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop:not([hidden]) { display: flex; }

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(20px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,0.15);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 6px auto 14px;
}

.sheet h2 {
  font-size: 1.1rem;
  margin: 0 0 16px;
  text-align: center;
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 8px;
}

.share-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--ink);
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.share-option:active { background: var(--bg); }

.share-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.share-icon-whatsapp { background: #25d366; }
.share-icon-telegram { background: #29a9eb; }
.share-icon-viber { background: #7360f2; }
.share-icon-facebook { background: #1877f2; }
.share-icon-email { background: var(--brand-2); }
.share-icon-image { background: linear-gradient(135deg, var(--header-grad-1), var(--header-grad-2)); }
.share-icon-more { background: var(--ink-soft); }
.share-icon-download { background: var(--accent); color: var(--accent-ink); }

.sheet-note {
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-align: center;
  margin: 4px 0 16px;
}

@media (min-width: 480px) {
  .app-header { padding: 16px 28px; }
  main { padding: 36px 20px 48px; }
}

/* Pro badge — shown on card view when a company code is active */
.pro-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--header-grad-1), var(--header-grad-2));
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  vertical-align: middle;
  margin: 4px 0 8px;
}

/* Company code field */
.company-code-field {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 4px;
}
.field-hint {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--ink-soft);
  line-height: 1.4;
}

/* Initials avatar — shown on card view when no profile photo is set */
.initials-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--header-grad-1), var(--header-grad-2));
  color: #fff;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid rgba(255,255,255,0.6);
  box-shadow: 0 2px 10px rgba(27,30,51,0.12);
  user-select: none;
}

/* Gradient header band inside the card panel */
.card-header-band {
  background: linear-gradient(135deg, var(--header-grad-1), var(--header-grad-2));
  min-height: 130px;
  margin: 0 -22px;           /* break out of card-panel's side padding */
  padding: 20px 22px 0;      /* top-align logo so avatar has clearance below */
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* Photo / initials — straddles the band / body boundary */
.card-photo-section {
  display: flex;
  justify-content: center;
  margin-top: -44px;         /* pull up by half the 88px avatar */
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}
/* White ring so avatar reads cleanly against the gradient */
.card-photo-section .card-photo   { border-color: #fff; }
.card-photo-section .initials-avatar { border-color: #fff; }

/* Institution logo inside the band (Pro deployments) */
.card-logo-wrap:not([hidden]) {
  display: flex;
  justify-content: center;
  align-items: center;
}
.card-logo {
  height: 48px;
  max-width: 180px;
  object-fit: contain;
  display: block;
}

/* Pro: square photo / initials shape */
.photo-square .card-photo      { border-radius: 12px; }
.photo-square .initials-avatar { border-radius: 12px; }

/* Pro: left-aligned institution logo in header band */
.logo-left .card-header-band         { justify-content: flex-start; }
.logo-left .card-logo-wrap:not([hidden]) { justify-content: flex-start; }

/* ── Booking flow ───────────────────────────────────────────────────────── */

/* Date picker sheet */
.booking-date-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0 20px;
}
.booking-date-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.booking-date-input {
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
  width: 100%;
  appearance: none;
}
.booking-date-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 179, 160, 0.15);
}

/* Confirmation card sheet */
.booking-confirm-sheet {
  text-align: center;
  padding-bottom: 32px;
}
.booking-confirm-icon {
  font-size: 3rem;
  margin: 8px 0 10px;
  line-height: 1;
}
.booking-confirm-sheet h2 {
  margin-bottom: 2px;
}
.booking-confirm-name {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0 0 18px;
}
.booking-confirm-date-wrap {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 0 0 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.booking-confirm-date-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.booking-confirm-date {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
}
.btn-dpatro {
  display: inline-block;
  text-decoration: none;
  margin-top: 2px;
  background: var(--surface);
  color: var(--brand);
  border: 1px solid var(--border);
}
.btn-dpatro:hover { opacity: 0.85; }

/* Booking reference */
.booking-confirm-ref {
  font-size: 0.75rem;
  color: var(--ink-soft);
  font-family: monospace;
  letter-spacing: 0.3px;
}

/* My Bookings button in card actions */
.btn-bookings {
  font-size: 0.88rem;
  padding: 10px 18px;
}

/* ── Bookings dashboard ─────────────────────────────────────────────────── */

.bookings-dash-sheet {
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 8px;
}
.bookings-dash-sheet h2 {
  flex-shrink: 0;
}
.bookings-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -22px;
  padding: 0 22px 8px;
}
.bookings-empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 24px 0;
  font-size: 0.9rem;
  margin: 0;
}
.bookings-group-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--ink-soft);
  margin: 18px 0 8px;
}
.bookings-group-label:first-child { margin-top: 4px; }
.booking-card {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.booking-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.booking-card-name {
  font-weight: 700;
  font-size: 0.97rem;
  color: var(--ink);
}
.booking-card-date {
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-bottom: 2px;
}
.booking-card-email {
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.booking-card-ref {
  font-size: 0.72rem;
  font-family: monospace;
  color: var(--ink-soft);
  margin-top: 6px;
}
.booking-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.booking-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-pending   { background: #fef3c7; color: #92400e; }
.badge-confirmed { background: #d1fae5; color: #065f46; }
.badge-declined  { background: #fee2e2; color: #991b1b; }

.btn-confirmed {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-confirmed:hover { opacity: 0.88; }
.btn-declined {
  background: transparent;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-declined:hover { background: #fee2e2; }
.btn-delete {
  background: transparent;
  color: #9ca3af;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-left: auto;
}
.btn-delete:hover { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
