/* ========================================
   Vollbild-Kalender: Querformat, Tage als Spalten
   ======================================== */

body {
  overflow: hidden;
}

.cal-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height));
  background: var(--card-bg);
}

/* Steuerleiste */
.cal-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: white;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* Modus-Umschalter */
.view-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.view-toggle-btn {
  border: none;
  background: none;
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.view-toggle-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.cal-controls-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

/* Standort-Filter */
.location-filter {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
}

.location-filter::before {
  content: 'Standort:';
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
}

.cal-week-label {
  font-weight: 700;
  font-size: 15px;
  flex: 1;
  text-align: center;
  white-space: nowrap;
}

.cal-controls select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
}

/* Kalender-Grid-Wrapper */
.cal-grid-outer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: none;
}

/* ── Kopfzeile: Wochentage ── */
.cal-head {
  display: flex;
  flex-shrink: 0;
  background: #f8f9fa;
  border-bottom: 1px solid var(--border);
}

.cal-time-gutter {
  width: 48px;
  min-width: 48px;
  border-right: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-days-head {
  flex: 1;
  display: grid;
  /* wird per JS gesetzt: grid-template-columns */
}

.cal-day-label {
  text-align: center;
  padding: 5px 4px;
  font-size: 12px;
  font-weight: 600;
  border-right: 1px solid var(--border);
  user-select: none;
}

.cal-day-label.today {
  background: #dbeafe;
  color: #1d4ed8;
}

/* ── Sub-Kopfzeile: Platz-Namen ── */
.cal-subhead {
  display: flex;
  flex-shrink: 0;
  background: #fafafa;
  border-bottom: 2px solid var(--primary);
}

.cal-pitch-labels {
  flex: 1;
  display: grid;
  /* gleiche columns wie cal-days-head */
}

.cal-pitch-label {
  font-size: 10px;
  text-align: center;
  padding: 2px 2px;
  color: var(--text-muted);
  border-right: 1px solid #eee;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

/* ── Scrollbarer Kalender-Körper ── */
.cal-body-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

.cal-body-inner {
  display: flex;
  position: relative;
}

/* Zeitspalte */
.cal-time-col {
  width: 48px;
  min-width: 48px;
  position: relative;
  border-right: 1px solid var(--border);
  background: #fafafa;
  flex-shrink: 0;
}

.cal-time-tick {
  position: absolute;
  right: 4px;
  font-size: 10px;
  color: var(--text-muted);
  transform: translateY(-50%);
  white-space: nowrap;
  line-height: 1;
}

/* Spalten-Grid */
.cal-pitch-cols {
  flex: 1;
  display: grid;
  /* columns per JS */
  position: relative;
}

.cal-pitch-col {
  position: relative;
  border-right: 1px solid #e8eaed;
  background: white;
  min-width: 0;
}

/* Tages-Trenner (dunklere Linie zw. Tagen) */
.cal-pitch-col.day-start {
  border-left: 2px solid #d0d5dd;
}

/* Horizontale Gitterlinien */
.cal-grid-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  pointer-events: none;
}
.cal-grid-line.hour  { background: #d8dce3; }
.cal-grid-line.half  { background: #eef0f3; }

/* ── Trainingsblock ── */
.training-block {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: 5px;
  padding: 3px 5px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  overflow: hidden;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  line-height: 1.25;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
  transition: filter 0.1s, z-index 0s;
  border-left: 3px solid rgba(0,0,0,0.2);
}

.training-block:hover {
  filter: brightness(0.88);
  z-index: 10;
  transform: none;
}

.training-block .block-name {
  font-weight: 700;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.training-block .block-time {
  font-size: 9px;
  opacity: 0.8;
}

.training-block .block-type {
  font-size: 9px;
  opacity: 0.7;
  text-transform: capitalize;
}

.training-block.own-team {
  box-shadow: 0 0 0 2px rgba(0,0,0,0.35), 0 2px 6px rgba(0,0,0,0.25);
  filter: saturate(1.2) brightness(1.05);
  z-index: 3;
}

.training-block.other-team {
  opacity: 0.55;
}

.training-block.cancelled {
  opacity: 0.25;
}

.training-block.type-spiel {
  border-left-color: rgba(255,255,255,0.6);
  border-style: dashed;
}

/* ── Spiel-Block im Grid ── */
.match-block {
  position: absolute;
  left: 1px; right: 1px;
  border-radius: 4px;
  padding: 3px 5px;
  overflow: hidden;
  cursor: pointer;
  background: #fff9e6;
  border: 2px solid #f39c12;
  color: #7d4e00;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.match-block:hover { filter: brightness(0.92); z-index: 10; }
.match-block .block-name { font-weight: 700; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.match-block .block-time { font-size: 9px; opacity: 0.8; }

/* ── Extra-Termin-Block im Grid ── */
.extra-block {
  position: absolute;
  border-radius: 5px;
  padding: 3px 6px;
  overflow: hidden;
  cursor: pointer;
  background: #6c3483;
  color: #fff;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 1px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  border-left: 3px solid rgba(255,255,255,0.35);
}
.extra-block.allday {
  opacity: 0.45;
  z-index: 2;
  pointer-events: auto;
}
.extra-block:hover { filter: brightness(1.1); z-index: 10; }
.extra-block .block-name { font-weight: 700; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.extra-block .block-time { font-size: 9px; opacity: 0.85; white-space: nowrap; }

/* ── Spiele-Leiste (unten) ── */
.matches-bar {
  border-top: 1px solid var(--border);
  padding: 4px 12px;
  background: #fffbf0;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
  min-height: 30px;
}

.matches-bar-title {
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  font-size: 11px;
}

.match-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: #f0f4f8;
  white-space: nowrap;
  border: 1px solid var(--border);
}

.match-chip .chip-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Legende ── */
.legend-bar {
  border-top: 1px solid var(--border);
  padding: 4px 12px;
  background: #fafafa;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
  min-height: 28px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}

.legend-item.own-team {
  font-weight: 700;
  color: var(--text);
}

.legend-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ── Session-Popup ── */
.session-popup {
  position: fixed;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  min-width: 200px;
  max-width: 280px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18);
  z-index: 500;
  font-size: 13px;
}

.session-popup h4 {
  font-size: 14px;
  margin-bottom: 8px;
  padding-right: 20px;
}

.popup-row {
  display: flex;
  gap: 8px;
  margin-bottom: 3px;
  font-size: 12px;
}

.popup-label {
  color: var(--text-muted);
  min-width: 52px;
  flex-shrink: 0;
}

.popup-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.btn-close-popup {
  position: absolute;
  top: 8px; right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px 4px;
}

.btn-close-popup:hover { color: var(--text); }

/* Responsive Kurzformen */
.day-name-short { display: none; }
.pitch-name-short { display: none; }

@media (max-width: 900px) {
  .cal-week-label { font-size: 12px; }
  .training-block .block-time { display: none; }
  .cal-time-gutter { width: 36px; min-width: 36px; }
  .cal-time-col { width: 36px; min-width: 36px; }
}

@media (max-width: 600px) {
  /* Wochentage abkürzen: Montag → Mo */
  .day-name-long { display: none; }
  .day-name-short { display: inline; }
  /* Platznamen abkürzen: A-Platz → A */
  .pitch-name-long { display: none; }
  .pitch-name-short { display: inline; }
  /* Tages-Header etwas kompakter */
  .cal-day-label { font-size: 11px; padding: 4px 2px; }
  /* Mo–Fr / Sa–So Toggle überflüssig auf Mobile (alle 7 Tage sichtbar) */
  .view-toggle { display: none; }
  /* Export-Buttons auf Mobile ausblenden */
  #btn-export-pdf,
  #btn-export-excel-week,
  #btn-export-excel-season { display: none; }

  /* Horizontales Scrollen: nur Header clippen, Body-Scroll unverändert */
  .cal-head,
  .cal-subhead { overflow: hidden; }

  /* Pitch-Scroll-Wrapper: scrollt nur die Platzspalten */
  .cal-pitch-scroll {
    flex: 1;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .cal-pitch-scroll::-webkit-scrollbar { display: none; }

  /* Zeitspalte bleibt immer links — ist außerhalb des Scroll-Containers */
  .cal-time-col { flex-shrink: 0; }
}
