/** Calendar grids, activity chips, and the sticker layer. */

.cal-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.cal-period {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--letter-display);
  min-width: 11ch;
}

/* ---------------- month grid ---------------- */

.cal-month {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: var(--border-width) var(--border-style) var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  flex: 1;
  min-height: 560px;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--surface-2);
  border-bottom: var(--border-width) var(--border-style) var(--border);
}
.cal-weekday {
  padding: var(--sp-2);
  text-align: center;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(104px, 1fr);
  flex: 1;
  /* Grid lines are drawn by cell borders; this background fills the gaps so
     no seam shows through at fractional pixel widths. */
  background: var(--cal-grid-line);
  gap: 1px;
}

.cal-day {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-1);
  background: var(--cal-day-bg);
  min-width: 0;
  transition: background-color var(--dur-fast) var(--ease);
}
.cal-day:hover { background: var(--surface-2); }
.cal-day.is-outside { background: var(--cal-day-outside); }
.cal-day.is-outside .cal-daynum { color: var(--text-subtle); }
.cal-day.is-weekend:not(.is-outside) { background: var(--cal-weekend-bg); }
.cal-day.is-selected { box-shadow: inset 0 0 0 2px var(--accent); }

.cal-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  min-height: 22px;
}

.cal-daynum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
}
.cal-day.is-today .cal-daynum {
  background: var(--cal-today-ring);
  color: var(--accent-contrast);
  font-weight: var(--fw-bold);
}

/* The one-click add button. Hidden until hover on pointer devices, but always
   visible on touch, where there is no hover to reveal it. */
.cal-add {
  width: 20px; height: 20px;
  flex: none; /* the day-head is a flex row and would otherwise squash it */
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-subtle);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.cal-day:hover .cal-add,
.cal-add:focus-visible { opacity: 1; }
.cal-add:hover { background: var(--accent); color: var(--accent-contrast); }

/* Touch devices have no hover to reveal the button, so it stays visible.
   The width rule is a belt-and-braces backup: hover media queries are
   unreliable on hybrid and emulated devices, and an invisible "add" button
   would make the one-tap flow unusable exactly where it matters most. */
@media (hover: none), (pointer: coarse), (max-width: 700px) {
  .cal-add {
    opacity: 0.6;
    /* A 20px target is too small to hit reliably with a thumb. The cell itself
       stays tappable as a fallback (it opens the day, which has its own add
       button), but the + should be hittable on its own. */
    width: 28px;
    height: 28px;
  }
}

.cal-day-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  flex: 1;
  position: relative;
  z-index: 2; /* above the sticker layer */
}

.cal-more {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.cal-more:hover { background: var(--surface-3); color: var(--text); }

/* ---------------- holidays ---------------- */

.cal-day.is-holiday .cal-daynum { color: var(--cal-holiday); }
.cal-holiday-label {
  font-size: var(--fs-xs);
  color: var(--cal-holiday);
  background: var(--cal-holiday-soft);
  border-radius: var(--radius-sm);
  padding: 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: none;
}

/* ---------------- activity chips ---------------- */

.act {
  --act-colour: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 5px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  line-height: 1.35;
  text-align: left;
  width: 100%;
  min-width: 0;
  /* Colour-mix keeps the chip readable in both modes from a single stored
     colour: a light tint on white, a dark tint on black. */
  background: color-mix(in srgb, var(--act-colour) 16%, var(--surface));
  color: var(--text);
  border-left: 3px solid var(--act-colour);
  transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
:root[data-mode="dark"] .act {
  background: color-mix(in srgb, var(--act-colour) 26%, var(--surface));
}
.act:hover {
  background: color-mix(in srgb, var(--act-colour) 32%, var(--surface));
}
.act:active { transform: scale(0.985); }

.act-solid {
  background: var(--act-colour);
  color: #fff;
  border-left-color: color-mix(in srgb, var(--act-colour) 70%, #000);
}

.act-time { font-variant-numeric: tabular-nums; opacity: 0.8; flex: none; }
.act-icon { flex: none; line-height: 1; }
.act-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }

/* Multi-day continuation: square off the joined edges so a trip reads as one
   continuous bar rather than separate blocks per day. */
.act.is-continuation {
  border-left-width: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  padding-left: 8px;
}
.act.is-continuation:not(.is-end) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.act:not(.is-end):not(.is-continuation) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* "I am in charge of this" - the filter highlight. A ring plus a dot, never
   colour alone, so it survives colour-blindness and greyscale printing. */
.act.is-incharge {
  box-shadow: 0 0 0 2px var(--cal-incharge-ring);
  font-weight: var(--fw-semibold);
}
.act.is-incharge::after {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cal-incharge-ring);
  flex: none;
}

/* Dimmed rather than hidden when another filter is focused. */
.act.is-dimmed { opacity: 0.3; }

.act-cancelled { text-decoration: line-through; opacity: 0.55; }

/* ---------------- stickers ---------------- */

.sticker-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}
.sticker {
  position: absolute;
  font-size: 1.35rem;
  line-height: 1;
  transform-origin: center;
  user-select: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
  transition: transform var(--dur-fast) var(--ease);
}
.sticker-interactive { pointer-events: auto; cursor: grab; }
.sticker-interactive:hover { transform: scale(1.18) rotate(0deg) !important; z-index: 3; }
.sticker-interactive:active { cursor: grabbing; }

.app.is-placing-sticker .cal-day { cursor: crosshair; }
.app.is-placing-sticker .cal-day:hover { background: var(--accent-soft); }

/* ---------------- week & day views ---------------- */

.cal-week {
  display: grid;
  grid-template-columns: 56px repeat(var(--day-count, 7), minmax(0, 1fr));
  background: var(--surface);
  border: var(--border-width) var(--border-style) var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.cal-week-head {
  display: contents;
}
.cal-week-corner,
.cal-week-daycol {
  padding: var(--sp-2);
  background: var(--surface-2);
  border-bottom: var(--border-width) var(--border-style) var(--border);
  text-align: center;
}
.cal-week-daycol { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.cal-week-dayname { font-size: var(--fs-xs); text-transform: uppercase; color: var(--text-subtle); }
.cal-week-daynum {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
}
.cal-week-daycol.is-today .cal-week-daynum { background: var(--accent); color: var(--accent-contrast); }

/* All-day row sits above the scrolling hour grid, as in every calendar app. */
.cal-allday {
  display: contents;
}
.cal-allday-label,
.cal-allday-cell {
  padding: 3px;
  background: var(--surface);
  border-bottom: var(--border-width) var(--border-style) var(--border);
  min-height: 30px;
}
.cal-allday-label {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  text-align: right;
  padding-right: var(--sp-2);
}
.cal-allday-cell { display: flex; flex-direction: column; gap: 2px; border-left: var(--border-width) var(--border-style) var(--border); }

.cal-hours {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 56px repeat(var(--day-count, 7), minmax(0, 1fr));
  max-height: 62vh;
  overflow-y: auto;
  position: relative;
}

.cal-hour-labels { display: flex; flex-direction: column; }
.cal-hour-label {
  height: var(--hour-h, 48px);
  padding-right: var(--sp-2);
  text-align: right;
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
  transform: translateY(-0.5em);
}

.cal-daycol {
  position: relative;
  border-left: var(--border-width) var(--border-style) var(--border);
  /* Hour lines drawn as a background gradient: one element instead of 24. */
  background-image: repeating-linear-gradient(
    to bottom,
    var(--border) 0 1px,
    transparent 1px var(--hour-h, 48px)
  );
}
.cal-daycol:hover { background-color: var(--surface-2); }

.cal-timed {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: var(--radius-sm);
  padding: 2px 5px;
  font-size: var(--fs-xs);
  overflow: hidden;
  background: color-mix(in srgb, var(--act-colour, var(--accent)) 20%, var(--surface));
  border-left: 3px solid var(--act-colour, var(--accent));
  text-align: left;
  min-height: 18px;
}
:root[data-mode="dark"] .cal-timed {
  background: color-mix(in srgb, var(--act-colour, var(--accent)) 30%, var(--surface));
}

/* Current-time line, drawn only on today's column. */
.cal-now {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: var(--danger);
  z-index: 4;
  pointer-events: none;
}
.cal-now::before {
  content: '';
  position: absolute;
  left: -4px; top: -3px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

/* ---------------- agenda (list) view of a single day ---------------- */

.day-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.day-entry {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: var(--border-width) var(--border-style) var(--border);
  border-left: 4px solid var(--act-colour, var(--accent));
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  width: 100%;
  transition: background-color var(--dur-fast) var(--ease);
}
.day-entry:hover { background: var(--surface-2); }
.day-entry-time {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  min-width: 5.5ch;
  flex: none;
}
.day-entry-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.day-entry-title { font-weight: var(--fw-medium); }
.day-entry-meta { display: flex; gap: var(--sp-3); flex-wrap: wrap; font-size: var(--fs-sm); color: var(--text-muted); }

@media (max-width: 700px) {
  .cal-grid { grid-auto-rows: minmax(78px, 1fr); }
  .cal-month { min-height: 460px; }
  .act-time { display: none; } /* the title matters more at this width */
  .cal-period { font-size: var(--fs-md); min-width: auto; }
}

/* A clash marker on an activity chip. A glyph rather than a colour change:
   the chip already carries the activity's own colour, and a colour-only signal
   would be invisible to a good share of people. */
.act-clash {
  flex: none;
  font-size: 0.9em;
  line-height: 1;
  color: var(--warning);
}
.act.has-conflict {
  box-shadow: inset 0 0 0 1px var(--warning);
}

.cal-timed.has-conflict { box-shadow: inset 0 0 0 1px var(--warning); }
.day-entry .act-clash { align-self: center; }
