/*
 * Calendar: month grid, agenda, toolbar, filters, day popover, print.
 *
 * Month grid structure: one nested CSS Grid per week row rather than a single
 * 42-cell grid. That is what makes multi-day spanning trivial — a bar is just
 * `grid-column: 3 / span 4` — instead of absolutely positioning over cells and
 * recomputing pixel offsets on resize.
 *
 * Row 1 of each week holds the date numbers; rows 2..n are event lanes.
 * Day backgrounds span every row at z-index 0 so today/weekend/out-of-month
 * tinting needs no second stacking layer.
 */

.cal {
  --cal-lane-h: 22px;
  --cal-daynum-h: 26px;
  --cal-week-min: 108px;
  --cal-gap: 2px;
}

/* ── Toolbar ──────────────────────────────────────────────────────────────── */

.cal-toolbar {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  margin-bottom: var(--spacing-sm);
}

.cal-viewswitch {
  display: inline-flex;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-primary);
}

.cal-viewbtn {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  border-right: 1px solid var(--border-color);
  transition: background 0.12s ease;
}

.cal-viewbtn:last-child { border-right: none; }
.cal-viewbtn:hover { background: var(--bg-secondary); }

.cal-viewbtn.active {
  background: var(--vmdo-teal);
  color: #fff;
}

.cal-nav {
  display: inline-flex;
  gap: 4px;
}

.cal-navbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  font-size: 0.85rem;
  color: var(--text-primary);
  text-decoration: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
}

.cal-navbtn:hover {
  background: var(--bg-secondary);
  border-color: var(--vmdo-teal);
}

.cal-navbtn-today { font-size: 0.75rem; }

.cal-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

.cal-toolbar-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.cal-btn {
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.cal-btn:hover {
  background: var(--bg-secondary);
  border-color: var(--vmdo-teal);
}

/* ── Filters and legend ───────────────────────────────────────────────────── */

.cal-filters {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  flex-wrap: wrap;
  padding: 8px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-sm);
}

.cal-filtergroup {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.cal-filtergroup-right {
  margin-left: auto;
  gap: var(--spacing-sm);
}

.cal-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.cal-chip:hover { border-color: var(--vmdo-teal); }

.cal-chip.active {
  color: var(--text-primary);
  border-color: var(--vmdo-gray-10);
  background: var(--bg-primary);
  font-weight: 600;
}

/* Inactive chips lose their colour so the active set reads at a glance. */
.cal-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  filter: grayscale(1);
  opacity: 0.45;
}

.cal-chip.active .cal-chip-dot {
  filter: none;
  opacity: 1;
}

.cal-select {
  padding: 4px 8px;
  font-size: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  max-width: 180px;
}

.cal-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  margin-bottom: 6px;
}

.cal-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.cal-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.cal-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ── Month grid ───────────────────────────────────────────────────────────── */

.cal-dow-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border: 1px solid var(--border-color);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  overflow: hidden;
  background: var(--bg-secondary);
}

.cal-dow {
  padding: 6px 8px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
}

.cal-dow--weekend { color: var(--vmdo-gray-4); }

.cal-month {
  border: 1px solid var(--border-color);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  overflow: hidden;
  background: var(--bg-primary);
}

.cal-week {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: var(--cal-daynum-h);
  grid-auto-rows: var(--cal-lane-h);
  min-height: var(--cal-week-min);
  border-bottom: 1px solid var(--border-color);
}

.cal-week:last-child { border-bottom: none; }

/* Absolutely positioned, not grid items: a grid item spanning `1 / -1` only
   covers the rows that exist, so in a week with one event the today ring and
   weekend tint would stop a third of the way down the cell. */
.cal-daybg {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--col) * 100% / 7);
  width: calc(100% / 7);
  border-right: 1px solid var(--border-color);
  z-index: 0;
}

.cal-daybg--last { border-right: none; }
.cal-daybg--weekend { background: rgba(185, 186, 186, 0.12); }
.cal-daybg--out { background: rgba(185, 186, 186, 0.06); }

.cal-daybg--today {
  background: rgba(0, 156, 189, 0.06);
  box-shadow: inset 0 0 0 2px var(--vmdo-teal);
}

.cal-daynum {
  grid-row: 1;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 4px 6px 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-primary);
  pointer-events: none;
}

/* Dim the number only. Dimming the whole cell makes the grid look broken. */
.cal-daynum--out { opacity: 0.45; }

.cal-daynum--today span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--vmdo-teal);
  color: #fff;
  font-weight: 700;
}

/* ── Pills ────────────────────────────────────────────────────────────────── */

.cal-pill {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  margin: 1px 3px;
  padding: 0 6px;
  height: calc(var(--cal-lane-h) - 3px);
  border-radius: 3px;
  background: var(--pill-bg);
  color: var(--pill-ink);
  box-shadow: inset 3px 0 0 var(--pill-color);
  font-size: 0.7rem;
  line-height: 1;
  text-decoration: none;
  text-align: left;
  border: none;
  cursor: pointer;
  overflow: hidden;
  transition: filter 0.12s ease;
}

.cal-pill:hover { filter: brightness(0.95); }

.cal-pill-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A single-day point event gets a dot rather than a rail, so a real span
   reads as a span. */
.cal-pill--point {
  box-shadow: none;
  background: transparent;
  padding-left: 2px;
}

.cal-pill--point::before {
  content: '';
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--pill-color);
}

/* Flatten the cut edge so a bar reads as continuing onto the next week row. */
.cal-pill--cont-left {
  margin-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  box-shadow: none;
}

.cal-pill--cont-right {
  margin-right: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.cal-pill--cancelled .cal-pill-label { text-decoration: line-through; }
.cal-pill--cancelled { opacity: 0.6; }
.cal-pill--past { opacity: 0.72; }

.cal-more {
  z-index: 1;
  margin: 1px 3px;
  padding: 0 6px;
  height: calc(var(--cal-lane-h) - 3px);
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  text-align: left;
}

.cal-more:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ── Month-precision strip ────────────────────────────────────────────────── */

/* Project timeline values are month-precision. They get their own band rather
   than being dropped on the 1st, which would assert a day the data lacks. */
.cal-monthstrip {
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-sm);
  padding: 7px 10px;
  margin-bottom: var(--spacing-sm);
  background: var(--bg-secondary);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
}

.cal-monthstrip-label {
  flex: 0 0 auto;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-top: 3px;
}

.cal-monthstrip-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cal-pill--month {
  height: auto;
  padding: 3px 8px;
  margin: 0;
  max-width: 260px;
}

/* ── Agenda ───────────────────────────────────────────────────────────────── */

.cal-agenda {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-primary);
}

.cal-agenda-day {
  display: flex;
  gap: var(--spacing-sm);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
}

.cal-agenda-day:last-child { border-bottom: none; }
.cal-agenda-day--today { background: rgba(0, 156, 189, 0.05); }
.cal-agenda-day--month { background: var(--bg-secondary); }

.cal-agenda-date {
  flex: 0 0 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding-top: 2px;
}

.cal-agenda-dow {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.cal-agenda-num {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.05;
  color: var(--text-primary);
}

.cal-agenda-day--today .cal-agenda-num { color: var(--vmdo-teal); }

.cal-agenda-rel {
  font-size: 0.6rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.cal-agenda-items {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cal-agenda-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--text-primary);
}

.cal-agenda-row:hover { background: var(--bg-secondary); }
.cal-agenda-row--cancelled { opacity: 0.6; }
.cal-agenda-row--cancelled .cal-agenda-title { text-decoration: line-through; }

.cal-agenda-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.cal-agenda-title {
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-agenda-meta {
  flex: 1 1 auto;
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-agenda-badge {
  flex: 0 0 auto;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 600;
}

/* ── Day popover ──────────────────────────────────────────────────────────── */

.cal-popover {
  position: absolute;
  z-index: 20;
  width: 280px;
  max-height: 300px;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.cal-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
}

.cal-popover-close {
  background: none;
  border: none;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
}

.cal-popover-close:hover { color: var(--text-primary); }

.cal-popover-body {
  overflow-y: auto;
  padding: 4px;
}

/* ── States ───────────────────────────────────────────────────────────────── */

.cal-empty {
  padding: var(--spacing-xl);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
}

.cal-skeleton {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (max-width: 900px) {
  .cal { --cal-week-min: 88px; --cal-lane-h: 19px; }
  .cal-toolbar-actions { margin-left: 0; }
  .cal-filtergroup-right { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .cal-pill,
  .cal-viewbtn,
  .cal-chip { transition: none; }
}

/* ── Print ────────────────────────────────────────────────────────────────── */

@media print {
  /* Nothing in frontend/css had a print block before this. Without it the
     report prints app chrome, the AI panel, and a clipped viewport. */
  .app-header,
  .ai-chat-panel,
  #ai-chat-toggle,
  .profile-menu,
  #loading-bar,
  .cal-toolbar-actions,
  .cal-viewswitch,
  .cal-nav,
  .cal-filters,
  .cal-more { display: none !important; }

  body,
  #app-content,
  .route-view.active {
    height: auto;
    overflow: visible;
    max-width: none;
    padding: 0;
    margin: 0;
  }

  .cal-title {
    font-size: 14pt;
    margin-bottom: 8pt;
  }

  .cal-week,
  .cal-agenda-day { break-inside: avoid; }

  /* Every pill prints white without this and the report is meaningless. */
  .cal-pill,
  .cal-agenda-dot,
  .cal-legend-dot,
  .cal-daynum--today span,
  .cal-agenda-badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  @page {
    size: letter landscape;
    margin: 0.5in;
  }
}
