/* ==========================================================
   Apple/Google Calendar-style: Time Grid, Week View, Pills
   ========================================================== */

/* Month view — colored task pills. A pill is a row: checkbox, title, cancel, add.
   Only the title flexes; the controls keep their width so titles never push them out. */
.cal-month-pill {
  display: flex;
  align-items: center;
  gap: 3px;
  border-radius: var(--radius-xs);
  padding: 1px 4px;
  font-size: var(--fs-11);
  text-decoration: none;
  white-space: nowrap;
  margin-bottom: 2px;
  line-height: 1.45;
  color: var(--text-1);
  transition: filter var(--dur-fast);
  min-width: 0;
  overflow: hidden;
  background: color-mix(in srgb, var(--cat, #4d9fff) 17%, transparent);
  min-height: var(--cal-pill-height, 20px);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.cal-month-pill:hover { filter: brightness(1.2); }
/* The tint is the category's colour (--cat, set on the pill) over the cell. A recurring
   task still to do is outlined instead of filled: a daily habit lands on every day of the
   month, and filled it drowned out the one-offs that make each day different. Once done
   it takes its fill back — faded as done, an outline would leave it no colour at all. */

.cal-month-pill.is-recurring:not(.tg-completed) {
  background: transparent;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--cat, #4d9fff) 32%, transparent);
  color: var(--text-2);
}
/* AreaOfInterest::ROUTINE_TINT — kept under a routine's outline too, done or not. */
.cal-month-pill.is-routine,
.cal-month-pill.is-routine.is-recurring:not(.tg-completed) { background: #192e21; }
/* A place is where you were, not something to do: no fill of its own — it takes on
   whatever it sits in front of (the cell, today's tint, a block's wash) — and never
   outlined, even one that recurs. Its text is the recurring pills' grey either way, so a
   one-off place fades to the same shade as the habits around it. */
.cal-month-pill.is-place,
.cal-month-pill.is-place.is-recurring { background: transparent; box-shadow: none; color: var(--text-2); }
.cal-month-pill.is-faded { opacity: 0.4; }
.cal-month-pill.cal-block-member { background: transparent; box-shadow: none; }
/* Done reads from the fade and the ticked box; no strikethrough, which made the few
   words a pill has room for hard to read. */
.cal-month-pill.tg-completed { opacity: 0.45; }

/* The link is the text, not the row. It shrinks to what it says (margin-right keeps the
   controls out at the right edge), so the empty space beside a short title belongs to the
   pill — grab it there and drag, rather than clicking through to the task by accident.
   Dragging still works from the text too; a click only counts as a click if the pointer
   never travelled. */
.cal-pill-title {
  display: flex;
  align-items: baseline;
  gap: 4px;
  flex: 0 1 auto;
  margin-right: auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
/* Only the words are cut, by the width the cell has; the time either side stays whole. */
.cal-pill-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cal-pill-time,
.cal-pill-due { flex: 0 0 auto; font-size: var(--fs-10); font-variant-numeric: tabular-nums; }
.cal-pill-time { color: color-mix(in srgb, var(--cat, #4d9fff) 70%, #fff); font-weight: 600; }
.cal-pill-due { color: var(--text-3); }
.cal-month-pill.is-place .cal-pill-time { color: var(--text-3); }
/* The checkbox keeps the size it has everywhere else (.toggle-completed, further down
   this file) — it is the tallest thing in a pill, so it sets the row's height. The spacer
   a place task carries instead, and the row's floor, are both cut to that same number, so
   a pill stands the same height whether or not it has something to tick off. One value,
   named here, rather than three that can drift apart. */
/* Scoped to the page, not to a pill, because the block footer is cut to it too. */
/* A small round box rather than the day view's 22px square: a pill is a line of text,
   and the square was as tall as the line, crowding the title. The row keeps its own
   height (--cal-pill-height), which the block footer is cut to as well. */
#cal-root { --cal-check-size: 14px; --cal-pill-height: 20px; }

.cal-month-pill .cal-pill-check {
  flex: 0 0 auto;
  margin: 0 1px 0 0;
  cursor: pointer;
}
#cal-root .cal-month-pill .toggle-completed {
  width: var(--cal-check-size);
  height: var(--cal-check-size);
  border-width: 1.5px;
  border-color: rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  --check-stroke: 1.5px;
}
#cal-root .cal-month-pill .toggle-completed:checked { border-color: transparent; }
.cal-pill-check-spacer {
  display: inline-block;
  width: var(--cal-check-size, 22px);
  height: var(--cal-check-size, 22px);
  visibility: hidden;
}

/* A block's enclosure: the area's wash behind the whole group and one unbroken accent
   down its left edge, drawn by the wrapper rather than by each row — pills are 2px apart,
   so a per-row border draws as a dashed line instead of a single one. */
.cal-block-group {
  background: var(--block-wash, #080808);
  border-left: 3px solid var(--cat, #6b7280);
  border-radius: var(--radius-xs);
  overflow: hidden;
  margin-bottom: 2px;
  padding-bottom: 0;
}
.cal-block-group .cal-month-pill { margin-bottom: 0; border-radius: 0; }
.cal-block-group .cal-month-pill + .cal-month-pill { border-top: 1px solid var(--hairline); }
/* The band names the group, so its label sits centred over it. The checkbox-sized
   spacer on the left and the "+" on the right are near enough the same width that
   centring within the title's own space centres it over the row. */
.cal-block-band .cal-pill-title { justify-content: center; }
.cal-month-pill.cal-block-band { background: transparent; box-shadow: none; color: var(--cat); }
.cal-block-band {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: var(--fs-10);
  font-weight: 600;
  /* A band is a header, not something you drag. */
  cursor: default;
}

/* The closing strip, carrying the block's own cancel — the control the schedule
   column's footer carries. */
/* The closing strip stands as tall as the rows above it, so the group reads as an even
   stack rather than trailing off into a sliver. */
.cal-block-footer {
  position: relative;
  display: flex;
  align-items: stretch;
  min-height: var(--cal-pill-height, 20px);
  border-top: 1px solid var(--hairline-strong);
}
.cal-block-cancel {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  color: var(--text-3);
  font-size: var(--fs-11);
  line-height: 1;
  text-decoration: none;
  opacity: 0.55;
  transition: opacity var(--dur-fast), color var(--dur-fast), background var(--dur-fast);
}
.cal-block-group:hover .cal-block-cancel { opacity: 1; }
/* The footer's "+", at its right edge as in the schedule column: adds a task below the
   whole group. Waits for hover like the pills' own controls. */
.cal-block-add {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  color: var(--text-3);
  font-size: var(--fs-9);
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--dur-fast), color var(--dur-fast);
}
.cal-block-group:hover .cal-block-add,
.cal-block-add:focus-visible { opacity: 1; }
.cal-block-add:hover { color: var(--accent); }
@media (hover: none) { .cal-block-add { opacity: 0.6; } }
/* The global `a:hover {text-decoration: underline}` (0,1,1) outranks the reset above. */
.cal-block-cancel:hover {
  text-decoration: none;
  color: var(--blue);
  background: rgba(255, 255, 255, 0.04);
}

/* Dragging a task, by mouse or by finger. touch-action keeps a drag that starts on a
   pill from being taken over by the page's own scrolling; the cells around it still
   scroll normally. */
.cal-month-pill {
  cursor: grab;
}
.cal-pill-dragging { opacity: 0.45; cursor: grabbing; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45); }
/* A drag must not paint a selection behind it. The pill already opts out, but the pointer
   travels over the rest of the page too, and pointerdown can't preventDefault without
   killing the click — so selection is switched off everywhere for as long as a drag runs. */
body.cal-dragging,
body.cal-dragging * {
  cursor: grabbing !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}
/* The cancel/add icons stay out of the way until the pill is hovered — a month cell
   is too narrow to carry six always-lit icons per day and still read as a calendar. */
.cal-pill-btn {
  flex: 0 0 auto;
  color: var(--text-3);
  font-size: var(--fs-9);
  text-decoration: none;
  padding: 0 1px;
  opacity: 0;
  transition: opacity var(--dur-fast), color var(--dur-fast);
}
.cal-month-pill:hover .cal-pill-btn { opacity: 1; }
.cal-pill-btn:focus-visible { opacity: 1; }
.cal-pill-cancel:hover { color: var(--danger); }
.cal-pill-add:hover { color: var(--accent); }

/* ---- The calendar page: toolbar and month grid (/calendar) ---- */
.cal-root { padding: 1.25rem 1.5rem 1.5rem; }

/* ‹ Title › and Today, centred over the grid. */
.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 1rem;
  position: relative;
}
.cal-toolbar .cal-title {
  min-width: 11ch;
  margin: 0;
  color: var(--text-1);
  font-size: var(--fs-20);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: center;
}
/* Scoped to the toolbar: Stats has a .cal-nav-btn of its own. */
.cal-toolbar .cal-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-12);
  text-decoration: none;
  transition: color var(--dur-fast) ease, border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.cal-toolbar .cal-nav-btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-bright); }
.cal-toolbar .cal-today-btn {
  height: 30px;
  margin-left: 6px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-1);
  font-size: var(--fs-12);
  font-weight: 600;
  line-height: 28px;
  text-decoration: none;
  transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.cal-toolbar .cal-today-btn:hover { border-color: var(--border-strong); background: var(--surface-3); }
/* Already looking at today's month or week: nothing to go back to, so it isn't shown —
   but it holds its width, or the title would jump sideways as you page. */
.cal-toolbar .cal-today-btn.is-current { visibility: hidden; }
.cal-toolbar .cal-nav-btn:focus-visible, .cal-toolbar .cal-today-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The month: whole weeks, as tall as the window so each day has room for its tasks.
   --cal-weeks (4-6) is set on the table and each row takes its share of the window —
   sized on the rows, since a table hands any height of its own to whichever row it likes. */
.cal-month {
  width: 100%;
  border: 1px solid var(--border-panel);
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-card);
  color: var(--text-1);
  table-layout: fixed;
}
.cal-month th {
  height: 32px;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-2);
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}
.cal-month tbody tr { height: max(104px, calc((100dvh - 138px) / var(--cal-weeks, 5))); }
.cal-cell {
  position: relative;
  padding: 4px;
  border-top: 1px solid var(--border-panel);
  border-left: 1px solid var(--border-panel);
  vertical-align: top;
  overflow: hidden;
  transition: background-color var(--dur-fast) ease;
}
.cal-month tr > .cal-cell:first-child { border-left: none; }
.cal-month tbody tr:first-child > .cal-cell { border-top: none; }
.cal-cell.is-weekend { background: rgba(255, 255, 255, 0.012); }
/* Days gone by step back a little; today steps forward, the whole cell and not only
   its number, with a line of accent along its top. */
.cal-cell.is-past .cal-month-pill.tg-completed { opacity: 0.4; }
/* Today: its number in green and a faint wash. No bar across its top too — a third
   mark of the same day made it the loudest thing on the page. */
.cal-cell.is-today { background: rgba(34, 197, 94, 0.06); }
/* The neighbouring months' days: there to finish the rectangle, and to click through. */
.cal-cell.is-outside { background: rgba(0, 0, 0, 0.3); }
.cal-cell.is-outside .cal-day-num { color: var(--text-3); opacity: 0.55; }

/* Clicking anywhere on the cell opens the day. One highlight for one destination: the
   number and this overlay open the same page, so only the cell lights up. */
.cal-cell-link { position: absolute; inset: 0; z-index: 0; }
.cal-cell:hover > .cal-cell-link { background: rgba(255, 255, 255, 0.025); }
.cal-cell-top {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin-bottom: 3px;
}
.cal-cell-marks { display: flex; flex: 1; flex-wrap: nowrap; gap: 3px; min-width: 0; overflow: hidden; }
.cal-mark {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-xs);
  font-size: var(--fs-9);
}
.cal-mark.is-priority { background: rgba(251, 191, 36, 0.14); color: var(--gold-bright); }
.cal-mark.is-tracker { background: rgba(52, 211, 153, 0.13); color: #34d399; }
.cal-mark.is-subcategory { background: rgba(134, 239, 172, 0.12); color: #86efac; }
/* Scoped to the month grid: the home page's schedule calendar has a .cal-day-num of its own. */
.cal-month .cal-day-num {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  border-radius: 999px;
  color: var(--text-1);
  font-size: var(--fs-12);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
}
.cal-cell.is-past .cal-day-num { color: var(--text-3); }
.cal-cell.is-today .cal-day-num { background: var(--accent); color: #04140a; font-weight: 700; }

.cal-month-pills { position: relative; z-index: 1; }
.cal-overflow-link {
  display: block;
  padding: 1px 5px;
  color: var(--text-3);
  font-size: var(--fs-10);
  font-weight: 600;
  text-decoration: none;
}
.cal-overflow-link:hover { color: var(--text-1); }
.cal-overflow-link[hidden] { display: none; }

/* A milestone: a thin full-width bar in its own colour (--ms), on the month grid, in the
   week's milestone row and in the phone agenda alike. */
.cal-milestones { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 2px; margin-bottom: 3px; }
.cal-milestone {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  height: 18px;
  padding: 0 6px;
  border-left: 3px solid var(--ms);
  border-radius: var(--radius-xs);
  background: color-mix(in srgb, var(--ms) 18%, transparent);
  color: color-mix(in srgb, var(--ms) 75%, #fff);
  font-size: var(--fs-10);
  font-weight: 600;
  white-space: nowrap;
}
.cal-milestone-icon { flex: 0 0 auto; font-size: var(--fs-9); }
.cal-milestone-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 640px) {
  .cal-root { padding: 0.75rem 0.5rem 1.25rem; }
  .cal-toolbar .cal-title { min-width: 0; font-size: var(--fs-16); }
  .cal-month th { padding: 0 2px; font-size: var(--fs-9); letter-spacing: 0.04em; }
  .cal-month tbody tr { height: auto; }
  .cal-cell { height: 76px; padding: 2px; }
  .cal-cell-marks { display: none; }
  .cal-milestone { height: 14px; padding: 0 3px; font-size: var(--fs-9); }
  .cal-milestone-icon { display: none; }
  /* A phone's day is about 50px wide: its pills keep only their words and colour. Ticking
     off and times are the agenda's and the day's, where there is room for them. */
  .cal-month-pills .cal-pill-check,
  .cal-month-pills .cal-pill-time,
  .cal-month-pills .cal-pill-due,
  .cal-month-pills .cal-pill-btn { display: none; }
  .cal-month-pills .cal-month-pill { padding: 1px 3px; font-size: var(--fs-10); }
}

/* ---- Calendar refinements ---- */

/* A priority is starred on its own pill (calendars/_calendar_pill), not in the day's corner. */
.cal-pill-star { flex: 0 0 auto; align-self: center; color: var(--gold-bright); font-size: 8px; }

/* Days gone by step further back, and say how they went: the day's done count, kept by the
   page script as pills are ticked. All done reads in the accent. */
.cal-cell.is-past { background: rgba(0, 0, 0, 0.28); }
.cal-cell.is-past .cal-month-pill { opacity: 0.7; }
.cal-mark.is-done-count { background: rgba(255, 255, 255, 0.05); color: var(--text-3); font-size: var(--fs-10); font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-mark.is-done-count.is-all-done { background: var(--accent-soft); color: var(--accent-bright); }
.cal-mark.is-done-count[hidden] { display: none; }

/* Month | Week, at the toolbar's right edge (and in the sidebar dashboard). */

.cal-view-switch {
  position: absolute;
  right: 0;
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}
.cal-view-switch a {
  padding: 4px 14px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: var(--fs-12);
  font-weight: 600;
  text-decoration: none;
  transition: color var(--dur-fast), background-color var(--dur-fast);
}
.cal-view-switch a:hover { color: var(--text-1); }
.cal-view-switch a.is-current { background: var(--accent); color: #04140a; }
.cal-view-switch a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Desktop: a pill's title may take two lines rather than cut at a dozen letters — the
   cells have the width, and the page script fits rows by measuring them. Bands keep
   their centred single line. */
@media (min-width: 641px) {
  #cal-root .cal-month-pills .cal-month-pill:not(.cal-block-band),
  #cal-root .week-allday-cell .cal-month-pill:not(.cal-block-band) { align-items: flex-start; white-space: normal; }
  #cal-root .cal-month-pills .cal-month-pill:not(.cal-block-band) .cal-pill-title,
  #cal-root .week-allday-cell .cal-month-pill:not(.cal-block-band) .cal-pill-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  #cal-root .cal-month-pill:not(.cal-block-band) .cal-pill-star { margin-right: 3px; vertical-align: 1px; }
  #cal-root .cal-month-pill:not(.cal-block-band) .cal-pill-time { margin-right: 4px; }
  #cal-root .cal-month-pill:not(.cal-block-band) .cal-pill-due { margin-left: 4px; }
  #cal-root .cal-month-pills .cal-month-pill .cal-pill-check,
  #cal-root .week-allday-cell .cal-month-pill .cal-pill-check { margin-top: 1px; }
  #cal-root .cal-month-pill .cal-pill-btn { align-self: center; }

  /* The week has the room the month doesn't: a little bigger, a little more air. */
  #cal-root .week-allday-cell .cal-month-pill { padding: 3px 6px; font-size: var(--fs-12); }
}

/* The week's header: under each day's number, how much of it is done. */
.week-col-hdr .wch-count { min-height: 14px; margin-top: 3px; color: var(--text-3); font-size: var(--fs-10); font-weight: 600; font-variant-numeric: tabular-nums; }
.week-col-hdr .wch-count.is-all-done { color: var(--accent-bright); }

/* An empty month or week: one quiet line under the toolbar. */
.cal-empty-note { margin: -4px 0 12px; color: var(--text-3); font-size: var(--fs-12); text-align: center; }

/* Now, in today's list (week column, day list): a thin accent line with a dot at its head. */
.cal-now-line { position: relative; flex: 0 0 auto; height: 2px; margin: 2px 0 2px 5px; border-radius: 1px; background: var(--danger); }
.cal-now-line::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  transform: translateY(-50%);
}

/* A day in the phone's month grid, under a pill dragged from the day list. */
.cal-month td.cal-cell.is-drop-target { background: color-mix(in srgb, var(--accent) 22%, transparent); box-shadow: inset 0 0 0 2px var(--accent); }

/* The phone's month list (calendars/index): hidden on wider screens, where the grid holds
   the tasks itself. */
.cal-month-agenda { display: none; }

@media (max-width: 640px) {
  /* ‹ title › on a line of its own, centred, and the switch on the next with Today beside
     it when there's a today to go back to. The hidden Today used to hold its width beside
     the title here too, which set the title 40px left of centre; on its own line under it,
     it can come and go without moving anything. The ::before is the line break. */
  .cal-toolbar { flex-wrap: wrap; row-gap: 8px; }
  .cal-toolbar::before { content: ''; order: 9; flex-basis: 100%; height: 0; }
  .cal-view-switch { position: static; order: 10; margin: 0; }
  .cal-toolbar .cal-today-btn { order: 11; margin-left: 0; }
  .cal-toolbar .cal-today-btn.is-current { display: none; }
  .cal-view-switch a { padding: 4px 16px; }

  /* A phone's day is about 50px wide, too narrow for words: its tasks become dots in their
     colours (a habit still to do is a ring, as its pill is outlined), and tapping the day
     shows them as a list under the grid. The dots don't take taps; the day does. */
  .cal-view-month .cal-month .cal-cell { height: 54px; }
  .cal-view-month .cal-month-pills {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 3px;
    padding-top: 2px;
    pointer-events: none;
  }
  .cal-view-month .cal-month-pills .cal-month-pill {
    width: 6px;
    height: 6px;
    min-height: 0;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    background: var(--cat, #4d9fff);
    box-shadow: none;
  }
  .cal-view-month .cal-month-pills .cal-month-pill > * { display: none !important; }
  .cal-view-month .cal-month-pills .cal-month-pill.is-recurring:not(.tg-completed) { background: transparent; box-shadow: inset 0 0 0 1px var(--cat, #4d9fff); }
  .cal-view-month .cal-month-pills .cal-month-pill.is-priority { background: var(--gold-bright); }
  .cal-view-month .cal-month-pills .cal-month-pill.tg-completed { opacity: 0.4; }
  .cal-view-month .cal-month-pills .cal-block-group { display: contents; border: none; background: none; }
  .cal-view-month .cal-month-pills .cal-block-group > :not(.cal-month-pill),
  .cal-view-month .cal-month-pills .cal-block-band,
  .cal-view-month .cal-month-pills .cal-overflow-link { display: none !important; }
  .cal-view-month .cal-month td.cal-cell.is-selected { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }

  .cal-view-month .cal-month-agenda {
    display: block;
    margin-top: 12px;
    border: 1px solid var(--border-panel);
    border-radius: var(--radius-md);
    background: var(--surface-card);
    overflow: hidden;
  }
  .cal-month-agenda-day[hidden] { display: none; }
  /* A tap leaves the cell "hovered" on a phone, which lit its add-milestone flag. */
  .cal-view-month .cal-month .cal-add-milestone { display: none; }
  .cal-month-agenda .week-agenda-day { border-top: none; }
}

/* ---- Week view (on /calendar?view=week) ---- */
.week-grid-wrap {
  border: 1px solid var(--border-panel);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-card);
  display: flex;
  flex-direction: column;
}
.week-header {
  display: flex;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  /* The month grid's weekday header wears the same, so the two views match. */
  background: var(--surface-1);
}
.week-col-hdr {
  flex: 1;
  min-width: 0;
  padding: 6px 4px;
  text-align: center;
  border-left: 1px solid var(--border-panel);
  position: relative;
}
.week-col-hdr-link {
  display: block;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-xs);
  transition: background var(--dur-fast);
}
/* The global `a:hover {text-decoration: underline}` (0,1,1) outranks the class-level
   reset above, so restate it here — the header lights up, it doesn't underline. */
.week-col-hdr-link:hover { text-decoration: none; }
.week-col-hdr:hover .week-col-hdr-link { background: rgba(255,255,255,0.025); }
.week-col-hdr .wch-name {
  font-size: var(--fs-11);
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.week-col-hdr .wch-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: var(--fs-14);
  font-weight: bold;
  color: var(--text-1);
  margin-top: 2px;
}
/* Today's column starts with the same line of accent the month grid draws along the top
   of today's cell, and the same tint the rest of the column wears. */
.week-col-hdr.is-today { background: rgba(34, 197, 94, 0.11); box-shadow: inset 1px 0 0 rgba(34, 197, 94, 0.22), inset -1px 0 0 rgba(34, 197, 94, 0.22), inset 0 2px 0 var(--accent); }
.week-col-hdr.is-today .wch-name { color: var(--accent-bright); }
.week-col-hdr.is-today .wch-num { background: var(--accent); color: #04140a; }
/* A day's "add milestone" (calendars/_add_milestone_button). On the month grid it sits in
   the day's top line just left of the number; in the week view, in the header's top-right
   corner, beside the header link rather than in it. It waits for hover rather than putting
   a flag on all 35 days — and where there is no hover it stays, faintly, so a touch screen
   can still reach it. */
.cal-add-milestone {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  height: 20px;
  padding: 0 4px;
  margin-top: 1px;
  border-radius: var(--radius-xs);
  /* The same grey as the + beside it; the milestone pink only under the pointer, so the
     pair don't outshine the day's milestones themselves. */
  color: var(--text-2);
  font-size: var(--fs-10);
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--dur-fast), background var(--dur-fast), color var(--dur-fast);
}
.cal-add-milestone-plus { font-size: 0.7em; }
.cal-add-milestone:hover { background: rgba(255, 255, 255, 0.07); color: var(--milestone); }
.cal-add-milestone:focus-visible,
#cal-root td:hover .cal-add-milestone,
.week-col-hdr:hover .cal-add-milestone { opacity: 1; }
@media (hover: none) { .cal-add-milestone { opacity: 0.45; } }

.week-col-hdr .cal-add-milestone {
  position: absolute;
  top: 4px;
  right: 4px;
  margin-top: 0;
}
/* Milestones across the top of the week, on the same flex-basis:0 columns as the header
   and the rows below, so a flag sits over the day it belongs to. */
.week-milestone-row {
  display: flex;
  border-bottom: 1px solid var(--border-panel);
  background: var(--surface-card);
}
.week-milestone-cell {
  flex: 1;
  min-width: 0;
  padding: 3px;
  border-left: 1px solid var(--border-panel);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.week-allday-row {
  display: flex;
  border-bottom: 1px solid var(--border-panel);
  background: var(--surface-card);
  min-height: 22px;
}
/* A week with no tasks yet keeps the row on the page (calendars/_week_allday_row) so an
   added task has somewhere to land, but takes no room until it does. */
.week-allday-row.is-empty { display: none; }
.week-allday-cell {
  flex: 1;
  min-width: 0;
  padding: 2px;
  border-left: 1px solid var(--border-panel);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
/* The review strip under each day of the week: one cell per column, on the same
   flex-basis:0 columns as the header and the all-day row so all three stay aligned. */
.week-footer-row {
  display: flex;
  border-top: 1px solid var(--border-panel);
  background: var(--surface-card);
}
.week-footer-cell {
  flex: 1;
  min-width: 0;
  padding: 4px 3px 6px;
  border-left: 1px solid var(--border-panel);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
/* Today's column, header to foot, a step stronger than before so the week has an anchor,
   with a faint green edge either side. */
.week-footer-cell.is-today,
.week-allday-cell.is-today { background: rgba(34, 197, 94, 0.085); box-shadow: inset 1px 0 0 rgba(34, 197, 94, 0.22), inset -1px 0 0 rgba(34, 197, 94, 0.22); }

/* A day card is wide; a week column is a seventh of one. Everything in the strip is sized
   for the card, so it is re-cut here rather than left to overflow: the fixed dots column
   goes fluid so the dots wrap under the title instead of pushing the row past the column
   (and dragging the whole grid out of alignment), and the two readings — the dial and the
   completion footer — shrink and wrap to the width they actually have. */
.week-day-items { width: 100%; border-collapse: collapse; table-layout: fixed; }
.week-day-items .day-rule-row,
.week-day-items .day-value-row,
.week-day-items .day-thing-row { height: auto; }
.week-day-items td { padding: 3px 0 3px 2px; }
/* The icon stays — it carries the status in its ring and fill — just cut down to the
   column: a 16px circle rather than the card's 22px. */
.week-day-items .day-item-icon-cell { width: 18px; padding-left: 0; }
.week-day-items .day-item-icon { width: 16px; height: 16px; border-width: 1px; }
/* The glyph inside the circle, not the circle: 7px, and the emoji variant carries its
   own inline 0.8em so it takes an !important to reach. */
.week-day-items .day-item-icon i { font-size: 7px; }
.week-day-items .day-item-icon span { font-size: 8px; }
/* Reads like a task pill: the same size, and not bold. Both row partials wrap the title
   in <strong> and set --fs-14 inline on the link, so the size has to be stated with
   !important to reach past the inline rule. */
.week-day-items .day-item-title-cell { font-size: var(--fs-11); line-height: 1.3; }
.week-day-items .day-item-title-cell strong { font-weight: 400; }
/* The calendar's week columns are too narrow for a second line: one, cut short. */
.week-day-items .day-item-name, .week-span-items .day-item-name { display: block; white-space: nowrap; text-overflow: ellipsis; -webkit-line-clamp: unset; }
.week-day-items .day-item-title-cell a { font-size: var(--fs-11) !important; }
/* The frequency chips are the first thing a column this narrow has no room for, and the
   strip already separates daily items from the rest into two tables. */
.week-day-items .day-item-chip,
.week-day-items :is(.review-cadence-glyph, .auto-mark) { display: none; }
/* And the rating dots with them: five circles per row is the widest thing in the strip,
   and the row already says its status in the colour of its own text. The week reads as a
   summary — a status is set on the day itself, where the dots have room. */
.week-day-items .day-item-dots-cell { display: none; }

/* The week's value score, as a bar (calendars/_value_bar): filled to the score in its
   level's colour (--bar-color, --bar-fill), the percent inside. An odometer's semicircle
   had no width to say anything in a seventh of the page. */
.cal-value-bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 20px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  overflow: hidden;
}
.cal-value-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar-fill, 0%);
  background: linear-gradient(90deg, color-mix(in srgb, var(--bar-color) 55%, transparent), var(--bar-color));
  border-radius: inherit;
  transition: width var(--dur-slow) ease;
}
.cal-value-bar-text {
  position: relative;
  color: var(--text-1);
  font-size: var(--fs-11);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.cal-value-bar.is-unrated .cal-value-bar-text { color: var(--text-3); font-weight: 500; text-shadow: none; }

/* Nothing rated it yet — grey, and quieter than the days that have a reading. */
.day-value-dial.is-unrated { opacity: 0.55; }

/* The week's own rules and values: one list under all seven columns, centred, so it
   reads as belonging to the week rather than to whichever day it sits over. Wide enough
   to keep the rows as the schedule column draws them — dots, full-size text and all. */
.week-span-row {
  border-top: 1px solid var(--border-panel);
  background: var(--surface-card);
  /* Room above the label so it doesn't sit on top of the day footers hanging into it. */
  padding: 14px 8px 8px;
}
.week-span-label {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: var(--fs-9);
  color: var(--text-3);
  margin-bottom: 2px;
}
/* Sized to its rows rather than to a fixed 520px box: auto margins then centre the table
   itself, so a short rule sits in the middle of the week instead of at the left edge of an
   invisible column. */
.week-span-items {
  width: auto;
  max-width: 520px;
  margin: 0 auto;
  border-collapse: collapse;
  table-layout: auto;
}
/* The dots go here too — the week's rows are read the same way its days' are, and a
   status is set on the day itself. With them gone the table is down to two columns, and
   `table-layout: fixed` with no width on either splits it half and half — which parked the
   icon a whole column away from the text it belongs to. The icon takes what it needs and
   the title takes the rest. */
.week-span-loading { text-align: center; color: var(--text-3); font-size: var(--fs-12); padding: 6px 0; }
.week-span-items .day-item-dots-cell { display: none; }
.week-span-items .day-item-icon-cell { width: 26px; padding-left: 0; }
.week-span-items .day-item-title-cell { padding-right: 0.4rem; }
.week-span-items .day-item-title-cell strong { font-weight: 400; }

/* The span's own value bar, centred under the columns. */
.week-span-row .cal-value-bar { max-width: 260px; margin: 4px auto 0; height: 22px; }

/* The week as a list, for a phone (see .week-agenda in calendars/index): one block per
   day, its pills at full width. Shown, and the seven columns above hidden, below 640px. */
.week-agenda { display: none; }
@media (max-width: 640px) {
  .week-grid-wrap > .week-header,
  .week-grid-wrap > .week-milestone-row,
  .week-grid-wrap > .week-allday-row,
  .week-grid-wrap > .week-footer-row { display: none; }
  .week-agenda { display: block; }
}
.week-agenda-day { padding: 10px 12px 12px; border-top: 1px solid var(--border-panel); }
.week-agenda-day:first-child { border-top: none; }
.week-agenda-day.is-today { background: rgba(34, 197, 94, 0.05); }
.week-agenda-day.is-past { opacity: 0.75; }
.week-agenda-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.week-agenda-date { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; color: var(--text-1); text-decoration: none; }
.week-agenda-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: var(--fs-13);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.week-agenda-day.is-today .week-agenda-num { background: var(--accent); color: #04140a; }
.week-agenda-name { font-size: var(--fs-13); font-weight: 600; }
.week-agenda-count { color: var(--text-3); font-size: var(--fs-11); font-variant-numeric: tabular-nums; }
.week-agenda-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--text-3);
  font-size: var(--fs-11);
  text-decoration: none;
}
.week-agenda-add:hover { background: var(--surface-2); color: var(--accent-bright); }
.week-agenda-day > .cal-milestone { margin: 0 0 4px 36px; }
.week-agenda-pills { display: flex; flex-direction: column; gap: 3px; padding-left: 36px; }
.week-agenda-pills .cal-month-pill { margin-bottom: 0; min-height: 30px; padding: 2px 8px; font-size: var(--fs-13); }
/* No hover on a phone, so the pill's cancel and add stay in reach. */
.week-agenda-pills .cal-pill-btn { opacity: 0.6; padding: 4px; font-size: var(--fs-11); }
.week-agenda-empty { margin: 0; color: var(--text-3); font-size: var(--fs-12); }

/* The week's lower sections ease in as they're scrolled to (calendars/index adds
   .cal-reveal only to those that start below the fold, and .is-revealed as each comes
   into view). */
.cal-reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.cal-reveal.is-revealed { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .cal-reveal { opacity: 1; transform: none; transition: none; }
}

/* ---- Calendar filter toggle buttons ---- */
/* Month pills: hidden by default; JS in updateCalOverflows() shows up to 4 that pass filters */
.cal-month-pills .cal-month-pill { display: none; }

/* Hide filtered elements. Milestones use !important (JS never overrides them).
   Type filters on week-view events use plain display:none; month pills are
   managed by JS so inline styles override these without !important. */
#cal-root.cal-hide-milestones   [data-cal-milestone]   { display: none !important; }
#cal-root.cal-hide-priority     [data-cal-priority]    { display: none; }
/* Habits and blocks, except in the phone month's day list, which has room for them: the
   page script hides them there only when the filter was switched off by hand. */
#cal-root.cal-hide-recurring    [data-cal-recurring]:not(.cal-month-agenda *) { display: none; }
#cal-root.cal-hide-nonrecurring [data-cal-nonrecurring] { display: none; }
/* Priority outranks One-off: a one-off priority task stays while Priority is on. (The
   month's pills are shown and hidden by the page script, which applies the same rule.) */
#cal-root.cal-hide-nonrecurring:not(.cal-hide-priority) .cal-month-pill[data-cal-nonrecurring][data-cal-priority] { display: flex; }
#cal-root.cal-hide-place        [data-cal-place]       { display: none; }
#cal-root.cal-hide-blocks       [data-cal-block]:not(.cal-month-agenda *) { display: none; }
#cal-root.cal-hide-value        [data-cal-value-dial]  { display: none !important; }

/* Month view: a day's value score, tinted in its dial's colour. Opens the day's
   values in the modal to rate them (calendars/day_values). */
.cal-value-badge {
  --dial-color: #4a4a55;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-10);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--dial-color);
  background: color-mix(in srgb, var(--dial-color) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--dial-color) 38%, transparent);
  transition: background-color var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.cal-value-badge i { font-size: var(--fs-9); }
.cal-value-badge:hover { background: color-mix(in srgb, var(--dial-color) 28%, transparent); }
.cal-value-badge.is-unrated { color: var(--text-3); border-style: dashed; }

/* The day's values in the modal: dial on top, then one row per value with its dots */
.cal-day-values-card .val-form-body { gap: 10px; padding: 16px 18px 18px; }
.cal-day-values-dial { display: flex; justify-content: center; }
.cal-day-values-dial .day-value-dial svg { width: 150px; height: 84px; }
.cal-day-values-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal-day-values-table .day-item-icon-cell { width: 34px; }
.cal-day-values-table .day-item-dots-cell { width: 150px; padding-right: 4px; }
.cal-day-values-table tr + tr td { border-top: 1px solid var(--hairline); }
.cal-day-values-empty { margin: 0; text-align: center; color: var(--text-3); font-size: var(--fs-13); }

/* Bottom drop pad: permanently reserves a strip at the end of each category
   task table so "drop below the last task" has a real hover zone (reads as
   bottom padding of the card). Keep it constant-height at all times: expanding
   it mid-drag shifts rows under the cursor (task jumps on pickup), and any
   synchronous layout shift inside dragstart makes WebKit cancel the drag. */
tr.bottom-drop-pad td {
  height: 18px;
  padding: 0;
  border: none;
}
tr.bottom-drop-pad-sub td {
  height: 12px;
}
tr.bottom-drop-pad.is-tight td {
  height: 2px;
}

/* ---- Calendar: fitting more, adding, missed, before signup ---- */
/* Every month day: one line a title (the page script's fitMonthCell sets is-tight on
   all of them), so days line up and more show before "+N more". The full title is the
   pill's hover. */
@media (min-width: 641px) {
  #cal-root .cal-month-pills.is-tight .cal-month-pill:not(.cal-block-band) { align-items: center; }
  #cal-root .cal-month-pills.is-tight .cal-month-pill:not(.cal-block-band) .cal-pill-title { -webkit-line-clamp: 1; overflow-wrap: normal; word-break: break-all; }
  /* The 1px that lines the box up with a two-line title's first line; centred on one
     line, it sat the circle below the words. */
  #cal-root .cal-month-pills.is-tight .cal-month-pill .cal-pill-check { margin-top: 0; }
}

/* A day's "add a task" (calendars/_add_task_button), beside its add-milestone: on hover,
   faintly where there's none. */
.cal-add-task {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; margin-top: 1px; border-radius: var(--radius-xs);
  color: var(--text-2); font-size: var(--fs-10); text-decoration: none;
  opacity: 0; transition: opacity var(--dur-fast), background var(--dur-fast);
}
.cal-add-task:hover { background: rgba(255, 255, 255, 0.07); color: #fff; text-decoration: none; }
.cal-add-task:focus-visible, #cal-root td:hover .cal-add-task, .week-col-hdr:hover .cal-add-task { opacity: 1; }
@media (hover: none) { .cal-add-task { opacity: 0.45; } }
.week-col-hdr .cal-add-task { position: absolute; top: 4px; left: 4px; margin-top: 0; }
/* The phone's month cells are dots; its day list below has its own +. */
@media (max-width: 640px) { .cal-view-month .cal-month .cal-add-task { display: none; } }

/* A task a day gone by didn't get done: its check a dashed grey ring, and the pill a
   little dimmer. It used to be ringed in red, which turned every past week into a wall of
   failures; the day's done count and the bar along its foot already tell how it went.
   Ticking it (tg-completed) takes it away. */
#cal-root .cal-month-pill.is-missed:not(.tg-completed) .cal-pill-check,
#cal-root .cal-month-pill.is-missed:not(.tg-completed) .toggle-completed { border-style: dashed; border-color: rgba(161, 161, 170, 0.6); box-shadow: none; }
#cal-root .cal-month-pill.is-missed:not(.tg-completed) .cal-pill-title { opacity: 0.72; }

/* Days before the account existed: a faint hatch, so a new account's month doesn't read
   as a run of missed days. */
#cal-root .cal-cell.is-before-signup,
#cal-root .week-allday-cell.is-before-signup,
#cal-root .week-col-hdr.is-before-signup {
  background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.025) 0 6px, transparent 6px 12px);
}
#cal-root .cal-cell.is-before-signup .cal-day-num,
#cal-root .week-col-hdr.is-before-signup .wch-num { opacity: 0.55; }

/* ---- Week view: hover controls, totals, progress, the phone's folded days ---- */
/* A pill's skip and + float over its top-right corner on hover; the pill's own colour fades
   in behind them, so the title under them goes rather than reading through. */
@media (min-width: 641px) {
  #cal-root .week-allday-cell .cal-month-pill:not(.cal-block-band)::after {
    content: ''; position: absolute; top: 0; right: 0; width: 64px; height: 30px; z-index: 1;
    /* The pill's tint (17% of its colour) made solid over the card, so it covers. */
    background: color-mix(in srgb, var(--cat, #4d9fff) 17%, var(--surface-card)); border-top-right-radius: inherit;
    -webkit-mask-image: linear-gradient(to left, #000 62%, transparent);
    mask-image: linear-gradient(to left, #000 62%, transparent);
    opacity: 0; pointer-events: none; transition: opacity var(--dur-fast);
  }
  #cal-root .week-allday-cell .cal-month-pill:not(.cal-block-band):hover::after,
  #cal-root .week-allday-cell .cal-month-pill:not(.cal-block-band):focus-within::after { opacity: 1; }
}

/* The week's total beside its dates (updateWeekTotal). */
.cal-week-total { color: var(--text-3); font-size: var(--fs-12); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cal-week-total.is-all-done { color: var(--accent-bright); }
.cal-week-total[hidden] { display: none; }
/* Empty, it still keeps its line, so the header is one height with or without tasks. */
@media (min-width: 641px) { .cal-week-total[hidden] { display: block; visibility: hidden; } }
/* A phone's toolbar has no room beside the dates; each day's own count is in its list. */
@media (max-width: 640px) { .cal-week-total { display: none; } }

/* Each week day's done count with a thin line under it, as a month day has along its foot. */
.week-col-hdr.has-progress .wch-count::after {
  content: ''; display: block; width: 44px; height: 2px; margin: 4px auto 0; border-radius: 1px;
  background: linear-gradient(to right, var(--accent) calc(var(--cal-done, 0) * 100%), rgba(255, 255, 255, 0.1) 0);
}

/* The phone's week: a finished day gone by folds to its header; its count opens it. */
.week-agenda .week-agenda-day.is-foldable:not(.is-open) > :not(.week-agenda-head) { display: none; }
.week-agenda .week-agenda-day.is-foldable:not(.is-open) .week-agenda-head { margin-bottom: 0; }
.week-agenda .week-agenda-day.is-foldable .week-agenda-count { cursor: pointer; }
.week-agenda .week-agenda-day.is-foldable .week-agenda-count::after {
  content: '\f078'; font-family: 'Font Awesome 6 Free'; font-weight: 900; font-size: 9px; margin-left: 6px; opacity: 0.7;
}
.week-agenda .week-agenda-day.is-foldable.is-open .week-agenda-count::after { content: '\f077'; }
/* The dates with the week's total under them, between the arrows. */
.cal-title-stack { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.cal-title-stack .cal-week-total { line-height: 1.2; min-height: 1.2em; }

/* "Things: Dining & living area" in a schedule row's category cell: the thing opens on the
   Things page, but reads as the cell's text until pointed at. */
.task-cell-thing { color: inherit; text-decoration: none; }
.task-cell-thing:hover { text-decoration: underline; text-underline-offset: 2px; }

/* "Movies: Drama", "Things: Dining & living area": where it's filed, small, over what it is,
   which takes two lines at most — the cell is narrow. */
.task-cell-pair { display: inline-flex; flex-direction: column; align-items: center; max-width: 100%; line-height: 1.15; }
.task-cell-pair-top { color: var(--text-3); font-size: var(--fs-10); letter-spacing: 0.02em; }
.task-cell-pair-main { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: var(--fs-12); overflow-wrap: anywhere; }
@media (max-width: 720px) { .task-cell-pair { display: inline; } .task-cell-pair-main { display: inline; } }

/* The calendar's toolbar runs to the page's right edge; clear the corner button. */
@media (min-width: 820px) {
  .cal-view-switch { margin-right: 46px; }
}

/* A month day's progress: a thin bar along its foot instead of an "x/y" chip in its corner.
   The page script sets --cal-done (0–1) and .has-progress / .is-all-done on the cell. */
#cal-root .cal-cell .cal-mark.is-done-count { display: none; }
#cal-root .cal-cell.has-progress::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 4px;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) calc(var(--cal-done, 0) * 100%), rgba(255, 255, 255, 0.07) 0);
  pointer-events: none;
}
#cal-root .cal-cell.has-progress:not(.is-all-done)::after {
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 55%, transparent) calc(var(--cal-done, 0) * 100%), rgba(255, 255, 255, 0.07) 0);
}


/* ---- The week fills the window (desktop) ----
   Its tasks row stretches down to the rules strip at the foot, so each day is a tall
   column to drop into rather than a short band over an empty page. An empty week keeps
   the row too, for the same reason. */
@media (min-width: 641px) {
  .cal-view-week .week-grid-wrap { min-height: calc(100dvh - 7.25rem); }
  .cal-view-week .week-grid-wrap > .week-allday-row { flex: 1 1 auto; }
  .cal-view-week .week-grid-wrap > .week-allday-row.is-empty { display: flex; }
}

/* ---- An empty day still to come: a faint + in its middle on hover ---- */
.cal-empty-add {
  position: absolute; inset: 30px 6px 10px; z-index: 1;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-3); font-size: var(--fs-14); text-decoration: none;
  opacity: 0; transition: opacity var(--dur-fast), background var(--dur-fast), color var(--dur-fast);
}
#cal-root td:not(.is-empty) .cal-empty-add { display: none; }
#cal-root td.is-empty:hover .cal-empty-add { opacity: 1; }
.cal-empty-add:hover { background: rgba(255, 255, 255, 0.04); color: var(--text-1); text-decoration: none; }
@media (max-width: 640px), (hover: none) { .cal-empty-add { display: none; } }

/* ---- "+N more" opens the day in place ----
   The cell's own list, lifted over its neighbours with every row showing, a header with
   the date and a way to the day view (calendar_page.js). The rows are the real ones, so
   ticking, cancelling and dragging work as they do in the cell. */
#cal-root td.cal-popped { overflow: visible; z-index: 40; }
#cal-root td.cal-popped .cal-month-pills {
  position: absolute; top: -6px; left: -8px; right: -8px; min-width: 230px; z-index: 41;
  max-height: min(60vh, 460px); overflow-y: auto;
  padding: 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-pop); box-shadow: 0 22px 50px -14px rgba(0, 0, 0, 0.8);
}
#cal-root td.cal-popped:nth-child(7) .cal-month-pills { left: auto; right: -8px; width: 240px; }
.cal-pop-head { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; padding: 0 2px 6px; border-bottom: 1px solid var(--border-panel); }
.cal-pop-title { flex: 1; color: var(--text-1); font-size: var(--fs-13); font-weight: 600; }
.cal-pop-day { color: var(--text-3); font-size: var(--fs-11); font-weight: 500; text-decoration: none; }
.cal-pop-day:hover { color: var(--text-1); text-decoration: none; }
.cal-pop-close { display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: none; border-radius: var(--radius-xs); background: none; color: var(--text-3); cursor: pointer; }
.cal-pop-close:hover { background: rgba(255, 255, 255, 0.07); color: var(--text-1); }
#cal-root td.cal-popped .cal-month-pill .cal-pill-title { -webkit-line-clamp: 2; }
#cal-root td.cal-popped .cal-done-summary { display: none; }

/* The new task popup names the day it was opened from, as the milestone one does. */
.task-form-date { margin-left: 6px; color: var(--text-3); font-weight: 500; }
.task-form-date::before { content: '· '; }

/* ---- Phones ---- */
/* What the dots and rings under the month mean. */
.cal-month-legend { display: none; }
@media (max-width: 640px) {
  .cal-view-month .cal-month-legend {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin: 10px 0 0;
    color: var(--text-3); font-size: var(--fs-11);
  }
  .cal-month-legend span { display: inline-flex; align-items: center; gap: 5px; }
  .cal-legend-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); }
  .cal-legend-diamond { width: 6px; height: 6px; background: var(--milestone); transform: rotate(45deg); }
  .cal-legend-ring { width: 11px; height: 11px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--accent); }
  .cal-legend-bar { width: 14px; height: 3px; border-radius: 2px; background: linear-gradient(90deg, var(--accent) 60%, rgba(255, 255, 255, 0.15) 60%); }

  /* A milestone in a dot cell: a small pink diamond beside the day's task dots, not a chip
     cut to "Ana…". Its name is in the day's list below. */
  .cal-view-month .cal-month .cal-milestones { flex-direction: row; justify-content: center; gap: 3px; margin: 2px 0 1px; }
  .cal-view-month .cal-month .cal-milestone {
    width: 6px; height: 6px; padding: 0; border: 0; border-radius: 1px;
    background: var(--ms); transform: rotate(45deg); font-size: 0; overflow: hidden;
  }
  .cal-view-month .cal-month .cal-milestone > * { display: none; }
}

/* The phone's day lists: one quiet ⋯ per row in place of its cancel and +, which show on
   the row it opens. Elsewhere the ⋯ isn't drawn. */
.cal-pill-more { display: none; }
@media (max-width: 640px), (hover: none) {
  .week-agenda-pills .cal-pill-more {
    display: inline-grid; place-items: center; flex: 0 0 auto; width: 28px; height: 24px; padding: 0;
    border: none; border-radius: var(--radius-xs); background: none; color: var(--text-3); font-size: var(--fs-12); cursor: pointer;
  }
  .week-agenda-pills .cal-month-pill:not(.is-tools-open) .cal-pill-btn { display: none; }
  .week-agenda-pills .cal-month-pill.is-tools-open .cal-pill-btn { display: inline-flex; opacity: 0.85; }
  .week-agenda-pills .cal-month-pill.is-tools-open .cal-pill-more { color: var(--text-1); background: rgba(255, 255, 255, 0.07); }
}

/* Desktop: the title on the left as every page has it, the ‹ › and Today after it, Month |
   Week at the right. It was centred between the arrows, the one page that did that. */
@media (min-width: 820px) {
  .cal-toolbar { justify-content: flex-start; }
  .cal-toolbar .cal-title-stack { order: -1; align-items: flex-start; margin-right: 8px; }
  .cal-toolbar .cal-title { min-width: 0; text-align: left; font-size: var(--fs-22); }
}

/* The week's rules and values under each day: the status lives in each one's icon, so the
   names read in plain grey. Coloured red and green, they were a wall of colour to scan. */
.week-day-items .day-item-name a { color: var(--text-2) !important; }
.week-day-items .day-item-name a:hover { color: var(--text-1) !important; }

/* The phone's day lists: each task a dark row with its area's colour as a left edge, as
   Home's rows have it, not a block filled in that colour. */
@media (max-width: 819px) {
  .week-agenda-pills .cal-month-pill:not(.cal-block-band) {
    background: var(--surface-1, #141417) !important;
    border: 1px solid var(--border-panel) !important;
    box-shadow: inset 3px 0 0 var(--cat, #4d9fff) !important;
    color: var(--text-1);
  }
  .week-agenda-pills .cal-month-pill.is-routine:not(.cal-block-band) { box-shadow: inset 3px 0 0 var(--accent) !important; }
}

/* The desktop week: tasks as dark rows with their area's colour as a left edge, the same
   as the phone's day lists and Home, rather than blocks filled in it. */
#cal-root .week-allday-cell .cal-month-pill:not(.cal-block-band) {
  background: var(--surface-1, #141417) !important;
  border: 1px solid var(--border-panel) !important;
  box-shadow: inset 3px 0 0 var(--cat, #4d9fff) !important;
}
#cal-root .week-allday-cell .cal-month-pill.is-routine:not(.cal-block-band) { box-shadow: inset 3px 0 0 var(--accent) !important; }

/* The week's rule and value names wrap to a second line rather than being cut off. */
.week-day-items .day-item-name, .week-span-items .day-item-name {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  white-space: normal; overflow: hidden; overflow-wrap: anywhere;
}
.week-day-items .day-rule-row .day-item-name,
.week-day-items .day-rule-row .day-item-name > a { white-space: normal; }

/* The span lists under the week sit under "This week" / "This month", which says their
   pace: the little period calendar after each name only repeated it. */
.week-span-items :is(.review-cadence-glyph, .auto-mark) { display: none; }

/* Days still to come: their rules and values step back, and the empty bar keeps its place
   (so the columns line up) without being drawn. */
.week-footer-cell.is-future .week-day-items { opacity: 0.45; }
.week-footer-cell.is-future .week-day-items:hover { opacity: 1; }
.week-footer-cell.is-future .cal-value-bar.is-unrated { visibility: hidden; }

/* The phone month's key, folded behind a small "Key" at the grid's right corner. */
.cal-month-key { display: none; }
@media (max-width: 640px) {
  .cal-view-month .cal-month-key { display: block; margin: 6px 2px 0; }
  .cal-month-key > summary {
    display: flex; justify-content: flex-end; align-items: center; gap: 5px; list-style: none;
    color: var(--text-3); font-size: var(--fs-11); cursor: pointer;
  }
  .cal-month-key > summary::-webkit-details-marker { display: none; }
  .cal-month-key[open] > summary { color: var(--text-2); }
  .cal-view-month .cal-month-key .cal-month-legend { margin-top: 6px; }
}

/* The week's, month's, and year's own items, left-aligned like the rest of the page: the
   label at the left, the items as a row beside it, and the period's bar at the right. */
@media (min-width: 820px) {
  .week-span-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) 220px; align-items: center; column-gap: 18px; padding: 10px 16px; }
  .week-span-label { text-align: left; margin: 0; }
  .week-span-items { max-width: none; margin: 0; }
  .week-span-items tbody { display: flex; flex-wrap: wrap; gap: 2px 20px; }
  .week-span-items tr { display: flex; align-items: center; }
  .week-span-row .cal-value-bar { max-width: none; margin: 0; }
  .week-span-row > turbo-frame { display: block; min-width: 0; }
  .week-span-row .week-span-loading { text-align: right; }
}

/* A past day's task left unticked steps back, so the days gone by read as finished and the
   ones still to come stand out. (Not struck through: that reads as done.) */
#cal-root .week-allday-cell.is-past .cal-month-pill:not(.tg-completed):not(.cal-block-band) { opacity: 0.5; }
#cal-root .week-allday-cell.is-past .cal-month-pill:not(.tg-completed):not(.cal-block-band):is(:hover, :focus-within) { opacity: 1; }

/* The phone month: today picked is said by its green number alone, not also a green box
   round the cell. Another picked day keeps the box, its only mark. */
@media (max-width: 640px) {
  .cal-view-month .cal-month td.cal-cell.is-selected.is-today { box-shadow: none; }
}

/* The week day's done line runs the column's width, readable at a glance, not a 44px sliver. */
.week-col-hdr.has-progress .wch-count::after { width: auto; height: 3px; margin: 6px 10px 0; border-radius: 2px; }
.week-col-hdr .week-col-hdr-link { align-self: stretch; }

/* The week sizes to its tasks (with a floor, so a light week still has room to drop into)
   rather than stretching every column to the window's foot. */
@media (min-width: 641px) {
  .cal-view-week .week-grid-wrap { min-height: 0; }
  .cal-view-week .week-grid-wrap > .week-allday-row { flex: 0 0 auto; min-height: 240px; }
}

/* The phone month's ‹ ›: small and quiet, so the month's name leads. */
@media (max-width: 640px) {
  .cal-toolbar .cal-nav-btn, .cal-toolbar :is(.cal-prev, .cal-next) { width: 32px; height: 32px; min-width: 32px; font-size: var(--fs-12); background: transparent; border-color: transparent; color: var(--text-3); }
}
