/* ============================================================
   FamHealth — Component Styles
   Shared component layer. Uses only CSS custom properties.
   Linked after styles.css to allow overrides.
   ============================================================ */

/* ── Tabular numerics utility ────────────────────────────── */

.tnum,
.stat-value,
.ring-value,
.meal-kcal,
.progress-pct,
.editorial-number {
  font-variant-numeric: tabular-nums;
}
/* ── Glass chrome (tab bar, overlays, sync pill) ─────────── */

.glass {
  background: var(--tab-bar-bg);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--border);
}

/* ── Stat card (shared card atom) ───────────────────────── */

.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border-s);
  border-top-color: var(--edge-hi);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px;
  transition: box-shadow var(--dur-fast) var(--ease-enter),
              transform var(--dur-fast) var(--ease-enter);
}

.stat-card:active {
  transform: scale(0.98);
}

.stat-card--key {
  box-shadow: var(--shadow-glow);
}

.stat-card__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}

.stat-card__value {
  font-family: var(--font-serif);
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.stat-card__sub {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 4px;
}

/* ── Bento grid ──────────────────────────────────────────── */

.bento {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.bento-hero {
  grid-column: 1 / -1;
}

@media (min-width: 600px) {
  .bento {
    grid-template-columns: repeat(4, 1fr);
  }
  .bento-hero {
    grid-column: span 2;
  }
}

@media (max-width: 380px) {
  .bento {
    grid-template-columns: 1fr;
  }
}

/* ── Progress ring ───────────────────────────────────────── */

@property --ring-pct {
  syntax: '<number>';
  inherits: false;
  initial-value: 0;
}

.ring {
  --ring-size: 96px;
  --ring-thickness: 10px;
  position: relative;
  width: var(--ring-size);
  height: var(--ring-size);
  border-radius: 50%;
  background: conic-gradient(
    var(--ring-fill) calc(var(--ring-pct) * 1%),
    var(--ring-track) 0
  );
  transition: --ring-pct var(--dur-slow) var(--ease-spring);
  flex-shrink: 0;
}

.ring::before {
  content: '';
  position: absolute;
  inset: var(--ring-thickness);
  background: var(--surface-2);
  border-radius: 50%;
}

.ring-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  z-index: 1;
}

.ring-value {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.ring-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.ring--lg {
  --ring-size: 120px;
  --ring-thickness: 12px;
}

.ring--sm {
  --ring-size: 64px;
  --ring-thickness: 7px;
}

/* ── Sparkline ───────────────────────────────────────────── */

.sparkline {
  display: block;
  width: 100%;
  height: 32px;
  overflow: visible;
}

.sparkline-line {
  fill: none;
  stroke: var(--moss);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sparkline-area {
  opacity: 0.15;
}

/* ── Segmented control ───────────────────────────────────── */

.segmented {
  display: inline-flex;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}

.segmented__opt {
  flex: 1;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-2);
  font: 600 13px/1 var(--font);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-enter),
              color var(--dur-fast) var(--ease-enter),
              box-shadow var(--dur-fast) var(--ease-enter);
  white-space: nowrap;
}

.segmented__opt:hover {
  color: var(--ink);
}

.segmented__opt.active,
.segmented__opt[aria-checked="true"],
.segmented__opt[aria-pressed="true"] {
  background: var(--surface-1);
  color: var(--ink);
  box-shadow: var(--shadow-card);
}

@media (min-width: 600px) {
  .segmented__opt {
    min-height: 48px;
  }
}

/* ── Toast system ────────────────────────────────────────── */

.toast-host {
  position: fixed;
  bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface-4);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-float);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateY(12px);
  opacity: 0;
  transition: transform var(--dur-normal) var(--ease-enter),
              opacity var(--dur-normal) var(--ease-enter);
  max-width: min(90vw, 360px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.toast--visible {
  transform: translateY(0);
  opacity: 1;
}

.toast--success { border-left: 3px solid var(--moss); }
.toast--error   { border-left: 3px solid var(--danger); }
.toast--info    { border-left: 3px solid var(--border); }

/* ── Sync pill ───────────────────────────────────────────── */

.sync-pill {
  position: fixed;
  top: calc(52px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  transition: opacity var(--dur-fast) var(--ease-enter),
              transform var(--dur-fast) var(--ease-enter);
}

.sync-pill[hidden] {
  display: none;
}

.sync-pill--syncing { color: var(--ink-2); }
.sync-pill--synced  { color: var(--moss); }
.sync-pill--offline { color: var(--danger); }
.sync-pill--error   { color: var(--danger); }

/* ── Mesh gradient background ────────────────────────────── */

.mesh-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: inherit;
  z-index: 0;
}

.mesh-bg::before,
.mesh-bg::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(48px);
  opacity: 0.4;
}

.mesh-bg::before {
  width: 60%;
  height: 60%;
  top: -20%;
  right: -10%;
  background: radial-gradient(circle, var(--moss-tint-2), transparent 70%);
}

.mesh-bg::after {
  width: 40%;
  height: 40%;
  bottom: -10%;
  left: 10%;
  background: radial-gradient(circle, var(--accent-tint), transparent 70%);
}

@media (prefers-reduced-transparency: reduce) {
  .mesh-bg { display: none; }
}

/* ── Press / active feedback (extend global) ─────────────── */

.meal-card:active,
.recipe-chip:active,
.set-btn:active,
.workout-card:active {
  transform: scale(0.97);
}

/* ── Visually hidden (for aria-live) ────────────────────── */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Tab bar enhanced ────────────────────────────────────── */

#tab-bar {
  border-top: 1px solid var(--border-s);
}

/* ── Modal/sheet border radius upgrade ───────────────────── */

.modal {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

@media (min-width: 600px) {
  .modal {
    border-radius: var(--radius-lg);
  }
}

/* ── Tablet touch targets ────────────────────────────────── */

@media (min-width: 600px) {
  .lista-qty-btn,
  .lista-remove-btn {
    min-width: 48px;
    min-height: 48px;
  }
}

/* ── Lista quantity buttons tap target ───────────────────── */

.lista-qty-btn,
.lista-remove-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Meal action button tap target ───────────────────────── */

.meal-swap-btn,
.meal-recipe-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Achievements grid ───────────────────────────────────── */

.achievements-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.achievement-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-3);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-3);
  opacity: 0.55;
  transition: opacity var(--dur-fast) var(--ease-enter);
}

.achievement-chip.earned {
  opacity: 1;
  color: var(--ink);
  border-color: var(--moss);
  background: rgba(16, 185, 129, 0.08);
}

.achievement-icon {
  font-size: 11px;
  color: var(--moss);
}

.achievement-label {
  white-space: nowrap;
}

/* ── Exercise weight / reps row ──────────────────────────── */

.set-weight-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.set-weight-row .ex-weight-input,
.set-weight-row .ex-reps-input {
  min-height: 36px;
  padding: 0 8px;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.set-weight-row .ex-weight-input { width: 68px; }
.set-weight-row .ex-reps-input   { width: 60px; }

.set-weight-unit {
  font-size: 12px;
  color: var(--ink-2);
  flex-shrink: 0;
}


/* ── Auth gate ── */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.auth-logo {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 400;
  color: var(--moss);
  margin-bottom: 8px;
  text-align: center;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--ink-2);
  text-align: center;
  margin-bottom: 28px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-error {
  font-size: 13px;
  color: var(--danger, #c0392b);
  text-align: center;
  margin: 0;
}

/* ── Admin badge on tab button ── */

.tab-btn {
  position: relative;
}

.admin-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--danger, #c0392b);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  padding: 0 4px;
  pointer-events: none;
}
