/**
 * assets/css/app.css
 * ------------------------------------------------------------
 * Sits ON TOP OF Tailwind (loaded via CDN in partials/_head.php).
 * Tailwind's play-CDN build cannot compile @apply, so this file is
 * plain CSS: design tokens as custom properties, plus the handful of
 * components that are awkward to build from utility classes alone
 * (modal, toast, bottom nav, skeletons). Everything else - spacing,
 * grids, text - stays as Tailwind classes directly in the HTML.
 *
 * LOAD ORDER in partials/_head.php:
 *   1. <script src="https://cdn.tailwindcss.com"></script>
 *   2. tailwind.config = { theme: { extend: { colors: { brand: {...} } } } }
 *      (kept in sync with the tokens below - see the comment at the bottom)
 *   3. <link rel="stylesheet" href="<?= asset('css/app.css') ?>">
 *
 * CONTENTS
 *   1. Design tokens (colors, radii, shadows, spacing, z-index)
 *   2. Base + accessibility (focus rings, scrollbars, reduced motion)
 *   3. Buttons + form fields
 *   4. App shell (topbar, sidebar, bottom nav)
 *   5. Card, table, empty state, skeleton loaders
 *   6. Modal + confirm dialog
 *   7. Toast (success / error / info)
 *   8. Badges, avatar
 *   9. Utilities (safe-area, hide-scrollbar, truncate-2)
 */

/* ============================================================
 * 1. Design tokens
 * ========================================================== */
:root {
  /* Brand - indigo, matches the email templates in mailer.php (MAIL_BRAND_COLOR) */
  --brand-50:  #EEF2FF;
  --brand-100: #E0E7FF;
  --brand-400: #818CF8;
  --brand-500: #6366F1;
  --brand-600: #4F46E5;
  --brand-700: #4338CA;

  --ok-500:   #16A34A;
  --ok-50:    #F0FDF4;
  --warn-500: #D97706;
  --warn-50:  #FFFBEB;
  --danger-500: #DC2626;
  --danger-50:  #FEF2F2;

  --ink-900: #111827;
  --ink-700: #374151;
  --ink-500: #6B7280;
  --ink-300: #D1D5DB;
  --ink-100: #F3F4F6;
  --ink-50:  #F9FAFB;
  --surface: #FFFFFF;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.06);
  --shadow-md: 0 4px 16px rgba(17, 24, 39, 0.08);
  --shadow-lg: 0 16px 40px rgba(17, 24, 39, 0.16);

  --topbar-h:    64px;
  --bottomnav-h: 64px;
  --sidebar-w:   256px;

  --z-sidebar:  40;
  --z-topbar:   30;
  --z-bottomnav: 30;
  --z-backdrop: 50;
  --z-modal:    60;
  --z-toast:    70;

  color-scheme: light;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* Dark mode: opt-in only, via <html class="dark">. Off by default (see app.js theme note). */
html.dark {
  --ink-900: #F9FAFB;
  --ink-700: #E5E7EB;
  --ink-500: #9CA3AF;
  --ink-300: #374151;
  --ink-100: #1F2937;
  --ink-50:  #161B26;
  --surface: #111827;
  color-scheme: dark;
}

/* ============================================================
 * 2. Base + accessibility
 * ========================================================== */
html, body {
  height: 100%;
  background: var(--ink-50);
  color: var(--ink-900);
  -webkit-font-smoothing: antialiased;
}

* { -webkit-tap-highlight-color: transparent; }

/* One visible focus style for every interactive element - never remove it, only restyle it. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--ink-300); border-radius: var(--radius-pill); }
::-webkit-scrollbar-track { background: transparent; }

@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;
  }
}

/* ============================================================
 * 3. Buttons + form fields
 * Structure (Tailwind for layout) + these classes for appearance,
 * so every button/input looks the same without repeating utility
 * soup on every page.
 * ========================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.625rem 1.125rem;
  font-weight: 600; font-size: 0.9375rem; line-height: 1.25;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand-600); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-700); }

.btn-secondary { background: var(--surface); color: var(--ink-700); border-color: var(--ink-300); }
.btn-secondary:hover:not(:disabled) { background: var(--ink-100); }

.btn-danger { background: var(--danger-500); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #B91C1C; }

.btn-ghost { background: transparent; color: var(--ink-700); }
.btn-ghost:hover:not(:disabled) { background: var(--ink-100); }

.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8125rem; border-radius: var(--radius-sm); }

/* Spinner shown inside a button while a request is in flight (app.js toggles .is-loading) */
.btn .btn-spinner { display: none; width: 1rem; height: 1rem; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5); border-top-color: #fff; animation: sv-spin 0.6s linear infinite; }
.btn-secondary .btn-spinner, .btn-ghost .btn-spinner { border-color: var(--ink-300); border-top-color: var(--ink-700); }
.btn.is-loading .btn-spinner { display: inline-block; }
.btn.is-loading .btn-label { opacity: 0.7; }
.btn.is-loading { pointer-events: none; }

.field-label { display: block; font-size: 0.8125rem; font-weight: 600; color: var(--ink-700); margin-bottom: 0.375rem; }
.field-hint  { font-size: 0.8125rem; color: var(--ink-500); margin-top: 0.375rem; }
.field-error { font-size: 0.8125rem; color: var(--danger-500); margin-top: 0.375rem; }

.field-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field-input::placeholder { color: var(--ink-500); }
.field-input:focus { border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--brand-100); outline: none; }
.field-input.field-invalid { border-color: var(--danger-500); }
.field-input.field-invalid:focus { box-shadow: 0 0 0 3px var(--danger-50); }

/* Unit toggle for measurements (in / cm) - a two-option segmented control */
.segmented { display: inline-flex; padding: 3px; background: var(--ink-100); border-radius: var(--radius-pill); }
.segmented button {
  padding: 0.375rem 0.875rem; font-size: 0.8125rem; font-weight: 600; color: var(--ink-500);
  border-radius: var(--radius-pill); border: none; background: transparent; cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.segmented button.is-active { background: var(--surface); color: var(--brand-700); box-shadow: var(--shadow-sm); }

/* ============================================================
 * 4. App shell
 * Mobile: sticky topbar + fixed bottom nav, sidebar hidden.
 * Desktop (md:): sidebar visible, no bottom nav (app.js/partials add "hidden md:flex" etc).
 * ========================================================== */
.app-topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  height: var(--topbar-h);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid transparent; /* fades in via .is-scrolled, see below */
  padding-top: env(safe-area-inset-top, 0px);
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.app-topbar.is-scrolled {
  border-bottom-color: var(--ink-100);
}
html.dark .app-topbar {
  background: rgba(17, 24, 39, 0.72);
}
html.dark .app-topbar.is-scrolled {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.app-sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  z-index: var(--z-sidebar);
  background: var(--ink-50);
  box-shadow: 4px 0 24px rgba(17, 24, 39, 0.04);
  padding-top: env(safe-area-inset-top, 0px);
  transform: translateX(-100%);
  transition: transform 0.2s ease, width 0.2s ease;
}
.app-sidebar.is-open { transform: translateX(0); }
@media (min-width: 768px) {
  .app-sidebar { transform: none; }
}

.app-sidebar-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.625rem 0.875rem; margin-bottom: 0.125rem;
  border-radius: var(--radius-pill);
  color: var(--ink-700); font-weight: 500; font-size: 0.9375rem;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.app-sidebar-link:hover { background: var(--ink-100); }
.app-sidebar-link.is-active {
  background: var(--brand-600);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.app-sidebar-link.is-active:hover { background: var(--brand-700); }
html.dark .app-sidebar { background: var(--ink-50); box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3); }
.app-sidebar-link svg { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }
/* Collapsed state (desktop only) — toggled by _sidebar.php's JS via .is-collapsed */
.app-sidebar.is-collapsed { width: 72px; }
.app-sidebar.is-collapsed .sidebar-link-label { display: none; }
.app-sidebar.is-collapsed .app-sidebar-link { justify-content: center; }
@media (min-width: 768px) {
  body:has(.app-sidebar.is-collapsed) .app-main { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + 3rem); }
}
.app-backdrop {
  position: fixed; inset: 0; z-index: var(--z-backdrop);
  background: rgba(17, 24, 39, 0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.app-backdrop.is-open { opacity: 1; pointer-events: auto; }
@media (min-width: 768px) { .app-backdrop { display: none; } }

/* Floating glass pill nav — detached from the screen edge, rounded,
   translucent with backdrop blur. Two equal link-groups sit inside;
   the FAB floats centered on top, straddling the gap between them. */
.app-bottomnav {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: calc(100% - 2rem);
  max-width: 400px;
  height: var(--bottomnav-h);
  z-index: var(--z-bottomnav);
  display: flex; align-items: stretch;
  gap: 2.5rem; /* leaves room for the FAB to float centered without overlapping links */
  padding: 0 0.5rem;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow-lg);
}
html.dark .app-bottomnav {
  background: rgba(17, 24, 39, 0.72);
  border-color: rgba(255, 255, 255, 0.08);
}
@media (min-width: 768px) { .app-bottomnav { display: none; } }

.app-bottomnav-group { flex: 1; display: flex; justify-content: space-evenly; }

.app-bottomnav-link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.125rem;
  color: var(--ink-500); font-size: 0.6875rem; font-weight: 600; text-decoration: none;
}
.app-bottomnav-link svg { width: 1.375rem; height: 1.375rem; }
.app-bottomnav-link.is-active { color: var(--brand-600); }

/* "+" FAB floats above the pill, centered, straddling the gap
   between the two link groups rather than being a 5th flex column. */
.app-bottomnav-fab {
  position: absolute;
  left: 50%; top: -1.15rem;
  transform: translateX(-50%);
  width: 3.25rem; height: 3.25rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-600); color: #fff;
  border: 4px solid var(--surface);
  border-radius: 50%;
  box-shadow: var(--shadow-md);
}
.app-bottomnav-fab svg { width: 1.5rem; height: 1.5rem; }

/* Page content: clears the fixed topbar/sidebar/bottomnav */
.app-main { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + 1rem); }
@media (min-width: 768px) {
  .app-main { margin-left: var(--sidebar-w); padding-bottom: 1rem; }
}

/* ============================================================
 * 5. Card, table, empty state, skeletons
 * ========================================================== */
.card { background: var(--surface); border: 1px solid var(--ink-100); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.data-table th {
  text-align: left; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--ink-500); padding: 0.75rem 1rem; border-bottom: 1px solid var(--ink-100);
}
.data-table td { padding: 0.875rem 1rem; border-bottom: 1px solid var(--ink-100); color: var(--ink-900); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr.is-clickable { cursor: pointer; }
.data-table tr.is-clickable:hover { background: var(--ink-50); }

.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 3rem 1.5rem; color: var(--ink-500); }
.empty-state svg { width: 3rem; height: 3rem; color: var(--ink-300); margin-bottom: 1rem; }
.empty-state h3 { color: var(--ink-900); font-weight: 600; font-size: 1rem; margin-bottom: 0.375rem; }

/* Skeleton loaders: shown while a fetch() is in flight, swapped out by app.js on response */
.skeleton { position: relative; overflow: hidden; background: var(--ink-100); border-radius: var(--radius-sm); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  animation: sv-shimmer 1.4s ease-in-out infinite;
}
html.dark .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent); }
.skeleton-text { height: 0.875rem; margin: 0.25rem 0; }
.skeleton-avatar { width: 2.5rem; height: 2.5rem; border-radius: 50%; }

/* ============================================================
 * 6. Modal + confirm dialog
 * Markup convention app.js expects, e.g. for #sv-modal-root:
 *   <div class="sv-modal-backdrop"><div class="sv-modal" role="dialog" aria-modal="true">...</div></div>
 * app.js adds/removes .is-open and traps focus; this file only styles it.
 * ========================================================== */
.sv-modal-backdrop {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(17, 24, 39, 0.5);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 0;
}
.sv-modal-backdrop.is-open { opacity: 1; pointer-events: auto; }
@media (min-width: 640px) {
  .sv-modal-backdrop { align-items: center; padding: 1rem; }
}

.sv-modal {
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  transform: translateY(16px);
  transition: transform 0.2s ease;
}
.sv-modal-backdrop.is-open .sv-modal { transform: translateY(0); }
@media (min-width: 640px) {
  .sv-modal { border-radius: var(--radius-lg); transform: translateY(8px) scale(0.98); }
  .sv-modal-backdrop.is-open .sv-modal { transform: none; }
}

.sv-modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.sv-modal-title { font-size: 1.125rem; font-weight: 700; color: var(--ink-900); }
.sv-modal-close { color: var(--ink-500); background: transparent; border: none; cursor: pointer; padding: 0.25rem; border-radius: var(--radius-sm); }
.sv-modal-close:hover { background: var(--ink-100); color: var(--ink-900); }
.sv-modal-body { color: var(--ink-700); font-size: 0.9375rem; line-height: 1.55; }
.sv-modal-footer { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem; }
@media (max-width: 480px) {
  .sv-modal-footer { flex-direction: column-reverse; }
  .sv-modal-footer .btn { width: 100%; }
}

/* Confirm dialog is a .sv-modal with a coloured icon badge (danger by default) */
.sv-confirm-icon {
  width: 2.75rem; height: 2.75rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; margin-bottom: 1rem;
  background: var(--danger-50); color: var(--danger-500);
}
.sv-confirm-icon.is-neutral { background: var(--brand-50); color: var(--brand-600); }
.sv-confirm-icon svg { width: 1.375rem; height: 1.375rem; }

/* ============================================================
 * 7. Toast
 * app.js creates: <div class="sv-toast sv-toast-success"><svg>..</svg><span>msg</span></div>
 * inside a fixed #sv-toast-root container it positions.
 * ========================================================== */
#sv-toast-root {
  position: fixed; z-index: var(--z-toast);
  left: 1rem; right: 1rem; bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + 1rem);
  display: flex; flex-direction: column; gap: 0.5rem;
  pointer-events: none;
}
@media (min-width: 768px) {
  #sv-toast-root { left: auto; right: 1.5rem; bottom: 1.5rem; width: 360px; }
}

.sv-toast {
  display: flex; align-items: flex-start; gap: 0.625rem;
  padding: 0.875rem 1rem;
  background: var(--ink-900); color: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem; line-height: 1.4;
  pointer-events: auto;
  opacity: 0; transform: translateY(8px);
  animation: sv-toast-in 0.2s ease forwards;
}
.sv-toast.is-leaving { animation: sv-toast-out 0.15s ease forwards; }
.sv-toast svg { width: 1.125rem; height: 1.125rem; flex-shrink: 0; margin-top: 0.0625rem; }
.sv-toast-success { background: var(--ok-500); }
.sv-toast-error   { background: var(--danger-500); }
.sv-toast-info    { background: var(--ink-900); }
.sv-toast-close { margin-left: auto; background: transparent; border: none; color: rgba(255,255,255,0.8); cursor: pointer; padding: 0; line-height: 1; }
.sv-toast-close:hover { color: #fff; }

@keyframes sv-toast-in  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes sv-toast-out { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(4px); } }
@keyframes sv-shimmer   { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
@keyframes sv-spin      { to { transform: rotate(360deg); } }

/* ============================================================
 * 8. Badges, avatar
 * ========================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 0.3125rem;
  padding: 0.1875rem 0.625rem; border-radius: var(--radius-pill);
  font-size: 0.75rem; font-weight: 600;
}
.badge-ok     { background: var(--ok-50);     color: var(--ok-500); }
.badge-warn   { background: var(--warn-50);   color: var(--warn-500); }
.badge-danger { background: var(--danger-50); color: var(--danger-500); }
.badge-neutral{ background: var(--ink-100);   color: var(--ink-700); }

/* Avatar: shows a photo if set on the element (background-image via inline style),
   otherwise falls back to the initials() text already in the markup (helpers.php). */
.avatar {
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-100); color: var(--brand-700);
  font-weight: 700; font-size: 0.8125rem;
  background-size: cover; background-position: center;
  flex-shrink: 0;
}
.avatar-lg { width: 4rem; height: 4rem; font-size: 1.25rem; }

/* ============================================================
 * 9. Utilities
 * ========================================================== */
.safe-top    { padding-top: env(safe-area-inset-top, 0px); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom, 0px); }

.hide-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }
.hide-scrollbar::-webkit-scrollbar { display: none; }

.truncate-2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ------------------------------------------------------------
 * Keep tailwind.config's colors.brand in partials/_head.php equal to
 * the tokens above, so Tailwind utilities like bg-brand-600 match:
 *   brand: { 50:'#EEF2FF',100:'#E0E7FF',400:'#818CF8',500:'#6366F1',600:'#4F46E5',700:'#4338CA' }
 * ---------------------------------------------------------- */


 /* ============================================================
 * Promo carousel (dashboard home)
 * ========================================================== */
.promo-carousel {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.promo-track {
  display: flex;
  transition: transform 0.4s ease;
}
.promo-slide {
  min-width: 100%;
  padding: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: #fff;
}
.promo-slide-text {
  max-width: 60%;
  min-width: 0; /* prevents unbroken text from forcing the flex row wider than its parent */
  overflow-wrap: break-word;
}
.promo-slide h3 { font-weight: 800; font-size: 1.0625rem; margin-bottom: 0.25rem; }
.promo-slide p { font-size: 0.8125rem; line-height: 1.4; opacity: 0.92; }
.promo-illustration { width: 5rem; height: 5rem; flex-shrink: 0; }
.promo-dots {
  position: absolute; bottom: 0.75rem; left: 50%; transform: translateX(-50%);
  display: flex; gap: 0.375rem;
}
.promo-dot {
  width: 0.4rem; height: 0.4rem; border-radius: 50%;
  background: rgba(255, 255, 255, 0.5); border: none; padding: 0; cursor: pointer;
  transition: background-color 0.2s ease, width 0.2s ease;
}
.promo-dot.is-active { background: #fff; width: 1.125rem; border-radius: var(--radius-pill); }

@media (max-width: 480px) {
  .promo-illustration { display: none; }
  .promo-slide-text { max-width: 100%; }
}

/* ============================================================
 * Dashboard stat cards
 * ========================================================== */
.stat-card { display: flex; align-items: flex-start; justify-content: space-between; }
.stat-card-icon {
  width: 2.25rem; height: 2.25rem; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-50); color: var(--brand-600);
  flex-shrink: 0;
}
html.dark .stat-card-icon { background: rgba(99, 102, 241, 0.16); }

/* Keeps the "current measurements" panel in view while scrolling
   through a long history list, on desktop only. */
@media (min-width: 1024px) {
  .customer-sticky-panel {
    position: sticky;
    top: calc(var(--topbar-h) + 1.5rem);
  }
}

/* Global overflow safety: any flex/grid child holding text should be
   able to shrink and wrap rather than force the page into horizontal
   scroll. Without this, a single long unbroken word (a customer's
   full name with no spaces, a long email) can blow out its entire
   row and drag the WHOLE PAGE into horizontal scroll — a classic
   flexbox trap (flex items default to min-width: auto, which means
   "as wide as my content needs", overriding any parent max-width). */
.flex > *, .grid > * {
  min-width: 0;
}
body {
  overflow-x: hidden;
}