/* ---------------------------------------------------------------- Calendar (pages/calendar.js) */
.cal-page { display: grid; gap: 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.cal-brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.cal-brand h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.cal-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; padding: 8px 10px;
  border-radius: 18px; background: var(--glass); border: 1px solid rgba(255,255,255,.9); box-shadow: var(--shadow-1); }
.cal-tools .grow { flex: 1; }
.cal-nav { display: inline-flex; gap: 2px; }
.cal-title { margin: 0 4px; font-size: 21px; font-weight: 800; letter-spacing: -.015em; white-space: nowrap; }

.cal-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: start; }
.cal-body.with-rail { grid-template-columns: 272px minmax(0, 1fr); }
.cal-main { padding: 14px; min-width: 0; }
.cal-rail { padding: 18px; position: sticky; top: 86px; }
.cal-error { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

/* rail: mini month + calendars */
.cal-rail-in { display: grid; gap: 22px; }
.mini-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.mini-head b { font-size: 15.5px; }
.mini-head span { display: inline-flex; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.mini-dow { font-size: 11.5px; font-weight: 800; color: var(--faint); padding: 4px 0; }
.mini-day { position: relative; border: none; background: none; cursor: pointer; aspect-ratio: 1; border-radius: 50%;
  font: 600 13px var(--font); color: var(--ink-2); display: grid; place-items: center; }
.mini-day:hover { background: var(--surface-3); }
.mini-day.out { color: var(--faint); }
.mini-day.busy::after { content: ''; position: absolute; bottom: 3px; width: 4px; height: 4px; border-radius: 50%; background: var(--green); }
.mini-day.today { color: var(--green-ink); font-weight: 800; box-shadow: inset 0 0 0 1.5px var(--green-tint); }
.mini-day.sel { background: var(--green); color: #fff; }
.mini-day.sel::after { background: #fff; }
.cal-list h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.cal-check { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 12px; cursor: pointer; font-weight: 650; font-size: 14.5px; user-select: none; }
.cal-check:hover { background: var(--surface-3); }
.cal-check input { position: absolute; opacity: 0; pointer-events: none; }
.cal-check .box { width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; border: 2px solid var(--c); color: #fff; flex: none; transition: background .15s; }
.cal-check .box svg { opacity: 0; }
.cal-check input:checked + .box { background: var(--c); }
.cal-check input:checked + .box svg { opacity: 1; }
.cal-check input:focus-visible + .box { box-shadow: 0 0 0 3px var(--c-tint); }
.cal-check > svg { color: var(--c); }
.cal-rail-foot { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; }

/* chips (month cells, all-day row, popovers) */
.cal-chip { position: relative; display: flex; align-items: center; gap: 5px; min-width: 0; height: 22px; padding: 0 7px; margin: 0 3px;
  border-radius: 7px; font-size: 12.5px; font-weight: 700; cursor: pointer; overflow: hidden; white-space: nowrap; user-select: none;
  touch-action: none; }
.cal-chip.bar { background: var(--c-soft); color: var(--c-ink); box-shadow: inset 3px 0 0 var(--c); }
.cal-chip.bar.cl { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; box-shadow: none; }
.cal-chip.bar.cr { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; }
.cal-chip.timed { color: var(--ink-2); }
.cal-chip.timed::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.cal-chip.timed:hover, .cal-chip.bar:hover { filter: brightness(.97); background: var(--c-soft); }
.cal-chip .t { color: var(--muted); font-weight: 650; font-variant-numeric: tabular-nums; }
.cal-chip.bar .t { color: inherit; opacity: .75; }
.cal-chip .n { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cal-chip.done .n { text-decoration: line-through; opacity: .6; }
.cal-chip:focus-visible { outline: 2px solid var(--c); outline-offset: 1px; }
.chip-check { width: 14px; height: 14px; margin: 0; flex: none; accent-color: var(--green); cursor: pointer; }
.cal-more { border: none; background: none; text-align: left; padding: 0 9px; font: 800 12px var(--font); color: var(--muted); cursor: pointer; border-radius: 7px; margin: 0 3px; }
.cal-more:hover { background: var(--surface-3); color: var(--ink); }

/* month view */
.cal-month { --cols: 7; display: grid; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--surface); }
.cal-mhead { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.cal-mhead span { padding: 8px 10px; font-size: 12.5px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.cal-mrow { position: relative; min-height: 128px; border-bottom: 1px solid var(--line); }
.cal-mrow:last-child { border-bottom: none; }
.cal-mcells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
.cal-mcell { border-right: 1px solid var(--line); padding: 5px 6px; cursor: pointer; transition: background .15s; }
.cal-mcell:last-child { border-right: none; }
.cal-mcell:hover { background: var(--surface-2); }
.cal-mcell.out { background: rgba(238, 242, 247, .55); }
.cal-mcell.out .cal-mnum { color: var(--faint); }
.cal-mcell.drop { background: var(--green-soft); box-shadow: inset 0 0 0 2px var(--green-tint); }
.cal-mnum { border: none; background: none; cursor: pointer; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 999px;
  font: 700 13px var(--font); color: var(--ink-2); }
.cal-mnum:hover { background: var(--surface-3); }
.cal-mcell.today .cal-mnum { background: var(--green); color: #fff; }
.cal-mlayer { position: relative; margin-top: 34px; padding-bottom: 6px; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-auto-rows: 22px; row-gap: 3px; pointer-events: none; }
.cal-mlayer > * { pointer-events: auto; }
.cal-month.dragging { cursor: grabbing; }
.cal-month.dragging .cal-mlayer > * { pointer-events: none; }

/* week / day time grid */
.tg { --cols: 7; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--surface); }
.tg-head, .tg-allday { display: grid; grid-template-columns: 58px minmax(0, 1fr); }
.tg-head { grid-template-columns: 58px repeat(var(--cols), minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.tg-gutter { display: flex; align-items: flex-end; justify-content: flex-end; padding: 6px 8px; font-size: 11.5px; }
.tg-day { border: none; background: none; cursor: pointer; padding: 8px 4px 10px; display: grid; justify-items: center; gap: 2px; border-left: 1px solid var(--line); font-family: var(--font); }
.tg-day span { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tg-day b { font-size: 22px; font-weight: 750; color: var(--ink); width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; }
.tg-day:hover b { background: var(--surface-3); }
.tg-day.today span { color: var(--green-ink); }
.tg-day.today b { background: var(--green); color: #fff; }
.tg-allday { border-bottom: 1px solid var(--line); background: var(--surface-2); }
.tg-allday .tg-gutter { align-items: center; }
.tg-alllayer { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); row-gap: 3px; padding: 5px 0; min-height: 34px; border-left: 1px solid var(--line); }
.tg-scroll { height: clamp(420px, calc(100vh - 330px), 980px); overflow-y: auto; overscroll-behavior: contain; }
.tg-body { position: relative; display: grid; grid-template-columns: 58px minmax(0, 1fr); height: calc(24 * 48px); }
.tg-hours { position: relative; }
.tg-hours span { display: block; height: 48px; text-align: right; padding-right: 8px; font-size: 11.5px; font-weight: 650; color: var(--faint);
  transform: translateY(-7px); font-variant-numeric: tabular-nums; }
.tg-cols { position: relative; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); touch-action: pan-y;
  background-image: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px 48px); cursor: cell; user-select: none; }
.tg-col { position: relative; border-left: 1px solid var(--line); }
.tg-col.weekend { background: rgba(238, 242, 247, .45); }
.tg-col.today { background: rgba(228, 245, 232, .35); }
.tg-work { position: absolute; left: 0; right: 0; background: rgba(255, 255, 255, .5); pointer-events: none; }
.tg-now { position: absolute; left: -1px; right: 0; height: 2px; background: var(--rose); z-index: 4; pointer-events: none; }
.tg-now::before { content: ''; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--rose); }
.tg-ev { position: absolute; z-index: 2; padding: 4px 7px; border-radius: 9px; overflow: hidden; cursor: grab; touch-action: none;
  background: var(--c-soft); color: var(--c-ink); border: 1px solid var(--surface); box-shadow: inset 3px 0 0 var(--c), 0 1px 2px rgba(14,27,46,.08);
  display: flex; flex-direction: column; gap: 1px; font-size: 12.5px; line-height: 1.25; transition: box-shadow .15s; }
.tg-ev:hover { box-shadow: inset 3px 0 0 var(--c), var(--shadow-2); z-index: 3; }
.tg-ev b { font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.tg-ev span { opacity: .8; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tg-ev.tiny { flex-direction: row; align-items: center; padding: 1px 7px; }
.tg-ev.ghost { box-shadow: inset 3px 0 0 var(--c), var(--shadow-3); opacity: .92; z-index: 5; cursor: grabbing; }
.tg-ev.locked { cursor: pointer; }
.tg-rep { position: absolute; right: 6px; top: 6px; opacity: .6; }
.tg-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; cursor: ns-resize; }
.tg-resize::after { content: ''; position: absolute; left: 50%; bottom: 2px; width: 18px; height: 3px; margin-left: -9px; border-radius: 3px; background: var(--c); opacity: 0; transition: opacity .15s; }
.tg-ev:hover .tg-resize::after { opacity: .6; }
.tg-new { position: absolute; left: 3px; right: 3px; z-index: 5; border-radius: 9px; background: var(--green); color: #fff; padding: 4px 8px;
  font-size: 12.5px; font-weight: 750; box-shadow: var(--shadow-2); pointer-events: none; }

/* schedule */
.cal-sched { display: grid; }
.sched-day { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 14px; padding: 12px 8px; border-bottom: 1px solid var(--line); }
.sched-day:last-child { border-bottom: none; }
.sched-date { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.sched-date b { font-size: 24px; font-weight: 800; min-width: 34px; }
.sched-date span { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.sched-date em { font-style: normal; font-size: 12px; font-weight: 800; color: #fff; background: var(--green); padding: 2px 8px; border-radius: 999px; }
.sched-day.today .sched-date b { color: var(--green-ink); }
.sched-list { display: grid; gap: 2px; }
.sched-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border: none; background: none; border-radius: 12px; text-align: left;
  font-family: var(--font); color: var(--ink); cursor: pointer; min-width: 0; }
.sched-item:hover { background: var(--surface-2); }
.sched-item .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.sched-item input { width: 16px; height: 16px; margin: 0; accent-color: var(--green); flex: none; }
.sched-item .when { width: 150px; flex: none; font-size: 13.5px; font-weight: 650; color: var(--muted); font-variant-numeric: tabular-nums; }
.sched-item .what { flex: 1; min-width: 0; display: grid; }
.sched-item .what b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sched-item .what small { color: var(--muted); font-size: 12.5px; }
.sched-item.done .what b { text-decoration: line-through; opacity: .6; }
.cal-empty { display: grid; justify-items: center; gap: 8px; padding: 60px 20px; text-align: center; }
.cal-empty h3 { margin: 8px 0 0; }
.cal-empty p { margin: 0 0 8px; }

/* popovers */
.cal-float { z-index: 90; max-height: calc(100vh - 24px); overflow: auto; padding: 14px 14px 16px; border-radius: 20px; background: var(--surface);
  border: 1px solid var(--hair); box-shadow: var(--shadow-3); animation: pop .18s var(--ease) both; }
.cf-head { display: flex; align-items: flex-start; gap: 10px; }
.cf-head .grow { flex: 1; min-width: 0; }
.cf-head h3 { margin: 2px 0 2px; font-size: 18px; font-weight: 800; line-height: 1.25; word-break: break-word; }
.cf-head p { margin: 0; font-size: 13.5px; color: var(--muted); }
.cf-dot { width: 14px; height: 14px; border-radius: 5px; background: var(--c); flex: none; margin-top: 7px; }
.cf-rows { display: grid; gap: 9px; margin-top: 12px; padding-left: 24px; font-size: 14.5px; }
.cf-rows > div { display: flex; align-items: center; gap: 9px; color: var(--ink-2); }
.cf-rows > div > svg { color: var(--muted); flex: none; }
.cf-rows .btn { justify-self: start; }
.cf-notes { margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); color: var(--ink-2); white-space: pre-wrap; font-size: 14px; }
.more-list { display: grid; gap: 4px; margin-top: 10px; }
.more-list .cal-chip { height: 26px; margin: 0; }

/* editor & dialogs */
.ev-form { display: grid; gap: 16px; }
.ev-title { font-size: 20px; font-weight: 700; min-height: 54px; }
.ev-when { display: grid; gap: 10px; }
.ev-when .check { font-weight: 700; }
.ev-dates { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ev-err { display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--rose-soft); color: var(--rose-ink); font-weight: 650; }
.swatch.auto { display: grid; place-items: center; background: var(--surface); color: var(--muted); --c: var(--slate-tint); }
.danger-text { color: var(--rose) !important; }
.modal-foot .grow { flex: 1; }
.ev-form .span-2 { grid-column: 1 / -1; }
.choice-msg { margin: 0; font-size: 16.5px; color: var(--ink-2); }
.keys-list { display: grid; gap: 8px; margin-bottom: 12px; }
.keys-list > div { display: flex; align-items: center; gap: 14px; }
.keys-list > div > span { width: 150px; display: inline-flex; gap: 4px; align-items: center; flex: none; }
.keys-list i { font-style: normal; color: var(--muted); font-size: 13px; }

/* narrower screens */
@media (max-width: 720px) {
  .cal-brand h1 { font-size: 24px; }
  .cal-brand .small { display: none; }
  .cal-title { font-size: 17px; order: 10; flex-basis: 100%; margin: 2px 0 0; }
  .cal-tools .grow { display: none; }
  .cal-tools .segmented button { padding: 7px 11px; }
  .cal-main { padding: 8px; }
  .cal-mrow { min-height: 86px; }
  .cal-mcell { padding: 3px; }
  .cal-mlayer { margin-top: 30px; grid-auto-rows: 18px; }
  .cal-chip { height: 18px; font-size: 11px; padding: 0 4px; margin: 0 1px; gap: 3px; }
  .cal-chip.timed::before { width: 6px; height: 6px; }
  .cal-more { font-size: 10.5px; padding: 0 3px; }
  .cal-mhead span { padding: 6px 4px; text-align: center; }
  .tg-head, .tg-allday, .tg-body { grid-template-columns: 44px minmax(0, 1fr); }
  .tg-head { grid-template-columns: 44px repeat(var(--cols), minmax(0, 1fr)); }
  .tg-day b { font-size: 17px; width: 32px; height: 32px; }
  .tg-ev { font-size: 11.5px; padding: 3px 5px; }
  .sched-day { grid-template-columns: 1fr; gap: 6px; }
  .sched-item .when { width: 104px; font-size: 12.5px; }
  .cal-float { left: 12px !important; right: 12px !important; width: auto !important; top: auto !important; bottom: 12px; }
}
