/* Rowing Courses — Leaflet map browser */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f5;
}

#app {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar map";
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

header {
  grid-area: header;
  padding: 0.75rem 1rem;
  background: #1a3a4a;
  color: #fff;
  position: relative;
}

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.header-brand {
  flex: 1 1 auto;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Site title link — avoid browser :visited purple on dark header */
header h1 a:link,
header h1 a:visited {
  color: #fff;
  text-decoration: none;
}

header h1 a:hover {
  text-decoration: underline;
}

header .logo {
  height: 1.75em;
  width: auto;
  vertical-align: middle;
}

.tagline {
  margin: 0;
  font-size: 0.875rem;
  opacity: 0.9;
}

/* Hamburger button — visible on mobile only */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 4px;
  cursor: pointer;
  color: #fff;
}

.hamburger span {
  display: block;
  width: 1.25rem;
  height: 2px;
  background: currentColor;
  margin: 0 auto;
  transition: transform 0.2s, opacity 0.2s;
}

.hamburger[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.hamburger[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}

.hamburger[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

#auth-status {
  margin-top: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

#auth-status a:link,
#auth-status a:visited {
  color: #7dd;
}

/* Toggled visibility site-wide. !important beats #auth-status a (otherwise links stay visible). */
.hidden {
  display: none !important;
}

/* Nav overlay — slide-out on mobile */
.nav-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(20rem, 85vw);
  background: #1a3a4a;
  padding: 1rem;
  z-index: 1100;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.nav-overlay[aria-hidden="false"] {
  transform: translateX(0);
}

.nav-overlay .nav-overlay-backdrop {
  display: none;
}

.nav-overlay #auth-status {
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

.nav-overlay #auth-status a {
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.nav-overlay .auth-teaser {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

/* Desktop: nav inline, no overlay */
@media (min-width: 768px) {
  .hamburger {
    display: none !important;
  }

  .nav-overlay {
    position: static;
    width: auto;
    transform: none;
    padding: 0;
    background: transparent;
    overflow: visible;
  }

  .nav-overlay #auth-status {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .nav-overlay #auth-status a {
    padding: 0;
    border-bottom: none;
  }

  .nav-overlay .auth-teaser {
    width: 100%;
    margin-top: 0.35rem;
    padding-top: 0;
    border-top: none;
  }
}

/* Mobile: hamburger visible, nav in overlay */
@media (max-width: 767px) {
  .hamburger {
    display: flex;
  }

  .nav-overlay {
    padding-top: 3.5rem;
  }

  .nav-overlay .nav-overlay-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: -1;
  }
}

.load-error-banner {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: #b52;
  color: #fff;
  border-radius: 4px;
  font-size: 0.875rem;
}

.auth-teaser {
  font-size: 0.8rem;
  color: #888;
  margin: 0.35rem 0 0;
}

aside#sidebar {
  grid-area: sidebar;
  padding: 1rem;
  background: #fff;
  border-right: 1px solid #ddd;
  overflow-y: auto;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.controls input[type="search"] {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.controls select {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.filter-row {
  display: flex;
  gap: 1rem;
}

.filter-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
}

.distance-filter label {
  display: block;
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
}

.distance-filter select {
  width: 100%;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: #555;
}

.map-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.map-legend .legend-item.hidden {
  display: none;
}

.map-legend .legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #333;
  flex-shrink: 0;
}

.map-legend .legend-dot.liked {
  background: #c66;
}

.map-legend .legend-dot.established {
  background: #0a7;
}

.map-legend .legend-dot.provisional {
  background: #fa0;
}

#map .leaflet-control-layers-high-contrast {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.45rem 0 0;
  padding-top: 0.4rem;
  border-top: 1px solid #ddd;
  font-size: 0.875rem;
  font-weight: normal;
  cursor: pointer;
  color: #333;
}

#map .leaflet-control-layers-high-contrast input {
  cursor: pointer;
}

/* Mute base map when high contrast is on (main map + challenge list / leaderboard) */
#map.high-contrast .leaflet-tile-pane,
.map-high-contrast .leaflet-tile-pane {
  filter: grayscale(0.6) contrast(0.9);
}

.liked-courses {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eee;
}

.liked-courses.hidden {
  display: none;
}

.liked-courses-title {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #333;
}

.liked-courses ul {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 12rem;
  overflow-y: auto;
}

.liked-courses li {
  margin: 0.25rem 0;
}

.liked-course-link {
  font-size: 0.875rem;
  color: #1a73e8;
  text-decoration: none;
}

.liked-course-link:hover {
  text-decoration: underline;
}

.liked-courses-empty {
  font-size: 0.8rem;
  color: #666;
  font-style: italic;
}

main {
  grid-area: map;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 400px;
}

/* Layer control is rendered inside #map .leaflet-container (bottom-left) */
#map .leaflet-control-layers {
  background: #fff;
  color: #333;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
  line-height: 1.35;
}

#map .leaflet-control-layers-expanded {
  padding: 0.35rem 0.5rem;
}

#right-panels {
  position: fixed;
  top: 5.5rem;
  right: 1rem;
  width: 320px;
  max-width: 90vw;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  z-index: 1000;
}

#detail-panel {
  padding: 1rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

#detail-panel.hidden {
  display: none;
}

#close-detail {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  color: #666;
}

#close-detail:hover {
  color: #000;
}

#detail-content h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

#detail-content p {
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

#detail-content .course-id {
  padding: 0.35rem 0.5rem;
  background: #f0f4f8;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
}

#detail-content .course-id code {
  font-weight: 600;
}

.detail-course-times {
  margin: 0.75rem 0 0;
  padding: 0.75rem;
  background: #f8fafc;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

.detail-course-times ul {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}

.detail-course-times .detail-time-link {
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

.detail-course-times .detail-time-remove {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem;
  margin-left: 0.5rem;
  color: #666;
  vertical-align: middle;
}

.detail-course-times .detail-time-remove:hover {
  color: #c00;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
}

.badge.established {
  background: #cfc;
  color: #262;
}

.badge.provisional {
  background: #ffc;
  color: #662;
}

.notes {
  color: #555;
  font-size: 0.85rem;
}

.btn {
  display: inline-block;
  padding: 0.5rem 0.75rem;
  margin-right: 0.5rem;
  margin-top: 0.5rem;
  background: #1a3a4a;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
}

.btn:hover {
  background: #2a4a5a;
}

.like-btn.liked {
  background: #c66;
}

.like-btn.liked:hover {
  background: #a55;
}

.error {
  color: #c00;
}

.success {
  color: #262;
}

.btn-secondary {
  background: #888;
}

.btn-secondary:hover {
  background: #777;
}

.validation-note {
  font-size: 0.75rem;
  white-space: pre-wrap;
  max-height: 10em;
  overflow-y: auto;
  margin-top: 0.5rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

/* Calculate panel: fixed overlay on map, positioned below course detail */
.calculate-panel {
  position: fixed;
  top: 0;
  right: 1rem;
  width: 320px;
  max-width: 90vw;
  z-index: 1000;
}

.calculate-panel.hidden {
  display: none;
}

.calculate-panel .modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
}

.calculate-panel .modal-content {
  position: relative;
  z-index: 1001;
}

.modal-content {
  position: relative;
  background: #fff;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  max-width: 420px;
  width: 90%;
}

.modal-content h3 {
  margin: 0 0 1rem;
}

.modal-content select {
  width: 100%;
  padding: 0.5rem;
  margin: 0.5rem 0 1rem;
}

.modal-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

@media (max-width: 600px) {
  #app {
    grid-template-areas:
      "header"
      "sidebar"
      "map";
    grid-template-columns: 1fr;
  }

  aside#sidebar {
    border-right: none;
    border-bottom: 1px solid #ddd;
  }
}
