.cal-wrapper {
  --cal-bg: var(--strobl-gray-surface, #2a2a2a);
  --cal-border: var(--strobl-gray-accent, #3d3d3d);
  --cal-text: var(--strobl-white, #ffffff);
  --cal-text-muted: var(--strobl-white-muted, #d0d0d0);
  --cal-highlight: var(--strobl-yellow, #ffe500);
  max-width: 100%;
  min-height: 480px;
  position: relative;
  overflow: hidden;
  padding: 18px;
  color: var(--cal-text);
  background: var(--cal-bg);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.cal-wrapper,
.cal-wrapper * {
  box-sizing: border-box;
}

.cal-wrapper .cal-overlay,
.cal-wrapper .cal-loading {
  display: none !important;
}

.cal-wrapper .cal-status-message {
  margin-bottom: 10px;
  padding: 10px 12px;
  color: var(--cal-text-muted);
  background: var(--strobl-gray, #1c1c1c);
  border: 2px solid var(--cal-border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
}

.cal-wrapper .cal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.cal-wrapper .cal-header .label {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  margin: 0;
  padding: 0 16px;
  color: var(--cal-text);
  background: var(--strobl-gray, #1c1c1c);
  border: 2px solid var(--cal-border);
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}

.cal-wrapper .cal-header button {
  box-sizing: border-box;
  -webkit-appearance: none !important;
  appearance: none !important;
  display: inline-flex !important;
  flex: 0 0 auto !important;
  align-items: center !important;
  justify-content: center !important;
  inline-size: 46px !important;
  block-size: 46px !important;
  min-inline-size: 46px !important;
  min-block-size: 46px !important;
  margin: 0 !important;
  padding: 0 !important;
  font-size: 15px !important;
  font-weight: 700 !important;
  color: var(--cal-text-muted) !important;
  background: transparent !important;
  border: 2px solid var(--cal-border) !important;
  border-radius: 999px !important;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    transform 0.1s ease,
    filter 0.1s ease !important;
}

.cal-wrapper .cal-header button .cal-nav-icon {
  display: block;
  inline-size: 10px;
  block-size: 10px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
}

.cal-wrapper .cal-header button.prev .cal-nav-icon {
  transform: rotate(-135deg);
  margin-left: 3px;
}

.cal-wrapper .cal-header button.next .cal-nav-icon {
  transform: rotate(45deg);
  margin-right: 3px;
}

.cal-wrapper .calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.cal-wrapper .cal-weekday-cell {
  padding: 6px 0;
  color: var(--cal-text-muted);
  border: 2px solid var(--cal-border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
  text-transform: uppercase;
}

.cal-wrapper .cal-day-cell,
.cal-wrapper .cal-empty-cell {
  min-height: 72px;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 1px solid var(--cal-border);
  border-radius: 8px;
}

.cal-wrapper .cal-day-cell {
  padding-top: 5px;
  padding-right: 3px;
  padding-left: 3px;
  padding-bottom: 12px;
  background: var(--strobl-gray, #1c1c1c);
}

.cal-wrapper .cal-day-number {
  position: absolute;
  top: 6px;
  left: 7px;
  color: var(--cal-text-muted);
  opacity: 0.65;
  font-size: 11px;
  font-weight: 600;
}

.cal-wrapper .cal-event-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 10px;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.25;
  text-align: center;
}

.cal-wrapper .cal-class-label {
  display: block;
  width: 100%;
  font-weight: 600;
  line-height: 1.05;
}

.cal-wrapper .cal-event-text,
.cal-wrapper .cal-event-text-secondary {
  display: block;
  width: 100%;
  white-space: normal;
  word-wrap: break-word;
}

.cal-wrapper .cal-event-text-secondary {
  font-size: 0.9em;
  font-weight: 500;
  line-height: 1.15;
}

.cal-wrapper .cal-day-cell.cal-event-yellow .cal-class-label {
  font-size: 0.92em;
  font-weight: 600;
  line-height: 1.05;
  word-break: keep-all;
  overflow-wrap: normal;
}

.cal-wrapper .cal-day-cell.cal-event-yellow .cal-event-text {
  font-size: 0.9em;
  font-weight: 500;
  line-height: 1.15;
}

.cal-wrapper .cal-day-cell .cal-event-text-secondary {
  font-size: 0.9em;
  font-weight: 500;
  line-height: 1.15;
}

/* Fix fuer Desktop Büro-Zeiten */
.cal-wrapper[data-type="buero"] .cal-event-text {
  white-space: pre-line;
  letter-spacing: -0.01em;
}

.cal-wrapper .cal-event-gray {
  color: var(--cal-text);
  background: var(--cal-border);
}

.cal-wrapper .cal-event-yellow {
  color: #171717;
  background: var(--cal-highlight);
}

/* KONTRAST-FIX: Tageszahl dunkel bei gelbem Hintergrund */
.cal-wrapper .cal-day-cell.cal-event-yellow .cal-day-number {
  color: var(--strobl-gray, #1c1c1c);
  opacity: 0.8;
}

.cal-wrapper .cal-meta {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.cal-wrapper .cal-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 6vw;
}

.cal-wrapper .cal-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--cal-text-muted);
  font-family: Montserrat, sans-serif;
  font-size: 14.15px;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
}

.cal-wrapper .cal-legend-text {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.cal-wrapper .cal-legend-detail {
  white-space: nowrap;
}

.cal-wrapper .cal-legend-dot {
  inline-size: 10px;
  block-size: 10px;
  flex: 0 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
}

.cal-wrapper .cal-legend-dot.is-closed {
  background: var(--strobl-gray, #1c1c1c);
  border-color: var(--cal-border);
}

.cal-wrapper .cal-legend-dot.is-default {
  background: var(--strobl-gray-accent, #3d3d3d);
}

.cal-wrapper .cal-legend-dot.is-highlight {
  background: var(--strobl-yellow, #ffe500);
  border-color: rgba(23, 23, 23, 0.16);
}

.cal-wrapper .cal-header button:focus-visible {
  color: var(--cal-text) !important;
  background: var(--strobl-gray, #1c1c1c) !important;
  border-color: var(--strobl-white-muted, #d0d0d0) !important;
  box-shadow: 0 0 0 3px rgba(255, 229, 0, 0.22);
}

@media (hover: hover) and (pointer: fine) {
  .cal-wrapper .cal-header button:hover,
  .cal-wrapper .cal-header button:active {
    color: var(--cal-text) !important;
    background: var(--strobl-gray, #1c1c1c) !important;
    border-color: var(--strobl-white-muted, #d0d0d0) !important;
    filter: none !important;
  }
}

@media (hover: none), (pointer: coarse) {
  .cal-wrapper .cal-header button:hover,
  .cal-wrapper .cal-header button:active,
  .cal-wrapper .cal-header button:focus,
  .cal-wrapper .cal-header button:focus-visible {
    color: var(--cal-text-muted) !important;
    background: transparent !important;
    border-color: var(--cal-border) !important;
    box-shadow: none !important;
    filter: none !important;
    transform: none !important;
  }
}

/* Mobile Ansicht Optimierungen */
@media (max-width: 767px) {
  .cal-wrapper {
    padding: 10px;
    border-radius: 8px;
  }

  .cal-wrapper .cal-status-message {
    margin-bottom: 8px;
    padding: 9px 10px;
    font-size: 12px;
  }

  .cal-wrapper .cal-day-cell,
  .cal-wrapper .cal-empty-cell {
    min-height: 60px;
    height: 100%;
    padding-top: 5px;
    padding-right: 3px;
    padding-left: 3px;
    padding-bottom: 4px;
  }

  .cal-wrapper[data-type="buero"] .cal-day-cell {
    padding: 10px 1px 3px 1px;
  }

  .cal-wrapper .cal-day-number {
    top: 2px;
    left: 3px;
    font-size: 9px;
  }

  /* UNTERRICHTSKALENDER (Standard) */
  .cal-wrapper:not([data-type="buero"]) .cal-event-content {
    margin-top: 6px;
    /* Leicht erhoeht auf 9px fuer bessere Lesbarkeit */
    font-size: 9.4px; 
    line-height: 1.1;
  }

  .cal-wrapper:not([data-type="buero"]) .cal-event-text {
    /* Verhindert das Zerschneiden von Woertern */
    word-break: normal;
    overflow-wrap: normal;
    hyphens: none;
    -webkit-hyphens: none;
    letter-spacing: -0.01em;
  }

  .cal-wrapper .cal-day-cell.cal-event-yellow .cal-class-label {
    font-size: 0.9em;
    font-weight: 600;
    line-height: 1.02;
    word-break: keep-all;
    overflow-wrap: normal;
  }

  .cal-wrapper .cal-day-cell.cal-event-yellow .cal-event-text {
    font-size: 0.88em;
    font-weight: 500;
    line-height: 1.1;
  }

  .cal-wrapper .cal-day-cell .cal-event-text-secondary {
    font-size: 0.88em;
    font-weight: 500;
    line-height: 1.1;
  }

  /* BÜRO-MODUS (Bleibt unberührt) */
  .cal-wrapper[data-type="buero"] .cal-event-content {
    margin-top: 3px;
    font-size: 10.4px;
  }

  .cal-wrapper[data-type="buero"] .cal-event-text {
    font-size: 10.1px;
    line-height: 1.15;
    white-space: pre-wrap; 
    word-break: keep-all;
    hyphens: none;
    -webkit-hyphens: none;
    overflow: visible;
    letter-spacing: -0.025em;
  }

  .cal-wrapper .cal-meta {
    display: flex;
    margin-top: 12px;
    padding: 12px 14px;
    background: var(--strobl-gray, #1c1c1c);
    border: 2px solid var(--cal-border);
    border-radius: 8px;
  }

  .cal-wrapper .cal-legend {
    gap: 7px 12px;
  }

  .cal-wrapper .cal-legend-item {
    align-items: flex-start;
    font-size: 9.6px;
    gap: 5px;
  }

  .cal-wrapper .cal-legend-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
  }

  .cal-wrapper .cal-legend-detail {
    white-space: normal;
    line-height: 1.15;
  }

  .cal-wrapper .cal-legend-dot {
    inline-size: 9px;
    block-size: 9px;
    flex-basis: 9px;
  }
}

@media (min-width: 1025px) and (max-width: 1680px) {
  .cal-wrapper .cal-day-cell {
    padding-top: 8px;
    padding-right: 3px;
    padding-left: 3px;
    padding-bottom: 6px;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  .cal-wrapper .cal-legend {
    gap: 8px 16px;
  }

  .cal-wrapper .cal-legend-item {
    font-size: 10.4px;
    font-weight: 600;
    font-family: inherit;
  }

  .cal-wrapper .cal-day-number {
    font-size: 9px;
  }

  .cal-wrapper .cal-day-cell {
    padding-top: 8px;
    padding-right: 3px;
    padding-left: 3px;
    padding-bottom: 6px;
  }

  .cal-wrapper:not([data-type="buero"]) .cal-event-content {
    font-size: 9.4px;
    line-height: 1.1;
  }

  .cal-wrapper:not([data-type="buero"]) .cal-event-text {
    word-break: normal;
    overflow-wrap: normal;
    hyphens: none;
    -webkit-hyphens: none;
    letter-spacing: -0.01em;
  }

  .cal-wrapper .cal-day-cell.cal-event-yellow .cal-class-label {
    font-size: 0.9em;
    font-weight: 600;
    line-height: 1.02;
    word-break: keep-all;
    overflow-wrap: normal;
  }

  .cal-wrapper .cal-day-cell.cal-event-yellow .cal-event-text {
    font-size: 0.88em;
    font-weight: 500;
    line-height: 1.1;
  }

  .cal-wrapper .cal-day-cell .cal-event-text-secondary {
    font-size: 0.88em;
    font-weight: 500;
    line-height: 1.1;
  }

  .cal-wrapper[data-type="buero"] .cal-event-content {
    font-size: 10.4px;
  }

  .cal-wrapper[data-type="buero"] .cal-event-text {
    font-size: 10.1px;
    line-height: 1.15;
    white-space: pre-wrap;
    word-break: keep-all;
    hyphens: none;
    -webkit-hyphens: none;
    overflow: visible;
    letter-spacing: -0.025em;
  }
}
