/* =========================================================================
   Almo v2 — Calendar
   ========================================================================= */

.calendar { display: flex; flex-direction: column; min-height: 0; overflow-x: clip; } /* the swiped page slides past the edge */
.cal-nav { display: inline-flex; align-items: center; gap: 2px; }
/* Title, view switcher and filters stay put while the page scrolls (desktop;
   on narrow screens the top bar already is the fixed chrome). */
@media (min-width: 901px) {
  .cal-top {
    position: sticky; top: calc(var(--sp-3) - var(--sp-8)); z-index: var(--z-nav, 10);
    margin: calc(-1 * var(--sp-8)) calc(-1 * var(--sp-8)) 0; /* span the content padding so the bar is full width */
    padding: var(--sp-8) var(--sp-8) var(--sp-4);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
  }
  .cal-top .cal-filterbar { margin-bottom: 0; }
}
/* Search + person filter chips (like the Tasks screen). */
.cal-filterbar { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; margin-bottom: var(--sp-5); }
.cal-filterbar .input-group { min-width: 220px; }
.cal-people { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
@media (max-width: 720px) {
  .cal-filterbar .input-group { width: 100%; min-width: 0; }
}
.cal-body { position: relative; transition: opacity var(--dur); touch-action: pan-y; } /* horizontal swipes change week/month (useSwipe) */
.cal-body.is-loading { opacity: 0.55; }

/* ---- Event pill (people-combination hue via light-dark()) ------------ */
.ev {
  --event-h: 232;
  display: flex; align-items: center; gap: 5px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-left: 3px solid light-dark(hsl(var(--event-h) 55% 48%), hsl(var(--event-h) 55% 58%));
  background: light-dark(hsl(var(--event-h) 72% 95%), hsl(var(--event-h) 38% 20%));
  color: light-dark(hsl(var(--event-h) 48% 26%), hsl(var(--event-h) 72% 84%));
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  line-height: 1.25;
  transition: transform var(--dur-fast), box-shadow var(--dur-fast), filter var(--dur-fast);
}
@media (hover: hover) { .ev:hover { filter: brightness(0.97); box-shadow: var(--shadow-sm); } }
.ev:active { transform: scale(0.98); }
.ev[draggable="true"] { cursor: grab; }
.ev__time { font-variant-numeric: tabular-nums; font-size: var(--text-xs); opacity: 0.85; flex-shrink: 0; }
.ev__icon { opacity: 0.8; flex-shrink: 0; }
.ev__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ev--neutral {
  background: var(--surface-2); color: var(--text-muted);
  border-left-color: var(--border-strong);
}
.ev--ical { border-left-style: dashed; }
.ev--task { border-left-style: solid; }
.ev--task .ev__title { font-weight: var(--fw-regular); }
.ev--compact { padding: 2px 6px; font-size: var(--text-xs); border-radius: 5px; }
.ev--compact .ev__time { display: none; }
/* Block layout (week view): time above a full-width, wrapping title. */
.ev--block { flex-direction: column; align-items: stretch; gap: 2px; padding: 5px 8px; }
.ev__head { display: flex; flex-wrap: wrap; align-items: center; gap: 1px 6px; min-width: 0; }
.ev__head:empty { display: none; }
/* All pills (week, month, list) are one calm neutral colour; the person dots
   carry who it is for. */
.ev, .ev--neutral {
  background: var(--surface-2); color: var(--text);
  border-left: 1px solid transparent; /* no coloured stripe */
}
.ev--ical, .ev--task { border-left-style: solid; }
.ev__time { opacity: 1; font-weight: var(--fw-semibold); color: var(--text-muted); }
.ev--block .ev__title {
  white-space: normal; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  line-height: 1.25; font-weight: var(--fw-semibold);
  hyphens: auto; overflow-wrap: break-word; /* long words break with a proper "-" */
}
.ev--task.ev--block .ev__title { font-weight: var(--fw-regular); }
/* One dot per person on the event, in that person's own hue. */
.ev__people { display: inline-flex; align-items: center; gap: 3px; flex-shrink: 0; margin-top: 2px; }
/* Month cells are narrow: keep the title readable, show only the home/work marker. */
.ev--compact .ev__people { display: none; }
.ev__more { font-size: var(--text-2xs); font-weight: var(--fw-semibold); line-height: 1; }
.ev__dot, .chip__dot--person {
  --event-h: var(--dot-h, 232);
  width: 7px; height: 7px; border-radius: 999px; flex-shrink: 0;
  background: light-dark(hsl(var(--event-h) 60% 52%), hsl(var(--event-h) 60% 62%));
}
.chip__dot--person { width: 8px; height: 8px; }
.cat-mark { display: inline-flex; align-items: center; flex-shrink: 0; color: var(--cat); }
/* Dots + category marker share one tail, pinned to the pill's right edge. */
.ev__foot { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.ev__foot:empty { display: none; }
.ev__foot--inline { margin-left: auto; padding-left: 4px; }
.ev__foot--inline .ev__people { margin-top: 0; }
.ev--block .ev__foot { justify-content: space-between; margin-top: 2px; }
.ev--block .ev__foot .ev__people { margin-top: 0; }
.ev--block .ev__foot .cat-mark { margin-left: auto; }
/* Today's running event is highlighted, finished ones recede (all views). */
.ev.is-past { opacity: 0.55; }
.ev.is-now { background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
/* Red "now" line between done and upcoming events (week / month / list). */
.now-line { display: flex; align-items: center; gap: 6px; margin: 1px 0; color: var(--danger, #e5484d); font-size: var(--text-xs); font-weight: var(--fw-semibold); flex-shrink: 0; }
.now-line::after { content: ""; flex: 1; border-top: 2px solid currentColor; }
.ev--block .ev__icon { vertical-align: -1px; margin-right: 3px; }

/* ---- Week view ---- */
.week { overflow-x: auto; padding-bottom: var(--sp-2); }
.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  gap: var(--sp-2);
}
.week-col, .week-allday__cell { scroll-margin-top: 76px; }
.week-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 120px;
  display: flex; flex-direction: column;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.week-col.is-today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.week-col.is-today .week-col__head { background: var(--primary-soft); border-radius: calc(var(--radius-md) - 1px) calc(var(--radius-md) - 1px) 0 0; }
/* Days already gone recede a little so "what is left this week" reads at a glance. */
.week-col.is-past .week-col__body, .week-allday__cell.is-past > * { opacity: 0.8; transition: opacity var(--dur-fast); }
@media (hover: hover) { .week-col.is-past:hover .week-col__body, .week-allday__cell.is-past:hover > * { opacity: 1; } }
.week-col.is-over { background: var(--primary-soft); border-color: var(--primary); border-style: dashed; }
.week-col__head {
  display: flex; align-items: center; gap: 6px;
  padding: 0 var(--sp-3);
  height: 48px; /* fixed, so today's date circle never makes its header taller */
  border-bottom: 1px solid var(--border);
}
/* Weekday and date sit together on the left so they read as one label. */
.week-col__head.is-link { cursor: pointer; }
.week-col__dow { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: var(--fw-semibold); }
.week-col__num { font-weight: var(--fw-bold); font-size: var(--text-lg); line-height: 1; }
.week-col__month { display: none; font-size: var(--text-sm); color: var(--text-muted); }
.week-col__num.is-today {
  background: var(--primary); color: #fff;
  width: 28px; height: 28px; border-radius: 999px;
  display: grid; place-items: center; font-size: var(--text-base);
}
.week-col__body { display: flex; flex-direction: column; gap: 6px; padding: var(--sp-2); flex: 1; }
.week-col__empty { font-size: var(--text-xs); color: var(--text-subtle); padding: 2px 4px; }
.week-col__divider { height: 1px; background: var(--border); margin: 3px 1px; }
/* The per-column untimed block is only used in the stacked (mobile) layout;
   on wide screens untimed events live in the shared all-day row below. */
.week-col__untimed { display: none; }

/* ---- All-day row (untimed events lined up across the days) ---- */
.week-allday {
  border-top: 1px solid var(--border);
  margin-top: var(--sp-4);
  padding-top: var(--sp-3);
}
.week-allday__head {
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: var(--fw-semibold);
  margin: 0 2px var(--sp-2);
}
.week-allday__row {
  display: grid;
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  gap: var(--sp-2);
  align-items: start;
}
.week-allday__cell {
  display: flex; flex-direction: column; gap: 5px;
  min-width: 0; min-height: 48px; padding: var(--sp-2);
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.week-allday__cell.is-over { background: var(--primary-soft); border-color: var(--primary); border-style: dashed; }
/* Days with nothing untimed stay as quiet placeholders (the row keeps its
   alignment and every cell remains a drop target); they only show an outline
   while an activity is being dragged. */
.week-allday__cell.is-empty { background: transparent; border-color: transparent; }
.week.is-dragging .week-allday__cell.is-empty { border: 1px dashed var(--border-strong); }
.week.is-dragging .week-allday__cell.is-over { background: var(--primary-soft); border-color: var(--primary); }

/* ---- Month view ---- */
.month { display: flex; flex-direction: column; }
.month__dow {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 1px; /* match the grid's column gaps so labels sit over their columns */
  padding: 0 1px var(--sp-2); /* match the grid's 1px outer border */
}
.month__dow span { text-align: center; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-subtle); font-weight: var(--fw-semibold); }
.month__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(104px, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.month-cell {
  background: var(--surface);
  padding: 5px;
  display: flex; flex-direction: column; gap: 3px;
  min-height: 0;
  min-width: 0; /* let columns shrink evenly — long titles must not widen a day */
  transition: background var(--dur-fast);
}
.month-cell.is-outside { background: var(--surface-2); }
.month-cell.is-outside .month-cell__num { color: var(--text-subtle); }
.month-cell.is-over { background: var(--primary-soft); box-shadow: inset 0 0 0 2px var(--primary); }
.month-cell__num {
  align-self: flex-start;
  border: none; background: transparent;
  font-weight: var(--fw-semibold); font-size: var(--text-sm);
  color: var(--text); width: 24px; height: 24px; border-radius: 999px;
}
@media (hover: hover) { .month-cell__num:hover { background: var(--surface-3); } }
.month-cell__num.is-today { background: var(--primary); color: #fff; }
.month-cell__events { display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow: hidden; }
.month-cell__more { border: none; background: transparent; color: var(--text-muted); font-size: var(--text-xs); font-weight: var(--fw-semibold); text-align: left; padding: 1px 6px; }
@media (hover: hover) { .month-cell__more:hover { color: var(--primary); } }

/* ---- Agenda / list ---- */
.agenda { display: flex; flex-direction: column; gap: var(--sp-5); }
.agenda-day { display: grid; grid-template-columns: 68px 1fr; gap: var(--sp-4); align-items: start; }
.agenda-day__head { text-align: center; }
.agenda-day__num { display: block; font-size: var(--text-2xl); font-weight: var(--fw-bold); line-height: 1; }
.agenda-day__weekday { display: block; font-size: var(--text-xs); color: var(--text-muted); text-transform: capitalize; margin-top: 3px; font-weight: var(--fw-medium); }
.agenda-day__month { display: block; font-size: var(--text-2xs); color: var(--text-subtle); text-transform: capitalize; }
.agenda-day__head.is-today .agenda-day__num,
.agenda-day__head.is-today .agenda-day__month { color: var(--primary); }
.agenda-day__events { display: flex; flex-direction: column; gap: var(--sp-2); }

/* ---- Event detail modal ---- */
.event-detail { display: flex; flex-direction: column; gap: var(--sp-5); }
.event-detail__title { display: flex; align-items: center; gap: var(--sp-3); font-size: var(--text-lg); font-weight: var(--fw-bold); }
.event-detail__swatch {
  width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0;
  --event-h: 232;
  background: light-dark(hsl(var(--event-h) 60% 55%), hsl(var(--event-h) 60% 60%));
}
.event-detail__meta { display: flex; flex-direction: column; gap: var(--sp-2); }
.event-detail__row { display: flex; align-items: center; gap: var(--sp-2); color: var(--text-muted); font-size: var(--text-base); }
.event-detail__row .icon { color: var(--text-subtle); }
.event-detail__action { display: flex; flex-direction: column; gap: var(--sp-2); }
.event-detail__action .row .input { flex: 1; }

@media (max-width: 720px) {
  .agenda-day { grid-template-columns: 56px 1fr; gap: var(--sp-3); }
  .month-cell { padding: 3px; }
  .month-cell__num { font-size: var(--text-xs); width: 20px; height: 20px; }
  .page-head__actions { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  /* Week view stacks into a vertical agenda of days on narrow screens. Here the
     shared all-day row makes no sense, so each day shows its own untimed events
     under its timed ones instead. */
  .week { overflow-x: visible; }
  .week-grid { grid-template-columns: 1fr; }
  .week-col { min-height: auto; }
  .week-col__body.is-empty { display: none; }
  .week-col__head { border-bottom: none; }
  .week-col__body:not(.is-empty) { border-top: 1px solid var(--border); }
  .week-col.is-today .week-col__head { border-radius: calc(var(--radius-md) - 1px) calc(var(--radius-md) - 1px) 0 0; }
  .week-col__month { display: inline; }
  .week-col__untimed { display: flex; flex-direction: column; gap: 5px; }
  .week-allday { display: none; }
  .ev--block { flex-direction: row; align-items: center; gap: var(--sp-2); }
  /* head wrapper dissolves so time, title and dots share one row */
  .ev--block .ev__head { display: contents; }
  .ev--block .ev__people { margin: 0 0 0 auto; }
  .ev--compact .ev__people { display: none; }
  .ev--block .ev__title { -webkit-line-clamp: 1; }
}

/* ---- Day view (compact overview, no scrolling on a landscape tablet) ---- */
.day2 { display: grid; gap: var(--sp-4); align-items: start; }
.day2-main, .day2-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.day2-label {
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: var(--fw-semibold); margin: 0 2px 2px;
  display: flex; align-items: center; gap: 6px;
}
.day2-label span { background: var(--surface-2); border-radius: 999px; padding: 0 7px; font-size: 11px; }
@media (min-width: 900px) {
  .day2 { grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); }
  .day2.is-single { grid-template-columns: minmax(0, 1fr); }
}
.day2-none, .day2-empty { color: var(--text-subtle); font-size: var(--text-sm); padding: var(--sp-2); }
.day2-empty { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-6) var(--sp-2); }
.day2-untimed { display: flex; flex-direction: column; gap: 6px; }

/* One row: time | title + detail | who. */
.drow {
  display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; align-items: center; gap: var(--sp-3);
  width: 100%; padding: 7px var(--sp-3); text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
@media (hover: hover) { .drow:hover { background: var(--surface-2); } }
.drow__time { display: flex; flex-direction: column; line-height: 1.15; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.drow__time b { font-size: var(--text-base); color: var(--text); font-weight: var(--fw-bold); }
.drow__time i { font-style: normal; font-size: var(--text-xs); }
.drow__main { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.drow__title { font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drow__parent { font-weight: var(--fw-regular); color: var(--text-muted); }
.drow__info { color: var(--text-muted); font-size: var(--text-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drow__meta { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 4px 8px; max-width: 280px; }
.drow__tag { display: inline-flex; align-items: center; gap: 3px; font-size: var(--text-xs); color: var(--text-muted); }
.drow__who { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); color: var(--text); }
.drow.is-past { opacity: 0.55; }
.drow.is-now { background: var(--primary-soft); border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
.drow.is-done .drow__title { text-decoration: line-through; color: var(--text-muted); }
/* Narrow screens: time on top of the title, who below. */
@media (max-width: 720px) {
  .drow { grid-template-columns: 46px minmax(0, 1fr); }
  .drow__meta { grid-column: 2; justify-content: flex-start; max-width: none; }
  .drow__title { white-space: normal; }
}

/* "now" line between done and upcoming rows. */
.day2-now { display: flex; align-items: center; gap: 8px; margin: 2px 0 6px; color: var(--danger, #e5484d); font-size: var(--text-xs); font-weight: var(--fw-semibold); }
.day2-now::after { content: ""; flex: 1; border-top: 2px solid currentColor; }

/* Rows in the narrow right column: icon | title, with the tags/people underneath. */
.drow--side { grid-template-columns: 20px minmax(0, 1fr); align-items: start; gap: 2px var(--sp-2); }
.drow--side .drow__time { grid-row: 1 / span 2; padding-top: 2px; }
.drow--side .drow__meta { grid-column: 2; justify-content: flex-start; max-width: none; }
.drow--side .drow__title { white-space: normal; }
@media (hover: hover) { .drow--side:hover { background: var(--surface-2); } }
/* Tags on a row: "Nu" / "Næste · om …" / overdue. */
.drow__badge { font-size: 11px; font-weight: var(--fw-bold); border-radius: 999px; padding: 1px 8px; background: var(--surface-2); color: var(--text-muted); white-space: nowrap; }
.drow__badge.is-now { background: var(--primary); color: #fff; }
.drow__badge.is-next { background: var(--primary-soft); color: var(--primary); }
.drow__badge.is-late { background: color-mix(in srgb, var(--danger, #e5484d) 14%, transparent); color: var(--danger, #e5484d); }
.day2-side { gap: 6px; }
.day2-side .day2-label:not(:first-child) { margin-top: var(--sp-2); }
