/* Patient portal & health dashboard */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&family=Playfair+Display:wght@600;700&display=swap');

body.patient-portal {
  font-family: 'Poppins', sans-serif;
  background: linear-gradient(160deg, #fff8f3 0%, #fafafa 40%, #eef6f1 100%);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: max(72px, calc(56px + env(safe-area-inset-top))) 16px 0;
  box-sizing: border-box;
  overflow-x: hidden;
}

body.patient-portal #dg-site-footer {
  width: 100%;
  flex-shrink: 0;
}

body.patient-portal.dashboard-view {
  justify-content: flex-start;
  padding-top: max(16px, env(safe-area-inset-top));
}

body.patient-portal #backToHomeBtn.dg-home-link {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: auto;
  width: auto;
  z-index: 120;
}

.patient-portal-shell {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  position: relative;
}

body.patient-portal:not(.dashboard-view) .patient-portal-shell {
  min-height: min(560px, calc(100dvh - 200px));
}

body.patient-portal.dashboard-view .patient-portal-shell {
  justify-content: flex-start;
  min-height: 0;
  align-items: stretch;
}

body.patient-portal .card {
  background: rgba(255, 255, 255, 0.98);
  border-radius: 20px;
  padding: clamp(24px, 4vw, 40px);
  box-shadow: 0 20px 60px rgba(60, 60, 60, 0.12), 0 8px 24px rgba(242, 103, 39, 0.08);
  border: 1px solid rgba(60, 60, 60, 0.08);
  text-align: center;
  width: min(450px, calc(100vw - 32px));
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: absolute;
  top: 50%;
  left: 50%;
  right: auto !important;
  margin: 0 !important;
  transform: translate(-50%, -50%);
  transition: opacity 0.5s ease, z-index 0.001s linear;
}

body.patient-portal .card.hidden {
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}

body.patient-portal .card.visible {
  opacity: 1;
  pointer-events: auto;
  z-index: 5;
}

body.patient-portal .card h2 {
  font-family: 'Playfair Display', serif;
  color: #3c3c3c;
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.portal-login-sub {
  color: var(--dg-text-muted, #575757);
  font-size: 0.9rem;
  margin: 0 0 24px;
  line-height: 1.5;
}

body.patient-portal .form-group {
  margin-bottom: 18px;
  width: 100%;
  text-align: left;
}

body.patient-portal .form-group label {
  display: block;
  margin-bottom: 6px;
  color: #555;
  font-weight: 600;
  font-size: 0.9rem;
}

.portal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  min-height: 52px;
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
}

.portal-btn--primary {
  background: linear-gradient(135deg, #f26727, #ff8a50);
  color: #fff;
  box-shadow: 0 4px 16px rgba(242, 103, 39, 0.35);
}

.portal-btn--ghost {
  background: #fff;
  color: #3c3c3c;
  border: 1px solid rgba(60, 60, 60, 0.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.portal-btn:hover {
  transform: translateY(-1px);
}

.portal-btn + .portal-btn {
  margin-top: 12px;
}

.portal-message,
.dg-portal-toast {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  display: none;
  width: 100%;
  box-sizing: border-box;
}

.portal-message.success,
.dg-portal-toast.success { background: #d4edda; color: #155724; display: block; }
.portal-message.error,
.dg-portal-toast.error { background: #f8d7da; color: #721c24; display: block; }
.portal-message.info,
.dg-portal-toast.info { background: #d1ecf1; color: #0c5460; display: block; }

/* Dashboard */
.dg-patient-dashboard {
  width: 100%;
  opacity: 0;
  visibility: hidden;
  display: none;
  transition: opacity 0.4s ease;
}

.dg-patient-dashboard.visible {
  opacity: 1;
  visibility: visible;
  display: block;
}

.dg-pat-shell {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 8px 32px;
}

.dg-pat-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 0 16px;
  margin-bottom: 8px;
  background: rgba(250, 250, 250, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(60, 60, 60, 0.08);
}

.dg-pat-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 220px;
}

.dg-pat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f26727, #ff8a50);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.dg-pat-brand-text h1 {
  margin: 0;
  font-family: 'Playfair Display', serif;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
}

.dg-pat-brand-text p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--dg-text-muted, #575757);
}

.dg-pat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.dg-pat-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 10px;
  border: none;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
}

.dg-pat-btn--ghost {
  background: #fff;
  color: #3c3c3c;
  border: 1px solid rgba(60, 60, 60, 0.12);
}

.dg-pat-btn--primary {
  background: linear-gradient(135deg, #f26727, #ff8a50);
  color: #fff;
}

.dg-pat-btn--danger {
  background: #fff;
  color: #b91c1c;
  border: 1px solid rgba(185, 28, 28, 0.2);
}

.dg-dash-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.dg-dash-stat {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 14px;
  padding: 16px 10px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(60, 60, 60, 0.06);
  min-width: 0;
}

.dg-dash-stat strong {
  display: block;
  font-size: 1.5rem;
  color: #f26727;
  line-height: 1.2;
}

.dg-dash-stat span {
  font-size: 0.82rem;
  color: var(--dg-text-muted, #575757);
}

.dg-dash-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 20px;
}

.dg-dash-tab {
  border: 1px solid #f26727;
  background: #fff;
  color: #f26727;
  border-radius: 999px;
  padding: 9px 18px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  touch-action: manipulation;
}

.dg-dash-tab.active {
  background: #f26727;
  color: #fff;
}

.dg-dash-panel { display: none; }
.dg-dash-panel.active { display: block; }

#tab-appointments.active,
#tab-consultations.active,
#tab-prescriptions.active,
#tab-orders.active {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  align-items: stretch;
}

#tab-appointments.active:has(.dg-dash-empty),
#tab-consultations.active:has(.dg-dash-empty),
#tab-prescriptions.active:has(.dg-dash-empty),
#tab-orders.active:has(.dg-dash-empty) {
  display: block;
}

.dg-record-card {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(60, 60, 60, 0.06);
  text-align: left;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-wrap: anywhere;
}

.dg-record-card h3 {
  margin: 0 0 12px;
  text-align: left;
  color: #f26727;
  font-size: 1.1rem;
}

.dg-record-card p {
  margin: 6px 0;
  color: #444;
  font-size: 0.9rem;
  line-height: 1.45;
}

.dg-record-card p strong { color: #333; }

.dg-record-card .room-id {
  font-weight: 700;
  color: #b91c1c;
  background: #fff3cd;
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.dg-record-card .timer {
  position: static;
  display: inline-block;
  align-self: flex-start;
  margin: 0 0 10px;
  background: #f8d7da;
  color: #721c24;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.3;
}

.dg-record-card.expired { border-color: rgba(185, 28, 28, 0.35); }

.dg-record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
}

.dg-action-btn,
.dg-record-card .dg-btn,
.dg-record-card .dg-btn-primary,
.dg-record-card .dg-btn-secondary {
  width: 100%;
  margin-top: 8px;
  padding: 11px 14px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
  display: inline-block;
  font-family: inherit;
}

.dg-action-btn--call {
  background: linear-gradient(135deg, #2d6a4f, #40916c);
  color: #fff;
}

.dg-record-card .dg-btn-primary {
  background: linear-gradient(135deg, #f26727, #ff8a50);
  color: #fff !important;
  border-radius: 10px;
}

.dg-record-card .dg-btn-secondary {
  background: #fff;
  color: #3c3c3c;
  border: 1px solid rgba(60, 60, 60, 0.14);
}

.dg-record-actions .dg-btn,
.dg-record-actions .dg-btn-primary,
.dg-record-actions .dg-btn-secondary,
.dg-record-actions .dg-action-btn {
  width: auto;
  flex: 1 1 160px;
  margin-top: 0;
}

.dg-action-btn--followup {
  background: #16a34a;
  color: #fff;
  margin-top: 8px;
}

.dg-action-btn--expired {
  background: #6c757d;
  color: #fff;
  cursor: default;
  opacity: 0.85;
}

.dg-dash-empty {
  text-align: center;
  color: var(--dg-text-muted, #575757);
  padding: 32px 16px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 14px;
}

.dg-portal-toast {
  position: static;
  z-index: 40;
  margin-bottom: 16px;
}

body.patient-portal.dashboard-view #backToHomeBtn.dg-home-link {
  display: none !important;
}

#noAppointmentsMessage {
  display: none !important;
}

@media (max-width: 768px) {
  body.patient-portal.dashboard-view {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .dg-dash-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dg-pat-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .dg-pat-actions {
    justify-content: stretch;
  }

  .dg-pat-actions .dg-pat-btn {
    flex: 1;
    justify-content: center;
  }
}
