/* advplotter v1.0 - yellow theme (Australia) */
:root {
  --bg: #0f1214;
  --panel: #141a1c;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #d4a520;
  --accent-hover: #e6b82e;
  --chip: #2a2618;
  --green: #4caf50;
  --gravel: #22c55e;
  --sealed: #ef4444;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, Segoe UI, Roboto, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column
}

/* Header / Footer - matching advtracks exactly */
.site-header,
.site-footer {
  padding: 14px 18px;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px
}

.site-header.big .brand-row {
  display: flex;
  align-items: center;
  gap: 12px
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px
}

.logo {
  height: 40px;
  width: auto
}

.brand {
  font-weight: 400;
  font-size: 2rem
}

.ver {
  font-size: .9rem;
  color: var(--muted);
  margin-left: 6px
}

.site-nav a {
  color: var(--text);
  text-decoration: none;
  margin-left: 12px
}

.site-nav a:hover {
  text-decoration: underline
}

/* Footer - clean and minimal */
.site-footer {
  flex-direction: column;
  gap: 8px;
  text-align: center;
  border-top: 1px solid #2a2f36;
  padding: 16px 18px;
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
}

.footer-brand {
  color: var(--text);
  font-weight: 400;
}

.footer-links {
  display: flex;
  gap: 8px;
  align-items: center;
}

.footer-links a {
  color: var(--accent);
  text-decoration: none;
}

.footer-links a:hover {
  text-decoration: underline;
}

.footer-links .sep {
  color: var(--muted);
}

.osm-attribution {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.osm-attribution a {
  color: var(--accent);
  text-decoration: none;
}

.osm-attribution a:hover {
  text-decoration: underline;
}

/* Layout - matching advtracks */
.layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  grid-template-rows: 1fr;
  /* Force single row with fixed height */
  gap: 12px;
  padding: 12px;
  flex: 1;
  min-height: 0;
  height: calc(100vh - 140px);
  /* Fixed height based on header/footer */
  overflow: hidden;
  /* Prevent any content overflow from expanding the grid */
}

.map-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  /* Constrain to grid cell */
}

.map-container {
  position: relative;
  background: var(--panel);
  padding: 0;
  border-radius: 12px;
  border: 1px solid #2a2f36;
  flex: 1;
  overflow: hidden;
  min-height: 0;
  /* Allow flex item to shrink */
}

#map {
  width: 100% !important;
  height: 100% !important;
  position: absolute !important;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(0, 0, 0, .35);
}

/* Map controls - bottom left */
.map-controls {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 1000;
}

.map-controls button {
  background: var(--panel);
  border: 1px solid #2a2f36;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.map-controls button:hover {
  background: rgba(212, 165, 32, 0.15);
  border-color: var(--accent);
}

/* Disclaimer - cleaner styling */
.disclaimer {
  background: var(--panel);
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #2a2f36;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.disclaimer strong {
  color: var(--accent)
}

.disclaimer a {
  color: var(--accent);
  text-decoration: none
}

.disclaimer a:hover {
  text-decoration: underline
}

.disclaimer-mobile {
  display: none;
  margin-top: 12px
}

/* Tip styling */
.tip {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #2a2f36;
  font-size: 0.85rem;
  color: var(--muted);
}

.tip strong {
  color: var(--text)
}

.tip a {
  color: var(--accent);
  text-decoration: none
}

.tip a:hover {
  text-decoration: underline
}

/* Sidebar / Cards - matching advtracks */
.sidebar {
  background: transparent;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  /* Critical: allows flex/grid child to shrink below content size */
}

.sidebar .card,
.card {
  background: var(--panel);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid #2a2f36;
}

.sidebar .card {
  margin-bottom: 0;
}

.sidebar h3,
.card h3 {
  margin: 0 0 12px 0;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px
}

/* Form inputs - matching advtracks */
input,
select,
textarea {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #2a2f36;
  background: #0f1115;
  color: #e5e7eb
}

input::placeholder {
  color: var(--muted)
}

/* Point inputs */
.point-input {
  display: flex;
  gap: 8px;
  margin-bottom: 10px
}

.point-input input {
  flex: 1
}

.point-input .clear-btn {
  background: transparent;
  border: 1px solid #2a2f36;
  border-radius: 6px;
  color: var(--muted);
  padding: 0 12px;
  cursor: pointer;
  transition: all 0.2s;
  width: auto
}

.point-input .clear-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #ef4444
}

/* Waypoint inputs */
.waypoint-input {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  align-items: center
}

.waypoint-input.hidden {
  display: none
}

.waypoint-input input {
  flex: 1
}

.waypoint-input .clear-btn {
  background: transparent;
  border: 1px solid #2a2f36;
  border-radius: 6px;
  color: var(--muted);
  padding: 0 12px;
  cursor: pointer;
  transition: all 0.2s;
  width: auto
}

.waypoint-input .clear-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #ef4444
}

.waypoint-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: #3b82f6;
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  flex-shrink: 0;
}

/* Waypoint controls */
.waypoint-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.waypoint-controls .btn.small {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.waypoint-counter {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Button row */
.button-row {
  display: flex;
  gap: 8px;
}

.button-row .btn {
  flex: 1;
}

.button-row .btn.secondary {
  flex: 0 0 auto;
  padding: 12px 16px;
}

/* Buttons - matching advtracks */
.btn {
  display: inline-block;
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 12px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s
}

.btn:hover:not(:disabled) {
  filter: brightness(1.1)
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed
}

.btn.secondary {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent)
}

.btn.secondary:hover {
  background: rgba(45, 138, 78, 0.15)
}

/* Route stats */
#routeStats {
  display: none
}

#routeStats.visible {
  display: block
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #2a2f36
}

.stat-row:last-child {
  border-bottom: none
}

.stat-label {
  color: var(--muted)
}

.stat-value {
  font-weight: 600
}

.stat-value.gravel {
  color: var(--gravel)
}

.stat-value.sealed {
  color: var(--sealed)
}

/* Gravel bar */
.gravel-bar {
  height: 8px;
  background: var(--sealed);
  border-radius: 4px;
  margin: 12px 0;
  overflow: hidden
}

.gravel-bar .fill {
  height: 100%;
  background: var(--gravel);
  transition: width 0.5s ease
}

/* Instructions */
.instructions {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
  padding-left: 18px
}

.instructions li {
  margin-bottom: 6px
}

/* Legend - matching advtracks */
.legend {
  list-style: none;
  padding: 0;
  margin: 0
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0
}

.legend .legend-chip {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 4px
}

/* Loading */
.loading {
  display: none;
  text-align: center;
  padding: 20px
}

.loading.visible {
  display: block
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #2a2f36;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 12px
}

@keyframes spin {
  to {
    transform: rotate(360deg)
  }
}

/* Queue status */
.queue-status {
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: center
}

.queue-status .spinner {
  margin: 0
}

.queue-info {
  text-align: left;
  color: #e5e7eb
}

.queue-info strong {
  color: var(--accent)
}

.queue-position {
  font-size: 0.9em;
  color: #9ca3af;
  margin-top: 4px;
  display: inline-block
}

/* Error - improved styling for detailed messages */
.error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 12px;
  border-radius: 8px;
  margin-top: 12px;
  display: none;
  line-height: 1.5;
}

.error.visible {
  display: block
}

.error strong {
  color: #f87171;
  display: block;
  margin-bottom: 4px;
}

.error .error-tip {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9em;
  font-style: normal;
}

/* Container for standalone pages */
.container {
  max-width: 960px;
  margin: 24px auto;
  padding: 20px;
  background: var(--panel);
  border-radius: 12px
}

/* Feedback page styles */
.feedback-content {
  max-width: 800px;
  margin: 0 auto
}

.feedback-box {
  background: #1a1f26;
  padding: 24px;
  border-radius: 8px;
  margin: 24px 0;
  border-left: 4px solid #4a9eff
}

.feedback-box p {
  font-size: 1.1em;
  line-height: 1.6;
  margin: 16px 0
}

.feedback-box code {
  background: #0f1216;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 1em;
  color: #4a9eff
}

.email-btn {
  display: inline-block;
  background: #007bff;
  color: #fff;
  padding: 12px 24px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  margin-top: 20px;
  transition: background 0.2s ease;
  width: auto
}

.email-btn:hover {
  background: #0056b3
}

/* Plotting form (renamed from routing) */
.plotting-form {
  display: flex;
  flex-direction: column;
  gap: 10px
}

.plotting-result {
  margin-top: 10px;
  padding: 10px;
  background: #1a2026;
  border-radius: 8px
}

/* Data Info Section - above footer */
.data-info {
  background: var(--panel);
  border-top: 1px solid #2a2f36;
  padding: 10px 18px;
  text-align: center;
}

.data-info-content {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.data-info-item strong {
  color: var(--text);
  font-weight: 500;
}

.data-info-sep {
  color: #3a4046;
}

/* Ads - shared with advtracks */
.ad-top,
.ad-bottom {
  display: block;
  width: 100%;
  background: #0b0b0c;
  text-align: center
}

.ad-top a,
.ad-bottom a {
  display: inline-block
}

.ad-top img,
.ad-bottom img {
  width: 100%;
  max-width: 1200px;
  height: 200px;
  object-fit: scale-down;
  border-radius: 0
}

.ad-top.hidden,
.ad-bottom.hidden {
  display: none
}

/* Mobile responsive */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    padding: 8px;
    gap: 8px;
    height: auto
  }

  .map-wrap {
    padding: 0;
    height: auto
  }

  .map-container {
    min-height: 65vh;
    height: 65vh
  }

  .sidebar {
    border-top: 1px solid #2a2f36;
    padding-top: 8px
  }

  .site-header {
    flex-direction: column;
    gap: 10px
  }

  .site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center
  }

  .site-nav a {
    margin-left: 0
  }

  .map-wrap>.disclaimer {
    display: none
  }

  .disclaimer-mobile {
    display: block;
    font-size: 0.8rem
  }

  .footer-links {
    flex-wrap: wrap;
    justify-content: center
  }

  .data-info-content {
    flex-direction: column;
    gap: 4px
  }

  .data-info-sep {
    display: none
  }

  /* Mobile ads */
  .ad-top img,
  .ad-bottom img {
    height: auto;
    max-height: 150px
  }
}

/* Mobile landscape - map takes 2/3 of viewport */
@media (max-width: 900px) and (orientation: landscape) {
  .layout {
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 1fr;
    height: calc(100vh - 120px)
  }

  .map-wrap {
    height: 100%
  }

  .map-container {
    min-height: unset;
    height: 100%
  }

  .sidebar {
    border-top: none;
    border-left: 1px solid #2a2f36;
    padding-top: 0;
    padding-left: 8px;
    overflow-y: auto
  }
}

/* Leaflet Layer Control - Dark Theme */
.leaflet-control-layers {
  border: none !important;
  border-radius: 8px !important;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4) !important;
}

.leaflet-control-layers-toggle {
  width: 36px !important;
  height: 36px !important;
  background-color: var(--panel) !important;
  border-radius: 8px !important;
}

.leaflet-control-layers-expanded {
  background: var(--panel) !important;
  color: var(--text) !important;
  padding: 8px 12px !important;
}

.leaflet-control-layers-selector {
  accent-color: var(--accent) !important;
}

.leaflet-control-layers-separator {
  border-top-color: #2a2f36 !important;
  margin: 6px 0 !important;
}