:root {
  --md-primary: #6750a4; --md-on-primary: #ffffff;
  --md-primary-container: #eaddff; --md-on-primary-container: #21005d;
  --md-secondary-container: #e8def8; --md-on-secondary-container: #1d192b;
  --md-surface: #fffbfe; --md-on-surface: #1c1b1f; --md-on-surface-variant: #49454f;
  --md-surface-container: #f3edf7; --md-surface-container-high: #ece6f0; --md-surface-container-highest: #e6e0e9;
  --md-outline: #79747e; --md-outline-variant: #cac4d0;
  --md-error: #b3261e; --md-on-error: #ffffff; --md-error-container: #f9dedc;
  --md-inverse-surface: #313033; --md-inverse-on-surface: #f4eff4;
  --md-scrim: rgba(0,0,0,.4);
  --md-shadow-1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
  --md-shadow-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.3);
  --md-radius: 12px; --md-radius-lg: 28px;
  /* Motion: entrances decelerate into place, exits accelerate away. Every
     duration is a token so prefers-reduced-motion can flatten all of them. */
  --md-ease: cubic-bezier(.2, 0, 0, 1);
  --md-ease-out: cubic-bezier(.05, .7, .1, 1);
  --md-ease-in: cubic-bezier(.3, 0, .8, .15);
  --md-dur-short: 120ms; --md-dur-med: 220ms; --md-dur-long: 380ms;
  --md-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --md-primary: #d0bcff; --md-on-primary: #381e72;
    --md-primary-container: #4f378b; --md-on-primary-container: #eaddff;
    --md-secondary-container: #4a4458; --md-on-secondary-container: #e8def8;
    --md-surface: #141218; --md-on-surface: #e6e0e9; --md-on-surface-variant: #cac4d0;
    --md-surface-container: #211f26; --md-surface-container-high: #2b2930; --md-surface-container-highest: #36343b;
    --md-outline: #938f99; --md-outline-variant: #49454f;
    --md-error: #f2b8b5; --md-on-error: #601410; --md-error-container: #8c1d18;
    --md-inverse-surface: #e6e0e9; --md-inverse-on-surface: #313033;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--md-font); font-size: 16px; line-height: 1.4; color: var(--md-on-surface); background: var(--md-surface); -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.icon { display: inline-block; vertical-align: middle; flex: none; }
[hidden] { display: none !important; }

/* Height the bottom navigation takes out of the screen; 0 on pages without one,
   so the FAB and the snackbar sit where they always did on the admin. */
:root { --nav-h: 0px; }
body.has-nav { --nav-h: calc(64px + env(safe-area-inset-bottom)); }
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  height: var(--nav-h); padding: 0 4px env(safe-area-inset-bottom);
  background: var(--md-surface-container); }
.bottom-bar.select-mode { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }

/* Top app bar */
.top-bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px; min-height: 64px; height: calc(64px + env(safe-area-inset-top)); padding: 0 4px 0 4px; background: var(--md-surface); padding-top: env(safe-area-inset-top); }
.top-bar.scrolled { background: var(--md-surface-container); }
.top-bar .title, .bottom-bar .title { flex: 1; min-width: 0; font-size: 22px; font-weight: 400; display: flex; align-items: center; gap: 4px; padding: 0 8px; height: 48px; border-radius: 24px; overflow: hidden; }
.top-bar .title span, .bottom-bar .title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-bar.select-mode { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 24px; border-radius: 24px; font-weight: 500; font-size: 16px; white-space: nowrap; transition: background var(--md-dur-med) var(--md-ease), box-shadow var(--md-dur-med) var(--md-ease), transform var(--md-dur-short) var(--md-ease); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .38; pointer-events: none; }
.btn-filled { background: var(--md-primary); color: var(--md-on-primary); }
.btn-tonal { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.btn-text { color: var(--md-primary); padding: 0 12px; }
.btn-outlined { color: var(--md-primary); border: 1px solid var(--md-outline); }
.btn-danger { background: var(--md-error-container); color: var(--md-on-surface); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 50%; color: var(--md-on-surface-variant); }
.fab-group { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom) + var(--nav-h)); z-index: 20; display: flex; align-items: center; gap: 12px; }
.fab { display: inline-flex; align-items: center; justify-content: center; gap: 12px; height: 56px; padding: 0 20px; border-radius: 16px; background: var(--md-primary-container); color: var(--md-on-primary-container); font-weight: 500; box-shadow: var(--md-shadow-3); }
/* Secondary action: square, no label, and a quieter surface so the download
   stays the obvious one. */
.fab-second { width: 56px; padding: 0; background: var(--md-surface-container-high); color: var(--md-on-surface-variant); }

/* Sheets, dialogs, snackbar */
.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: var(--md-scrim); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 80vh; overflow: auto; background: var(--md-surface-container); border-radius: var(--md-radius-lg) var(--md-radius-lg) 0 0; padding: 8px 0 calc(16px + env(safe-area-inset-bottom)); overscroll-behavior: contain;
  animation: sheet-in var(--md-dur-long) var(--md-ease-out); transition: transform var(--md-dur-med) var(--md-ease-out); }
.sheet .handle { width: 32px; height: 4px; border-radius: 2px; background: var(--md-outline); margin: 8px auto 12px; }
.sheet h3 { margin: 4px 24px 8px; font-size: 14px; font-weight: 500; color: var(--md-on-surface-variant); }
@keyframes sheet-in { from { transform: translateY(100%); } }
.dialog-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--md-scrim); display: flex; align-items: center; justify-content: center; padding: 24px; }
.dialog { width: 100%; max-width: 420px; background: var(--md-surface-container-high); border-radius: var(--md-radius-lg); padding: 24px; box-shadow: var(--md-shadow-3); }
.dialog h2 { margin: 0 0 12px; font-size: 24px; font-weight: 400; }
.dialog p { margin: 0 0 20px; color: var(--md-on-surface-variant); }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.snackbar { position: fixed; left: 16px; right: 16px; bottom: calc(24px + env(safe-area-inset-bottom) + var(--nav-h)); z-index: 50; margin: 0 auto; max-width: 560px; padding: 14px 16px; border-radius: 8px; background: var(--md-inverse-surface); color: var(--md-inverse-on-surface); box-shadow: var(--md-shadow-3); display: flex; align-items: center; gap: 12px; }
.snackbar .btn-text { color: var(--md-primary-container); margin-left: auto; }
body.has-snackbar .fab-group { bottom: calc(88px + env(safe-area-inset-bottom) + var(--nav-h)); }

/* Lists, cards, fields, misc */
.list-item { display: flex; align-items: center; gap: 16px; min-height: 56px; padding: 8px 24px; width: 100%; text-align: left; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .sub { font-size: 14px; color: var(--md-on-surface-variant); }
.list-item.selected { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.card { background: var(--md-surface-container); border-radius: var(--md-radius); padding: 16px; }
.text-field { display: block; width: 100%; min-height: 56px; padding: 16px; border: 1px solid var(--md-outline); border-radius: 4px; background: transparent; color: inherit; font: inherit; }
.text-field:focus { outline: 2px solid var(--md-primary); border-color: transparent; }
.progress { height: 4px; border-radius: 2px; background: var(--md-surface-container-highest); overflow: hidden; }
.progress > div { height: 100%; background: var(--md-primary); transition: width var(--md-dur-med) var(--md-ease); }
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--md-surface-container-high); border-radius: var(--md-radius); margin: 8px 16px; }
.banner p { margin: 0; flex: 1; font-size: 15px; }
.error-text { color: var(--md-error); }
.center { text-align: center; padding: 48px 24px; color: var(--md-on-surface-variant); }
.spinner { width: 40px; height: 40px; border: 4px solid var(--md-surface-container-highest); border-top-color: var(--md-primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Motion ---------------------------------------------------------------
   Everything below is feedback and choreography: press states, the ripple, and
   the paired enter/exit animations the JS drives by adding `.out`. */

@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* Touch feedback: a state layer that follows :active, plus the ripple motion.js
   spawns under the finger. Both tint with the surface's own colour. */
/* The ripple needs a positioning context and a clip. Nothing in this list may
   also set `position` in its own rule: this one comes later in the file and would
   win on source order. .fab-group is the fixed one; .fab itself is not. */
.btn, .icon-btn, .list-item, .fab, .top-bar .title, .bottom-bar .title, .day-check { position: relative; overflow: hidden; }
.btn::before, .icon-btn::before, .list-item::before, .fab::before, .top-bar .title::before, .bottom-bar .title::before, .day-check::before {
  content: ''; position: absolute; inset: 0; background: currentColor; opacity: 0;
  pointer-events: none; transition: opacity var(--md-dur-med) var(--md-ease);
}
.btn:active::before, .icon-btn:active::before, .list-item:active::before,
.fab:active::before, .top-bar .title:active::before, .bottom-bar .title:active::before, .day-check:active::before { opacity: .1; transition-duration: var(--md-dur-short); }
.ripple { position: absolute; border-radius: 50%; background: currentColor; opacity: .18;
  pointer-events: none; transform: scale(0); animation: ripple 520ms var(--md-ease-out) forwards; }
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

/* App bars: the surface swap on scroll and on select mode is a fade, never a jump. */
.top-bar, .bottom-bar { transition: background var(--md-dur-med) var(--md-ease), color var(--md-dur-med) var(--md-ease), box-shadow var(--md-dur-med) var(--md-ease); }
/* Only a real mode change (browse <-> select) re-animates the bar's contents: the
   selected-count rewrite happens on every tap and must not flicker. */
.swap > * { animation: bar-item-in var(--md-dur-med) var(--md-ease-out); }
@keyframes bar-item-in { from { opacity: 0; transform: translateY(6px); } }

/* FAB: grows in with the selection, shrinks away with it, and slides rather than
   jumps when a snackbar pushes it up. */
.fab-group { transition: bottom var(--md-dur-long) var(--md-ease); }
.fab { animation: fab-in var(--md-dur-long) var(--md-ease-out);
  transition: transform var(--md-dur-short) var(--md-ease), box-shadow var(--md-dur-med) var(--md-ease); }
/* The secondary comes in a beat behind the primary rather than with it. */
.fab-second { animation-delay: 60ms; animation-fill-mode: backwards; }
@keyframes fab-in { from { opacity: 0; transform: scale(.7) translateY(16px); } }
.fab-group.out { animation: fab-out var(--md-dur-med) var(--md-ease-in) forwards; pointer-events: none; }
@keyframes fab-out { to { opacity: 0; transform: scale(.7) translateY(16px); } }
.fab:active { transform: scale(.96); }

/* Sheets and dialogs: scrim fades, surface travels. */
.sheet-backdrop { animation: fade-in var(--md-dur-med) var(--md-ease-out); }
.sheet-backdrop.out { animation: fade-out var(--md-dur-med) var(--md-ease-in) forwards; pointer-events: none; }
.sheet-backdrop.out .sheet { animation: sheet-out var(--md-dur-med) var(--md-ease-in) forwards; }
@keyframes sheet-out { to { transform: translateY(100%); } }
/* Held by the drag-to-dismiss handler while a finger is on the sheet. */
.sheet.dragging { transition: none; }
.dialog-backdrop { animation: fade-in var(--md-dur-med) var(--md-ease-out); }
.dialog-backdrop.out { animation: fade-out var(--md-dur-short) var(--md-ease-in) forwards; pointer-events: none; }
.dialog { animation: dialog-in var(--md-dur-long) var(--md-ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: scale(.85); } }
.dialog-backdrop.out .dialog { animation: dialog-out var(--md-dur-short) var(--md-ease-in) forwards; }
@keyframes dialog-out { to { opacity: 0; transform: scale(.9); } }

.snackbar { animation: snack-in var(--md-dur-long) var(--md-ease-out); }
@keyframes snack-in { from { opacity: 0; transform: translateY(28px) scale(.96); } }
.snackbar.out { animation: snack-out var(--md-dur-med) var(--md-ease-in) forwards; pointer-events: none; }
@keyframes snack-out { to { opacity: 0; transform: translateY(28px) scale(.96); } }

.banner { animation: banner-in var(--md-dur-long) var(--md-ease-out); }
@keyframes banner-in { from { opacity: 0; transform: translateY(-12px); } }
.banner.out { animation: banner-out var(--md-dur-med) var(--md-ease-in) forwards; pointer-events: none; }
@keyframes banner-out { to { opacity: 0; transform: translateY(-12px) scale(.98); } }

.list-item { transition: background var(--md-dur-short) var(--md-ease), color var(--md-dur-short) var(--md-ease); }
.text-field { transition: border-color var(--md-dur-short) var(--md-ease), outline-color var(--md-dur-short) var(--md-ease); }

/* Reduced motion: keep every state change, drop the travel. The spinner is a
   progress indicator, not decoration, so it keeps turning at its own pace. */
@media (prefers-reduced-motion: reduce) {
  :root { --md-dur-short: 1ms; --md-dur-med: 1ms; --md-dur-long: 1ms; }
  *:not(.spinner) { animation-duration: 1ms !important; animation-delay: 0ms !important; }
  *:not(.spinner)::before, *:not(.spinner)::after { animation-duration: 1ms !important; animation-delay: 0ms !important; }
  .ripple { display: none; }
}
