/* Calendar — toolbar, filter chips, month grid, week columns, agenda list, the look-back
   summary, item detail and the subscribe modal. Extends the shared .cal-grid / .cal-cell /
   .cal-item base in app.css. Tokens only. */

/* ───────── toolbar ───────── */
.cal-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 12px; }
.cal-nav { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cal-nav-btns { display: flex; align-items: center; gap: 4px; }
.cal-title { font-size: 19px; font-weight: 800; font-variation-settings: 'wdth' 108; letter-spacing: -0.01em; white-space: nowrap; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.cal-title-sub { font: 500 11.5px/1.2 var(--mono); color: var(--muted); letter-spacing: 0.03em; white-space: nowrap; }
.cal-spinner { color: var(--muted); }
.cal-views { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ───────── filter chips ───────── */
.cal-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 16px; }
.cal-chip.chip-toggle { height: 28px; padding: 0 10px 0 9px; gap: 7px; font-size: 12.5px; }
.cal-chip.cal-mine { padding-left: 5px; }
.cal-chip .dot { width: 8px; height: 8px; }
.cal-chip:not(.on) { background: transparent; color: var(--muted); border-color: var(--border); }
.cal-chip:not(.on) .dot { opacity: 0.4; }
.cal-chip .count { height: 16px; min-width: 18px; font-size: 10.5px; padding: 0 5px; }
.cal-filters-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

/* Birthdays & milestones get a warm tone of their own, mixed from brand tokens. */
.tone-celebrate { background: linear-gradient(90deg, var(--red-soft), var(--violet-soft)); color: var(--text); }
.dot.tone-celebrate { background: linear-gradient(135deg, var(--red), var(--violet)); }

/* ───────── shared item states ───────── */
.cal-item { gap: 4px; }
.cal-item:hover { filter: brightness(1.12); }
.cal-item-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-time { flex: none; font: 600 10.5px/1.2 var(--mono); opacity: 0.85; }
.cal-item.is-done { opacity: 0.55; }
.cal-item.is-done .cal-item-title, .cal-item.is-done .cal-week-title { text-decoration: line-through; }
.cal-item.is-overdue { box-shadow: inset 2px 0 0 var(--red); }
.cal-usage { flex: none; font: 700 9px/1 var(--mono); letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 4px; border-radius: 4px; white-space: nowrap; }
.cal-item .cal-usage { margin-left: auto; }

/* ───────── month ───────── */
.cal-month .cal-grid, .cal-week { transition: opacity 0.15s; }
.cal-month.is-loading .cal-grid, .cal-week.is-loading { opacity: 0.6; }
.cal-cell { cursor: pointer; position: relative; }
.cal-cell:hover { box-shadow: inset 0 0 0 1px var(--border-strong); }
.cal-cell.today { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--red) 70%, transparent); }
.cal-cell.past:not(.today) .cal-item { opacity: 0.72; }
.cal-cell.past:not(.today) .cal-item.is-done { opacity: 0.5; }
.cal-cell.past:not(.today) .cal-daynum { color: var(--muted); }
.cal-cell-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; min-height: 22px; }
button.cal-daynum { border: 0; background: none; cursor: pointer; padding: 4px 5px; }
button.cal-daynum:hover { background: var(--surface-3); }
.cal-add {
  opacity: 0; flex: none; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.cal-cell:hover .cal-add, .cal-week-col:hover .cal-add, .cal-add:focus-visible { opacity: 1; }
.cal-add:hover { background: var(--surface-3); color: var(--text); }
.cal-more { border-radius: 5px; }
.cal-more:hover { color: var(--text); background: var(--surface-2); }
.cal-hint { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.cal-error { margin-bottom: 12px; }

/* ───────── week ───────── */
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-week-col { display: flex; flex-direction: column; min-width: 0; min-height: 420px; border-right: 1px solid var(--border); }
.cal-week-col:last-child { border-right: 0; }
.cal-week-head { display: flex; align-items: center; gap: 6px; padding: 8px 6px 8px 10px; background: var(--bg-2); border-bottom: 1px solid var(--border); }
.cal-week-dow { font: 500 10.5px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.cal-week-num { font: 700 13px/1 var(--mono); padding: 4px 6px; border-radius: 6px; color: var(--text-2); }
.cal-week-col.today .cal-week-num { background: var(--red); color: white; }
.cal-week-today { display: none; font: 600 10.5px/1 var(--mono); color: var(--red-ink); text-transform: uppercase; letter-spacing: 0.06em; }
.cal-week-head .cal-add { margin-left: auto; }
.cal-week-body { flex: 1; display: flex; flex-direction: column; gap: 5px; padding: 6px; cursor: pointer; }
.cal-week-col.past .cal-week-body { background: color-mix(in srgb, var(--bg) 25%, var(--surface)); }
.cal-week-col.past .cal-item { opacity: 0.75; }
.cal-week-item.cal-item { flex-direction: column; align-items: flex-start; gap: 2px; padding: 6px 7px; font-size: 12px; line-height: 1.3; white-space: normal; }
.cal-week-title { font-weight: 600; overflow-wrap: anywhere; }
.cal-week-sub { font-size: 11px; opacity: 0.8; }
.cal-week-item .cal-usage { margin-left: 0; }
.cal-week-empty { color: var(--faint); font-size: 12px; padding: 6px 2px; }

/* ───────── agenda (also the day modal and "What happened") ───────── */
.cal-agenda { display: flex; flex-direction: column; gap: 12px; }
.cal-agenda-day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-agenda-day.is-today { border-color: color-mix(in srgb, var(--red) 55%, var(--border)); }
.cal-agenda-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; font-size: 13.5px; font-weight: 700; background: var(--bg-2); border-bottom: 1px solid var(--border); }
.cal-agenda-day.is-past .cal-agenda-head > span:first-child { color: var(--text-2); }
.cal-agenda-list { list-style: none; margin: 0; padding: 0; }
.cal-row {
  display: grid; grid-template-columns: 96px 26px minmax(0, 1fr) auto; grid-template-areas: 'time mark main side';
  align-items: center; gap: 10px; width: 100%; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--border);
  background: none; color: var(--text); text-align: left; cursor: pointer; font: inherit;
}
.cal-agenda-list li:last-child .cal-row { border-bottom: 0; }
.cal-row:hover { background: var(--surface-2); }
.cal-row-time { grid-area: time; font: 500 12px/1.25 var(--mono); color: var(--muted); }
.cal-row-mark { grid-area: mark; width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.cal-row-main { grid-area: main; min-width: 0; }
.cal-row-title { display: block; font-weight: 600; font-size: 13.5px; overflow-wrap: anywhere; }
.cal-row-sub { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-row-side { grid-area: side; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.cal-row.is-done .cal-row-title { text-decoration: line-through; color: var(--muted); }
.cal-row.is-overdue .cal-row-time { color: var(--red-ink); font-weight: 600; }
.cal-day-list { margin: -16px -18px; }

/* ───────── "What happened" summary ───────── */
.cal-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.cal-summary .stat-value { font-size: 24px; }
.cal-summary-wrap { margin-bottom: 16px; }

/* ───────── item detail ───────── */
.cal-detail-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.cal-usage-note { margin: 0 0 12px; padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; }
.cal-detail-notes { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); font-size: 13.5px; }
.cal-people { display: flex; flex-wrap: wrap; gap: 6px 14px; }

/* ───────── subscribe ───────── */
.cal-feed-url { display: flex; gap: 8px; }
.cal-feed-url .input { min-width: 0; font-family: var(--mono); font-size: 12px; }
.cal-howto { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.cal-howto section { padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; }
.cal-howto h4 { font-size: 13px; margin-bottom: 6px; }
.cal-howto ol { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; color: var(--text-2); }

.cal-keys { margin-top: 16px; color: var(--faint); font-size: 12px; }
.cal-keys .kbd { margin: 0 1px; }

/* ───────── responsive ───────── */
@media (max-width: 900px) {
  .cal-week-col { min-height: 320px; }
  .cal-howto { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .cal-bar { flex-direction: column; align-items: stretch; }
  .cal-nav { flex-wrap: wrap; justify-content: space-between; }
  .cal-title { order: -1; width: 100%; font-size: 18px; flex-wrap: wrap; gap: 2px 10px; }
  .cal-views { justify-content: space-between; }
  .cal-filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-left: -16px; margin-right: -16px; padding: 0 16px 2px; }
  .cal-filters::-webkit-scrollbar { display: none; }
  .cal-chip.chip-toggle { flex: none; }

  /* month: too small for badges and times — keep a coloured dot for usage */
  .cal-cell .cal-add { display: none; }
  .cal-cell .cal-time { display: none; }
  .cal-cell .cal-usage { font-size: 0; width: 6px; height: 6px; padding: 0; border-radius: 50%; background: currentColor; }
  button.cal-daynum { padding: 3px 4px; }

  .cal-week { grid-template-columns: minmax(0, 1fr); }
  .cal-week-col { min-height: 0; border-right: 0; border-bottom: 1px solid var(--border); }
  .cal-week-col:last-child { border-bottom: 0; }
  .cal-week-body { min-height: 40px; }
  .cal-week-today { display: inline; }
  .cal-week-head .cal-add { opacity: 1; }

  .cal-row { grid-template-columns: 58px 22px minmax(0, 1fr); grid-template-areas: 'time mark main' 'time mark side'; gap: 4px 10px; padding: 10px 12px; }
  .cal-row-time { align-self: start; padding-top: 3px; font-size: 11.5px; }
  .cal-row-mark { align-self: start; width: 22px; height: 22px; }
  .cal-row-side { justify-content: flex-start; }
  .cal-row-side:empty { display: none; }
  .cal-row-sub { white-space: normal; }
  .cal-day-list { margin: -16px -18px; }

  .cal-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cal-feed-url { flex-direction: column; }
  .cal-keys { display: none; }
}
@media (hover: none) {
  .cal-week-head .cal-add { opacity: 1; }
}

/* Month cells are too narrow for a word badge next to the title: the usage flag is a coloured
   dot there (its tooltip explains it). Week, agenda and detail views keep the words. */
.cal-cell .cal-usage { font-size: 0; width: 7px; height: 7px; padding: 0; border-radius: 50%; background: currentColor; margin-left: 4px; }
