/* ==========================================================================
   BASELINE COMPLETE DESIGN SYSTEM & STYLESHEET
   Mobile-first (390px default), Duolingo-inspired chunky UI, Dark/Light modes
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design Tokens & CSS Variables
   -------------------------------------------------------------------------- */
:root {
  /* Light Theme (Default) */
  --bg-app: #f4f6f8;
  --bg-card: #ffffff;
  --bg-card-subtle: #edf2f7;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Friendly Warm Emerald / Teal Primary Accent (Duolingo Tactile) */
  --accent: #0d9488;
  --accent-light: #ccfbf1;
  --accent-hover: #0f766e;
  --accent-active: #115e59;
  --accent-shadow: #042f2e;

  /* Duolingo Signature Vibrant Accents */
  --duo-green: #58cc02;
  --duo-green-shadow: #46a302;
  --duo-green-hover: #61e002;
  --duo-blue: #1cb0f6;
  --duo-blue-shadow: #1899d6;
  --duo-amber: #ff9600;
  --duo-amber-shadow: #e58500;
  --duo-purple: #ce82ff;
  --duo-purple-shadow: #a559e0;

  /* Alert / Out-of-Range (Duolingo Coral Red) */
  --danger: #ff4b4b;
  --danger-light: #fee2e2;
  --danger-border: #fca5a5;
  --danger-shadow: #d33131;

  /* Normal Range SVG Band */
  --band-fill: rgba(13, 148, 136, 0.12);
  --band-stroke: rgba(13, 148, 136, 0.35);

  /* Chart Line & Dot Colors */
  --chart-line: #0d9488;
  --chart-dot: #0f766e;
  --chart-dot-latest: #042f2e;
  --chart-dot-out: #ff4b4b;

  /* Focus outline */
  --focus-ring: #1cb0f6;

  /* Elevation / 3D button depths */
  --btn-bottom-depth: 4px;
  --card-bottom-depth: 4px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.12);

  /* Typography */
  --font-main: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
  --font-kannada: "Noto Sans Kannada", sans-serif;
  --font-hindi: "Noto Sans Devanagari", sans-serif;

  --line-height-normal: 1.5;
  --line-height-indic: 1.8;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-app: #0f172a;
  --bg-card: #1e293b;
  --bg-card-subtle: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --border-strong: #475569;

  --accent: #14b8a6;
  --accent-light: #134e4a;
  --accent-hover: #2dd4bf;
  --accent-active: #0d9488;
  --accent-shadow: #042f2e;

  --duo-green: #58cc02;
  --duo-green-shadow: #2e6901;
  --duo-green-hover: #61e002;
  --duo-blue: #38bdf8;
  --duo-blue-shadow: #0369a1;
  --duo-amber: #fbbf24;
  --duo-amber-shadow: #b45309;
  --duo-purple: #c084fc;
  --duo-purple-shadow: #7e22ce;

  --danger: #f87171;
  --danger-light: #450a0a;
  --danger-border: #7f1d1d;
  --danger-shadow: #991b1b;

  --band-fill: rgba(20, 184, 166, 0.18);
  --band-stroke: rgba(20, 184, 166, 0.4);

  --chart-line: #2dd4bf;
  --chart-dot: #5eead4;
  --chart-dot-latest: #ffffff;
  --chart-dot-out: #f87171;

  --focus-ring: #38bdf8;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 14px 28px rgba(0, 0, 0, 0.5);
}

/* --------------------------------------------------------------------------
   Reset & Base Styles
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-main), var(--font-kannada), var(--font-hindi);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: var(--line-height-normal);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Kannada and Hindi extra line-height */
html[lang="kn"], html[lang="hi"],
.lang-kn, .lang-hi {
  line-height: var(--line-height-indic);
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Layout & Container (Mobile-first ~390px, laptop friendly)
   -------------------------------------------------------------------------- */
.app-container {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 768px) {
  .app-container {
    max-width: 640px;
    padding: 24px 20px;
    gap: 20px;
  }
}

/* --------------------------------------------------------------------------
   Duolingo-style Chunky Buttons & Tap Targets (>= 44px)
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 0.96rem;
  font-weight: 800;
  letter-spacing: 0.2px;
  text-decoration: none;
  border-radius: 16px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.08s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.08s ease, background-color 0.15s ease;
  user-select: none;
  text-align: center;
  position: relative;
}

.btn-primary {
  background-color: var(--accent);
  color: #ffffff;
  border-color: var(--accent-active);
  border-bottom: 4px solid var(--accent-shadow);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(3px);
  border-bottom-width: 1px;
  box-shadow: none;
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-strong);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-card-subtle);
  border-color: var(--border-strong);
}

.btn-secondary:active:not(:disabled) {
  transform: translateY(3px);
  border-bottom-width: 1px;
  box-shadow: none;
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
  border-color: var(--danger-border);
  border-bottom: 4px solid var(--danger-shadow);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-danger:active:not(:disabled) {
  transform: translateY(3px);
  border-bottom-width: 1px;
  box-shadow: none;
}

.btn-sm {
  min-height: 42px;
  padding: 8px 14px;
  font-size: 0.88rem;
  border-radius: 14px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
  border-bottom-width: 2px !important;
}

/* --------------------------------------------------------------------------
   Duolingo Tactile Card Component
   -------------------------------------------------------------------------- */
.card {
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-strong);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow-md);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.2s ease, box-shadow 0.2s ease;
}

/* --------------------------------------------------------------------------
   Header Bar
   -------------------------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border-color);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-main);
  font-weight: 900;
  font-size: 1.35rem;
  letter-spacing: -0.5px;
}

.brand-badge {
  background-color: var(--accent);
  color: #ffffff;
  font-size: 0.62rem;
  padding: 3px 7px;
  border-radius: 999px;
  font-weight: 800;
  white-space: nowrap;   /* "Powered by AWS" stays on one line on a phone */
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;   /* the language name stays readable rather than being squeezed to "Engli..." */
}

.theme-toggle-btn {
  background: none;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
}

.theme-toggle-btn:hover {
  background-color: var(--bg-card-subtle);
}

/* --------------------------------------------------------------------------
   Screen B: People & Language Bar
   -------------------------------------------------------------------------- */
.people-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.people-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.select-wrapper {
  position: relative;
  flex: 1;
  min-width: 140px;
}

.app-select {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 14px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}

.lang-select-wrapper {
  width: 110px;
  flex: none;
}

/* --------------------------------------------------------------------------
   Mascot Component & Animated Speech Bubble (Duolingo Style)
   -------------------------------------------------------------------------- */
.mascot-section {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin: 4px 0 12px 0;
}

.mascot-avatar-wrapper {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  box-shadow: 0 4px 0 var(--border-strong), var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  position: relative;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: mascotFloat 3.5s ease-in-out infinite;
}

@keyframes mascotFloat {
  0%, 100% {
    transform: translateY(0px) rotate(0deg);
  }
  50% {
    transform: translateY(-5px) rotate(1.5deg);
  }
}

.mascot-avatar {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Duolingo bouncy micro-animation on mascot hover/interact */
.mascot-avatar-wrapper:hover {
  transform: scale(1.1) rotate(-3deg);
  animation-play-state: paused;
}

.mascot-avatar-wrapper:active {
  transform: scale(0.96) rotate(2deg);
}

.mascot-bubble {
  position: relative;
  flex: 1;
  min-width: 0;
  /* A fixed height on purpose: she types her line out letter by letter, and a bubble that
     grew with it would shove the whole page down a line at a time. Longer lines scroll
     inside instead, and the text below never moves. */
  height: 104px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-strong);
  border-radius: 20px;
  padding: 13px 18px;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  line-height: 1.45;
  scrollbar-width: thin;
  transition: border-color 0.2s ease;
}
.mascot-bubble::-webkit-scrollbar { width: 5px; }
.mascot-bubble::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}
@media (min-width: 768px) {
  .mascot-bubble { height: 92px; }
}

/* Speech bubble left triangle arrow */
.mascot-bubble::before {
  content: "";
  position: absolute;
  top: 24px;
  left: -10px;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 10px solid var(--border-color);
}

.mascot-bubble::after {
  content: "";
  position: absolute;
  top: 24px;
  left: -7px;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-right: 9px solid var(--bg-card);
}

.mascot-bubble.pop {
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  0% { transform: scale(0.92) translateY(4px); opacity: 0.8; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* --------------------------------------------------------------------------
   Screen C: History Path & Next Due Reminder
   -------------------------------------------------------------------------- */
.history-path-card {
  padding: 16px;
}

.path-heading {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-path-track {
  display: flex;
  align-items: center;
  overflow-x: auto;
  padding: 8px 4px;
  gap: 4px;
  scrollbar-width: thin;
}

.path-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  width: 80px;
  text-align: center;
}

.node-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: var(--accent-light);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  box-shadow: 0 2px 0 var(--accent);
}

.node-date {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.path-connector {
  flex: 1;
  min-width: 24px;
  height: 4px;
  background-color: var(--accent);
  border-radius: 2px;
  margin-top: -18px;
}

.locked-node .node-circle {
  background-color: var(--bg-card-subtle);
  border-color: var(--border-strong);
  box-shadow: 0 2px 0 var(--border-strong);
}

.locked-node .node-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
}

.overdue-node .node-circle {
  background-color: var(--danger-light);
  border-color: var(--danger);
  box-shadow: 0 2px 0 var(--danger-shadow);
}

.overdue-node .node-label {
  color: var(--danger);
}

/* --------------------------------------------------------------------------
   Screen D: Add a Report
   -------------------------------------------------------------------------- */
.upload-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.photo-preview-box {
  border: 2px dashed var(--border-strong);
  border-radius: 14px;
  padding: 10px;
  text-align: center;
  background-color: var(--bg-card-subtle);
}

.photo-preview-box img {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 8px;
}

.collapsible-details {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.88rem;
}

.collapsible-details summary {
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
}

.collapsible-content {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.date-input {
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  background-color: var(--bg-card);
  color: var(--text-main);
}

.upload-status {
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  min-height: 22px;
  transition: color 0.2s ease;
}

.status-loading {
  color: var(--accent);
}

.status-success {
  color: #15803d;
}

.status-error {
  color: var(--danger);
}

/* --------------------------------------------------------------------------
   Screen E: Trend Cards & SVG Charts
   -------------------------------------------------------------------------- */
.trends-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.trend-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  outline: none;
  border-bottom: 4px solid var(--border-strong);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease, border-color 0.15s ease;
}

.trend-card:hover {
  transform: translateY(-3px);
  border-bottom-color: var(--accent);
  box-shadow: var(--shadow-lg);
}

.trend-card:active {
  transform: translateY(-1px);
}

.trend-card:focus-visible {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.trend-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.test-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.test-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.2px;
}

/* Status Badge H / L (Duolingo Tactile Pill) */
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: 0.88rem;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

.badge-high, .badge-low {
  background-color: var(--danger-light);
  color: var(--danger);
  border: 2px solid var(--danger-border);
  box-shadow: 0 2px 0 var(--danger-shadow);
}

.test-value-group {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.test-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.test-unit {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.trend-arrow {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--text-muted);
  margin-left: 2px;
}

/* Out of Range Card Highlight */
.card-out-of-range {
  border-color: var(--danger-border);
}

.card-out-of-range .test-value,
.card-out-of-range .trend-arrow {
  color: var(--danger);
}

/* Card updated highlight */
.trend-card-updated {
  animation: cardHighlight 1.5s ease-out;
}

@keyframes cardHighlight {
  0% { box-shadow: 0 0 0 4px var(--accent); }
  100% { box-shadow: var(--shadow-md); }
}

/* Inline SVG Chart */
.trend-chart-wrapper {
  width: 100%;
  background-color: var(--bg-card-subtle);
  border-radius: 12px;
  padding: 6px;
  overflow: hidden;
}

.trend-chart-svg {
  width: 100%;
  height: 72px;
  display: block;
}

/* SVG Chart Elements */
.svg-band {
  fill: var(--band-fill);
}

.svg-band-line {
  stroke: var(--band-stroke);
  stroke-width: 1.5;
}

.svg-line {
  stroke: var(--chart-line);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.svg-dot {
  fill: var(--chart-dot);
  stroke: var(--bg-card);
  stroke-width: 1.5;
}

.svg-dot-latest {
  fill: var(--accent);
  stroke: var(--bg-card);
  stroke-width: 2;
}

.svg-dot-out {
  fill: var(--danger);
  stroke: var(--bg-card);
  stroke-width: 2;
}

.svg-date-label {
  font-family: var(--font-mono);
  font-size: 9px;
  fill: var(--text-muted);
  font-weight: 600;
}

.trend-card-footer {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.range-info {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.trend-summary {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.4;
}

.empty-trends-card {
  text-align: center;
  padding: 32px 16px;
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

/* --------------------------------------------------------------------------
   Screen G: Chat Panel ("Ask about these results")
   -------------------------------------------------------------------------- */
.chat-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-header-title {
  font-size: 1.1rem;
  font-weight: 800;
}

.chat-chips-container {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
}

.chip-btn {
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 2px solid var(--border-color);
  border-bottom: 3px solid var(--border-strong);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  min-height: 38px;
  transition: transform 0.08s ease, background-color 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.chip-btn:hover {
  background-color: var(--accent-light);
  border-color: var(--accent);
}

.chip-btn:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

.chat-messages {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 4px;
  border-radius: 12px;
  background-color: var(--bg-card-subtle);
  min-height: 80px;
}

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.4;
}

.user-bubble {
  align-self: flex-end;
  background-color: var(--accent);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.mascot-reply-bubble {
  align-self: flex-start;
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 1.5px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.mascot-thinking {
  align-self: flex-start;
  background-color: var(--bg-card);
  color: var(--text-muted);
  font-style: italic;
  border: 1.5px solid var(--border-color);
}

.chat-error-bubble {
  align-self: flex-start;
  background-color: var(--danger-light);
  color: var(--danger);
  border: 1.5px solid var(--danger-border);
}

.chat-input-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-text-input {
  flex: 1;
  min-height: 48px;
  padding: 10px 14px;
  border: 2px solid var(--border-color);
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.95rem;
  background-color: var(--bg-card);
  color: var(--text-main);
}

.chat-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Screen F: Doctor View (Modal & Full Screen Panel)
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-sheet {
  background-color: var(--bg-card);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.clinical-header {
  border-bottom: 2px solid var(--border-strong);
  padding-bottom: 12px;
}

.clinical-main-title {
  font-size: 1.3rem;
  font-weight: 900;
}

.clinical-dates, .clinical-meta {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 4px;
}

.clinical-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.clinical-table-wrapper {
  margin-top: 14px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.clinical-test-title {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.clinical-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  text-align: left;
}

.clinical-table th, .clinical-table td {
  padding: 8px 10px;
  border: 1px solid var(--border-color);
}

.clinical-table th {
  background-color: var(--bg-card-subtle);
  font-weight: 800;
}

.flagged-row {
  background-color: var(--danger-light);
}

.flag-cell {
  color: var(--danger);
  font-weight: 900;
}

/* --------------------------------------------------------------------------
   Habit Celebration Overlay
   -------------------------------------------------------------------------- */
.celebration-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(13, 148, 136, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  backdrop-filter: blur(4px);
}

.celebration-overlay.active {
  display: flex;
}

.celebration-card {
  background-color: var(--bg-card);
  border: 3px solid var(--duo-green);
  border-bottom: 6px solid var(--duo-green-shadow);
  border-radius: 28px;
  padding: 32px 28px;
  text-align: center;
  max-width: 380px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.15);
  animation: celebratePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes celebratePop {
  0% { transform: scale(0.8) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.celebration-emoji {
  font-size: 3.5rem;
  margin-bottom: 10px;
  animation: floatEmoji 1.5s ease-in-out infinite alternate;
}

@keyframes floatEmoji {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-6px) scale(1.08); }
}

.celebration-title {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--duo-green);
  letter-spacing: -0.3px;
}

.celebration-subtitle {
  font-size: 0.98rem;
  font-weight: 700;
  margin-top: 8px;
  color: var(--text-main);
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
.app-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: var(--text-main);
  color: var(--bg-card);
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 0.9rem;
  font-weight: 700;
  z-index: 1500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
}

.app-toast.toast-show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-error {
  background-color: var(--danger);
  color: #ffffff;
}

.toast-success {
  background-color: #15803d;
  color: #ffffff;
}

/* --------------------------------------------------------------------------
   Medical Disclaimer Footer
   -------------------------------------------------------------------------- */
.app-footer {
  margin-top: auto;
  padding: 24px 16px;
  text-align: center;
  border-top: 2px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

.footer-disclaimer {
  max-width: 500px;
  margin: 0 auto;
  font-weight: 600;
}

.footer-meta {
  margin-top: 8px;
  font-size: 0.75rem;
  opacity: 0.85;
}

/* --------------------------------------------------------------------------
   Technical Concept: Print CSS
   Print CSS uses @media print queries to isolate the clean black-and-white clinical tables,
   enforcing A4 sizing and preventing awkward page-break splits across table rows.
   -------------------------------------------------------------------------- */
@media print {
  body {
    background-color: #ffffff !important;
    color: #000000 !important;
  }

  .app-container, .app-footer, .no-print, .theme-toggle-btn, .header-actions {
    display: none !important;
  }

  #doctor-modal {
    display: block !important;
    position: static !important;
    background: transparent !important;
    padding: 0 !important;
  }

  .modal-sheet {
    max-width: 100% !important;
    max-height: none !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .clinical-table-wrapper {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-bottom: 24px;
  }

  .clinical-table th, .clinical-table td {
    border: 1px solid #000000 !important;
    color: #000000 !important;
    background: #ffffff !important;
  }

  .flagged-row {
    background: #f1f1f1 !important;
  }

  .flag-cell strong {
    font-weight: 900 !important;
  }
}

/* --------------------------------------------------------------------------
   Reduced Motion Accessibility
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .btn:active {
    transform: none !important;
  }
  .mascot-avatar-wrapper:hover {
    transform: none !important;
  }
}

/* ===== Login page and account bar ===== */
.auth-page {
  max-width: 420px;
  margin: 0 auto;
  padding: 32px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-brand {
  align-self: center;
  font-size: 1.8rem;
}

.auth-mascot {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-mascot .mascot-avatar {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 6px;
  background: var(--bg-card-subtle);
  border: 2px solid var(--border-color);
  border-radius: 16px;
  margin-bottom: 18px;
}

.auth-tab {
  font: inherit;
  font-weight: 800;
  min-height: 44px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.auth-tab.active {
  background: var(--bg-card);
  color: var(--accent);
  border-color: var(--border-color);
  border-bottom: 3px solid var(--border-strong);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.auth-tab:active {
  transform: translateY(2px);
}

.auth-tab:focus-visible,
.link-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-label {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.auth-input {
  width: 100%;
  min-height: 44px;
}

.auth-error {
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 700;
  min-height: 20px;
}

.auth-notice {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
}

.auth-notice:empty {
  display: none;
}

.auth-submit {
  width: 100%;
  min-height: 48px;
}

.auth-boundary {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.account-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: -4px 0 12px;
  overflow-wrap: anywhere;
}

.link-btn {
  font: inherit;
  font-weight: 800;
  background: none;
  border: none;
  padding: 8px 4px;
  color: var(--accent);
  cursor: pointer;
}

/* "+ Add person" pulses when there's nobody yet */
.needs-attention {
  box-shadow: 0 0 0 0 var(--accent);
  animation: attention-pulse 1.8s ease-out infinite;
}

@keyframes attention-pulse {
  0% { box-shadow: 0 0 0 0 rgba(13, 148, 136, 0.55); }
  70% { box-shadow: 0 0 0 12px rgba(13, 148, 136, 0); }
  100% { box-shadow: 0 0 0 0 rgba(13, 148, 136, 0); }
}

/* Spinner inside a button while it works */
.btn-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-loading::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 3px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.8s linear infinite;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .needs-attention { animation: none; outline: 3px solid var(--accent); }
  .btn-loading::before { animation: none; border-right-color: currentColor; opacity: 0.6; }
}

/* Password box with a show/hide button inside it */
.password-field {
  position: relative;
}

.password-field .auth-input {
  padding-right: 52px;
}

.reveal-btn {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 10px;
}

.reveal-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

/* ===== Dr. Bindu: the rigged mascot (see mascot.js) ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mascot-avatar-wrapper {
  width: 88px;
  height: 88px;
  overflow: visible;          /* waving hands and confetti may leave the circle */
  cursor: pointer;
}

.mascot-avatar-wrapper:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.bindu {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.landing-hero .bindu {
  width: 128px;
  height: 132px;
}

.auth-mascot .bindu {
  width: 80px;
  height: 84px;
  flex-shrink: 0;
}

.bindu .b-sleeve {
  fill: none;
  stroke: #ffffff;
  stroke-width: 8;
  stroke-linecap: round;
}

.bindu .b-arms {
  filter: drop-shadow(0 0 0.7px #94a3b8);
}

.bindu .b-hand {
  fill: #fcd34d;
}

/* Everything pose-specific starts hidden; the pose class shows its parts. */
.bindu .b-arms,
.bindu .b-prop,
.bindu .b-happy-eyes,
.bindu .b-mouth,
.bindu .b-mouth-talk,
.bindu .b-dots,
.bindu .b-confetti {
  display: none;
}

.pose-wave .arms-wave,
.pose-smile .arms-rest,
.pose-pointing .arms-point,
.pose-reading .arms-hold,
.pose-calendar .arms-hold,
.pose-thinking .arms-chin,
.pose-shrug .arms-shrug,
.pose-celebrate .arms-up,
.pose-reading .b-clipboard,
.pose-calendar .b-calendar,
.pose-thinking .b-dots,
.pose-celebrate .b-happy-eyes {
  display: inline;
}

.pose-wave .m-smile,
.pose-smile .m-smile,
.pose-pointing .m-soft,
.pose-reading .m-soft,
.pose-calendar .m-soft,
.pose-shrug .m-soft,
.pose-thinking .m-o,
.pose-celebrate .m-grin {
  display: inline;
}

.pose-celebrate .b-look {
  display: none;
}

/* Talking: the pose mouth gives way to a flapping one while the words type out. */
.bindu.talking .b-mouth {
  display: none !important;
}

.bindu.talking .b-mouth-talk {
  display: inline;
  transform-box: fill-box;
  transform-origin: center;
  animation: b-talk 0.18s ease-in-out infinite alternate;
}

@keyframes b-talk {
  from { transform: scaleY(0.3); }
  to { transform: scaleY(1); }
}

/* Idle life: breathing, a slight head bob, blinking. */
.bindu .b-all {
  transform-box: view-box;
  transform-origin: 60px 118px;
  animation: b-breathe 3.6s ease-in-out infinite;
}

@keyframes b-breathe {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.018); }
}

.bindu .b-head {
  animation: b-bob 3.6s ease-in-out infinite;
}

@keyframes b-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-0.9px); }
}

.bindu .b-eyes circle {
  transform-box: fill-box;
  transform-origin: center;
  animation: b-blink 4.3s infinite;
}

@keyframes b-blink {
  0%, 93%, 100% { transform: scaleY(1); }
  96% { transform: scaleY(0.1); }
}

/* Where she looks, by pose (the pointer-following offset sits on top of this). */
.bindu .b-eyes {
  transition: transform 0.25s ease;
}

.pose-reading .b-eyes { transform: translate(0, 1.8px); }
.pose-calendar .b-eyes { transform: translate(0, 1.4px); }
.pose-thinking .b-eyes { transform: translate(1.6px, -1.8px); }
.pose-pointing .b-eyes { transform: translate(1.8px, -0.6px); }

/* Brows carry the mood: calm concern when pointing at red results, raised when shrugging or thinking. */
.bindu .brow-l,
.bindu .brow-r {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.25s ease;
}

.pose-pointing .brow-l { transform: rotate(-6deg); }
.pose-pointing .brow-r { transform: rotate(6deg); }
.pose-shrug .brow-l,
.pose-shrug .brow-r { transform: translateY(-2.5px); }
.pose-thinking .brow-l { transform: translateY(-2px) rotate(-4deg); }
.pose-celebrate .brow-l,
.pose-celebrate .brow-r { transform: translateY(-2px); }

/* Waving and pointing arms move from the shoulder. */
.bindu .b-wave-arm {
  transform-box: view-box;
  transform-origin: 87px 85px;
  animation: b-wave 1.1s ease-in-out infinite;
}

@keyframes b-wave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-14deg); }
  75% { transform: rotate(9deg); }
}

.bindu .b-point-arm {
  animation: b-point 1.4s ease-in-out infinite;
}

@keyframes b-point {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(1.5px, -1px); }
}

/* Thinking dots rise one after another. */
.bindu .b-dots circle {
  fill: #94a3b8;
  animation: b-dot 1.2s ease-in-out infinite;
}

.bindu .b-dots circle:nth-child(2) { animation-delay: 0.2s; }
.bindu .b-dots circle:nth-child(3) { animation-delay: 0.4s; }

@keyframes b-dot {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

/* Celebration: a jump and a burst of confetti. */
.bindu.b-jump {
  animation: b-jump 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes b-jump {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-12px) scale(1.04, 0.98); }
  60% { transform: translateY(0) scale(1.03, 0.96); }
  100% { transform: translateY(0) scale(1); }
}

.pose-celebrate.b-jump .b-confetti {
  display: inline;
}

.bindu .b-confetti > * {
  transform-box: fill-box;
  transform-origin: center;
  animation: b-confetti 1.1s ease-out forwards;
}

@keyframes b-confetti {
  0% { opacity: 1; transform: translateY(8px) rotate(0deg); }
  100% { opacity: 0; transform: translateY(-14px) rotate(160deg); }
}

/* Tap: a quick bounce. */
.mascot-avatar-wrapper.b-bounce {
  animation: b-bounce 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes b-bounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.14) rotate(-4deg); }
  70% { transform: scale(0.96) rotate(2deg); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .bindu *,
  .bindu,
  .mascot-avatar-wrapper.b-bounce {
    animation: none !important;
  }
}

/* =====================================================================
   Layout v2: top bar, drawer, profile, person bar, tabs, cards, review
   ===================================================================== */
[hidden] { display: none !important; }

/* Selects: room for the chevron so text never runs under it (fix for the overlap) */
.app-select {
  padding-right: 42px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 14px center;
  background-size: 16px 16px;
}

.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  vertical-align: middle;
}

[data-icon] {
  display: inline-flex;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-block { width: 100%; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 2px solid var(--danger);
}

.btn-danger:hover { background: var(--danger); color: #fff; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn-accent:hover { color: #fff; filter: brightness(1.08); }
.icon-btn:focus-visible, .avatar-btn:focus-visible, .tab:focus-visible, .menu-item:focus-visible,
.drawer-button:focus-visible, .history-item:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border-color);
}

.topbar-brand {
  justify-self: center;
  font-size: 1.35rem;
  font-weight: 900;
  color: var(--text-main);
  text-decoration: none;
}

.avatar-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font: 800 0.95rem var(--font-main);
  cursor: pointer;
}

.profile-wrap { position: relative; }

.profile-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 240px;
  padding: 12px;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
}

.profile-name { font-weight: 800; margin: 0; overflow-wrap: anywhere; }
.profile-email { font-size: 0.85rem; color: var(--text-muted); margin: 2px 0 10px; overflow-wrap: anywhere; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--text-main);
  font: 700 0.95rem var(--font-main);
  text-align: left;
  cursor: pointer;
}

.menu-item:hover { background: var(--bg-card-subtle); }

/* Drawer (hamburger menu) */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 60;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(320px, 86vw);
  padding: 16px;
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: drawer-in 0.2s ease-out;
}

@keyframes drawer-in {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.drawer-title { font-weight: 900; font-size: 1.2rem; }

.drawer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 6px 8px;
  border-radius: 12px;
  font-weight: 700;
  color: var(--text-main);
  text-decoration: none;
}

.drawer-row > span:nth-child(2) { flex: 1; }
.drawer-button { border: none; background: none; font: inherit; font-weight: 700; cursor: pointer; width: 100%; text-align: left; }
.drawer-button:hover { background: var(--bg-card-subtle); }
.drawer-select { width: auto; min-width: 130px; min-height: 40px; }
.drawer-foot { margin-top: auto; font-size: 0.8rem; color: var(--text-muted); }

.switch {
  appearance: none;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Whose results */
.person-bar {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 14px 0 6px;
}

.person-select-wrap { flex: 1; min-width: 0; }
.person-select { font-size: 1.05rem; font-weight: 800; }
.person-meta { margin: 4px 0 0 4px; font-size: 0.85rem; color: var(--text-muted); font-weight: 700; min-height: 1.2em; }

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin: 8px 0 14px;
  background: var(--bg-card-subtle);
  border-radius: 16px;
  position: sticky;
  top: 66px;
  z-index: 30;
}

.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  font: 800 0.92rem var(--font-main);
  cursor: pointer;
}

.tab.active { background: var(--bg-card); color: var(--accent); box-shadow: var(--shadow-sm); }
.tab-panel { display: flex; flex-direction: column; gap: 14px; }

.card-title { font-size: 1.1rem; font-weight: 800; margin: 0; }
.card-hint { font-size: 0.85rem; color: var(--text-muted); margin: 4px 0 10px; }
.section-label { font-size: 0.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 16px 0 6px; }
.field-label { display: block; font-weight: 700; font-size: 0.85rem; margin-bottom: 4px; }

/* Latest report summary */
.summary-card { border-left: 5px solid var(--accent); }
.summary-head { display: flex; gap: 12px; align-items: flex-start; }
.summary-icon { color: var(--accent); background: var(--accent-light); border-radius: 12px; padding: 8px; display: inline-flex; }
.summary-text { font-size: 1rem; line-height: 1.6; margin: 8px 0 12px; }

/* Result cards */
.tc-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tc-head .test-name { margin: 0; }
.tc-value { display: flex; align-items: baseline; gap: 6px; margin: 6px 0 2px; }
.tc-value .test-value { font-family: var(--font-mono); font-size: 2rem; font-weight: 600; }
.tc-dir { color: var(--text-muted); align-self: center; }
.value-danger .test-value, .value-danger .tc-dir { color: var(--danger); }

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
  background: var(--bg-card-subtle);
  color: var(--text-muted);
}

.pill-high, .pill-low { background: var(--danger-light, #fee2e2); color: var(--danger); }
.pill-normal { background: var(--accent-light); color: var(--accent-active, var(--accent)); }

.range-bar { margin: 12px 0 4px; }
.rb-track { position: relative; height: 12px; border-radius: 999px; background: var(--bg-card-subtle); }
.rb-zone { position: absolute; top: 0; bottom: 0; background: var(--accent-light); border: 2px solid var(--accent); border-radius: 999px; }
.rb-marker {
  position: absolute;
  top: 50%;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: var(--accent);
  border: 3px solid var(--bg-card);
  box-shadow: 0 0 0 2px var(--accent);
}

.rb-high, .rb-low { background: var(--danger); box-shadow: 0 0 0 2px var(--danger); }
.rb-labels { position: relative; height: 18px; margin-top: 4px; font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }
.rb-limit { position: absolute; transform: translateX(-50%); }
.tc-diff { font-weight: 800; margin: 4px 0 6px; }
.tc-diff-high, .tc-diff-low { color: var(--danger); }
.tc-diff-normal { color: var(--accent-active, var(--accent)); }
.tc-history { margin: 6px 0; }
.tc-history-label { font-size: 0.75rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* History */
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.history-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: var(--text-main);
}

.history-icon { color: var(--accent); background: var(--accent-light); border-radius: 12px; padding: 10px; display: inline-flex; }
.history-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.history-date { font-weight: 800; font-size: 1.05rem; }
.history-meta { font-size: 0.85rem; color: var(--text-muted); overflow-wrap: anywhere; }
.history-chevron { color: var(--text-muted); }
.history-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-muted); text-align: center; }

/* Modals */
.modal-narrow { max-width: 440px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-title { font-size: 1.2rem; font-weight: 800; margin: 0; }
.modal-intro { color: var(--text-muted); margin: 6px 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field { flex: 1 1 140px; min-width: 0; }
.field-small { flex: 0 1 110px; }
.field .date-input, .field .app-select { width: 100%; }
.check-row { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; min-height: 44px; }
.check-row input { width: 22px; height: 22px; accent-color: var(--accent); }
.form-error { color: var(--danger); font-weight: 700; font-size: 0.9rem; min-height: 1.2em; }
.loading-line { color: var(--text-muted); }

/* Review: name check, values editor */
.name-banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 14px; margin: 12px 0; font-weight: 700; }
.name-banner p { margin: 0; }
.banner-ok { background: var(--accent-light); color: var(--accent-active, var(--accent)); }
.banner-warn { background: #fef3c7; color: #92400e; }
.banner-danger { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .banner-warn { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .banner-danger { background: #450a0a; color: #fca5a5; }
.review-thumb { display: block; max-width: 100%; max-height: 180px; margin: 8px auto; border-radius: 12px; border: 2px solid var(--border-color); }
.review-analysis { margin-top: 10px; }

.rows-editor { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.edit-rows { display: flex; flex-direction: column; gap: 8px; }
.edit-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr 44px;
  gap: 6px;
  align-items: center;
}

.edit-row .date-input { width: 100%; min-width: 0; padding: 8px; font-size: 0.9rem; }
.edit-row-head { font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; }
.rows-editor .er-add { align-self: flex-start; }

@media (max-width: 560px) {
  .edit-row-head { display: none; }
  .edit-row {
    grid-template-columns: 1fr 1fr 44px;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 14px;
  }
  .edit-row .er-name { grid-column: 1 / 3; }
  .edit-row .er-remove { grid-column: 3; grid-row: 1; }
}

/* A saved report */
.values-table { width: 100%; border-collapse: collapse; }
.values-table th { text-align: left; font-size: 0.72rem; text-transform: uppercase; color: var(--text-muted); padding: 6px 4px; }
.values-table td { padding: 10px 4px; border-top: 1px solid var(--border-color); vertical-align: top; font-weight: 700; }
.vt-range { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); }
.vt-value { font-family: var(--font-mono); white-space: nowrap; }
.report-photo-box summary { cursor: pointer; font-weight: 800; margin: 14px 0 8px; }
.report-photo { width: 100%; border-radius: 12px; border: 2px solid var(--border-color); }
.report-no-photo { display: flex; gap: 8px; align-items: center; color: var(--text-muted); }

.empty-icon .icon { width: 40px; height: 40px; color: var(--text-muted); }
.celebration-icon { color: var(--accent); display: flex; justify-content: center; }
.celebration-icon .icon { width: 56px; height: 56px; }
.node-circle .icon { width: 18px; height: 18px; }

/* Values editor v2: each result is a small card with labelled boxes, in pairs on phones */
.edit-row,
.edit-row-head {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr 44px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 2px solid var(--border-color);
  border-radius: 14px;
}

.er-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.er-label { font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.edit-row .er-remove { align-self: end; }

@media (max-width: 560px) {
  .edit-row {
    grid-template-columns: 1fr 1fr 44px;
  }
  .edit-row .er-name-field { grid-column: 1 / 3; grid-row: 1; }
  .edit-row .er-remove { grid-column: 3; grid-row: 1; }
  .edit-row .er-value-field { grid-column: 1; grid-row: 2; }
  .edit-row .er-unit-field { grid-column: 2; grid-row: 2; }
  .edit-row .er-low-field { grid-column: 1; grid-row: 3; }
  .edit-row .er-high-field { grid-column: 2; grid-row: 3; }
}


/* ---------- Quick analysis for visitors with no account ---------- */
.topbar-analyze { grid-template-columns: 44px 1fr auto; }
.topbar-lang { max-width: 132px; font-size: 0.9rem; }

/* "Nothing is saved" sits under the buttons, quiet but present. */
.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text-muted);
}
.privacy-note svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }

/* The one thing a single report cannot do: show what changed. */
.upsell-card {
  border: 2px dashed var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.upsell-card .btn-block { margin-top: 2px; }
#analyze-results { display: flex; flex-direction: column; gap: 16px; }

/* Narrow phones: the header holds brand, badge, language and theme without pushing anything off. */
@media (max-width: 400px) {
  .app-header { gap: 6px; }
  .header-left { min-width: 0; gap: 6px; }
  .header-actions { gap: 6px; }
  .header-actions .app-select { min-width: 96px; padding-right: 34px; font-size: 0.85rem; }
}

/* ---------- Comparison with the previous report ---------- */
/* Said in words first, then drawn as one bar per report. */
.tc-compare {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--bg-card-subtle);
  border-left: 4px solid var(--border-strong);
}
.tc-compare-rising { border-left-color: var(--danger); }
.tc-compare-falling { border-left-color: var(--accent); }
.tc-compare-stable, .tc-compare-first { border-left-color: var(--border-strong); }
.tc-compare-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.tc-compare-text {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--text-main);
  margin: 0;
}

.bar-compare { margin: 14px 0 0 0; }
/* Room above for the value labels and below for the dates. */
.bc-plot {
  position: relative;
  height: 124px;
  margin: 22px 0 24px 0;
  border-bottom: 2px solid var(--border-color);
}
/* The normal range, behind the bars, measured from the same bottom line. */
.bc-band {
  position: absolute;
  left: 0;
  right: 0;
  background: var(--band-fill);
  border-top: 1px dashed var(--band-stroke);
  border-bottom: 1px dashed var(--band-stroke);
}
.bc-cols {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.bc-col { position: relative; flex: 1; min-width: 0; }
.bc-bar {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 62%;
  max-width: 34px;
  border-radius: 6px 6px 0 0;
  background: var(--accent);
}
.bc-normal { background: var(--accent); }
.bc-high, .bc-low { background: var(--danger); }
.bc-unknown { background: var(--border-strong); }
/* Earlier reports step back so the newest one reads as "now". */
.bc-col:not(.bc-col-latest) .bc-bar { opacity: 0.5; }
.bc-value {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.bc-col-latest .bc-value { color: var(--text-main); font-weight: 700; font-size: 0.8rem; }
.bc-date {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.bc-caption {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* The comparison chart waits behind a button, so a screen of cards stays scannable. */
.tc-compare-btn {
  margin-top: 12px;
  width: 100%;
  gap: 8px;
}
.tc-compare-btn svg { width: 17px; height: 17px; }
.tc-chart[hidden] { display: none; }

/* The printed limits, drawn straight across the chart and labelled with their number. */
.bc-limit {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px dashed var(--accent-hover);
  pointer-events: none;
}
.bc-limit-low { border-top-style: dotted; opacity: 0.75; }
.bc-limit-value {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--accent-hover);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--accent-hover);
  line-height: 1.3;
}
/* Bars keep clear of the limit labels on the right. */
.bc-cols { right: 40px; }
