/*
 * Theatersaal-Kalender — frontend styles.
 * Uses theme tokens (with fallbacks) so it matches the site palette.
 */

.ts-calendar {
  --ts-green: var(--mghp-green-700, #3e6107);
  --ts-line: var(--mghp-line, rgba(36, 63, 18, 0.12));
  max-width: var(--mghp-max-width, 1340px);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2.5rem);
}

/* Category legend — single horizontally scrollable row (saves vertical space) */
.ts-legend {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.35rem;
  font-size: 0.85rem;
  overflow-x: auto;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.ts-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: 0 0 auto;
  white-space: nowrap;
}

.ts-legend__dot {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

/* FullCalendar theming */
.ts-calendar .fc {
  --fc-border-color: var(--ts-line);
  --fc-today-bg-color: rgba(62, 97, 7, 0.06);
  --fc-now-indicator-color: var(--mghp-clay, #b85c38);
  background: var(--mghp-paper, #fff);
  color: var(--mghp-ink, #20251f);
  font-size: 0.9rem;
}

.ts-calendar .fc .fc-toolbar-title {
  color: var(--ts-green);
  font-size: 1.2rem;
}

.ts-calendar .fc .fc-button {
  background: var(--ts-green);
  border-color: var(--ts-green);
  text-transform: none;
  box-shadow: none;
}

.ts-calendar .fc .fc-button:hover,
.ts-calendar .fc .fc-button:focus {
  background: var(--mghp-green-900, #243f12);
  border-color: var(--mghp-green-900, #243f12);
}

.ts-calendar .fc .fc-button-primary:not(:disabled).fc-button-active {
  background: var(--mghp-green-900, #243f12);
  border-color: var(--mghp-green-900, #243f12);
}

.ts-calendar .fc .fc-event {
  border-radius: 4px;
  padding: 0;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
}

/* Keep event text readable and make dense week cells intentionally compact. */
.ts-calendar .fc .fc-event-main,
.ts-calendar .fc .fc-event-title,
.ts-calendar .fc .fc-event-time {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.ts-calendar .fc-timegrid-event .fc-event-main {
  height: 100%;
  min-width: 0;
  padding: 0;
  font-size: 0.72rem;
  line-height: 1.15;
  overflow: hidden;
}

.ts-calendar .fc-timegrid-event .fc-event-main-frame {
  height: 100%;
}

.ts-calendar .fc-timegrid-event .ts-event-chip {
  display: flex;
  flex-direction: column;
  gap: 1px;
  height: 100%;
  min-width: 0;
  padding: 2px 4px;
  overflow: hidden;
}

.ts-calendar .fc-timegrid-event .ts-event-chip__time {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ts-calendar .fc-timegrid-event .ts-event-chip__title {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  line-height: 1.12;
}

/* Very short events: use the limited height for the title and expose details on tap/click. */
.ts-calendar .fc-timegrid-event.ts-event-short .ts-event-chip__time {
  display: none;
}

.ts-calendar .fc-timegrid-event.ts-event-short .ts-event-chip__title {
  -webkit-line-clamp: 1;
  line-clamp: 1;
}

.ts-calendar .fc-daygrid-event .ts-event-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.25rem;
  align-items: start;
  padding: 1px 4px;
}

.ts-calendar .fc-daygrid-event .ts-event-chip__time {
  white-space: nowrap;
}

.ts-calendar .fc-daygrid-event .ts-event-chip__title {
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.ts-calendar .fc-daygrid-event .fc-event-title,
.ts-calendar .fc-list-event-title {
  white-space: normal;
}

.ts-event-list-title,
.ts-event-list-title__text {
  white-space: normal;
  overflow-wrap: anywhere;
}

.ts-event-dialog[hidden] {
  display: none;
}

.ts-event-dialog {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.ts-event-dialog__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 32, 15, 0.42);
}

.ts-event-dialog__panel {
  position: relative;
  width: min(34rem, 100%);
  max-height: min(36rem, calc(100vh - 2rem));
  overflow: auto;
  border-radius: 8px;
  border: 1px solid var(--ts-line);
  background: var(--mghp-paper, #fff);
  color: var(--mghp-ink, #20251f);
  padding: 1.25rem;
  box-shadow: 0 20px 60px rgba(20, 32, 15, 0.24);
}

.ts-event-dialog__close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--ts-line);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.ts-event-dialog__meta {
  margin: 0 2.5rem 0.35rem 0;
  color: var(--mghp-muted, #5f6d54);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.ts-event-dialog__title {
  margin: 0 2.5rem 1rem 0;
  color: var(--ts-green);
  font-size: 1.25rem;
  line-height: 1.25;
}

.ts-event-dialog__details {
  display: grid;
  gap: 0.75rem;
  margin: 0;
}

.ts-event-dialog__details div {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  gap: 0.75rem;
}

.ts-event-dialog__details dt {
  color: var(--mghp-muted, #5f6d54);
  font-weight: 700;
}

.ts-event-dialog__details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

:root[data-mghp-theme="dark"] .ts-calendar .fc {
  --fc-page-bg-color: var(--mghp-paper);
  --fc-neutral-bg-color: color-mix(
    in srgb,
    var(--mghp-paper) 78%,
    var(--mghp-cream)
  );
  --fc-list-event-hover-bg-color: color-mix(
    in srgb,
    var(--mghp-green-700) 12%,
    transparent
  );
  --fc-today-bg-color: color-mix(in srgb, var(--mghp-gold) 14%, transparent);
}

:root[data-mghp-theme="dark"] .ts-calendar .fc-theme-standard td,
:root[data-mghp-theme="dark"] .ts-calendar .fc-theme-standard th,
:root[data-mghp-theme="dark"] .ts-calendar .fc-theme-standard .fc-scrollgrid {
  border-color: var(--mghp-line);
}

:root[data-mghp-theme="dark"] .ts-calendar .fc .fc-col-header-cell,
:root[data-mghp-theme="dark"] .ts-calendar .fc .fc-timegrid-slot-label,
:root[data-mghp-theme="dark"] .ts-calendar .fc .fc-list-day-cushion {
  background: color-mix(in srgb, var(--mghp-paper) 82%, var(--mghp-cream));
  color: var(--mghp-muted);
}

:root[data-mghp-theme="dark"] .ts-calendar .fc .fc-button {
  color: #14200f;
}

:root[data-mghp-theme="dark"] .ts-calendar .fc .fc-button:disabled,
:root[data-mghp-theme="dark"]
  .ts-calendar
  .fc
  .fc-button-primary:not(:disabled).fc-button-active {
  background: var(--mghp-green-900);
  border-color: var(--mghp-green-900);
  color: #14200f;
}

:root[data-mghp-theme="dark"] .ts-calendar .fc .fc-daygrid-day-number,
:root[data-mghp-theme="dark"] .ts-calendar .fc .fc-list-event-time {
  color: var(--mghp-ink);
}

/* Responsive: keep the week grid usable on small screens */
@media (max-width: 640px) {
  .ts-calendar .fc .fc-toolbar.fc-header-toolbar {
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
  }

  .ts-calendar .fc .fc-toolbar-title {
    font-size: 1rem;
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .ts-calendar .fc .fc-toolbar-chunk {
    display: flex;
    justify-content: center;
  }

  .ts-calendar__mount .fc-view-harness {
    overflow-x: visible;
  }

  .ts-calendar .fc .fc-timegrid,
  .ts-calendar .fc .fc-daygrid {
    min-width: 0;
  }

  .ts-calendar .fc .fc-col-header-cell-cushion,
  .ts-calendar .fc .fc-daygrid-day-number {
    padding-inline: 2px;
    font-size: 0.7rem;
  }

  .ts-calendar .fc .fc-timegrid-slot-label {
    font-size: 0.72rem;
  }

  .ts-calendar .fc .fc-timegrid-axis,
  .ts-calendar .fc .fc-timegrid-slot-label {
    width: 3.25rem;
  }

  .ts-calendar .fc-timegrid-event .ts-event-chip {
    padding: 2px;
  }

  .ts-calendar .fc-timegrid-event .ts-event-chip__title {
    font-size: 0.66rem;
    line-height: 1.08;
    -webkit-line-clamp: 1;
    line-clamp: 1;
  }

  .ts-calendar .fc-timegrid-event .ts-event-chip__time {
    display: none;
  }

  .ts-calendar .fc-daygrid-event .ts-event-chip {
    display: block;
    padding: 1px 2px;
  }

  .ts-calendar .fc-daygrid-event .ts-event-chip__time {
    display: none;
  }

  .ts-calendar .fc-daygrid-event .ts-event-chip__title {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 0.68rem;
  }

  .ts-event-dialog__panel {
    padding: 1rem;
  }

  .ts-event-dialog__details div {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
}
