/* Calendar. Same tokens and the same square, ruled look as the rest. */

.cal { display: grid; grid-template-columns: 220px minmax(0, 1fr); height: 100%; min-height: 0; }
.cal-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.cal-bar { display: flex; align-items: center; gap: var(--space-2); padding: 10px var(--space-4); border-bottom: 1px solid var(--color-divider); flex-wrap: wrap; }
.cal-title { font-family: var(--font-heading); font-size: 17px; margin: 0 var(--space-3); }
.cal-bar .modeswitch { display: inline-flex; border: 1px solid var(--color-neutral-400, var(--color-divider)); border-radius: var(--radius-sm); margin-right: var(--space-2); }
.cal-bar .modeswitch button { padding: 4px 12px; border: 0; background: transparent; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; color: var(--color-neutral-700); }
.cal-bar .modeswitch button[aria-pressed="true"] { background: var(--color-text); color: var(--color-bg); }
.cal-note { padding: 8px var(--space-4); font-size: 13px; border-bottom: 1px solid var(--color-divider); background: var(--color-surface); }

/* A calendar's colour. Five, used in turn; they have to be told apart at a
   glance, which the single accent cannot do, so this is the one place with
   more than one hue. Each is a fill, a line and a text colour. */
.cal-c0 { --cal: var(--color-accent); }
.cal-c1 { --cal: #1f8a70; }
.cal-c2 { --cal: #8a4fbf; }
.cal-c3 { --cal: #b9770e; }
.cal-c4 { --cal: #5b6b7a; }

/* ── the side ──────────────────────────────────────────────────────────── */
.cal-side { border-right: 2px solid var(--color-divider); padding: var(--space-4); overflow-y: auto; font-size: 13px; }
.cal-side h6 { margin: var(--space-4) 0 var(--space-2); }
.cal-mini-head { display: flex; align-items: center; margin-bottom: 6px; }
.cal-mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; text-align: center; }
.cal-mini-dow { font-size: 10px; color: var(--color-neutral-600); padding: 2px 0; }
.cal-mini-grid button { background: none; border: 0; padding: 4px 0; cursor: pointer; font: inherit; font-size: 12px; color: inherit; }
.cal-mini-grid button:hover { background: var(--color-surface); }
.cal-mini-grid button.is-other { color: var(--color-neutral-500); }
.cal-mini-grid button.is-shown { background: var(--color-accent-100); }
.cal-mini-grid button.is-today { background: var(--color-accent); color: var(--color-bg); font-weight: 700; }
.cal-pick { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.cal-pick > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-pick--off { cursor: default; color: var(--color-neutral-500); }
.cal-dot { flex: none; width: 10px; height: 10px; background: var(--cal, var(--color-neutral-400)); }
.cal-dot--task { background: transparent; border: 1.5px dashed var(--color-neutral-600); }
/* A mailbox with several calendars: its own tick as a heading, theirs under it. */
.cal-pick--head { font-weight: 600; }
.cal-pick-lists { padding-left: 21px; margin-bottom: 6px; }
.cal-side-link { display: block; margin: 0 0 8px 21px; font-size: 12px; text-align: left; }
.cal-holds-link { margin: 10px 0 0; }
.cal-search { width: 180px; padding: 4px 8px; font-size: 12px; margin-right: var(--space-2); }
.cal-zone-side { width: 100%; padding: 4px 6px; font-size: 12px; }
.cal-zone-note { margin-top: 4px; font-size: 11px; }
.cal-zone-second { margin-top: 6px; }
/* A second time zone: its own column of hours, quieter, and a name over each. */
.cal-hours--second span { color: var(--color-neutral-500); }
.cal-zone-tag { align-self: end; padding: 0 6px 4px; font-size: 10px; text-align: right; color: var(--color-neutral-600); white-space: nowrap; overflow: hidden; }

/* ── day, work week, week ──────────────────────────────────────────────── */
.cal-head, .cal-allday { display: grid; border-bottom: 1px solid var(--color-divider); padding-right: 12px; }
.cal-day { background: none; border: 0; border-left: 1px solid var(--color-divider); padding: 6px 8px; text-align: left; cursor: pointer; font: inherit; color: inherit; display: flex; align-items: baseline; gap: 6px; }
.cal-day:hover { background: var(--color-surface); }
.cal-dow { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--color-neutral-600); }
.cal-num { font-family: var(--font-heading); font-size: 18px; }
.cal-day.is-today .cal-num { background: var(--color-accent); color: var(--color-bg); padding: 0 6px; }
.cal-day.is-today .cal-dow { color: var(--color-accent); font-weight: 700; }
.cal-allday-label { font-size: 10px; color: var(--color-neutral-600); padding: 4px 6px; text-align: right; }
/* The strip of whole-day things runs under all the days; each thing says which of them it covers. */
.cal-allday-rows { grid-column: 2 / -1; display: grid; grid-auto-flow: row dense; gap: 2px; padding: 3px 2px; min-height: 8px; border-left: 1px solid var(--color-divider); }
.cal-scroll { flex: 1; min-height: 0; overflow-y: scroll; }
.cal-grid { display: grid; position: relative; }
.cal-hours { position: relative; }
.cal-hours span { position: absolute; right: 6px; transform: translateY(-50%); font-size: 10px; color: var(--color-neutral-600); white-space: nowrap; }
.cal-col {
  position: relative; border-left: 1px solid var(--color-divider); cursor: cell;
  /* A line on the hour and a fainter one on the half. */
  background-image:
    linear-gradient(to bottom, var(--color-divider) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--color-divider) 45%, transparent) 1px, transparent 1px);
  background-size: 100% 48px, 100% 24px;
}
.cal-col.is-today { background-color: color-mix(in srgb, var(--color-accent) 4%, transparent); }
.cal-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--color-accent); z-index: 3; pointer-events: none; }
.cal-now::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--color-accent); }

.cal-ev {
  /* clip, not hidden: the title can then stay in sight while a long event is scrolled past. */
  position: absolute; z-index: 1; overflow: clip; padding: 2px 6px; cursor: pointer; user-select: none;
  background: color-mix(in srgb, var(--cal) 16%, var(--color-bg)); border-left: 3px solid var(--cal); color: var(--color-text);
  font-size: 12px; line-height: 1.3; display: flex; flex-direction: column;
}
.cal-ev:hover { background: color-mix(in srgb, var(--cal) 26%, var(--color-bg)); z-index: 2; }
.cal-ev.is-short { flex-direction: row; gap: 6px; padding-block: 0; align-items: center; }
.cal-ev-title { flex: none; position: sticky; top: 2px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-ev-time { color: var(--color-neutral-700); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-ev-grip { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; cursor: ns-resize; }
.cal-ev.is-dragging { opacity: .8; z-index: 5; box-shadow: var(--shadow-md); cursor: grabbing; }
/* A time held while someone answers is striped and dashed: it is kept, not yet a meeting. */
.cal-ev.is-hold, .cal-chip.is-hold {
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--cal) 14%, var(--color-bg)) 0 6px, var(--color-bg) 6px 12px);
  outline: 1px dashed var(--cal); outline-offset: -1px;
}
.cal-hold-bar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; padding: 10px var(--space-6); background: var(--color-accent-100); border-bottom: 1px solid var(--color-divider); font-size: 13px; }

/* An invitation not yet answered is an outline; one answered "maybe" is hatched; a declined one is struck through. */
.cal-ev.is-unanswered, .cal-chip.is-unanswered { background: var(--color-bg); outline: 1px dashed var(--cal); outline-offset: -1px; }
.cal-ev.is-tentative, .cal-chip.is-tentative { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--cal) 18%, var(--color-bg)) 0 6px, var(--color-bg) 6px 12px); }
.cal-ev.is-declined, .cal-chip.is-declined { opacity: .55; }
.cal-ev.is-declined .cal-ev-title, .cal-chip.is-declined { text-decoration: line-through; }
.cal-ghost {
  position: absolute; left: 1px; right: 3px; z-index: 4; pointer-events: none; padding: 2px 6px; font-size: 11px; font-weight: 600;
  background: color-mix(in srgb, var(--color-accent) 22%, var(--color-bg)); border: 1px dashed var(--color-accent);
}

.cal-chip {
  display: block; width: 100%; min-width: 0; padding: 1px 6px; border: 0; text-align: left; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 600; color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: color-mix(in srgb, var(--cal) 18%, var(--color-bg)); border-left: 3px solid var(--cal);
}
.cal-chip:hover { background: color-mix(in srgb, var(--cal) 30%, var(--color-bg)); }
.cal-chip[draggable="true"] { cursor: grab; }
/* The right edge of an all-day event, to drag its last day. */
.cal-allday-rows .cal-chip { position: relative; }
.cal-chip-grip { position: absolute; top: 0; right: 0; bottom: 0; width: 7px; cursor: ew-resize; }
.cal-col.is-drop { outline: 1px dashed var(--color-accent); outline-offset: -1px; }
.cal-chip.is-dragging { opacity: .5; }
/* Where an event being dragged would land. */
.cal-cell.is-drop, .cal-allday-rows.is-drop { background: color-mix(in srgb, var(--color-accent) 12%, var(--color-bg)); outline: 1px dashed var(--color-accent); outline-offset: -1px; }
.cal-chip-time { font-weight: 400; color: var(--color-neutral-700); }
.cal-chip--task { background: transparent; border: 1px dashed var(--color-neutral-500); font-weight: 400; }
.cal-chip--task:hover { background: var(--color-surface); }

/* ── month ─────────────────────────────────────────────────────────────── */
.cal-month { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: auto repeat(6, minmax(0, 1fr)); overflow-y: auto; }
.cal-month-dow { padding: 6px 8px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--color-neutral-600); border-bottom: 1px solid var(--color-divider); }
.cal-cell { min-height: 96px; border-right: 1px solid var(--color-divider); border-bottom: 1px solid var(--color-divider); padding: 2px 3px; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.cal-cell.is-other { background: var(--color-surface); }
.cal-cell.is-other .cal-cell-num { color: var(--color-neutral-500); }
.cal-cell-num { align-self: flex-start; background: none; border: 0; padding: 1px 5px; cursor: pointer; font: inherit; font-size: 12px; color: inherit; }
.cal-cell.is-today .cal-cell-num { background: var(--color-accent); color: var(--color-bg); font-weight: 700; }
.cal-more { background: none; border: 0; padding: 0 6px; text-align: left; cursor: pointer; font: inherit; font-size: 11px; color: var(--color-neutral-700); }
.cal-more:hover { color: var(--color-accent); }

/* ── the event window ──────────────────────────────────────────────────── */
.cal-window {
  width: min(760px, 100%); max-height: 90vh; overflow-y: auto;
  background: var(--color-bg); border: 1px solid var(--color-divider); box-shadow: var(--shadow-lg);
}
.cal-window-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap;
  padding: var(--space-4) var(--space-6); background: var(--color-bg); border-bottom: 2px solid var(--color-divider);
}
.cal-form { padding: var(--space-4) var(--space-6); overflow: visible; }
.cal-when .row { gap: 8px; align-items: center; }
.cal-when .input { width: auto; }
.cal-guests { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; font-size: 13px; }
.cal-free { margin-top: 6px; }
.cal-free-answer { margin: 8px 0 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.cal-free-row { display: flex; flex-direction: column; gap: 3px; }
/* A guest's day as a strip: shaded when busy, outlined where the event is. */
.cal-strip { position: relative; display: block; height: 14px; margin-bottom: 12px; background: var(--color-surface); border: 1px solid var(--color-divider); }
.cal-strip i { position: absolute; top: 0; bottom: 0; }
.cal-strip-busy { background: var(--color-neutral-500); }
.cal-strip-at { outline: 2px solid var(--color-accent); outline-offset: -1px; z-index: 1; }
.cal-strip-lo, .cal-strip-hi { position: absolute; top: 15px; font-size: 10px; color: var(--color-neutral-600); }
.cal-strip-lo { left: 0; }
.cal-strip-hi { right: 0; }
/* A pattern of the person's own. */
.cal-rule { background: var(--color-surface); padding: 10px 12px; border: 1px solid var(--color-divider); display: flex; flex-direction: column; gap: 8px; }
.cal-rule .row { gap: 8px; align-items: center; flex-wrap: wrap; }
.cal-rule .input { width: auto; }
.cal-rule-n.input { width: 64px; }
.cal-rule-days-of-month.input { width: 110px; }
/* Days a series skips, and the weekdays of a month a pattern names: small tags, each with a way out. */
.cal-skip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.cal-skip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 8px; border: 1px solid var(--color-divider); background: var(--color-bg); font-size: 12px; }
.cal-skip.is-new { border-color: var(--color-accent); }
.cal-skip button { border: 0; background: none; cursor: pointer; font: inherit; font-size: 11px; color: var(--color-neutral-600); padding: 0 4px; }
.cal-skip button:hover { color: var(--color-accent); }
.cal-skips { display: flex; flex-direction: column; gap: 8px; }
.cal-skips .row { gap: 8px; align-items: center; flex-wrap: wrap; }
.cal-skips .input { width: auto; }
/* Times when everyone is free. */
.cal-slots { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.cal-slots .row { gap: 6px; flex-wrap: wrap; }
.cal-rule-days { display: inline-flex; gap: 2px; }
.cal-rule-days button { width: 28px; height: 28px; border: 1px solid var(--color-divider); background: var(--color-bg); cursor: pointer; font: inherit; font-size: 12px; color: inherit; }
.cal-rule-days button.is-on { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-bg); font-weight: 700; }
.cal-zone.input { max-width: 190px; }
/* What a search found. */
.cal-results { padding: var(--space-3) var(--space-6) var(--space-5); }
.cal-results h6 { margin: var(--space-4) 0 var(--space-2); }
.cal-result {
  display: grid; grid-template-columns: 10px 250px minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%;
  padding: 7px 4px; border: 0; border-bottom: 1px solid var(--color-divider); background: none; cursor: pointer;
  font: inherit; font-size: 13px; color: inherit; text-align: left;
}
.cal-result:hover { background: var(--color-surface); }
.cal-result-when { color: var(--color-neutral-700); font-size: 12px; }
.cal-result-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-window .crm-dialog-foot { position: sticky; bottom: 0; background: var(--color-bg); }
.cal-window .crm-source { display: inline; }
.palette-backdrop:has(.cal-window) { padding-top: 5vh; }
.crm-meetrow > span:first-child { width: 132px; }

@media (max-width: 900px) {
  .cal { grid-template-columns: minmax(0, 1fr); }
  .cal-side { display: none; }
}

/* A list of events for paper. It is only ever there while it is being printed. */
.cal-agenda { display: none; }

/* ── on paper ──────────────────────────────────────────────────────────────
   Print gives the days that are on screen and nothing of the app around
   them: the month as it is, a week from its first event to its last. */
@media print {
  @page { size: landscape; margin: 10mm; }
  html, body { height: auto !important; overflow: visible !important; }
  body:has(.cal) .appbar, body:has(.cal) #overlay, body:has(.cal) #toasts, body:has(.cal) .banner,
  .cal-side, .cal-bar > :not(.cal-title), .cal-note, .cal-now, .cal-ev-grip, .cal-chip-grip { display: none !important; }
  body:has(.cal) .app, body:has(.cal) .app-main { display: block; height: auto !important; overflow: visible !important; }
  .cal, .cal-main { display: block; height: auto !important; }
  .cal-bar { border: 0; padding: 0 0 6px; }
  .cal-title { margin: 0; font-size: 16px; }
  /* Only the hours that have something in them (set just before printing). */
  .cal-scroll { overflow: hidden !important; flex: none; height: var(--print-height, auto); }
  .cal-grid { margin-top: calc(-1 * var(--print-from, 0px)); }
  .cal-head, .cal-allday { padding-right: 0; }
  .cal-month { overflow: visible; }
  .cal-cell { min-height: 28mm; break-inside: avoid; }
  .cal-ev, .cal-chip, .cal-col, .cal-day.is-today .cal-num, .cal-cell.is-today .cal-cell-num { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .cal-ev-title { position: static; }

  /* The list of events instead of the screen. */
  body.print-agenda > :not(.cal-agenda) { display: none !important; }
  body.print-agenda .cal-agenda { display: block; font-size: 11pt; color: #000; }
  .cal-agenda h1 { font-size: 16pt; margin: 0 0 2mm; }
  .cal-agenda h2 { font-size: 12pt; margin: 6mm 0 1mm; padding-bottom: 1mm; border-bottom: 1px solid #000; break-after: avoid; }
  .cal-agenda p { margin: 0 0 2mm; color: #444; }
  .cal-agenda table { width: 100%; border-collapse: collapse; }
  .cal-agenda tr { break-inside: avoid; }
  .cal-agenda td { padding: 1.2mm 2mm 1.2mm 0; vertical-align: top; border-bottom: 1px solid #ccc; }
  .cal-agenda-when { width: 42mm; white-space: nowrap; }
  .cal-agenda-cal { width: 40mm; text-align: right; color: #444; }
  .cal-agenda-where { color: #444; font-size: 10pt; }
}
