:root {
  /* Match DEFAULT_COLORS in app.js so the brief pre-init flash uses the right hue.
     soft/deep variants derived via the same parentShades() math so they match
     what applyParentColors() writes once JS runs. */
  --p1: #2359fb;
  --p1-soft: #dee6fe;
  --p1-deep: #13318a;
  --p2: #ff2e85;
  --p2-soft: #ffe0ed;
  --p2-deep: #8c1949;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-elev: #e8ecf2;
  --border: #e1e4ea;
  --text: #1f2433;
  --muted: #6b7280;
  --hover-bg: #eef0f4;
  --today-outline: #22c55e;
  --danger: #c0392b;
  --danger-bg: #ffeceb;
  --danger-border: #f3b7b2;
  --bar-unassigned: #e5e7eb;
  --unassigned-dot: #d1d5db;
  --invert-bg: #1f2433;
  --invert-text: #ffffff;
  --segmented-thumb: #ffffff;
  --inset-hover: rgba(0, 0, 0, 0.06);
  --shadow: 0 1px 3px rgba(20, 24, 40, 0.05), 0 4px 16px rgba(20, 24, 40, 0.04);
  --radius: 12px;
}

[data-theme="dark"] {
  --p1: #2359fb;
  --p1-soft: rgba(35, 89, 251, 0.16);
  --p1-deep: #7b9bfd;
  --p2: #ff2e85;
  --p2-soft: rgba(255, 46, 133, 0.16);
  --p2-deep: #ff82b6;
  --bg: #0d0d10;
  --surface: #161b27;
  --surface-elev: #2c3349;
  --border: #2a3043;
  --text: #e7e9ee;
  --muted: #9298a8;
  --hover-bg: #252b3a;
  --today-outline: #4ade80;
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --danger-border: rgba(248, 113, 113, 0.4);
  --bar-unassigned: #333a4a;
  --unassigned-dot: #4d5566;
  --invert-bg: #e7e9ee;
  --invert-text: #161b27;
  --segmented-thumb: #2c3247;
  --inset-hover: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

/* ---------- Top bar ---------- */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.top-bar h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.parent-inputs { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.parent-fields-row { display: flex; gap: 10px; }
.parent-inputs-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-left: 2px;
}

.top-bar-right {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.theme-toggle {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  color: var(--muted);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.08s;
  padding: 0;
}
.theme-toggle:hover { background: var(--hover-bg); color: var(--text); }
.theme-toggle:active { transform: scale(0.94); }
.theme-toggle svg { width: 18px; height: 18px; display: block; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.parent-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  box-shadow: var(--shadow);
}
.parent-field input[type="text"] {
  border: none;
  background: transparent;
  font: inherit;
  color: var(--text);
  width: 130px;
  outline: none;
  font-weight: 500;
}
.gender-mark {
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
  flex-shrink: 0;
  user-select: none;
}
.parent-field.p1 .gender-mark { color: var(--p1-deep); }
.parent-field.p2 .gender-mark { color: var(--p2-deep); }
/* Native color input styled to look like the old static .swatch dot. */
.swatch-hit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  border-radius: 50%;
}
/* WCAG 2.5.5 minimum touch target — only on coarse pointers so desktop layout
   stays compact. The visible swatch inside stays 16 px. */
@media (pointer: coarse) {
  .swatch-hit { padding: 14px; }
}
.swatch-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: transparent;
  flex-shrink: 0;
  overflow: hidden;
  box-sizing: border-box;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.swatch-input:hover { transform: scale(1.12); box-shadow: 0 0 0 2px var(--inset-hover); }
.swatch-input:focus-visible { outline: 2px solid var(--today-outline); outline-offset: 2px; }
.swatch-input::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
.swatch-input::-webkit-color-swatch { border: none; border-radius: 50%; }
.swatch-input::-moz-color-swatch { border: none; border-radius: 50%; }

/* ---------- Controls row ---------- */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

.toggle-group {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow);
}

.toggle {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s ease;
}
.toggle.p1.active { background: var(--p1); color: #fff; }
.toggle.p2.active { background: var(--p2); color: #fff; }
.toggle:not(.active):hover { background: var(--hover-bg); color: var(--text); }

.month-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}
.month-label {
  font-size: 16px;
  font-weight: 600;
  min-width: 160px;
  text-align: center;
  transform-origin: center;
}
@keyframes year-flash-anim {
  0%   { transform: scale(1);    color: var(--text); text-shadow: none; }
  /* Year-flash green — same family as --today-outline. Hardcoded so the dark-theme
     palette doesn't suddenly desaturate the flash. */
  30%  { transform: scale(1.10); color: #22c55e; text-shadow: 0 0 12px rgba(34, 197, 94, 0.55); }
  100% { transform: scale(1);    color: var(--text); text-shadow: none; }
}
.month-label.year-flash {
  animation: year-flash-anim 0.55s ease-out;
}

.nav-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: background 0.15s;
}
.nav-btn:hover { background: var(--hover-bg); }

.secondary-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 14px;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: background 0.15s, border-color 0.15s;
}
.secondary-btn:hover { background: var(--hover-bg); }
.secondary-btn.danger { color: var(--danger); }
.secondary-btn.danger:hover { background: var(--danger-bg); border-color: var(--danger-border); }

.primary-btn {
  border: 1px solid var(--invert-bg);
  background: var(--invert-bg);
  color: var(--invert-text);
  padding: 9px 18px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.08s;
  box-shadow: var(--shadow);
}
.primary-btn:hover { opacity: 0.88; }
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Templates popover ---------- */
.templates-wrap { position: relative; display: inline-flex; }
.templates-btn { font-weight: 600; }
.templates-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: min(360px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(20, 24, 40, 0.10), 0 16px 40px rgba(20, 24, 40, 0.10);
  padding: 14px 16px 12px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.templates-popover.hidden { display: none; }
@media (max-width: 720px) {
  .templates-popover { left: auto; right: 0; }
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.template-option {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface-elev);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.template-option:hover { background: var(--hover-bg); }
.template-option.active {
  border-color: var(--invert-bg);
  box-shadow: 0 0 0 1px var(--invert-bg) inset;
}
.template-name { font-weight: 600; font-size: 13px; }
.template-alias { font-weight: 400; color: var(--muted); font-size: 11px; margin-left: 4px; }
.template-desc { font-size: 11px; color: var(--muted); line-height: 1.35; }

.template-apply-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
  padding-top: 12px;
}

.bulk-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* Clear buttons live in a sub-group so they wrap to a new row as a UNIT instead
   of breaking apart. `margin-left: auto` right-aligns the group when it shares
   a line with the left buttons; on its own row it sits at the right edge.
   The ::before draws the visual separator and travels with the group. */
.bulk-clear-group {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-left: auto;
  padding-left: 12px;
  position: relative;
}
.bulk-clear-group::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: var(--border);
}

/* ---------- Calendar ---------- */
.calendar-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
@keyframes calendar-year-flash-anim {
  0%, 100% { box-shadow: var(--shadow); }
  30% {
    box-shadow:
      var(--shadow),
      0 0 0 6px rgba(34, 197, 94, 0.55),        /* sharp green ring on the edge */
      0 0 28px 6px rgba(34, 197, 94, 0.40);     /* soft green outer halo */
  }
}
.calendar-wrap.year-flash {
  animation: calendar-year-flash-anim 0.65s ease-out;
}

/* Every day cell briefly stroked with a green inset during a year change. */
@keyframes day-cell-year-flash-anim {
  0%, 100% { box-shadow: none; }
  30%      { box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.55) inset; }
}
.calendar-grid.year-flash .day-cell {
  animation: day-cell-year-flash-anim 0.65s ease-out;
}

.weekday-header {
  display: grid;
  /* `minmax(0, 1fr)` lets the day columns shrink below the intrinsic width of
     the weekday-button text without breaking grid math. The week-pick column
     has its own minmax so it can shrink (down to ~56 px) on narrow viewports
     while still being wide enough for the button labels. Both grids below
     MUST keep these track definitions identical or the columns drift. */
  grid-template-columns: repeat(7, minmax(0, 1fr)) minmax(56px, 80px);
  gap: 6px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.weekday-header > * {
  padding: 6px 8px;
  text-align: center;
  border-radius: 6px;
}
.weekday-btn {
  border: none;
  background: transparent;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, color 0.12s;
}
.weekday-btn:hover {
  background: var(--hover-bg);
  color: var(--text);
}
.weekday-btn:active { transform: scale(0.96); }
.weekday-btn.active-target {
  background: var(--invert-bg);
  color: var(--invert-text);
  box-shadow: 0 2px 6px rgba(20, 24, 40, 0.18);
}
.weekday-btn.active-target:hover { background: var(--invert-bg); color: var(--invert-text); }
.week-col-header { border-left: 1px solid var(--border); }

.calendar-grid {
  display: grid;
  /* MUST mirror .weekday-header track definitions exactly — same minmax() so
     column widths resolve identically and the two grids stay aligned. */
  grid-template-columns: repeat(7, minmax(0, 1fr)) minmax(56px, 80px);
  gap: 6px;
}
/* Row wrappers carry role="row" for ARIA but `display: contents` keeps their
   children participating in .calendar-grid's column layout. */
.calendar-row { display: contents; }

.day-cell {
  aspect-ratio: 1 / 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-elev);
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 6px 8px;
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
  user-select: none;
  position: relative;
  /* Belt-and-suspenders: pair with minmax(0, 1fr) on the parent so a cell can
     shrink below its content's intrinsic width without forcing column growth. */
  min-width: 0;
  /* Allow vertical page scroll on a touch that starts on a cell; horizontal drag
     and the post-long-press paint gesture are owned by us via preventDefault. */
  touch-action: pan-y;
}
.day-cell.drag-armed {
  transform: scale(1.05);
  box-shadow: 0 0 0 3px var(--today-outline) inset;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.day-cell:hover { box-shadow: 0 0 0 2px var(--inset-hover) inset; }
.day-cell:active { transform: scale(0.97); }

/* Ghost cells = the leading/trailing days from adjacent months that pad the
   current month's grid. Fully interactive (selectable, drag-paintable, week-
   pick targets) — only visually muted to signal "this belongs to a different
   month." Their dataset.key points to the actual prior/next-month date so
   assignments persist exactly where they should. */
.day-cell.ghost {
  opacity: 0.42;
}
.day-cell.ghost:not(.p1):not(.p2) {
  color: var(--muted);
}
.day-cell.ghost:hover {
  opacity: 0.7;
}

.day-cell.today {
  outline: 2px solid var(--today-outline);
  outline-offset: -2px;
}

.day-cell.p1 {
  background: var(--p1-soft);
  border-color: var(--p1);
  color: var(--p1-deep);
}
.day-cell.p2 {
  background: var(--p2-soft);
  border-color: var(--p2);
  color: var(--p2-deep);
}
/* Parent gender symbol — non-color signal so ownership reads under any palette,
   including for color-blind users. data-parent-symbol set by setOwnerClass. */
.day-cell[data-parent-symbol]::before {
  content: attr(data-parent-symbol);
  position: absolute;
  bottom: 3px;
  left: 5px;
  font-size: 15px;
  line-height: 1;
  font-weight: 700;
  opacity: 0.85;
  pointer-events: none;
}
.day-cell:focus-visible {
  outline: 2px solid var(--today-outline);
  outline-offset: 2px;
  z-index: 1;
}

.day-cell .weekend-dot {
  position: absolute;
  left: 6px;
  top: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.45;
}

/* Week pick column */
.week-pick-cell {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-elev);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: stretch;
  font-size: 10px;
  font-weight: 600;
  min-width: 0;
}
.week-pick-cell.empty { background: transparent; border: none; }

.week-pick-btn {
  /* flex:1 makes both buttons grow to evenly split the cell's row height —
     larger tap target on small screens than the previous content-height pills. */
  flex: 1;
  min-height: 30px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 5px;
  padding: 6px 2px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 10px;
  transition: all 0.15s;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.week-pick-btn:hover { background: var(--hover-bg); }
.week-pick-btn.p1-active { background: var(--p1); color: #fff; border-color: var(--p1); }
.week-pick-btn.p2-active { background: var(--p2); color: #fff; border-color: var(--p2); }

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 14px 0 0;
  line-height: 1.5;
}

/* ---------- Weekday popover ---------- */
.weekday-popover {
  position: absolute;
  width: min(300px, calc(100% - 36px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(20, 24, 40, 0.10), 0 16px 40px rgba(20, 24, 40, 0.10);
  padding: 14px 16px 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.weekday-popover.hidden { display: none; }

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.popover-title {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.01em;
}
.popover-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 8px;
  border-radius: 6px;
  height: 28px;
}
.popover-close:hover { background: var(--hover-bg); color: var(--text); }

.popover-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.popover-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex: 0 0 56px;
}

.segmented {
  display: inline-flex;
  background: var(--hover-bg);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
  flex: 1;
}
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 10px;
  border-radius: 6px;
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.seg-btn:hover:not(.active) { color: var(--text); }
.seg-btn.active {
  background: var(--invert-bg);
  color: var(--invert-text);
  box-shadow: 0 1px 3px rgba(20, 24, 40, 0.22);
}
/* Parent-colored variants override the neutral active style above via higher specificity. */
.seg-btn.p1.active { background: var(--p1); color: #fff; box-shadow: 0 1px 3px rgba(20, 24, 40, 0.22); }
.seg-btn.p2.active { background: var(--p2); color: #fff; box-shadow: 0 1px 3px rgba(20, 24, 40, 0.22); }

.popover-cycle {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  box-shadow: var(--shadow);
}
.popover-cycle:hover { background: var(--hover-bg); }
.popover-cycle:active { transform: scale(0.98); }

.popover-status {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  line-height: 1.4;
}
.popover-status strong {
  color: var(--text);
  font-weight: 600;
}

.popover-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
  font-style: italic;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 40, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: modal-fade 0.18s ease-out;
}
.modal-backdrop.hidden { display: none; }

@keyframes modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px 24px 20px;
  width: min(420px, 100%);
  box-shadow: 0 20px 50px rgba(20, 24, 40, 0.20), 0 4px 16px rgba(20, 24, 40, 0.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: modal-pop 0.2s ease-out;
}

@keyframes modal-pop {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.modal-close {
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 8px;
  height: 28px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--hover-bg); color: var(--text); }

.modal-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.modal-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.modal-label {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  flex: 0 0 56px;
}
.modal-row input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  outline: none;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.modal-row input:focus {
  border-color: var(--p1);
  box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.18);
}

.modal-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

/* ---------- Totals ---------- */
.totals { margin-bottom: 20px; }
.totals h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 10px;
}
.totals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.totals-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
/* "This Year" card — visually anchors the trio. Slate-500 chosen to read
   strongly in both themes without pulling in a parent or accent color. */
.totals-card-featured {
  border: 2px solid #64748b;
  box-shadow: var(--shadow), 0 0 0 4px rgba(100, 116, 139, 0.12);
}
.card-title {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
  font-weight: 600;
}
.card-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.parent-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}
.parent-row .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.parent-row.p1 .dot { background: var(--p1); }
.parent-row.p2 .dot { background: var(--p2); }
.parent-row.unassigned .dot { background: var(--unassigned-dot); }
.parent-row.unassigned .label,
.parent-row.unassigned .count,
.parent-row.unassigned .pct { color: var(--muted); }
.parent-row .label {
  flex: 1;
  color: var(--text);
}
.parent-row .count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}
.parent-row .pct {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 48px;
  text-align: right;
}

.bar {
  height: 6px;
  background: var(--hover-bg);
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  margin-top: 2px;
}
.bar .bar-p1 { background: var(--p1); }
.bar .bar-p2 { background: var(--p2); }
.bar .bar-unassigned { background: var(--bar-unassigned); }

/* ---------- Data tools ---------- */
.data-tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.file-label { display: inline-flex; align-items: center; cursor: pointer; }

@media (max-width: 720px) {
  .weekday-header, .calendar-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr)) minmax(48px, 60px);
  }
  .day-cell { font-size: 12px; padding: 4px 6px; }
  .week-pick-btn { font-size: 9px; min-height: 28px; }
  .month-label { min-width: 130px; }
}

/* Visually-hidden utility for the aria-live announcement region. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Keyboard focus ring across every interactive element — the browser default
   is invisible against the inverted dark-mode buttons. */
.toggle:focus-visible,
.nav-btn:focus-visible,
.secondary-btn:focus-visible,
.primary-btn:focus-visible,
.theme-toggle:focus-visible,
.weekday-btn:focus-visible,
.week-pick-btn:focus-visible,
.seg-btn:focus-visible,
.popover-cycle:focus-visible,
.popover-close:focus-visible,
.modal-close:focus-visible,
.swatch-hit:focus-visible {
  outline: 2px solid var(--today-outline);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .month-label.year-flash,
  .calendar-wrap.year-flash,
  .calendar-grid.year-flash .day-cell,
  .modal-backdrop,
  .modal {
    animation: none !important;
  }
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Back to StageLine.net ---------- */
.site-backlink { margin: 40px auto 8px; text-align: center; }
.backlink {
  display: inline-flex; align-items: center; gap: 9px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font-size: 13.5px; font-weight: 600; text-decoration: none;
  transition: color .18s, border-color .18s, background .18s;
}
.backlink:hover { color: var(--text); border-color: var(--accent, #9333ea); background: var(--accent-soft, rgba(147,51,234,.08)); }
.backlink:focus-visible { outline: 2px solid var(--accent, #9333ea); outline-offset: 2px; }
.backlink-mark {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 6px; background: #9333ea; color: #fff; font-weight: 800; font-size: 12px;
}
