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

:root {
  --sidebar-w: 320px;
  --color-m: #3b82f6;
  --color-f: #ec4899;
  --color-x: #8b5cf6;
  --color-none: #6b7280;
  --radius: 8px;
  --font: system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  display: flex;
  height: 100dvh;
  overflow: hidden;
  background: #f1f5f9;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  overflow: hidden;
  z-index: 10;
}

#sidebar header {
  padding: 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #1e293b;
  color: #fff;
}

#sidebar header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#count-label {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-top: 2px;
}

/* ── Filters ── */
#filters {
  padding: 12px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-group label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-bottom: 4px;
}

.btn-group {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.btn-group button {
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
  background: #fff;
  font-size: 0.78rem;
  cursor: pointer;
  color: #334155;
  transition: all 0.15s;
}

.btn-group button:hover { background: #f1f5f9; }
.btn-group button.active {
  background: #1e293b;
  color: #fff;
  border-color: #1e293b;
}

select {
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid #cbd5e1;
  font-size: 0.82rem;
  background: #fff;
  color: #334155;
  cursor: pointer;
}

#reset-filters {
  padding: 6px 12px;
  border-radius: var(--radius);
  border: none;
  background: #f1f5f9;
  color: #64748b;
  font-size: 0.78rem;
  cursor: pointer;
  align-self: flex-start;
  transition: background 0.15s;
}
#reset-filters:hover { background: #e2e8f0; }

/* ── Tournament list ── */
#tournament-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 8px;
}

#tournament-list li {
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 4px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}

#tournament-list li:hover { background: #f8fafc; }
#tournament-list li.active { background: #eff6ff; border-left-color: #3b82f6; }

.t-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #1e293b;
  line-height: 1.3;
}

.t-meta {
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 3px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.67rem;
  font-weight: 600;
  color: #fff;
}
.badge-M { background: var(--color-m); }
.badge-F { background: var(--color-f); }
.badge-X { background: var(--color-x); }
.badge-  { background: var(--color-none); }

/* ── Period grid ── */
.period-grid {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 4px;
  align-items: center;
}

.period-lbl {
  font-size: 0.75rem;
  color: #64748b;
  font-weight: 500;
}

/* ── Map ── */
#map {
  flex: 1;
  height: 100%;
}

/* ── Popup ── */
#popup {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 280px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  padding: 16px;
  z-index: 100;
  transition: opacity 0.2s, transform 0.2s;
}

#popup.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

#popup-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: #94a3b8;
}

#popup-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: #1e293b;
  padding-right: 20px;
  margin-bottom: 10px;
  line-height: 1.3;
}

#popup-details {
  font-size: 0.78rem;
  color: #475569;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#popup-details .row {
  display: flex;
  gap: 6px;
}

#popup-details .row .lbl {
  color: #94a3b8;
  min-width: 60px;
}

/* ── Footer ── */
footer {
  padding: 8px 12px;
  font-size: 0.68rem;
  color: #94a3b8;
  border-top: 1px solid #e2e8f0;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  body { flex-direction: column; }
  #sidebar {
    width: 100%;
    height: 45dvh;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
    overflow-y: auto;
  }
  #tournament-list { overflow-y: visible; }
  #map { height: 55dvh; flex: unset; }
  #popup { bottom: auto; top: 45dvh; right: 0; left: 0; width: 100%; border-radius: 0; }
}
