/* Questmio calendar – month with event chips and spanning bars, time grids (day / 3 days / week), schedule list,
   event sheet and form. Builds on the tokens and base components of app.css. */

.page.calendar { gap: 12px; }
.page.calendar > .section-head { margin: 0; }

/* ------------------------------------------------------------------ header */
.cal-head { display: flex; align-items: center; gap: 2px; min-height: 48px; margin: 0 -6px; }
.cal-head .icon-btn { min-width: 42px; }
.today-btn .today-num { display: grid; place-items: center; width: 24px; height: 24px; border: 2px solid currentColor; border-radius: 7px; font-size: .72rem; font-weight: 800; line-height: 1; padding-top: 2px; }
.cal-title { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 44px; padding: 0 4px; border-radius: 12px; font-weight: 700; font-size: 1.0625rem; letter-spacing: -.01em; cursor: pointer; }
.cal-title > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cal-title .icon { color: var(--muted); flex: none; }
.cal-title:focus-within { outline: 3px solid var(--focus); }
.date-overlay { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.view-btn { flex: none; gap: 2px; padding: 6px 8px 6px 12px; min-height: 40px; }
.cal-head .btn.view-btn { background: var(--surface); color: var(--ink); }
.cal-head .btn.view-btn:hover { background: var(--surface-2); }
.cal-search { margin-top: -4px; }
.cal-filter-hint { display: flex; gap: 6px; align-items: center; margin: -4px 0 0; }
.icon.flip { transform: rotate(180deg); }
.avatar.xs { width: 22px; height: 22px; font-size: .62rem; }

/* ------------------------------------------------------------------ event colours */
.color-plum { --ev: var(--c-plum); --ev-soft: var(--c-plum-soft); } .color-sage { --ev: var(--c-sage); --ev-soft: var(--c-sage-soft); }
.color-apricot { --ev: var(--c-apricot); --ev-soft: var(--c-apricot-soft); } .color-sky { --ev: var(--c-sky); --ev-soft: var(--c-sky-soft); }
.color-rose { --ev: var(--c-rose); --ev-soft: var(--c-rose-soft); } .color-sand { --ev: var(--c-sand); --ev-soft: var(--c-sand-soft); }
.color-slate { --ev: var(--c-slate); --ev-soft: var(--c-slate-soft); }
.swatch.color-plum, .swatch.color-sage, .swatch.color-apricot, .swatch.color-sky, .swatch.color-rose, .swatch.color-sand, .swatch.color-slate { background: var(--ev); }

/* ------------------------------------------------------------------ month */
.month { --chip-h: 18px; --chip-gap: 2px; background: var(--surface); border: 0; border-radius: var(--r); overflow: hidden; touch-action: pan-y; }
.m-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.m-head span { text-align: center; font-size: .7rem; font-weight: 600; color: var(--muted); padding: 10px 0 6px; letter-spacing: .02em; }
.m-row { position: relative; border-bottom: 1px solid var(--line); }
.m-row:last-child { border-bottom: 0; }
.m-cells { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.m-cell { position: relative; min-height: calc(30px + 3 * (var(--chip-h) + var(--chip-gap)) + 4px); display: flex; flex-direction: column; align-items: flex-start; padding: 3px 0 0 4px; border: 0; background: none; cursor: pointer; color: var(--ink); text-align: left; }
.m-cell:first-child { border-left: 0; }
.m-cell.other { color: var(--muted); }
.m-cell.other .m-num { font-weight: 400; }
.m-cell.sel { background: color-mix(in srgb, var(--primary-soft) 75%, transparent); }
.m-cell.sel.other { color: var(--ink-2); }
.m-num { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; font-weight: 550; font-size: .82rem; font-variant-numeric: tabular-nums; }
.m-cell.today .m-num { background: var(--primary-strong); color: var(--on-primary); font-weight: 700; }
.m-lanes { position: absolute; left: 0; right: 0; top: 29px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: calc(var(--chip-h) + var(--chip-gap)); pointer-events: none; }
.m-bar { min-width: 0; padding: 0 2px 0 3px; pointer-events: auto; }
.m-chip { display: flex; align-items: center; gap: 4px; width: 100%; height: var(--chip-h); min-height: 0; padding: 0 4px; border: 0; border-radius: 5px; font-size: .68rem; font-weight: 600; line-height: 1; color: var(--ink); background: none; text-align: left; cursor: pointer; overflow: hidden; }
.m-chip > span { overflow: hidden; white-space: nowrap; text-overflow: clip; }
.m-chip.allday { background: var(--ev); color: var(--surface); font-weight: 650; }
.m-chip.allday.cont { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -3px; padding-left: 6px; }
.m-chip.allday.open { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: -2px; }
.m-chip.timed { padding-left: 3px; }
.m-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--ev); }
.m-chip.timed.bar { height: 6px; margin: calc((var(--chip-h) - 6px) / 2) 0; padding: 0; border-radius: 3px; background: var(--ev); opacity: .85; }
.m-chip.timed.bar:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.m-more { pointer-events: auto; margin: 0 2px; height: var(--chip-h); min-height: 0; border: 0; border-radius: 5px; background: none; color: var(--ink-2); font-size: .68rem; font-weight: 750; text-align: left; padding: 0 4px; cursor: pointer; }
.m-more:hover { background: var(--surface-2); }
.day-agenda { display: flex; flex-direction: column; gap: 8px; }
.cal-empty-line { color: var(--muted); font-size: .92rem; padding: 6px 2px; }

/* ------------------------------------------------------------------ agenda rows & schedule */
.ag-list { display: flex; flex-direction: column; gap: 6px; }
/* rows of one day share one surface (DS4 grouped list) */
.ag-day .ag-list, .day-agenda .ag-list { gap: 0; background: var(--surface); border-radius: 14px; overflow: hidden; }
.ag-day .ag-list > .ag-row, .day-agenda .ag-list > .ag-row { position: relative; border-radius: 0; background: transparent; }
.ag-day .ag-list > .ag-row + .ag-row::before, .day-agenda .ag-list > .ag-row + .ag-row::before { content: ""; position: absolute; top: 0; left: 27px; right: 0; height: 1px; background: var(--line); }
.ag-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 8px 14px 8px 12px; border: 0; border-radius: 14px; background: var(--surface); text-align: left; cursor: pointer; color: inherit; }
.ag-row:hover { background: var(--surface-2); }
.ag-row:active { transform: scale(.995); }
.ag-bar { flex: none; width: 3px; align-self: stretch; border-radius: 2px; background: var(--ev); }
.ag-row strong { display: block; font-size: 1rem; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; }
.ag-row .meta { font-variant-numeric: tabular-nums; }
.ag-date { flex: none; display: flex; flex-direction: column; align-items: center; width: 40px; line-height: 1.1; }
.ag-date b { font-size: 1.1rem; font-weight: 700; }
.ag-date span { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ag-who { display: flex; }
.ag-who .avatar { margin-left: -6px; box-shadow: 0 0 0 2px var(--surface); }
.ag-who .avatar:first-child { margin-left: 0; }
.agenda { display: flex; flex-direction: column; gap: 10px; touch-action: pan-y; }
.ag-month { position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top, 0px)); z-index: 1; margin: 4px 0 -2px; padding: 8px 0 6px; background: var(--bg); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ag-day { display: grid; grid-template-columns: 48px 1fr; gap: 8px; align-items: start; }
.ag-dayhead { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border: 0; background: none; cursor: pointer; color: var(--ink); min-height: 44px; }
.ag-dayhead b { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; font-size: 1rem; font-weight: 700; }
.ag-dayhead span { font-size: .66rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; text-align: center; }
.ag-day.today .ag-dayhead b { background: var(--primary-strong); color: var(--on-primary); }
.ag-day.today .ag-dayhead span { color: var(--primary-strong); }
.cal-empty { margin-top: 24px; }

/* ------------------------------------------------------------------ time grid */
.timegrid { --gutter: 48px; background: var(--surface); border: 0; border-radius: var(--r); overflow: hidden; touch-action: pan-y; }
.tg-head { display: grid; grid-template-columns: var(--gutter) repeat(var(--cols, 7), minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.tg-gutter { display: grid; place-items: center; font-size: .6rem; line-height: 1.1; text-align: center; color: var(--muted); padding: 0 2px; overflow-wrap: anywhere; hyphens: auto; min-width: 0; }
.tg-day { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; border: 0; background: none; cursor: pointer; font-size: .68rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; min-height: 56px; }
.tg-day b { font-size: 1.05rem; color: var(--ink); width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; letter-spacing: 0; }
.tg-day.today { color: var(--primary-strong); }
.tg-day.today b { background: var(--primary-strong); color: var(--on-primary); }
.tg-allday { display: grid; grid-template-columns: var(--gutter) 1fr; border-bottom: 1px solid var(--line); background: transparent; }
.tg-adgrid { display: grid; grid-template-columns: repeat(var(--cols, 7), minmax(0, 1fr)); grid-auto-rows: 22px; gap: 2px 0; padding: 4px 0; }
.tg-adgrid .m-bar { padding: 0 2px; }
.tg-adgrid .m-chip { height: 20px; font-size: .72rem; }
.tg-scroll { overflow-y: auto; overscroll-behavior: contain; }
.tg-body { position: relative; display: grid; grid-template-columns: var(--gutter) repeat(var(--cols, 7), minmax(0, 1fr));
  background-image: repeating-linear-gradient(to bottom, var(--line) 0, var(--line) 1px, transparent 1px, transparent 56px); }
.tg-hours { position: relative; }
.tg-hours span { position: absolute; right: 8px; transform: translateY(-50%); font-size: .66rem; color: var(--muted); font-variant-numeric: tabular-nums; background: var(--surface); padding: 0 2px; }
.tg-col { position: relative; border-left: 1px solid var(--line); cursor: copy; }
.tg-col.today { background: color-mix(in srgb, var(--primary-soft) 30%, transparent); }
.tg-ev { position: absolute; z-index: 1; overflow: hidden; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 3px 5px 3px 7px; border: 1px solid color-mix(in srgb, var(--ev) 30%, transparent); border-left: 3px solid var(--ev);
  border-radius: 7px; background: var(--ev-soft); color: var(--ink); font-size: .72rem; line-height: 1.2; text-align: left; cursor: pointer; box-shadow: 0 1px 1px rgba(0, 0, 0, .04); }
.tg-ev:hover, .tg-ev:focus-visible { z-index: 2; box-shadow: var(--shadow-2); }
.tg-ev.past { opacity: .72; }
.tg-ev { touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tg-ev.dragging { z-index: 6; box-shadow: var(--shadow-2); opacity: .96; cursor: grabbing; transition: none; outline: 2px solid var(--ev); outline-offset: 0; }
.tg-ev.dragging.resize { cursor: ns-resize; }
.tg-rz { position: absolute; left: 0; right: 0; bottom: 0; height: 12px; cursor: ns-resize; touch-action: none; }
.tg-rz::after { content: ""; position: absolute; left: 50%; bottom: 3px; width: 26px; height: 3px; margin-left: -13px; border-radius: 2px; background: var(--ev); opacity: 0; transition: opacity .15s; }
.tg-ev:hover .tg-rz::after, .tg-ev:focus-visible .tg-rz::after, .tg-ev.dragging .tg-rz::after { opacity: .7; }
@media (pointer: coarse) { .tg-rz::after { opacity: .3; } }
.tg-ev b { font-weight: 650; max-width: 100%; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.timegrid.cols-7 .tg-ev b, .timegrid.cols-3 .tg-ev b { overflow-wrap: normal; word-break: normal; -webkit-line-clamp: 3; }
.tg-ev.short { padding-top: 2px; padding-bottom: 2px; }
.tg-ev.short b { -webkit-line-clamp: 1; white-space: nowrap; }
.tg-ev span { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.now-line { position: absolute; left: -1px; right: 0; height: 2px; background: var(--primary-strong); z-index: 3; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary-strong); }
.tg-hint { padding: 10px 12px 14px; font-size: .78rem; color: var(--muted); text-align: center; }
.view-day .tg-day { flex-direction: row; justify-content: center; gap: 10px; }
.view-day .tg-day span { font-size: .8rem; }
.view-day .tg-ev { font-size: .8rem; padding: 5px 8px 5px 9px; }

/* ------------------------------------------------------------------ event sheet */
.ev-dialog .dialog-head { padding-left: 14px; border-left: 5px solid var(--ev); border-radius: 3px; }
.ev-sheet { display: flex; flex-direction: column; gap: 14px; }
.ev-facts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ev-facts li { display: flex; gap: 12px; align-items: flex-start; font-size: .95rem; line-height: 1.4; }
.ev-facts .icon { flex: none; margin-top: 2px; color: var(--ev, var(--muted)); }
.ev-people { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 6px; }
.ev-person { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--ink-2); }
.ev-notes { white-space: pre-wrap; color: var(--ink-2); padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-size: .95rem; }

/* ------------------------------------------------------------------ event form */
.ev-form { gap: 14px; }
.ev-form .title-field input { font-size: 1.15rem; font-weight: 650; min-height: 54px; }
.ev-form .switch.row { justify-content: space-between; align-items: center; padding: 2px 2px; }
.ev-form .switch.row > span { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; font-weight: 600; }
.ev-form .switch.row > input { margin: 0; }
.when-box { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow: hidden; }
.when-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 4px; min-height: 52px; padding: 0 6px 0 14px; border-bottom: 1px solid var(--line); }
.when-row:last-of-type { border-bottom: 0; }
.when-label { font-weight: 600; font-size: .92rem; color: var(--ink-2); }
.when-field { position: relative; display: grid; place-items: center; min-height: 44px; padding: 0 10px; border-radius: 10px; font-weight: 650; font-variant-numeric: tabular-nums; cursor: pointer; }
.when-field:hover { background: var(--surface-2); }
.when-field:focus-within { outline: 3px solid var(--focus); outline-offset: -2px; }
.when-field input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.when-field[hidden] { display: none; }
.when-box .tz-box summary { padding: 10px 14px; }
.when-box .tz-box select { margin: 0 14px 12px; width: calc(100% - 28px); }
.scope-seg label { display: flex; align-items: center; justify-content: center; gap: 6px; }
.scope-seg label > span { display: inline-flex; align-items: center; gap: 6px; }
.people-picker legend { margin-bottom: 8px; }
.people-picker .chip-radio > span { gap: 8px; padding-left: 6px; }
.people-picker .chip-radio .avatar { width: 24px; height: 24px; min-height: 0; padding: 0; font-size: .66rem; }
.people-picker .hint { margin-top: 8px; }
.color-picker { gap: 2px; }
.icon-field { position: relative; }
.icon-field > .icon { position: absolute; left: 14px; top: 15px; color: var(--muted); pointer-events: none; }
.icon-field input, .icon-field textarea { padding-left: 42px; }
.repeat-box { display: flex; flex-direction: column; gap: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.actions.sticky { position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom, 0px)); margin: 4px -16px -20px; padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--line); z-index: 1; }
.flow-note ul { margin: 6px 0; padding-left: 18px; }
.conflicts:empty { display: none; }

/* ------------------------------------------------------------------ responsiveness */
@media (max-width: 479px) {
  .cal-head [data-prev], .cal-head [data-next] { display: none; } /* phones: swipe + date picker instead of arrows */
  .cal-title { font-size: 1.05rem; }
}
@media (max-width: 359px) {
  .month { --chip-h: 16px; }
  .m-chip { font-size: .62rem; }
  .timegrid { --gutter: 40px; }
  .tg-ev { font-size: .66rem; padding-left: 5px; }
  .view-btn { padding: 6px 6px 6px 10px; font-size: .8rem; }
}
@media (min-width: 600px) {
  .month { --chip-h: 20px; --chip-gap: 3px; }
  .m-chip { font-size: .76rem; }
  .m-cell { min-height: calc(28px + var(--lanes, 3) * (var(--chip-h) + var(--chip-gap)) + 22px); padding-left: 6px; }
  .m-lanes { top: 31px; }
  .tg-ev { font-size: .78rem; }
  .ag-day { grid-template-columns: 56px 1fr; }
  .actions.sticky { margin-inline: -24px; padding-inline: 24px; }
}
@media (hover: hover) {
  .m-chip:hover { filter: brightness(.96); }
}

/* fallback look for the view button until app.css defines .btn.tonal (kept harmless afterwards) */
.cal-head .view-btn { background: var(--primary-soft); border-color: transparent; color: var(--primary-strong); }
