/* Calendar's own styles.
 *
 * The rule (CLAUDE.md rule 5, packages/design/README.md): this file may CONSUME
 * semantic tokens and nothing else. No raw values, no redefining a `.ds-*`
 * component, no reaching for a primitive ramp. The app's accent is repointed in
 * `packages/design/css/app-themes.css` under `[data-app="calendar"]`, not here,
 * and a diary's colour comes from the `--ds-cat-*` set in tokens.css rather than
 * from a hex anybody picked — which is why the database stores the NAME.
 *
 * Everything is prefixed `cal-`. A grid is the one thing the design system has
 * no component for, and it is the whole of this file.
 */

/* ── the colour a diary carries ──────────────────────────────────────────── */

.cal-sage   { --cal-mark: var(--ds-cat-sage);   --cal-tint: var(--ds-cat-sage-subtle); }
.cal-ocean  { --cal-mark: var(--ds-cat-ocean);  --cal-tint: var(--ds-cat-ocean-subtle); }
.cal-plum   { --cal-mark: var(--ds-cat-plum);   --cal-tint: var(--ds-cat-plum-subtle); }
.cal-clay   { --cal-mark: var(--ds-cat-clay);   --cal-tint: var(--ds-cat-clay-subtle); }
.cal-moss   { --cal-mark: var(--ds-cat-moss);   --cal-tint: var(--ds-cat-moss-subtle); }
.cal-slate  { --cal-mark: var(--ds-cat-slate);  --cal-tint: var(--ds-cat-slate-subtle); }
.cal-amber  { --cal-mark: var(--ds-cat-amber);  --cal-tint: var(--ds-cat-amber-subtle); }
.cal-rose   { --cal-mark: var(--ds-cat-rose);   --cal-tint: var(--ds-cat-rose-subtle); }

.cal-dot {
  display: inline-block;
  inline-size: 0.6em;
  block-size: 0.6em;
  border-radius: var(--ds-radius-full);
  background: var(--cal-mark, var(--ds-accent));
  flex: none;
}

/* ── the toolbar's date navigation ───────────────────────────────────────── */

.cal-nav { gap: var(--ds-space-1); flex-wrap: nowrap; }

.cal-period {
  font-weight: var(--ds-weight-semibold);
  white-space: nowrap;
  margin-inline-start: var(--ds-space-2);
}

/* ── month ───────────────────────────────────────────────────────────────── */

.cal-month {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--ds-border-width);
  background: var(--ds-border);
  border: var(--ds-border-width) solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  overflow: hidden;
}

.cal-month__name {
  background: var(--ds-surface-sunken);
  padding: var(--ds-space-2);
  font-size: var(--ds-text-xs);
  font-weight: var(--ds-weight-semibold);
  color: var(--ds-text-muted);
  text-align: center;
}

.cal-day {
  background: var(--ds-surface);
  min-block-size: 6.5rem;
  padding: var(--ds-space-1);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cal-day--outside { background: var(--ds-surface-sunken); }
.cal-day--today .cal-day__number {
  background: var(--ds-accent);
  color: var(--ds-on-accent);
  border-radius: var(--ds-radius-full);
}

.cal-day__number {
  font-size: var(--ds-text-xs);
  font-weight: var(--ds-weight-medium);
  color: var(--ds-text-muted);
  align-self: flex-start;
  min-inline-size: 1.5em;
  padding: 1px var(--ds-space-1);
  text-align: center;
  border: 0;
  background: none;
  cursor: pointer;
}

/* ── one entry on the grid ───────────────────────────────────────────────── */

.cal-chip {
  display: flex;
  align-items: center;
  gap: var(--ds-space-1);
  inline-size: 100%;
  text-align: start;
  font-size: var(--ds-text-xs);
  line-height: var(--ds-leading-tight);
  padding: 2px var(--ds-space-1);
  border: 0;
  border-radius: var(--ds-radius-sm);
  background: var(--cal-tint, var(--ds-accent-subtle));
  color: var(--ds-text);
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cal-chip:hover { background: var(--ds-surface-hover); }
.cal-chip__time { color: var(--ds-text-muted); flex: none; font-variant-numeric: tabular-nums; }
.cal-chip__title { overflow: hidden; text-overflow: ellipsis; }

/* A block of somebody else's time, shown because a calendar was shared at
   "busy". It has no title by construction — see src/calendars.js. */
.cal-chip--busy { background: repeating-linear-gradient(
    45deg, var(--ds-surface-sunken), var(--ds-surface-sunken) 4px,
    var(--ds-surface) 4px, var(--ds-surface) 8px); color: var(--ds-text-muted); }

.cal-chip--tentative { border: var(--ds-border-width) dashed var(--ds-border-strong); }
.cal-chip--task { background: var(--ds-warning-subtle); }

.cal-more {
  font-size: var(--ds-text-xs);
  color: var(--ds-text-muted);
  background: none;
  border: 0;
  padding: 0 var(--ds-space-1);
  cursor: pointer;
  text-align: start;
}

/* ── week and day ────────────────────────────────────────────────────────── */

/* Horizontally scrollable on a narrow screen rather than squeezed: seven
   columns at phone width is seven unreadable columns. The page itself must
   never scroll sideways (CLAUDE.md), so the overflow lives on this box. */
.cal-week-scroll { overflow-x: auto; }

.cal-week {
  display: grid;
  grid-template-columns: 3.5rem repeat(var(--cal-columns, 7), minmax(6rem, 1fr));
  gap: var(--ds-border-width);
  background: var(--ds-border);
  border: var(--ds-border-width) solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  overflow: hidden;
  min-inline-size: fit-content;
}

.cal-week__head, .cal-week__gutter, .cal-week__cell { background: var(--ds-surface); }

.cal-week__head {
  padding: var(--ds-space-2);
  text-align: center;
  font-size: var(--ds-text-xs);
  font-weight: var(--ds-weight-semibold);
}

.cal-week__head--today { color: var(--ds-accent); }
.cal-week__head small { display: block; color: var(--ds-text-muted); font-weight: var(--ds-weight-normal); }

.cal-week__gutter {
  font-size: var(--ds-text-xs);
  color: var(--ds-text-muted);
  text-align: end;
  padding: 2px var(--ds-space-1);
  font-variant-numeric: tabular-nums;
}

.cal-week__cell { min-block-size: 2.25rem; padding: 1px; display: flex; flex-direction: column; gap: 1px; }
.cal-week__allday { background: var(--ds-surface-sunken); min-block-size: 1.75rem; }

/* ── agenda ──────────────────────────────────────────────────────────────── */

.cal-agenda__day { margin-block-end: var(--ds-space-5); }

.cal-agenda__heading {
  font-size: var(--ds-text-sm);
  font-weight: var(--ds-weight-semibold);
  color: var(--ds-text-muted);
  padding-block-end: var(--ds-space-2);
  border-block-end: var(--ds-border-width) solid var(--ds-border);
  margin-block-end: var(--ds-space-2);
}

.cal-agenda__row {
  display: flex;
  gap: var(--ds-space-3);
  align-items: baseline;
  inline-size: 100%;
  text-align: start;
  padding: var(--ds-space-2);
  border: 0;
  background: none;
  border-radius: var(--ds-radius-sm);
  cursor: pointer;
}

.cal-agenda__row:hover { background: var(--ds-surface-hover); }
.cal-agenda__when { color: var(--ds-text-muted); font-variant-numeric: tabular-nums; flex: none; min-inline-size: 7.5rem; }

/* ── setup screens ───────────────────────────────────────────────────────── */

.cal-swatches { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }

.cal-swatch {
  inline-size: 1.75rem;
  block-size: 1.75rem;
  border-radius: var(--ds-radius-full);
  border: 2px solid transparent;
  background: var(--cal-mark);
  cursor: pointer;
}

.cal-swatch[aria-pressed="true"] { border-color: var(--ds-text); }

.cal-status { font-size: var(--ds-text-xs); }
.cal-status--ok { color: var(--ds-success); }
.cal-status--bad { color: var(--ds-danger); }

.cal-feed-url {
  font-family: var(--ds-font-mono);
  font-size: var(--ds-text-xs);
  word-break: break-all;
  color: var(--ds-text-muted);
}

@media (max-width: 40rem) {
  .cal-day { min-block-size: 4rem; }
  .cal-agenda__when { min-inline-size: 5rem; }
  .cal-period { font-size: var(--ds-text-sm); }
}
