/* =========================================================================
   TailoredHealth Design System — Colors, Type, & Component Tokens
   -------------------------------------------------------------------------
   Adapted from /tailoredhealth-design-system/project/colors_and_type.css
   plus the website UI kit (Nav, ProfileCard, FormulaCard, Sections).

   Scoped to .th-scope so it only applies to surfaces we've explicitly
   converted (currently: the /dashboard layout). The rest of the app is
   untouched.
   ========================================================================= */

/* ---------- Webfonts ----------------------------------------------------- */
@font-face {
  font-family: "Aeonik Pro";
  src: url(/assets/aeonikpro-regular-cce863306a54970d3f5bee73b30f2647aca98c8bdd8437d96bf588fb38d4f8e5.otf) format("opentype");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Aeonik Mono";
  src: url(/assets/aeonikmono-regular-98ab99698b7778db6366062fb676f335d276c9b0cf0ebebafa3ace511f2bc7f6.otf) format("opentype");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Ivar Display";
  src: url(/assets/IvarDisplay-Italic-cb92089c39da6fd6684a1cb58c4bbb21a251399328d2cea4a206f0ed990f6bbb.otf) format("opentype");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

/* ---------- Tokens ------------------------------------------------------- */
.th-scope {
  /* Primary */
  --th-midnight:   #162A2C;
  --th-midnight-2: #010C11;
  --th-charcoal:   #1E1E1E;
  --th-snow:       #FFFFFF;

  /* Warm neutrals */
  --th-cream:      #F3EEE7;
  --th-bone:       #F7F5F1;
  --th-sand:       #E5E2DC;
  --th-stone:      #525252;
  --th-mist:       #88847C;

  /* Tertiary accents */
  --th-moss:       #CBD1B7;
  --th-lilac:      #B4BBD6;

  /* Status */
  --th-good:       #EAF3EA;
  --th-good-fg:    #538574;
  --th-warn:       #F4E8BD;
  --th-warn-fg:    #8a7300;
  --th-bad:        #FFE8E8;
  --th-bad-fg:     #B23A3A;

  /* Semantic */
  --th-fg-1:       var(--th-charcoal);
  --th-fg-2:       rgba(30, 30, 30, 0.7);
  --th-fg-3:       rgba(30, 30, 30, 0.5);
  --th-fg-on-dark: var(--th-snow);
  --th-fg-on-dark-2: rgba(255, 255, 255, 0.7);
  --th-fg-brand:   var(--th-midnight);

  --th-bg-page:    var(--th-cream);
  --th-bg-paper:   var(--th-cream);
  --th-bg-panel:   var(--th-bone);
  --th-bg-card:    var(--th-snow);
  --th-bg-dark:    var(--th-midnight);

  --th-border-1:   rgba(22, 42, 44, 0.12);
  --th-border-2:   rgba(22, 42, 44, 0.20);
  --th-rule:       var(--th-midnight);

  /* Type */
  --th-font-sans: "Aeonik Pro", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --th-font-mono: "Aeonik Mono", ui-monospace, "Roboto Mono", monospace;
  --th-font-display-italic: "Ivar Display", "Aeonik Pro", Georgia, serif;

  /* Shape */
  --th-radius-xs:   8px;
  --th-radius-sm:   12px;
  --th-radius-md:   16px;
  --th-radius-lg:   20px;
  --th-radius-pill: 9999px;

  --th-shadow-card:     0 1px 2px rgba(22, 42, 44, 0.04), 0 8px 24px rgba(22, 42, 44, 0.06);
  --th-shadow-floating: 0 8px 32px rgba(22, 42, 44, 0.12), 0 1px 2px rgba(22, 42, 44, 0.06);
  --th-shadow-pressed:  inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 1px 0 rgba(22, 42, 44, 0.06);

  /* Motion */
  --th-ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --th-t-fast:      120ms;
  --th-t-base:      220ms;
}

/* ---------- Element resets (scoped) ------------------------------------- */
.th-scope {
  font-family: var(--th-font-sans);
  font-size: 18px;
  line-height: 1.55;
  color: var(--th-fg-1);
  background: var(--th-bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.th-scope .th-em-italic {
  font-family: var(--th-font-display-italic);
  font-style: italic;
  font-weight: 400;
}

/* ---------- Typography utilities ---------------------------------------- */
.th-eyebrow {
  font-family: var(--th-font-sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--th-fg-1);
}
.th-eyebrow-mini { font-size: 10px; opacity: 0.7; }

.th-h1 {
  font: 400 clamp(36px, 4.4vw, 56px)/1.04 var(--th-font-sans);
  letter-spacing: -0.02em;
  color: var(--th-midnight);
  margin: 0;
}
.th-h1 em, .th-h1 .th-em-italic {
  font-family: var(--th-font-display-italic);
  font-style: italic;
  font-weight: 400;
}

.th-h2 {
  font: 400 clamp(28px, 3.2vw, 40px)/1.08 var(--th-font-sans);
  letter-spacing: -0.015em;
  color: var(--th-midnight);
  margin: 0;
}
.th-h2 em { font-family: var(--th-font-display-italic); font-style: italic; font-weight: 400; }

.th-h3 {
  font: 500 20px/1.2 var(--th-font-sans);
  letter-spacing: 0;
  color: var(--th-midnight);
  margin: 0;
}

.th-body { font: 400 16px/1.55 var(--th-font-sans); color: var(--th-fg-1); }
.th-body-sm { font: 400 14px/1.55 var(--th-font-sans); color: var(--th-fg-2); }
.th-mono { font-family: var(--th-font-mono); font-size: 12px; letter-spacing: 0.02em; color: var(--th-fg-2); }

.th-rule { border: 0; border-top: 1px solid var(--th-rule); margin: 0; opacity: 0.9; }

/* ---------- Buttons (pill-shaped, brand signature) ---------------------- */
.th-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 24px;
  border-radius: var(--th-radius-pill);
  border: 0;
  font: 500 14px/1 var(--th-font-sans);
  cursor: pointer;
  transition: background var(--th-t-base) var(--th-ease-out), color var(--th-t-base) var(--th-ease-out), transform var(--th-t-fast) var(--th-ease-out);
  text-decoration: none;
  white-space: nowrap;
}
.th-btn-primary { background: var(--th-midnight); color: var(--th-snow); }
.th-btn-primary:hover { background: #22383a; color: var(--th-snow); }
.th-btn-primary:active { transform: scale(0.99); box-shadow: var(--th-shadow-pressed); }

.th-btn-secondary {
  background: var(--th-snow);
  color: var(--th-midnight);
  border: 1px solid var(--th-border-1);
}
.th-btn-secondary:hover { background: var(--th-bone); }

.th-btn-ghost {
  background: transparent;
  color: var(--th-midnight);
  padding: 0 16px;
  height: 36px;
}
.th-btn-ghost:hover { background: rgba(22, 42, 44, 0.06); }

.th-btn-sm { height: 36px; padding: 0 18px; font-size: 13px; }

.th-link-underline {
  color: var(--th-fg-1);
  text-decoration: underline;
  text-underline-offset: 3px;
  font: 400 14px/1 var(--th-font-sans);
  transition: color var(--th-t-base) var(--th-ease-out);
}
.th-link-underline:hover { color: var(--th-midnight); text-decoration: none; }

/* ---------- Cards ------------------------------------------------------- */
.th-card {
  background: var(--th-bg-card);
  border-radius: var(--th-radius-md);
  padding: 24px;
  box-shadow: var(--th-shadow-card);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.th-card-floating { box-shadow: var(--th-shadow-floating); }
.th-card-panel { background: var(--th-bg-panel); box-shadow: none; }
.th-card-dark { background: var(--th-midnight); color: var(--th-fg-on-dark); }
.th-card-dark .th-h3 { color: var(--th-fg-on-dark); }
.th-card-dark .th-mono { color: var(--th-fg-on-dark-2); }

a.th-card { text-decoration: none; color: inherit; transition: box-shadow var(--th-t-base) var(--th-ease-out), transform var(--th-t-fast) var(--th-ease-out); }
a.th-card:hover { box-shadow: var(--th-shadow-floating); }
a.th-card:active { transform: translateY(1px); }

/* ---------- Tags / chips ------------------------------------------------ */
.th-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.th-tag {
  padding: 6px 12px;
  border-radius: var(--th-radius-xs);
  background: var(--th-bone);
  font: 500 12px/1 var(--th-font-sans);
  color: var(--th-fg-1);
}

.th-chip {
  padding: 4px 10px;
  border-radius: var(--th-radius-pill);
  font: 500 11px/1 var(--th-font-sans);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.th-dot { width: 5px; height: 5px; border-radius: 999px; flex-shrink: 0; }
.th-chip-good { background: var(--th-good); color: var(--th-good-fg); }
.th-chip-good .th-dot { background: var(--th-good-fg); }
.th-chip-warn { background: var(--th-warn); color: var(--th-warn-fg); }
.th-chip-warn .th-dot { background: var(--th-warn-fg); }
.th-chip-bad  { background: var(--th-bad);  color: var(--th-bad-fg); }
.th-chip-bad  .th-dot { background: var(--th-bad-fg); }
.th-chip-neutral { background: var(--th-bone); color: var(--th-fg-2); }
.th-chip-neutral .th-dot { background: var(--th-fg-2); }

/* ---------- Lab list (used in ProfileCard / FormulaCard) ---------------- */
.th-lab-list { display: flex; flex-direction: column; gap: 10px; }
.th-lab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font: 400 14px/1.3 var(--th-font-sans);
  color: var(--th-fg-1);
}
.th-lab-row > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Nav --------------------------------------------------------- */
/* The .th-nav-stack wraps the (optional) impersonation bar + the main nav so
   they scroll-stick together as one block. */
.th-nav-stack {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--th-snow);
  border-bottom: 1px solid var(--th-border-1);
}
.th-nav {
  background: var(--th-snow);
}
.th-nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 32px;
}
.th-nav-section { display: flex; align-items: center; gap: 24px; min-width: 0; }
.th-wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  text-decoration: none;
  color: var(--th-midnight);
  flex-shrink: 0;
}
.th-wm-name { font: 500 22px/1 var(--th-font-sans); letter-spacing: -0.01em; }
.th-wm-sup { font: 500 11px/1 var(--th-font-sans); letter-spacing: 0.06em; transform: translateY(-8px); display: inline-block; }

/* Brand image logo. Use .th-brand-logo--lg / --xl for splash sizing.
   Aspect ratio is fixed at the source image (1080x221 ≈ 4.886:1). */
.th-brand-logo {
  display: block;
  height: 24px;
  width: auto;
  flex-shrink: 0;
}
.th-brand-logo--sm { height: 20px; }
.th-brand-logo--md { height: 28px; }
.th-brand-logo--lg { height: 36px; }
.th-brand-logo--xl { height: clamp(56px, 9vw, 96px); }
.th-nav-eyebrow {
  border-left: 1px solid var(--th-border-1);
  padding-left: 16px;
  margin-left: 4px;
  font: 500 12px/1 var(--th-font-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--th-fg-2);
}
.th-nav-links { display: flex; align-items: center; gap: 6px; }
.th-nav-link {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 16px;
  border-radius: var(--th-radius-pill);
  color: var(--th-fg-1);
  text-decoration: none;
  font: 500 14px/1 var(--th-font-sans);
  transition: background var(--th-t-base) var(--th-ease-out), color var(--th-t-base) var(--th-ease-out);
}
.th-nav-link:hover { background: rgba(22, 42, 44, 0.06); color: var(--th-midnight); }
.th-nav-link-active {
  background: var(--th-midnight);
  color: var(--th-snow);
}
.th-nav-link-active:hover { background: #22383a; color: var(--th-snow); }

.th-nav-user { display: flex; align-items: center; gap: 10px; position: relative; }
.th-nav-user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 12px;
  background: transparent;
  border: 0;
  border-radius: var(--th-radius-pill);
  cursor: pointer;
  transition: background var(--th-t-base) var(--th-ease-out);
  font-family: var(--th-font-sans);
}
.th-nav-user-trigger:hover { background: rgba(22, 42, 44, 0.06); }
.th-avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--th-midnight);
  color: var(--th-snow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 500 13px/1 var(--th-font-sans);
  flex-shrink: 0;
}
.th-nav-user-meta { text-align: right; line-height: 1.2; }
.th-nav-user-name { font: 500 13px/1.2 var(--th-font-sans); color: var(--th-midnight); }
.th-nav-user-sub { font: 400 11px/1.2 var(--th-font-sans); color: var(--th-fg-2); }

/* .th-menu uses the existing dropdown_controller.js, which toggles
   tailwind classes (opacity-0 / invisible / scale-95, etc). We only
   provide the visual chrome here. */
.th-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 12px);
  min-width: 220px;
  background: var(--th-snow);
  border-radius: var(--th-radius-md);
  box-shadow: var(--th-shadow-floating);
  padding: 8px;
  transform-origin: top right;
  z-index: 50;
}
.th-menu-header { padding: 12px 12px 10px; border-bottom: 1px solid var(--th-border-1); margin-bottom: 4px; }
.th-menu-eyebrow { font: 500 10px/1 var(--th-font-sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--th-fg-2); margin-bottom: 4px; }
.th-menu-email { font: 500 13px/1.3 var(--th-font-sans); color: var(--th-midnight); word-break: break-all; }
.th-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: 0;
  border-radius: var(--th-radius-sm);
  color: var(--th-fg-1);
  font: 400 14px/1 var(--th-font-sans);
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--th-t-fast) var(--th-ease-out);
}
.th-menu-item:hover { background: var(--th-bone); }
.th-menu-item-active,
.th-menu-item-active:hover {
  background: var(--th-midnight);
  color: var(--th-snow);
}

/* In-dropdown primary nav (sm/md only). The links live in the DOM at all
   widths so the dropdown stays a single component, but they're hidden on
   wider screens where the inline .th-nav-links is visible instead. */
.th-menu-nav { display: none; }
.th-menu-nav-eyebrow { padding: 8px 12px 6px; }
.th-menu-divider {
  height: 1px;
  background: var(--th-border-1);
  margin: 6px -8px 4px;
}

/* ---------- Mobile nav -------------------------------------------------- */
.th-nav-toggle { display: none; }
@media (max-width: 900px) {
  .th-nav-inner { padding: 14px 20px; }
  .th-nav-links { display: none; }
  .th-nav-eyebrow { display: none; }
  .th-menu-nav { display: block; }
}

/* ---------- Page hero (cream, no photo) --------------------------------- */
.th-page-hero {
  max-width: 1280px;
  margin: 0 auto;
  padding: 56px 32px 24px;
}
@media (max-width: 900px) { .th-page-hero { padding: 32px 20px 16px; } }
.th-page-hero-eyebrow { color: var(--th-fg-2); margin-bottom: 16px; }
.th-page-hero-eyebrow .th-rule-tab {
  display: inline-block;
  width: 24px;
  height: 1px;
  background: var(--th-rule);
  vertical-align: middle;
  margin-right: 12px;
  opacity: 0.6;
}
.th-page-hero-title { margin-bottom: 16px; }
.th-page-hero-sub { color: var(--th-fg-2); max-width: 620px; }

.th-back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--th-fg-2);
  text-decoration: none;
  font: 500 12px/1 var(--th-font-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 24px;
  transition: color var(--th-t-base) var(--th-ease-out);
}
.th-back-link:hover { color: var(--th-midnight); }

/* ---------- Content container ------------------------------------------- */
.th-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 32px 96px;
}
@media (max-width: 900px) { .th-container { padding: 16px 20px 64px; } }

/* ---------- Footer ------------------------------------------------------ */
.th-footer {
  background: var(--th-midnight);
  color: var(--th-fg-on-dark);
  padding: 56px 32px 32px;
  margin-top: 48px;
}
.th-footer-inner { max-width: 1280px; margin: 0 auto; }
.th-footer-disclaimer {
  font: 400 12px/1.6 var(--th-font-sans);
  color: var(--th-fg-on-dark-2);
  max-width: 920px;
  margin-bottom: 40px;
}
.th-footer-disclaimer a { color: var(--th-fg-on-dark); text-decoration: underline; }
.th-footer-bottom {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  align-items: flex-start;
}
@media (min-width: 700px) {
  .th-footer-bottom { flex-direction: row; align-items: center; justify-content: space-between; }
}
.th-footer-copy {
  font-family: var(--th-font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
}

/* ---------- Impersonation bar (TH variant) ------------------------------ */
.th-impersonation-bar {
  position: relative;
  background: var(--th-warn);
  color: var(--th-warn-fg);
  border-bottom: 1px solid rgba(138, 115, 0, 0.18);
}
.th-impersonation-bar-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 8px 20px;
  font: 500 13px/1 var(--th-font-sans);
}
.th-impersonation-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  opacity: 0.9;
}
.th-impersonation-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(138, 115, 0, 0.22);
  color: var(--th-warn-fg);
  border-radius: var(--th-radius-pill);
  padding: 4px 12px;
  font: 500 13px/1 var(--th-font-sans);
  cursor: pointer;
  transition: background var(--th-t-base) var(--th-ease-out);
}
.th-impersonation-name:hover { background: rgba(255, 255, 255, 0.85); }
.th-btn-impersonation-exit {
  background: var(--th-warn-fg);
  color: var(--th-snow);
  height: 28px;
  padding: 0 14px;
  font-size: 12px;
}
.th-btn-impersonation-exit:hover { background: #6b5a00; color: var(--th-snow); }

/* Centered metadata panel — opens beneath the impersonation bar.
   Uses actions-dropdown_controller, which simply toggles `hidden`. */
.th-impersonation-panel {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  margin-top: 8px;
  width: min(440px, calc(100vw - 32px));
  background: var(--th-snow);
  color: var(--th-fg-1);
  border-radius: var(--th-radius-md);
  box-shadow: var(--th-shadow-floating);
  border: 1px solid var(--th-border-1);
  z-index: 60;
  overflow: hidden;
}
.th-impersonation-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--th-border-1);
  font: 500 11px/1 var(--th-font-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--th-fg-2);
}
.th-impersonation-fields { padding: 4px 0; }
.th-impersonation-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  transition: background var(--th-t-fast) var(--th-ease-out);
}
.th-impersonation-field:hover { background: var(--th-bone); }
.th-impersonation-field-label {
  font: 500 10px/1.2 var(--th-font-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--th-fg-2);
}
.th-impersonation-field-value {
  font: 400 13px/1.3 var(--th-font-sans);
  color: var(--th-midnight);
  word-break: break-all;
  margin-top: 3px;
}
.th-impersonation-field-value.th-mono { font-family: var(--th-font-mono); font-size: 12px; }
.th-impersonation-field-empty {
  font: 500 10px/1 var(--th-font-sans);
  color: var(--th-bad-fg);
  background: var(--th-bad);
  padding: 4px 8px;
  border-radius: var(--th-radius-pill);
  margin-top: 4px;
  display: inline-block;
}
.th-copy-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  border-radius: var(--th-radius-sm);
  color: var(--th-fg-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--th-t-fast) var(--th-ease-out), color var(--th-t-fast) var(--th-ease-out);
}
.th-copy-btn:hover { background: var(--th-bone); color: var(--th-midnight); }

/* =========================================================================
   PAGE-LEVEL HELPERS
   ------------------------------------------------------------------------- */

/* ---------- Section + page card ----------------------------------------- */
/* `.th-section` is the standard wrapper used between hero and footer for
   sub-pages. It mirrors `.th-container` width but with adjusted padding so
   pages can stack multiple cards inside it. */
.th-section {
  max-width: 1280px;
  margin: 0 auto;
  padding: 8px 32px 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
@media (max-width: 900px) { .th-section { padding: 8px 20px 48px; gap: 16px; } }

/* `.th-page-card` is a roomier white card used for the dense pages
   (formula, lifestyle, genetics, labs, account). Provides its own padding. */
.th-page-card {
  background: var(--th-bg-card);
  border-radius: var(--th-radius-md);
  box-shadow: var(--th-shadow-card);
  overflow: hidden;
}
.th-page-card-body { padding: 24px 28px; }
@media (max-width: 640px) { .th-page-card-body { padding: 18px 18px; } }

.th-page-card-header {
  padding: 20px 28px;
  border-bottom: 1px solid var(--th-border-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
@media (max-width: 640px) { .th-page-card-header { padding: 16px 18px; } }
.th-page-card-header-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.th-page-card-header-meta .th-eyebrow { color: var(--th-fg-2); }

/* Eyebrow + title + sub combo, used inline at the top of cards/sections */
.th-section-head { display: flex; flex-direction: column; gap: 6px; }
.th-section-head-eyebrow {
  font: 500 11px/1 var(--th-font-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--th-fg-2);
}
.th-section-head-title { font: 500 18px/1.25 var(--th-font-sans); color: var(--th-midnight); margin: 0; }
.th-section-head-sub { font: 400 13px/1.5 var(--th-font-sans); color: var(--th-fg-2); margin: 0; }

/* Soft inset panel used inside cards (was `bg-slate-50 rounded-xl`). */
.th-soft-panel {
  background: var(--th-bone);
  border-radius: var(--th-radius-sm);
  border: 1px solid var(--th-border-1);
  padding: 16px;
}
.th-soft-panel--flush { padding: 0; overflow: hidden; }

/* Small soft tile for vitals/grid stats (was the white square cards). */
.th-soft-tile {
  background: var(--th-snow);
  border: 1px solid var(--th-border-1);
  border-radius: var(--th-radius-sm);
  padding: 12px 14px;
}
.th-soft-tile--dashed { border-style: dashed; background: var(--th-bone); }
.th-soft-tile-label {
  font: 500 10px/1 var(--th-font-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--th-fg-3);
  margin-bottom: 6px;
}
.th-soft-tile-value { font: 500 14px/1.2 var(--th-font-sans); color: var(--th-midnight); }
.th-soft-tile-value--placeholder { color: var(--th-fg-3); font-style: italic; font-family: var(--th-font-display-italic); }

/* ---------- Status helpers ---------------------------------------------- */
/* Inline status pill inside table rows / list items. Slightly tighter than
   the chip variants used for hero cards. */
.th-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--th-radius-pill);
  font: 500 11px/1 var(--th-font-sans);
  white-space: nowrap;
}
.th-status--good { background: var(--th-good); color: var(--th-good-fg); }
.th-status--warn { background: var(--th-warn); color: var(--th-warn-fg); }
.th-status--bad  { background: var(--th-bad);  color: var(--th-bad-fg); }
.th-status--neutral { background: var(--th-bone); color: var(--th-fg-2); }
.th-status--midnight { background: var(--th-midnight); color: var(--th-snow); }

/* Just a colored dot (used in legends, list rows). */
.th-status-dot { width: 6px; height: 6px; border-radius: 999px; flex-shrink: 0; display: inline-block; }
.th-status-dot--good { background: var(--th-good-fg); }
.th-status-dot--warn { background: var(--th-warn-fg); }
.th-status-dot--bad  { background: var(--th-bad-fg); }
.th-status-dot--neutral { background: var(--th-fg-3); }

/* ---------- Tab pill group --------------------------------------------- */
.th-tab-group { display: flex; flex-wrap: wrap; gap: 6px; }
.th-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--th-radius-pill);
  background: var(--th-bone);
  color: var(--th-fg-2);
  font: 500 12px/1 var(--th-font-sans);
  border: 0;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--th-t-base) var(--th-ease-out), color var(--th-t-base) var(--th-ease-out);
}
.th-tab:hover { background: rgba(22, 42, 44, 0.08); color: var(--th-midnight); }
.th-tab-active, .th-tab[aria-selected="true"] {
  background: var(--th-midnight);
  color: var(--th-snow);
}
.th-tab-active:hover { background: #22383a; color: var(--th-snow); }

/* Mobile horizontal tab strip (used in labs filters). */
.th-tab-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.th-tab-scroll::-webkit-scrollbar { display: none; }
.th-tab-scroll .th-tab { flex-shrink: 0; }

/* ---------- Form inputs ------------------------------------------------- */
.th-form-label {
  display: block;
  font: 500 11px/1 var(--th-font-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--th-fg-2);
  margin-bottom: 6px;
}
.th-form-input,
.th-form-select,
.th-form-textarea {
  display: block;
  width: 100%;
  background: var(--th-snow);
  color: var(--th-midnight);
  border: 1px solid var(--th-border-1);
  border-radius: var(--th-radius-sm);
  padding: 10px 14px;
  font: 400 14px/1.4 var(--th-font-sans);
  transition: border-color var(--th-t-base) var(--th-ease-out), box-shadow var(--th-t-base) var(--th-ease-out);
  outline: 0;
  -webkit-appearance: none;
  appearance: none;
}
.th-form-input::placeholder,
.th-form-textarea::placeholder { color: var(--th-fg-3); }
.th-form-input:focus,
.th-form-select:focus,
.th-form-textarea:focus {
  border-color: var(--th-midnight);
  box-shadow: 0 0 0 3px rgba(22, 42, 44, 0.1);
}
.th-form-input:disabled,
.th-form-select:disabled {
  background: var(--th-bone);
  color: var(--th-fg-3);
  cursor: not-allowed;
}
.th-form-textarea { resize: vertical; min-height: 96px; }
.th-form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%231e1e1e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.th-form-search {
  position: relative;
}
.th-form-search > i, .th-form-search > svg, .th-form-search > [data-lucide] {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--th-fg-3);
  pointer-events: none;
}
.th-form-search > .th-form-input { padding-left: 40px; }

/* ---------- Modal ------------------------------------------------------- */
/* All TH modals use a fixed cream-tinted backdrop and a white panel with the
   floating shadow. Existing controllers (`modal`, `formula-ai-summary`,
   `formula-risk-modal`, `dashboard-labs`, `labs-report`, `report-text-modal`,
   `labs-delete`) all toggle the `hidden` class or move classes around their
   own targets — these styles only provide chrome. */
.th-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(22, 42, 44, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
/* Stimulus controllers toggle the `hidden` class to show/close modals.
   `.th-modal-backdrop` has the same specificity as `.hidden`, and since this
   stylesheet loads after Tailwind, it would otherwise win — keep `hidden`
   authoritative when both are present. */
.th-modal-backdrop.hidden { display: none; }
/* Spinner shown while modal content is loading. Uses flex but yields to
   `.hidden` so the controller can toggle it with a single class. */
.th-modal-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
}
.th-modal-loading.hidden { display: none; }
.th-modal-panel {
  background: var(--th-snow);
  color: var(--th-fg-1);
  border-radius: var(--th-radius-md);
  box-shadow: var(--th-shadow-floating);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.th-modal-panel--md { max-width: 640px; }
.th-modal-panel--lg { max-width: 800px; }
.th-modal-panel--xl { max-width: 960px; }
.th-modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--th-border-1);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.th-modal-header-title { font: 500 18px/1.2 var(--th-font-sans); color: var(--th-midnight); margin: 0; }
.th-modal-header-sub { font: 400 13px/1.4 var(--th-font-sans); color: var(--th-fg-2); margin: 4px 0 0; }
.th-modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--th-radius-pill);
  border: 0;
  background: transparent;
  color: var(--th-fg-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--th-t-fast) var(--th-ease-out), color var(--th-t-fast) var(--th-ease-out);
  flex-shrink: 0;
}
.th-modal-close:hover { background: var(--th-bone); color: var(--th-midnight); }
.th-modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.th-modal-body--flush { padding: 0; }
.th-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--th-border-1);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-shrink: 0;
  background: var(--th-bone);
}

/* Action button color variants used inside modals (pause/cancel/resume).
   These keep the pill silhouette but tint with the appropriate semantic. */
.th-btn-warn { background: var(--th-warn-fg); color: var(--th-snow); }
.th-btn-warn:hover { background: #6b5a00; color: var(--th-snow); }
.th-btn-bad { background: var(--th-bad-fg); color: var(--th-snow); }
.th-btn-bad:hover { background: #962e2e; color: var(--th-snow); }
.th-btn-good { background: var(--th-good-fg); color: var(--th-snow); }
.th-btn-good:hover { background: #426853; color: var(--th-snow); }

/* Soft variants used as "outlined" pills inside cards (e.g. "Pause" tinted
   amber) — same color family as a chip but tappable. */
.th-btn-soft-warn { background: var(--th-warn); color: var(--th-warn-fg); }
.th-btn-soft-warn:hover { background: #ecdda6; }
.th-btn-soft-bad { background: var(--th-bad); color: var(--th-bad-fg); }
.th-btn-soft-bad:hover { background: #ffd8d8; }
.th-btn-soft-good { background: var(--th-good); color: var(--th-good-fg); }
.th-btn-soft-good:hover { background: #d8e8d8; }

/* ---------- Data table (lab markers) ----------------------------------- */
.th-data-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--th-border-1);
  border-radius: var(--th-radius-sm);
  overflow: hidden;
  background: var(--th-snow);
}
.th-data-table thead th {
  background: var(--th-midnight);
  color: var(--th-snow);
  font: 500 11px/1 var(--th-font-sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 12px 14px;
  text-align: left;
}
.th-data-table thead th.th-th-center { text-align: center; }
.th-data-table tbody td {
  padding: 12px 14px;
  border-top: 1px solid var(--th-border-1);
  font: 400 14px/1.4 var(--th-font-sans);
  color: var(--th-midnight);
  vertical-align: middle;
}
.th-data-table tbody tr:hover { background: var(--th-bone); }
.th-data-table tr.th-data-table-section td {
  background: rgba(22, 42, 44, 0.04);
  font: 500 11px/1 var(--th-font-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--th-fg-2);
  padding: 8px 14px;
  border-top: 1px solid var(--th-border-1);
}
.th-data-table tr.th-row--bad td { background: rgba(178, 58, 58, 0.04); }
.th-data-table tr.th-row--warn td { background: rgba(138, 115, 0, 0.05); }

/* ---------- Misc -------------------------------------------------------- */
.th-progress-track { height: 6px; background: var(--th-bone); border-radius: var(--th-radius-pill); overflow: hidden; }
.th-progress-fill { height: 100%; background: var(--th-midnight); border-radius: var(--th-radius-pill); transition: width 700ms var(--th-ease-out); }

.th-divider { border: 0; border-top: 1px solid var(--th-border-1); margin: 0; }

/* Keyword/empty-state CTA card */
.th-empty-card {
  background: var(--th-bg-card);
  border-radius: var(--th-radius-md);
  box-shadow: var(--th-shadow-card);
  padding: 56px 24px;
  text-align: center;
}
.th-empty-card-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 18px;
  border-radius: var(--th-radius-pill);
  background: var(--th-bone);
  color: var(--th-fg-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.th-empty-card h3 { font: 500 22px/1.2 var(--th-font-sans); color: var(--th-midnight); margin: 0 0 10px; }
.th-empty-card p { color: var(--th-fg-2); margin: 0 auto 24px; max-width: 420px; }

/* Inline list with hairline rules (used for ingredient lists, profile lists). */
.th-list { display: flex; flex-direction: column; }
.th-list > * + * { border-top: 1px solid var(--th-border-1); }
.th-list-item { padding: 14px 0; }

/* Lab marker row used in the formula card hero (existing) — extend visual */

/* Override: when th-card is a link (e.g. wrapper card), allow children. */
a.th-page-card { display: block; text-decoration: none; color: inherit; transition: box-shadow var(--th-t-base) var(--th-ease-out); }
a.th-page-card:hover { box-shadow: var(--th-shadow-floating); }

@keyframes th-spin { to { transform: rotate(360deg); } }

/* ---------- Onboarding shell ------------------------------------------- */
/* Used by signin + onboarding pages that render through `application.html.erb`.
   `.th-auth-shell` provides the cream-on-cream centered layout; `.th-auth-card`
   is the white panel that holds the form. Keep both narrow (max ~480px) so the
   feel stays focused. Nest under `.th-scope` for tokens. */
.th-auth-shell {
  min-height: 100vh;
  background: var(--th-cream);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px 48px;
  position: relative;
}
.th-auth-shell--with-nav { padding-top: 96px; }
.th-auth-shell--wide .th-auth-card { max-width: 720px; }

.th-auth-card {
  background: var(--th-snow);
  width: 100%;
  max-width: 480px;
  border-radius: var(--th-radius-md);
  box-shadow: var(--th-shadow-card);
  overflow: hidden;
}
.th-auth-card-body { padding: 32px 28px; }
@media (min-width: 640px) { .th-auth-card-body { padding: 40px 36px; } }

.th-auth-header { text-align: center; margin-bottom: 28px; }
.th-auth-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--th-radius-pill);
  background: var(--th-bone);
  color: var(--th-midnight);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}
.th-auth-title {
  font: 400 28px/1.15 var(--th-font-sans);
  letter-spacing: -0.015em;
  color: var(--th-midnight);
  margin: 0 0 8px;
}
.th-auth-title em, .th-auth-title .th-em-italic {
  font-family: var(--th-font-display-italic);
  font-style: italic;
  font-weight: 400;
}
.th-auth-sub {
  font: 400 15px/1.5 var(--th-font-sans);
  color: var(--th-fg-2);
  margin: 0 auto;
  max-width: 360px;
}

.th-auth-form { display: flex; flex-direction: column; gap: 18px; }
.th-auth-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.th-auth-foot {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--th-border-1);
  text-align: center;
  font: 400 14px/1.5 var(--th-font-sans);
  color: var(--th-fg-2);
}
.th-auth-foot a { color: var(--th-midnight); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.th-auth-foot a:hover { text-decoration-thickness: 2px; }
.th-auth-foot-fine {
  margin-top: 12px;
  font-size: 12px;
  color: var(--th-fg-3);
  line-height: 1.55;
}
.th-auth-foot-fine a { color: var(--th-fg-2); text-decoration: underline; text-underline-offset: 2px; }

/* Inline alert banners for onboarding cards */
.th-alert {
  border-radius: var(--th-radius-sm);
  padding: 12px 14px;
  font: 400 14px/1.45 var(--th-font-sans);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.th-alert--bad { background: var(--th-bad); color: var(--th-bad-fg); }
.th-alert--good { background: var(--th-good); color: var(--th-good-fg); }
.th-alert--info { background: var(--th-bone); color: var(--th-midnight); }
.th-alert--warn { background: var(--th-warn); color: var(--th-warn-fg); }

/* OTP boxes — used by `magic_links/_otp_form` and `dashboard/shared/_sms_otp_form` */
.th-otp {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.th-otp-grid { display: flex; justify-content: center; gap: 8px; }
.th-otp-box {
  width: 44px;
  height: 52px;
  border-radius: var(--th-radius-xs);
  border: 1px solid var(--th-border-2);
  background: var(--th-snow);
  display: flex;
  align-items: center;
  justify-content: center;
  font: 500 22px/1 var(--th-font-mono);
  color: var(--th-midnight);
  transition: border-color var(--th-t-fast) var(--th-ease-out), background var(--th-t-fast) var(--th-ease-out);
  position: relative;
}
.th-otp-box.has-value { border-color: var(--th-midnight); background: var(--th-bone); }
.th-otp-box.next-to-fill { border-style: dashed; border-color: var(--th-midnight); background: var(--th-bone); }
.th-otp-box.empty:not(.next-to-fill) { border-color: var(--th-border-1); }
.th-otp-box--error { border-color: var(--th-bad-fg) !important; }
@keyframes th-otp-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.th-otp-box.next-to-fill::after {
  content: "";
  position: absolute;
  bottom: 22%;
  left: 50%;
  width: 2px;
  height: 50%;
  background: var(--th-midnight);
  transform: translateX(-50%);
  animation: th-otp-blink 1s infinite;
  opacity: 0;
}
.th-otp.input-focused .th-otp-box.next-to-fill::after { opacity: 1; }
.th-otp-hint { font: 400 12px/1.4 var(--th-font-sans); color: var(--th-fg-3); text-align: center; }

/* Onboarding checklist — vertical step list with completed/current/locked states */
.th-step-list { display: flex; flex-direction: column; gap: 10px; }
.th-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: var(--th-radius-sm);
  background: var(--th-bone);
  border: 1px solid var(--th-border-1);
}
.th-step--done { background: var(--th-bone); }
.th-step--done .th-step-title { color: var(--th-fg-3); text-decoration: line-through; }
.th-step--done .th-step-desc { color: var(--th-fg-3); }
.th-step--current {
  background: var(--th-snow);
  border-color: var(--th-midnight);
  box-shadow: var(--th-shadow-card);
  flex-direction: column;
  align-items: stretch;
}
.th-step--locked { opacity: 0.6; }
.th-step-row { display: flex; gap: 14px; align-items: flex-start; width: 100%; }
.th-step-marker {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--th-radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 500 13px/1 var(--th-font-sans);
}
.th-step-marker--done { background: var(--th-midnight); color: var(--th-snow); }
.th-step-marker--current { background: var(--th-midnight); color: var(--th-snow); }
.th-step-marker--locked { background: var(--th-bone); color: var(--th-fg-3); border: 1px solid var(--th-border-1); }
.th-step-body { flex: 1; min-width: 0; }
.th-step-title { font: 500 14px/1.3 var(--th-font-sans); color: var(--th-midnight); margin: 0; }
.th-step-desc { font: 400 13px/1.45 var(--th-font-sans); color: var(--th-fg-2); margin: 4px 0 0; }
.th-step-actions { display: flex; gap: 10px; margin-top: 14px; }
.th-step-actions .th-btn { flex: 1; }

/* Country/phone combo used on SMS setup */
.th-country-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: 44px;
  background: var(--th-bone);
  border: 1px solid var(--th-border-1);
  border-radius: var(--th-radius-sm);
  font: 500 14px/1 var(--th-font-sans);
  color: var(--th-fg-2);
  cursor: not-allowed;
}

/* Welcome splash — animated TailoredHealth wordmark */
.th-welcome-splash {
  min-height: 100vh;
  background: var(--th-cream);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
}
.th-welcome-splash-inner { display: flex; flex-direction: column; align-items: center; gap: 24px; }
.th-welcome-eyebrow {
  font: 400 14px/1 var(--th-font-sans);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--th-fg-2);
  opacity: 0;
  animation: th-fade-up 1.2s var(--th-ease-out) 0.1s forwards;
}
.th-welcome-wordmark {
  display: inline-flex;
  align-items: center;
  color: var(--th-midnight);
  opacity: 0;
  animation: th-fade-up 1.2s var(--th-ease-out) 0.5s forwards;
}
.th-welcome-wordmark img {
  display: block;
  height: clamp(56px, 10vw, 110px);
  width: auto;
  max-width: 80vw;
}
.th-welcome-msg {
  font: 400 16px/1.5 var(--th-font-sans);
  color: var(--th-fg-2);
  opacity: 0;
  animation: th-fade-up 1.2s var(--th-ease-out) 1.2s forwards;
}
.th-welcome-dots {
  display: inline-flex;
  gap: 6px;
  margin-left: 2px;
}
.th-welcome-dots span {
  width: 4px;
  height: 4px;
  background: var(--th-fg-2);
  border-radius: var(--th-radius-pill);
  animation: th-welcome-dot 1.4s ease-in-out infinite;
}
.th-welcome-dots span:nth-child(2) { animation-delay: 0.2s; }
.th-welcome-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes th-welcome-dot {
  0%, 80%, 100% { opacity: 0.2; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}
@keyframes th-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Drag-and-drop dropzone (labs intent) */
.th-dropzone {
  border: 1.5px dashed var(--th-border-2);
  border-radius: var(--th-radius-sm);
  background: var(--th-bone);
  padding: 28px 20px;
  text-align: center;
  transition: border-color var(--th-t-fast) var(--th-ease-out), background var(--th-t-fast) var(--th-ease-out);
}
.th-dropzone:hover { border-color: var(--th-midnight); background: var(--th-snow); }
.th-dropzone-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--th-radius-pill);
  background: var(--th-snow);
  color: var(--th-fg-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}
.th-dropzone-title { font: 500 14px/1.3 var(--th-font-sans); color: var(--th-midnight); margin: 0 0 4px; }
.th-dropzone-sub { font: 400 12px/1.4 var(--th-font-sans); color: var(--th-fg-3); margin: 0 0 16px; }
.th-page-overlay-card {
  border: 2px dashed rgba(255, 255, 255, 0.4);
  border-radius: var(--th-radius-md);
  padding: 56px 64px;
  text-align: center;
  color: var(--th-snow);
  pointer-events: none;
}
