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

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --text: #e8edf4;
  --text-muted: #9aa8bc;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border: #2d3a4f;
  --danger: #ef4444;
  --pesapallo: #22c55e;
  --tractor: #f97316;
  --ralli: #ef4444;
  --muu: #8b5cf6;
  --map-height: 55vh;
  --panel-height: 45vh;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: var(--accent);
}

/* Layout – päänäkymä */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.app-header .nav-link {
  font-size: 0.9rem;
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  background: var(--surface-2);
}

.app-header .nav-link:hover {
  background: var(--accent);
  color: #fff;
}

.map-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#map {
  flex: 1;
  min-height: 300px;
  z-index: 1;
}

.bottom-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: var(--panel-height);
  overflow: hidden;
}

/* Timeline */

.timeline-controls {
  padding: 0.75rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.timeline-date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.timeline-date {
  font-size: 1rem;
  font-weight: 600;
}

.timeline-nav {
  display: flex;
  gap: 0.25rem;
}

.timeline-nav button,
.view-mode button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.timeline-nav button:hover,
.view-mode button:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.view-mode {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.5rem;
}

.view-mode button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#date-slider {
  width: 100%;
  margin: 0.25rem 0;
  accent-color: var(--accent);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Tapahtumalista */

.event-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1rem 1rem;
}

.event-list h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.event-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.event-item:hover {
  background: var(--surface-2);
  margin: 0 -0.5rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  border-radius: 6px;
}

.event-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}

.event-dot.pesapallo { background: var(--pesapallo); }
.event-dot.tractor_pulling { background: var(--tractor); }
.event-dot.ralli { background: var(--ralli); }
.event-dot.muu { background: var(--muu); }

.event-info {
  flex: 1;
  min-width: 0;
}

.event-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.event-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 1rem 0;
}

/* Leaflet markerit */

.category-marker {
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.category-marker.pesapallo { background: var(--pesapallo); }
.category-marker.tractor_pulling { background: var(--tractor); }
.category-marker.ralli { background: var(--ralli); }
.category-marker.muu { background: var(--muu); }

.leaflet-popup-content {
  margin: 0.6rem 0.8rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.popup-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.popup-category {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--surface-2);
  margin-bottom: 0.35rem;
}

/* Admin-sivu */

.admin-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

.admin-page h1 {
  margin: 0 0 1rem;
  font-size: 1.4rem;
}

.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.form-section h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.form-group {
  margin-bottom: 0.75rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

#admin-map {
  height: 220px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-top: 0.5rem;
}

.search-results {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.search-results li {
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.search-results li:hover {
  background: var(--surface-2);
}

.search-results li:last-child {
  border-bottom: none;
}

.coords-display {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.admin-event-list .event-item {
  align-items: center;
}

.admin-event-list .event-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.admin-event-list .btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.status-msg {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.status-msg.success {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

.status-msg.error {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

@media (min-width: 768px) {
  :root {
    --map-height: 60vh;
    --panel-height: 40vh;
  }

  .map-page {
    flex-direction: row;
    flex-wrap: wrap;
  }

  #map {
    width: 65%;
    height: calc(100vh - 48px);
  }

  .bottom-panel {
    width: 35%;
    max-height: calc(100vh - 48px);
    border-top: none;
    border-left: 1px solid var(--border);
  }
}

@media (max-width: 480px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}
