/* Speichenplan */

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

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes fadeOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

:root {
  --bg: #f5f0e8;
  --surface: #ffffff;
  --surface-warm: #faf7f2;
  --text: #2a2520;
  --text-secondary: #5a5249;
  --text-muted: #8a8078;
  --accent: #c2542d;
  --accent-hover: #a8441f;
  --accent-light: #fdf1ec;
  --accent-glow: rgba(194, 84, 45, 0.08);
  --header-bg: #2a2520;
  --header-text: #f5f0e8;
  --border: #e5ddd3;
  --border-light: #efe9e0;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow-xs: 0 1px 2px rgba(42,37,32,0.04);
  --shadow-sm: 0 1px 3px rgba(42,37,32,0.06);
  --shadow: 0 2px 8px rgba(42,37,32,0.08);
  --shadow-md: 0 4px 16px rgba(42,37,32,0.1);
  --shadow-lg: 0 8px 30px rgba(42,37,32,0.12);
  --transition: 0.2s ease;
  --font-display: "Instrument Serif", Georgia, serif;
  --font-body: "Figtree", -apple-system, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ===== HEADER ===== */

header {
  background: var(--header-bg);
  color: var(--header-text);
  position: relative;
  overflow: hidden;
}

header::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 80% 50%, rgba(194, 84, 45, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 20% 80%, rgba(194, 84, 45, 0.06) 0%, transparent 40%);
  pointer-events: none;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.1rem 2rem;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

header h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1;
}

header .subtitle {
  font-size: 0.78rem;
  font-weight: 400;
  opacity: 0.45;
  letter-spacing: 0.02em;
}

/* ===== FILTERS ===== */

#filters {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  gap: 0.75rem;
  align-items: end;
  max-width: 1400px;
  margin: 0 auto;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.filter-group label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.filter-group input,
.filter-group select {
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.filter-group input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.filter-group input:focus,
.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.plz-row,
.date-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.plz-row input { width: 5rem; }
.plz-row select { width: 5.5rem; }
.date-row input { width: 8.5rem; }
.date-row span {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.filter-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-light);
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

#event-count {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.view-toggle {
  display: flex;
  gap: 0.2rem;
}

.view-toggle button {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.view-toggle button:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.view-toggle button.active {
  background: var(--header-bg);
  color: var(--header-text);
  border-color: var(--header-bg);
}

/* ===== MAP ===== */

#map-container {
  padding: 0;
  max-width: 1400px;
  margin: 0 auto;
}

#map {
  height: 65vh;
  min-height: 420px;
}

.hidden { display: none !important; }

/* ===== TABLE ===== */

#list-container {
  padding: 0.75rem 2rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

#event-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
}

#event-table thead th {
  background: var(--surface-warm);
  text-align: left;
  padding: 0.7rem 0.9rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: relative;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}

th.sortable:hover {
  color: var(--text);
}

th.sortable::after {
  content: " \25B4\25BE";
  font-size: 0.6rem;
  opacity: 0.35;
  margin-left: 0.2rem;
}

th.sort-asc { color: var(--accent); }
th.sort-desc { color: var(--accent); }
th.sort-asc::after { content: " \25B2"; opacity: 0.8; }
th.sort-desc::after { content: " \25BC"; opacity: 0.8; }

#event-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background var(--transition);
}

#event-table tbody tr:last-child {
  border-bottom: none;
}

#event-table tbody tr:hover {
  background: var(--accent-light);
}

#event-table td {
  padding: 0.6rem 0.9rem;
  font-size: 0.84rem;
  vertical-align: middle;
  color: var(--text-secondary);
}

.td-date {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text);
}

.td-type {
  white-space: nowrap;
}

/* ===== TYPE BADGES ===== */

.type-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.type-RTF {
  background: #e3eed8;
  color: #3d6b2e;
}

.type-CTF {
  background: #d8e8ee;
  color: #2c5f73;
}

.type-Marathon {
  background: #eedbd8;
  color: #8b3a30;
}

.type-Radmarathon-Cup {
  background: #eedad8;
  color: #8b3a30;
  border: 1px solid #e0c6c2;
}

.type-Brevet {
  background: #eee7d2;
  color: #7a6628;
}

.type-Gravelride {
  background: #e4ddd4;
  color: #5c4e3c;
}

.type-Sonstige {
  background: #e9e5e0;
  color: #6b6158;
}

.type-default {
  background: #e9e5e0;
  color: #6b6158;
}

/* ===== DISTANCES & ELEVATION ===== */

.distances {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
}

.dist-chip {
  display: inline-block;
  background: var(--bg);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

.elevation {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ===== DETAIL PANEL ===== */

#event-detail:not(.hidden) .detail-backdrop {
  animation: fadeOverlay 0.25s ease forwards;
}

#event-detail:not(.hidden) .detail-panel {
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(42, 37, 32, 0.35);
  z-index: 999;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.detail-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(520px, 92vw);
  background: var(--surface);
  z-index: 1000;
  box-shadow: -6px 0 30px rgba(42, 37, 32, 0.18);
  overflow-y: auto;
  padding: 2rem;
}

.detail-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--surface-warm);
  border: 1px solid var(--border-light);
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  line-height: 1;
}

.detail-close:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.detail-content h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 400;
  margin-bottom: 0.5rem;
  padding-right: 2.5rem;
  line-height: 1.25;
  color: var(--text);
}

.detail-content .detail-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.detail-content dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.6rem 1.2rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
}

.detail-content dt {
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 0.1rem;
}

.detail-content dd {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.detail-content dd a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

.detail-content dd a:hover {
  border-bottom-color: var(--accent);
}

.detail-routes {
  margin-top: 1.5rem;
}

.detail-routes h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 400;
  margin-bottom: 0.6rem;
  color: var(--text);
}

.detail-routes table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.detail-routes th,
.detail-routes td {
  text-align: left;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--border-light);
}

.detail-routes th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-routes td {
  color: var(--text-secondary);
}

.detail-map {
  height: 220px;
  margin-top: 1.5rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

/* ===== FOOTER ===== */

footer {
  text-align: center;
  padding: 1.75rem 2rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

footer a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

footer a:hover {
  border-bottom-color: var(--accent);
}

/* ===== RESPONSIVE ===== */

/* 1200px: hide Ort */
@media (max-width: 1200px) {
  .hide-narrow { display: none; }
}

/* 1000px: filter grid collapses to 2 rows */
@media (max-width: 1000px) {
  .filter-row {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .hide-medium { display: none; }
}

/* 768px: tablet */
@media (max-width: 768px) {
  .header-inner { padding: 0.85rem 1rem; flex-wrap: wrap; gap: 0 0.75rem; }
  header h1 { font-size: 1.3rem; }

  #filters { padding: 0.75rem 1rem; }
  .filter-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }
  .filter-group input,
  .filter-group select { font-size: 16px; }

  #list-container { padding: 0.5rem 0.5rem 1rem; }
  #event-table td { padding: 0.45rem 0.5rem; font-size: 0.8rem; }
  #event-table thead th { padding: 0.6rem 0.5rem; }
  .hide-mobile { display: none; }

  .detail-panel { width: 100vw; padding: 1.5rem; }
  .detail-content h2 { font-size: 1.2rem; }

  footer { padding: 1.25rem 1rem; }
}

/* 480px: phone */
@media (max-width: 480px) {
  .filter-row {
    grid-template-columns: 1fr;
  }
  .date-row input { flex: 1; min-width: 0; }
  .hide-phone { display: none; }
}
