/* ============================================================
   COMPONENT · CALENDAR
   Read-only month grid + agenda (P5.2a). A fixed 7-column grid —
   the week starts Monday (= column 1), so each day cell's position
   comes from natural document order. No inline style, no dynamic
   positioning class (the strict CSP forbids inline style=).
   Existing design tokens only.
   ============================================================ */

.c-calendar {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* Weekday header — a 7-col plaque strip echoing the grid columns below. */
.c-calendar__weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--space-1);
}

.c-calendar__weekday {
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-plaque);
  font-size: var(--fs-2xs);
  letter-spacing: var(--ls-wider);
  text-transform: uppercase;
  color: var(--color-text-muted);
  text-align: right;
}

/* The month grid — 7 fixed columns with bezel-coloured grid lines between cells. */
.c-calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--color-border);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.c-calendar__day {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-height: 5.5rem;
  padding: var(--space-1) var(--space-2);
  background: var(--color-surface);
}

.c-calendar__daynum {
  align-self: flex-end;
  font-family: var(--font-data);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
}

/* Today — a cyan ring + lit day number. */
.c-calendar__day--today {
  box-shadow:
    inset 0 0 0 1px var(--color-accent),
    var(--glow-cyan);
}

.c-calendar__day--today .c-calendar__daynum {
  color: var(--color-phosphor-cyan);
}

/* Adjacent-month days — dimmed/sunken so focus stays on the current month. */
.c-calendar__day--outside {
  background: var(--color-surface-sunken);
  opacity: 0.55;
}

.c-calendar__events {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* A compact event chip — single line, truncated with an ellipsis. */
.c-calendar__event {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 1px var(--space-1);
  border-radius: var(--radius-xs);
  border-left: 2px solid var(--color-accent);
  background: var(--color-surface-sunken);
  font-size: var(--fs-2xs);
  color: var(--color-text);
}

/* Events = a solid accent edge; actions = a dotted accent edge. A scheduled
   action is *on the calendar*, not *at risk* — differentiate by line style, not
   by an amber alarm hue. */
.c-calendar__event--event {
  border-left-color: var(--color-accent);
}

.c-calendar__event--action {
  border-left-style: dotted;
  border-left-color: var(--color-accent);
}

.c-calendar__event-time {
  font-family: var(--font-data);
  color: var(--color-text-muted);
}

.c-calendar__more {
  font-size: var(--fs-2xs);
  color: var(--color-text-muted);
}

/* ── Agenda list — a clean ledger of the month's entries, grouped by day. ── */
.c-calendar__agenda {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.c-calendar__agenda-day {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.c-calendar__agenda-date {
  font-family: var(--font-plaque);
  font-size: var(--fs-2xs);
  letter-spacing: var(--ls-wider);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.c-calendar__agenda-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--color-border);
}

.c-calendar__agenda-time {
  flex: 0 0 4rem;
  color: var(--color-text-muted);
}

.c-calendar__agenda-title {
  flex: 1 1 auto;
  color: var(--color-text);
}

.c-calendar__agenda-kind {
  flex: 0 0 auto;
  font-family: var(--font-plaque);
  font-size: var(--fs-2xs);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.c-calendar__agenda-row--action .c-calendar__agenda-kind {
  color: var(--color-text-muted);
}

.c-calendar__agenda-meta {
  flex: 0 1 auto;
  font-size: var(--fs-2xs);
}

/* ── Mobile (≤ --bp-sm, 480px) — agenda-first. ────────────────────────────────
   Calendars are exactly where mobile pain is worst: a fixed 7-column grid crushes
   to ~50px columns on a phone. Below the breakpoint we LEAD with the agenda ledger
   (the one part that degrades well) and collapse the month grid — the grid + the
   7-weekday markup stay in the DOM (the calendar test asserts them), they're just
   hidden from the small viewport. The agenda row also stacks: the title takes its
   own line; time / kind / meta drop to a secondary muted line so long titles stop
   overflowing. (Custom props can't ride a media query, so --bp-sm is inlined.) */
@media (max-width: 30rem) {
  .c-calendar__weekdays,
  .c-calendar__grid {
    display: none;
  }

  .c-calendar__agenda-row {
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: var(--space-2);
    row-gap: 2px;
    padding: var(--space-2) 0;
  }

  /* Title leads, on its own full-width line. */
  .c-calendar__agenda-title {
    flex: 1 0 100%;
    order: -1;
  }

  /* Time / kind / meta fall to a secondary, muted line beneath the title. */
  .c-calendar__agenda-time {
    flex: 0 0 auto;
  }

  .c-calendar__agenda-meta {
    color: var(--color-text-muted);
  }
}
