/* The period, its measures and the grid share one calendar surface. */
#calendar-view .operations-calendar-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.2fr);
  gap: 10px;
  min-width: 0;
}
#calendar-view .operations-calendar-summary:empty,
#calendar-view .operations-calendar-summary[hidden] { display: none; }
#calendar-view .calendar-measure {
  --measure-color: #2671ca;
  position: relative;
  isolation: isolate;
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
  min-height: 75px;
  overflow: hidden;
  padding: 10px 16px;
  border: 1px solid color-mix(in srgb, var(--measure-color) 19%, var(--surface));
  border-radius: 13px;
  background: linear-gradient(115deg, color-mix(in srgb, var(--measure-color) 7%, var(--surface)), color-mix(in srgb, var(--measure-color) 13%, var(--surface)));
}
#calendar-view .calendar-measure[data-tone="green"] { --measure-color: #149460; }
#calendar-view .calendar-measure[data-tone="amber"] { --measure-color: #c97a06; }
#calendar-view .calendar-measure[data-tone="red"] { --measure-color: #d34458; }
#calendar-view .calendar-measure[data-tone="purple"] { --measure-color: #8147c6; }
#calendar-view .calendar-measure-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: color-mix(in srgb, var(--measure-color) 16%, var(--surface));
  color: color-mix(in srgb, var(--measure-color) 84%, var(--text));
  font-size: 24px;
}
#calendar-view .calendar-measure-copy { min-width: 0; color: var(--text); }
#calendar-view .calendar-measure-copy strong { display: block; font-size: clamp(21px, 1.55vw, 28px); line-height: 1.12; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
#calendar-view .calendar-measure-copy span { display: block; margin-top: 4px; font-size: 13px; font-weight: 600; line-height: 1.25; }

#mainContent #calendar-view .calendar-toolbar .segment[aria-pressed="true"] {
  --status-filter-selected: #ffca07;
  --filter-ink: #1b2030;
  background: var(--status-filter-selected); color: var(--filter-ink); box-shadow: none;
}
#calendar-view .calendar-crew-filter {
  order: 7;
  flex: 0 1 auto;
  width: auto;
  max-width: 190px;
  min-height: 38px;
  margin: 0;
  padding: 0 26px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}
#calendar-view .calendar-toolbar #personalCalendarToggle { order: 8; }
#calendar-view #calendarStage {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
#calendar-view #calendarStage .month-grid { background: var(--surface); }
#calendar-view #calendarStage .month-weekday {
  background: var(--surface-muted);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}
#calendar-view #calendarStage .month-day { border-color: var(--line); background: var(--surface); }
#calendar-view #calendarStage .month-day.muted { background: color-mix(in srgb, var(--surface-muted) 65%, var(--surface)); }
#calendar-view #calendarStage .month-day.selected-day { background: color-mix(in srgb, #4585db 8%, var(--surface)); box-shadow: inset 0 0 0 1px #5687cf; }
#calendar-view #calendarStage .month-day.current { background: color-mix(in srgb, #ffce28 10%, var(--surface)); box-shadow: inset 0 0 0 2px #efbb12; }
#calendar-view #calendarStage .month-day > strong {
  display: flex; align-items: center; justify-content: flex-start; justify-self: start;
  width: max-content; height: 28px; max-width: 100%; padding: 0; margin: 0 0 0 9px;
  background: transparent; font-size: 13px; font-weight: 700; line-height: 1;
}
#calendar-view #calendarStage .month-day.current > strong {
  height: 22px; margin: 3px 0 3px 6px; padding: 0 7px; border-radius: 6px; background: #ffcf28; color: #201f18;
}
#calendar-view #calendarStage .month-day.current > strong::after {
  content: "Today"; padding-inline-start: 5px; font-size: 9px; text-transform: uppercase;
}
#calendar-view #calendarStage .day-head.current .date-dot { background: #ffcf28; color: #201f18; }
#calendar-view .compact-calendar-item { --entry-accent: #2a76c8; --entry-glyph: "work"; }
#calendar-view [data-job-kind="carpark"] { --entry-accent: #bd7906; --entry-glyph: "directions_car"; }
#calendar-view [data-job-kind="warehouse"] { --entry-accent: #3075cf; --entry-glyph: "warehouse"; }
#calendar-view [data-job-kind="roadmarking"], #calendar-view [data-job-kind="line marking"] { --entry-accent: #14965c; --entry-glyph: "add_road"; }
#calendar-view [data-job-kind="maintenance"] { --entry-accent: #8054bb; --entry-glyph: "build"; }
#calendar-view [data-job-kind^="project"] { --entry-accent: #d78021; --entry-glyph: "apartment"; }
#calendar-view .compact-calendar-item[data-custom-label] { --entry-accent: var(--month-label); }
#calendar-view #calendarStage .month-items .compact-calendar-item {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  width: calc(100% - 6px);
  min-width: 0;
  margin-inline: 3px;
  padding-inline: 5px;
  border: solid transparent;
  border-width: 1px 0;
  border-radius: 7px;
  background: color-mix(in srgb, var(--entry-accent) 14%, var(--surface)) padding-box;
  color: var(--text);
  box-shadow: none;
}
#calendar-view #calendarStage .month-items .compact-calendar-item:hover { background-color: color-mix(in srgb, var(--entry-accent) 24%, var(--surface)); }
#calendar-view #calendarStage .month-items .compact-calendar-item:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
#calendar-view #calendarStage .month-items .compact-calendar-item strong { min-width: 0; font-size: 12px; font-weight: 650; text-align: start; }
#calendar-view #calendarStage .month-items .compact-calendar-item small { color: var(--text); font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums; }
#calendar-view #calendarStage .month-items .compact-calendar-item .calendar-dot {
  display: grid; place-items: center; width: 16px; height: 16px; border: 0; border-radius: 0;
  background: transparent; box-shadow: none; color: color-mix(in srgb, var(--entry-accent) 65%, var(--text));
  font-family: "Material Symbols Rounded"; font-size: 15px; line-height: 1; font-feature-settings: "liga";
}
#calendar-view #calendarStage .month-items .compact-calendar-item .calendar-dot::before { content: var(--entry-glyph); }
#calendar-view #calendarStage .week-booking > .compact-calendar-item {
  border-inline-start-color: var(--entry-accent);
  background-color: color-mix(in srgb, var(--entry-accent) 15%, var(--surface));
}
@media screen and (min-width: 761px) {
  body[data-view="calendar"] #mainContent { --calendar-header-height: 60px; }
  body[data-view="calendar"] #mainContent > .topbar {
    display: flex; flex-flow: row nowrap; align-items: center; justify-content: space-between;
    gap: 12px; height: var(--calendar-header-height); min-height: var(--calendar-header-height); padding-block: 0;
  }
  body[data-view="calendar"] #mainContent > .topbar > #pageToolbar { flex: 1 1 auto; width: auto; min-width: 0; height: auto; }
  body[data-view="calendar"] #mainContent > .topbar > .topbar-shared { flex: 0 1 auto; width: auto; height: 48px; }
  body[data-view="calendar"] #mainContent #calendar-view .calendar-layout > .calendar-panel {
    display: flex; flex-direction: column; gap: 10px;
    min-width: 0; min-height: 0; height: calc(100dvh - var(--calendar-header-height));
    padding: 0 clamp(10px, 1.3vw, 24px) 8px; border: 0; background: var(--surface);
  }
  body[data-view="calendar"] #mainContent #calendar-view .calendar-header {
    position: relative; top: auto; display: block; flex: none; height: auto; min-width: 0; margin: 0;
    border: 0; background: transparent; overflow: visible; transform: none;
  }
  body[data-view="calendar"] #calendar-view .calendar-header h1 { display: none; }
  body[data-view="calendar"] #calendar-view .calendar-header .calendar-toolbar {
    display: flex; flex-flow: row wrap; align-items: center; gap: 6px;
    width: 100%; height: auto; min-height: 48px; padding: 6px 0 0; overflow: visible;
  }
  #mainContent #calendar-view .calendar-toolbar .segmented { flex: 0 0 auto; width: auto; height: 37px; margin: 0; }
  #mainContent #calendar-view .calendar-toolbar .segment { padding-inline: 14px; }
  #mainContent #calendar-view .calendar-toolbar .today-button { width: auto; min-width: 52px; flex: 0 0 auto; padding-inline: 10px; }
  #calendar-view #operationsCalendarSummary { flex: none; }
  #mainContent #calendar-view .calendar-panel > #calendarStage { flex: 1 1 0; height: auto; }
  body[data-calendar-view-mode="month"] #mainContent #calendar-view #calendarStage { overflow: hidden; }
}
@container calendar-day (max-width: 135px) {
  #calendar-view #calendarStage .month-items .compact-calendar-item { grid-template-columns: 15px minmax(0, 1fr); }
  #calendar-view #calendarStage .month-items .compact-calendar-item small { display: none; }
}
@media screen and (max-width: 1050px) {
  #calendar-view .calendar-measure { min-height: 67px; padding: 8px; gap: 7px; }
  #calendar-view .calendar-measure-icon { width: 29px; height: 29px; border-radius: 9px; font-size: 18px; }
  #calendar-view .calendar-measure-copy strong { font-size: 19px; }
  #calendar-view .calendar-measure-copy span { font-size: 11px; }
  #calendar-view #calendarStage .month-day.current > strong::after { content: none; }
}
@media screen and (max-width: 760px) {
  #mainContent #calendar-view .calendar-panel { gap: 8px; padding: 0 8px 10px; }
  #mainContent #calendar-view .calendar-header { display: block; height: auto; }
  #mainContent #calendar-view .calendar-header h1 { position: static; width: auto; height: auto; margin: 8px 0; clip: auto; overflow: visible; white-space: normal; font-size: 21px; }
  #mainContent #calendar-view .calendar-header .calendar-toolbar {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: stretch;
    gap: 4px 6px; height: auto; min-height: 0; padding: 0; overflow: visible;
  }
  #mainContent #calendar-view .calendar-toolbar .segmented { grid-area: 1 / 1; width: 100%; }
  #mainContent #calendar-view .calendar-toolbar .calendar-period-navigation { grid-area: 1 / 2; justify-content: center; }
  #mainContent #calendar-view .calendar-toolbar .calendar-date-controls { grid-area: 2 / 1 / auto / -1; }
  #mainContent #calendar-view .calendar-toolbar .calendar-period-label { display: inline; }
  #mainContent #calendar-view .calendar-toolbar .calendar-mobile-date-label { display: none; }
  #mainContent #calendar-view .calendar-toolbar .calendar-crew-filter { grid-area: 3 / 1; width: 100%; max-width: none; min-width: 0; font-size: 12px; }
  #mainContent #calendar-view .calendar-toolbar #personalCalendarToggle { grid-area: 3 / 2; width: 100%; }
  #calendar-view .operations-calendar-summary { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 5px; }
  #calendar-view .calendar-measure { min-height: 49px; padding: 7px; border-radius: 9px; }
  #calendar-view .calendar-measure:last-child { grid-column: span 2; }
  #calendar-view .calendar-measure-copy strong { font-size: 16px; }
  #calendar-view .calendar-measure-copy span { margin-top: 1px; }
  #calendar-view #calendarStage .month-day > strong { margin-inline-start: 2px; height: 20px; font-size: 11px; }
  #calendar-view #calendarStage .month-day.current > strong { height: 18px; padding-inline: 4px; margin: 0; }
  #calendar-view #calendarStage .month-weekday { font-size: 11px; }
  #calendar-view #calendarStage .month-items .compact-calendar-item { grid-template-columns: minmax(0, 1fr); width: calc(100% - 2px); margin: 0 1px; padding-inline: 2px; }
  #calendar-view #calendarStage .month-items .compact-calendar-item .calendar-dot,
  #calendar-view #calendarStage .month-items .compact-calendar-item small { display: none; }
  #calendar-view #calendarStage .month-items .compact-calendar-item strong { font-size: 10px; }
}

/* Calendar editing sheets share the workspace header, fields and action footer. */
@media screen {
  body:not(.login-mode) > :is(.calendar-todo-modal-backdrop, .calendar-repeat-modal-backdrop) {
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    place-items: stretch end;
    padding: 0;
    overflow: hidden;
  }
  body:not(.login-mode) > :is(.calendar-todo-modal-backdrop, .calendar-repeat-modal-backdrop) > [role="dialog"],
  body > .calendar-job-reschedule-dialog {
    box-sizing: border-box;
    width: min(100%, 31rem);
    max-width: 100%;
    min-height: 0;
    max-height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-inline-start: 1px solid var(--cl-rule);
    border-radius: 0;
    background: var(--surface);
    color: var(--text);
    overscroll-behavior: contain;
  }
  body:not(.login-mode) > .calendar-repeat-modal-backdrop > .calendar-repeat-modal {
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
  }
  body > .calendar-job-reschedule-dialog {
    position: fixed;
    inset: 60px 0 0 auto;
    height: calc(100dvh - 60px);
  }
  .calendar-job-reschedule-dialog > form {
    display: flex;
    min-height: 100%;
    flex-direction: column;
    gap: 0;
    padding: 0;
  }
  .calendar-job-reschedule-form > :is(h2, p, .calendar-job-reschedule-fields),
  .calendar-repeat-modal > :is(.calendar-repeat-modal-row, .calendar-repeat-ends) {
    margin: 14px 20px 0;
  }
  .calendar-job-reschedule-form > h2 { margin-top: 22px; }
  .calendar-job-reschedule-form #calendarJobRescheduleName {
    margin-top: 6px;
    font-size: .9375rem;
    color: var(--text);
  }
  .calendar-job-reschedule-form [data-calendar-job-current-schedule] {
    padding: 12px;
    border: 1px solid var(--cl-rule);
    border-radius: 9px;
    background: var(--surface-muted);
  }
  .calendar-job-reschedule-form > .calendar-job-reschedule-fields { margin-bottom: 18px; }
  .calendar-job-reschedule-fields > label { margin: 0; font-weight: 650; color: var(--muted); }
  .calendar-job-reschedule-fields > label > input { margin: 0; color: var(--text); font-weight: 500; }

  :is(.calendar-repeat-modal, .calendar-todo-modal) > .calendar-modal-header {
    grid-template-columns: auto minmax(0, 1fr);
    padding: 14px 20px;
    border-bottom: 1px solid var(--cl-rule);
  }
  .calendar-modal-header .calendar-modal-header-spacer { display: none; }
  :is(.calendar-repeat-modal, .calendar-todo-modal) .calendar-modal-header h2,
  .calendar-job-reschedule-form > h2,
  .calendar-discard-modal-backdrop .calendar-discard-modal h2 {
    justify-self: start;
    padding-inline-start: 10px;
    border-inline-start: 4px solid var(--cl-gold);
    color: var(--text);
    font-size: clamp(1.125rem, 1.4vw, 1.375rem);
    font-weight: 700;
    letter-spacing: -.025em;
    line-height: 1.25;
    text-align: start;
    overflow-wrap: anywhere;
  }
  .calendar-modal-header .calendar-modal-close,
  .calendar-repeat-modal .calendar-repeat-cancel,
  .calendar-discard-modal .calendar-discard-cancel {
    border: 1px solid var(--cl-rule);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
  }

  .calendar-todo-modal > :is(.calendar-todo-scroll-area, .calendar-note-scroll-area) {
    margin: 0;
    padding: 18px 20px;
  }
  .calendar-note-modal .calendar-note-field textarea,
  .calendar-todo-modal .calendar-todo-item-row,
  .calendar-repeat-modal :is(.calendar-repeat-unit-button, input[type="number"], input[type="date"]) {
    border: 1px solid var(--cl-rule);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
  }
  .calendar-note-modal .calendar-note-field textarea { min-height: 0; padding: 12px; }
  .calendar-todo-modal .calendar-todo-item-input,
  .calendar-repeat-modal :is(.calendar-repeat-modal-row > span, .calendar-repeat-ends > strong, .calendar-repeat-end-row) { color: var(--text); }
  .calendar-todo-modal :is(.calendar-todo-remove, .calendar-todo-drag, .calendar-todo-completed-toggle, .calendar-todo-completed-toggle .material-symbols-rounded),
  .calendar-todo-modal .calendar-todo-item-row.completed .calendar-todo-item-input { color: var(--muted); }
  .calendar-todo-modal .calendar-todo-item-row.completed { background: var(--surface-muted); }
  .calendar-todo-modal .calendar-todo-add-row {
    min-height: 44px;
    margin-inline: 0;
    padding-inline: 8px;
    color: var(--text);
  }
  .calendar-todo-modal .calendar-todo-add-row .material-symbols-rounded { color: inherit; }
  .calendar-repeat-modal .calendar-repeat-ends { gap: 8px; margin-bottom: 20px; }
  .calendar-repeat-modal .calendar-repeat-end-row { min-height: 44px; }
  .calendar-repeat-modal .calendar-repeat-end-row:has(input:checked) { font-weight: 650; }
  .calendar-repeat-modal input[type="radio"], .calendar-todo-modal input[type="checkbox"] { accent-color: var(--text); }

  .calendar-job-reschedule-form > .calendar-job-reschedule-actions,
  .calendar-repeat-modal > .calendar-repeat-modal-actions,
  .calendar-discard-modal > .calendar-discard-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: auto;
    padding: 14px 20px max(14px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--cl-rule);
    background: var(--surface-muted);
  }
  .calendar-job-reschedule-form > .calendar-job-reschedule-error:not([hidden]),
  .calendar-job-reschedule-form:not(:has(.calendar-job-reschedule-fields)) > [data-calendar-job-current-schedule] { margin-bottom: 18px; }
  .calendar-job-reschedule-actions [data-open-unschedule] { margin-inline-end: auto; }
  .calendar-todo-modal > .calendar-todo-ok-button {
    justify-self: end;
    min-width: 88px;
    min-height: 44px;
    margin: 8px 20px max(14px, env(safe-area-inset-bottom));
    background: var(--cl-gold);
    color: var(--cl-gold-ink);
  }
  .calendar-repeat-modal .calendar-repeat-save { background: var(--cl-gold); color: var(--cl-gold-ink); }
  .calendar-discard-modal-backdrop .calendar-discard-modal {
    width: min(27rem, 100%);
    gap: 0;
    max-height: 100%;
    overflow-y: auto;
    padding: 0;
    border: 1px solid var(--cl-rule);
    border-radius: 14px;
    background: var(--surface);
  }
  .calendar-discard-modal-backdrop .calendar-discard-modal h2 {
    margin: 20px 20px 8px;
    border-inline-start-color: var(--red);
  }
  .calendar-discard-modal-backdrop .calendar-discard-modal p {
    padding: 0 20px 18px;
    color: var(--muted);
    overflow-wrap: anywhere;
  }

  #calendarEventForm, #calendarAppointmentForm {
    background: var(--cl-canvas);
    color: var(--text);
  }
  #calendarEventForm :is(.event-editor-toolbar, .event-section-card, .event-extra-list),
  #calendarAppointmentForm :is(.appointment-editor-toolbar, .appointment-form-section) {
    border-color: var(--cl-rule);
    background: var(--surface);
  }
  #calendarEventForm .event-editor-toolbar > strong,
  #calendarAppointmentForm .appointment-editor-toolbar strong {
    padding-inline-start: 10px;
    border-inline-start: 4px solid var(--cl-gold);
    color: var(--text);
    font-size: 1.125rem;
  }
  #calendarEventForm :is(.event-title-label, .event-select-row > span, .event-toggle-row > span),
  #calendarAppointmentForm .appointment-field > span { color: var(--text); }
  #calendarEventForm :is(.event-title-input, .event-date-display, .event-extra-input),
  #calendarAppointmentForm .appointment-field .input {
    border-color: var(--cl-rule);
    background-color: var(--surface);
    color: var(--text);
  }
  #calendarEventForm .event-title-input[aria-invalid="true"],
  #calendarAppointmentForm .appointment-field .input[aria-invalid="true"] { border-color: var(--red); }
  #calendarEventForm :is(.event-repeat-option[aria-pressed="true"], .event-type-tabs [aria-pressed="true"]) {
    background: var(--cl-gold);
    color: var(--cl-gold-ink);
  }
  #calendarEventForm .event-repeat-option.selected .event-label-radio { border-color: var(--cl-gold-ink); }
  #calendarEventForm .event-repeat-option.selected .event-label-radio::after { background: var(--cl-gold-ink); }
  #calendarEventForm .event-footer-actions { border-color: var(--cl-rule); background: var(--surface-muted); }

  /* The picker is portalled to the page when its trigger is inside a scrolling panel. */
  body[data-view="calendar"] .event-date-picker-popover {
    border: 1px solid var(--cl-rule);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
  }
  body[data-view="calendar"] .event-date-picker-head strong { color: var(--text); font-weight: 700; }
  body[data-view="calendar"] :is(.event-date-picker-icon, .event-date-picker-nav, .event-date-picker-nav button) {
    border-color: var(--cl-rule);
    background-color: var(--surface);
    color: var(--text);
  }
  body[data-view="calendar"] .event-date-picker-day:not(.selected, .sunday, .muted) { color: var(--text); }
  body[data-view="calendar"] .event-date-picker-day.muted { color: var(--muted); }
  body[data-view="calendar"] .event-date-picker-day[aria-pressed="true"] {
    background: var(--cl-gold);
    color: var(--cl-gold-ink);
    font-weight: 750;
  }
  body[data-view="calendar"] .event-date-picker-day:not([aria-pressed="true"], :disabled):hover,
  .calendar-modal-header .calendar-modal-close:hover { background: var(--surface-muted); }
  body[data-view="calendar"] .event-date-picker-popover button:focus-visible,
  body :is(.calendar-todo-modal, .calendar-repeat-modal, .calendar-job-reschedule-dialog, .calendar-discard-modal) :is(button, textarea, input):focus-visible {
    outline: 2px solid var(--accent, #2862b7);
    outline-offset: -2px;
  }
}

@media screen and (max-width: 760px) {
  body:not(.login-mode) > :is(.calendar-todo-modal-backdrop, .calendar-repeat-modal-backdrop) > [role="dialog"],
  body > .calendar-job-reschedule-dialog { width: 100%; border-inline: 0; }
  body > .calendar-job-reschedule-dialog { inset: 0; height: 100dvh; }
  .calendar-job-reschedule-form > h2 { margin-top: max(18px, env(safe-area-inset-top)); }
  :is(.calendar-repeat-modal, .calendar-todo-modal) > .calendar-modal-header { padding-top: max(14px, env(safe-area-inset-top)); }
  .calendar-job-reschedule-form .calendar-job-reschedule-fields .input,
  .calendar-todo-modal .calendar-todo-item-input, .calendar-note-modal .calendar-note-field textarea,
  .calendar-repeat-modal :is(input[type="date"], input[type="number"]) { font-size: 1rem; }
}
