/* ==========================================================================
   Calendar (cal-*) — month / week grid with lane-stacked multi-day events,
   agenda list, popovers.
   ========================================================================== */
.cal-title-picker { position: relative; display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; height: 28px; border-radius: var(--radius); cursor: pointer; }
.cal-title-picker:hover { background: var(--bg-hover); }
.cal-title { font-size: 1.12rem; font-weight: 600; white-space: nowrap; }
.cal-title-picker .icon { color: var(--text-muted); width: 14px; height: 14px; }
.cal-title-picker input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; border: 0; padding: 0; }

.cal { --cal-row-h: 130px; position: relative; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; user-select: none; -webkit-user-select: none; }
.cal-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--bg-subtle); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 3; }
.cal-head-cell { padding: 8px 10px; font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); border-left: 1px solid var(--border); white-space: nowrap; overflow: hidden; }
.cal-head-cell:first-child { border-left: 0; }
.cal-head-cell.is-off { color: var(--text-faint); }
.cal-head-short { display: none; }
.cal-mode-week .cal-head-cell { font-size: .8rem; }
.cal-mode-week .cal-head-cell b { font-size: 1.05rem; margin-left: 2px; color: var(--text); }
.cal-mode-week .cal-head-cell.is-today, .cal-mode-week .cal-head-cell.is-today b { color: var(--primary); }
.cal-weeks { position: relative; }
.cal-week { position: relative; height: var(--cal-row-h); border-bottom: 1px solid var(--border); }
.cal-week:last-child { border-bottom: 0; }
.cal-days { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-day { border-left: 1px solid var(--border); position: relative; min-width: 0; }
.cal-day:first-child { border-left: 0; }
.cal-day.is-off { background: color-mix(in srgb, var(--text-faint) 8%, transparent); }
.cal-day.is-holiday { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--text-faint) 12%, transparent) 0 5px, transparent 5px 10px); }
.cal-day.is-other .cal-daynum { color: var(--text-faint); }
.cal-day.is-other { background-color: color-mix(in srgb, var(--bg-subtle) 60%, transparent); }
.cal-day.is-selected { background: color-mix(in srgb, var(--primary) 14%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 40%, transparent); }
.cal-day-head { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px; }
.cal-daynum { font-size: .86rem; font-weight: 600; color: var(--text-muted); min-width: 24px; height: 22px; display: inline-grid; place-items: center; border-radius: 11px; padding: 0 4px; }
.cal-daynum-month { color: var(--text); }
.cal-day.is-today .cal-daynum { background: var(--primary); color: var(--primary-text); }
.cal-holiday { font-size: .72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cal-weeknum { position: absolute; right: 6px; bottom: 3px; font-size: .68rem; color: var(--text-faint); pointer-events: none; display: none; }
.cal-mode-month .cal-weeknum { display: block; }
.cal-evs { position: absolute; inset: 0; pointer-events: none; }
.cal-ev, .cal-more { pointer-events: auto; }
.cal-week { cursor: cell; }

.cal-ev {
  position: absolute; height: 21px; display: flex; align-items: center; gap: 5px; padding: 0 7px; border-radius: 4px; font-size: .82rem; line-height: 21px;
  background: var(--c); color: var(--fg, #fff); white-space: nowrap; overflow: hidden; text-decoration: none; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); z-index: 1;
}
.cal-ev:hover { text-decoration: none; color: var(--fg, #fff); filter: brightness(1.07); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 40%, transparent); }
.cal-ev.is-draggable { cursor: grab; touch-action: none; }
.cal-ev.is-dragging { opacity: .85; box-shadow: 0 0 0 2px var(--primary), 0 4px 10px rgba(0, 0, 0, .25); z-index: 4; }
.cal-ev.is-saving { opacity: .55; }
.cal-ev.is-closed { opacity: .5; text-decoration: line-through; }
.cal-ev.cut-l { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.cal-ev.cut-r { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.cal-ev.cut-l::before { content: "‹"; margin-left: -3px; opacity: .7; }
.cal-ev-text { overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 auto; }
.cal-ev-id { opacity: .75; font-variant-numeric: tabular-nums; }
.cal-ev-who { flex: 0 0 auto; display: inline-flex; }
.cal-ev-who .avatar { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .7); }
.cal-ev-parent { background: color-mix(in srgb, var(--c) 18%, var(--surface)); color: var(--text); border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); box-shadow: none; }
.cal-ev-parent:hover { color: var(--text); }
.cal-ev-milestone { background: transparent; color: var(--text); box-shadow: none; padding-left: 4px; }
.cal-ev-milestone:hover { color: var(--text); background: var(--bg-hover); box-shadow: none; filter: none; }
.cal-ev-diamond { width: 10px; height: 10px; flex: 0 0 10px; background: var(--c); transform: rotate(45deg); border-radius: 1px; margin: 0 2px; }
.cal-ev-meeting { background: var(--primary-soft); color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
.cal-ev-meeting:hover { color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); filter: none; background: color-mix(in srgb, var(--primary) 22%, var(--surface)); }
.cal-ev-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-handle { position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; }
.cal-handle-l { left: 0; }
.cal-handle-r { right: 0; }
.cal-ev:hover .cal-handle::after { content: ""; position: absolute; top: 5px; bottom: 5px; left: 2px; width: 2px; border-radius: 2px; background: var(--fg, #fff); opacity: .6; }
.cal.is-dragging, .cal.is-dragging * { cursor: grabbing !important; }

.cal-more {
  position: absolute; height: 20px; border: 0; background: none; text-align: left; padding: 0 6px; font: inherit; font-size: .8rem; font-weight: 600;
  color: var(--text-muted); border-radius: 4px; cursor: pointer; white-space: nowrap; overflow: hidden;
}
.cal-more:hover { background: var(--bg-hover); color: var(--text); }

/* Week view */
.cal-mode-week .cal-week { min-height: 380px; }
.cal-mode-week .cal-day-head { display: none; }
.cal-head-holiday { display: block; font-size: .7rem; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }
.cal-mode-week .cal-day.is-today { background: color-mix(in srgb, var(--primary) 6%, transparent); }

/* Popover */
.cal-pop { position: absolute; z-index: 330; width: 300px; max-width: calc(100vw - 16px); background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 6px; animation: menu-in .12s ease; }
.cal-pop-head { display: flex; align-items: center; gap: 6px; padding: 4px 6px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.cal-pop-head .btn { margin-left: auto; }
.cal-pop .menu-title { padding: 6px 8px 4px; font-size: .74rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-faint); font-weight: 600; }
.cal-pop-list { max-height: 320px; overflow-y: auto; }
.cal-pop-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--text); font-size: .9rem; min-width: 0; }
.cal-pop-item:hover { background: var(--bg-hover); text-decoration: none; color: var(--text); }
.cal-pop-item.is-closed { color: var(--text-muted); text-decoration: line-through; }

/* Agenda list */
.cal-mode-list { padding: 4px 0; overflow: visible; }
.cal-agenda-day { display: grid; grid-template-columns: 220px minmax(0, 1fr); border-bottom: 1px solid var(--border); }
.cal-agenda-day:last-child { border-bottom: 0; }
.cal-agenda-day.is-off { background: color-mix(in srgb, var(--text-faint) 6%, transparent); }
.cal-agenda-date { display: flex; align-items: flex-start; gap: 10px; margin: 0; padding: 12px 16px; font-size: .92rem; font-weight: 400; }
.cal-agenda-date > span:nth-child(2) { display: flex; flex-direction: column; }
.cal-agenda-num { font-size: 1.5rem; font-weight: 700; line-height: 1; min-width: 34px; height: 34px; display: grid; place-items: center; border-radius: 17px; color: var(--text); }
.cal-agenda-day.is-today .cal-agenda-num { background: var(--primary); color: var(--primary-text); }
.cal-agenda-list { list-style: none; margin: 0; padding: 6px 12px 6px 0; }
.cal-agenda-item { display: grid; grid-template-columns: 120px 14px minmax(0, 1fr); align-items: start; gap: 10px; padding: 7px 8px; border-radius: var(--radius); }
.cal-agenda-item:hover { background: var(--bg-hover); }
.cal-agenda-item.is-closed .cal-agenda-main > a { color: var(--text-muted); text-decoration: line-through; }
.cal-agenda-when { color: var(--text-muted); font-size: .86rem; font-variant-numeric: tabular-nums; padding-top: 1px; }
.cal-agenda-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-top: 5px; flex: 0 0 10px; }
.cal-agenda-dot.is-ms { border-radius: 2px; transform: rotate(45deg); }
.cal-agenda-meeting { background: var(--primary); border-radius: 3px; }
.cal-agenda-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-agenda-main > a { color: var(--text); font-weight: 500; }
.cal-agenda-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .86rem; }
.cal-mode-list .empty-state { padding: 60px 20px; }

@media (max-width: 900px) {
  .cal-head-long { display: none; }
  .cal-head-short { display: inline; }
  .cal-head-cell { padding: 6px 6px; }
  .cal-holiday { display: none; }
  .cal-ev-id { display: none; }
  .cal-agenda-day { grid-template-columns: 1fr; }
  .cal-agenda-date { padding-bottom: 0; }
  .cal-agenda-list { padding-left: 12px; }
  .cal-agenda-item { grid-template-columns: 88px 12px minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .cal-mode-week { overflow-x: auto; }
  .cal-mode-week .cal-head, .cal-mode-week .cal-weeks { min-width: 500px; }
  .cal-mode-month .cal-head-cell { padding: 6px 2px; text-align: center; justify-content: center; font-size: .7rem; }
  .cal-mode-month .cal-day-head { padding: 4px 2px; justify-content: center; }
  .cal-mode-month .cal-daynum { font-size: .78rem; padding: 0 2px; }
  .cal-mode-month .cal-weeknum { display: none; }
  .cal-mode-month .cal-ev { font-size: .7rem; padding: 0 3px; gap: 2px; }
  .cal-mode-month .cal-more { font-size: .7rem; padding: 0 2px; }
  .cal-ev { font-size: .76rem; padding: 0 4px; }
  .cal-title { font-size: 1rem; }
}
@media print {
  body.planning-page .cal { border-color: #999; overflow: visible; }
  .cal-ev, .cal-day.is-off, .cal-day.is-today .cal-daynum { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
