/* ============================================================
   Patient Portal — overlay styles on top of main design system
   ============================================================ */

/* Portal page hero */
.portal-hero {
  background: linear-gradient(150deg, #2A3A2A 0%, #3D4F3D 50%, #5C7A5C 100%);
  padding: var(--space-16) 0 var(--space-12);
  position: relative;
  overflow: hidden;
}
.portal-hero::before {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(107,140,107,0.18) 0%, transparent 70%);
  top: -120px; right: -80px;
  border-radius: 50%;
  pointer-events: none;
}
.portal-hero__badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: rgba(255,255,255,0.13);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.9);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: var(--space-4);
  backdrop-filter: blur(8px);
}
.portal-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 3rem);
  color: var(--white);
  line-height: 1.15;
  margin-bottom: var(--space-4);
}
.portal-hero p {
  font-size: var(--text-base);
  color: rgba(255,255,255,0.78);
  max-width: 540px;
  line-height: 1.7;
}

/* Sub-nav tabs */
.portal-tabs {
  background: var(--white);
  border-bottom: 1px solid var(--color-border-light);
  position: sticky;
  top: 104px; /* nav (64px) + crisis banner (40px) */
  z-index: 40; /* must be above portal-hero (position:relative, auto z-index) */
}
/* When banner is dismissed, nav shrinks back to 64px */
.banner-hidden .portal-tabs {
  top: 64px;
}
.portal-tabs__inner {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 0;
}
.portal-tabs__inner::-webkit-scrollbar { display: none; }
.portal-tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.2s;
  flex-shrink: 0;
}
.portal-tab:hover { color: var(--sage-dark); }
.portal-tab.active {
  color: var(--sage-dark);
  border-bottom-color: var(--sage-dark);
}
.portal-tab svg { opacity: 0.7; }
.portal-tab.active svg { opacity: 1; }

/* Portal content area */
.portal-content {
  background: var(--cream);
  min-height: 60vh;
  padding: var(--space-12) 0 var(--space-16);
  /* Must sit above portal-hero (position:relative, auto z-index = stacking level 6) */
  position: relative;
  z-index: 2;
}

/* Cards — using main design system base, portal variant */
.portal-card {
  background: var(--white);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-sm);
  padding: var(--space-8);
  transition: box-shadow 0.2s;
}
.portal-card:hover { box-shadow: var(--shadow-md); }

/* Tile grid for home */
.portal-tile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-5);
}
@media (max-width: 640px) { .portal-tile-grid { grid-template-columns: 1fr; } }

.portal-tile {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  background: var(--white);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border-light);
  padding: var(--space-6);
  text-decoration: none;
  color: var(--charcoal);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
  /* Fix iOS double-tap: forces single tap to fire as click */
  touch-action: manipulation;
  cursor: pointer;
  position: relative;
  z-index: 1;
}
.portal-tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--sage);
}
.portal-tile--primary {
  background: linear-gradient(135deg, var(--sage-deep), var(--sage));
  border: none;
  color: white;
}
.portal-tile--primary:hover { border-color: transparent; }
.portal-tile__emoji { font-size: 1.75rem; flex-shrink: 0; }
.portal-tile__title { font-weight: 700; font-size: var(--text-base); margin-bottom: var(--space-1); }
.portal-tile--primary .portal-tile__title { color: white; }
.portal-tile__desc { font-size: var(--text-sm); color: var(--color-text-secondary); }
.portal-tile--primary .portal-tile__desc { color: rgba(255,255,255,0.75); }
.portal-tile__arrow { margin-left: auto; flex-shrink: 0; opacity: 0.35; }
.portal-tile--primary .portal-tile__arrow { opacity: 0.8; }

/* Form elements matching main site feel */
.p-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--charcoal);
  margin-bottom: var(--space-2);
}
.p-input, .p-select {
  width: 100%;
  padding: 11px var(--space-4);
  border: 1.5px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  color: var(--charcoal);
  background: var(--white);
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.p-input:focus, .p-select:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(107,140,107,0.15);
}
.p-input::placeholder { color: var(--color-text-muted); }
.p-group { margin-bottom: var(--space-5); }
.p-note { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: var(--space-1); line-height: 1.5; }

/* Radio pills */
.p-radio-group { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.p-radio-pill {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 9px var(--space-4);
  border: 1.5px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all 0.15s;
  color: var(--charcoal);
}
.p-radio-pill.checked {
  border-color: var(--sage);
  background: var(--sage-lighter);
  color: var(--sage-dark);
  font-weight: 700;
}
.p-radio-pill input { display: none; }
.p-radio-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--color-border-light);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.p-radio-pill.checked .p-radio-dot {
  border-color: var(--sage);
  background: var(--sage);
}
.p-radio-pill.checked .p-radio-dot::after {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: white;
}

/* Toggle switch */
.p-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-xl);
  padding: var(--space-4) var(--space-6);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-xs);
}
.p-toggle-label { font-size: var(--text-sm); font-weight: 600; color: var(--charcoal); margin-bottom: 2px; }
.p-toggle-desc { font-size: var(--text-xs); color: var(--color-text-muted); }
.p-toggle {
  position: relative; width: 44px; height: 24px; flex-shrink: 0;
}
.p-toggle input { opacity: 0; width: 0; height: 0; }
.p-toggle-slider {
  position: absolute; inset: 0;
  background: var(--color-border-light);
  border-radius: 100px; cursor: pointer; transition: 0.3s;
}
.p-toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px; left: 3px; top: 3px;
  background: white; border-radius: 50%; transition: 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.p-toggle input:checked + .p-toggle-slider { background: var(--sage); }
.p-toggle input:checked + .p-toggle-slider::before { transform: translateX(20px); }

/* Calendar */
.p-cal-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4);
}
.p-cal-nav {
  background: none;
  border: 1.5px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  width: 36px; height: 36px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--charcoal); font-size: 16px; transition: all 0.2s;
}
.p-cal-nav:hover { background: var(--sage-lighter); border-color: var(--sage); }
.p-cal-month { font-weight: 700; font-size: var(--text-base); color: var(--charcoal); }
.p-cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; margin-bottom: 6px;
}
.p-cal-day-label {
  text-align: center; font-size: 11px; font-weight: 700;
  color: var(--color-text-muted); padding: 5px 0;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.p-cal-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-lg); font-size: var(--text-sm); cursor: pointer;
  transition: all 0.15s; position: relative; font-weight: 500; color: var(--charcoal);
}
.p-cal-day:hover:not(.empty):not(.past) { background: var(--sage-lighter); }
.p-cal-day.today { border: 2px solid var(--sage); font-weight: 700; }
.p-cal-day.has-slots::after {
  content: ''; position: absolute; bottom: 4px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--sage);
}
.p-cal-day.selected { background: var(--sage-dark) !important; color: white; }
.p-cal-day.past { color: var(--color-text-muted); cursor: default; opacity: 0.4; }
.p-cal-day.empty { cursor: default; }

/* Slots */
.p-slots-header { font-size: var(--text-sm); font-weight: 700; color: var(--charcoal); margin-bottom: var(--space-3); }
.p-slots { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.p-slot {
  padding: 8px var(--space-4);
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--sage);
  background: var(--sage-lighter);
  color: var(--sage-dark);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-body);
}
.p-slot:hover, .p-slot.selected {
  background: var(--sage-dark); color: white; border-color: var(--sage-dark);
}

/* Confirm summary */
.p-confirm {
  background: var(--sage-lighter);
  border: 1px solid rgba(107,140,107,0.3);
  border-radius: var(--radius-xl);
  padding: var(--space-6) var(--space-7);
  margin-top: var(--space-6);
}
.p-confirm h3 { font-size: var(--text-base); font-weight: 700; margin-bottom: var(--space-4); color: var(--charcoal); }
.p-confirm-row {
  display: flex; gap: var(--space-2); font-size: var(--text-sm); margin-bottom: var(--space-2);
}
.p-confirm-row strong { min-width: 90px; flex-shrink: 0; color: var(--charcoal); }
.p-confirm-row span { color: var(--color-text-secondary); }

/* Login center layout */
.portal-login-wrap {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-4);
  background: var(--cream);
}
.portal-login-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border-radius: var(--radius-2xl);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-lg);
  padding: var(--space-10);
}

/* Mic meter */
.p-mic-meter {
  display: flex; gap: 4px; align-items: flex-end; height: 40px; margin-bottom: var(--space-4);
}
.p-mic-bar {
  width: 8px; border-radius: 4px;
  background: var(--color-border-light);
  transition: height 0.1s ease; min-height: 4px;
}
.p-mic-bar.active { background: var(--sage); }

/* AV status */
.p-av-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 700;
}
.p-av-status .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.p-av-status--waiting { background: #FFF3CD; color: #856404; }
.p-av-status--ok { background: var(--sage-lighter); color: var(--sage-dark); }
.p-av-status--error { background: #FEF2F2; color: #991B1B; }

/* Video preview */
#video-preview {
  width: 100%; max-width: 480px; aspect-ratio: 4/3;
  background: #1A2B1A; border-radius: var(--radius-xl);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; margin-bottom: var(--space-4);
}
#video-preview video { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-xl); display: none; }
#video-preview .placeholder {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
  color: rgba(255,255,255,0.4); font-size: 2rem;
}
#video-preview .placeholder p { font-size: var(--text-sm); color: rgba(255,255,255,0.4); margin: 0; }

/* Alert */
.p-alert {
  padding: var(--space-4); border-radius: var(--radius-lg);
  font-size: var(--text-sm); line-height: 1.6; margin-bottom: var(--space-5); display: none;
}
.p-alert--success { background: var(--sage-lighter); border: 1px solid rgba(107,140,107,0.3); color: var(--sage-dark); }
.p-alert--error { background: #FEF2F2; border: 1px solid #FECACA; color: #991B1B; }

/* Info grid */
.portal-info-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-5);
}
@media (max-width: 768px) { .portal-info-grid { grid-template-columns: 1fr; } }

/* Utility */
.p-divider {
  display: flex; align-items: center; gap: var(--space-3);
  font-size: var(--text-xs); color: var(--color-text-muted); margin: var(--space-6) 0;
}
.p-divider::before, .p-divider::after { content: ''; flex: 1; height: 1px; background: var(--color-border-light); }

.p-checkbox-row {
  display: flex; align-items: flex-start; gap: var(--space-3); margin-bottom: var(--space-5);
}
.p-checkbox-row input[type="checkbox"] {
  width: 16px; height: 16px; margin-top: 2px; accent-color: var(--sage); flex-shrink: 0;
}
.p-checkbox-row label { font-size: var(--text-sm); color: var(--color-text-secondary); line-height: 1.5; }

/* ── Lang button visibility on portal pages ─────────────── */
/* Ensure both EN and ES buttons are always clearly visible  */
.portal-hero ~ * .nav__lang-btn,
.portal-content ~ * .nav__lang-btn,
.portal-login-wrap ~ * .nav__lang-btn {
  color: rgba(255,255,255,0.85);
}
/* Simpler: just always show both clearly in portal context  */
body .nav__lang-btn {
  opacity: 1;
}
body .nav__lang-btn:not(.active) {
  color: rgba(255,255,255,0.75);
}
body.scrolled .nav__lang-btn:not(.active),
body .nav.scrolled .nav__lang-btn:not(.active) {
  color: var(--stone);
}

/* ── Portal: make both EN/ES buttons always visible ──────── */
/* The transparent nav at top hides the inactive button —    */
/* give the whole pill group a visible background always     */
.portal-hero ~ nav .nav__lang,
.portal-hero + nav .nav__lang,
nav + nav .nav__lang,
.portal-tabs ~ * .nav__lang {
  background: rgba(255,255,255,0.22);
  border: 1px solid rgba(255,255,255,0.3);
}

/* Force both buttons visible regardless of page scroll state */
body .nav__lang {
  background: rgba(255,255,255,0.2) !important;
  border: 1px solid rgba(255,255,255,0.28) !important;
}
body .nav__lang-btn {
  color: rgba(255,255,255,0.9) !important;
  font-weight: 700 !important;
}
body .nav__lang-btn.active {
  background: white !important;
  color: var(--sage-dark) !important;
  box-shadow: var(--shadow-sm) !important;
}
/* Scrolled state — keep dark version readable too */
body .nav.scrolled .nav__lang {
  background: var(--cream-dark) !important;
  border-color: var(--color-border-light) !important;
}
body .nav.scrolled .nav__lang-btn {
  color: var(--stone) !important;
}
body .nav.scrolled .nav__lang-btn.active {
  background: white !important;
  color: var(--sage-dark) !important;
}
