/* Activities calendar (B-052 week, B-053 day and month). Colours only via tokens.css and the page tokens below. */

/* Page tokens live on :root, not .cal-page: popovers (period picker, quick add, +N more) mount on body
   and need them too (BUG-097). Values still come from tokens.css. */
:root {
  --cal-gutter-w: 56px;
  --cal-hour-h: 48px;
  --cal-line: var(--daycal-line);
  --cal-line-half: #f1f1f3;
  --cal-head-h: 40px;
  --cal-allday-min: 40px;
  --cal-event-bg: var(--daycal-block-bg);
  --cal-event-edge: var(--daycal-block-edge);
  --cal-event-text: var(--daycal-block-text);
  --cal-event-hover: #cfe0fa;
  --cal-done-bg: var(--daycal-done-bg);
  --cal-done-text: var(--daycal-done-text);
  --cal-new: var(--daycal-block-new);
  --cal-now: var(--daycal-now);
  --cal-today: var(--blue-bright);
  --cal-check: var(--green);
  --cal-other-day: #fafafb;
  --cal-slot-hover: #f5f8fd;
  --cal-selected: var(--blue-bright);
  --cal-selected-hover: var(--blue);
}

.cal-page {
  display: flex; flex-direction: column; height: 100%; min-height: 0; padding: var(--sp-6) var(--sp-6) 0;
}

/* ---- Toolbar ---- */
.cal-toolbar { display: flex; flex-direction: column; gap: var(--sp-4); flex: none; margin-bottom: var(--sp-4); }
.cal-page .view-btn { border-top: 0; border-right: 0; border-bottom: 0; padding: 0; cursor: pointer; }
.cal-page .view-btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; }
.cal-add { gap: var(--sp-3); padding: 0 var(--sp-5) 0 var(--sp-4); }
.cal-controls { gap: var(--sp-4); flex-wrap: nowrap; }

.cal-segs, .cal-navs {
  display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden;
  box-shadow: var(--shadow-button); background: var(--bg-surface);
}
.cal-seg, .cal-nav {
  height: calc(var(--control-h) - 2px); padding: 0 var(--sp-5); border: 0; border-left: 1px solid var(--border);
  background: var(--bg-surface); color: var(--text); font: inherit; font-weight: var(--fw-semibold); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.cal-seg:first-child, .cal-nav:first-child { border-left: 0; }
.cal-seg:hover, .cal-nav:hover { background: var(--bg-hover); }
.cal-seg:focus-visible, .cal-nav:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; }
.cal-seg.is-active { background: var(--view-active-bg); color: var(--blue); box-shadow: inset 0 0 0 1px var(--view-active-border); }
.cal-nav-prev, .cal-nav-next { width: 32px; padding: 0; }
.cal-nav .ic, .cal-nav .ic svg { width: 14px; height: 14px; }

.cal-range { gap: var(--sp-4); padding: 0 var(--sp-4) 0 var(--sp-5); min-width: 168px; justify-content: space-between; font-weight: var(--fw-semibold); }
.cal-range.is-open { background: var(--bg-hover); }
.cal-caret, .cal-caret svg { width: 8px; height: 8px; }

.cal-owner.select-trigger {
  width: auto; min-width: 120px; max-width: 220px; gap: var(--sp-3); border-color: var(--blue-bright); color: var(--blue);
  font-weight: var(--fw-semibold);
}
.cal-owner.select-trigger:hover { background: var(--bg-info); }
.cal-owner-ic, .cal-owner-ic svg { width: 14px; height: 14px; color: var(--blue); flex: none; }
.cal-owner .select-caret { color: var(--blue); }

.cal-filters { justify-content: flex-start; }

/* ---- Period picker ---- */
.cal-picker { width: 232px; padding: var(--sp-4); }
.cal-picker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-4); }
.cal-picker-title { font-weight: var(--fw-semibold); color: var(--blue); }
.cal-picker-nav { width: 32px; height: 32px; border: 1px solid var(--border); border-radius: var(--r-md); }
.cal-picker-nav:first-child { border-left: 1px solid var(--border); }
.cal-picker-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--sp-1); }
.cal-picker-wd { text-align: center; font-size: var(--fs-xs); color: var(--text-2); line-height: 24px; border-bottom: 1px solid var(--border); margin-bottom: var(--sp-2); }
.cal-picker-day {
  height: 28px; border: 0; border-radius: var(--r-sm); background: none; color: var(--text); font: inherit;
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); cursor: pointer;
}
.cal-picker-day:hover { background: var(--bg-hover); }
.cal-picker-day.is-other { color: var(--text-muted); font-weight: var(--fw-regular); }
.cal-picker-day.is-today { background: var(--bg-hover); color: var(--text-2); }
.cal-picker-day.is-range { background: var(--bg-selected); }
/* The view's first day: solid blue, white 14px semibold (BUG-097). */
.cal-picker-num { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 4px; }
.cal-picker-day.is-start, .cal-picker-day.is-start .cal-picker-num {
  background: var(--cal-selected); color: var(--text-inverse); border-radius: 4px;
  font-size: var(--fs-md); font-weight: var(--fw-semibold);
}
.cal-picker-day.is-start:hover, .cal-picker-day.is-start:hover .cal-picker-num { background: var(--cal-selected-hover); }
.cal-picker-day:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }

/* ---- Week and day grid ---- */
.cal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; margin: 0 calc(-1 * var(--sp-6)); border-top: 1px solid var(--cal-line); background: var(--bg-surface); }
.cal-week { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cal-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; position: relative; }
.cal-head, .cal-allday-row, .cal-grid {
  display: grid; grid-template-columns: var(--cal-gutter-w) repeat(var(--cal-days), minmax(0, 1fr));
}
.cal-head {
  position: sticky; top: 0; z-index: 4; height: var(--cal-head-h); background: var(--bg-surface);
  border-bottom: 1px solid var(--cal-line);
}
.cal-gutter { border-right: 1px solid var(--cal-line); }
.cal-month-abbr { display: flex; align-items: center; justify-content: center; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-2); }
.cal-dayhead {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-3); border-right: 1px solid var(--cal-line);
  font-weight: var(--fw-semibold); color: var(--text); white-space: nowrap;
}
.cal-dayhead-num { min-width: 22px; height: 22px; padding: 0 var(--sp-2); display: inline-grid; place-items: center; border-radius: var(--r-pill); }
.cal-dayhead.is-today .cal-dayhead-num { background: var(--cal-today); color: var(--text-inverse); }
.cal-allday-row {
  position: sticky; top: var(--cal-head-h); z-index: 4; min-height: var(--cal-allday-min); background: var(--bg-surface);
  border-bottom: 1px solid var(--cal-line);
}
.cal-allday { display: flex; flex-direction: column; gap: var(--sp-1); padding: var(--sp-2) var(--sp-3); border-right: 1px solid var(--cal-line); min-width: 0; }

.cal-grid { position: relative; }
.cal-hours { position: relative; }
.cal-hour-label { position: relative; height: var(--cal-hour-h); }
.cal-hour-label span {
  position: absolute; top: -8px; right: var(--sp-4); font-size: var(--fs-xs); line-height: 16px; color: var(--text-2);
  white-space: nowrap;
}
.cal-col { position: relative; border-right: 1px solid var(--cal-line); min-width: 0; }
.cal-slot { height: calc(var(--cal-hour-h) / 2); border-top: 1px solid var(--cal-line); cursor: pointer; }
.cal-slot.is-half { border-top-color: var(--cal-line-half); }
.cal-slot:first-child { border-top: 0; }
.cal-slot:hover { background: var(--cal-slot-hover); }
.cal-lane { position: absolute; inset: 0 var(--sp-2) 0 0; pointer-events: none; }
.cal-lane > * { pointer-events: auto; }

/* ---- Events ---- */
.cal-event {
  display: flex; align-items: flex-start; gap: var(--sp-2); padding: var(--sp-1) var(--sp-3) var(--sp-1) var(--sp-4);
  border-radius: var(--r-sm); background: var(--cal-event-bg); color: var(--cal-event-text);
  box-shadow: inset 3px 0 0 var(--cal-event-edge); font-size: var(--fs-sm); line-height: var(--lh-sm);
  font-weight: var(--fw-semibold); cursor: pointer; min-width: 0; user-select: none; touch-action: none;
  transition: background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.cal-event:hover { background: var(--cal-event-hover); }
.cal-event:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.cal-lane .cal-event { position: absolute; overflow: hidden; }
.cal-event.is-short { align-items: center; }
.cal-event-ic, .cal-event-ic svg { width: 14px; height: 14px; flex: none; }
.cal-event.is-short .cal-event-ic { margin-top: 0; }
.cal-event-ic { margin-top: 1px; }
.cal-event-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-event-time { flex: none; font-weight: var(--fw-regular); color: var(--text-2); }
.cal-event-prio, .cal-event-prio svg { width: 14px; height: 14px; flex: none; }
.cal-event-prio.prio-high { color: var(--prio-high); }
.cal-event-prio.prio-medium { color: var(--prio-medium); }
.cal-event-prio.prio-low { color: var(--prio-low); }
.cal-event.is-allday { height: 24px; align-items: center; }
.cal-event.is-done { background: var(--cal-done-bg); color: var(--cal-done-text); box-shadow: inset 3px 0 0 var(--border-strong); }
.cal-event.is-done .cal-event-text { text-decoration: line-through; }
.cal-event.is-dragging { opacity: 0.45; }
.cal-event.is-resizing { z-index: 3; box-shadow: inset 3px 0 0 var(--cal-event-edge), var(--shadow-raised-hover); }
.cal-ghost { z-index: 5; pointer-events: none; background: var(--cal-new); color: var(--text-inverse); box-shadow: var(--shadow-raised-hover); opacity: 0.9; }
.cal-lane .cal-ghost { left: 1px; width: calc(100% - 3px); }
.cal-draft { z-index: 5; background: var(--cal-new); color: var(--text-inverse); box-shadow: var(--shadow-raised); cursor: default; }
.cal-draft:hover { background: var(--cal-new); }
.cal-lane .cal-draft { animation: cal-pop var(--t-med) var(--ease-enter); }
@keyframes cal-pop { from { opacity: 0; transform: scaleY(0.6); transform-origin: top; } to { opacity: 1; transform: none; } }

/* Done circle: empty ring, green check when done */
.cal-done {
  flex: none; width: 16px; height: 16px; margin-left: auto; padding: 0; display: grid; place-items: center;
  border: 1.5px solid var(--border-strong); border-radius: 50%; background: var(--bg-surface); color: var(--text-inverse); cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.cal-done:hover { border-color: var(--cal-check); }
.cal-done.is-done { background: var(--cal-check); border-color: var(--cal-check); }
.cal-done .ic, .cal-done .ic svg { width: 12px; height: 12px; }
.cal-done:disabled { cursor: default; opacity: 0.6; }
.cal-done:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.cal-event-prio + .cal-done { margin-left: 0; }
.cal-event-text + .cal-done { margin-left: 0; }

/* Bottom edge: drag to change the length */
.cal-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; cursor: ns-resize; }
.cal-resize::after {
  content: ""; position: absolute; left: 50%; bottom: 1px; width: 16px; height: 2px; margin-left: -8px;
  border-radius: 1px; background: var(--cal-event-edge); opacity: 0; transition: opacity var(--t-fast) var(--ease);
}
.cal-event:hover .cal-resize::after { opacity: 0.6; }

/* Now-line: red across every day, the time in the gutter */
.cal-now {
  position: absolute; left: var(--cal-gutter-w); right: 0; height: 0; border-top: 1px solid var(--cal-now); z-index: 3; pointer-events: none;
}
.cal-now::before { content: ""; position: absolute; left: -4px; top: -4px; width: 7px; height: 7px; border-radius: 50%; background: var(--cal-now); }
.cal-now-label {
  position: absolute; right: calc(100% + 6px); top: -8px; font-size: var(--fs-xs); line-height: 16px;
  font-weight: var(--fw-semibold); color: var(--cal-now); white-space: nowrap; background: var(--bg-surface);
}

/* ---- Quick add popover ---- */
.cal-quick-pop { padding: 0; }
.cal-quick { width: 304px; }
.cal-quick-main { display: flex; flex-direction: column; gap: var(--sp-5); padding: var(--sp-6) var(--sp-6) var(--sp-5); }
.cal-quick-types { display: inline-flex; align-self: flex-start; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.cal-quick-type {
  width: 33px; height: 32px; display: grid; place-items: center; border: 0; border-left: 1px solid var(--border);
  background: var(--bg-surface); color: var(--text); cursor: pointer; transition: background var(--t-fast) var(--ease);
}
.cal-quick-type:first-child { border-left: 0; }
.cal-quick-type:hover { background: var(--bg-hover); }
.cal-quick-type.is-active { background: var(--column-bg); box-shadow: inset 0 0 0 1px var(--border-strong); }
.cal-quick-type:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; }
.cal-quick-type .ic, .cal-quick-type svg { width: 16px; height: 16px; }
.cal-quick-subject { width: 100%; }
.cal-quick-when { display: flex; align-items: center; gap: var(--sp-1); color: var(--text); }
.cal-quick-arrow, .cal-quick-arrow svg { width: 14px; height: 14px; }
.cal-quick-main .field-error:empty { display: none; }
.cal-quick-foot {
  display: flex; justify-content: flex-end; gap: var(--sp-4); padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border); background: var(--bg-app); border-radius: 0 0 var(--r-md) var(--r-md);
}

/* ---- Month ---- */
.cal-month { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cal-month-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--cal-line); flex: none; }
.cal-month-wd {
  height: 32px; display: flex; align-items: center; justify-content: center; font-weight: var(--fw-semibold);
  color: var(--text-2); border-right: 1px solid var(--cal-line);
}
.cal-month-grid {
  flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(128px, 1fr)); overflow-y: auto;
}
.cal-mday { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; min-height: 0; overflow: hidden; padding: var(--sp-2) var(--sp-3) var(--sp-3);
  border-right: 1px solid var(--cal-line); border-bottom: 1px solid var(--cal-line); }
.cal-mday.is-other { background: var(--cal-other-day); }
.cal-mday.is-other .cal-mday-num { color: var(--text-muted); }
.cal-mday-head { display: flex; justify-content: flex-start; }
.cal-mday-num {
  min-width: 24px; height: 24px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-pill); background: none;
  color: var(--text); font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-semibold); cursor: pointer;
}
.cal-mday-num:hover { background: var(--bg-hover); text-decoration: underline; }
.cal-mday.is-today .cal-mday-num { background: var(--cal-today); color: var(--text-inverse); }
.cal-mday-num:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.cal-mday-list { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.cal-event.is-compact { height: 22px; align-items: center; padding-top: 0; padding-bottom: 0; }
.cal-more {
  align-self: flex-start; height: 20px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-sm); background: none;
  color: var(--text-2); font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-semibold); cursor: pointer;
}
.cal-more:hover { background: var(--bg-hover); color: var(--text); }
.cal-more:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.cal-more-box { width: 260px; padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
.cal-more-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.cal-more-title { font-weight: var(--fw-semibold); }
.cal-more-close {
  display: inline-flex; align-items: center; justify-content: center; flex: none; width: 24px; height: 24px;
  margin: calc(-1 * var(--sp-2)) calc(-1 * var(--sp-2)) calc(-1 * var(--sp-2)) 0; padding: 0; border: 0;
  border-radius: var(--r-sm); background: none; color: var(--text-2); cursor: pointer;
}
.cal-more-close .ic { width: 14px; height: 14px; }
.cal-more-close:hover { background: var(--bg-hover); color: var(--text); }
.cal-more-close:active { background: var(--bg-selected); }
.cal-more-close:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.cal-more-rows { display: flex; flex-direction: column; gap: var(--sp-2); max-height: 320px; overflow-y: auto; }

@media (max-width: 1100px) {
  .cal-page .actlist-type .actlist-chip-label { display: none; }
  .cal-page .actlist-type[data-testid="cal-type-all"] .actlist-chip-label { display: inline; }
  .cal-range { min-width: 0; }
}
