/* =========================
   Base layout
   ========================= */
html, body {
  height: 100%;
  margin: 0;
  font-family: system-ui, sans-serif;
  overflow-x: hidden;
}

/* =========================
   Top bar
   ========================= */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: #1f2937;
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* =========================
   Layout (2 columns only)
   ========================= */
.layout {
  height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
  overflow: hidden;
}

/* =========================
   Sidebar
   ========================= */
.sidebar {
  background: #1f2937;
  color: #e5e7eb;
  padding: 16px;
  overflow-y: auto;
}

/* =========================
   Map
   ========================= */
.mapwrap {
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

/* =========================
   Cards
   ========================= */
.card {
  background: #111827;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.25),
    0 2px 6px rgba(0,0,0,0.4);
}

.card h3 {
  margin: 0 0 10px 0;
  color: #f9fafb;
  font-size: 1rem;
}

/* =========================
   Layer card
   ========================= */
.layer-card {
  border: 1px solid rgba(255,255,255,0.12);
}

/* =========================
   Basemap block
   ========================= */
.basemap-box {
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: rgba(0,0,0,0.15);
}

.basemap-row {
  display: flex;
  align-items: center;
}

.basemap-label {
  margin-right: 20px;
  color: #cbd5f5;
  font-size: 0.9rem;
  white-space: nowrap;
}

#basemapSelect {
  flex: 1;
  background: #020617;
  color: #f9fafb;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

#basemapSelect:focus {
  outline: none;
  border-color: #3b82f6;
}

/* =========================
   Rows (switches)
   ========================= */
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0;
}

/* =========================
   Info text
   ========================= */
.info {
  font-size: 0.9rem;
  color: #e5e7eb;
  white-space: pre-wrap;
}

/* =========================
   Buttons
   ========================= */
.btn {
  background: #374151;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
}

.btn:hover {
  background: #4b5563;
}

.sql-btn {
  width: 100%;
  margin-top: 8px;
}

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

/* =========================
   Cancel coastline button
   ========================= */
#cancelCoastlineBtn {
  margin-top: 16px;
  min-width: 120px;
}

/* =========================
   Switch
   ========================= */
.switch {
  position: relative;
  width: 36px;
  height: 20px;
}

.switch input {
  display: none;
}

.slider {
  position: absolute;
  inset: 0;
  background: #374151;
  border-radius: 20px;
  cursor: pointer;
}

.slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background: #3b82f6;
}

.switch input:checked + .slider::before {
  transform: translateX(16px);
}

/* =========================
   Mouse coordinates overlay
   ========================= */
.mouse-coords {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 999;
  background: #1f2937;
  color: #e5e7eb;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.2;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  cursor: pointer;
  user-select: none;
}

/* =========================
   Notable coordinates
   ========================= */
.mk-item {
  margin-top: 10px;
}

.mk-label {
  font-size: 0.9rem;
  color: #e5e7eb;
  margin-bottom: 6px;
}

/* =========================
   Overlay
   ========================= */
.legal-overlay {
  position: absolute;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.legal-overlay.hidden {
  display: none;
}

.legal-box {
  background: #1f2937;
  color: #e5e7eb;
  padding: 20px 24px;
  border-radius: 10px;

  width: 800px;
  max-width: 90vw;

  max-height: 70vh;
  overflow-y: auto;

  text-align: center;
  pointer-events: auto;

  border: 1px solid rgba(255,255,255,0.12);

  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.25),
    0 10px 30px rgba(0,0,0,0.3);
}

.scientific-box {
  text-align: left;
}

.scientific-box h3 {
  margin: 0 0 14px 0;
  text-align: center;
  font-weight: 700;
}

.scientific-box h4 {
  color: #f9fafb;
  font-weight: 700;
  text-align: left;
}

.scientific-box p {
  text-align: left;
}

.scientific-box a.scientific-link,
.scientific-box a.scientific-link:visited {
  color: #f9fafb !important;
  font-weight: 700;
  text-decoration: none;
}

.scientific-box a.scientific-link:hover,
.scientific-box a.scientific-link:focus {
  color: #ffffff !important;
  text-decoration: underline;
}

#loadingOverlay {
  pointer-events: all;
}

/* =========================
   Logo
   ========================= */
.logo-container {
  margin-bottom: 8px;
  padding: 0 4px;
}

.logo {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.25),
    0 2px 6px rgba(0,0,0,0.4);
}

/* =========================
   University logo
   ========================= */
.uni-logo {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;

  background: #ffffff;

  padding: 10px;
  box-sizing: border-box;

  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);

  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.25),
    0 2px 6px rgba(0,0,0,0.4);
}

/* =========================
   Responsive layout
   ========================= */
@media (max-width: 768px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
  }

  .layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .mapwrap {
    order: -1;
    width: 100%;
    height: clamp(360px, 62dvh, 620px);
    min-height: 360px;
    flex: 0 0 auto;
  }

  .sidebar {
    width: 100%;
    padding: 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    box-sizing: border-box;
    overflow: visible;
  }

  .logo-container,
  .card {
    margin-bottom: 7px;
  }

  .logo-container {
    padding: 0;
  }

  .basemap-row {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .basemap-label {
    margin-right: 0;
  }

  #basemapSelect,
  .btn {
    min-height: 44px;
    font-size: 1rem;
  }

  .switch {
    width: 44px;
    height: 24px;
  }

  .slider::before {
    width: 20px;
    height: 20px;
  }

  .switch input:checked + .slider::before {
    transform: translateX(20px);
  }

  .mouse-coords {
    top: 10px;
    right: 10px;
    max-width: calc(100% - 68px);
    box-sizing: border-box;
    font-size: 0.75rem;
  }

  .legal-overlay {
    position: fixed;
    padding: max(12px, env(safe-area-inset-top)) 12px
      max(12px, env(safe-area-inset-bottom));
    box-sizing: border-box;
  }

  .legal-box {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 24px);
    padding: 18px 16px;
    box-sizing: border-box;
  }

  .leaflet-control-container .leaflet-bottom {
    bottom: 4px;
  }
}

@media (max-width: 380px) {
  .mapwrap {
    height: 55dvh;
    min-height: 320px;
  }

  .sidebar {
    padding-inline: 10px;
  }

  .card {
    padding: 12px;
  }
}
