/* ==========================================================================
   ShareFam — calendar.css  (S11)

   MOBILE FIRST, AND LITERALLY SO. The base rules below ARE the narrow-phone
   layout (DEV_GUIDE #5's 22.5rem floor): one column, a compact agenda,
   controls that stack. Everything wider is a `min-width` addition. Written
   the other way round — a desktop grid with `max-width` subtractions — the
   small screen becomes a series of apologies, and the small screen is where
   a parent actually reads this page, standing in a corridor.

   ZERO px (DEV_GUIDE #1). Every length here is rem, %, fr, vh/dvh or a
   keyword. The one number worth naming out loud is 2.75rem: the minimum
   touch target (#6). A calendar is a page of small targets by nature, which
   is exactly why the minimum is enforced rather than assumed.
   ========================================================================== */

:root {
  --sf-cal-gap: 0.75rem;
  --sf-cal-radius: 0.625rem;
  --sf-cal-tap: 2.75rem;                /* DEV_GUIDE #6 — never "44px" */
  --sf-cal-motion: 180ms;               /* DEV_GUIDE #14 — 150-300ms */
  --sf-cal-ease: cubic-bezier(0.2, 0, 0.2, 1);
  --sf-cal-rule: rgba(15, 23, 42, 0.12);
  --sf-cal-muted: rgba(15, 23, 42, 0.62);
  --sf-cal-surface: rgba(255, 255, 255, 0.72);
  --sf-cal-accent: #4f46e5;
  --sf-cal-cancel: rgba(220, 38, 38, 0.9);
}

[data-theme="dark"] {
  --sf-cal-rule: rgba(226, 232, 240, 0.16);
  --sf-cal-muted: rgba(226, 232, 240, 0.68);
  --sf-cal-surface: rgba(30, 41, 59, 0.64);
  --sf-cal-accent: #a5b4fc;
  --sf-cal-cancel: rgba(248, 113, 113, 0.92);
}

/* --------------------------------------------------------------------------
   View switcher
   -------------------------------------------------------------------------- */
.sf-cal-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 0.0625rem solid var(--sf-cal-rule);
  border-radius: var(--sf-cal-radius);
}

.sf-cal-switcher__btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: var(--sf-cal-tap);
  min-width: var(--sf-cal-tap);
  padding: 0 0.75rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background-color var(--sf-cal-motion) var(--sf-cal-ease);
}

.sf-cal-switcher__btn.is-active {
  background: var(--sf-cal-accent);
  color: #fff;
}

.sf-cal-switcher__btn:focus-visible {
  outline: 0.1875rem solid var(--sf-cal-accent);
  outline-offset: 0.125rem;
}

/* On the narrowest screens the four labels do not fit beside the icons; the
   icon carries the meaning and the accessible name comes from the label text
   that is still in the DOM. */
.sf-cal-switcher__btn span {
  display: none;
}

/* --------------------------------------------------------------------------
   Period bar and time-zone label
   -------------------------------------------------------------------------- */
.sf-cal-periodbar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 0.0625rem solid var(--sf-cal-rule);
}

.sf-cal-periodbar__label {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.sf-cal-tz {
  margin: 0;
  font-size: 0.85rem;
  color: var(--sf-cal-muted);
}

/* --------------------------------------------------------------------------
   Filters
   -------------------------------------------------------------------------- */
.sf-cal-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sf-cal-gap);
}

.sf-cal-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--sf-cal-tap);
}

.sf-cal-field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sf-cal-gap);
}

/* --------------------------------------------------------------------------
   The agenda — the mobile layout, and the fallback for every view
   -------------------------------------------------------------------------- */
.sf-cal-region {
  min-height: 8rem;
}

.sf-cal-agenda {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sf-cal-daygroup {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.sf-cal-daygroup__label {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 0.375rem 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--sf-cal-muted);
  background: var(--sf-cal-surface);
  backdrop-filter: blur(0.25rem);
}

.sf-cal-item {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.75rem;
  align-items: start;
  width: 100%;
  min-height: var(--sf-cal-tap);
  padding: 0.625rem 0.75rem;
  border: 0.0625rem solid var(--sf-cal-rule);
  border-left: 0.1875rem solid var(--sf-cal-accent);
  border-radius: var(--sf-cal-radius);
  background: var(--sf-cal-surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform var(--sf-cal-motion) var(--sf-cal-ease),
              border-color var(--sf-cal-motion) var(--sf-cal-ease);
}

.sf-cal-item:hover {
  transform: translateY(-0.0625rem);
}

.sf-cal-item:focus-visible {
  outline: 0.1875rem solid var(--sf-cal-accent);
  outline-offset: 0.125rem;
}

.sf-cal-item--cancelled {
  border-left-color: var(--sf-cal-cancel);
  opacity: 0.72;
}

.sf-cal-item--cancelled .sf-cal-item__title {
  text-decoration: line-through;
}

.sf-cal-item--derived {
  border-left-style: dashed;
  cursor: default;
}

.sf-cal-item__time {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--sf-cal-muted);
}

.sf-cal-item__title {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.sf-cal-item__meta {
  margin: 0.125rem 0 0;
  font-size: 0.82rem;
  color: var(--sf-cal-muted);
  overflow-wrap: anywhere;
}

.sf-cal-badge {
  display: inline-block;
  margin-right: 0.375rem;
  padding: 0.0625rem 0.4rem;
  border-radius: 999rem;
  font-size: 0.72rem;
  border: 0.0625rem solid var(--sf-cal-rule);
}

/* --------------------------------------------------------------------------
   Grid views — a real grid only where there is room for one
   -------------------------------------------------------------------------- */
.sf-cal-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.25rem;
}

.sf-cal-grid__cell {
  min-height: 4rem;
  padding: 0.375rem;
  border: 0.0625rem solid var(--sf-cal-rule);
  border-radius: 0.5rem;
}

.sf-cal-grid__daynum {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--sf-cal-muted);
}

.sf-cal-grid__cell--other {
  opacity: 0.55;
}

/* --------------------------------------------------------------------------
   States
   -------------------------------------------------------------------------- */
.sf-cal-state {
  margin: 0 0 0.5rem;
  padding: 0.75rem;
  border-radius: var(--sf-cal-radius);
  font-size: 0.9rem;
  color: var(--sf-cal-muted);
}

.sf-cal-state--error {
  color: #b91c1c;
  border: 0.0625rem solid rgba(185, 28, 28, 0.4);
}

.sf-cal-state--warn {
  border: 0.0625rem dashed var(--sf-cal-rule);
}

[data-theme="dark"] .sf-cal-state--error {
  color: #fca5a5;
}

/* --------------------------------------------------------------------------
   Modal blocks
   -------------------------------------------------------------------------- */
.sf-cal-block {
  padding-top: 0.875rem;
  margin-top: 0.875rem;
  border-top: 0.0625rem solid var(--sf-cal-rule);
}

.sf-cal-block h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.sf-cal-rsvp {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.sf-cal-rsvp .sf-btn {
  min-height: var(--sf-cal-tap);
  min-width: 4.5rem;
}

.sf-cal-rsvp .sf-btn.is-chosen {
  background: var(--sf-cal-accent);
  color: #fff;
}

.sf-cal-repeat {
  padding: 0.75rem;
  border: 0.0625rem solid var(--sf-cal-rule);
  border-radius: var(--sf-cal-radius);
}

.sf-cal-repeat legend {
  padding: 0 0.375rem;
  font-size: 0.85rem;
  font-weight: 700;
}

.sf-cal-scope {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0;
  border: 0;
}

.sf-cal-scope__hint {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--sf-cal-muted);
}

.sf-cal-scope__opt {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  min-height: var(--sf-cal-tap);
  padding: 0.625rem;
  border: 0.0625rem solid var(--sf-cal-rule);
  border-radius: var(--sf-cal-radius);
  cursor: pointer;
}

.sf-cal-scope__opt small {
  display: block;
  font-size: 0.8rem;
  color: var(--sf-cal-muted);
}

.sf-cal-attachments,
.sf-cal-thread {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 0.5rem;
}

.sf-cal-resp {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 0.0625rem solid var(--sf-cal-rule);
  font-size: 0.88rem;
}

.sf-cal-resp .sf-btn {
  min-height: var(--sf-cal-tap);
}

/* --------------------------------------------------------------------------
   Wider screens — additions only
   -------------------------------------------------------------------------- */
@media (min-width: 30rem) {
  .sf-cal-switcher__btn span {
    display: inline;
  }
  .sf-cal-field-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 48rem) {
  .sf-cal-periodbar {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
  }
  .sf-cal-filters {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
  }
  .sf-cal-field-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .sf-cal-item {
    grid-template-columns: 6rem 1fr;
  }
  .sf-cal-grid--week {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
  .sf-cal-grid--month {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
  .sf-cal-grid__cell {
    min-height: 6rem;
  }
}

/* --------------------------------------------------------------------------
   DEV_GUIDE #14 — motion is a courtesy, not a requirement. Focus and status
   feedback survive; decoration does not.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .sf-cal-switcher__btn,
  .sf-cal-item {
    transition: none;
  }
  .sf-cal-item:hover {
    transform: none;
  }
}
