/* ==========================================================================
   CR80 Printable Wallet Card & 3D Interactive Preview Styles
   ========================================================================== */

:root {
  --cr80-width: 85.60mm;
  --cr80-height: 53.98mm;
  --cr80-radius: 3.18mm;
  --cr80-px-w: 380px;
  --cr80-px-h: 240px;
}

.card-generator-container {
  max-width: 900px;
  margin: 0 auto;
}

/* Control Toolbar */
.card-toolbar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-controls-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.card-controls-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* Interactive 3D Card Preview Stage */
.preview-stage {
  perspective: 1200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-radius: var(--radius-lg);
  margin-bottom: 2rem;
  box-shadow: var(--shadow-lg);
}

.flip-card-wrapper {
  width: var(--cr80-px-w);
  height: var(--cr80-px-h);
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.flip-card-wrapper.flipped {
  transform: rotateY(180deg);
}

/* 3D Preview Card Faces (Position Absolute for 3D Flip) */
.flip-card-wrapper .wallet-card-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--cr80-radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  font-family: var(--font-sans);
  user-select: none;
  box-sizing: border-box;
}

.flip-card-wrapper .wallet-card-face.card-back {
  transform: rotateY(180deg);
}

/* Physical Printable Card Units (Position Relative for Side-by-Side Sheet) */
.print-card-unit {
  width: var(--cr80-width);
  height: var(--cr80-height);
  min-width: var(--cr80-width);
  min-height: var(--cr80-height);
  max-width: var(--cr80-width);
  max-height: var(--cr80-height);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  box-sizing: border-box;
  font-family: var(--font-sans);
  position: relative;
  background: #ffffff;
  color: #0f172a;
}

/* Theme 1: Medical Red / White */
.theme-red .wallet-card-face,
.theme-red.print-card-unit,
.theme-red .print-card-unit {
  background: #ffffff;
  color: #0f172a;
}

.theme-red .card-header-bar {
  background: #dc2626 !important;
  color: #ffffff !important;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* Theme 2: Navy & Gold */
.theme-navy .wallet-card-face,
.theme-navy.print-card-unit,
.theme-navy .print-card-unit {
  background: #0f172a;
  color: #f8fafc;
}

.theme-navy .card-header-bar {
  background: #1e293b !important;
  color: #fbbf24 !important;
  border-bottom: 2px solid #fbbf24;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.theme-navy .card-body-front,
.theme-navy .card-body-back {
  color: #f1f5f9;
}

.theme-navy .card-patient-name {
  color: #ffffff !important;
}

.theme-navy .card-meta-row {
  color: #cbd5e1 !important;
}

.theme-navy .card-blood-box {
  background: #fbbf24 !important;
  color: #0f172a !important;
}

.theme-navy .back-meds-summary {
  background: #1e293b !important;
  border-color: #334155 !important;
  color: #f8fafc !important;
}

.theme-navy .back-section-title {
  color: #fbbf24 !important;
}

.theme-navy .card-footer-bar {
  background: #1e293b !important;
  border-top-color: #334155 !important;
  color: #94a3b8 !important;
}

/* Theme 3: High-Contrast Monochromatic */
.theme-mono .wallet-card-face,
.theme-mono.print-card-unit,
.theme-mono .print-card-unit {
  background: #ffffff;
  color: #000000;
}

.theme-mono .card-header-bar {
  background: #000000 !important;
  color: #ffffff !important;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* Card Header Elements */
.header-left {
  display: flex;
  align-items: center;
  gap: 5px;
}

.header-left span {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.header-badge-text {
  font-size: 8px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.25);
  padding: 1px 4px;
  border-radius: 3px;
  letter-spacing: 0.04em;
}

/* Card Body: Front Side */
.card-body-front {
  padding: 8px 10px;
  display: flex;
  gap: 10px;
  flex: 1;
  align-items: center;
}

.card-qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.qr-box {
  background: #ffffff;
  padding: 2px;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-box svg {
  display: block;
  width: 72px;
  height: 72px;
}

.qr-caption {
  font-size: 7.5px;
  font-weight: 800;
  color: #dc2626;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 2px;
  text-align: center;
}

.card-patient-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}

.card-patient-name {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.15;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9.5px;
  font-weight: 600;
  color: #475569;
  margin-top: 2px;
}

.card-blood-box {
  background: #dc2626;
  color: #ffffff;
  font-size: 10.5px;
  font-weight: 900;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.02em;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.card-allergy-alert {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 3px solid #dc2626;
  border-radius: 3px;
  padding: 2px 5px;
  font-size: 8.5px;
  color: #991b1b;
  margin-top: 3px;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.card-allergy-alert strong {
  display: block;
  font-size: 8px;
  font-weight: 800;
}

.card-contact-line {
  font-size: 9px;
  color: #334155;
  font-weight: 600;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Card Footer Bar */
.card-footer-bar {
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  padding: 3px 10px;
  font-size: 7.5px;
  font-weight: 600;
  color: #64748b;
  display: flex;
  justify-content: space-between;
  align-items: center;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* Card Body: Back Side */
.card-body-back {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1;
}

.back-section-title {
  font-size: 8.5px;
  font-weight: 800;
  text-transform: uppercase;
  color: #dc2626;
  letter-spacing: 0.03em;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.back-meds-summary {
  font-size: 8px;
  color: #334155;
  line-height: 1.3;
  background: #f8fafc;
  padding: 4px 6px;
  border-radius: 3px;
  border: 1px solid #e2e8f0;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.back-contacts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 2px;
}

.back-contact-box {
  font-size: 7.5px;
  color: #1e293b;
}

.back-contact-box strong {
  display: block;
  font-size: 7.5px;
  color: #64748b;
  text-transform: uppercase;
}

.back-notice-box {
  font-size: 7px;
  color: #64748b;
  text-align: center;
  border-top: 1px dashed #cbd5e1;
  padding-top: 2px;
  margin-top: 2px;
}

/* Print Sheet Container (On-Screen Layout) */
.print-sheet-section {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
}

.print-instructions {
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.print-sheet {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-md);
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Dual Side-by-Side Foldable Layout */
.foldable-card-pair {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  width: 171.20mm; /* Exactly 2 x 85.60mm */
  height: 53.98mm; /* Exactly 53.98mm */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  position: relative;
  background: #ffffff;
}

.unit-front {
  border: 1px dashed #94a3b8;
  border-right: 1px dashed #dc2626;
  border-top-left-radius: var(--cr80-radius);
  border-bottom-left-radius: var(--cr80-radius);
}

.unit-back {
  border: 1px dashed #94a3b8;
  border-left: none;
  border-top-right-radius: var(--cr80-radius);
  border-bottom-right-radius: var(--cr80-radius);
}

.fold-indicator {
  position: absolute;
  top: -18px;
  left: 85.60mm;
  transform: translateX(-50%);
  font-size: 8.5px;
  font-weight: 800;
  color: #dc2626;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ==========================================================================
   PRINT MEDIA QUERY (Exact 100% Physical CR80 Scale)
   ========================================================================== */
@media print {
  @page {
    size: letter portrait;
    margin: 15mm;
  }

  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body, html {
    background: #ffffff !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* Hide app shell and on-screen controls */
  .app-header,
  .card-toolbar,
  .preview-stage,
  .print-instructions,
  .toast-container,
  .btn,
  .hide-on-print {
    display: none !important;
  }

  .main-content {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .print-sheet-section {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .print-sheet {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
  }

  .foldable-card-pair {
    display: flex !important;
    flex-direction: row !important;
    width: 171.20mm !important;
    height: 53.98mm !important;
    margin: 20mm auto 0 auto !important;
    box-shadow: none !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .print-card-unit {
    width: 85.60mm !important;
    height: 53.98mm !important;
    min-width: 85.60mm !important;
    min-height: 53.98mm !important;
    max-width: 85.60mm !important;
    max-height: 53.98mm !important;
    position: relative !important;
    display: flex !important;
    box-sizing: border-box !important;
  }

  .unit-front {
    border: 0.5pt dashed #475569 !important;
    border-right: 0.5pt dashed #dc2626 !important;
    border-radius: 0 !important;
  }

  .unit-back {
    border: 0.5pt dashed #475569 !important;
    border-left: none !important;
    border-radius: 0 !important;
  }

  .qr-box svg {
    width: 20mm !important;
    height: 20mm !important;
    display: block !important;
  }
}
