/* Calendar: shared spacing and colours keep every view in the same quiet rhythm. */
.cal-calendar {
  --cal-hour: 64px;
  --cal-event-min-height: 22px;
  --cal-ruler: 56px;
  --cal-columns: 7;
  --cal-soft: color-mix(in srgb, var(--sage) 52%, var(--panel));
  --cal-gridline: color-mix(in srgb, var(--line) 58%, transparent);
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 5px 24px #27382704;
  color: var(--ink);
  isolation: isolate;
}

.cal-calendar button { font-family: inherit; }
:where(.cal-calendar) button:focus-visible,
.cal-drag-tooltip:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 3px;
}
.cal-calendar button:disabled { cursor: default; }
:where(.cal-calendar) button .icon { width: 16px; height: 16px; }
.cal-toolbar,
.cal-toolbar-main,
.cal-toolbar-actions,
.cal-nav,
.cal-view-switch { display: flex; align-items: center; }
.cal-toolbar {
  justify-content: space-between;
  gap: 20px;
  padding: 23px 24px;
}
.cal-toolbar-main { min-width: 0; gap: 17px; }
.cal-nav {
  flex: 0 0 auto;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.cal-nav button {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
}
.cal-nav button:hover { background: var(--sage); }
.cal-heading { min-width: 0; }
.cal-heading h2 {
  font-size: 19px;
  font-weight: 750;
  line-height: 1.35;
  letter-spacing: -.55px;
}
.cal-heading p {
  margin: 4px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}
.cal-toolbar-actions { flex-shrink: 0; gap: 10px; }
.cal-today,
.cal-add {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.cal-today:hover { background: var(--sage); }
.cal-add { background: var(--green); border-color: var(--green); color: #fff; }
.cal-add:hover { filter: brightness(.94); }
.cal-view-switch { gap: 2px; padding: 3px; border-radius: 9px; background: var(--cal-soft); }
.cal-view-switch button {
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 550;
  white-space: nowrap;
}
.cal-view-switch button:hover { color: var(--ink); }
.cal-view-switch button[aria-pressed="true"] {
  border-color: var(--line);
  background: var(--panel);
  color: var(--green);
  box-shadow: 0 1px 3px #263b1f08;
  font-weight: 700;
}

/* Month */
.cal-month-weekdays,
.cal-month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-month-weekdays {
  padding: 12px 0;
  border-block: 1px solid var(--line);
  background: var(--cal-soft);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .6px;
  text-align: center;
}
.cal-month-weekdays > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cal-month-cell {
  min-width: 0;
  min-height: 133px;
  padding: 9px 8px 11px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.cal-month-cell:nth-child(7n) { border-right: 0; }
.cal-month-cell.is-outside { background: var(--cal-soft); }
.cal-month-cell.is-outside .cal-date-button { color: var(--muted); }
.cal-month-cell.is-today { background: color-mix(in srgb, var(--sage) 45%, var(--panel)); }
.cal-month-cell-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-bottom: 7px; }
.cal-date-button,
.cal-cell-add {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  flex-shrink: 0;
}
.cal-date-button { width: 28px; height: 28px; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-cell-add { width: 24px; height: 24px; color: var(--muted); opacity: .5; }
.cal-cell-add .icon { width: 13px; height: 13px; }
.cal-date-button:hover,
.cal-cell-add:hover { background: var(--sage); }
.cal-month-cell:hover .cal-cell-add,
.cal-month-cell:focus-within .cal-cell-add { opacity: 1; }
.cal-month-cell.is-today .cal-date-button { background: var(--green); color: #fff; }
.cal-month-events { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-month-task {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  min-height: 26px;
  padding: 5px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: color-mix(in srgb, var(--cal-color, var(--green)) 9%, var(--panel));
  color: var(--ink);
  font-size: 10px;
  line-height: 1.4;
  text-align: left;
}
.cal-month-task:hover { border-color: color-mix(in srgb, var(--cal-color, var(--green)) 35%, var(--line)); }
.cal-task-dot { flex: 0 0 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--cal-color, var(--green)); }
.cal-month-time { flex-shrink: 0; color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.cal-month-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.cal-month-task.is-done .cal-month-title { color: var(--muted); text-decoration: line-through; }
.cal-month-task.is-completion { display: grid; grid-template-columns: 5px minmax(0, 1fr); gap: 1px 5px; }
.cal-month-task.is-completion .cal-task-dot { grid-column: 1; grid-row: 1 / 3; }
.cal-month-task.is-completion .cal-month-time,
.cal-month-task.is-completion .cal-month-title { grid-column: 2; }
.cal-month-task.is-completion .cal-month-time { color: var(--green); }
.cal-more {
  align-self: flex-start;
  max-width: 100%;
  padding: 4px 6px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--green);
  font-size: 10px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-more:hover { background: var(--sage); }

/* The time ruler and upper rows remain anchored while the schedule scrolls. */
.cal-timeline-scroller {
  position: relative;
  max-height: 680px;
  overflow: auto;
  border-block: 1px solid var(--line);
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--green) 28%, var(--line)) transparent;
}
.cal-timeline { position: relative; min-width: 0; }
.cal-timeline[data-cal-columns="7"] { min-width: max(700px, var(--cal-min-width, 700px)); }
.cal-timeline[data-cal-columns="1"] { min-width: max(280px, var(--cal-min-width, 280px)); }
.cal-timeline-top { position: sticky; top: 0; z-index: 20; background: var(--panel); box-shadow: 0 2px 5px #27382705; }
.cal-day-headings,
.cal-all-day,
.cal-time-grid { display: grid; grid-template-columns: var(--cal-ruler) var(--cal-day-tracks, repeat(var(--cal-columns), minmax(0, 1fr))); }
.cal-day-headings { min-height: 80px; }
.cal-corner,
.cal-all-day-label {
  position: sticky;
  left: 0;
  z-index: 3;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px 5px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 9px;
  line-height: 1.4;
  text-align: center;
}
.cal-corner { align-items: flex-end; padding-bottom: 12px; }
.cal-day-heading {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 10px 5px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  text-align: center;
}
.cal-day-heading:last-child { border-right: 0; }
.cal-day-heading strong { font-size: 10px; line-height: 1.4; font-weight: 550; color: var(--muted); }
.cal-day-heading > span { display: grid; place-items: center; min-width: 31px; height: 31px; padding-inline: 5px; border-radius: 10px; font-size: 17px; font-weight: 650; line-height: 1; font-variant-numeric: tabular-nums; }
.cal-day-heading:hover { background: var(--cal-soft); }
.cal-day-heading.is-today { background: var(--cal-soft); }
.cal-day-heading.is-today strong { color: var(--green); }
.cal-day-heading.is-today > span { background: var(--green); color: #fff; }
.cal-all-day { max-height: 148px; overflow-y: auto; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--cal-soft); scrollbar-width: thin; }
.cal-all-day-label { top: 0; align-self: start; min-height: 42px; background: var(--cal-soft); }
.cal-all-day-cell { display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 6px; border-right: 1px solid var(--line); }
.cal-all-day-cell:last-child { border-right: 0; }
.cal-due-task {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid color-mix(in srgb, var(--cal-color, var(--green)) 24%, var(--line));
  border-left: 3px solid var(--cal-color, var(--green));
  border-radius: 5px;
  background: var(--panel);
  color: var(--ink);
  font-size: 10px;
  line-height: 1.5;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-due-task:hover { background: var(--sage); }
.cal-due-task.is-done { color: var(--muted); text-decoration: line-through; }
.cal-time-grid { position: relative; }
.cal-time-ruler {
  position: sticky;
  left: 0;
  z-index: 10;
  width: var(--cal-ruler);
  height: calc(var(--cal-hour) * 24);
  border-right: 1px solid var(--line);
  background: var(--panel);
}
.cal-hour-label {
  position: absolute;
  right: 11px;
  max-width: calc(var(--cal-ruler) - 14px);
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 9px;
  line-height: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cal-hour-label:first-child { transform: translateY(2px); }
.cal-hour-label:last-child { transform: translateY(-100%); }
.cal-day-column {
  position: relative;
  min-width: 0;
  height: calc(var(--cal-hour) * 24);
  border-right: 1px solid var(--line);
  background-color: var(--panel);
  background-image:
    linear-gradient(to bottom, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--cal-gridline) 1px, transparent 1px);
  background-size: 100% var(--cal-hour), 100% calc(var(--cal-hour) / 2);
  background-position: 0 -1px;
}
.cal-day-column:last-child { border-right: 0; }
.cal-day-column.is-today { background-color: color-mix(in srgb, var(--sage) 25%, var(--panel)); }
.cal-day-column:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }

/* Move and resize handles are separate from the always available edit control. */
.cal-event {
  position: absolute;
  z-index: 2;
  min-height: var(--cal-event-min-height);
  min-width: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--cal-color, var(--green)) 32%, var(--line));
  border-left: 3px solid var(--cal-color, var(--green));
  border-radius: 7px;
  background: color-mix(in srgb, var(--cal-color, var(--green)) 12%, var(--panel));
  box-shadow: 0 1px 2px #20342006;
  color: var(--ink);
}
.cal-event:hover { border-top-color: var(--cal-color, var(--green)); border-right-color: var(--cal-color, var(--green)); border-bottom-color: var(--cal-color, var(--green)); }
.cal-event:focus-within { z-index: 5; box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--green); }
.cal-event-open {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 7px 24px 9px 7px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  line-height: 1.35;
  text-align: left;
  overflow: hidden;
}
.cal-event-open:focus-visible { outline-offset: -3px; }
.cal-event-time { display: block; flex-shrink: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; font-weight: 500; font-variant-numeric: tabular-nums; color: color-mix(in srgb, var(--ink) 72%, var(--muted)); }
.cal-event-title { display: block; flex-shrink: 0; max-width: 100%; overflow: hidden; overflow-wrap: anywhere; font-size: 11px; line-height: 1.4; font-weight: 650; }
.cal-event-project { display: block; flex-shrink: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; color: color-mix(in srgb, var(--ink) 56%, var(--muted)); }
.cal-event-grip,
.cal-event-resize {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: color-mix(in srgb, var(--cal-color, var(--green)) 75%, var(--ink));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.cal-event-grip { top: 0; right: 0; width: 23px; height: 23px; border-radius: 0 6px 0 5px; cursor: grab; opacity: .7; }
.cal-event-grip .icon { width: 12px; height: 12px; }
.cal-event-grip:hover,
.cal-event-grip:focus-visible { background: color-mix(in srgb, var(--cal-color, var(--green)) 13%, transparent); opacity: 1; }
.cal-event-grip:active { cursor: grabbing; }
.cal-event-resize { inset: auto 0 0; width: 100%; height: 8px; cursor: ns-resize; }
.cal-event-resize::after { content: ""; width: 22px; max-width: 45%; height: 2px; border-radius: 2px; background: currentColor; opacity: .42; }
.cal-event-resize:hover::after,
.cal-event-resize:focus-visible::after { opacity: 1; }
.cal-event-grip:focus-visible,
.cal-event-resize:focus-visible { outline-offset: -2px; }
.cal-event.is-short .cal-event-open { justify-content: flex-start; gap: 0; padding: 2px 24px 4px 6px; }
.cal-event.is-short .cal-event-time,
.cal-event.is-short .cal-event-project { display: none; }
.cal-event.is-short .cal-event-title { width: 100%; font-size: 10px; line-height: 15px; text-overflow: ellipsis; white-space: nowrap; }
.cal-event.is-short .cal-event-grip { height: 19px; }
.cal-event.is-short .cal-event-resize { height: 5px; }
.cal-event.is-done { opacity: .66; }
.cal-event.is-done .cal-event-title { text-decoration: line-through; }
/* A completion is a compact point marker, with no planned-duration handles. */
.cal-event.is-completion { opacity: 1; border: 0; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--cal-color, var(--green)) 32%, var(--line)); }
.cal-completion-point { position: absolute; top: calc(var(--cal-hour) * var(--cal-point-offset, 0)); left: 0; right: 0; height: 2px; transform: translateY(-50%); background: var(--cal-color, var(--green)); pointer-events: none; }
.cal-event.is-completion .cal-event-open { gap: 1px; padding: 4px 6px; }
.cal-event.is-completion .cal-event-time { color: var(--green); font-weight: 650; }
.cal-event.is-completion .cal-event-title { width: 100%; font-size: 10px; line-height: 14px; text-overflow: ellipsis; white-space: nowrap; }
.cal-event.cal-is-dragging { opacity: .3; }
.cal-event.cal-drag-preview { z-index: 30; pointer-events: none; border-style: dashed; border-left-style: solid; box-shadow: 0 6px 20px #20342024; opacity: .92; }
.cal-event.cal-is-saving { opacity: .6; }
.cal-event.cal-is-saving .cal-event-open,
.cal-event.cal-is-saving .cal-event-grip,
.cal-event.cal-is-saving .cal-event-resize { cursor: progress; }
.cal-now-line { position: absolute; left: 0; right: 0; z-index: 6; height: 2px; background: #b27a53; pointer-events: none; }
.cal-now-line::before { content: ""; position: absolute; top: -3px; left: -4px; width: 8px; height: 8px; border-radius: 50%; background: #b27a53; }

.cal-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 20px; padding: 14px 22px; color: var(--muted); font-size: 10px; line-height: 1.6; }
.cal-help { display: flex; align-items: center; gap: 6px; }
.cal-help .icon { width: 13px; height: 13px; flex-shrink: 0; }
.cal-zone { margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cal-dst-note { flex-basis: 100%; color: var(--green); font-size: 10px; }
.cal-status { margin: 0 22px 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--sage); color: var(--ink); font-size: 11px; line-height: 1.6; }
.cal-status:empty { display: none; }
.cal-status.is-error { background: #fcf2ef; border-color: #eacfc6; color: #9d5045; }
.cal-drag-tooltip { position: fixed; z-index: 1000; max-width: min(300px, calc(100vw - 24px)); padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--ink); box-shadow: 0 5px 18px #20342020; color: var(--panel); font: 11px/1.5 var(--font, sans-serif); font-variant-numeric: tabular-nums; pointer-events: none; }
.cal-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

body.dark .cal-calendar { box-shadow: none; }
body.dark .cal-add,
body.dark .cal-month-cell.is-today .cal-date-button,
body.dark .cal-day-heading.is-today > span { color: #17241d; }
body.dark .cal-event { background: color-mix(in srgb, var(--cal-color, var(--green)) 19%, var(--panel)); }
body.dark .cal-event-grip,
body.dark .cal-event-resize { color: var(--ink); }
body.dark .cal-status.is-error { background: #442e28; border-color: #70483c; color: #edb6a8; }
body.dark .cal-now-line,
body.dark .cal-now-line::before { background: #d8a276; }

@media (max-width: 1100px) {
  .cal-toolbar { flex-wrap: wrap; gap: 17px; }
  .cal-toolbar-actions { margin-left: auto; }
}

@media (max-width: 760px) {
  .cal-calendar { border-radius: 12px; }
  .cal-toolbar { align-items: stretch; padding: 17px 14px; gap: 16px; }
  .cal-toolbar-main { width: 100%; gap: 12px; }
  .cal-heading h2 { font-size: 17px; letter-spacing: -.4px; }
  .cal-heading p { font-size: 10px; }
  .cal-nav button { width: 33px; height: 33px; }
  .cal-toolbar-actions { width: 100%; flex-wrap: wrap; gap: 8px; margin-left: 0; }
  .cal-view-switch { margin-left: auto; }
  .cal-view-switch button { min-height: 34px; padding-inline: 10px; }
  .cal-add { padding-inline: 11px; }
  .cal-month-weekdays { padding-block: 10px; font-size: 9px; letter-spacing: 0; }
  .cal-month-cell { min-height: 104px; padding: 5px 3px 8px; }
  .cal-month-cell-head { gap: 0; margin-bottom: 6px; }
  .cal-date-button { width: 24px; height: 26px; border-radius: 7px; font-size: 10px; }
  .cal-cell-add { width: 16px; height: 26px; }
  .cal-cell-add .icon { width: 11px; height: 11px; }
  .cal-month-events { gap: 3px; }
  .cal-month-task { gap: 3px; min-height: 23px; padding: 4px 3px; border-radius: 4px; font-size: 9px; }
  .cal-task-dot { flex-basis: 3px; width: 3px; height: 3px; }
  .cal-month-time { display: none; }
  .cal-month-task.is-completion { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .cal-month-task.is-completion .cal-task-dot { display: none; }
  .cal-month-task.is-completion .cal-month-time,
  .cal-month-task.is-completion .cal-month-title { grid-column: 1; }
  .cal-month-task.is-completion .cal-month-time { display: block; font-size: 8px; overflow-wrap: anywhere; }
  .cal-more { padding: 4px 2px; font-size: 9px; }
  .cal-timeline-scroller { max-height: 640px; }
  .cal-timeline[data-cal-columns="7"] { min-width: max(850px, var(--cal-min-width, 850px)); }
  .cal-timeline[data-cal-columns="1"] { min-width: max(280px, var(--cal-min-width, 280px)); }
  .cal-footer { align-items: flex-start; gap: 7px 12px; padding: 12px 14px; font-size: 9px; }
  .cal-zone { margin-left: 0; }
  .cal-status { margin-inline: 14px; }
}

@media (max-width: 380px) {
  .cal-toolbar-actions { justify-content: space-between; }
  .cal-view-switch { order: 3; justify-content: stretch; width: 100%; margin-left: 0; }
  .cal-view-switch button { flex: 1; }
  .cal-month-cell { padding-inline: 2px; }
  .cal-date-button { width: 21px; }
  .cal-cell-add { width: 14px; }
}
