/* ===========================================================================
   Kalender-Modul (Monats- und Wochenansicht)
   Nutzt durchgaengig die Design-Tokens aus app.css (Hell/Dunkel automatisch).
   Eigene Farben nur fuer Event-/Typ-Daten (kommen inline aus dem JS).
   =========================================================================== */

.cal {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
}

/* ---- Toolbar ---- */
.cal-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.cal-toolbar__nav {
  display: flex;
  align-items: center;
  gap: 6px;
}
.cal-toolbar__title {
  font-size: 18px;
  font-weight: 600;
  min-width: 160px;
}
.cal-toolbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* Segment-Umschalter Monat/Woche */
.cal-switch {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.cal-switch__btn {
  appearance: none;
  border: 0;
  background: var(--surface);
  color: var(--text-soft);
  font: inherit;
  padding: 7px 14px;
  cursor: pointer;
}
.cal-switch__btn + .cal-switch__btn {
  border-left: 1px solid var(--border);
}
.cal-switch__btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.cal-switch__btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ---- Gemeinsamer Body ---- */
.cal__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ===========================================================================
   Monatsansicht
   =========================================================================== */

.cal-month {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Wochentag-Kopfzeile */
.cal-month__head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.cal-month__weekday {
  padding: 9px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.cal-month__weekday:nth-child(n+6) {
  color: var(--text-faint); /* Wochenende dezenter */
}

/* Gitter: pro Woche eine Zeile */
.cal-month__grid {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Eine Wochenzeile traegt 7 Tageszellen + ein Balken-Overlay.
   flex: 1 lässt alle Wochen die Resthöhe gleichmäßig teilen. */
.cal-week-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  flex: 1;
  min-height: 116px;
}
/* Kalenderwoche klein oben links in jeder Wochenzeile */
.cal-kw {
  position: absolute;
  top: 3px;
  left: 4px;
  z-index: 3;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-faint);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border-radius: 5px;
  padding: 0 4px;
  pointer-events: none;
}
.cal-week-row:last-child {
  border-bottom: 0;
}

/* Tageszelle */
.cal-day {
  position: relative;
  min-height: 116px;
  padding: 4px 5px 6px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  overflow: hidden;
}
.cal-day:last-child {
  border-right: 0;
}
.cal-day:hover {
  background: var(--surface-2);
}
.cal-day.is-outside {
  background: var(--bg);
}
.cal-day.is-outside .cal-day__num {
  color: var(--text-faint);
}

.cal-day__head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 2px;
}
.cal-day__num {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-soft);
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
/* Heutiger Tag: ganze Zelle klar umrandet + getönt für schnelle Orientierung */
.cal-day.is-today {
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
  box-shadow: inset 0 0 0 2px var(--accent);
  border-radius: 5px;
}
.cal-day.is-today:hover {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}
.cal-day.is-today .cal-day__num {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  box-shadow: 0 2px 6px -1px color-mix(in srgb, var(--accent) 60%, transparent);
}
/* "Heute"-Markierung links im Tageskopf */
.cal-day.is-today .cal-day__head { justify-content: space-between; }
.cal-day.is-today .cal-day__head::before {
  content: 'Heute';
  align-self: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 6px;
  padding: 1px 7px;
}
/* Ist heute der erste Wochentag (Montag), "Heute" rechts neben die KW rücken. */
.cal-day:first-child.is-today .cal-day__head::before { margin-left: 32px; }

.cal-day__events {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Platzhalter, damit eintaegige Chips unter den mehrtaegigen Balken sitzen */
.cal-chip-spacer {
  height: 19px;
}

/* Overlay-Ebene fuer mehrtaegige Balken (liegt ueber den Tageskoepfen) */
.cal-bars {
  position: absolute;
  top: 28px;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  padding: 0 3px;
  pointer-events: none;
}
.cal-bars .cal-bar {
  pointer-events: auto;
}

/* ===========================================================================
   Event-Chips (gemeinsam fuer Monatsansicht)
   =========================================================================== */

.cal-chip {
  font-size: 12px;
  line-height: 1.3;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 19px;
}
.cal-chip:hover {
  filter: brightness(1.05);
}
.cal-chip__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Durchgehender Balken (mehrtaegig / Urlaub) */
.cal-chip--bar {
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.cal-chip--bar.is-cont-left {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.cal-chip--bar.is-cont-right {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

/* Geburtstag: dezent, mit Farbpunkt */
.cal-chip--geburtstag {
  background: transparent !important;
  color: var(--text) !important;
  padding-left: 2px;
}
.cal-chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

/* Termin (gefuellt) erbt nur Grundstil; Farbe kommt inline aus JS */

/* Kanban-Karte (schreibgeschuetzt, deutlich andersartig) */
.cal-chip--kanban {
  background: transparent;
  color: var(--text-soft);
  border: 1px dashed var(--border-strong);
  font-style: italic;
}
.cal-chip--kanban:hover {
  background: var(--surface-2);
  filter: none;
}

/* ===========================================================================
   Wochenansicht
   =========================================================================== */

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  align-items: start;
}

/* ---- Tagesansicht (Agenda) ---- */
.cal-dayview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: auto;
  height: 100%;
}
.cal-dayview.is-today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.cal-dayview__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  max-width: 760px;
  margin: 0 auto;
  cursor: pointer;
  min-height: 100%;
}
.cal-dayview__empty {
  text-align: center;
  padding: 32px 8px;
  font-size: 14px;
}

.cal-wcol {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}
.cal-wcol.is-today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.cal-wcol__head {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.cal-wcol__head:hover {
  background: var(--surface-2);
}
.cal-wcol.is-today .cal-wcol__head {
  background: var(--accent-soft);
}
.cal-wcol__wd {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
}
.cal-wcol.is-today .cal-wcol__wd {
  color: var(--accent);
}
.cal-wcol__num {
  font-size: 12px;
  color: var(--text-faint);
}

.cal-wcol__list {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}
.cal-wcol__empty {
  text-align: center;
  padding: 8px 0;
  font-size: 13px;
}

/* Listeneintrag in der Wochenansicht (etwas groesser als Chip) */
.cal-witem {
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  display: flex;
  align-items: stretch;
  gap: 8px;
  white-space: normal;
  min-height: auto;
}
.cal-witem:hover {
  background: var(--surface-2);
  filter: brightness(0.98);
}
.cal-witem__bar {
  width: 4px;
  border-radius: 3px;
  flex: none;
}
.cal-witem__txt {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}
.cal-witem__title {
  font-size: 13px;
  font-weight: 500;
  white-space: normal;
  overflow-wrap: anywhere;
}
.cal-witem__time {
  font-size: 12px;
}

/* ===========================================================================
   Schreibgeschuetzte Detailansicht (Termin / Aufgabe)
   Wird vor dem Bearbeitungsformular gezeigt; ruhiger Lesestil ueber Tokens.
   =========================================================================== */

.cal-detail {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cal-detail__row {
  display: flex;
  gap: 12px;
  align-items: baseline;
  font-size: 14px;
}
.cal-detail__label {
  flex: none;
  width: 110px;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.cal-detail__value {
  color: var(--text);
  overflow-wrap: anywhere;
}

/* Beschreibung als eigener Block (mehrzeilig) */
.cal-detail__desc {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
.cal-detail__desc p {
  margin: 0;
  color: var(--text-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Hinweiszeile (z.B. "Bearbeitung im Board", Auto-Geburtstag) */
.cal-detail__hint {
  margin: 4px 0 0;
  font-size: 13px;
}

/* Farbtupfer im Detail-Titel */
.cal-detail__swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 4px;
  margin-right: 8px;
  vertical-align: middle;
  flex: none;
}

@media (max-width: 760px) {
  .cal-detail__row {
    flex-direction: column;
    gap: 2px;
  }
  .cal-detail__label {
    width: auto;
  }
}

/* ===========================================================================
   Formular-Ergaenzungen im Modal
   =========================================================================== */

.cal-check {
  margin-bottom: 12px;
}
.cal-check__row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}
.cal-check__row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* Farbwaehler kompakt */
.cal-color {
  height: 40px;
  padding: 4px;
  cursor: pointer;
}

/* Deaktiviertes Intervallfeld dezent */
.field.is-disabled {
  opacity: .5;
}

/* ===========================================================================
   Responsives Verhalten
   =========================================================================== */

@media (max-width: 760px) {
  .cal-toolbar__title {
    order: 3;
    width: 100%;
    text-align: center;
    min-width: 0;
  }
  .cal-day {
    min-height: 84px;
  }
  /* Wochenansicht stapelt die Tage untereinander */
  .cal-week {
    grid-template-columns: 1fr;
  }
  .cal-wcol {
    min-height: auto;
  }
}

/* ===========================================================================
   SVG-Line-Icons (Navigation, Geburtstag, Kanban)
   Farbe wird ueber stroke="currentColor" geerbt; auf farbigen Chips
   uebernimmt das Icon damit automatisch die Chip-Textfarbe.
   =========================================================================== */

.cal-icon {
  display: inline-block;
  flex: none;
  vertical-align: middle;
}

/* Inline-Icons neben Text (Geburtstag, Kanban): saubere vertikale Mitte,
   ohne die Textzeile aus der Bahn zu werfen. */
.cal-icon--inline {
  vertical-align: -0.15em;
}

/* Icon-Buttons der Toolbar: Pfeil-SVG exakt zentrieren. */
.cal-toolbar .btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* In Geburtstags-/Kanban-Chips liegt das Icon im Text-Span; das Icon soll
   beim Abschneiden (ellipsis) nicht gestaucht werden. */
.cal-chip__text .cal-icon,
.cal-witem__title .cal-icon {
  flex: none;
}

/* ===== Handy-Layout Kalender (nur < 640px; Desktop unverändert) ===== */
@media (max-width: 640px) {
  .cal-kw { display: none; }                 /* KW-Überlappung auf dem Handy vermeiden */
  .cal-week-row { min-height: 58px; }
  .cal-day { min-height: 58px; padding: 2px 3px; }
  .cal-day__num { width: 20px; height: 20px; font-size: 12px; }
  .cal-month__weekday { padding: 6px 3px; font-size: 10px; }
  .cal-chip { font-size: 10px; padding: 1px 4px; }
  .cal-chip__dot { width: 6px; height: 6px; }
}
