/*
 * kd-cal.css — Darstellung der Korpodesk-Termine.
 *
 * Gestaltung nach dem Vorbild der Veranstaltungskarte in Korpodesk: Datums-Badge,
 * Datumszeile über dem Titel, Chips mit Symbolen, klare Aktionsknöpfe.
 * Alles unter `.kd-cal` gescoped, Farben und Radius kommen als CSS-Variablen aus den
 * Plugin-Einstellungen. Schriftart und Textfarbe erbt die Ansicht vom Theme — die
 * Liste soll zur Vereinsseite passen, nicht zu uns. Kein !important.
 */

/*
 * Linien, Flächen und gedämpfte Schrift leiten sich von der TEXTFARBE des Themes ab.
 * Der naheliegende Weg — `prefers-color-scheme` — ist hier falsch: er verrät nur die
 * Einstellung des Betriebssystems, nicht die Farbe der Vereinsseite. Ein helles Theme
 * auf einem dunkel gestellten Rechner bekäme sonst weiße Linien auf weißem Grund, also
 * eine unsichtbare Terminliste. Über currentColor passt sich die Ansicht dagegen an
 * das an, was tatsächlich um sie herum steht.
 *
 * Die rgba-Werte davor sind der Rückfall für Browser ohne color-mix (vor 2023).
 */
.kd-cal {
  --kd-accent: #1f3a5f;
  --kd-radius: 12px;
  --kd-linie: rgba(128, 128, 128, 0.38);
  --kd-flaeche: rgba(128, 128, 128, 0.12);
  --kd-zart: rgba(128, 128, 128, 0.06);
  --kd-leise: rgba(128, 128, 128, 1);
  --kd-schatten: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.08);
  color: inherit;
  line-height: 1.5;
}

@supports (color: color-mix(in srgb, currentColor 10%, transparent)) {
  .kd-cal {
    --kd-linie: color-mix(in srgb, currentColor 22%, transparent);
    --kd-flaeche: color-mix(in srgb, currentColor 7%, transparent);
    --kd-zart: color-mix(in srgb, currentColor 3.5%, transparent);
    --kd-leise: color-mix(in srgb, currentColor 68%, transparent);
  }
}

.kd-cal *,
.kd-cal *::before,
.kd-cal *::after { box-sizing: border-box; }

.kd-cal-titelzeile {
  margin: 0 0 16px;
  font-size: clamp(1.25rem, 1rem + 1vw, 1.6rem);
  line-height: 1.2;
}

.kd-cal-leer { color: var(--kd-leise); }

.kd-cal-icon {
  width: 1em;
  height: 1em;
  flex: none;
  vertical-align: -0.125em;
}

/* ── Karten ──────────────────────────────────────────────────────────── */
.kd-cal-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}

.kd-cal-karte {
  position: relative;
  border: 1px solid var(--kd-linie);
  border-radius: var(--kd-radius);
  background: transparent;
  overflow: hidden;
  transition: box-shadow 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}
.kd-cal-karte:hover {
  border-color: color-mix(in srgb, var(--kd-accent) 45%, transparent);
  box-shadow: var(--kd-schatten);
}
.kd-cal-karte:focus-within {
  border-color: var(--kd-accent);
}

.kd-cal-stil-schlicht .kd-cal-karte {
  border: 0;
  border-bottom: 1px solid var(--kd-linie);
  border-radius: 0;
  overflow: visible;
}
.kd-cal-stil-schlicht .kd-cal-karte:hover { box-shadow: none; }

.kd-cal-bild img {
  display: block;
  width: 100%;
  height: clamp(140px, 22vw, 220px);
  object-fit: cover;
}

.kd-cal-karte-kopf {
  display: flex;
  gap: 14px;
  padding: 16px;
  align-items: flex-start;
}

.kd-cal-badge {
  flex: none;
  width: 56px;
  padding: 8px 4px;
  border-radius: calc(var(--kd-radius) - 4px);
  background: var(--kd-accent);
  color: #fff;
  text-align: center;
  line-height: 1.1;
}
.kd-cal-badge-tag { display: block; font-size: 1.5rem; font-weight: 700; }
.kd-cal-badge-monat {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.9;
}

.kd-cal-karte-text { min-width: 0; flex: 1; }

.kd-cal-meta {
  margin: 0 0 2px;
  font-size: 0.85rem;
  color: var(--kd-leise);
}

.kd-cal-titel {
  margin: 0 0 8px;
  font-size: 1.15rem;
  line-height: 1.25;
}
.kd-cal-titel-btn {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.kd-cal-titel-btn:hover { color: var(--kd-accent); }

.kd-cal-chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 8px;
  padding: 0;
}
.kd-cal-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--kd-flaeche);
  border: 1px solid var(--kd-linie);
  font-size: 0.8rem;
  color: var(--kd-leise);
  max-width: 100%;
}
.kd-cal-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.kd-cal-text {
  margin: 0;
  color: inherit;
  opacity: 0.9;
}

.kd-cal-hinweis-zeile {
  margin: 0;
  padding: 0 16px 14px;
  font-size: 0.85rem;
  color: var(--kd-leise);
}

/* ── Knöpfe ──────────────────────────────────────────────────────────── */
.kd-cal-aktionen {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 16px;
}
.kd-cal-detail-inhalt .kd-cal-aktionen { padding: 4px 0 0; }

.kd-cal-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--kd-accent);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: filter 0.15s ease, background-color 0.15s ease;
}
.kd-cal-btn-haupt {
  background: var(--kd-accent);
  border-color: var(--kd-accent);
  color: #fff;
}
.kd-cal-btn-haupt:hover { filter: brightness(1.1); }
.kd-cal-btn-leise:hover { background: var(--kd-flaeche); }
.kd-cal-btn:focus-visible { outline: 2px solid var(--kd-accent); outline-offset: 2px; }

/* ── Overlay ─────────────────────────────────────────────────────────── */
.kd-cal-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 20, 28, 0.55);
  backdrop-filter: blur(2px);
  overscroll-behavior: contain;
}
.kd-cal-overlay[hidden] { display: none; }

.kd-cal-overlay-karte {
  position: relative;
  width: min(640px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  /* Grund und Schrift kommen vom Skript aus der Seite selbst; Canvas ist nur der
     Rückfall, wenn es (noch) nicht gelaufen ist. */
  background: var(--kd-grund, Canvas);
  color: var(--kd-text, CanvasText);
  color-scheme: light dark;
  border-radius: calc(var(--kd-radius) + 4px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}
.kd-cal-overlay-zu {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--kd-grund, Canvas);
  color: var(--kd-text, CanvasText);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
.kd-cal-overlay-zu:hover { background: var(--kd-flaeche); }
.kd-cal-overlay-inhalt > .kd-cal-detail { display: block; }

.kd-cal-detail-inhalt { padding: 20px; }
.kd-cal-detail-bild {
  margin: -20px -20px 16px;
}
.kd-cal-detail-bild img {
  display: block;
  width: 100%;
  height: clamp(160px, 30vw, 260px);
  object-fit: cover;
}
.kd-cal-detail-titel {
  margin: 2px 0 10px;
  font-size: 1.35rem;
  line-height: 1.25;
}
.kd-cal-detail-text { margin: 12px 0 16px; white-space: normal; }

body.kd-cal-fixiert { overflow: hidden; }

/* Ohne JavaScript gibt es kein Overlay — dann stehen die Details einfach in der Karte. */
.kd-cal-detail { display: none; }
.kd-cal-detail[hidden] { display: none; }

/* ── Gastformular ────────────────────────────────────────────────────── */
.kd-cal-anmeldung {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--kd-linie);
}
.kd-cal-anmeldung-titel { margin: 0 0 10px; font-size: 1rem; }

.kd-cal-felder {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.kd-cal-feld { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.kd-cal-feld label { font-size: 0.85rem; font-weight: 600; }
.kd-cal-feld input[type="text"],
.kd-cal-feld input[type="email"],
.kd-cal-feld input[type="number"],
.kd-cal-feld input[type="date"],
.kd-cal-feld select,
.kd-cal-feld textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--kd-linie);
  border-radius: 10px;
  font: inherit;
  background: var(--kd-grund, Canvas);
  color: var(--kd-text, CanvasText);
  color-scheme: light dark;
}
.kd-cal-feld input:focus-visible,
.kd-cal-feld select:focus-visible,
.kd-cal-feld textarea:focus-visible {
  outline: 2px solid var(--kd-accent);
  outline-offset: 1px;
}
.kd-cal-datenschutz { margin: 12px 0 0; }
.kd-cal-datenschutz label {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-weight: 400;
  font-size: 0.85rem;
}
.kd-cal-feldhinweis { font-size: 0.78rem; color: var(--kd-leise); }
.kd-cal-rest { margin: 0 0 10px; font-size: 0.85rem; color: var(--kd-leise); }
.kd-cal-kleingedruckt { margin: 10px 0 0; font-size: 0.82rem; color: var(--kd-leise); }
.kd-cal-absenden { margin: 14px 0 0; }

/* Honigtopf: für Menschen unsichtbar, für Screenreader ausgeblendet. */
.kd-cal-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.kd-cal-meldung {
  padding: 12px 16px;
  border-radius: var(--kd-radius);
  margin-bottom: 16px;
  border: 1px solid var(--kd-linie);
  border-left-width: 4px;
  background: var(--kd-flaeche);
}
.kd-cal-meldung-ok { border-left-color: #2f9e44; }
.kd-cal-meldung-fehler { border-left-color: #e03131; }
.kd-cal-hinweis {
  padding: 10px 14px;
  border: 1px dashed var(--kd-linie);
  border-radius: var(--kd-radius);
  color: var(--kd-leise);
  font-size: 0.9rem;
}

/* ── Monatsansicht ───────────────────────────────────────────────────── */
.kd-cal-monat-kopf {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.kd-cal-monat-kopf .kd-cal-titelzeile {
  margin: 0;
  flex: 1;
  text-align: center;
  text-transform: none;
}
.kd-cal-nav {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  font-size: 1.3rem;
  line-height: 1;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--kd-linie);
  border-radius: 50%;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.kd-cal-nav:hover { background: var(--kd-flaeche); border-color: var(--kd-accent); }

.kd-cal-raster {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.kd-cal-wt {
  padding: 4px 0 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--kd-leise);
  text-align: center;
}
.kd-cal-zelle {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 104px;
  padding: 6px;
  border: 1px solid var(--kd-linie);
  border-radius: 10px;
  background: transparent;
}
.kd-cal-zelle.kd-cal-we { background: var(--kd-zart); }
.kd-cal-zelle-leer { border-color: transparent; background: none; }
.kd-cal-hat-termin { border-color: color-mix(in srgb, var(--kd-accent) 35%, var(--kd-linie)); }
.kd-cal-heute {
  border-color: var(--kd-accent);
  box-shadow: inset 0 0 0 1px var(--kd-accent);
}
.kd-cal-znr {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--kd-leise);
  padding: 0 2px 2px;
}
.kd-cal-heute .kd-cal-znr {
  color: #fff;
  background: var(--kd-accent);
  border-radius: 999px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
}

.kd-cal-pille {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  text-align: left;
  padding: 5px 7px;
  border: 0;
  border-left: 3px solid var(--kd-accent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--kd-accent) 10%, transparent);
  color: inherit;
  font: inherit;
  font-size: 0.78rem;
  line-height: 1.25;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.kd-cal-pille:hover { background: color-mix(in srgb, var(--kd-accent) 20%, transparent); }
.kd-cal-pille-zeit { font-weight: 600; color: var(--kd-accent); font-size: 0.72rem; }
.kd-cal-pille-titel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Im Monatsraster ist die Agenda-Liste doppelt — sie ist nur der Mobil-Ersatz
   (und der Ort, an dem die Detailblöcke fürs Overlay stehen). */
.kd-cal-monat .kd-cal-agenda { display: none; }

@media (max-width: 720px) {
  .kd-cal-raster { display: none; }
  .kd-cal-monat .kd-cal-agenda { display: grid; margin-top: 4px; }
  .kd-cal-karte-kopf { padding: 14px; gap: 12px; }
  .kd-cal-badge { width: 48px; }
  .kd-cal-badge-tag { font-size: 1.3rem; }
  .kd-cal-aktionen { padding: 0 14px 14px; }
  .kd-cal-overlay { padding: 0; align-items: flex-end; }
  .kd-cal-overlay-karte {
    width: 100%;
    max-height: 92vh;
    border-radius: calc(var(--kd-radius) + 4px) calc(var(--kd-radius) + 4px) 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kd-cal * { transition: none; }
}

