/* ==========================================================================
   wrkt-tracker design system
   --------------------------------------------------------------------------
   1. Design tokens (light + dark)        5. Cards, list rows, chips, stats
   2. Base / typography / links           6. Forms
   3. Buttons                             7. Tables
   4. Navigation (top bar, panels, tabs)  8. Feature-specific legacy rules
                                          9. Sync strip, flash, banners

   TOKEN RULES FOR EVERYONE BUILDING ON THIS FILE
   - Never hard-code a colour. Use a token; both themes then work for free.
   - Text on --bg / --surface / --surface-2 uses --text or --text-muted (both
     pass WCAG AA on all three). Coloured text uses --accent-text,
     --success-text, --warning-text, --danger-text (AA on surfaces).
   - Filled controls: --accent + --accent-contrast, --danger + --danger-contrast.
   - "Soft" tints (--accent-soft, --success-soft, --warning-soft, --danger-soft)
     are backgrounds for chips/alerts; pair them with the matching *-text token.
   - Theme selection: :root[data-theme="light"|"dark"] is an explicit choice
     (set from localStorage by the inline <head> script); with no data-theme the
     prefers-color-scheme media query decides.
   ========================================================================== */

/* ---- 1. Tokens ---------------------------------------------------------- */
:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eceef8;
  --border: #dcdff0;
  --border-strong: #c3c8e2;
  --control-border: #858bb0; /* form-control outlines: >=3:1 on surfaces (WCAG 1.4.11) */
  --overlay: rgba(14, 16, 40, 0.45);

  /* Text */
  --text: #14162b;
  --text-muted: #565b78;

  /* Accent: electric indigo */
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --accent-soft: #e8e7fd;
  --accent-text: #4338ca;

  /* Status */
  --success: #15803d;
  --success-soft: #dcfce7;
  --success-text: #166534;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --warning-text: #854d0e;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-contrast: #ffffff;
  --danger-soft: #fee2e2;
  --danger-text: #b91c1c;
  --streak: #b93c08;
  --streak-soft: #ffedd5;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(20, 22, 60, 0.06), 0 1px 1px rgba(20, 22, 60, 0.04);
  --shadow: 0 2px 10px rgba(20, 22, 60, 0.08), 0 1px 2px rgba(20, 22, 60, 0.05);
  --shadow-lg: 0 12px 32px rgba(20, 22, 60, 0.18), 0 2px 6px rgba(20, 22, 60, 0.08);
  --ring: 0 0 0 3px rgba(79, 70, 229, 0.35);

  /* Shape */
  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  /* Spacing scale (use for gap / padding / margin) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  /* Type scale */
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.25rem;

  /* Layout */
  --tap: 44px;            /* minimum touch target */
  --content-w: 960px;     /* .container and nav content width */
  --nav-h: 60px;
  --tabbar-h: 60px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0d18;
  --surface: #161829;
  --surface-2: #20223a;
  --border: #2c2f4d;
  --border-strong: #41456c;
  --control-border: #6b719a;
  --overlay: rgba(0, 0, 0, 0.6);
  --text: #eceefb;
  --text-muted: #a4a9c9;
  --accent: #8b8cf8;
  --accent-hover: #a3a4fb;
  --accent-contrast: #0c0d18;
  --accent-soft: #26284d;
  --accent-text: #aeb0ff;
  --success: #4ade80;
  --success-soft: #12331f;
  --success-text: #6ee7a0;
  --warning: #fbbf24;
  --warning-soft: #3a2d0c;
  --warning-text: #fcd34d;
  --danger: #f87171;
  --danger-hover: #fca5a5;
  --danger-contrast: #2a0a0a;
  --danger-soft: #3d1517;
  --danger-text: #fca5a5;
  --streak: #fb923c;
  --streak-soft: #3b2010;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  --ring: 0 0 0 3px rgba(139, 140, 248, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0d18;
    --surface: #161829;
    --surface-2: #20223a;
    --border: #2c2f4d;
    --border-strong: #41456c;
    --control-border: #6b719a;
    --overlay: rgba(0, 0, 0, 0.6);
    --text: #eceefb;
    --text-muted: #a4a9c9;
    --accent: #8b8cf8;
    --accent-hover: #a3a4fb;
    --accent-contrast: #0c0d18;
    --accent-soft: #26284d;
    --accent-text: #aeb0ff;
    --success: #4ade80;
    --success-soft: #12331f;
    --success-text: #6ee7a0;
    --warning: #fbbf24;
    --warning-soft: #3a2d0c;
    --warning-text: #fcd34d;
    --danger: #f87171;
    --danger-hover: #fca5a5;
    --danger-contrast: #2a0a0a;
    --danger-soft: #3d1517;
    --danger-text: #fca5a5;
    --streak: #fb923c;
    --streak-soft: #3b2010;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
    --ring: 0 0 0 3px rgba(139, 140, 248, 0.45);
  }
}

/* ---- 2. Base ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* The `hidden` attribute's UA-stylesheet `display: none` loses to ANY
   author rule that sets `display` on the same element, so `el.hidden = true`
   on a `.btn` is a silent no-op without this (found via the guest-mode nav
   walkthrough: `[data-nav-signin]`/`[data-nav-signout]` are toggled by
   `nav.js`). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: var(--text-base);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-text); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.muted { color: var(--text-muted); }
.eyebrow { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: var(--text-2xl); font-weight: 800; margin-bottom: var(--space-4); }
h2 { font-size: var(--text-lg); font-weight: 700; margin-bottom: var(--space-3); color: var(--text); }
h3 { font-size: var(--text-base); font-weight: 700; }

.container {
  max-width: var(--content-w);
  margin: var(--space-5) auto var(--space-6);
  padding: 0 var(--space-4);
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Page title row: <div class="page-header"><h1>..</h1><div class="page-header__actions">..</div></div> */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }
.page-header h1 { margin-bottom: 0; }
.page-header__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.page-subtitle { color: var(--text-muted); margin: calc(var(--space-2) * -1) 0 var(--space-4); }

/* Small layout helpers */
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---- 3. Buttons --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
@media (pointer: coarse) { .btn { min-height: var(--tap); } }
.btn:active { transform: translateY(1px); }
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-contrast); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: var(--danger-contrast); }
.btn-danger:hover { background: var(--danger-hover); color: var(--danger-contrast); }
/* Extras (new): */
.btn-ghost { background: transparent; color: var(--accent-text); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-sm { min-height: 34px; padding: 0.3rem 0.75rem; font-size: var(--text-xs); }
@media (pointer: coarse) { .btn-sm { min-height: 40px; } }
.btn-lg { min-height: 48px; padding: 0.75rem 1.5rem; font-size: var(--text-base); }
.btn-block { display: flex; width: 100%; }
.btn-icon { padding: 0; width: 40px; min-width: 40px; }
@media (pointer: coarse) { .btn-icon { width: var(--tap); min-width: var(--tap); } }
button.btn { font-family: inherit; }

/* Forms rendered by button_to should not add block margins */
form.button_to { display: inline; margin: 0; }

/* ---- 4. Navigation ------------------------------------------------------ */
/* Markup lives in app/views/layouts/_chrome.html.erb; behaviour in
   app/javascript/controllers/nav_controller.js (panels, active state) and
   theme_controller.js (night mode). Desktop: top bar + dropdown panels.
   Mobile (<= 760px): slim top bar + fixed bottom tab bar + bottom sheets. */
.nav {
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}

.nav-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: var(--content-w);
  height: var(--nav-h);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.nav-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 800;
  font-size: var(--text-lg);
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  margin-right: var(--space-4);
}
.nav-brand::before {
  content: "";
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--streak));
  flex: none;
}
.nav-brand:hover { text-decoration: none; }

.nav-primary { display: flex; align-items: center; gap: var(--space-1); }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 38px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active, .nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
.nav-link .chev { font-size: 0.7em; opacity: 0.7; }

.nav-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.nav-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.nav-icon-btn:hover { background: var(--surface-2); }
.nav-icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Theme icon: which glyph shows depends on <html data-theme-pref>, set before
   first paint by the inline head script (layouts/_theme_init). */
.theme-icon { display: none; }
:root[data-theme-pref="light"] .theme-icon--light,
:root[data-theme-pref="dark"] .theme-icon--dark,
:root[data-theme-pref="system"] .theme-icon--system { display: block; }

.nav-more-btn { gap: 0.4rem; width: auto; padding: 0 var(--space-3); font-size: var(--text-sm); font-weight: 600; }

/* Dropdown / sheet panels */
.nav-panel {
  position: absolute;
  top: calc(100% - 4px);
  z-index: 80;
  width: min(320px, calc(100vw - 2rem));
  max-height: calc(100vh - var(--nav-h) - 2rem);
  overflow-y: auto;
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.nav-panel--progress { left: var(--panel-left, 1rem); }
.nav-panel--more { right: max(1rem, calc((100vw - var(--content-w)) / 2 + 1rem)); }

.nav-panel__title { padding: var(--space-2) var(--space-3); }
.nav-panel-list { display: flex; flex-direction: column; }
.nav-panel-list:empty { display: none; }
.nav-panel a,
.nav-panel .nav-panel-item,
.nav-panel button.nav-panel-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 42px;
  padding: 0.5rem var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.nav-panel a:hover, .nav-panel .nav-panel-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-panel a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.nav-panel .nav-panel-item--danger { color: var(--danger-text); }
.nav-panel hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-2) 0; }
.nav-panel form.button_to { display: block; }
.nav-panel [data-controller="notifications"] { display: block; }
.nav-progress-list { display: flex; flex-direction: column; }

/* Segmented theme control inside the More panel */
.theme-seg { display: flex; gap: 2px; padding: 3px; margin: 0 var(--space-3) var(--space-2); background: var(--surface-2); border-radius: var(--radius-pill); }
.theme-seg button {
  flex: 1;
  min-height: 34px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  cursor: pointer;
}
.theme-seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.nav-panel-label { padding: var(--space-2) var(--space-3) var(--space-1); }

.nav-backdrop { position: fixed; inset: 0; z-index: 70; background: transparent; }

.tabbar { display: none; }
.nav-only-mobile { display: none !important; }

@media (max-width: 760px) {
  .nav-bar { height: 52px; }
  .nav-primary, .nav-log, .nav-more-btn { display: none !important; }
  .nav-only-mobile { display: flex !important; }
  .nav-brand { margin-right: 0; }

  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--space-3)); }
  .container { margin-top: var(--space-4); }

  .nav-backdrop.is-open { background: var(--overlay); }
  .nav-panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 75vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
    padding: var(--space-3) var(--space-3) calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  }
  .nav-panel::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 0 auto var(--space-3); }
  .nav-panel a, .nav-panel .nav-panel-item { min-height: var(--tap); font-size: var(--text-base); }

  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    min-height: var(--tabbar-h);
    padding: 0 var(--space-2) env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    /* Firefox for Android reflows fixed-position elements on the main thread
       as its dynamic toolbar hides/shows during a scroll gesture, so the bar
       visibly lags and appears to jump upward mid-scroll before settling.
       Promoting it to its own compositor layer keeps it pinned smoothly
       (harmless no-op on browsers that don't need it). */
    transform: translateZ(0);
    will-change: transform;
  }
  .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: var(--tap);
    padding: var(--space-2) 0;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.6875rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .tab.is-active, .tab[aria-current="page"] { color: var(--accent-text); }
  .tab--log { flex: 0 0 auto; }
  .tab--log .tab-plus {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin-top: -18px;
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: var(--accent-contrast);
    box-shadow: var(--shadow), 0 0 0 4px var(--surface);
  }
  .tab--log { color: var(--text-muted); padding-top: 0; }
  .tab--log svg { stroke-width: 2.6; }
}

/* ---- 5. Cards, list rows, chips, stat tiles ----------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.card > :last-child { margin-bottom: 0; }
.card-title { font-size: var(--text-base); font-weight: 700; margin-bottom: var(--space-2); }

.session-list, .list { display: flex; flex-direction: column; gap: var(--space-2); }

/* Tappable list row: <a class="list-row"> with any children; .session-item is the
   original name for the same thing and shares the styling. */
.list-row,
.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--tap);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.list-row:hover, .session-item:hover { border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.list-row__title { font-weight: 600; }
.list-row__meta { font-size: var(--text-sm); color: var(--text-muted); }

.session-date { font-weight: 600; color: var(--text-muted); font-size: var(--text-sm); }
.session-type { font-weight: 700; font-size: var(--text-base); }
.session-count { font-size: var(--text-sm); color: var(--text-muted); }

/* Chip / badge. Variants: .chip-accent .chip-success .chip-warning .chip-danger .chip-streak */
.chip, .badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.65rem;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}
.chip-accent { background: var(--accent-soft); color: var(--accent-text); }
.chip-success { background: var(--success-soft); color: var(--success-text); }
.chip-warning { background: var(--warning-soft); color: var(--warning-text); }
.chip-danger { background: var(--danger-soft); color: var(--danger-text); }
.chip-streak { background: var(--streak-soft); color: var(--streak); }

/* Stat tile: <div class="stat-grid"><div class="stat-tile"><div class="stat-tile__value">12</div><div class="stat-tile__label">Sessions</div></div>...</div> */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4); box-shadow: var(--shadow-sm); }
.stat-tile__value { font-size: var(--text-2xl); font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-tile__label { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); margin-top: var(--space-1); }
.stat-tile--streak .stat-tile__value { color: var(--streak); }
.stat-tile--accent .stat-tile__value { color: var(--accent-text); }

.empty-state { text-align: center; padding: var(--space-7) var(--space-4); color: var(--text-muted); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.empty-state p { font-size: var(--text-lg); margin-bottom: var(--space-4); }

.detail-header { margin-bottom: var(--space-4); }
.detail-header .date { color: var(--text-muted); font-size: var(--text-sm); }
.weight-value { font-weight: 700; font-size: var(--text-lg); }
.actions { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-top: var(--space-5); }

/* ---- 6. Forms ----------------------------------------------------------- */
.form-group { margin-bottom: var(--space-4); }
.form-group label { display: block; font-weight: 600; margin-bottom: var(--space-1); font-size: var(--text-sm); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="search"], input[type="url"], input[type="tel"],
select, textarea {
  font: inherit;
  font-size: 1rem; /* 16px: stops iOS Safari zooming on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  min-height: 42px;
  max-width: 100%;
}
@media (pointer: coarse) {
  input[type="text"], input[type="email"], input[type="password"], input[type="number"],
  input[type="date"], input[type="time"], input[type="search"], select { min-height: var(--tap); }
}
.form-group select,
.form-group textarea,
.form-group input[type="date"],
.form-group input[type="time"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="text"] { width: 100%; }
textarea { font-family: inherit; resize: vertical; }
::placeholder { color: var(--text-muted); opacity: 0.8; }

input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 1.1rem; height: 1.1rem; vertical-align: middle; }
label { cursor: default; }

.field-group { display: flex; flex-direction: column; gap: var(--space-1); min-width: 90px; }
.field-group label, .field-group .field-label { font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); }
.field-group input[type="number"] { width: 100%; padding: 0.4rem 0.5rem; }
.field-value { font-weight: 600; }

/* ---- 7. Tables ---------------------------------------------------------- */
table { border-collapse: collapse; }
.series-table { width: 100%; margin-top: var(--space-2); }
.series-table th, .series-table td { padding: 0.35rem 0.5rem; text-align: left; font-size: var(--text-sm); }
.series-table th { color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.series-table input[type="number"] { width: 100%; padding: 0.35rem 0.5rem; font-size: var(--text-sm); min-height: 38px; }
.series-row-number { color: var(--text-muted); }

.table-scroll { position: relative; overflow-x: auto; max-width: 100%; border-radius: var(--radius); }
.table-scroll .admin-table { min-width: 680px; }
.admin-table td, .admin-table th { white-space: nowrap; }
.admin-table { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.admin-table th, .admin-table td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); text-align: left; }
.admin-table th { background: var(--surface-2); font-weight: 700; font-size: var(--text-sm); color: var(--text-muted); }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table td form { display: inline; }
.admin-table .row-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
@media (max-width: 760px) { .admin-table { display: block; overflow-x: auto; } }

/* ---- 8. Feature-specific rules (per-screen agents refine these) --------- */
.exercise-log-row { padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.exercise-log-row:first-child { border-top: none; padding-top: 0; }
.exercise-log-row > .field-group { max-width: 120px; }

.note-entry { padding-top: var(--space-4); margin-top: var(--space-4); border-top: 1px solid var(--border); }
.note-entry:first-of-type { padding-top: var(--space-2); margin-top: var(--space-3); border-top: none; }
.note-entry > div:last-child { margin-top: var(--space-1); }

.exercise-name { font-weight: 600; min-width: 180px; }
.target-hint { font-size: var(--text-xs); color: var(--text-muted); }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(380px, 100%), 1fr)); gap: var(--space-4); }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); box-shadow: var(--shadow-sm); }
.chart-card h3 { font-size: var(--text-sm); margin-bottom: var(--space-3); color: var(--text-muted); }
canvas { max-width: 100%; }

.type-selector { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }
.type-btn {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0.4rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.type-btn:hover { background: var(--surface-2); text-decoration: none; }
.type-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

.metric-row { display: flex; gap: var(--space-2); align-items: center; margin-bottom: var(--space-2); }
.metric-row input[type="text"] { flex: 1; }
.metric-row select.timer-kind-select,
.metric-row select.value-kind-select { width: auto; flex: 0 0 auto; padding: 0.4rem 0.5rem; font-size: var(--text-sm); }
.metric-row .timer-seconds-wrapper input[type="number"] { width: 9rem; padding: 0.4rem 0.5rem; font-size: var(--text-sm); }

.rest-timer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  margin-top: var(--space-2);
}
.rest-timer-label { font-size: var(--text-xs); color: var(--text-muted); font-weight: 600; }
.rest-timer .timer-display { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent-text); min-width: 3.2rem; }
.rest-timer .btn { font-size: var(--text-xs); padding: 0.35rem 0.7rem; }

.set-timer { display: flex; align-items: center; gap: 0.3rem; }
.set-timer input[type="number"] { flex: 1; min-width: 0; }
.set-timer .timer-display { font-variant-numeric: tabular-nums; font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }
.set-timer .btn-timer-toggle {
  padding: 0.3rem 0.5rem;
  min-height: 34px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--accent-text);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.set-timer .btn-timer-toggle:hover { background: var(--accent); color: var(--accent-contrast); }

.exercise-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.exercise-row.dragging { position: relative; z-index: 10; opacity: 0.9; box-shadow: var(--shadow-lg); }
.exercise-row-main { display: flex; align-items: flex-start; gap: var(--space-2); min-width: 0; }
.drag-handle { cursor: grab; touch-action: none; user-select: none; color: var(--text-muted); font-size: 1.2rem; line-height: 1.5; padding: 0 var(--space-1); }
.exercise-row.dragging .drag-handle { cursor: grabbing; }

/* Discover / templates */
.discover-sort { display: flex; gap: var(--space-4); margin: var(--space-4) 0; flex-wrap: wrap; }
.discover-sort a.active { font-weight: 700; text-decoration: underline; }
.tag-rail { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }
.tag-rail a { font-size: var(--text-sm); color: var(--text-muted); }
.tag-rail a.active { font-weight: 700; color: var(--accent-text); }
.tag-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: var(--space-2) 0; }
.tag-chip { font-size: var(--text-xs); font-weight: 600; background: var(--accent-soft); border-radius: var(--radius-pill); padding: 0.1rem 0.65rem; color: var(--accent-text); }
.template-card { display: flex; flex-direction: column; gap: 0.4rem; }
.template-card-actions { display: flex; gap: var(--space-2); align-items: center; margin-top: var(--space-2); flex-wrap: wrap; }
.pager { display: flex; gap: var(--space-5); margin: var(--space-5) 0; }
.like-button form { display: inline; }

/* ---- 9. Flash, sync strip, banners -------------------------------------- */
.flash {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
  border: 1px solid transparent;
  font-weight: 500;
}
.flash-notice { background: var(--success-soft); color: var(--success-text); border-color: var(--success); }
.flash-alert, .flash-error { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger); }

/* `.sync-status` and siblings render INSIDE `#app-main.container` (supplies width
   and gutters). `.flash-region` is a body-level sibling so it centres itself. */
.sync-status { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-3); }
.sync-status .btn { font-size: var(--text-xs); padding: 0.3rem 0.8rem; min-height: 34px; }
.sync-status__label { font-size: var(--text-sm); color: var(--text-muted); }
.sync-status__label--syncing { color: var(--accent-text); }
.sync-status__label--offline,
.sync-status__label--reauth { color: var(--warning-text); font-weight: 600; }
.sync-status__label a { color: inherit; }

/* "Some changes didn't sync" chip; wraps onto its own line under the controls. */
.sync-errors {
  flex-basis: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--warning-text);
  background: var(--warning-soft);
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
}
.sync-errors__summary { font-weight: 600; cursor: pointer; }
.sync-errors ul { list-style: none; margin: 0; padding: 0; }

.restore-notice,
.ios-install-hint {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  color: var(--warning-text);
  background: var(--warning-soft);
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
}

.app-view { margin-top: var(--space-3); }

/* Shown only with JavaScript disabled. */
.noscript-notice {
  max-width: var(--content-w);
  margin: var(--space-5) auto;
  padding: var(--space-4) var(--space-5);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.noscript-notice a { color: inherit; }

.restoring-splash { margin: var(--space-5) 0; color: var(--text-muted); }

/* Client flash region (`flash()` in layout.js): empty until it carries a message. */
.flash-region:not(:empty) {
  max-width: var(--content-w);
  margin: var(--space-3) auto 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
}
.flash-region--notice { background: var(--success-soft); color: var(--success-text); border: 1px solid var(--success); }
.flash-region--alert { background: var(--danger-soft); color: var(--danger-text); border: 1px solid var(--danger); }
@media (max-width: 1000px) { .flash-region:not(:empty) { margin-left: var(--space-4); margin-right: var(--space-4); } }

.impersonation-banner {
  background: var(--warning-soft);
  border-bottom: 1px solid var(--warning);
  color: var(--warning-text);
  padding: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  font-weight: 500;
}
.impersonation-banner form { display: inline; margin: 0; }
.impersonation-banner .btn { font-size: var(--text-xs); padding: 0.3rem 0.7rem; min-height: 34px; }
