/* ============================================================================
   Stufe 2 – Kalender (Woche/Monat/Liste), Verfügbarkeit, Termin-Dialoge, Push
   Nutzt ausschließlich die Tokens aus app.css (hell + dunkel).
   ============================================================================ */
:root { --open-c: #E3A008; --hatch: rgba(124, 136, 154, .13); }
:root[data-theme="dark"] { --hatch: rgba(160, 175, 200, .12); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --hatch: rgba(160, 175, 200, .12); } }

.cal-page { max-width: 1480px; }
.cal-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-check { font-size: 13px; color: var(--ink-2); gap: 6px; cursor: pointer; white-space: nowrap; }
.cal-check input { accent-color: var(--brand); width: 16px; height: 16px; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 12.5px; color: var(--ink-3); align-items: center; }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cal-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; }
.cal-legend i.open { background: color-mix(in srgb, var(--open-c) 30%, var(--surface)); border: 1.5px dashed var(--open-c); }
.cal-legend i.hatch { background: repeating-linear-gradient(135deg, var(--surface) 0 3px, var(--line) 3px 5px); border: 1px solid var(--line); }

/* ------------------------------------------------------------------ Woche (Zeitraster) */
.wg { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-lg); overflow: hidden; }
.wg-head { display: grid; grid-template-columns: 56px repeat(var(--days), minmax(0, 1fr)); border-bottom: 1px solid var(--line); background: var(--surface); }
.wg-corner { border-right: 1px solid var(--line-2); }
.wg-dh { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 9px 4px 8px; border-left: 1px solid var(--line-2); font-size: 13px; color: var(--ink-2); min-width: 0; }
.wg-dh span { font-weight: 500; color: var(--ink-3); }
.wg-dh b { font-weight: 600; color: var(--ink); }
.wg-dh em { font-style: normal; font-size: 11px; font-weight: 600; color: var(--ink-3); background: var(--surface-3); border-radius: 8px; padding: 0 6px; }
.wg-dh.today { color: var(--brand); }
.wg-dh.today b { color: #fff; background: var(--brand); border-radius: 7px; padding: 1px 6px; }
.wg-scroll { max-height: calc(100dvh - 296px); min-height: 420px; overflow-y: auto; overscroll-behavior: contain; }
.wg-body { position: relative; display: grid; grid-template-columns: 56px repeat(var(--days), minmax(0, 1fr)); }
.wg-times { position: relative; border-right: 1px solid var(--line-2); }
.wg-times span { position: absolute; right: 8px; transform: translateY(-50%); font-size: 11px; color: var(--ink-3); font-weight: 500; }
.wg-times span:first-child { transform: none; top: 2px !important; }
.wg-day { position: relative; border-left: 1px solid var(--line-2); cursor: cell; min-width: 0; }
.wg-day:first-of-type { border-left: 0; }
.wg-day.today { background: color-mix(in srgb, var(--brand-soft) 35%, transparent); }
.wg-line { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--line-2); pointer-events: none; }
.wg-line.half { border-top-style: dashed; opacity: .55; }
.wg-off { position: absolute; left: 0; right: 0; pointer-events: none; background: repeating-linear-gradient(135deg, transparent 0 6px, var(--hatch) 6px 12px); }
.wg-now { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--danger); z-index: 6; pointer-events: none; }
.wg-now::before { content: ''; position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }

.wg-ev { --evc: var(--open-c); position: absolute; z-index: 4; box-sizing: border-box; overflow: hidden; padding: 3px 7px 3px 8px; border-radius: 7px;
  background: color-mix(in srgb, var(--evc) 15%, var(--surface)); border-left: 3px solid var(--evc); color: var(--ink);
  font-size: 12px; line-height: 1.3; cursor: grab; user-select: none; touch-action: none;
  box-shadow: 0 1px 2px rgba(20, 33, 58, .10); transition: box-shadow .12s; }
.wg-ev:hover { box-shadow: 0 2px 8px rgba(20, 33, 58, .18); z-index: 5; }
.wg-ev:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; z-index: 5; }
.mg-ev:focus-visible, .agenda-item:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.wg-ev.open { background: color-mix(in srgb, var(--open-c) 14%, var(--surface)); border: 1.5px dashed var(--open-c); border-left: 3px solid var(--open-c); }
.wg-ev.cancelled { opacity: .5; cursor: pointer; }
.wg-ev.cancelled .wg-ev-t { text-decoration: line-through; }
.wg-ev.dragging { cursor: grabbing; opacity: .92; box-shadow: 0 10px 24px -6px rgba(20, 33, 58, .4); transition: none; }
.wg-ev-t { display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.wg-ev-t b { font-weight: 700; }
.wg-ev-t .icon { flex: none; color: var(--evc); }
.wg-ev.open .wg-ev-t .icon { color: color-mix(in srgb, var(--open-c) 80%, #000); }
.wg-ev-s { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wg-ev-drag { position: absolute; right: 4px; bottom: 3px; background: var(--ink); color: #fff; border-radius: 5px; padding: 0 5px; font-size: 11px; font-weight: 700; }

/* ------------------------------------------------------------------ Monat */
.mg { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-lg); overflow: hidden; }
.mg-wd { padding: 8px 10px; font-size: 12.5px; font-weight: 600; color: var(--ink-3); border-bottom: 1px solid var(--line); }
.mg-day { min-height: 112px; padding: 6px 6px 8px; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 3px; cursor: pointer; min-width: 0; }
.mg-day:nth-child(7n) { border-right: 0; }
.mg-day:hover { background: var(--surface-2); }
.mg-day.other { background: var(--surface-2); }
.mg-day.other .mg-num { color: var(--ink-3); opacity: .6; }
.mg-num { align-self: flex-start; font-size: 13px; font-weight: 600; min-width: 24px; height: 24px; display: grid; place-items: center; border-radius: 12px; }
.mg-day.today .mg-num { background: var(--brand); color: #fff; }
.mg-ev { --evc: var(--open-c); display: block; width: 100%; text-align: left; border: 0; border-left: 3px solid var(--evc); background: color-mix(in srgb, var(--evc) 13%, var(--surface)); color: var(--ink);
  border-radius: 5px; padding: 2px 6px; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.mg-ev.open { border-left-style: dashed; }
.mg-ev:hover { filter: brightness(.97); }
.mg-more { font-size: 11.5px; color: var(--ink-3); padding-left: 4px; }
.mg-dots { display: none; }

/* ------------------------------------------------------------------ Liste */
.agenda-past-toggle { align-self: flex-start; color: var(--ink-2); }
.agenda-item.cancelled { opacity: .55; }
.agenda-item.cancelled .agenda-time { text-decoration: line-through; }

/* ------------------------------------------------------------------ Verfügbarkeit */
.av-wrap { overflow-x: auto; }
.av-grid { display: grid; grid-template-columns: 58px repeat(7, minmax(100px, 1fr)); gap: 3px; padding: 0 14px 16px; min-width: 760px; }
.av-corner { position: sticky; top: 0; }
.av-dh { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 24px 8px; white-space: nowrap; font-size: 13px; font-weight: 600; color: var(--ink); text-align: center; }
.av-dh small { font-size: 11.5px; font-weight: 500; color: var(--bearb); }
.av-dh.closed span { color: var(--ink-3); }
.av-dh.today span { color: var(--brand); }
.av-dh.closed small { color: var(--ink-3); }
.av-dh .menu-wrap { position: absolute; top: 4px; right: 0; }
.av-daybtn { width: 24px; height: 24px; border: 0; background: transparent; border-radius: 6px; color: var(--ink-3); cursor: pointer; display: grid; place-items: center; }
.av-daybtn:hover { background: var(--surface-3); color: var(--ink); }
.av-time { font-size: 11.5px; color: var(--ink-3); display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; font-weight: 500; }
.av-cell { height: 28px; border: 0; border-radius: 6px; font-size: 11.5px; font-weight: 500; cursor: pointer; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: filter .1s; }
.av-cell:hover { filter: brightness(.96); }
.av-cell:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.av-cell.free { background: var(--bearb-bg); color: var(--bearb); }
.av-cell.free.soon { background: var(--faellig-bg, var(--surface-3)); background: color-mix(in srgb, var(--open-c) 16%, var(--surface)); color: color-mix(in srgb, var(--open-c) 60%, var(--ink)); }
.av-cell.blocked { background: repeating-linear-gradient(135deg, var(--surface-3) 0 5px, var(--surface-2) 5px 10px); color: var(--ink-3); }
.av-cell.booked { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.av-cell.past { background: transparent; color: transparent; cursor: default; box-shadow: inset 0 0 0 1px var(--line-2); opacity: .5; }
.av-cell.closed { background: repeating-linear-gradient(135deg, transparent 0 5px, var(--hatch) 5px 10px); color: transparent; cursor: not-allowed; }
.av-cell.none { visibility: hidden; }

/* ------------------------------------------------------------------ Termin-Dialoge */
.link-btn { display: inline; border: 0; background: none; padding: 0; margin-left: 4px; color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--brand-ink); }
.appt-lead { display: flex; flex-direction: column; gap: 8px; }
.appt-lead-chip { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-ink); font-size: 13.5px; }
.appt-lead-chip span { flex: 1; min-width: 0; }

/* ------------------------------------------------------------------ Push-Einstellungen */
.push-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line-2); font-size: 14px; }
.push-row:first-child { border-top: 0; }
.push-row .grow { flex: 1; min-width: 0; }
.push-row .sub { font-size: 12.5px; color: var(--ink-3); }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 12px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch input:disabled + span { opacity: .5; }

@media (max-width: 860px) {
  .cal-toolbar { gap: 8px; }
  .cal-toolbar .segmented { max-width: 100%; overflow-x: auto; }
  .cal-toolbar > .spacer { display: none; }
  .mg-day { min-height: 58px; padding: 4px 2px 6px; align-items: center; }
  .mg-num { align-self: center; }
  .mg-ev, .mg-more { display: none; }
  .mg-dots { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px; margin-top: 2px; }
  .mg-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--open-c); }
  .mg-dots b { width: 100%; text-align: center; font-size: 11px; font-weight: 600; color: var(--ink-3); line-height: 1.2; }
  .mg-wd { padding: 6px 4px; text-align: center; }
  .av-time { position: sticky; left: 0; z-index: 1; background: var(--surface); }
  .av-grid { padding: 0 8px 12px; }
}
