:root {
  --bg: #f8f4e9;
  --paper: rgba(255, 252, 245, 0.78);
  --panel: rgba(255, 254, 250, 0.9);
  --ink: #1f2328;
  --muted: #5f6368;
  --accent: #da5e2a;
  --accent-dark: #ab3f14;
  --accent-soft: #ffe0ce;
  --line: #ddd3c3;
  --line-strong: #c8bba4;
  --chip: #ffe6d8;
  --chip-hover: #ffd4bd;
  --chip-single: #ffe8b8;
  --chip-single-border: #d79f32;
  --chip-recurring: #d8f3e7;
  --chip-recurring-border: #4f9e77;
  --selected: #fff1c4;
  --ring: 0 0 0 3px rgba(218, 94, 42, 0.2);
  --shadow-soft: 0 14px 34px rgba(60, 44, 22, 0.11);
  --shadow-strong: 0 22px 50px rgba(36, 27, 13, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "IBM Plex Sans Condensed", sans-serif;
  background:
    radial-gradient(circle at 0% 0%, #fff2d8 0%, transparent 40%),
    radial-gradient(circle at 100% 0%, #ffd6c0 0%, transparent 38%),
    radial-gradient(circle at 100% 100%, #ffe7b6 0%, transparent 32%),
    linear-gradient(135deg, #f2ebdb 0%, #f8f4e9 48%, #eee4d4 100%);
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(40px);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
}

.orb-1 {
  width: 340px;
  height: 340px;
  top: -120px;
  left: -90px;
  background: #ffb185;
  animation: drift 12s ease-in-out infinite alternate;
}

.orb-2 {
  width: 420px;
  height: 420px;
  bottom: -150px;
  right: -120px;
  background: #ffd66f;
  animation: drift 14s ease-in-out infinite alternate-reverse;
}

.layout {
  position: relative;
  z-index: 1;
  width: min(1240px, 95vw);
  margin: 20px auto 34px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  grid-template-areas:
    "hero hero"
    "calendar details";
  gap: 18px;
}

.hero {
  grid-area: hero;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.72), rgba(255, 246, 230, 0.65)),
    var(--paper);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 25px 28px;
  box-shadow: var(--shadow-strong);
  backdrop-filter: blur(8px);
  animation: reveal 500ms ease both;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent-dark);
  font-size: 0.75rem;
  font-weight: 700;
}

.hero h1 {
  margin: 10px 0 5px;
  font: 800 clamp(1.9rem, 4.2vw, 3rem) / 1.08 "Sora", sans-serif;
  text-wrap: balance;
}

.subline {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.98rem, 2.4vw, 1.1rem);
}

.calendar-shell,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(8px);
}

.calendar-shell {
  grid-area: calendar;
  padding: 16px;
  background: var(--panel);
  animation: reveal 680ms ease both;
}

.detail-panel {
  grid-area: details;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 248, 236, 0.85));
  animation: reveal 860ms ease both;
}

.calendar-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 10px;
  flex-wrap: wrap;
}

.nav-group,
.view-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  background: linear-gradient(140deg, #ea6d38, #c54c1e);
  color: #fff;
  padding: 9px 14px;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(184, 72, 29, 0.3);
  filter: saturate(1.05);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.btn-ghost {
  background: #fff7ef;
  border-color: #ebc8ac;
  color: #8a391b;
}

.btn-ghost:hover {
  box-shadow: 0 6px 14px rgba(185, 102, 67, 0.16);
}

.view-btn.active {
  background: linear-gradient(140deg, #b74a22, #8f3214);
  border-color: #8f3214;
  color: #fff;
}

.month-label {
  margin: 0;
  font: 700 1.3rem "Sora", sans-serif;
  letter-spacing: 0.01em;
}

.calendar-controls {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.63);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-group label,
.toggle-filters label,
.period-filter label,
.level-label {
  font-weight: 600;
  color: var(--muted);
}

#sportSearch {
  min-width: 230px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 8px 11px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.94rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#sportSearch:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.sport-search-wrap {
  position: relative;
  min-width: 230px;
}

.suggestion-box {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 16px 34px rgba(31, 35, 40, 0.16);
  max-height: 240px;
  overflow-y: auto;
  display: none;
}

.suggestion-box.visible {
  display: block;
}

.suggestion-item {
  width: 100%;
  border: 0;
  background: #fff;
  text-align: left;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 0.92rem;
  cursor: pointer;
}

.suggestion-item:hover {
  background: #fff1e7;
}

.selected-sports {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
}

.sport-chip,
.level-chip {
  border: 1px solid #d7be9a;
  background: #fff7e8;
  color: #413326;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.sport-chip:hover,
.level-chip:hover {
  background: #ffedd6;
  border-color: #cb9d6e;
}

.sport-chip::after {
  content: " x";
  font-weight: 700;
}

.toggle-filters,
.period-filter {
  width: 100%;
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 2px;
}

.toggle-filters label,
.period-filter label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.toggle-filters input[type="checkbox"],
.period-filter input[type="checkbox"] {
  accent-color: var(--accent);
}

.level-filter {
  width: 100%;
  display: none;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.level-filter.visible {
  display: flex;
}

.level-chip.off {
  background: #f2eee7;
  color: #8d8374;
  border-color: #ddd2c2;
  text-decoration: line-through;
}

.event-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 9px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
}

.legend-title {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: #3d352c;
  font-weight: 600;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.legend-dot.single {
  background: var(--chip-single);
  border-color: var(--chip-single-border);
}

.legend-dot.recurring {
  background: var(--chip-recurring);
  border-color: var(--chip-recurring-border);
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.weekday {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--muted);
  text-align: center;
  padding: 6px 2px;
  font-weight: 700;
}

.weekday-button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.weekday-button:hover {
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--line);
}

.weekday-spacer {
  opacity: 0;
  pointer-events: none;
}

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

.calendar-grid.month {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-grid.week,
.calendar-grid.day {
  grid-template-columns: minmax(0, 1fr);
}

.calendar-grid.day {
  overflow-x: auto;
}

.day-cell {
  min-height: 138px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.72);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: background 0.16s ease, transform 0.14s ease, box-shadow 0.14s ease;
}

.day-cell:hover {
  background: #fff;
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(32, 28, 19, 0.08);
}

.day-cell.outside {
  opacity: 0.46;
}

.day-cell.selected {
  background: var(--selected);
  border-color: #cea145;
  box-shadow: inset 0 0 0 1px #d4aa57;
}

.calendar-grid.week .day-cell {
  min-height: 190px;
}

.calendar-grid.day .day-cell {
  min-height: 430px;
}

.day-number {
  font-weight: 700;
  font-family: "Sora", sans-serif;
}

.event-chip {
  background: var(--chip);
  border: 1px solid #efc2a8;
  border-radius: 10px;
  padding: 4px 7px;
  font-size: 0.79rem;
  line-height: 1.22;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-chip:hover {
  background: var(--chip-hover);
}

.event-chip.single {
  background: var(--chip-single);
  border-color: var(--chip-single-border);
}

.event-chip.recurring {
  background: var(--chip-recurring);
  border-color: var(--chip-recurring-border);
}

.time-grid-wrapper {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 8px;
}

.time-axis {
  position: relative;
  height: 960px;
  display: grid;
  grid-template-rows: repeat(17, 1fr);
}

.calendar-grid.week .time-grid-wrapper {
  grid-template-columns: 62px 1fr;
}

.calendar-grid.day .time-grid-wrapper {
  grid-template-columns: 1fr;
}

.calendar-grid.week .time-axis {
  display: grid;
}

.calendar-grid.day .time-axis {
  display: none;
}

.time-axis-label {
  font-size: 0.75rem;
  color: var(--muted);
  transform: translateY(-8px);
}

.calendar-grid.week .time-axis-label {
  text-align: right;
  padding-right: 6px;
  font-weight: 700;
}

.time-columns {
  display: grid;
  gap: 8px;
  height: 960px;
}

.time-columns.week {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.time-columns.day {
  grid-template-columns: minmax(0, 1fr);
}

.time-column {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 13px;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent calc((100% / 16) - 1px),
      rgba(176, 156, 129, 0.25) calc((100% / 16) - 1px),
      rgba(176, 156, 129, 0.25) calc(100% / 16)
    ),
    rgba(255, 255, 255, 0.73);
  cursor: pointer;
  overflow: hidden;
}

.time-line-label {
  position: absolute;
  left: 8px;
  transform: translateY(-50%);
  font-size: 0.68rem;
  font-weight: 700;
  color: #786e5f;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 6px;
  padding: 0 4px;
  line-height: 1.3;
  pointer-events: none;
  z-index: 1;
}

.time-column.selected {
  border-color: #cea145;
  box-shadow: inset 0 0 0 1px #d4aa57;
}

.time-column.with-line-labels {
  padding-left: 0;
}

.time-grid-wrapper.day-scroll {
  min-width: max-content;
}

.time-columns.day.day-scroll-track {
  min-width: max-content;
}

.time-column.day-scroll-column {
  width: max-content;
}

.time-event {
  position: absolute;
  left: 6px;
  right: 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 5px 7px;
  overflow: hidden;
  text-align: left;
  min-height: 20px;
  box-shadow: 0 6px 10px rgba(30, 24, 16, 0.08);
  z-index: 2;
}

.time-event.single {
  background: var(--chip-single);
  border-color: var(--chip-single-border);
}

.time-event.recurring {
  background: var(--chip-recurring);
  border-color: var(--chip-recurring-border);
}

.time-event-time {
  font-size: 0.72rem;
  font-weight: 700;
}

.time-event-title {
  font-size: 0.78rem;
  line-height: 1.2;
  margin-top: 2px;
}

.time-event-sport {
  font-size: 0.72rem;
  color: #524a3d;
  margin-top: 2px;
}

.detail-panel h3 {
  margin: 0;
  font: 700 1.35rem "Sora", sans-serif;
}

.detail-date {
  margin: 6px 0 14px;
  color: var(--muted);
}

.detail-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.detail-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: #fff;
}

.detail-item.single {
  border-left: 6px solid var(--chip-single-border);
}

.detail-item.recurring {
  border-left: 6px solid var(--chip-recurring-border);
}

.detail-time {
  color: var(--accent-dark);
  font-weight: 700;
  margin-bottom: 3px;
}

.detail-title {
  font-size: 1rem;
  margin-bottom: 4px;
}

.detail-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.detail-item a {
  color: var(--accent-dark);
  font-weight: 700;
}

.detail-item a:hover {
  color: #7f2e10;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drift {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(18px, -12px, 0);
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "hero"
      "calendar"
      "details";
  }

  .hero,
  .calendar-shell,
  .detail-panel {
    border-radius: 20px;
  }

  .calendar-controls {
    padding: 10px;
  }

  .day-cell {
    min-height: 110px;
  }

  .time-grid-wrapper {
    grid-template-columns: 48px 1fr;
  }

  .time-axis,
  .time-columns {
    height: 880px;
  }

  #sportSearch,
  .sport-search-wrap {
    min-width: 170px;
  }
}

@media (max-width: 640px) {
  .layout {
    width: min(100%, 96vw);
    margin-top: 14px;
    margin-bottom: 22px;
  }

  .hero {
    padding: 20px;
  }

  .calendar-shell,
  .detail-panel {
    padding: 12px;
  }

  .month-label {
    font-size: 1.12rem;
  }

  .btn {
    padding: 8px 12px;
    font-size: 0.9rem;
  }

  .calendar-grid,
  .weekday-row {
    gap: 6px;
  }

  .day-cell {
    border-radius: 12px;
    min-height: 96px;
  }

  .event-chip {
    font-size: 0.74rem;
  }
}

/* KI Chat Widget */
.ai-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: inherit;
}
.ai-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}
.ai-button:hover { transform: scale(1.05); }
.ai-button svg { width: 30px; height: 30px; fill: currentColor; }

.ai-window {
  display: none;
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 350px;
  height: 500px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-color);
}
.ai-window.open { display: flex; }

.ai-header {
  background: var(--accent);
  color: white;
  padding: 15px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ai-header button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.2rem;
}
.ai-messages {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8f9fa;
  font-size: 0.9rem;
}
.ai-msg {
  padding: 10px 14px;
  border-radius: 18px;
  max-width: 85%;
  line-height: 1.4;
}
.ai-msg.ai {
  background: white;
  border: 1px solid var(--border-color);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.ai-msg.user {
  background: var(--accent);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.ai-input-area {
  padding: 15px;
  background: white;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.ai-input-area textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  outline: none;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
  font-family: inherit;
  box-sizing: border-box;
}
.ai-input-area textarea:focus { border-color: var(--accent); }
.ai-input-area button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-input-area button:disabled { background: #ccc; cursor: not-allowed; }

@media (max-width: 450px) {
  .ai-window {
    width: calc(100vw - 40px); /* Bildschirmbreite abzüglich Rand */
    height: 60vh;
  }
}

.ai-msg p { margin: 0 0 8px 0; }
.ai-msg p:last-child { margin-bottom: 0; }
.ai-msg ul, .ai-msg ol { margin: 8px 0 8px 20px; padding: 0; }
.ai-msg li { margin-bottom: 4px; }
.ai-msg a { color: var(--accent); text-decoration: underline; }
