/* ===== CALENDAR & EVENTS (js/calendar.js) =====
   Quiet chrome, same tokens as the rest of the shell: the accent appears on
   today's number, the selected day and the add buttons; every event wears its
   calendar's colour via --cal. Check new pairs against the dark palette. */

.calendar-container { display: none; flex: 1; min-height: 0; flex-direction: column; overflow-y: auto; }
.calendar-container:not(.hidden) { display: flex; }
.cal-host { display: flex; flex-direction: column; flex: 1; min-height: 0; }
/* The personal view scrolls in .calendar-container; the team view renders into
   #projectContainer (overflow:hidden), so its host has to scroll itself —
   otherwise the phone's Month day panel and Week strip were cut off unreachably. */
.cal-host.is-team { overflow-y: auto; }
.cal-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cal-nav.is-list .wk-arrow, .cal-nav.is-list .btn-today { display: none; }

/* In-content toolbar (team calendar; the personal view uses the top bar). */
.cal-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px 6px; flex-wrap: wrap;
}
.cal-toolbar .week-nav { position: relative; display: inline-flex; align-items: center; gap: 6px; }
.cal-toolbar .week-label { font-weight: 700; font-size: 0.95rem; cursor: pointer; padding: 4px 8px; border-radius: 7px; }
.cal-toolbar .week-label:hover { background: var(--bg-alt); }
.cal-toolbar-right { display: flex; align-items: center; gap: 8px; }

/* ---- Month grid ---- */
.cal-month {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: auto; grid-auto-rows: 1fr;
  flex: 1; min-height: 0; margin: 0 22px 22px;
}
.cal-dow {
  grid-row: 1; align-self: end; padding: 10px 8px 6px; text-align: right;
  font: 600 calc(12px * var(--text-scale))/1 var(--font); color: var(--text-secondary);
  letter-spacing: .02em; border-bottom: 1px solid var(--hairline-strong);
}
.cal-dow.is-weekend { color: var(--text-tertiary); }
.cal-cell {
  position: relative; display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  min-height: 0; padding: 8px 8px 6px; background: transparent; border: none;
  border-bottom: 1px solid var(--hairline); border-right: 1px solid var(--hairline);
  font: inherit; color: var(--text); text-align: right; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-ui);
  -webkit-tap-highlight-color: transparent;
}
.cal-cell:nth-child(7n + 7) { border-right: none; }
/* Weekends take a subtle shade so the working week reads as a block. */
.cal-cell.is-weekend { background: var(--fill-soft); }
.cal-cell:hover { background: var(--fill); }
.cal-cell.other-month .cal-daynum { color: var(--text-tertiary); }
.cal-cell.other-month .cal-dot { opacity: .55; }
.cal-cell.selected { background: var(--fill); box-shadow: inset 0 0 0 2px var(--accent); border-radius: 6px; z-index: 1; }
.cal-daynum {
  display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 26px; padding: 0 6px;
  border-radius: 13px; font: 500 calc(13.5px * var(--text-scale))/1 var(--font); color: var(--text);
}
.cal-cell.is-today .cal-daynum { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.cal-dots { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-start; align-self: stretch; margin-top: auto; }
/* "4 Home events" = a 4 in a red circle. */
.cal-dot {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 11px; color: #fff; font: 700 calc(11px * var(--text-scale))/1 var(--font); letter-spacing: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.cal-dot.is-light { color: #1d1d22; }
/* Named events in a desktop month cell (js: calRenderMonth / calFitMonthChips).
   A timed event is a dot + time + title; an all-day or multi-day one is a bar
   filled with its calendar's colour, the Apple Calendar idiom. Phones keep the
   count circles (.cal-dots) — a 50px cell can't name anything. */
.cal-cell-evs { display: flex; flex-direction: column; gap: 2px; align-self: stretch; min-height: 0; overflow: hidden; }
.cal-mev {
  display: flex; align-items: center; gap: 5px; min-width: 0; height: 20px; padding: 0 6px; border-radius: 5px;
  font: 500 calc(11.5px * var(--text-scale))/1 var(--font); color: var(--text); text-align: left; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-ui);
}
.cal-mev::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--cal); flex: none; }
.cal-mev:hover { background: var(--fill); }
.cal-mev:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-mev.is-allday { background: var(--cal); color: #fff; }
.cal-mev.is-allday::before { display: none; }
.cal-mev.is-allday:hover { filter: brightness(1.08); }
.cal-mev.is-allday.is-light { color: #1d1d22; }
.cal-mev-time { color: var(--text-secondary); font-weight: 400; flex: none; font-variant-numeric: tabular-nums; }
.cal-mev.is-allday .cal-mev-time { color: inherit; }
.cal-mev-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cal-mev-more { font: 500 calc(11px * var(--text-scale))/1 var(--font); color: var(--text-secondary); padding: 2px 6px; text-align: left; }
.cal-cell.other-month .cal-mev { opacity: .6; }

/* ---- Day detail (popover on desktop, panel under the grid on phones) ---- */
.cal-daypop {
  position: fixed; z-index: 1650; width: 340px; max-height: 60vh; overflow-y: auto;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 14px 38px rgba(var(--shadow), 0.22); padding: 10px 10px 8px;
}
.cal-dd-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 6px 8px; }
.cal-dd-title { font: 600 calc(14px * var(--text-scale))/1.3 var(--font); color: var(--text); }
.cal-dd-add {
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; flex: none;
  border-radius: 50%; border: none; background: var(--accent); color: var(--on-accent); cursor: pointer;
}
.cal-dd-add svg { width: 15px; height: 15px; }
.cal-dd-add:hover { filter: brightness(1.06); }
.cal-dd-list { display: flex; flex-direction: column; gap: 2px; }
.cal-daydetail { padding: 6px 16px 120px; }
.cal-daydetail.is-week { padding-top: 0; }

/* ---- One event line (every view + Today) ---- */
.cal-ev {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 7px 10px 7px 8px;
  border: none; border-radius: 10px; background: transparent; text-align: left; cursor: pointer; font: inherit; color: var(--text);
  transition: background var(--dur-fast) var(--ease-ui);
  -webkit-tap-highlight-color: transparent;
}
.cal-ev:hover { background: var(--fill-soft); }
.cal-ev-bar { flex: none; width: 4px; align-self: stretch; min-height: 30px; border-radius: 2px; background: var(--cal, var(--accent)); margin-top: 1px; }
.cal-ev-time { flex: none; width: 112px; padding-top: 2px; font: 500 calc(12.5px * var(--text-scale))/1.4 var(--font); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.cal-ev.is-allday .cal-ev-time { color: var(--text-tertiary); }
.cal-ev-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cal-ev-title { font: 500 calc(14px * var(--text-scale))/1.35 var(--font); color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.cal-ev-sub { font: 400 calc(12px * var(--text-scale))/1.35 var(--font); color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-ev.is-readonly .cal-ev-title::after { content: ''; }
.cal-daypop .cal-ev-time, .cal-daydetail .cal-ev-time { width: 96px; }

/* ---- Week (desktop columns) ---- */
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); flex: 1; min-height: 0; margin: 0 22px 22px; border-top: 1px solid var(--hairline-strong); }
.cal-wk-col { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--hairline); }
.cal-wk-col:last-child { border-right: none; }
.cal-wk-col.is-weekend { background: var(--fill-soft); }
.cal-wk-head { display: flex; align-items: baseline; gap: 6px; padding: 10px 10px 8px; border-bottom: 1px solid var(--hairline-strong); position: sticky; top: 0; background: inherit; }
.cal-wk-dow { font: 600 calc(12px * var(--text-scale))/1 var(--font); color: var(--text-secondary); text-transform: uppercase; letter-spacing: .06em; }
.cal-wk-date { font: 600 calc(18px * var(--text-scale))/1 var(--font-display); color: var(--text); }
.cal-wk-col.is-today .cal-wk-dow, .cal-wk-col.is-today .cal-wk-date { color: var(--accent); }
.cal-wk-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 6px 4px 12px; display: flex; flex-direction: column; gap: 2px; }
.cal-week .cal-ev { flex-direction: column; align-items: stretch; gap: 2px; padding: 6px 8px 6px 10px; position: relative; min-width: 0; }
.cal-week .cal-ev-body { width: 100%; min-width: 0; }
.cal-week .cal-ev-title { display: block; min-width: 0; }
.cal-week .cal-ev-bar { position: absolute; left: 4px; top: 7px; bottom: 7px; width: 3px; min-height: 0; }
.cal-week .cal-ev-time { width: auto; padding: 0; font-size: calc(11.5px * var(--text-scale)); }
.cal-week .cal-ev-title { font-size: calc(13px * var(--text-scale)); white-space: nowrap; }
.cal-week .cal-ev-sub { display: none; }
.cal-wk-add {
  display: inline-flex; align-items: center; gap: 6px; margin: 4px 4px 0; padding: 6px 8px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-tertiary); font: 500 calc(12.5px * var(--text-scale))/1 var(--font); cursor: pointer; opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-ui), background var(--dur-fast) var(--ease-ui);
}
.cal-wk-add svg { width: 14px; height: 14px; }
.cal-wk-col:hover .cal-wk-add, .cal-wk-add:focus-visible { opacity: 1; }
.cal-wk-add:hover { background: var(--fill); color: var(--text); }

/* ---- List ---- */
/* Full panel width, as the Month and Week grids are. .list-inner's auto margins
   would otherwise shrink it to its content inside the flex column it sits in. */
.cal-list { width: 100%; max-width: none; margin: 0; padding: 14px 22px 40px; }
.cal-list .list-group .cal-ev + .cal-ev { margin-top: 2px; }
.cal-list-more { display: flex; justify-content: center; padding: 10px 0 20px; }
.cal-host.cal-view-list .cal-inner { overflow-y: auto; }

/* ---- Today page ---- */
.cal-today-list { display: flex; flex-direction: column; gap: 2px; }

/* ---- Event modal ---- */
.cal-ev-modal .te-row input[type="time"] { margin-left: auto; margin-right: 0; }
.cal-ev-modal .te-datebtn { margin-right: 0; }
#eventModal.is-allday input[type="time"] { display: none; }
#eventModal.is-allday .te-datebtn { margin-right: auto; }
.cal-sel-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--accent); }
.cal-allday, .modal-body .cal-allday, .te-row .cal-allday { margin: 0; display: inline-flex; align-items: center; gap: 8px; font-size: 0.88rem; color: var(--text); cursor: pointer; padding: 6px 8px; margin-right: auto; }
.te-row .cal-allday input, .cal-allday input { flex: none; accent-color: var(--accent); width: 16px; height: 16px; margin: 0; padding: 0; border: none; }
.cal-row-spacer { flex: 1; }
.cal-static { flex: 1; font-size: 0.88rem; color: var(--text); padding: 6px 8px; }
.cal-ev-meta { margin-top: 10px; font-size: 0.8rem; color: var(--text-tertiary); }
#eventModal.is-readonly .te-clear { display: none; }
#eventModal .te-row select { flex: 1; }
#eventModal .cal-sel-dot + select { margin-left: -2px; }
.cal-swatch { border-color: transparent; }
.cal-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg-card) inset; }

/* ---- Calendars list modal ---- */
.cal-list-group + .cal-list-group { margin-top: 14px; }
.cal-list-head { font: 600 calc(12px * var(--text-scale))/1 var(--font); color: var(--text-secondary); text-transform: uppercase; letter-spacing: .06em; padding: 0 4px 8px; }
.cal-list-row { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-top: 1px solid var(--border-light); }
.cal-list-row.is-hidden .cal-list-name { color: var(--text-tertiary); }
.cal-list-vis, .modal-body .cal-list-vis { position: relative; display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.cal-list-vis input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.cal-list-dot { display: inline-block; width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); transition: transform var(--dur-fast) var(--ease-ui), opacity var(--dur-fast) var(--ease-ui); }
.cal-list-vis input:not(:checked) + .cal-list-dot { opacity: .3; transform: scale(.8); }
.cal-list-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }
.cal-tag { font: 600 10.5px/1 var(--font); color: var(--text-secondary); background: var(--fill); border-radius: 6px; padding: 4px 6px; text-transform: uppercase; letter-spacing: .04em; }
.cal-list-btn { width: 28px; height: 28px; border: none; border-radius: 8px; background: transparent; color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.cal-list-btn svg { width: 15px; height: 15px; }
.cal-list-btn:hover { background: var(--fill); color: var(--text); }
.cal-list-btn.is-busy svg { animation: cal-spin 1s linear infinite; }
@keyframes cal-spin { to { transform: rotate(360deg); } }
.cal-list-add { border: none; background: transparent; color: var(--accent); font: 500 0.86rem var(--font); padding: 8px 6px; cursor: pointer; }
.cal-list-add:hover { text-decoration: underline; }
.cal-menu-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex: none; }

/* ---- Phone ---- */
@media (max-width: 768px) {
  .cal-host { height: auto; }
  .cal-cell-evs { display: none; }
  .cal-inner { display: block; }
  .cal-month { margin: 4px 12px 10px; grid-auto-rows: auto; flex: none; }
  .cal-dow { padding: 6px 2px 8px; text-align: center; font-size: calc(11px * var(--text-scale)); border-bottom: none; }
  /* Square cells: the shaded weekend columns are one continuous block, and
     rounded corners would leave star-shaped gaps where four cells meet. */
  .cal-cell { aspect-ratio: 1 / 1.08; align-items: center; justify-content: flex-start; padding: 5px 2px 4px; gap: 3px; border-right: none; border-bottom: none; text-align: center; }
  .cal-cell.selected { border-radius: 10px; }
  .cal-cell.is-weekend { background: var(--fill-soft); }
  .cal-cell.selected { box-shadow: inset 0 0 0 2px var(--accent); }
  .cal-daynum { min-width: 24px; height: 24px; font-size: calc(13px * var(--text-scale)); }
  .cal-dots { justify-content: center; margin-top: 0; gap: 2px; }
  .cal-dot { min-width: 16px; height: 16px; padding: 0 4px; font-size: calc(9.5px * var(--text-scale)); border-radius: 8px; box-shadow: none; }
  .cal-ev { padding: 8px 10px 8px 8px; }
  /* Events on the phone's task scale (styles.css, "One type scale for every
     task surface"): --m-task-fs/400 title, --m-task-meta-fs/400 time and
     calendar line — an event on Today sits directly under task rows and read
     two sizes smaller. The wider time column fits "10:00 – 11:00". */
  .cal-ev-title { font-size: calc(var(--m-task-fs) * var(--text-scale)); font-weight: 400; }
  .cal-ev-time, .cal-daydetail .cal-ev-time { width: 104px; font-size: calc(var(--m-task-meta-fs) * var(--text-scale)); font-weight: 400; line-height: 1.35; padding-top: 3px; }
  .cal-ev-sub { font-size: calc(var(--m-task-meta-fs) * var(--text-scale)); }
  .cal-list { padding: 8px 16px var(--tabbar-clear); }
  .cal-daydetail { padding-bottom: var(--tabbar-clear); }
  .cal-list .view-head { display: none; }
  .cal-toolbar { padding: 8px 12px 4px; }
  .cal-toolbar-right .seg-group { display: none; }
  /* The FAB adds events on a phone; the top bar keeps only the nav + calendars. */
  .topbar .new-btn.calendar-ctl { display: none !important; }
  /* Five tabs when the calendar is on: let the pills share the width. */
  .tabbar.has-cal .tab-item { max-width: none; }
  .tabbar.has-cal .tab-item span { font-size: 10px; }
}
@media (min-width: 769px) {
  /* The calendar's title lives in the top bar's nav label, like Tasks → Week.
     The List carries its own heading in the content, so its nav goes, as the
     Tasks List's week navigation does. */
  .cal-host.cal-view-month .cal-inner, .cal-host.cal-view-week .cal-inner { padding-top: 8px; }
  /* Named chips replace the count circles here. */
  .cal-dots { display: none; }
  #tbCalendar .cal-nav.is-list { display: none; }
}
