/* Clinic Reports — Premium Patient Widget
   Fraunces (serif display) + Sora (sans-serif body)
   Teal/navy medical palette · BEM cr- prefix */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600&family=Sora:wght@300;400;500;600&display=swap');

/* ── Design tokens ───────────────────────────────────────── */
.cr-widget {
  --cr-font-display:  'Fraunces', Georgia, serif;
  --cr-font-body:     'Sora', system-ui, -apple-system, sans-serif;

  /* Teal accent — brand/decorative (light) */
  --cr-teal:          #0ABFBC;
  --cr-teal-glow:     rgba(10, 191, 188, 0.18);
  --cr-teal-dim:      #E4F7F7;

  /* Teal — interactive (dark enough for AA contrast with white) */
  --cr-teal-btn:      #0D7377;
  --cr-teal-btn-dark: #0A5C60;
  --cr-teal-dark:     #089C99;

  /* Navy header */
  --cr-navy:          #0D2B47;
  --cr-navy-mid:      #0F3458;

  /* Text & surface */
  --cr-text:          #1A2B3C;
  --cr-muted:         #617589;
  --cr-bg:            #ffffff;
  --cr-surface:       #F4F8FC;
  --cr-surface-2:     #EBF2F9;
  --cr-border:        #D4E2EF;
  --cr-border-focus:  var(--cr-teal);

  /* Elevation */
  --cr-shadow-sm:     0 2px 8px rgba(11, 35, 64, 0.06);
  --cr-shadow-md:     0 8px 32px rgba(11, 35, 64, 0.1);
  --cr-shadow-lg:     0 24px 64px rgba(11, 35, 64, 0.14);

  /* Shape */
  --cr-radius-xs:     6px;
  --cr-radius-sm:     10px;
  --cr-radius:        16px;
  --cr-radius-lg:     22px;

  font-family:  var(--cr-font-body);
  color:        var(--cr-text);
  max-width:    520px;
  margin:       0 auto;
  line-height:  1.5;
  animation:    cr-fade-in 0.45s ease both;
}

/* Dark theme overrides */
.cr-widget.cr-theme-dark {
  --cr-teal:        #22D3D0;
  --cr-teal-dark:   #0ABFBC;
  --cr-teal-btn:    #1AACAA;
  --cr-teal-btn-dark: #148F8D;
  --cr-teal-dim:    rgba(10, 191, 188, 0.12);
  --cr-teal-glow:   rgba(10, 191, 188, 0.15);
  --cr-text:        #E2EDF8;
  --cr-muted:       #7FA3C4;
  --cr-bg:          #0A1929;
  --cr-surface:     #0E2137;
  --cr-surface-2:   #132843;
  --cr-border:      #1E3A58;
  --cr-navy:        #0E2A46;
  --cr-navy-mid:    #122F50;
  --cr-shadow-lg:   0 24px 64px rgba(0, 0, 0, 0.4);
}

/* ── Card shell ──────────────────────────────────────────── */
.cr-card {
  background:    var(--cr-bg);
  border-radius: var(--cr-radius-lg);
  box-shadow:    var(--cr-shadow-lg);
  overflow:      hidden;
  animation:     cr-slide-up 0.5s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* ── Header ──────────────────────────────────────────────── */
.cr-header {
  padding:    34px 32px 30px;
  background: linear-gradient(160deg, #0D2B47 0%, #0F3458 55%, #0D3160 100%);
  position:   relative;
  overflow:   hidden;
}

/* Decorative orbs */
.cr-header::before,
.cr-header::after {
  content:        '';
  position:       absolute;
  border-radius:  50%;
  pointer-events: none;
}

.cr-header::before {
  width:      220px;
  height:     220px;
  background: radial-gradient(circle, rgba(10,191,188,0.12) 0%, transparent 70%);
  top:        -70px;
  right:      -50px;
}

.cr-header::after {
  width:      120px;
  height:     120px;
  background: radial-gradient(circle, rgba(10,191,188,0.08) 0%, transparent 70%);
  bottom:     -30px;
  left:       24px;
}

.cr-eyebrow {
  display:         inline-flex;
  align-items:     center;
  gap:             6px;
  padding:         4px 12px;
  background:      rgba(255, 255, 255, 0.08);
  border:          1px solid rgba(255, 255, 255, 0.18);
  border-radius:   999px;
  color:           #A8EAE8;
  font-size:       0.6875rem;
  font-weight:     600;
  letter-spacing:  0.07em;
  text-transform:  uppercase;
  margin-bottom:   14px;
  position:        relative;
  z-index:         1;
}

.cr-title {
  font-family:  var(--cr-font-display);
  font-size:    1.625rem;
  font-weight:  600;
  color:        #ffffff;
  margin:       0 0 8px;
  line-height:  1.25;
  position:     relative;
  z-index:      1;
}

.cr-subtitle {
  font-size:   0.875rem;
  color:       rgba(255, 255, 255, 0.78);
  margin:      0;
  font-weight: 300;
  line-height: 1.6;
  position:    relative;
  z-index:     1;
}

/* ── Body (lookup + OTP sections) ───────────────────────── */
.cr-body {
  padding: 28px 32px 32px;
}

/* ── Field groups ────────────────────────────────────────── */
.cr-field-group {
  margin-bottom: 20px;
}

.cr-field-label {
  display:        block;
  font-size:      0.6875rem;
  font-weight:    600;
  color:          var(--cr-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom:  7px;
}

.cr-input-wrap {
  position: relative;
}

.cr-input-icon {
  position:        absolute;
  left:            14px;
  top:             50%;
  transform:       translateY(-50%);
  color:           var(--cr-muted);
  display:         flex;
  align-items:     center;
  pointer-events:  none;
  transition:      color 0.2s;
}

.cr-input-wrap:focus-within .cr-input-icon {
  color: var(--cr-teal);
}

.cr-input {
  width:         100%;
  padding:       13px 16px 13px 44px;
  border:        1.5px solid var(--cr-border);
  border-radius: var(--cr-radius-sm);
  background:    var(--cr-surface);
  color:         var(--cr-text);
  font-family:   var(--cr-font-body);
  font-size:     1rem;
  font-weight:   400;
  box-sizing:    border-box;
  transition:    border-color 0.2s, box-shadow 0.2s, background 0.2s;
  -webkit-appearance: none;
  appearance:    none;
}

.cr-input:focus {
  outline:      none;
  border-color: var(--cr-border-focus);
  background:   var(--cr-bg);
  box-shadow:   0 0 0 3px var(--cr-teal-glow);
}

.cr-input::placeholder { color: var(--cr-muted); opacity: 0.6; }

.cr-otp-input {
  padding-left:   16px;
  text-align:     center;
  font-size:      1.375rem;
  font-weight:    600;
  letter-spacing: 0.4em;
}

.cr-hint {
  margin:      8px 0 0;
  font-size:   0.75rem;
  color:       var(--cr-muted);
  line-height: 1.65;
}

.cr-hint-contact {
  margin-top:   6px;
  padding:      8px 10px;
  background:   var(--cr-surface);
  border-radius: var(--cr-radius-xs);
  border-left:  2px solid var(--cr-teal);
}

/* ── Buttons ─────────────────────────────────────────────── */
.cr-btn-primary {
  display:         flex;
  align-items:     center;
  justify-content: center;
  gap:             8px;
  width:           100%;
  padding:         14px 24px;
  min-height:      48px;
  background:      linear-gradient(135deg, var(--cr-teal-btn) 0%, var(--cr-teal-btn-dark) 100%);
  color:           #ffffff;
  border:          none;
  border-radius:   var(--cr-radius-sm);
  font-family:     var(--cr-font-body);
  font-size:       0.9375rem;
  font-weight:     600;
  line-height:     1.4;
  cursor:          pointer;
  box-shadow:      0 4px 16px rgba(13, 115, 119, 0.35);
  position:        relative;
  overflow:        hidden;
  transition:      transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.cr-btn-primary::after {
  content:    '';
  position:   absolute;
  inset:      0;
  background: rgba(255, 255, 255, 0);
  transition: background 0.2s;
}

.cr-btn-primary:hover:not(:disabled)::after  { background: rgba(255, 255, 255, 0.08); }
.cr-btn-primary:active:not(:disabled)        { transform: scale(0.985); box-shadow: 0 2px 8px rgba(13,115,119,0.22); }
.cr-btn-primary:disabled                     { opacity: 0.5; cursor: not-allowed; }

.cr-btn-label { position: relative; z-index: 1; }

.cr-btn-arrow {
  flex-shrink: 0;
  position:    relative;
  z-index:     1;
  transition:  transform 0.2s;
}

.cr-btn-primary:hover:not(:disabled) .cr-btn-arrow { transform: translateX(4px); }

.cr-btn-text {
  background:          none;
  border:              none;
  color:               var(--cr-teal);
  font-family:         var(--cr-font-body);
  font-size:           0.875rem;
  font-weight:         500;
  cursor:              pointer;
  padding:             8px 0;
  text-decoration:     underline;
  text-underline-offset: 3px;
  display:             block;
  margin:              10px auto 0;
}

.cr-btn-text:hover { color: var(--cr-teal-dark); }

/* ── Status messages ─────────────────────────────────────── */
.cr-status {
  margin-top:    12px;
  font-size:     0.8125rem;
  border-radius: var(--cr-radius-xs);
  line-height:   1.5;
  transition:    all 0.2s;
}

.cr-status:not(:empty) { padding: 10px 14px; }

.cr-status-error   { background: #FEF2F2; color: #991B1B; border-left: 3px solid #EF4444; }
.cr-status-success { background: #F0FBF8; color: #065F46; border-left: 3px solid var(--cr-teal); }
.cr-status-info    { background: #EFF6FF; color: #1E40AF; border-left: 3px solid #3B82F6; }

/* ── OTP step ────────────────────────────────────────────── */
.cr-otp-message {
  padding:       12px 16px;
  background:    var(--cr-surface);
  border-left:   3px solid var(--cr-teal);
  border-radius: 0 var(--cr-radius-xs) var(--cr-radius-xs) 0;
  font-size:     0.9375rem;
  color:         var(--cr-text);
  margin:        0 0 20px;
  line-height:   1.5;
}

/* ── Results section ─────────────────────────────────────── */
.cr-results-header {
  padding:         16px 32px 12px;
  font-size:       0.8125rem;
  color:           var(--cr-muted);
  border-bottom:   1px solid var(--cr-surface-2);
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  flex-wrap:       wrap;
  gap:             6px;
}

.cr-results-header strong { color: var(--cr-text); font-weight: 600; }

.cr-results-back {
  background:     none;
  border:         none;
  color:          var(--cr-teal);
  font-family:    var(--cr-font-body);
  font-size:      0.8125rem;
  font-weight:    500;
  cursor:         pointer;
  padding:        2px 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cr-results-back:hover { color: var(--cr-teal-dark); }

.cr-reports-list {
  padding: 16px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Report cards ────────────────────────────────────────── */
.cr-report-card {
  background:    var(--cr-surface);
  border:        1px solid var(--cr-border);
  border-radius: var(--cr-radius);
  overflow:      hidden;
  animation:     cr-slide-up 0.4s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  transition:    box-shadow 0.2s, transform 0.2s, border-color 0.2s;
}

.cr-report-card:hover {
  box-shadow:   var(--cr-shadow-md);
  transform:    translateY(-2px);
  border-color: rgba(10, 191, 188, 0.25);
}

.cr-report-card:nth-child(1) { animation-delay: 0.04s; }
.cr-report-card:nth-child(2) { animation-delay: 0.08s; }
.cr-report-card:nth-child(3) { animation-delay: 0.12s; }
.cr-report-card:nth-child(4) { animation-delay: 0.16s; }
.cr-report-card:nth-child(5) { animation-delay: 0.20s; }

.cr-report-card-header {
  padding:       12px 16px;
  display:       flex;
  align-items:   center;
  gap:           12px;
  border-bottom: 1px solid var(--cr-border);
  background:    var(--cr-bg);
}

.cr-report-icon {
  width:           36px;
  height:          36px;
  border-radius:   9px;
  background:      var(--cr-teal-dim);
  display:         flex;
  align-items:     center;
  justify-content: center;
  flex-shrink:     0;
  color:           var(--cr-teal-dark);
}

.cr-widget.cr-theme-dark .cr-report-icon { background: rgba(10,191,188,0.12); color: var(--cr-teal); }

.cr-report-meta { flex: 1 1 auto; min-width: 0; }

.cr-report-title {
  margin:          0 0 5px;
  font-size:       0.9375rem;
  font-weight:     600;
  color:           var(--cr-text);
  white-space:     nowrap;
  overflow:        hidden;
  text-overflow:   ellipsis;
}

.cr-report-badges {
  display:     flex;
  align-items: center;
  gap:         6px;
  flex-wrap:   wrap;
}

.cr-badge {
  display:        inline-flex;
  align-items:    center;
  padding:        2px 8px;
  border-radius:  999px;
  font-size:      0.6875rem;
  font-weight:    600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background:     var(--cr-teal-dim);
  color:          var(--cr-teal-dark);
}

.cr-badge-lab          { background: #E8F8F5; color: #0E6655; }
.cr-badge-radiology    { background: #EBF5FB; color: #1A5276; }
.cr-badge-discharge    { background: #F5EEF8; color: #7D3C98; }
.cr-badge-prescription { background: #FEF9E7; color: #9A7D0A; }
.cr-badge-other        { background: var(--cr-surface-2); color: var(--cr-muted); }

.cr-widget.cr-theme-dark .cr-badge-lab         { background: rgba(14,102,85,0.2);  color: #4ECDC4; }
.cr-widget.cr-theme-dark .cr-badge-radiology   { background: rgba(26,82,118,0.2);  color: #74B9F4; }
.cr-widget.cr-theme-dark .cr-badge-discharge   { background: rgba(125,60,152,0.2); color: #CF9EE6; }
.cr-widget.cr-theme-dark .cr-badge-prescription{ background: rgba(154,125,10,0.2); color: #F4D03F; }
.cr-widget.cr-theme-dark .cr-badge-other       { background: rgba(255,255,255,0.06); color: var(--cr-muted); }

.cr-date-pill {
  display:     inline-flex;
  align-items: center;
  gap:         3px;
  font-size:   0.6875rem;
  color:       var(--cr-muted);
}

/* ── File list ───────────────────────────────────────────── */
.cr-file-list {
  list-style: none;
  margin:     0;
  padding:    4px 0;
}

.cr-file-item {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  gap:             8px;
  padding:         8px 16px;
  transition:      background 0.15s;
}

.cr-file-item + .cr-file-item {
  border-top: 1px solid var(--cr-border);
}

.cr-file-item:hover { background: var(--cr-surface-2); }

.cr-file-info {
  display:      flex;
  align-items:  center;
  gap:          8px;
  min-width:    0;
  flex:         1 1 auto;
  color:        var(--cr-text);
}

.cr-file-type-icon {
  flex-shrink: 0;
  color:       var(--cr-muted);
  opacity:     0.75;
}

.cr-file-name {
  font-size:     0.8125rem;
  font-weight:   500;
  overflow:      hidden;
  text-overflow: ellipsis;
  white-space:   nowrap;
}

.cr-file-size {
  font-size:  0.6875rem;
  color:      var(--cr-muted);
  flex-shrink: 0;
}

.cr-file-actions {
  display:     flex;
  gap:         5px;
  flex-shrink: 0;
}

.cr-btn-sm {
  display:         inline-flex;
  align-items:     center;
  gap:             4px;
  padding:         5px 10px;
  border-radius:   var(--cr-radius-xs);
  font-family:     var(--cr-font-body);
  font-size:       0.75rem;
  font-weight:     600;
  cursor:          pointer;
  text-decoration: none;
  transition:      background 0.15s, transform 0.1s, box-shadow 0.1s;
  white-space:     nowrap;
}

.cr-btn-sm:active { transform: scale(0.94); }

.cr-btn-view {
  background: var(--cr-teal-dim);
  color:      var(--cr-teal-dark);
  border:     1px solid rgba(10, 191, 188, 0.22);
}
.cr-btn-view:hover { background: rgba(10, 191, 188, 0.22); }

.cr-btn-download {
  background:  var(--cr-teal-btn);
  color:       #fff;
  border:      none;
  box-shadow:  0 2px 8px rgba(13, 115, 119, 0.32);
}
.cr-btn-download:hover { background: var(--cr-teal-btn-dark); box-shadow: 0 3px 10px rgba(13,115,119,0.4); }

.cr-widget.cr-theme-dark .cr-btn-view {
  background: rgba(10,191,188,0.1);
  color:      var(--cr-teal);
  border-color: rgba(10,191,188,0.2);
}
.cr-widget.cr-theme-dark .cr-btn-view:hover { background: rgba(10,191,188,0.18); }

/* ── Empty state ─────────────────────────────────────────── */
.cr-empty-state {
  text-align:  center;
  padding:     40px 24px;
  color:       var(--cr-muted);
}

.cr-empty-state-icon {
  display:       flex;
  align-items:   center;
  justify-content: center;
  width:         56px;
  height:        56px;
  border-radius: 50%;
  background:    var(--cr-surface-2);
  margin:        0 auto 14px;
  color:         var(--cr-muted);
}

.cr-empty-state p {
  margin:      0;
  font-size:   0.9375rem;
  line-height: 1.6;
}

/* ── Modal ───────────────────────────────────────────────── */
.cr-modal {
  position:        fixed;
  inset:           0;
  z-index:         99999;
  display:         flex;
  align-items:     center;
  justify-content: center;
  animation:       cr-fade-in 0.2s ease both;
}

.cr-modal-overlay {
  position:   absolute;
  inset:      0;
  background: rgba(5, 14, 28, 0.78);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.cr-modal-content {
  position:        relative;
  z-index:         1;
  background:      var(--cr-bg);
  border-radius:   var(--cr-radius-lg);
  box-shadow:      0 32px 80px rgba(5, 14, 28, 0.45);
  width:           min(93vw, 920px);
  height:          min(90vh, 720px);
  display:         flex;
  flex-direction:  column;
  overflow:        hidden;
  animation:       cr-modal-in 0.3s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.cr-modal-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         14px 20px;
  border-bottom:   1px solid var(--cr-border);
  flex-shrink:     0;
  background:      var(--cr-surface);
}

.cr-modal-title {
  font-size:     0.9375rem;
  font-weight:   600;
  color:         var(--cr-text);
  overflow:      hidden;
  text-overflow: ellipsis;
  white-space:   nowrap;
  padding-right: 10px;
}

.cr-modal-close {
  width:           30px;
  height:          30px;
  display:         flex;
  align-items:     center;
  justify-content: center;
  background:      var(--cr-bg);
  border:          1px solid var(--cr-border);
  border-radius:   var(--cr-radius-xs);
  cursor:          pointer;
  color:           var(--cr-muted);
  flex-shrink:     0;
  transition:      background 0.15s, color 0.15s;
}

.cr-modal-close:hover {
  background: var(--cr-surface-2);
  color:      var(--cr-text);
}

#cr-preview-container {
  flex:            1;
  overflow:        hidden;
  display:         flex;
  align-items:     center;
  justify-content: center;
  background:      var(--cr-surface);
}

#cr-preview-container iframe {
  width:  100%;
  height: 100%;
  border: none;
}

#cr-preview-container img {
  max-width:   100%;
  max-height:  100%;
  object-fit:  contain;
  display:     block;
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes cr-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes cr-slide-up {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes cr-modal-in {
  from { opacity: 0; transform: scale(0.94) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Utility ─────────────────────────────────────────────── */
.cr-hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 540px) {
  .cr-header { padding: 24px 20px 22px; }
  .cr-title  { font-size: 1.375rem; }
  .cr-body   { padding: 22px 20px 24px; }

  .cr-results-header { padding: 12px 20px 10px; }
  .cr-reports-list   { padding: 12px 16px 20px; }

  .cr-report-card-header { padding: 10px 12px; }
  .cr-file-item          { padding: 8px 12px; gap: 6px; }
  .cr-file-actions       { flex-shrink: 0; }

  .cr-modal-content { width: 100vw; height: 100dvh; border-radius: 0; }
}
