:root {
  --bg-color: #0b0f19;
  --panel-bg: rgba(22, 29, 49, 0.7);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  
  --primary-color: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.35);
  
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.2);

  --font-family: 'Outfit', sans-serif;
  --transition-speed: 0.3s;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Header styling */
.app-header {
  background-color: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
}

.wave-logo {
  color: var(--primary-color);
  animation: pulse-wave 2s infinite ease-in-out;
}

@keyframes pulse-wave {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px var(--primary-color)); }
  50% { transform: scale(1.15); filter: drop-shadow(0 0 10px var(--primary-color)); }
}

.tm {
  font-size: 0.85rem;
  vertical-align: super;
  color: var(--primary-color);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 0.4rem 0.9rem;
  border-radius: 30px;
  font-family: var(--font-family);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition-speed);
}
.back-btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: var(--primary-glow);
}

.lang-selector {
  display: flex;
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 30px;
  padding: 2px;
  border: 1px solid var(--panel-border);
}

.lang-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 0.4rem 0.8rem;
  font-family: var(--font-family);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 30px;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.lang-btn.active {
  background-color: var(--primary-color);
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.portal-toggle {
  display: flex;
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--panel-border);
}

.toggle-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 0.5rem 1.2rem;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-speed);
}

.toggle-btn.active {
  background-color: var(--primary-color);
  color: #fff;
}

/* Clinician sidebar nav uses .secondary-btn-based tabs; the .active state
   mirrors .toggle-btn.active so whichever panel is open is always visible. */
.nav-tab-btn.active {
  background-color: var(--primary-color);
  color: #fff;
}
.nav-tab-btn.active i {
  color: #fff;
}

/* Layout Main */
.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.portal-section {
  display: none;
  width: 100%;
}

.portal-section.active {
  display: block;
}

.app-container {
  width: 100%;
  max-width: 1200px;
  min-height: 80vh;
  background-color: var(--bg-color);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  margin: 2rem auto;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 40px var(--primary-glow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all var(--transition-speed);
}

.app-screen {
  flex: 1;
  background: radial-gradient(circle at top, #1e1b4b 0%, #09090b 100%);
  padding: 3rem;
  overflow-y: auto;
  position: relative;
  scrollbar-width: none;
}

.app-screen::-webkit-scrollbar {
  display: none;
}

.app-screen-content {
  display: none;
  flex-direction: column;
  height: 100%;
  animation: fadeIn 0.4s ease-in-out;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.app-screen-content.active {
  display: flex;
}

@media (max-width: 768px) {
  .app-screen {
    padding: 1.5rem;
  }
  .app-container {
    margin: 1rem auto;
    border-radius: 16px;
    min-height: calc(100vh - 120px);
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Onboarding view styling */
.onboarding-header {
  text-align: center;
  margin-top: 2rem;
  margin-bottom: 2.5rem;
}

.splash-icon {
  font-size: 3.5rem;
  color: var(--primary-color);
  margin-bottom: 1rem;
  filter: drop-shadow(0 0 10px var(--primary-glow));
}

.onboarding-header h2 {
  font-size: 1.7rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.onboarding-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.onboarding-form, .progress-form {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group {
  flex: 1;
}

label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input, select, textarea {
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 0.95rem;
  transition: border-color var(--transition-speed);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 5px var(--primary-glow);
}

select option {
  background-color: #161d31;
  color: var(--text-primary);
}

/* Glass Panels */
.glass-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1.2rem;
  margin-bottom: 1.2rem;
  backdrop-filter: blur(8px);
}

/* Buttons */
.primary-btn {
  background-color: var(--primary-color);
  color: #fff;
  border: none;
  padding: 0.85rem 1.5rem;
  border-radius: 8px;
  font-family: var(--font-family);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 12px var(--primary-glow);
  transition: all var(--transition-speed);
}

.primary-btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.primary-btn:disabled {
  background-color: #374151;
  color: #9ca3af;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.secondary-btn {
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 0.85rem 1.2rem;
  border-radius: 8px;
  font-family: var(--font-family);
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background-color var(--transition-speed);
}

.secondary-btn:hover {
  background-color: rgba(255, 255, 255, 0.12);
}

.icon-btn-round {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-speed);
}

.icon-btn-round:hover {
  background: var(--danger-color);
}

/* Dashboard Patient Home */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.user-greeting span {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.user-greeting h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

.quick-status-card {
  background: linear-gradient(135deg, #312e81 0%, #1e1b4b 100%);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1.2rem;
  margin-bottom: 1.5rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.status-card-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #c7d2fe;
  display: block;
  margin-bottom: 0.75rem;
}

.active-protocol-summary-box p {
  font-size: 0.9rem;
  line-height: 1.4;
  color: #e0e7ff;
}

.active-protocol-preview {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.preview-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
}

.preview-row span {
  color: #c7d2fe;
}

.dashboard-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.action-card-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1rem;
  color: #fff;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: all var(--transition-speed);
}

.action-card-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

.card-icon {
  font-size: 1.8rem;
  color: var(--primary-color);
}

.card-text {
  display: flex;
  flex-direction: column;
}

.card-headline {
  font-weight: 600;
  font-size: 0.95rem;
}

.card-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* History logs list */
.recent-sessions-list h4 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 0.75rem;
  letter-spacing: 0.5px;
}

.session-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--panel-border);
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.session-history-item span {
  color: var(--text-secondary);
}

.session-history-item strong {
  color: var(--success-color);
}

.session-history-item.incomplete strong {
  color: var(--danger-color);
}

/* Body SVG Styling — 3D Anatomical Map */
.step-guide-txt {
  font-size: 0.95rem;
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

.body-selector-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.2rem;
  position: relative;
}

/* View Toggle */
.body-view-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 0.8rem;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--panel-border);
}

.view-toggle-btn {
  padding: 0.35rem 1rem;
  font-size: 0.78rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.25s ease;
  font-family: inherit;
  letter-spacing: 0.03em;
}

.view-toggle-btn.active {
  background: var(--primary-color);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.view-toggle-btn:not(.active):hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.08);
}

/* SVG Container */
.human-body-svg {
  width: 100%;
  max-width: 280px;
  height: auto;
  background: radial-gradient(ellipse at 50% 30%, rgba(99,102,241,0.04) 0%, rgba(0,0,0,0.15) 100%);
  border-radius: 16px;
  border: 1px solid rgba(99, 102, 241, 0.15);
  padding: 16px;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.body-view {
  display: none;
}

.body-view.active {
  display: flex;
  justify-content: center;
}

.large-body-svg {
  max-width: 340px;
  box-shadow:
    inset 0 2px 20px rgba(0, 0, 0, 0.4),
    0 4px 24px rgba(0, 0, 0, 0.2);
}

/* PNG Body Figure (photo-realistic selectable figures) */
.body-figure {
  position: relative;
  width: 190px;
  aspect-ratio: 167 / 362;
  margin: 0 auto;
  background: radial-gradient(ellipse at 50% 30%, rgba(99, 102, 241, 0.06) 0%, rgba(0, 0, 0, 0.22) 100%);
  border-radius: 16px;
  border: 1px solid rgba(99, 102, 241, 0.15);
  overflow: hidden;
  box-shadow:
    inset 0 2px 20px rgba(0, 0, 0, 0.4),
    0 4px 24px rgba(0, 0, 0, 0.2);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.body-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  margin: 0 auto;
  pointer-events: none;
}

.body-hit-map {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.body-hit-map .paint-surface {
  pointer-events: all;
}

/* Body Silhouette & Muscle Lines */
.body-silhouette {
  opacity: 1;
  filter: drop-shadow(0 5px 7px rgba(0, 0, 0, 0.28));
}

.muscle-lines {
  pointer-events: none;
}

.body-labels {
  transition: opacity 0.2s ease;
}

.body-parts-group:hover ~ .body-labels,
.body-selector-wrapper:hover .body-labels {
  opacity: 1;
}

/* Paint overlay — free-form selection clipped to body silhouette */
.body-paint {
  pointer-events: none;
}

.paint-surface {
  fill: transparent;
  pointer-events: all;
  cursor: crosshair;
  touch-action: none;
}

.body-figure.erasing .paint-surface {
  cursor: cell;
}

.paint-stroke {
  stroke: #6366f1;
  fill: none;
  opacity: 0.72;
  pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(99, 102, 241, 0.85));
}

.paint-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
  margin-left: auto;
  margin-right: auto;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 6px 10px;
  width: fit-content;
}

.brush-sizes {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding-right: 0.5rem;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}

.brush-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.brush-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.brush-btn.active {
  background: var(--primary-color);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.brush-dot {
  display: inline-block;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: background 0.2s ease;
}

.brush-btn.active .brush-dot {
  background: #fff;
}

.paint-action-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.paint-action-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.paint-action-btn.active {
  background: rgba(239, 68, 68, 0.22);
  color: #f87171;
}

.paint-clear-btn {
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0 8px 8px 0;
  color: #f87171;
}

/* Selected Part Label */
.selected-part-label {
  margin-top: 0.8rem;
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.selected-part-label strong {
  color: var(--primary-color);
  margin-left: 0.4rem;
  flex: 1 1 auto;
  min-width: 0;
}

/* Expand/collapse toggle next to the selected-area preview */
.selected-part-toggle {
  flex: 0 0 auto;
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent-primary, #6366f1);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-speed), border-color var(--transition-speed);
}
.selected-part-toggle:hover {
  background: rgba(99, 102, 241, 0.25);
}

/* Chips container (expanded state) */
.selected-part-chips {
  flex-basis: 100%;
  display: none;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.2rem;
}

.part-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 999px;
  padding: 0.22rem 0.4rem 0.22rem 0.7rem;
  font-size: 0.8rem;
  color: #e2e8f0;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.part-chip-x {
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0.12rem 0.32rem;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  transition: background var(--transition-speed), color var(--transition-speed);
}
.part-chip-x:hover {
  background: rgba(239, 68, 68, 0.4);
  color: #fff;
}

/* Floating toolbar over the 3D body map: Undo / Redo / Clear */
.body3d-actions {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 3;
}

.body3d-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.body3d-action-btn:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.55);
}

.body3d-action-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.body3d-clear-btn {
  margin-left: 2px;
}

.body3d-clear-btn:not(:disabled):hover {
  background: rgba(239, 68, 68, 0.55);
}

/* 3D body viewport (Three.js) */
.body3d-viewport {
  position: relative;
  width: 100%;
  max-width: 340px;
  height: clamp(320px, 52vh, 520px);
  margin: 0 auto;
  background: radial-gradient(ellipse at 50% 32%, rgba(99, 102, 241, 0.10) 0%, rgba(0, 0, 0, 0.28) 100%);
  border-radius: 16px;
  border: 1px solid rgba(99, 102, 241, 0.18);
  overflow: hidden;
  box-shadow:
    inset 0 2px 20px rgba(0, 0, 0, 0.4),
    0 4px 24px rgba(0, 0, 0, 0.2);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.body3d-viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.body3d-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  padding: 0.5rem 0.9rem;
  pointer-events: none;
}

.body3d-status.error {
  color: #f87171;
}

.body3d-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.45rem 0.6rem;
  font-size: 0.66rem;
  line-height: 1.3;
  text-align: center;
  color: var(--text-secondary);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0));
  pointer-events: none;
}

@media (min-width: 768px) {
  .body3d-viewport {
    max-width: 420px;
    height: clamp(420px, 58vh, 640px);
  }
}

@media (max-width: 380px) {
  .paint-toolbar {
    flex-wrap: wrap;
    max-width: 100%;
  }

  .brush-btn,
  .paint-action-btn {
    min-width: 40px;
    min-height: 38px;
  }
}


/* Pain slider */
.pain-slider-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem 0;
}

.pain-emoji {
  font-size: 3.5rem;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.pain-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary-color);
}

.custom-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: #374151;
  outline: none;
}

.custom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  box-shadow: 0 0 10px var(--primary-glow);
  transition: transform 0.1s;
}

.custom-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.navigation-row {
  display: flex;
  justify-content: space-between;
  margin-top: 1.5rem;
}

/* Protocol displays */
.protocol-card {
  margin-bottom: 1.2rem;
}

.protocol-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 0.6rem;
  margin-bottom: 0.8rem;
}

.badge-override {
  background: var(--warning-color);
  color: #000;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.protocol-header h4 {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.setting-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.setting-item i {
  color: var(--primary-color);
  font-size: 1.1rem;
}

.setting-details {
  display: flex;
  flex-direction: column;
}

.setting-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.setting-value {
  font-size: 0.85rem;
  font-weight: 700;
}

.placement-guide, .setup-steps {
  font-size: 0.8rem;
  line-height: 1.4;
  margin-bottom: 0.8rem;
}

.placement-guide h5, .setup-steps h5 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.setup-steps ol {
  padding-left: 1.2rem;
  color: var(--text-secondary);
}

/* Additional painted parts: secondary protocol cards */
.protocol-heading-multi {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 1rem 0 0.4rem;
}

.protocol-heading-multi h5 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sub-protocol-card {
  margin-bottom: 0.6rem;
  padding: 0.7rem;
}

#protocol-parts-list .sub-protocol-card .protocol-header {
  margin-bottom: 0.35rem;
}

#protocol-parts-list .sub-protocol-card .protocol-header h4 {
  font-size: 0.85rem;
}

/* Timer */
.timer-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
  gap: 0.8rem;
}

.timer-ring-container {
  position: relative;
  width: 120px;
  height: 120px;
}

.timer-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.05);
  stroke-width: 6;
}

.timer-progress {
  fill: none;
  stroke: var(--primary-color);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear;
}

.timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  font-weight: 800;
}

.timer-controls {
  display: flex;
  gap: 1.2rem;
}

.timer-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition-speed);
}

.timer-btn.primary {
  background-color: var(--primary-color);
  color: #fff;
}

.timer-btn.secondary {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

/* Radio cards */
.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
}

.radio-card {
  cursor: pointer;
}

.radio-card input {
  display: none;
}

.radio-content {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.6rem 0.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  text-align: center;
  transition: all var(--transition-speed);
}

.radio-card input:checked + .radio-content {
  border-color: var(--primary-color);
  background: rgba(99, 102, 241, 0.15);
  box-shadow: 0 0 5px var(--primary-glow);
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-round {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #374151;
  border-radius: 34px;
  transition: .3s;
}

.slider-round:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: .3s;
}

.toggle-switch input:checked + .slider-round {
  background-color: var(--success-color);
}

.toggle-switch input:checked + .slider-round:before {
  transform: translateX(22px);
}

/* Modal Feedback styling */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  text-align: center;
  padding: 2rem 1.5rem;
  max-width: 320px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  animation: modalPop 0.3s ease-out;
}

@keyframes modalPop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-icon {
  font-size: 3rem;
  color: var(--primary-color);
  filter: drop-shadow(0 0 8px var(--primary-glow));
}

/* CLINICIAN DASHBOARD PORTAL */
/* minmax(0, …) prevents wide children (tables/inputs) from inflating the 1fr
   track beyond the viewport — the root cause of mobile horizontal overflow. */
.dashboard-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 2rem;
  min-height: calc(100vh - 160px);
}

.dashboard-layout > * {
  min-width: 0;
}

.dashboard-workspace {
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

.dashboard-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: relative;
}

/* Slim floating collapse/expand button */
.sidebar-collapse-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(99, 102, 241, 0.12);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: background var(--transition-speed), color var(--transition-speed);
}
.sidebar-collapse-btn:hover {
  background: rgba(99, 102, 241, 0.3);
  color: #fff;
}
.sidebar-collapse-btn i {
  transition: transform var(--transition-speed);
}

/* ---- Collapsed state: slim icon rail ---- */
.dashboard-layout:has(.dashboard-sidebar.sidebar-collapsed) {
  grid-template-columns: 72px minmax(0, 1fr);
}

.dashboard-sidebar.sidebar-collapsed .sidebar-collapse-btn i {
  transform: rotate(180deg);
}

.dashboard-sidebar.sidebar-collapsed .sidebar-greeting > div {
  display: none;
}
.dashboard-sidebar.sidebar-collapsed .sidebar-greeting {
  justify-content: center;
}

.dashboard-sidebar.sidebar-collapsed .toggle-btn,
.dashboard-sidebar.sidebar-collapsed .secondary-btn {
  justify-content: center !important;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  overflow: hidden;
  white-space: nowrap;
}
.dashboard-sidebar.sidebar-collapsed .toggle-btn span,
.dashboard-sidebar.sidebar-collapsed .secondary-btn span:not(.chat-unread-badge) {
  display: none;
}

.dashboard-sidebar.sidebar-collapsed .clinician-stats-grid,
.dashboard-sidebar.sidebar-collapsed .alerts-feed-panel,
.dashboard-sidebar.sidebar-collapsed .analytics-panel {
  display: none;
}

.sidebar-greeting {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.doctor-avatar {
  font-size: 2.2rem;
  color: var(--primary-color);
  background: rgba(99, 102, 241, 0.1);
  padding: 0.75rem;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
}

.clinician-stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.metric-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  padding: 1rem;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
}

.metric-lbl {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.metric-val {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

.metric-card.red-theme {
  border-left: 4px solid var(--danger-color);
}
.metric-card.red-theme .metric-val {
  color: var(--danger-color);
}

.metric-card.green-theme {
  border-left: 4px solid var(--success-color);
}
.metric-card.green-theme .metric-val {
  color: var(--success-color);
}

.alerts-feed-panel {
  flex: 1;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.alerts-feed-panel h4 {
  font-size: 0.95rem;
  margin-bottom: 0.8rem;
  color: var(--text-secondary);
}

.alerts-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.alert-card {
  background: rgba(239, 68, 68, 0.05);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.8rem;
}

.alert-card.no-improvement {
  background: rgba(245, 158, 11, 0.05);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.alert-top {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.alert-title {
  color: var(--danger-color);
}

.alert-card.no-improvement .alert-title {
  color: var(--warning-color);
}

.alert-msg {
  color: var(--text-secondary);
  line-height: 1.3;
}

.analytics-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.analytics-panel h4 {
  font-size: 0.95rem;
  margin-bottom: 0.8rem;
  color: var(--text-secondary);
}

.analytics-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.analytics-item:last-child {
  border-bottom: none;
}

.analytics-lbl {
  flex: 1;
  color: var(--text-secondary);
}

.analytics-val {
  color: var(--text-primary);
}

.profile-card h4 {
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.alert-resolve-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  align-self: flex-end;
  font-family: var(--font-family);
  font-size: 0.7rem;
  font-weight: 600;
}

.alert-resolve-btn:hover {
  background: var(--success-color);
}

/* Workspace Panels */
.dashboard-workspace {
  flex: 1;
}

.workspace-panel {
  display: none;
  flex-direction: column;
  height: 100%;
}

.workspace-panel.active {
  display: flex;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.panel-header h2 {
  font-size: 1.8rem;
  font-weight: 700;
}

.search-box {
  position: relative;
  width: 300px;
}

.search-box i {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
}

.search-box input {
  width: 100%;
  padding-left: 2.5rem;
}

/* Patient Tables */
.table-container {
  overflow-x: auto;
}

.patient-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.patient-table th, .patient-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--panel-border);
  overflow-wrap: anywhere; /* long emails/phones/refs must wrap, not overflow */
}

.patient-table th {
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap; /* pills never wrap mid-word */
}

/* Table action buttons: no vertical letter-stacking on wide screens */
.patient-table .text-link-btn,
.patient-table .secondary-btn,
.patient-table .primary-btn,
.secondary-btn,
.primary-btn {
  white-space: nowrap;
}

.status-badge.green {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--success-color);
}
.status-badge.yellow {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--warning-color);
}
.status-badge.red {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--danger-color);
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--primary-color);
  font-family: var(--font-family);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.text-link-btn:hover {
  text-decoration: underline;
}

/* Patient Details Panel Grid */
.patient-detail-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 2rem;
}

.detail-left-col {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.chart-card {
  padding: 1.5rem;
}

.chart-container {
  height: 250px;
  position: relative;
}

.history-card {
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.history-table-wrapper {
  flex: 1;
  overflow-y: auto;
  max-height: 250px;
  margin-top: 1rem;
}

.history-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history-card th, .history-card td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--panel-border);
  text-align: left;
}

.history-card th {
  color: var(--text-secondary);
}

/* Override Panel Card */
.detail-right-col {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.override-card h4, .profile-card h4 {
  font-size: 1rem;
  margin-bottom: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.override-tip {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 1rem;
}

.override-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.override-form .button-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.override-form button {
  flex: 1;
}

.profile-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.profile-detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.profile-detail-row span {
  color: var(--text-secondary);
}

/* Footer styling */
.app-footer {
  text-align: center;
  padding: 1.5rem;
  background-color: #09090b;
  border-top: 1px solid var(--panel-border);
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: auto;
}

/* Utility Font sizes */
.font-sm {
  font-size: 0.85rem;
}
.font-xs {
  font-size: 0.75rem;
}

/* ============================================== */
/* CHAT / MESSAGING SYSTEM STYLES                */
/* ============================================== */

/* Chat FAB Button (Patient) */
.chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary-color);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 4px 20px var(--primary-glow);
  z-index: 200;
  transition: all var(--transition-speed);
}

.chat-fab:hover {
  transform: scale(1.1);
  background: var(--primary-hover);
}

.chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger-color);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 0 8px var(--danger-glow);
  border: 2px solid var(--bg-color);
}

/* Chat Overlay (Patient - Modal) */
.chat-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.chat-overlay.active {
  display: flex;
}

.chat-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 800px;
  height: 80vh;
  max-height: 700px;
  padding: 0;
  overflow: hidden;
  animation: modalPop 0.3s ease-out;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.chat-header h4 {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: background var(--transition-speed);
}

.chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.chat-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Conversations Sidebar */
.chat-conversations {
  width: 280px;
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.15);
}

.chat-conversations-header {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  border-bottom: 1px solid var(--panel-border);
}

.chat-conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0;
}

.chat-conversation-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.chat-start-cta {
  text-align: center;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.chat-conversation-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background var(--transition-speed);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.chat-conversation-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-conversation-item.active {
  background: rgba(99, 102, 241, 0.1);
  border-left: 3px solid var(--primary-color);
}

.chat-conversation-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-color);
  font-size: 1rem;
  flex-shrink: 0;
}

.chat-conversation-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.chat-conversation-name {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.chat-conversation-name strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-conversation-time {
  font-size: 0.65rem;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.chat-conversation-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-conversation-preview span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Unread Badge */
.chat-unread-badge {
  background: var(--danger-color);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  margin-left: 0.4rem;
  flex-shrink: 0;
}

/* Messages Panel */
.chat-messages-panel,
.clinician-chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-messages-header,
.clinician-chat-messages-header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.chat-messages-body,
.clinician-chat-messages-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 3rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin: auto;
}

.chat-empty-state i {
  font-size: 3rem;
  opacity: 0.3;
}

.chat-empty-state p {
  font-size: 0.9rem;
}

/* Message Bubbles */
.chat-message-row {
  display: flex;
  margin-bottom: 0.25rem;
}

.chat-message-row.mine {
  justify-content: flex-end;
}

.chat-message-row.other {
  justify-content: flex-start;
}

.chat-message-bubble {
  max-width: 75%;
  padding: 0.6rem 1rem;
  border-radius: 18px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-message-bubble.mine {
  background: var(--primary-color);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-message-bubble.other {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-message-text {
  margin-bottom: 0.15rem;
}

.chat-message-time {
  font-size: 0.6rem;
  opacity: 0.7;
  text-align: right;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

/* Chat Input Area */
.chat-input-area,
.clinician-chat-input-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.chat-input-area input,
.clinician-chat-input-area input {
  flex: 1;
  padding: 0.65rem 1rem;
  border-radius: 24px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-family: var(--font-family);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition-speed);
}

.chat-input-area input:focus,
.clinician-chat-input-area input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 5px var(--primary-glow);
}

.chat-input-area button,
.clinician-chat-input-area button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-color);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background var(--transition-speed);
  flex-shrink: 0;
}

.chat-input-area button:hover,
.clinician-chat-input-area button:hover {
  background: var(--primary-hover);
}

/* Clinician Chat Layout */
.clinician-chat-layout {
  display: flex;
  height: calc(100vh - 280px);
  min-height: 400px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  overflow: hidden;
}

.clinician-chat-conversations {
  width: 260px;
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.clinician-chat-conversations .chat-conversation-list {
  flex: 1;
  overflow-y: auto;
}

/* Chat conversation list in clinician sidebar */
.clinician-version {
  max-height: none;
}

/* Scrollbar for chat elements */
.chat-conversation-list::-webkit-scrollbar,
.chat-messages-body::-webkit-scrollbar,
.clinician-chat-messages-body::-webkit-scrollbar,
.clinician-chat-conversations .chat-conversation-list::-webkit-scrollbar {
  width: 4px;
}

.chat-conversation-list::-webkit-scrollbar-track,
.chat-messages-body::-webkit-scrollbar-track,
.clinician-chat-messages-body::-webkit-scrollbar-track,
.clinician-chat-conversations .chat-conversation-list::-webkit-scrollbar-track {
  background: transparent;
}

.chat-conversation-list::-webkit-scrollbar-thumb,
.chat-messages-body::-webkit-scrollbar-thumb,
.clinician-chat-messages-body::-webkit-scrollbar-thumb,
.clinician-chat-conversations .chat-conversation-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* Responsive Chat */
@media (max-width: 768px) {
  .chat-body {
    flex-direction: column;
  }
  .chat-conversations {
    width: 100%;
    max-height: 40%;
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
  }
  .clinician-chat-layout {
    flex-direction: column;
    height: auto;
  }
  .clinician-chat-conversations {
    width: 100%;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
  }
  .chat-container {
    height: 90vh;
    max-height: none;
  }
}

/* ============================================== */
/* RESPONSIVE MEDIA QUERIES                       */
/* ============================================== */

/* Medium Screens (Tablets & Smaller Laptops) */
@media (max-width: 1024px) {
  .main-container {
    max-width: 95%;
    padding: 1.5rem;
  }
  
  .dashboard-layout {
    grid-template-columns: minmax(0, 280px) minmax(0, 1fr);
    gap: 1.5rem;
  }
  
  .patient-detail-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

/* Small Screens (Mobile Viewports) */
@media (max-width: 768px) {
  .app-header {
    padding: 1rem;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    position: relative;
  }
  
  .logo {
    justify-content: center;
    font-size: 1.3rem; /* slightly smaller on mobile */
  }
  
  .nav-controls {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
  }
  
  /* Header auth controls (role badge + Logout).
     JS toggles inline style display:block/none, which would beat plain CSS
     rules — target the visible state only, and let inline "none" keep hiding. */
  #header-auth-controls[style*="block"] {
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    margin-top: 0.4rem;
  }

  /* Role badge: inline margin-right is overridden inline by HTML style attr */
  #header-user-role {
    margin-right: 0 !important;
    white-space: nowrap;
    font-size: 0.7rem;
  }

  #btn-logout-header {
    padding: 0.45rem 0.9rem !important;
    font-size: 0.78rem !important;
    white-space: nowrap;
  }

  /* Language selector sits as its own tidy centered pill row */
  .lang-selector {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    margin-bottom: 0.3rem;
  }

  .lang-selector, .portal-toggle {
    width: auto;
    justify-content: center;
  }
  
  .toggle-btn {
    justify-content: center;
  }
  
  .main-container {
    padding: 0;
    max-width: 100%;
  }

  /* Fix Panel Headers and Search Box */
  .panel-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }
  
  .search-box {
    width: 100%;
  }

  /* Fix Patient Detail header override (keep flex-start for title) */
  #panel-patient-detail .panel-header {
    align-items: flex-start;
  }
  #panel-patient-detail .panel-header h2 {
    font-size: 1.4rem;
  }

  /* Fix Patient info summary squishing */
  .patient-info-summary {
    flex-direction: column;
    gap: 0.5rem !important;
  }
  
  /* Full-bleed Patient Portal for a native app feel */
  #patient-portal {
    width: 100%;
    margin: 0;
    padding: 0;
  }
  
  .phone-frame {
    width: 100%;
    max-width: 100%;
    height: calc(100vh - 140px); /* Viewport minus headers on mobile */
    min-height: 500px;
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
  
  .phone-notch {
    display: none;
  }
  
  .phone-screen {
    padding: 1.2rem;
  }
  
  /* Clinician Dashboard responsive layout stacking */
  .dashboard-layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 1rem;
  }
  
  .clinician-stats-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
  }
  
  /* Adaptive Table Layout: Convert ALL tables to cards on Mobile.
     Generic transform applies everywhere; per-panel label rules below give
     each table its own correct field names. */
  .table-container {
    overflow-x: hidden;
  }

  .patient-table, .patient-table thead, .patient-table tbody, .patient-table th, .patient-table td, .patient-table tr {
    display: block;
  }

  .patient-table thead tr {
    display: none; /* Hide header row */
  }

  .patient-table tr {
    margin-bottom: 1rem;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.02);
    padding: 0.5rem;
  }

  .patient-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.75rem 0.5rem;
    white-space: normal; /* allow text wrapping */
    font-size: 0.85rem;
    text-align: right; /* align content to the right */
  }

  .patient-table td:last-child {
    border-bottom: none;
    justify-content: center; /* Center action buttons */
  }

  /* Shared label style */
  .patient-table td:before {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    margin-right: 1rem;
    text-align: left;
    max-width: 45%;
    white-space: normal;
  }
  /* Hide the label where the column IS an action button */
  .patient-table td:last-child:before { content: ""; display: none; }

  /* 1. Clinician — Patient Directory (7 cols) */
  #patients-table-body td:nth-of-type(1):before { content: "Status"; }
  #patients-table-body td:nth-of-type(2):before { content: "Name"; }
  #patients-table-body td:nth-of-type(3):before { content: "Age/Gender"; }
  #patients-table-body td:nth-of-type(4):before { content: "Location"; }
  #patients-table-body td:nth-of-type(5):before { content: "Phone"; }
  #patients-table-body td:nth-of-type(6):before { content: "Adherence"; }

  /* 2. Clinician — Patient Detail session log (4 cols, inside history-card) */
  .history-card table, .history-card thead, .history-card tbody, .history-card th, .history-card td, .history-card tr {
    display: block;
  }
  .history-card thead tr { display: none; }
  .history-card tr {
    margin-bottom: 1rem;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 0.5rem;
  }
  .history-card td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.5rem;
    text-align: right;
  }
  .history-card td:last-child { border-bottom: none; justify-content: center; }
  .history-card td:before {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    margin-right: 1rem;
    text-align: left;
    max-width: 45%;
    white-space: normal;
  }
  .history-card td:nth-of-type(1):before { content: "Date"; }
  .history-card td:nth-of-type(2):before { content: "Prescribed"; }
  .history-card td:nth-of-type(3):before { content: "Actual"; }
  .history-card td:nth-of-type(4):before { content: "Completed"; }

  /* 3. Medical Admin — Clinicians (7 cols) */
  #medadmin-clinicians-table-body td:nth-of-type(1):before { content: "Status"; }
  #medadmin-clinicians-table-body td:nth-of-type(2):before { content: "Name"; }
  #medadmin-clinicians-table-body td:nth-of-type(3):before { content: "Email"; }
  #medadmin-clinicians-table-body td:nth-of-type(4):before { content: "Phone"; }
  #medadmin-clinicians-table-body td:nth-of-type(5):before { content: "Specialty"; }
  #medadmin-clinicians-table-body td:nth-of-type(6):before { content: "Patients"; }

  /* 3. Medical Admin — Patients (6 cols) */
  #medadmin-patients-table-body td:nth-of-type(1):before { content: "Status"; }
  #medadmin-patients-table-body td:nth-of-type(2):before { content: "Name"; }
  #medadmin-patients-table-body td:nth-of-type(3):before { content: "Location"; }
  #medadmin-patients-table-body td:nth-of-type(4):before { content: "Contact"; }
  #medadmin-patients-table-body td:nth-of-type(5):before { content: "Clinician"; }

  /* 4. Super Admin — Accounts (6 cols) */
  #superadmin-accounts-table-body td:nth-of-type(1):before { content: "Status"; }
  #superadmin-accounts-table-body td:nth-of-type(2):before { content: "Name"; }
  #superadmin-accounts-table-body td:nth-of-type(3):before { content: "Role"; }
  #superadmin-accounts-table-body td:nth-of-type(4):before { content: "Contact"; }
  #superadmin-accounts-table-body td:nth-of-type(5):before { content: "Details"; }

  /* 4. Super Admin — Subscriptions (6 cols, last is payment ref, not an action) */
  #superadmin-subscriptions-table-body td:last-child { justify-content: space-between; }
  #superadmin-subscriptions-table-body td:last-child:before { content: "Payment Ref"; display: block; }
  #superadmin-subscriptions-table-body td:nth-of-type(1):before { content: "Clinician"; }
  #superadmin-subscriptions-table-body td:nth-of-type(2):before { content: "Plan"; }
  #superadmin-subscriptions-table-body td:nth-of-type(3):before { content: "Status"; }
  #superadmin-subscriptions-table-body td:nth-of-type(4):before { content: "Start"; }
  #superadmin-subscriptions-table-body td:nth-of-type(5):before { content: "Ends"; }

  /* 4. Super Admin — Assessments (6 cols) */
  #superadmin-assessments-table-body td:nth-of-type(1):before { content: "Date"; }
  #superadmin-assessments-table-body td:nth-of-type(2):before { content: "Facility"; }
  #superadmin-assessments-table-body td:nth-of-type(3):before { content: "Patients"; }
  #superadmin-assessments-table-body td:nth-of-type(4):before { content: "Quote"; }
  #superadmin-assessments-table-body td:nth-of-type(5):before { content: "Status"; }

  /* 4. Super Admin — Audit Logs (5 cols, last is details, not an action) */
  #superadmin-audit-table-body td:last-child { justify-content: space-between; }
  #superadmin-audit-table-body td:last-child:before { content: "Details"; display: block; }
  #superadmin-audit-table-body td:nth-of-type(1):before { content: "Timestamp"; }
  #superadmin-audit-table-body td:nth-of-type(2):before { content: "Actor"; }
  #superadmin-audit-table-body td:nth-of-type(3):before { content: "Action"; }
  #superadmin-audit-table-body td:nth-of-type(4):before { content: "Target"; }

  /* Hide the web footer inside staff portals on mobile (app-like feel) */
  body:has(#clinician-portal.active) .app-footer,
  body:has(#medical-admin-portal.active) .app-footer,
  body:has(#super-admin-portal.active) .app-footer {
    display: none;
  }

  /* Sidebars in staff portals: tighter on mobile */
  .dashboard-sidebar {
    gap: 1rem;
  }
  .sidebar-nav-tabs {
    flex-direction: row !important;
    flex-wrap: wrap;
    gap: 0.5rem !important;
  }
  .sidebar-nav-tabs .toggle-btn {
    flex: 1 1 45%;
    min-width: 0;
  }

  /* Clinician sidebar nav (full-width stacked list on phones) */
  .clinician-nav-tabs {
    padding: 0 1rem !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
  }
  .clinician-nav-tabs button {
    margin-top: 0 !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  /* Touch-friendly tap targets in staff sidebars */
  .dashboard-sidebar .secondary-btn,
  .sidebar-nav-tabs .toggle-btn {
    min-height: 42px;
  }

  /* Never force the 72px collapsed rail on phones: a persisted collapsed
     state must not leave the sidebar unusable. Keep a full-width stacked
     nav and simply re-show the labels/panels that collapse hides. */
  .dashboard-layout:has(.dashboard-sidebar.sidebar-collapsed) {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
  }
  .dashboard-sidebar.sidebar-collapsed .sidebar-greeting > div {
    display: block;
  }
  .dashboard-sidebar.sidebar-collapsed .sidebar-greeting {
    justify-content: flex-start;
  }
  .dashboard-sidebar.sidebar-collapsed .toggle-btn,
  .dashboard-sidebar.sidebar-collapsed .secondary-btn {
    justify-content: center;
  }
  .dashboard-sidebar.sidebar-collapsed .toggle-btn span,
  .dashboard-sidebar.sidebar-collapsed .secondary-btn span:not(.chat-unread-badge) {
    display: inline;
  }
  .dashboard-sidebar.sidebar-collapsed .clinician-stats-grid {
    display: grid;
  }
  .dashboard-sidebar.sidebar-collapsed .alerts-feed-panel,
  .dashboard-sidebar.sidebar-collapsed .analytics-panel {
    display: flex;
  }

  /* Nothing may overflow horizontally inside panels/screens on phones */
  .dashboard-workspace,
  .app-screen {
    overflow-x: hidden;
  }
  .workspace-panel,
  .app-screen-content {
    min-width: 0;
    max-width: 100%;
  }

  /* Modals: full-bleed-ish with internal scroll on small screens */
  .modal-overlay {
    padding: 0;
  }
  .modal-content {
    margin: 0.75rem;
    max-height: calc(100vh - 1.5rem);
    overflow-y: auto;
  }

  /* Workspace content: allow vertical scroll instead of clipping */
  .workspace-panel {
    height: auto;
    overflow: visible;
  }

  /* Panel titles smaller on phones */
  .panel-header h2 {
    font-size: 1.3rem;
  }
}

@media (max-width: 480px) {
  .clinician-stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Safety Monitoring Notice Banner */
.safety-banner {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.12) 0%, rgba(245, 158, 11, 0.12) 50%, rgba(239, 68, 68, 0.12) 100%);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 12px;
  padding: 0.85rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: #fbcfe8;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  line-height: 1.4;
  backdrop-filter: blur(8px);
}

.safety-banner-icon {
  font-size: 1.3rem;
  color: #f59e0b;
  flex-shrink: 0;
}

/* Status Badge Overrides */
.status-badge.suspended {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.status-badge.active-status {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* User Details Modal Styles */
.details-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-color);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 0.3rem;
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.details-grid p {
  margin: 0.3rem 0;
  font-size: 0.95rem;
}

.details-subtable {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.details-subtable th, .details-subtable td {
  padding: 0.6rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.details-subtable th {
  color: var(--text-secondary);
  font-weight: 500;
}

/* Toast notification system */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 400px;
}

.toast {
  padding: 0.85rem 1.25rem;
  border-radius: 10px;
  background: rgba(22, 29, 49, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-family);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: toast-slide-in 0.3s ease-out;
  cursor: pointer;
}

.toast.success { border-left: 4px solid var(--success-color); }
.toast.error { border-left: 4px solid var(--danger-color); }
.toast.warning { border-left: 4px solid var(--warning-color); }
.toast.info { border-left: 4px solid var(--primary-color); }

.toast .toast-icon { font-size: 1.1rem; }
.toast.success .toast-icon { color: var(--success-color); }
.toast.error .toast-icon { color: var(--danger-color); }
.toast.warning .toast-icon { color: var(--warning-color); }
.toast.info .toast-icon { color: var(--primary-color); }

.toast .toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.25rem;
}

@keyframes toast-slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-slide-out {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* ============================================== */
/* LANDING PAGE STYLES                            */
/* ============================================== */

#landing-page {
  display: none;
  width: 100%;
  overflow-x: hidden;
}

#landing-page.active {
  display: block;
}

body:has(#landing-page.active) .app-header {
  display: none;
}

body:has(#landing-page.active) .main-container {
  padding: 0;
  max-width: 100%;
}

body:has(#landing-page.active) .app-footer {
  display: none;
}

/* Landing Navigation */
.landing-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 4rem;
  background: rgba(11, 15, 25, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

.landing-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
}

.landing-logo .wave-logo {
  color: var(--primary-color);
  animation: pulse-wave 2s infinite ease-in-out;
}

.landing-nav-links {
  display: flex;
  gap: 2rem;
}

.landing-nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color var(--transition-speed);
  position: relative;
}

.landing-nav-link:hover,
.landing-nav-link.active {
  color: var(--text-primary);
}

.landing-nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary-color);
  border-radius: 2px;
}

.landing-nav-buttons {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.landing-btn-outline {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-speed);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.landing-btn-outline:hover {
  border-color: var(--primary-color);
  background: rgba(99, 102, 241, 0.1);
  color: #fff;
}

.landing-btn-primary {
  background: var(--primary-color);
  border: none;
  color: #fff;
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-speed);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.landing-btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.landing-btn-lg {
  padding: 0.85rem 2rem;
  font-size: 1rem;
}

/* Hero Section */
.landing-hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6rem 2rem 4rem;
  overflow: hidden;
}

.landing-hero-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
              radial-gradient(ellipse at 20% 80%, rgba(99, 102, 241, 0.05) 0%, transparent 50%);
  pointer-events: none;
}

.landing-hero-content {
  position: relative;
  z-index: 1;
  text-align: center;
  max-width: 800px;
}

.landing-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 0.5rem 1.2rem;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 2rem;
}

.landing-hero-title {
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 1.5rem;
  letter-spacing: -0.02em;
}

.text-gradient {
  background: linear-gradient(135deg, #6366f1, #a78bfa, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.landing-hero-sub {
  font-size: 1.15rem;
  color: var(--text-secondary);
  line-height: 1.7;
  max-width: 640px;
  margin: 0 auto 2rem;
}

.landing-hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 3rem;
}

.landing-hero-stats {
  display: flex;
  gap: 3rem;
  justify-content: center;
}

.hero-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.hero-stat strong {
  font-size: 1.8rem;
  font-weight: 800;
}

.hero-stat span {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* General Landing Sections */
.landing-section {
  padding: 5rem 4rem;
  max-width: 1200px;
  margin: 0 auto;
}

.landing-section-header {
  text-align: center;
  margin-bottom: 3.5rem;
}

.landing-section-tag {
  display: inline-block;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  padding: 0.4rem 1rem;
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary-color);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 1rem;
}

.landing-section-header h2 {
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.landing-section-header p {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.6;
}

/* Features Grid */
.landing-features-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.landing-feature-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 2rem 1.5rem;
  transition: all var(--transition-speed);
}

.landing-feature-card:hover {
  border-color: rgba(99, 102, 241, 0.3);
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.1);
}

.feature-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(99, 102, 241, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: var(--primary-color);
  margin-bottom: 1.2rem;
}

.landing-feature-card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
}

.landing-feature-card p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* How It Works */
.landing-works {
  background: rgba(255, 255, 255, 0.01);
  border-top: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
  max-width: 100%;
  padding: 5rem 4rem;
}

.landing-works .landing-section-header {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

.landing-steps {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  max-width: 700px;
  margin: 0 auto;
}

.landing-step {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  width: 100%;
}

.step-number {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary-color);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.step-content {
  flex: 1;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.step-icon {
  font-size: 1.2rem;
  color: var(--primary-color);
}

.step-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.step-content p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.landing-step-connector {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0;
  color: var(--primary-color);
  font-size: 1rem;
  opacity: 0.5;
  width: 48px;
}

/* Pricing Section */
.landing-pricing-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.landing-pricing-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all var(--transition-speed);
}

.landing-pricing-card:hover {
  border-color: rgba(99, 102, 241, 0.2);
  transform: translateY(-2px);
}

.landing-pricing-card.featured {
  border-color: var(--primary-color);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(99, 102, 241, 0.02));
  transform: scale(1.03);
}

.landing-pricing-card.featured:hover {
  transform: scale(1.03) translateY(-2px);
}

.pricing-badge {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-color);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.35rem 1.2rem;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pricing-header {
  margin-bottom: 1.5rem;
  text-align: center;
}

.pricing-header h3 {
  font-size: 1.3rem;
  font-weight: 700;
}

.pricing-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
}

.pricing-amount {
  text-align: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--panel-border);
}

.pricing-currency {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 600;
  vertical-align: super;
}

.pricing-value {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.pricing-period {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.pricing-features {
  list-style: none;
  padding: 0;
  margin: 0 0 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  flex: 1;
}

.pricing-features li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.pricing-features li i {
  color: var(--success-color);
  font-size: 0.85rem;
  width: 18px;
}

.pricing-btn {
  width: 100%;
  justify-content: center;
  padding: 0.75rem;
}

/* About Section */
.landing-about {
  text-align: center;
  border-top: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
  max-width: 100%;
  padding: 5rem 4rem;
  background: rgba(255, 255, 255, 0.01);
}

.landing-about .landing-section-header {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

.landing-about-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
  max-width: 900px;
  margin: 0 auto;
}

.about-stat-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.about-stat-card i {
  font-size: 1.5rem;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.about-stat-card strong {
  font-size: 1.8rem;
  font-weight: 800;
}

.about-stat-card span {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* CTA Section */
.landing-contact {
  padding: 5rem 4rem;
  max-width: 1200px;
  margin: 0 auto;
}

.landing-cta-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(99, 102, 241, 0.03));
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 24px;
  padding: 4rem 3rem;
  text-align: center;
}

.landing-cta-card h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.landing-cta-card p {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 500px;
  margin: 0 auto 2rem;
  line-height: 1.6;
}

.landing-cta-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.landing-cta-actions a {
  text-decoration: none;
}

/* Footer */
.landing-footer {
  background: rgba(11, 15, 25, 0.95);
  border-top: 1px solid var(--panel-border);
  padding: 3rem 4rem 1.5rem;
}

.landing-footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 3rem;
  margin-bottom: 2rem;
}

.landing-footer-brand {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 280px;
}

.landing-footer-brand .wave-logo {
  color: var(--primary-color);
  font-size: 1.5rem;
}

.landing-footer-brand span {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.landing-footer-brand p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.landing-footer-links {
  display: flex;
  gap: 3rem;
}

.footer-col {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.footer-col h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.footer-col a {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-speed);
}

.footer-col a:hover {
  color: var(--text-primary);
}

.landing-footer-bottom {
  max-width: 1200px;
  margin: 0 auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--panel-border);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ============================================== */
/* TERMS & CONDITIONS STYLES                      */
/* ============================================== */

.terms-checkbox-wrapper {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
}

.terms-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  user-select: none;
}

.terms-checkbox-label input {
  display: none;
}

.terms-checkbox-custom {
  width: 20px;
  height: 20px;
  border: 2px solid var(--panel-border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed);
  flex-shrink: 0;
  background: transparent;
}

.terms-checkbox-label input:checked + .terms-checkbox-custom {
  background: var(--primary-color);
  border-color: var(--primary-color);
}

.terms-checkbox-label input:checked + .terms-checkbox-custom::after {
  content: '\f00c';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 0.7rem;
  color: #fff;
}

.terms-checkbox-label span:last-child {
  line-height: 1.4;
}

.terms-modal-content {
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  text-align: left;
  padding: 2rem;
}

.terms-modal-body {
  flex: 1;
  overflow-y: auto;
  max-height: 50vh;
  padding-right: 0.5rem;
}

.terms-modal-body h5 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--primary-color);
}

.terms-modal-body h6 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 1rem;
  margin-bottom: 0.3rem;
  color: var(--text-primary);
}

.terms-modal-body p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 0.5rem;
}

/* Landing responsive */
@media (max-width: 1024px) {
  .landing-nav {
    padding: 1rem 2rem;
  }
  .landing-nav-links {
    gap: 1rem;
  }
  .landing-hero-title {
    font-size: 2.5rem;
  }
  .landing-features-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .landing-pricing-grid {
    grid-template-columns: 1fr;
    max-width: 400px;
    margin: 0 auto;
  }
  .landing-pricing-card.featured {
    transform: none;
  }
  .landing-pricing-card.featured:hover {
    transform: translateY(-2px);
  }
  .landing-about-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .landing-footer-content {
    flex-direction: column;
    gap: 2rem;
  }
}

@media (max-width: 768px) {
  .landing-nav {
    padding: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .landing-nav-links {
    order: 3;
    width: 100%;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
  }
  .landing-nav-buttons {
    margin-left: auto;
  }
  .landing-hero {
    padding: 5rem 1.5rem 3rem;
  }
  .landing-hero-title {
    font-size: 1.8rem;
  }
  .landing-hero-sub {
    font-size: 0.95rem;
  }
  .landing-hero-stats {
    gap: 1.5rem;
    flex-wrap: wrap;
  }
  .landing-hero-actions {
    flex-direction: column;
    align-items: center;
  }
  .landing-section {
    padding: 3rem 1.5rem;
  }
  .landing-section-header h2 {
    font-size: 1.6rem;
  }
  .landing-features-grid {
    grid-template-columns: 1fr;
  }
  .landing-pricing-grid {
    max-width: 100%;
  }
  .landing-about-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .landing-cta-card {
    padding: 2.5rem 1.5rem;
  }
  .landing-cta-actions {
    flex-direction: column;
    align-items: center;
  }
  .landing-cta-card h2 {
    font-size: 1.5rem;
  }
  .landing-footer {
    padding: 2rem 1.5rem 1rem;
  }
  .landing-footer-links {
    flex-wrap: wrap;
    gap: 1.5rem;
  }
  .landing-works {
    padding: 3rem 1.5rem;
  }
  .landing-about {
    padding: 3rem 1.5rem;
  }
}

/* Loading spinner overlay */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(11, 15, 25, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-overlay.active { display: flex; }

.loading-spinner {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.loading-spinner i {
  font-size: 2rem;
  color: var(--primary-color);
  margin-bottom: 1rem;
}

/* Telemetry / Location Tracking Styles */
.telemetry-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.15);
  color: var(--success-color);
  font-size: 0.9rem;
  animation: telemetry-pulse 2s infinite ease-in-out;
}

@keyframes telemetry-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

/* Location Consent Banner */
.location-consent-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 12px;
  font-size: 0.85rem;
}
.location-consent-icon {
  font-size: 1.5rem;
  color: var(--warning-color);
  flex-shrink: 0;
}
.location-consent-text {
  flex: 1;
  min-width: 0;
}
.location-consent-text strong {
  display: block;
  color: var(--warning-color);
  margin-bottom: 0.15rem;
}
.location-consent-text p {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.4;
}

.location-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.5rem;
}

.location-map-section {
  display: flex;
  flex-direction: column;
}

.location-info-section {
  display: flex;
  flex-direction: column;
}

.location-info-card {
  flex: 1;
}

.location-info-card h4 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 0.5rem;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 0.85rem;
}

.info-row:last-child {
  border-bottom: none;
}

.info-row span {
  color: var(--text-secondary);
}

.info-row strong {
  font-weight: 600;
}

@media (max-width: 768px) {
  .location-layout {
    grid-template-columns: 1fr;
  }
}

/* ---- Fix quality badge ----
   A confidence indicator has to be unmissable: this is the difference between
   "the patient is at this house" and "the patient is somewhere in this area".
   Emergency responders read the badge, not the grey precision text. */
.fix-quality-row { margin: 0.45rem 0 0.35rem; }

.fix-quality {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: help;
}
.fix-quality i { font-size: 0.7rem; }

.fix-quality.q-excellent {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.45);
}
.fix-quality.q-good {
  background: rgba(59, 130, 246, 0.16);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.4);
}
.fix-quality.q-fair {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.45);
}
.fix-quality.q-poor {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.55);
}
.fix-quality.q-unknown {
  background: rgba(148, 163, 184, 0.16);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.4);
}

/* Accounts search — filtering by name/role/ID without leaving the board */
.track-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-top: 0.7rem;
}
.track-search-wrap > i {
  position: absolute;
  left: 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  pointer-events: none;
}
.track-search {
  width: 100%;
  padding: 0.6rem 2.1rem 0.6rem 2.1rem;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s ease;
}
.track-search:focus {
  border-color: var(--primary-color);
}
.track-search::placeholder { color: var(--text-secondary); }
.track-search::-webkit-search-cancel-button { display: none; }

.track-search-clear {
  position: absolute;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}
.track-search-clear:hover { color: var(--text-primary); }
.track-search-wrap.has-query .track-search-clear { display: inline-flex; }

/* Empty state when a search matches nothing */
.track-empty {
  padding: 1.4rem 0.8rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.5;
}
.track-empty strong { color: var(--text-primary); }

/* Highlight the matched substring so the operator sees why a row matched */
.track-item mark {
  background: rgba(99, 102, 241, 0.32);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

/* ---- Live Tracking board ---- */
/* Dashboard-grade: the map IS the screen. Taller than before and free to go
   wheel-to-wheel when the accounts side panel is collapsed. */
.track-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1.1rem;
  align-items: stretch;
}

.track-layout.side-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.track-layout.side-collapsed .location-info-card {
  display: none;
}

/* Full-height map: fills the console between the panel header and the page
   footer; on small windows the min keeps it comfortably zoomable. */
.track-map {
  width: 100%;
  height: calc(100vh - 240px);
  min-height: 480px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  z-index: 1;
  overscroll-behavior: contain;
}

.track-map .maplibregl-canvas {
  touch-action: none;
  outline: none;
}

/* Detail card must never fight the pins for the pointer. MapLibre popups are
   non-interactive by content by default; force the card above cluster labels
   and markers and make it firmly hover/click-safe. */
.maplibregl-popup {
  z-index: 9500 !important;
  pointer-events: auto !important;
}
.maplibregl-popup-content {
  pointer-events: auto;
  min-width: 230px;
  max-width: min(90vw, 320px);
  border-radius: 12px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
}
.track-popup .maplibregl-popup-content a.gnav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.7rem;
}

/* Accounts side panel: head row with collapse handle */
.track-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.track-side-head h4 { margin: 0; }

.track-side-toggle {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  min-width: 34px;
  cursor: pointer;
  justify-content: center;
  display: inline-flex;
  align-items: center;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.track-side-toggle:hover {
  color: var(--text-primary);
  border-color: var(--primary-color);
}

/* Floating re-open chip after the panel is collapsed */
.track-side-expand {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 40;
  background: var(--panel-bg);
  color: var(--text-primary);
  border: 1px solid var(--primary-color);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.78rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.track-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: calc(100vh - 330px);
  min-height: 200px;
  overflow-y: auto;
  margin-top: 0.6rem;
  padding-right: 0.2rem;
}

.track-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color var(--transition-speed), background var(--transition-speed);
}

.track-item:hover {
  border-color: var(--primary-color);
}

.track-item.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary-color);
}

.track-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--success-color);
  flex-shrink: 0;
}
.track-dot.stale { background: var(--warning-color); }
.track-dot.off { background: var(--text-secondary); opacity: 0.45; }

.track-item .t-name {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-item .t-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Unique pin badges: initials disc, role-colored ring */
.track-pin-badge { background: transparent; border: none; }
.track-pin {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 2.5px solid var(--primary-color);
  background: rgba(11, 15, 25, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}
.track-pin:hover {
  transform: scale(1.15);
  box-shadow: 0 3px 14px rgba(99, 102, 241, 0.6);
}
.leaflet-div-icon.track-pin-badge { border: none; }
.maplibregl-popup-content { color: #0b0f19; }
.track-pin .geo-name strong { color: var(--primary-color); }

/* On-map label under each pin: NAME + precise address, readable at any zoom */
.track-pin-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  pointer-events: auto;
}
.pin-label {
  margin-top: 3px;
  background: rgba(11, 15, 25, 0.85);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 2px 6px;
  text-align: center;
  max-width: 170px;
  line-height: 1.25;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.pin-label strong {
  display: block;
  font-size: 0.72rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pin-label .pin-addr {
  display: block;
  font-size: 0.63rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Google Maps navigation deep-link inside pin popups */
.gnav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  background: var(--primary-color);
  color: #fff !important;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
}
.gnav-link:hover { filter: brightness(1.15); }

/* "Show everyone" chip while a person is isolated */
.showall-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.6rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--primary-color);
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary-color);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-family);
}
.showall-chip:hover { background: rgba(99, 102, 241, 0.3); }

/* Optional online imagery toggle (top-right of the map) */
.track-layer-toggle {
  display: flex;
  gap: 0.3rem;
  z-index: 500;
}

.track-toggle-btn {
  background: rgba(11, 15, 25, 0.85);
  color: #e2e8f0;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-family);
  transition: background var(--transition-speed), border-color var(--transition-speed);
}
.track-toggle-btn:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}
.track-toggle-btn.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: #fff;
}

/* Visual cue when online imagery is active */
.track-map.online-imagery .track-toggle-btn {
  border-color: var(--primary-color);
}

@media (max-width: 900px) {
  .track-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .track-map {
    height: 68vh;
  }
  .track-list {
    max-height: 260px;
  }
}

/* ============================================== */
/* NEEDS ASSESSMENT STYLES                       */
/* ============================================== */

.na-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 1.5rem;
  padding: 0.5rem 0;
}

.na-step {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition-speed);
  flex-shrink: 0;
}

.na-step.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: #fff;
  box-shadow: 0 0 8px var(--primary-glow);
}

.na-step.completed {
  background: var(--success-color);
  border-color: var(--success-color);
  color: #fff;
}

.na-step-connector {
  width: 30px;
  height: 2px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0 4px;
}

.na-step-content {
  display: none;
}

.na-step-content.active {
  display: block;
  animation: fadeIn 0.3s ease-in-out;
}

/* Quote Display */
.quote-display {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(99, 102, 241, 0.05));
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
  margin: 1rem 0;
}

.quote-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.quote-amount {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary-color);
  text-shadow: 0 0 20px var(--primary-glow);
}

/* ============================================== */
/* SUBSCRIPTION PLAN CARDS                       */
/* ============================================== */

.sub-plans-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.sub-plan-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  transition: all var(--transition-speed);
  position: relative;
}

.sub-plan-card:hover {
  border-color: rgba(99, 102, 241, 0.3);
  transform: translateY(-2px);
}

.sub-plan-card.featured {
  border-color: var(--primary-color);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(99, 102, 241, 0.02));
}

.sub-plan-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.sub-plan-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.sub-plan-price {
  text-align: center;
  padding: 1rem 0;
  border-top: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
  margin-bottom: 1rem;
}

.sub-plan-currency {
  font-size: 0.85rem;
  color: var(--text-secondary);
  vertical-align: super;
}

.sub-plan-value {
  font-size: 2rem;
  font-weight: 800;
}

.sub-plan-period {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.sub-plan-features {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sub-plan-features li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.sub-plan-features li i {
  color: var(--success-color);
  font-size: 0.8rem;
  width: 16px;
}

.sub-plan-btn {
  width: 100%;
  justify-content: center;
}

@media (max-width: 768px) {
  .sub-plans-grid {
    grid-template-columns: 1fr;
  }
  .na-progress {
    gap: 0;
  }
  .na-step-connector {
    width: 15px;
  }
  #na-features-checkboxes {
    grid-template-columns: 1fr;
  }
}

/* Assessment Detail */
.assessment-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.assessment-detail-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.assessment-detail-item span:first-child {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.assessment-detail-item strong {
  font-size: 0.95rem;
}

/* ============================================== */
/* SUBSCRIPTION GATE OVERLAY                      */
/* ============================================== */

.subscription-gate-overlay {
  background: rgba(11, 15, 25, 0.92);
  backdrop-filter: blur(8px);
  z-index: 10000;
}

.subscription-gate-content {
  max-width: 440px;
  width: 100%;
  padding: 2.5rem 2rem;
  text-align: center;
}

.subscription-gate-icon {
  font-size: 3rem;
  color: var(--primary-color);
  margin-bottom: 1rem;
  filter: drop-shadow(0 0 12px var(--primary-glow));
}

.subscription-gate-content h4 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.subscription-gate-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.subscription-gate-features {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  text-align: left;
}

.sub-gate-feature {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.sub-gate-feature i {
  color: var(--success-color);
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

.subscription-gate-note {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.75rem;
}

/* ============================================== */
/* TRIAL BANNER                                    */
/* ============================================== */

.trial-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  animation: fadeIn 0.3s ease-in-out;
  gap: 0.75rem;
}

.trial-banner-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.trial-banner-content i {
  font-size: 1rem;
}

.trial-banner-green {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
}

.trial-banner-yellow {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fcd34d;
}

.trial-banner-red {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.trial-banner-grandfathered {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
}

.trial-banner-dismiss {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem;
  border-radius: 4px;
  transition: all var(--transition-speed);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.trial-banner-dismiss:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

/* ============================================== */
/* ACCOUNT CREATION IN NEEDS ASSESSMENT           */
/* ============================================== */

#na-account-creation {
  border-top: 1px solid var(--panel-border);
}

#na-account-creation h5 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ============================================== */
/* BILLING INFO FORM                              */
/* ============================================== */

.sub-billing-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--panel-border);
}

.sub-billing-section h4 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary-color);
}

.sub-billing-note {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.billing-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 600px;
}

.billing-form .switch-row {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

/* ----------------------------------------------------
   SESSION NAVIGATION HISTORY (backlinks under header)
   ---------------------------------------------------- */
.nav-history-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 2rem;
  background: rgba(11, 15, 25, 0.75);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  z-index: 90;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: thin;
}

.nav-history-bar::-webkit-scrollbar { height: 4px; }
.nav-history-bar::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 4px; }

.nav-history-lead {
  color: var(--text-secondary);
  font-size: 0.8rem;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  padding-right: 0.25rem;
  border-right: 1px solid var(--panel-border);
}

.nav-history-trail {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex: 0 0 auto;
}

.nav-history-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.28);
  color: var(--text-primary);
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-speed), border-color var(--transition-speed);
  font-family: var(--font-family);
}

.nav-history-chip:hover {
  background: rgba(99, 102, 241, 0.26);
  border-color: var(--primary-color);
}

.nav-history-chip.current {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: #fff;
  cursor: default;
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.nav-history-chip i { font-size: 0.7rem; opacity: 0.9; }

.nav-history-sep {
  color: var(--text-secondary);
  font-size: 0.65rem;
  opacity: 0.6;
  flex: 0 0 auto;
  padding: 0 0.1rem;
}

@media (max-width: 640px) {
  .nav-history-bar { padding: 0.4rem 0.75rem; }
  .nav-history-chip {
    font-size: 0.7rem;
    padding: 0.3rem 0.6rem;
    min-height: 30px; /* respectable touch target for history chips */
  }
}

/* ====================================================================
   NATIVE ANDROID SHELL ONLY (html.mobitens-native)
   ====================================================================
   The Compose/WebView shell adds class "mobitens-native" to the document
   element at document-start. Everything below is scoped to it, so the
   browser build (mobitens.vercel.app) stays pixel-identical.

   The shell supplies its own Material 3 top app bar ("MobiTENS", back
   arrow, sign-out) and handles all screen insets itself — therefore we
   deliberately DO NOT add top paddings/margins to compensate.

   1) Opaque dark background chain — the WebView surface is opaque dark
      (#FF0B0F19) and html/body may never be transparent again. All
      translucent panel surfaces become solid dark so light text can
      NEVER resolve against a light background again.
   2) Decorative brand/watermark marks (the stylized pulse/X wave logo
      and company header chrome) never render inside the app, and can
      therefore never overlap the dashboard stat cards.
   3) Stat-card labels/values get guaranteed contrast on their cards.
   4) The user chip (avatar + name + facility + "<" collapse button)
      stays visible but gets readable colors and clean alignment, with
      a reserved slot so the floating "<" button can never overlap text
      or the cards below it.
   5) Mobile-first ergonomics: 48px thumb targets in the sidebar,
      stacked stat cards, bottom-anchored toasts (a fixed top toast
      would sit exactly over the full-width "Total Patients" card). */

/* ---- 0. Root: dark scheme + SOLID panel surfaces ------------------- */
html.mobitens-native {
  background-color: var(--bg-color);
  color: var(--text-primary);
}
html.mobitens-native body {
  background-color: var(--bg-color);
  color: var(--text-primary);
}

/* --panel-bg is rgba(22, 29, 49, 0.7) in the browser build. Composite
   of that translucent tint over the page's own #0b0f19 is #131929 —
   the exact same surface color, but opaque. Any light text that sat on
   a translucent panel now sits on solid dark, whatever is behind. */
html.mobitens-native {
  --panel-bg: #131929;
}

html.mobitens-native .main-container,
html.mobitens-native .portal-section,
html.mobitens-native .portal-section.active,
html.mobitens-native .dashboard-layout,
html.mobitens-native .dashboard-sidebar,
html.mobitens-native .dashboard-workspace,
html.mobitens-native .workspace-panel,
html.mobitens-native .alerts-feed-panel,
html.mobitens-native .analytics-panel,
html.mobitens-native .metric-card,
html.mobitens-native .glass-panel,
html.mobitens-native .table-container {
  background-color: var(--bg-color);
}
html.mobitens-native .glass-panel,
html.mobitens-native .metric-card,
html.mobitens-native .alerts-feed-panel,
html.mobitens-native .analytics-panel {
  background-color: var(--panel-bg);
}

/* ---- 1. Shell chrome is replaced natively: defense-in-depth mirrors.
        The wave logo is the ONLY "stylized pulse/X" brand mark on the
        page — it must never paint inside the app (it was the element
        seen floating over the TOTAL PATIENTS stat card). */
html.mobitens-native .app-header,
html.mobitens-native #nav-history-bar,
html.mobitens-native #header-auth-controls,
html.mobitens-native #landing-page,
html.mobitens-native footer,
html.mobitens-native .app-footer,
html.mobitens-native .site-footer,
html.mobitens-native #site-footer,
html.mobitens-native .logo,
html.mobitens-native .wave-logo {
  display: none !important;
}

/* ---- 2. Dashboard decorations: nothing may overlay the stat cards */
html.mobitens-native .dashboard-sidebar::before,
html.mobitens-native .dashboard-sidebar::after,
html.mobitens-native .dashboard-layout::before,
html.mobitens-native .dashboard-layout::after,
html.mobitens-native .clinician-stats-grid::before,
html.mobitens-native .clinician-stats-grid::after {
  content: none !important;
}
/* Stat cards get their own stacking slot, above any neutral
   decorative sibling that could ever be introduced. */
html.mobitens-native .clinician-stats-grid,
html.mobitens-native .clinician-stats-grid .metric-card {
  position: relative;
  z-index: 1;
}

/* ---- 3. Stat cards: readable labels, tight but comfortable padding */
html.mobitens-native .metric-card {
  padding: 1rem 1.1rem;
  border-radius: 12px;
}
html.mobitens-native .metric-lbl {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.4px;
  line-height: 1.3;
}
html.mobitens-native .metric-val {
  color: var(--text-primary);
  font-size: 1.6rem;
  line-height: 1.2;
  margin-top: 0.35rem;
}
/* Themed values keep their accent colors (unreadable nowhere: solid
   dark surface beneath), but the themed CARD body stays normal. */

/* ---- 4. User chip: readable, aligned, with a reserved slot for the
        floating "<" collapse button so nothing overlaps */
html.mobitens-native .sidebar-greeting {
  align-items: center;
  gap: 0.9rem;
  padding-right: 3.6rem; /* reserved slot for the 48px collapse button */
  min-height: 48px;
}
html.mobitens-native .doctor-avatar {
  flex-shrink: 0;
  color: var(--primary-color);
}
html.mobitens-native .sidebar-greeting > div {
  min-width: 0;
}
html.mobitens-native .sidebar-greeting h3 {
  color: var(--text-primary);
  font-size: 1.05rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
}
html.mobitens-native .sidebar-greeting h3 span,
html.mobitens-native .sidebar-greeting > div > span,
html.mobitens-native #clinician-facility-display {
  display: block;
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.3;
}
/* Sidebar headings (Real-time Alerts / Practice Analytics) too */
html.mobitens-native .alerts-feed-panel h4,
html.mobitens-native .analytics-panel h4 {
  color: var(--text-primary);
}

/* Native keeps the web "<" collapse button — make the hit target
   comfortable and keep it pinned inside the reserved sidebar slot.
   48px box + background-clip on the padding box = 44px visual circle
   with a full 48px touch target. */
html.mobitens-native .sidebar-collapse-btn {
  top: 0.5rem;
  right: 0.5rem;
  width: 48px;
  height: 48px;
  font-size: 0.95rem;
  background: rgba(99, 102, 241, 0.18);
  background-clip: padding-box;
  border: 2px solid transparent; /* visual circle 44px, hit target 48px */
  color: var(--text-primary);
}

/* ---- 5. Sidebar nav: >=48px thumb targets (Users/Settings/Messages/
        Subscription/Subscription tabs) */
html.mobitens-native .dashboard-sidebar .secondary-btn,
html.mobitens-native .dashboard-sidebar .toggle-btn {
  min-height: 48px;
}

/* ---- 6. Toasts anchor to the bottom in the app: a fixed top-right
        toast lands exactly on the full-width "Total Patients" card at
        phone widths (another source of overlap). */
html.mobitens-native #toast-container {
  top: auto;
  right: 0.75rem;
  left: 0.75rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  max-width: none;
  align-items: stretch;
}

/* ---- 7. Mobile-first rhythm inside the app shell (no horizontal
        scroll, full-width stacks, no double title below the app bar) */
@media (max-width: 768px) {
  html.mobitens-native .main-container {
    padding: 1rem 0.85rem;
  }
  html.mobitens-native .dashboard-layout {
    padding: 0;
    gap: 1rem;
    min-height: auto;
  }
  html.mobitens-native .clinician-nav-tabs button {
    width: 100%;
  }
}
@media (max-width: 480px) {
  /* Stat cards stack full-width on phones (already 1fr in the base
     build; keep it so the native shell can never regress). */
  html.mobitens-native .clinician-stats-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}
