/**
 * MediCare AI — Personal Health AI OS (VIP Pro V3 Rebuild)
 * Architecture: Slim Navigation Rail + Expansive Workspace + Contextual Off-Canvas Drawers + Floating Glass Composer
 */

@import url("theme.css");

/* ==========================================================================
   1. RESET & UNIVERSAL BASE
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  width: 100%;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-l0, #f8fafc);
  color: var(--text-primary, #0f172a);
  overflow-x: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a, a:visited {
  color: inherit;
  text-decoration: none;
  transition: color var(--motion-fast, 180ms ease);
}

a:hover {
  color: var(--accent-primary, #0d9488);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button, input[type="button"], input[type="submit"], input[type="reset"] {
  cursor: pointer;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   2. MEDICAL DESIGN TOKENS & BACKWARD COMPATIBILITY
   ========================================================================== */
:root {
  /* Legacy & Phase 6/7 Contracts */
  --green: #0d9488;
  --green-2: #0f766e;
  --green-soft: #ccfbf1;
  --green-pale: #f0fdfa;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.08);
  --page: #f8fafc;
  --card: #ffffff;
  --danger: #ef4444;
  --shadow: 0 16px 44px rgba(15, 23, 42, 0.06);

  --med-primary: #0d9488;
  --med-primary-hover: #0f766e;
  --med-primary-light: #f0fdfa;
  --med-primary-border: #ccfbf1;
  --med-primary-text: #115e59;
  
  --med-bg-page: #f8fafc;
  --med-bg-card: #ffffff;
  --med-bg-sidebar: #ffffff;
  --med-bg-input: #ffffff;
  --med-text-main: #0f172a;
  --med-text-muted: #64748b;
  --med-border: rgba(15, 23, 42, 0.08);
  --med-border-subtle: rgba(15, 23, 42, 0.05);

  --med-emergency-bg: #fef2f2;
  --med-emergency-border: #fca5a5;
  --med-emergency-text: #991b1b;
  --med-emergency-btn: #dc2626;
  --med-emergency-btn-hover: #b91c1c;

  --med-urgent-bg: #fffbeb;
  --med-urgent-border: #fcd34d;
  --med-urgent-text: #92400e;

  --med-caution-bg: #fefce8;
  --med-caution-border: #fef08a;
  --med-caution-text: #854d0e;

  --nav-rail-width: 76px;
  --topbar-height: 64px;
  --drawer-width: 340px;
}

html[data-theme="dark"], body.dark {
  --green: #14b8a6;
  --green-2: #0d9488;
  --green-soft: rgba(20, 184, 166, 0.16);
  --green-pale: rgba(20, 184, 166, 0.08);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.09);
  --page: #070b12;
  --card: #0d1424;
  --danger: #f87171;
  --shadow: 0 16px 44px rgba(0, 0, 0, 0.4);

  --med-primary: #14b8a6;
  --med-primary-hover: #2dd4bf;
  --med-primary-light: rgba(20, 184, 166, 0.14);
  --med-primary-border: rgba(20, 184, 166, 0.28);
  --med-primary-text: #5eead4;
  
  --med-bg-page: #070b12;
  --med-bg-card: #0d1424;
  --med-bg-sidebar: #0d1424;
  --med-bg-input: #131d31;
  --med-text-main: #f1f5f9;
  --med-text-muted: #94a3b8;
  --med-border: rgba(255, 255, 255, 0.09);
  --med-border-subtle: rgba(255, 255, 255, 0.05);

  --med-emergency-bg: rgba(239, 68, 68, 0.14);
  --med-emergency-border: rgba(239, 68, 68, 0.32);
  --med-emergency-text: #fca5a5;

  --med-urgent-bg: rgba(245, 158, 11, 0.14);
  --med-urgent-border: rgba(245, 158, 11, 0.32);
  --med-urgent-text: #fcd34d;

  --med-caution-bg: rgba(234, 179, 8, 0.14);
  --med-caution-border: rgba(234, 179, 8, 0.32);
  --med-caution-text: #fef08a;
}

/* ==========================================================================
   3. APP ARCHITECTURE: SLIM NAVIGATION RAIL (DESKTOP)
   ========================================================================== */
.app-nav-rail {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--nav-rail-width, 76px);
  z-index: 100;
  background: var(--bg-l1, #ffffff);
  border-right: 1px solid var(--border-subtle, rgba(15, 23, 42, 0.08));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 18px;
  gap: 12px;
  user-select: none;
}

.rail-brand {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-primary, #0d9488), #0f766e);
  color: #ffffff;
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(13, 148, 136, 0.28);
  transition: transform var(--motion-fast), box-shadow var(--motion-fast);
  margin-bottom: 8px;
}
.rail-brand:hover {
  transform: scale(1.05);
  box-shadow: 0 10px 24px rgba(13, 148, 136, 0.36);
}

.rail-menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.rail-item {
  position: relative;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--text-secondary, #64748b);
  background: transparent;
  transition: all var(--motion-fast);
  text-decoration: none;
}
.rail-item:hover {
  color: var(--accent-primary, #0d9488);
  background: var(--accent-light, #ccfbf1);
}
.rail-item.active {
  color: #ffffff;
  background: var(--accent-primary, #0d9488);
  box-shadow: 0 6px 16px rgba(13, 148, 136, 0.32);
}
.rail-label {
  display: none;
}

/* Tooltip for rail item */
.rail-item[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 62px;
  top: 50%;
  transform: translateY(-50%) scale(0.95);
  padding: 6px 11px;
  border-radius: 8px;
  background: #0f172a;
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  box-shadow: var(--shadow-md);
  transition: opacity var(--motion-fast), transform var(--motion-fast);
  z-index: 100;
}
.rail-item[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

.rail-divider {
  width: 36px;
  height: 1px;
  background: var(--border-subtle, rgba(15, 23, 42, 0.08));
  margin: 6px 0;
}

.rail-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: auto;
}

.rail-user-avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 4px 10px rgba(13, 148, 136, 0.22);
}

/* ==========================================================================
   4. TOP CONTEXT BAR (PERSONAL HEALTH OS HEADER)
   ========================================================================== */
.topbar.os-topbar {
  position: sticky;
  top: 0;
  margin-left: var(--nav-rail-width, 76px);
  width: calc(100% - var(--nav-rail-width, 76px));
  height: var(--topbar-height, 64px);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--glass-panel, rgba(255, 255, 255, 0.85));
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle, rgba(15, 23, 42, 0.08));
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand.os-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent-light, #ccfbf1);
  color: var(--accent-primary, #0d9488);
  font-size: 22px;
  font-weight: 900;
}
.brand strong {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.brand em {
  color: var(--accent-primary, #0d9488);
  font-style: normal;
}
.brand small {
  display: block;
  font-size: 10px;
  color: var(--text-secondary, #64748b);
}

.topbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-control-wrap {
  position: relative;
}

.os-profile-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 14px 6px 8px;
  border-radius: 9999px;
  border: 1px solid var(--border-strong, rgba(15, 23, 42, 0.12));
  background: var(--bg-l1, #ffffff);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: all var(--motion-fast);
}
.os-profile-chip:hover {
  border-color: var(--accent-primary, #0d9488);
  background: var(--accent-light, #ccfbf1);
}
.os-profile-chip .mini-avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-primary, #0d9488);
  color: #ffffff;
  font-weight: 700;
  font-size: 11px;
}
.profile-chip-text {
  display: flex;
  flex-direction: column;
  text-align: left;
  line-height: 1.15;
}
.profile-chip-text small {
  font-size: 9px;
  color: var(--text-secondary, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.profile-chip-text strong {
  font-size: 12px;
  color: var(--text-primary, #0f172a);
}
.chevron-svg {
  color: var(--text-secondary, #64748b);
}

.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  max-height: 320px;
  overflow-y: auto;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l1, #ffffff);
  box-shadow: var(--shadow-xl);
  padding: 8px;
  z-index: 120;
}
.profile-menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  text-align: left;
}
.profile-menu button:hover {
  background: var(--accent-light);
  color: var(--accent-primary);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.back-overview {
  padding: 8px 14px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l1, #ffffff);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.back-overview:hover {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l1, #ffffff);
  color: var(--text-secondary);
  font-size: 16px;
  position: relative;
  transition: all var(--motion-fast);
}
.icon-button:hover {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}
.icon-button b {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--status-emergency, #ef4444);
  color: #ffffff;
  font-size: 9px;
  display: grid;
  place-items: center;
  border: 2px solid #ffffff;
}

.account-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 6px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l1, #ffffff);
}
.account-avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
}
.account-button strong, .account-button small {
  display: block;
  line-height: 1.15;
}
.account-button strong {
  font-size: 12px;
}
.account-button small {
  font-size: 9px;
  color: var(--text-secondary);
}

/* ==========================================================================
   5. CONSULTATION SHELL & EXPANSIVE CHAT WORKSPACE
   ========================================================================== */
.consultation-shell {
  margin-left: var(--nav-rail-width, 76px);
  width: calc(100% - var(--nav-rail-width, 76px));
  min-height: calc(100vh - var(--topbar-height, 64px));
  display: block;
  position: relative;
}

.chat-workspace {
  width: 100%;
  max-width: var(--content-wide-max, 1680px);
  margin: 0 auto;
  padding: 24px 32px 140px;
  min-height: calc(100vh - var(--topbar-height, 64px));
  display: flex;
  flex-direction: column;
}

.chat-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.chat-card-header {
  display: none; /* Subsumed cleanly into os-topbar */
}

/* ==========================================================================
   6. AI VISUAL IDENTITY & NEW CHAT EMPTY STATE
   ========================================================================== */
.welcome-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  max-width: 860px;
  margin: 40px auto 30px;
  padding: 0 16px;
  animation: fadeIn 0.4s ease;
}

.ai-visual-identity {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

.ai-pulse-orb {
  position: relative;
  width: 90px;
  height: 90px;
  display: grid;
  place-items: center;
}

.orb-halo {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}
.orb-halo.halo-1 {
  background: radial-gradient(circle, rgba(13, 148, 136, 0.35) 0%, transparent 70%);
  animation: pulse-ring 3s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
.orb-halo.halo-2 {
  inset: -14px;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.22) 0%, transparent 70%);
  animation: pulse-ring 3s cubic-bezier(0.4, 0, 0.6, 1) infinite 1s;
}
.orb-halo.halo-3 {
  inset: -28px;
  background: radial-gradient(circle, rgba(13, 148, 136, 0.12) 0%, transparent 70%);
  animation: pulse-ring 3s cubic-bezier(0.4, 0, 0.6, 1) infinite 2s;
}

.orb-core {
  position: relative;
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #14b8a6, #0d9488 60%, #0f766e);
  color: #ffffff;
  box-shadow: 0 0 35px rgba(13, 148, 136, 0.45);
  animation: ai-orb-breathe 4s ease-in-out infinite;
}

.orb-glyph {
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}

.core-harmonic-wave {
  position: relative;
  z-index: 3;
  width: 48px;
  height: 30px;
  pointer-events: none;
}

.core-harmonic-wave .wave-path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.core-harmonic-wave .wave-primary {
  stroke: #ffffff;
  stroke-width: 2.2;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.9));
  animation: waveFloatPrimary 3s ease-in-out infinite alternate;
}

.core-harmonic-wave .wave-secondary {
  stroke: rgba(167, 243, 208, 0.75);
  stroke-width: 1.6;
  filter: drop-shadow(0 0 4px rgba(45, 212, 191, 0.5));
  animation: waveFloatSecondary 4s ease-in-out infinite alternate;
}

@keyframes waveFloatPrimary {
  0% { transform: translateY(-1.5px); opacity: 0.85; }
  100% { transform: translateY(1.5px); opacity: 1; }
}

@keyframes waveFloatSecondary {
  0% { transform: translateY(1.5px); opacity: 0.5; }
  100% { transform: translateY(-1.5px); opacity: 0.8; }
}

.ai-badge-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 9999px;
  background: var(--accent-light, #ccfbf1);
  color: var(--accent-primary, #0d9488);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.pulse-dot-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-primary, #0d9488);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.25);
}

.welcome-title {
  font-size: clamp(24px, 3.5vw, 34px);
  font-weight: 800;
  color: var(--text-primary, #0f172a);
  letter-spacing: -0.025em;
  line-height: 1.25;
  margin-bottom: 10px;
}

.welcome-subtitle {
  font-size: 15px;
  color: var(--text-secondary, #64748b);
  max-width: 620px;
  line-height: 1.6;
  margin-bottom: 32px;
}

/* ==========================================================================
   7. HIERARCHY-DRIVEN STARTER ACTION TILES
   ========================================================================== */
.starter-cards {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr 1fr;
  gap: 14px;
  width: 100%;
  max-width: 880px;
}

.starter-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--border-subtle, rgba(15, 23, 42, 0.08));
  background: var(--bg-l1, #ffffff);
  box-shadow: var(--shadow-sm);
  transition: all var(--motion-fast);
  cursor: pointer;
}
.starter-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-primary, #0d9488);
  box-shadow: 0 12px 28px -4px rgba(13, 148, 136, 0.16);
}

.starter-card.featured-tile {
  background: linear-gradient(145deg, var(--bg-l1, #ffffff), #f0fdfa);
  border-color: rgba(13, 148, 136, 0.35);
  box-shadow: 0 6px 18px rgba(13, 148, 136, 0.08);
}
.starter-card.featured-tile:hover {
  border-color: var(--accent-primary);
  box-shadow: 0 14px 32px rgba(13, 148, 136, 0.22);
}

.starter-icon-wrap {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent-light, #ccfbf1);
  color: var(--accent-primary, #0d9488);
  margin-bottom: 12px;
}
.starter-icon-wrap.icon-meds {
  background: #fef3c7;
  color: #d97706;
}
.starter-icon-wrap.icon-loc {
  background: #e0e7ff;
  color: #4f46e5;
}
.starter-icon-wrap.icon-air {
  background: #dcfce7;
  color: #16a34a;
}

.starter-copy strong {
  display: block;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.starter-copy small {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.starter-arrow {
  position: absolute;
  right: 14px;
  bottom: 14px;
  color: var(--accent-primary);
  font-size: 14px;
  font-weight: 700;
}

/* ==========================================================================
   8. MESSAGE STREAM & CLINICAL AI REPORT LAYOUT
   ========================================================================== */
.message-list {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  flex: 1;
}

.message-item {
  display: flex;
  gap: 14px;
  max-width: 100%;
  animation: fadeIn 0.3s ease;
}

.message-item.user {
  justify-content: flex-end;
}
.message-item.user .message-bubble {
  background: linear-gradient(135deg, var(--accent-primary, #0d9488), #0f766e);
  color: #ffffff;
  padding: 12px 18px;
  border-radius: 18px 18px 4px 18px;
  max-width: min(640px, 85%);
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.18);
  font-size: 14.5px;
  line-height: 1.55;
}

.message-item.assistant {
  justify-content: flex-start;
}
.message-item.assistant .message-bubble {
  background: var(--bg-l1, #ffffff);
  border: 1px solid var(--border-subtle);
  border-radius: 20px 20px 20px 4px;
  padding: 20px 24px;
  max-width: 100%;
  width: 100%;
  box-shadow: var(--shadow-sm);
  font-size: 14.5px;
  line-height: 1.65;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--text-secondary);
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}
.chat-actions button {
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  background: var(--bg-l0);
}
.chat-actions button:hover {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

/* RAG Sources */
.rag-sources-panel {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(13, 148, 136, 0.25);
  background: var(--accent-light, #f0fdfa);
}
.rag-source-card {
  display: block;
  font-size: 11px;
  color: var(--med-primary-text, #115e59);
  margin-top: 4px;
}

/* Risk Notice */
.risk-notice {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--med-emergency-border, #fca5a5);
  background: var(--med-emergency-bg, #fef2f2);
  color: var(--med-emergency-text, #991b1b);
  font-size: 12.5px;
  font-weight: 600;
}


/* AI Thinking State & Pulse Indicator */
.ai-thinking-bubble, .ai-thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-radius: 20px 20px 20px 4px;
  background: var(--bg-l1, #ffffff);
  border: 1px solid var(--border-subtle, rgba(15, 23, 42, 0.08));
  box-shadow: var(--shadow-sm);
  color: var(--text-secondary, #64748b);
  font-size: 13.5px;
}

.medical-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-primary, #0d9488);
  box-shadow: 0 0 0 0 rgba(13, 148, 136, 0.6);
  animation: medicalPulse 1.8s infinite;
}

@keyframes medicalPulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(13, 148, 136, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 10px rgba(13, 148, 136, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(13, 148, 136, 0);
  }
}

/* Table wrap */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
}
.table-wrap th, .table-wrap td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
}

/* ==========================================================================
   9. FLOATING GLASS COMPOSER (BOTTOM CENTER)
   ========================================================================== */
.composer {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: calc(50% + (var(--nav-rail-width, 76px) / 2));
  transform: translateX(-50%);
  width: min(840px, calc(100% - var(--nav-rail-width, 76px) - 48px));
  z-index: 75;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 28px;
  background: var(--glass-composer, rgba(255, 255, 255, 0.92));
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-strong, rgba(15, 23, 42, 0.12));
  box-shadow: 0 20px 40px -4px rgba(15, 23, 42, 0.14), 0 0 0 1px rgba(13, 148, 136, 0.08);
  transition: all var(--motion-fast);
}

.composer:focus-within {
  border-color: var(--accent-primary, #0d9488);
  box-shadow: 0 22px 48px -4px rgba(13, 148, 136, 0.22), 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.composer-tool {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary, #64748b);
  font-size: 18px;
  flex-shrink: 0;
  transition: all var(--motion-fast);
}
.composer-tool:hover {
  background: var(--accent-light, #ccfbf1);
  color: var(--accent-primary, #0d9488);
}

.composer-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.composer-input-wrap textarea {
  width: 100%;
  min-height: 24px;
  max-height: 160px;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14.5px;
  color: var(--text-primary, #0f172a);
  resize: none;
  line-height: 1.5;
  padding: 2px 0;
}
.composer-input-wrap textarea::placeholder {
  color: var(--text-tertiary, #94a3b8);
}

.char-counter {
  position: absolute;
  right: 4px;
  bottom: -22px;
  font-size: 10px;
  color: var(--text-secondary);
}

.send-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-primary, #0d9488);
  color: #ffffff;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(13, 148, 136, 0.32);
  transition: transform var(--motion-fast), background var(--motion-fast);
}
.send-button:hover {
  transform: scale(1.06);
  background: #0f766e;
}
.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chat-disclaimer {
  position: fixed;
  bottom: 6px;
  left: calc(50% + (var(--nav-rail-width, 76px) / 2));
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  pointer-events: none;
  z-index: 74;
}

/* Quick area & Pills */
.quick-area {
  margin: 14px auto;
  max-width: 860px;
  width: 100%;
}
.quick-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
}
.quick-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.quick-list button {
  padding: 7px 13px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l1);
  font-size: 12px;
  color: var(--text-secondary);
  transition: all var(--motion-fast);
}
.quick-list button:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-light);
}

/* ==========================================================================
   10. CONVERSATION DRAWER (OFF-CANVAS LEFT)
   ========================================================================== */
.history-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--drawer-width, 340px);
  z-index: 90;
  background: var(--bg-l1, #ffffff);
  border-right: 1px solid var(--border-subtle);
  transform: translateX(-100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s ease;
  display: flex;
  flex-direction: column;
  padding: 20px 18px;
  gap: 14px;
  box-shadow: none;
}

.history-sidebar.drawer-open,
.history-sidebar.mobile-open {
  transform: translateX(var(--nav-rail-width, 76px));
  visibility: visible;
  pointer-events: auto;
  box-shadow: var(--shadow-xl);
}

.new-chat-button {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-primary, #0d9488), #0f766e);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(13, 148, 136, 0.22);
  transition: transform var(--motion-fast);
}
.new-chat-button:hover {
  transform: translateY(-2px);
}

.history-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.history-search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l0);
}
.history-search input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-size: 12px;
}
.filter-button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l1);
  display: grid;
  place-items: center;
  font-size: 14px;
}

.history-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
}
.history-title-row button {
  font-size: 11px;
  color: var(--accent-primary);
}


.history-skeleton {
  height: 48px;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--bg-l0, #f8fafc) 25%, var(--bg-l2, #f1f5f9) 50%, var(--bg-l0, #f8fafc) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-item {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--bg-l0);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-item:hover, .history-item.active {
  border-color: var(--med-primary-border);
  background: var(--accent-light);
}

.active-person-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l0);
}
.privacy-note {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  gap: 8px;
  align-items: center;
}


/* Confirmation Modal */
.confirm-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 11, 18, 0.60);
  backdrop-filter: blur(8px);
  z-index: 140;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.confirm-modal-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--bg-l1, #ffffff);
  border: 1px solid var(--border-subtle, rgba(15, 23, 42, 0.08));
  border-radius: 20px;
  box-shadow: var(--shadow-xl);
  padding: 24px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modalFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   11. HEALTH CONTEXT PANEL (OFF-CANVAS RIGHT SLIDE-OVER)
   ========================================================================== */
.context-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  z-index: 90;
  background: var(--bg-l1, #ffffff);
  border-left: 1px solid var(--border-subtle);
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s ease;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: none;
}

.context-sidebar.drawer-open,
.context-sidebar.mobile-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  box-shadow: var(--shadow-xl);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 11, 18, 0.50);
  backdrop-filter: blur(4px);
  z-index: 84;
}

.context-card {
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l0);
}
.context-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.context-heading h2 {
  font-size: 14px;
  font-weight: 700;
}
.context-heading button {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-l1);
}

.emergency-card {
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--med-emergency-border);
  background: var(--med-emergency-bg);
  color: var(--med-emergency-text);
}
.emergency-card a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  background: var(--status-emergency, #ef4444);
  color: #ffffff;
  font-weight: 700;
}

/* ==========================================================================
   12. MOBILE & RESPONSIVE BREAKPOINTS
   ========================================================================== */
.mobile-nav-btn,
.mobile-only {
  display: none !important;
}

@media (max-width: 980px) {
  .starter-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .mobile-only {
    display: flex !important;
  }
  
  .app-nav-rail {
    display: none;
  }

  .topbar.os-topbar {
    margin-left: 0;
    width: 100%;
    padding: 0 16px;
  }
  
  .desktop-history-trigger, .back-overview {
    display: none;
  }

  .consultation-shell {
    margin-left: 0;
    width: 100%;
  }

  .chat-workspace {
    padding: 12px 14px 170px;
  }

  .welcome-hero {
    margin: 16px auto 16px;
  }

  .welcome-title {
    font-size: clamp(19px, 5.5vw, 24px);
    line-height: 1.25;
  }

  .welcome-subtitle {
    font-size: 13.5px;
    margin-bottom: 20px;
  }

  .starter-cards {
    grid-template-columns: 1fr;
  }

  .history-sidebar {
    left: 0;
    width: min(340px, 86vw);
  }
  .history-sidebar.drawer-open,
  .history-sidebar.mobile-open {
    transform: translateX(0) !important;
  }
  .mobile-nav-btn {
    display: grid !important;
  }

  .context-sidebar {
    width: min(360px, 90vw);
  }

  .composer {
    left: 12px;
    right: 12px;
    transform: none;
    width: calc(100% - 24px);
    bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  }

  .chat-disclaimer {
    left: 50%;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    z-index: 82;
    background: var(--glass-panel, rgba(255, 255, 255, 0.95));
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-around;
  }
  .mobile-bottom-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    padding: 4px 8px;
  }
  .mobile-bottom-item.active {
    color: var(--accent-primary);
  }
}

/* 4K Ultra HD bounding */
@media (min-width: 1921px) {
  .chat-workspace {
    max-width: 1680px;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
