/* Connect CRM - calendar (CRM Plus Phase 1, docs/blueprints/CRM-PLUS-PHASE1-CONTRACT.md section 5.4, session S6).
   Only what this area draws that the screen kit (apps/shared/kit.css) does not: `cr-` classes scoped
   to the area. Colour only from tokens (--cx-*, --pa-*), no !important, no @layer; Day and Dark
   come from connect-theme.css; Compact (<= 640 px) rules at the end. */

/* ---- the controls over the calendar: view, Today / previous / next, a date jump, the period --- */
.cr-cal-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--pa-s3); min-width: 0; width: 100%; }
.cr-cal-nav { display: inline-flex; gap: var(--pa-s1); align-items: center; }
.cr-cal-period { margin: 0 0 0 auto; font-size: var(--cx-text-section); font-weight: 650; align-self: center; }
.cr-cal-zone { margin: 0 0 var(--pa-s2); }
.cr-cal-legend { list-style: none; padding: 0; }
.cr-cal-legend .cr-cal-chip { max-width: none; }

/* ---- an item's kind: an icon and its word, side by side (never colour alone) ---------------- */
.cr-cal-kind { display: inline-flex; align-items: center; gap: 6px; min-width: 0; color: var(--cx-text-2); font-size: var(--cx-text-meta); font-weight: 600; white-space: nowrap; }
.cr-cal-chip { display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; padding: 1px 6px; border-radius: var(--cx-radius-pill); background: var(--cx-surface-2); color: var(--cx-text); font-size: 12px; line-height: 1.4; }
.cr-cal-chip svg { flex: none; color: var(--cx-text-2); }
.cr-cal-chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-cal-chip[data-cancelled] .cr-cal-chip-text, .is-struck { text-decoration: line-through; }
/* A week column has the room for the time and two lines of the title; a month cell shows the title alone. */
.cr-cal-week .cr-cal-chip { flex-wrap: wrap; align-items: flex-start; border-radius: var(--cx-radius-sm); padding: 2px 6px; }
.cr-cal-week .cr-cal-chip svg { margin-top: 2px; }
.cr-cal-week .cr-cal-chip-text { flex-basis: 100%; white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cr-cal-chip-time { color: var(--cx-text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cr-cal-more { color: var(--cx-text-3); font-size: 12px; font-weight: 600; padding: 0 6px; }

/* ---- the grid and the side panel -------------------------------------------------------------- */
.cr-cal-body { display: block; min-width: 0; }
.cr-cal-body.has-side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); gap: var(--pa-s4); align-items: start; }
.cr-cal-main { min-width: 0; }
.cr-cal-side { position: sticky; top: var(--pa-s4); min-width: 0; padding: var(--pa-s4); border: 1px solid var(--cx-border-soft); border-radius: var(--cx-radius); background: var(--cx-surface); max-height: calc(100dvh - 120px); overflow-y: auto; overscroll-behavior: contain; }

.cr-cal-month { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 3px; }
.cr-cal-month th { padding: 2px 6px; color: var(--cx-text-3); font-size: var(--cx-text-meta); font-weight: 600; text-align: left; }
.cr-cal-month abbr { text-decoration: none; }
.cr-cal-month td { padding: 0; vertical-align: top; }
.cr-cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }

.cr-cal-day { display: flex; flex-direction: column; align-items: stretch; gap: 3px; width: 100%; min-width: 0; min-height: 96px; padding: 6px; border: 1px solid var(--cx-border-soft); border-radius: var(--cx-radius-sm); background: var(--cx-surface); color: var(--cx-text); font: inherit; text-align: left; cursor: pointer; }
.cr-cal-week .cr-cal-day { min-height: 260px; }
.cr-cal-day:hover { background: var(--cx-hover); }
.cr-cal-day:focus-visible { outline: 2px solid var(--cx-focus); outline-offset: 1px; }
.cr-cal-day[data-focus] { border-color: var(--cx-border-strong); }
.cr-cal-day.is-other { background: transparent; color: var(--cx-text-3); }
.cr-cal-num { display: inline-grid; place-items: center; align-self: flex-start; min-width: 24px; height: 24px; padding: 0 4px; border-radius: var(--cx-radius-pill); font-size: var(--cx-text-small); font-weight: 650; font-variant-numeric: tabular-nums; }
.cr-cal-day[aria-current="date"] .cr-cal-num { background: var(--cx-action); color: var(--cx-action-ink); }
.cr-cal-items { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* ---- rows of one date: details panel, Day view, the agenda ------------------------------------ */
.cr-cal-details { display: flex; flex-direction: column; gap: var(--pa-s3); min-width: 0; }
.cr-cal-details-title { margin: 0; font-size: var(--cx-text-section); font-weight: 650; }
.cr-cal-details-actions { flex-wrap: wrap; }
.cr-cal-group h3 { display: flex; align-items: baseline; gap: 6px; }
.cr-cal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.cr-cal-row { display: grid; grid-template-columns: minmax(120px, 180px) minmax(0, 1fr) auto; gap: var(--pa-s2) var(--pa-s3); align-items: start; padding: var(--pa-s2) 0; border-top: 1px solid var(--cx-border-soft); }
.cr-cal-row:first-child { border-top: 0; }
.cr-cal-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.cr-cal-row-side { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--pa-s1) var(--pa-s2); }
.cr-cal-side .cr-cal-row, .pa-sheet-body .cr-cal-row { grid-template-columns: minmax(0, 1fr); }
.cr-cal-side .cr-cal-row-side, .pa-sheet-body .cr-cal-row-side { justify-content: flex-start; }

.cr-cal-agenda { display: flex; flex-direction: column; gap: var(--pa-s4); }
/* A long agenda skips the days off screen (P2, regression contract 10). */
.cr-cal-agenda-day { content-visibility: auto; contain-intrinsic-size: auto 180px; }
.cr-cal-agenda-head { margin: 0 0 var(--pa-s1); font-size: var(--cx-text-small); }
.cr-cal-open { display: inline-flex; align-items: center; min-height: max(var(--pa-tap), 28px); padding: 0; border: 0; background: transparent; color: var(--cx-text); font: inherit; font-weight: 650; cursor: pointer; text-align: left; }
.cr-cal-open:hover { color: var(--cx-link); text-decoration: underline; }
.cr-cal-open:focus-visible { outline: 2px solid var(--cx-focus); outline-offset: 2px; border-radius: var(--cx-radius-sm); }
.cr-cal-open[aria-current="date"] { color: var(--cx-link); }

/* ---- Compact's date strip: scrolls sideways inside itself, never the page ---------------------- */
.cr-cal-strip { display: flex; gap: var(--pa-s1); margin: 0 0 var(--pa-s3); padding-bottom: var(--pa-s1); overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: thin; }
.cr-cal-strip-day { flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 52px; min-height: 64px; padding: 6px 4px; border: 1px solid var(--cx-border-soft); border-radius: var(--cx-radius-sm); background: var(--cx-surface); color: var(--cx-text-2); font: inherit; font-size: 12px; cursor: pointer; scroll-snap-align: center; }
.cr-cal-strip-day b { color: var(--cx-text); font-size: 16px; font-variant-numeric: tabular-nums; }
.cr-cal-strip-day[aria-current="date"] b { text-decoration: underline; text-underline-offset: 3px; }
.cr-cal-strip-day[aria-pressed="true"] { border-color: var(--cx-action); background: var(--cx-action); color: var(--cx-action-ink); }
.cr-cal-strip-day[aria-pressed="true"] b { color: var(--cx-action-ink); }
.cr-cal-strip-day:focus-visible { outline: 2px solid var(--cx-focus); outline-offset: 2px; }
.cr-cal-dots { min-height: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---- forms: the event editor, the wizard, the settings ------------------------------------------ */
.cr-cal-form { display: flex; flex-direction: column; gap: var(--pa-s4); min-width: 0; }
.cr-cal-form .pa-fieldset { display: flex; flex-direction: column; gap: var(--pa-s3); min-width: 0; }
.cr-cal-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: var(--pa-s3); }
.cr-cal-pair > [hidden], .cr-cal-form [hidden] { display: none; }
.cr-cal-summary { margin: 0; padding: var(--pa-s2) var(--pa-s3); border-radius: var(--cx-radius-sm); background: var(--cx-surface-2); color: var(--cx-text); font-size: var(--cx-text-small); }
.cr-cal-reminders, .cr-cal-cats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--pa-s2); }
.cr-cal-reminder, .cr-cal-cat { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--pa-s2); }
.cr-cal-reminder .pa-field, .cr-cal-cat .pa-field { flex: 1 1 160px; min-width: 0; margin: 0; }
.cr-cal-form-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--pa-s2); padding-top: var(--pa-s3); border-top: 1px solid var(--cx-border-soft); }
.cr-cal-check { display: inline-flex; align-items: center; gap: 8px; min-height: max(var(--pa-tap), 28px); cursor: pointer; font-size: var(--cx-text-small); }
.cr-cal-check input { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--cx-action); }
.cr-cal-checks { display: flex; flex-wrap: wrap; gap: var(--pa-s1) var(--pa-s4); }
.cr-cal-choices .pa-radio > span { display: flex; flex-direction: column; gap: 2px; }
.cr-cal-channel { display: flex; flex-direction: column; gap: var(--pa-s3); padding: var(--pa-s3) var(--pa-s4); border: 1px solid var(--cx-border-soft); border-radius: var(--cx-radius-sm); }
.cr-cal-starter { align-items: flex-end; flex-wrap: wrap; }
.cr-cal-starter .pa-field { flex: 1 1 220px; min-width: 0; margin: 0; }
.cr-cal-holders { display: flex; flex-wrap: wrap; align-items: center; gap: var(--pa-s1) var(--pa-s2); }
.cr-cal-regions { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 2px var(--pa-s4); max-height: 360px; overflow-y: auto; overscroll-behavior: contain; }
.cr-cal-regions li { content-visibility: auto; contain-intrinsic-size: auto 32px; min-width: 0; overflow-wrap: anywhere; }

/* ---- the record picker -------------------------------------------------------------------------- */
.cr-cal-pick { display: flex; flex-direction: column; gap: var(--pa-s1); min-width: 0; }
.cr-cal-pick .pa-tags { margin: 0; }
.cr-cal-pick .pa-tags[hidden] { display: none; }
.cr-cal-pick > .pa-meta:empty { display: none; }
.cr-cal-results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.cr-cal-result { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px var(--pa-s2); width: 100%; min-height: max(var(--pa-tap), 36px); padding: 6px var(--pa-s2); border: 1px solid var(--cx-border-soft); border-radius: var(--cx-radius-sm); background: var(--cx-surface); color: var(--cx-text); font: inherit; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.cr-cal-result:hover { background: var(--cx-hover); }
.cr-cal-result:focus-visible { outline: 2px solid var(--cx-focus); outline-offset: 1px; }

/* ---- automations: actions under the title, the preview, approval facts -------------------------- */
.cr-cal-actions { flex-wrap: wrap; margin: 0 0 var(--pa-s3); }
.cr-cal-preview { display: flex; flex-direction: column; gap: var(--pa-s3); min-width: 0; }
.cr-cal-reasons { list-style: none; margin: 0 0 var(--pa-s3); padding: 0; display: flex; flex-direction: column; gap: var(--pa-s1); }
.cr-cal-reasons li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--pa-s2); font-size: var(--cx-text-small); overflow-wrap: anywhere; }
.cr-cal-reasons b { font-variant-numeric: tabular-nums; }
.cr-cal-samples { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--pa-s2); }
.cr-cal-sample { display: flex; flex-direction: column; gap: var(--pa-s1); padding: var(--pa-s3); border: 1px solid var(--cx-border-soft); border-radius: var(--cx-radius-sm); background: var(--cx-surface-2); min-width: 0; }
.cr-cal-sample-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--pa-s1) var(--pa-s2); }
.cr-cal-sample-subject { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.cr-cal-sample-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--cx-text-small); }
.cr-cal-facts { margin: 0; padding-left: var(--pa-s5); display: flex; flex-direction: column; gap: 2px; font-size: var(--cx-text-small); overflow-wrap: anywhere; }

/* ---- history ------------------------------------------------------------------------------------ */
.cr-cal-history-pick { margin-bottom: var(--pa-s3); }
.cr-cal-history-pick .pa-select { max-width: 420px; }
.cr-cal-run-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--pa-s2) var(--pa-s3); margin-bottom: var(--pa-s3); }
.cr-cal-run-head .pa-btn { margin-left: auto; }
.cr-cal-deliveries .pa-row { content-visibility: auto; contain-intrinsic-size: auto 72px; }

/* ---- Medium: the side panel's room goes to the grid ----------------------------------------- */
@media (max-width: 1179px) {
  .cr-cal-day { min-height: 84px; padding: 4px; }
  .cr-cal-chip { padding: 1px 4px; }
}

/* ---- Compact (<= 640 px): one column; Week and Month are an agenda under the date strip ----- */
@media (max-width: 640px) {
  .cr-cal-bar { gap: var(--pa-s2); }
  .cr-cal-bar .pa-seg { width: 100%; }
  .cr-cal-bar .pa-seg button { flex: 1 1 0; }
  .cr-cal-period { margin: 0; width: 100%; order: -1; }
  .cr-cal-bar .pa-filter { flex: 1 1 140px; }
  .cr-cal-bar .pa-input, .cr-cal-form .pa-input, .cr-cal-form .pa-select, .cr-cal-form .pa-textarea, .cr-cal-pick .pa-input { font-size: 16px; }
  .cr-cal-row { grid-template-columns: minmax(0, 1fr); gap: var(--pa-s1); }
  .cr-cal-row-side { justify-content: flex-start; }
  .cr-cal-kind, .cr-cal-chip, .cr-cal-strip-day, .cr-cal-more { font-size: 12px; }
  .cr-cal-agenda-head, .cr-cal-summary, .cr-cal-check, .cr-cal-sample-body, .cr-cal-reasons li, .cr-cal-facts { font-size: 13.5px; }
  .cr-cal-legend { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
  .cr-cal-legend .cr-cal-chip { flex: none; }
  .cr-cal-run-head .pa-btn { margin-left: 0; }
  .cr-cal-regions { max-height: none; }
}
@media (any-pointer: coarse) {
  .cr-cal-strip-day, .cr-cal-result, .cr-cal-check { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .cr-cal-strip { scroll-behavior: auto; }
}
