/* =========================================================
   TÂM AN - MINIMALIST, HIGH-END & APPLE-GRADE MOBILE DESIGN
   Clean, Sophisticated, Modern & Professional
   ========================================================= */

:root {
  --font-sans: 'Plus Jakarta Sans', 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Palette - Clean, Modern Neutral & Medical Teal */
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;
  
  --text-primary: #0f172a;       /* Deep Slate */
  --text-secondary: #475569;     /* Slate */
  --text-muted: #94a3b8;         /* Light Slate */
  --text-inverted: #ffffff;

  /* Primary Accent - Refined Deep Teal / Forest */
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-light: #f0fdfa;
  --primary-border: #ccfbf1;
  --primary-focus: rgba(15, 118, 110, 0.12);

  --border-light: #e2e8f0;
  --border-subtle: #f1f5f9;

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --shadow-subtle: 0 1px 3px 0 rgba(0, 0, 0, 0.04), 0 1px 2px -1px rgba(0, 0, 0, 0.04);
  --shadow-card: 0 4px 16px -2px rgba(15, 23, 42, 0.04), 0 2px 6px -2px rgba(15, 23, 42, 0.02);
  --shadow-float: 0 12px 30px -4px rgba(15, 23, 42, 0.08);

  --transition: 0.18s ease;
}

[data-theme="dark"] {
  --bg-primary: #090d16;
  --bg-surface: #101726;
  --bg-surface-elevated: #162033;
  --bg-subtle: #1a2438;
  --bg-hover: #222f46;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;

  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-light: #0f2926;
  --primary-border: #134e48;
  --primary-focus: rgba(20, 184, 166, 0.15);

  --border-light: #1e293b;
  --border-subtle: #141c2c;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}

.container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Navbar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-light);
  padding-top: env(safe-area-inset-top);
  transition: all var(--transition);
}

[data-theme="dark"] .navbar {
  background: rgba(16, 23, 38, 0.92);
}

.nav-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  cursor: pointer;
}

.brand-logo-mark {
  width: 32px;
  height: 32px;
  background: #0f172a;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

[data-theme="dark"] .brand-logo-mark {
  background: #14b8a6;
  color: #090d16;
}

.brand-logo-mark svg {
  width: 18px;
  height: 18px;
}

.brand-text-name {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* User / Auth Button in Header */
.nav-auth-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  padding: 4px 12px 4px 6px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  color: var(--text-primary);
  max-width: 170px;
}

.nav-auth-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.nav-auth-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #0f172a;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

[data-theme="dark"] .nav-auth-avatar {
  background: #14b8a6;
  color: #090d16;
}

.nav-auth-name {
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-auth-role-badge {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.role-badge-admin {
  background: #fee2e2;
  color: #991b1b;
}

.role-badge-doctor {
  background: #e0f2fe;
  color: #0369a1;
}

.role-badge-user {
  background: #f1f5f9;
  color: #475569;
}

/* =========================================================
   HERO / INTRO SECTION (CLEAN & MINIMALIST)
   ========================================================= */
.app-hero {
  padding: 24px 0 16px;
}

.hero-tagline {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 6px;
}

.hero-heading {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1.25;
  margin-bottom: 8px;
}

.hero-subheading {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* =========================================================
   TRIAGE SECTION (APPLE / NOTION GRADE SEGMENTED UI)
   ========================================================= */
.triage-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-card);
}

.triage-header-block {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.triage-step-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.triage-step-desc {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.triage-group {
  margin-bottom: 18px;
}

.triage-label-text {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* Segmented Control for Age */
.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-sm);
  gap: 3px;
}

.segmented-btn {
  background: transparent;
  border: none;
  padding: 9px 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
  font-family: inherit;
  outline: none;
}

.segmented-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* 2-Column Grid for Gender */
.gender-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.gender-tile {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all var(--transition);
}

.gender-tile.full-width {
  grid-column: span 2;
}

.gender-tile.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
}

.check-indicator {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.gender-tile.active .check-indicator {
  border-color: var(--primary);
  background: var(--primary);
}

.gender-tile.active .check-indicator::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
}

/* List Items for Issues */
.issues-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.issue-row {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all var(--transition);
}

.issue-row:hover {
  border-color: var(--text-muted);
}

.issue-row.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.issue-main-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.issue-sub-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.issue-row.active .issue-main-text {
  color: var(--primary);
  font-weight: 700;
}

.issue-row.active .check-indicator {
  border-color: var(--primary);
  background: var(--primary);
}

.issue-row.active .check-indicator::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
}

/* Recommendation Result Callout */
.recommendation-callout {
  background: #0f172a;
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 18px;
  margin-top: 20px;
}

[data-theme="dark"] .recommendation-callout {
  background: #162033;
  border: 1px solid var(--border-light);
}

.rec-badge-small {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #2dd4bf;
  margin-bottom: 6px;
}

.rec-headline {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 6px;
  color: #ffffff;
  line-height: 1.3;
}

.rec-explanation {
  font-size: 0.86rem;
  color: #94a3b8;
  line-height: 1.5;
  margin-bottom: 14px;
}

.btn-cta-white {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: #ffffff;
  color: #0f172a;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-cta-white:active {
  transform: scale(0.98);
  background: #f1f5f9;
}

/* =========================================================
   TESTS LIST (CLEAN MINIMALIST CARDS)
   ========================================================= */
.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 12px;
}

.section-caption {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.tests-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}

.clean-test-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.clean-test-card:hover {
  border-color: #94a3b8;
  box-shadow: var(--shadow-card);
}

.clean-test-card:active {
  transform: scale(0.99);
}

.clean-test-card.active-match {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.test-card-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.test-badge-chip {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 4px;
}

.test-title-text {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.test-desc-text {
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: 12px;
}

.test-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
}

.test-arrow-link {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* =========================================================
   QUIZ VIEW (FOCUSED & CLEAN)
   ========================================================= */
.quiz-top-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quiz-back-button {
  background: none;
  border: none;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.quiz-counter {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-primary);
}

.quiz-progress-track {
  height: 4px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  margin-bottom: 14px;
  overflow: hidden;
}

.quiz-progress-thumb {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.25s ease;
}

.question-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}

.question-category-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  margin-bottom: 8px;
}

.question-content-text {
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 18px;
}

.options-vertical-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.clean-option-row {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  cursor: pointer;
  transition: all var(--transition);
}

.clean-option-row:hover {
  border-color: #94a3b8;
}

.clean-option-row:active {
  transform: scale(0.99);
}

.clean-option-row.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-key-label {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
}

.clean-option-row.selected .option-key-label {
  background: var(--primary);
  color: white;
}

.option-text-content {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
}

.clean-option-row.selected .option-text-content {
  font-weight: 600;
}

/* Sticky Quiz Nav Bottom */
.quiz-sticky-bottom {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-light);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  margin-left: -16px;
  margin-right: -16px;
  display: flex;
  gap: 8px;
  z-index: 50;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.04);
}

.btn-base {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all var(--transition);
}

.btn-base:active {
  transform: scale(0.98);
}

.btn-dark {
  background: #0f172a;
  color: white;
  flex: 1.5;
}

[data-theme="dark"] .btn-dark {
  background: #14b8a6;
  color: #090d16;
}

.btn-gray {
  background: var(--bg-subtle);
  color: var(--text-primary);
  flex: 1;
}

/* Minimalist Dot Strip */
.dot-strip-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0;
  scrollbar-width: none;
}

.dot-strip-wrapper::-webkit-scrollbar {
  display: none;
}

.dot-strip-row {
  display: flex;
  gap: 5px;
  width: max-content;
  margin: 0 auto;
}

.strip-dot {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
}

.strip-dot.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.strip-dot.done {
  background: #0f172a;
  color: white;
  border-color: #0f172a;
}

[data-theme="dark"] .strip-dot.done {
  background: #14b8a6;
  color: #090d16;
  border-color: #14b8a6;
}

/* =========================================================
   RESULTS VIEW (CLEAN REPORTING)
   ========================================================= */
.report-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  box-shadow: var(--shadow-card);
  margin-bottom: 16px;
  text-align: center;
}

.report-score-box {
  margin: 16px 0;
}

.report-number {
  font-size: 3.2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text-primary);
  line-height: 1;
}

.report-scale {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
}

.status-tag {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 4px;
  margin-bottom: 8px;
}

.tag-normal { background: #dcfce7; color: #166534; }
.tag-mild { background: #fef3c7; color: #92400e; }
.tag-moderate { background: #ffedd5; color: #9a3412; }
.tag-severe { background: #fee2e2; color: #991b1b; }

.report-title-heading {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.report-summary-p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 18px;
}

.dass-tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 16px 0;
  text-align: left;
}

.dass-tile-item {
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.dass-tile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.86rem;
  font-weight: 700;
}

/* Hotline & Safety Alert */
.safety-alert-card {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

.safety-title-red {
  font-size: 0.95rem;
  font-weight: 700;
  color: #991b1b;
  margin-bottom: 6px;
}

.safety-body-text {
  font-size: 0.85rem;
  color: #7f1d1d;
  line-height: 1.45;
  margin-bottom: 12px;
}

.hotline-link-btn {
  display: block;
  background: #dc2626;
  color: white;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 10px;
  text-align: center;
  border-radius: var(--radius-sm);
  text-decoration: none;
  margin-bottom: 6px;
}

/* Bottom Tab Navigation Bar */
.mobile-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(56px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 90;
}

[data-theme="dark"] .mobile-tab-bar {
  background: rgba(16, 23, 38, 0.95);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 14px;
  font-family: inherit;
  outline: none;
}

.tab-item.active {
  color: var(--primary);
  font-weight: 700;
}

.tab-item svg {
  width: 18px;
  height: 18px;
}

/* Footer */
footer {
  margin-top: auto;
  padding: 24px 0 calc(16px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* =========================================================
   LIVE SPECIALIST CHAT & CONSULTATION SYSTEM
   ========================================================= */

/* Floating Chat Trigger */
.floating-chat-btn {
  position: fixed;
  bottom: calc(70px + env(safe-area-inset-bottom));
  right: 16px;
  background: #0f172a;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 10px 16px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  cursor: pointer;
  z-index: 85;
  transition: all var(--transition);
  animation: bounceSoft 3s infinite ease-in-out;
}

[data-theme="dark"] .floating-chat-btn {
  background: #14b8a6;
  color: #090d16;
  box-shadow: 0 8px 24px rgba(20, 184, 166, 0.35);
}

.floating-chat-btn:active {
  transform: scale(0.95);
}

.online-dot-pulse {
  width: 9px;
  height: 9px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
  position: relative;
}

@keyframes bounceSoft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* Unread Badges & Patient Floating Toast */
.chat-unread-badge {
  background: #ef4444;
  color: white;
  font-size: 0.68rem;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  margin-left: 4px;
  animation: pulseAlert 1.5s infinite;
}

.tab-item {
  position: relative;
}

.tab-unread-dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 14px);
  width: 9px;
  height: 9px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
  animation: pulseAlert 1.5s infinite;
}

.patient-incoming-toast-banner {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  max-width: 420px;
  margin: 0 auto;
  background: var(--bg-surface);
  border: 1px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 190;
  cursor: pointer;
  animation: slideToastUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.patient-toast-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #0f766e;
  color: white;
  font-weight: 800;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.patient-toast-action-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-xs);
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

/* Result Page Consultation Banner */
.consult-action-card {
  background: linear-gradient(135deg, #f0fdfa 0%, #e0f2fe 100%);
  border: 1.5px solid var(--primary-border);
  border-radius: var(--radius-md);
  padding: 18px 16px;
  margin-top: 18px;
  margin-bottom: 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

[data-theme="dark"] .consult-action-card {
  background: linear-gradient(135deg, #0d2824 0%, #08273d 100%);
  border-color: #115e59;
}

.consult-header-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.specialist-avatar-img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #0f766e;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.consult-title-name {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.25;
}

.consult-status-sub {
  font-size: 0.76rem;
  color: var(--primary);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
}

.consult-prompt-text {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* Fullscreen / Drawer Chat Modal */
.chat-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}

@media (min-width: 641px) {
  .chat-overlay {
    align-items: center;
    padding: 20px;
  }
}

.chat-modal-window {
  width: 100%;
  max-width: 500px;
  height: 92vh;
  max-height: 720px;
  background: var(--bg-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
  animation: slideDrawer 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 641px) {
  .chat-modal-window {
    border-radius: var(--radius-xl);
    height: 85vh;
  }
}

@keyframes slideDrawer {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Chat Header */
.chat-top-header {
  padding: 14px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-profile-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-close-btn {
  background: var(--bg-subtle);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.chat-close-btn:active {
  transform: scale(0.9);
}

/* Messages Scroll Container */
.chat-conversation-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-primary);
  -webkit-overflow-scrolling: touch;
}

/* Message Bubbles */
.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: fadeIn 0.25s ease;
}

.msg-row.incoming {
  align-self: flex-start;
}

.msg-row.outgoing {
  align-self: flex-end;
}

.msg-bubble {
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.48;
  position: relative;
  word-break: break-word;
}

.msg-row.incoming .msg-bubble {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.msg-row.outgoing .msg-bubble {
  background: #0f172a;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

[data-theme="dark"] .msg-row.outgoing .msg-bubble {
  background: #14b8a6;
  color: #090d16;
}

.msg-timestamp {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

.msg-row.outgoing .msg-timestamp {
  text-align: right;
}

/* Test Summary Embed inside Chat */
.chat-test-summary-card {
  background: var(--bg-surface);
  border: 1.5px solid var(--primary-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-card-badge {
  font-weight: 800;
  color: var(--primary);
  font-size: 0.72rem;
  text-transform: uppercase;
}

/* Quick Replies Track */
.quick-replies-track {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  scrollbar-width: none;
  flex-shrink: 0;
}

.quick-replies-track::-webkit-scrollbar {
  display: none;
}

.quick-reply-pill {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}

.quick-reply-pill:active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* Typing Indicator Animation */
.typing-box {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  width: max-content;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Chat Input Bar */
.chat-input-bar {
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-input-field {
  flex: 1;
  background: var(--bg-subtle);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  padding: 10px 16px;
  font-size: 16px; /* prevent iOS zoom */
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition);
}

.chat-input-field:focus {
  border-color: var(--primary);
  background: var(--bg-surface);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #0f172a;
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}

[data-theme="dark"] .chat-send-btn {
  background: #14b8a6;
  color: #090d16;
}

.chat-send-btn:active {
  transform: scale(0.92);
}

/* =========================================================
   AUTH MODAL & ROLE MANAGEMENT UI
   ========================================================= */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 250;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}

@media (min-width: 641px) {
  .auth-overlay {
    align-items: center;
    padding: 20px;
  }
}

.auth-modal-window {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  background: var(--bg-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
  animation: slideDrawer 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 641px) {
  .auth-modal-window {
    border-radius: var(--radius-xl);
    max-height: 85vh;
  }
}

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

.auth-header-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-primary);
}

.auth-body-content {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Form Groups & Inputs */
.auth-form-group {
  margin-bottom: 14px;
}

.auth-form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.auth-input-text {
  width: 100%;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 16px; /* prevent iOS zoom */
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition);
}

.auth-input-text:focus {
  border-color: var(--primary);
  background: var(--bg-surface);
}

/* Role Selector Tiles */
.role-select-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.role-tile-btn {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
}

.role-tile-btn:hover {
  border-color: var(--text-muted);
}

.role-tile-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.role-tile-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.role-tile-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.35;
}

.role-tile-btn.active .role-tile-title {
  color: var(--primary);
}

/* Fast Switch Demo Accounts Track */
.demo-accounts-box {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 18px;
  border: 1px dashed var(--border-light);
}

.demo-box-caption {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.demo-user-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all var(--transition);
}

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

.demo-user-item.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* User Profile Badge Card in Profile View */
.profile-hero-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-card);
}

.profile-avatar-large {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #0f172a;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  flex-shrink: 0;
}

[data-theme="dark"] .profile-avatar-large {
  background: #14b8a6;
  color: #090d16;
}

/* RBAC Records Table & Filters */
.records-filter-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 14px;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.records-filter-tabs::-webkit-scrollbar {
  display: none;
}

.filter-tab-pill {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.filter-tab-pill.active {
  background: #0f172a;
  color: white;
  border-color: #0f172a;
}

[data-theme="dark"] .filter-tab-pill.active {
  background: #14b8a6;
  color: #090d16;
  border-color: #14b8a6;
}

.record-clinical-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
  transition: all var(--transition);
}

.record-clinical-item:hover {
  box-shadow: var(--shadow-card);
  border-color: #94a3b8;
}

.record-top-info {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.patient-name-tag {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.doctor-notes-box {
  background: var(--bg-subtle);
  border-left: 3px solid var(--primary);
  padding: 8px 12px;
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.doctor-notes-box p {
  margin: 0;
}

