/* ================================================================
   Pool Maintenance — modern, premium design system
   ================================================================ */

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }

:root {
  /* Brand palette */
  --c-brand-50:  #ecfeff;
  --c-brand-100: #cffafe;
  --c-brand-200: #a5f3fc;
  --c-brand-300: #67e8f9;
  --c-brand-400: #22d3ee;
  --c-brand-500: #06b6d4;
  --c-brand-600: #0891b2;
  --c-brand-700: #0e7490;
  --c-brand-800: #155e75;
  --c-brand-900: #164e63;

  --c-accent-500: #6366f1;
  --c-accent-600: #4f46e5;
  --c-accent-700: #4338ca;

  /* Neutrals */
  --c-bg:         #f6f9fc;
  --c-bg-deep:    #eef3f8;
  --c-surface:    #ffffff;
  --c-surface-2:  #f8fafc;
  --c-border:     #e5eaf0;
  --c-border-strong: #cdd6e0;
  --c-text:       #0f172a;
  --c-text-muted: #64748b;
  --c-text-soft:  #94a3b8;

  /* Semantic */
  --c-good:    #16a34a;
  --c-good-bg: #dcfce7;
  --c-warn:    #d97706;
  --c-warn-bg: #fef3c7;
  --c-crit:    #dc2626;
  --c-crit-bg: #fee2e2;
  --c-none:    #6b7280;
  --c-none-bg: #f1f5f9;

  /* Effects */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-sm: 0 2px 4px rgba(15, 23, 42, .05), 0 1px 2px rgba(15, 23, 42, .03);
  --shadow-md: 0 6px 16px -4px rgba(15, 23, 42, .08), 0 2px 6px -2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 20px 40px -10px rgba(15, 23, 42, .15), 0 8px 20px -8px rgba(15, 23, 42, .08);
  --shadow-xl: 0 32px 64px -16px rgba(15, 23, 42, .22);
  --shadow-glow: 0 0 0 4px rgba(6, 182, 212, .15);

  /* Radii */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-2xl: 28px;
  --r-full: 999px;

  /* Spacing scale */
  --s-1: .25rem;
  --s-2: .5rem;
  --s-3: .75rem;
  --s-4: 1rem;
  --s-5: 1.25rem;
  --s-6: 1.5rem;
  --s-8: 2rem;
  --s-10: 2.5rem;
  --s-12: 3rem;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  /* Layout */
  --header-h: 64px;
  --nav-h: 72px;
  --max-w: 1240px;

  /* Motion */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
}

@media (prefers-color-scheme: dark) {
  :root.theme-auto {
    --c-bg:        #0b1220;
    --c-bg-deep:   #060a12;
    --c-surface:   #111a2c;
    --c-surface-2: #0f1625;
    --c-border:    #1f2a40;
    --c-border-strong: #2a3856;
    --c-text:      #e2e8f0;
    --c-text-muted:#94a3b8;
    --c-text-soft: #64748b;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.3);
    --shadow-sm: 0 2px 4px rgba(0,0,0,.4);
    --shadow-md: 0 6px 16px -4px rgba(0,0,0,.5);
    --shadow-lg: 0 20px 40px -10px rgba(0,0,0,.6);
  }
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;     /* prevent pull-to-refresh accidental triggers */
}
body.modal-open { overflow: hidden; touch-action: none; }

h1, h2, h3, h4, h5 { margin: 0 0 var(--s-3); letter-spacing: -0.02em; font-weight: 700; }
h1 { font-size: clamp(1.75rem, 2.2vw + 1rem, 2.5rem); line-height: 1.1; }
h2 { font-size: clamp(1.35rem, 1.2vw + 1rem, 1.75rem); line-height: 1.2; }
h3 { font-size: 1.2rem; line-height: 1.3; }
h4 { font-size: 1rem; }
p { margin: 0 0 var(--s-3); }
a { color: var(--c-brand-600); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--c-brand-700); }
hr { border: 0; border-top: 1px solid var(--c-border); margin: var(--s-6) 0; }

/* ---------- Layout shell ---------- */
.app-shell {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center;
  padding: 0 var(--s-5);
  gap: var(--s-4);
}

.app-header__brand {
  display: flex; align-items: center; gap: var(--s-3);
  font-weight: 700; font-size: 1.05rem;
  color: var(--c-text);
}
.app-header__brand .logo {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--c-brand-400) 0%, var(--c-accent-600) 100%);
  display: grid; place-items: center;
  color: white; font-weight: 700;
  box-shadow: 0 4px 14px rgba(6, 182, 212, .35), inset 0 1px 0 rgba(255,255,255,.4);
}
.app-header__spacer { flex: 1; }
.app-header__user {
  display: flex; align-items: center; gap: var(--s-2);
  color: var(--c-text-muted); font-size: .9rem;
}
.app-header__brand span:not(.logo) {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50vw;
}
.header-link { padding: var(--s-2) var(--s-3); }
@media (max-width: 520px) {
  .header-link { padding: var(--s-2); width: 36px; height: 36px; }
  .header-link__text {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); border: 0;  /* visually hidden */
  }
  .app-header { padding: 0 var(--s-3); gap: var(--s-2); }
}
@media (max-width: 380px) {
  .app-header__brand { font-size: .95rem; }
  .app-header__brand .logo { width: 28px; height: 28px; }
  .app-header__avatar { width: 32px; height: 32px; font-size: .8rem; }
}
.app-header__avatar {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--c-brand-500), var(--c-accent-600));
  color: white; display: grid; place-items: center;
  font-weight: 600; font-size: .85rem;
  box-shadow: var(--shadow-sm);
}

.app-main {
  display: grid;
  grid-template-columns: 1fr;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: var(--s-6) var(--s-5) calc(var(--nav-h) + var(--s-12));
}

@media (min-width: 1024px) {
  .app-main { padding-bottom: var(--s-12); }
}

/* ---------- Bottom navigation (mobile) ---------- */
.app-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-top: 1px solid var(--c-border);
  z-index: 30;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-around;
}
.app-nav__btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 6px 4px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--c-text-muted); font-size: .68rem; font-weight: 600;
  border-radius: var(--r-md);
  transition: all .2s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.app-nav__btn svg { width: 22px; height: 22px; stroke-width: 1.8; }
.app-nav__btn.is-active {
  color: var(--c-brand-600);
}
.app-nav__btn.is-active svg {
  filter: drop-shadow(0 2px 6px rgba(6, 182, 212, .35));
}
/* Show short labels on mobile (more space), full labels on desktop side-nav */
.app-nav__btn .nav-lbl-full { display: none; }
.app-nav__btn .nav-lbl-short { display: inline; }
@media (min-width: 768px) {
  .app-nav__btn .nav-lbl-full { display: inline; }
  .app-nav__btn .nav-lbl-short { display: none; }
}
.app-nav__btn:hover:not(.is-active) {
  color: var(--c-text);
  background: var(--c-surface-2);
}

/* Side nav on tablet+ */
@media (min-width: 768px) {
  .app-shell {
    grid-template-columns: 240px 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas: "header header" "nav main";
  }
  .app-header { grid-area: header; }
  .app-nav {
    grid-area: nav;
    position: sticky; top: var(--header-h);
    bottom: auto; left: auto; right: auto;
    height: calc(100vh - var(--header-h));
    border-top: 0; border-right: 1px solid var(--c-border);
    flex-direction: column; justify-content: flex-start; align-items: stretch;
    padding: var(--s-4); gap: 4px;
    background: transparent;
    backdrop-filter: none;
  }
  .app-main { grid-area: main; padding: var(--s-8); }
  .app-nav__btn {
    flex: none; flex-direction: row; justify-content: flex-start;
    gap: var(--s-3); padding: var(--s-3) var(--s-4);
    font-size: .92rem; border-radius: var(--r-md);
  }
  .app-nav__btn svg { width: 20px; height: 20px; }
  .app-nav__btn.is-active {
    background: linear-gradient(135deg, var(--c-brand-50), rgba(99,102,241,.08));
    color: var(--c-brand-700);
  }
}

/* ---------- Tabs / panels ---------- */
.tab-panel { display: none; animation: fadeUp .35s var(--ease); }
.tab-panel.is-active { display: block; }

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

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--s-4); margin-bottom: var(--s-6); flex-wrap: wrap;
}
.page-head__title { margin: 0; }
.page-head__sub { color: var(--c-text-muted); margin: 4px 0 0; }
.page-head__actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-xs);
  transition: box-shadow .2s var(--ease), transform .2s var(--ease);
}
.card--hover:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.card__title { font-size: .95rem; font-weight: 600; margin: 0 0 var(--s-3); }
.card__meta  { color: var(--c-text-muted); font-size: .85rem; }

.card--hero {
  background: linear-gradient(135deg, var(--c-brand-600) 0%, var(--c-accent-600) 100%);
  color: white;
  border: 0;
  padding: var(--s-6);
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-lg);
}
@media (min-width: 640px) { .card--hero { padding: var(--s-8); } }
.card--hero::before {
  content: "";
  position: absolute; top: -40%; right: -10%;
  width: 60%; aspect-ratio: 1;
  background: radial-gradient(circle, rgba(255,255,255,.18), transparent 70%);
  border-radius: 50%; pointer-events: none;
}
.card--hero::after {
  content: "";
  position: absolute; bottom: -60%; left: -20%;
  width: 80%; aspect-ratio: 1;
  background: radial-gradient(circle, rgba(255,255,255,.10), transparent 70%);
  border-radius: 50%; pointer-events: none;
}
.card--hero h2, .card--hero p { color: white; position: relative; }
.card--hero .hero-greeting { font-size: .9rem; opacity: .85; margin: 0 0 var(--s-1); font-weight: 500; }
.card--hero .hero-name { font-size: clamp(1.5rem, 2vw + 1rem, 2.25rem); margin: 0; }
.card--hero .hero-sub { opacity: .85; margin: var(--s-2) 0 0; max-width: 60ch; }

.card--glass {
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, .5);
}

/* ---------- Stat tiles ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);   /* always 2-up on mobile */
  gap: var(--s-3);
  margin: var(--s-6) 0;
}
@media (min-width: 640px) {
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s-4); }
}
.stat {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-1);
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-xs);
}
@media (min-width: 640px) { .stat { padding: var(--s-5); } }
.stat__label { color: var(--c-text-muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding-right: 32px; }
.stat__value { font-size: clamp(1.35rem, 4vw + .5rem, 1.85rem); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat__delta { font-size: .75rem; color: var(--c-text-muted); }
.stat__icon {
  position: absolute; top: var(--s-3); right: var(--s-3);
  width: 32px; height: 32px; border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--c-brand-50); color: var(--c-brand-600);
}
.stat__icon svg { width: 16px; height: 16px; }
@media (min-width: 640px) {
  .stat__icon { top: var(--s-4); right: var(--s-4); width: 36px; height: 36px; }
  .stat__icon svg { width: 18px; height: 18px; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  min-height: 40px;
  border-radius: var(--r-md);
  font-family: inherit; font-size: .92rem; font-weight: 600; line-height: 1;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;     /* remove 300ms tap delay */
  user-select: none;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-glow); }

.btn--primary {
  background: linear-gradient(135deg, var(--c-brand-500) 0%, var(--c-accent-600) 100%);
  color: white;
  box-shadow: 0 4px 14px rgba(6, 182, 212, .28);
}
.btn--primary:hover {
  box-shadow: 0 8px 22px rgba(6, 182, 212, .38), 0 4px 8px rgba(79, 70, 229, .22);
}

.btn--secondary {
  background: var(--c-surface);
  color: var(--c-text);
  border-color: var(--c-border);
  box-shadow: var(--shadow-xs);
}
.btn--secondary:hover {
  background: var(--c-surface-2);
  border-color: var(--c-border-strong);
}

.btn--ghost {
  background: transparent;
  color: var(--c-text-muted);
}
.btn--ghost:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
}

.btn--danger {
  background: var(--c-crit-bg);
  color: var(--c-crit);
}
.btn--danger:hover { background: #fecaca; }

.btn--sm { padding: var(--s-2) var(--s-3); font-size: .82rem; gap: var(--s-1); }
.btn--icon { padding: var(--s-2); width: 36px; height: 36px; }

.btn-row { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.field label, .label {
  font-weight: 600; font-size: .85rem;
  color: var(--c-text); letter-spacing: -.01em;
}
.field .hint { font-size: .78rem; color: var(--c-text-muted); margin: 0; }
.field--error .input,
.field--error .select,
.field--error .textarea { border-color: var(--c-crit); }
.field--error .hint { color: var(--c-crit); }

.input, .select, .textarea {
  width: 100%;
  padding: var(--s-3) var(--s-4);
  min-height: 44px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
  color: var(--c-text);
  font-family: inherit; font-size: 16px; line-height: 1.4; /* 16px stops iOS auto-zoom */
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
  -webkit-appearance: none; appearance: none;
}
@media (min-width: 640px) {
  .input, .select, .textarea { font-size: .95rem; min-height: 40px; }
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-brand-500);
  box-shadow: var(--shadow-glow);
}
.textarea { resize: vertical; min-height: 84px; }
.select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%2364748b' stroke-width='2' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-4) center;
  appearance: none; -webkit-appearance: none;
  padding-right: var(--s-10);
}

/* Range-color metric input feedback */
.input--good   { border-color: var(--c-good); box-shadow: 0 0 0 3px rgba(22,163,74,.12); }
.input--warn   { border-color: var(--c-warn); box-shadow: 0 0 0 3px rgba(217,119,6,.12); }
.input--crit   { border-color: var(--c-crit); box-shadow: 0 0 0 3px rgba(220,38,38,.15); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-4);
}

/* Checkbox / switch */
.check {
  display: inline-flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
  font-size: .92rem; font-weight: 500;
  cursor: pointer;
  transition: all .15s var(--ease);
}
.check:hover { border-color: var(--c-border-strong); background: var(--c-surface-2); }
.check input { accent-color: var(--c-brand-600); width: 18px; height: 18px; margin: 0; }
.check.is-on { border-color: var(--c-brand-500); background: var(--c-brand-50); color: var(--c-brand-800); }

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--s-2);
}

/* ---------- Status badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: .75rem; font-weight: 600; letter-spacing: .01em;
  white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: var(--r-full); background: currentColor; opacity: .8; }
.badge--good { background: var(--c-good-bg); color: var(--c-good); }
.badge--warn { background: var(--c-warn-bg); color: var(--c-warn); }
.badge--crit { background: var(--c-crit-bg); color: var(--c-crit); }
.badge--none { background: var(--c-none-bg); color: var(--c-none); }
.badge--info { background: var(--c-brand-50); color: var(--c-brand-700); }
.badge--accent { background: rgba(99,102,241,.1); color: var(--c-accent-700); }

.chip {
  display: inline-flex; align-items: center;
  padding: 4px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-full);
  font-size: .78rem; color: var(--c-text-muted);
  background: var(--c-surface);
}

/* ---------- Tables ---------- */
.data-table-wrap {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.data-table {
  width: 100%; border-collapse: collapse;
  font-size: .9rem;
}
.data-table thead th {
  text-align: left;
  padding: var(--s-3) var(--s-4);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border);
  font-size: .76rem; font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
.data-table tbody td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background .15s var(--ease); }
.data-table tbody tr:hover { background: var(--c-surface-2); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .actions { text-align: right; white-space: nowrap; }

/* Mobile: turn tables into cards */
@media (max-width: 640px) {
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; }
  .data-table tr {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    margin-bottom: var(--s-3);
    padding: var(--s-2);
  }
  .data-table tbody td {
    border-bottom: 1px dashed var(--c-border);
    display: flex; justify-content: space-between; gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
  }
  .data-table tbody td:last-child { border-bottom: 0; }
  .data-table tbody td::before {
    content: attr(data-label);
    font-size: .75rem; font-weight: 600;
    color: var(--c-text-muted);
    text-transform: uppercase; letter-spacing: .03em;
  }
  .data-table .actions { justify-content: flex-end; flex-wrap: wrap; gap: var(--s-1); }
  .data-table .actions::before { display: none; }
  .data-table-wrap { background: transparent; border: 0; box-shadow: none; padding: 0; }
}

/* ---------- Pool / water-body cards grid ---------- */
.pool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--s-4);
}
.pool-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-xs);
  display: flex; flex-direction: column; gap: var(--s-3);
  position: relative;
  overflow: hidden;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.pool-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.pool-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); }
.pool-card__icon {
  width: 44px; height: 44px; border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--c-brand-100), var(--c-brand-300));
  display: grid; place-items: center;
  color: var(--c-brand-700); flex-shrink: 0;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.05);
}
.pool-card__title { font-weight: 700; font-size: 1.05rem; margin: 0; }
.pool-card__meta { color: var(--c-text-muted); font-size: .82rem; }

.metric-pills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: var(--s-2);
}
.pool-card .btn-row { margin-top: auto; }
.metric-pill {
  background: var(--c-surface-2);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  display: flex; flex-direction: column; gap: 2px;
  border-left: 3px solid var(--c-border);
}
.metric-pill__label { font-size: .65rem; color: var(--c-text-muted); text-transform: uppercase; letter-spacing: .05em; }
.metric-pill__value { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.metric-pill--good { border-left-color: var(--c-good); }
.metric-pill--warn { border-left-color: var(--c-warn); }
.metric-pill--crit { border-left-color: var(--c-crit); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: none;
  align-items: flex-end; justify-content: center;
  padding: 0;
  opacity: 0; transition: opacity .2s var(--ease);
}
.modal-backdrop.is-open { display: flex; opacity: 1; }
.modal {
  background: var(--c-surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%; max-width: 640px;
  max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  padding: var(--s-5) var(--s-5) calc(var(--s-5) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-xl);
  transform: translateY(20px);
  transition: transform .3s var(--ease-spring);
  position: relative;
  overscroll-behavior: contain;        /* don't scroll the page under it */
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 640px) {
  .modal { padding: var(--s-6); }
}
.modal-backdrop.is-open .modal { transform: translateY(0); }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: var(--s-5); }
  .modal { border-radius: var(--r-xl); max-height: 88vh; }
}

.modal__head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: var(--s-4); gap: var(--s-4);
}
.modal__title { font-size: 1.25rem; margin: 0; }
.modal__close {
  background: var(--c-surface-2); border: 0; color: var(--c-text-muted);
  width: 44px; height: 44px; border-radius: var(--r-full);
  display: grid; place-items: center; cursor: pointer;
  flex-shrink: 0;
  transition: all .15s var(--ease);
  touch-action: manipulation;
}
.modal__close:hover { background: var(--c-border); color: var(--c-text); }
.modal__foot {
  display: flex; justify-content: flex-end; gap: var(--s-2);
  margin: var(--s-5) calc(var(--s-5) * -1) calc(env(safe-area-inset-bottom) * -1);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--c-border);
  position: sticky; bottom: calc(env(safe-area-inset-bottom) * -1);
  background: var(--c-surface);
  z-index: 1;
}
@media (min-width: 640px) {
  .modal__foot { position: static; margin: var(--s-5) 0 0; padding: var(--s-5) 0 0; }
}

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--s-4));
  right: var(--s-4); left: var(--s-4);
  z-index: 200;
  display: flex; flex-direction: column-reverse; gap: var(--s-2);
  pointer-events: none;
}
@media (min-width: 640px) { .toast-stack { left: auto; max-width: 360px; bottom: var(--s-5); } }
.toast {
  background: var(--c-text); color: white;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn .3s var(--ease-spring);
  font-size: .9rem;
  display: flex; align-items: center; gap: var(--s-3);
}
.toast--success { background: var(--c-good); }
.toast--error { background: var(--c-crit); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Empty state ---------- */
.empty {
  padding: var(--s-10) var(--s-5);
  text-align: center;
  color: var(--c-text-muted);
  background: var(--c-surface);
  border: 1px dashed var(--c-border-strong);
  border-radius: var(--r-lg);
}
.empty__icon {
  width: 64px; height: 64px; margin: 0 auto var(--s-4);
  background: var(--c-brand-50); color: var(--c-brand-600);
  border-radius: var(--r-full); display: grid; place-items: center;
}
.empty__icon svg { width: 28px; height: 28px; }
.empty__title { color: var(--c-text); font-size: 1.1rem; font-weight: 600; margin: 0 0 var(--s-1); }
.empty__sub { margin: 0 0 var(--s-4); }

/* ---------- Guide cards ---------- */
.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--s-4);
}
.guide-card { display: flex; flex-direction: column; gap: var(--s-2); }
.guide-card__head {
  display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-1);
}
.guide-card__range {
  font-size: .85rem; font-weight: 600;
  color: var(--c-text); margin-top: var(--s-1);
  padding: var(--s-2) var(--s-3);
  background: var(--c-brand-50);
  border-radius: var(--r-sm);
}

/* ---------- Reminder rows ---------- */
.reminder-row {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  margin-bottom: var(--s-2);
  transition: all .15s var(--ease);
}
.reminder-row:hover { background: var(--c-surface-2); }
.reminder-row__icon {
  width: 36px; height: 36px; border-radius: var(--r-md);
  background: var(--c-brand-50); color: var(--c-brand-600);
  display: grid; place-items: center; flex-shrink: 0;
}
.reminder-row__body { flex: 1; min-width: 0; }
.reminder-row__title { font-weight: 600; font-size: .95rem; }
.reminder-row__meta { color: var(--c-text-muted); font-size: .82rem; }
.reminder-row__actions { display: flex; gap: var(--s-1); flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.reminder-row.overdue { border-color: var(--c-crit); background: var(--c-crit-bg); }
.reminder-row.overdue .reminder-row__icon { background: var(--c-crit); color: white; }
@media (max-width: 520px) {
  .reminder-row { flex-wrap: wrap; gap: var(--s-3); padding: var(--s-3); }
  .reminder-row__actions { width: 100%; justify-content: flex-start; padding-left: 52px; }
}

/* ---------- Charts ---------- */
.chart-wrap {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-xs);
}
.chart-controls {
  display: flex; gap: var(--s-2); flex-wrap: wrap;
  margin-bottom: var(--s-4);
}
.chart-canvas-wrap { position: relative; height: 280px; }
@media (min-width: 768px) { .chart-canvas-wrap { height: 360px; } }
.chart-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-2); padding: var(--s-5);
  text-align: center; color: var(--c-text-soft);
}
.chart-empty svg { color: var(--c-text-soft); opacity: .5; }
.chart-empty p { font-weight: 600; color: var(--c-text); margin: 0; }
.chart-empty span { font-size: .85rem; }

/* ---------- Tabs (sub) ---------- */
.subtabs {
  display: inline-flex; padding: 4px; gap: 2px;
  background: var(--c-surface-2);
  border-radius: var(--r-md);
  margin-bottom: var(--s-4);
  border: 1px solid var(--c-border);
}
.subtab {
  padding: var(--s-2) var(--s-4);
  border: 0; background: transparent;
  border-radius: calc(var(--r-md) - 2px);
  font-family: inherit; font-size: .85rem; font-weight: 600;
  color: var(--c-text-muted); cursor: pointer;
  transition: all .15s var(--ease);
}
.subtab.is-active { background: var(--c-surface); color: var(--c-text); box-shadow: var(--shadow-xs); }
.subtab:hover:not(.is-active) { color: var(--c-text); }

/* ---------- Auth pages ---------- */
.auth-shell {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--s-5);
  background:
    radial-gradient(circle at 15% 25%, rgba(6, 182, 212, .15), transparent 50%),
    radial-gradient(circle at 85% 80%, rgba(99, 102, 241, .15), transparent 50%),
    var(--c-bg-deep);
}
.auth-card {
  background: var(--c-surface);
  border-radius: var(--r-xl);
  padding: var(--s-8) var(--s-6);
  width: 100%; max-width: 440px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(15, 23, 42, .04);
}
@media (min-width: 640px) {
  .auth-card { padding: var(--s-10); }
}
.auth-card__brand {
  display: flex; align-items: center; justify-content: center; gap: var(--s-3);
  margin-bottom: var(--s-6); font-size: 1.15rem; font-weight: 700;
}
.auth-card__brand .logo {
  width: 44px; height: 44px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--c-brand-400), var(--c-accent-600));
  display: grid; place-items: center; color: white;
  box-shadow: 0 8px 24px rgba(6, 182, 212, .35), inset 0 1px 0 rgba(255,255,255,.4);
}
.auth-card h1 {
  font-size: 1.5rem; text-align: center; margin: 0 0 var(--s-2);
}
.auth-card .lede {
  text-align: center; color: var(--c-text-muted); margin: 0 0 var(--s-6);
}
.auth-card .footnote {
  text-align: center; margin-top: var(--s-5);
  font-size: .88rem; color: var(--c-text-muted);
}

/* ---------- Flash messages ---------- */
.flash {
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  margin-bottom: var(--s-4);
  font-size: .9rem;
  display: flex; align-items: center; gap: var(--s-2);
}
.flash--success { background: var(--c-good-bg); color: var(--c-good); }
.flash--error { background: var(--c-crit-bg); color: var(--c-crit); }
.flash--info { background: var(--c-brand-50); color: var(--c-brand-700); }

/* ---------- Onboarding / getting started ---------- */
.getting-started {
  background: linear-gradient(135deg, var(--c-brand-50) 0%, rgba(99,102,241,.05) 100%);
  border: 1px solid var(--c-brand-200);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  margin-bottom: var(--s-6);
  position: relative;
}
.getting-started__close {
  position: absolute; top: var(--s-3); right: var(--s-3);
  background: transparent; border: 0; color: var(--c-text-muted);
  width: 32px; height: 32px; border-radius: var(--r-full);
  cursor: pointer; display: grid; place-items: center;
}
.getting-started__close:hover { background: rgba(0,0,0,.05); color: var(--c-text); }
.getting-started h3 { margin-top: 0; }
.getting-started ol { padding-left: 1.25rem; margin: var(--s-3) 0; }
.getting-started li { margin: var(--s-1) 0; }

/* ---------- Utilities ---------- */
.text-muted { color: var(--c-text-muted); }
.text-soft  { color: var(--c-text-soft); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); }
.mb-4 { margin-bottom: var(--s-4); }
.mb-5 { margin-bottom: var(--s-5); }
.mb-6 { margin-bottom: var(--s-6); }
.mt-2 { margin-top: var(--s-2); }
.mt-4 { margin-top: var(--s-4); }
.mt-6 { margin-top: var(--s-6); }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.grid { display: grid; }
.w-full { width: 100%; }
.nowrap { white-space: nowrap; }

.skeleton {
  background: linear-gradient(90deg, var(--c-surface-2) 25%, var(--c-border) 50%, var(--c-surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
  height: 1em;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Mobile bottom-nav labels can be smaller; use abbreviations on tiny screens */
@media (max-width: 380px) {
  .app-nav__btn { font-size: .62rem; padding: 4px 2px; }
  .app-nav__btn svg { width: 20px; height: 20px; }
}

/* ---------- App footer (credits) ---------- */
.app-footer {
  margin-top: var(--s-10);
  padding: var(--s-5) var(--s-4);
  text-align: center;
  font-size: .82rem;
  color: var(--c-text-soft);
  border-top: 1px solid var(--c-border);
}
.app-footer a {
  color: var(--c-text-muted);
  font-weight: 600;
  text-decoration: none;
  transition: color .15s var(--ease);
}
.app-footer a:hover { color: var(--c-brand-600); }
.app-footer__version {
  display: inline-block;
  margin-left: var(--s-3);
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: var(--c-surface-2);
  color: var(--c-text-soft);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.auth-footer__version {
  display: inline-block;
  margin-left: var(--s-2);
  padding: 1px 7px;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, .15);
  color: rgba(255, 255, 255, .85);
  font-size: .7rem;
  font-weight: 600;
}

/* Auth-page footer: floats over the gradient background */
.auth-footer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: var(--s-4);
  text-align: center;
  font-size: .8rem;
  color: rgba(255, 255, 255, .7);
}
.auth-footer a {
  color: rgba(255, 255, 255, .9);
  font-weight: 600;
  text-decoration: none;
}
.auth-footer a:hover { color: white; text-decoration: underline; }
.auth-shell { position: relative; padding-bottom: calc(var(--s-12) + var(--s-5)); }

/* Print styles for PDF export */
@media print {
  .app-nav, .app-header, .modal-backdrop, .toast-stack, .btn { display: none !important; }
  body { background: white; }
  .data-table-wrap { box-shadow: none; border-color: #ccc; }
}
