/*
  Theme colours for light and dark mode.
  Everything else in this file uses these variables, so switching the
  .dark-mode class on the body changes the whole look at once.
*/
:root {
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --text: #1f2733;
  --muted: #6c7a89;
  --border: #e4e9f0;
  --accent: #000000;
  --page: #dfe6ef;
  --shadow: 0 10px 30px rgba(18, 38, 63, 0.18);
  --shadow-sm: 0 4px 14px rgba(18, 38, 63, 0.12);
  --radius: 16px;
}

body.dark-mode {
  --surface: #1d2531;
  --surface-2: #283142;
  --text: #e8edf4;
  --muted: #9aa7b6;
  --border: #34405200;
  --border: #344052;
  --accent: #ffffff;
  --page: #11161f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.45);
}

/*
  This makes the page use the full browser height.
  It also removes the default space around the page.
*/
html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background-color: var(--page);
}

/*
  These elements change colour with the theme, so a gentle transition
  keeps the switch between light and dark mode smooth.
*/
.modal-content,
.list-group-item,
.form-control,
.input-group-text,
.table,
#selectContainer,
#themeToggle,
.leaflet-bar button {
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

/*
  This makes the Leaflet map fill all the screen.
*/
#map {
  bottom: 0;
  height: 100vh;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  width: 100vw;
  background-color: var(--page);
}

/*
  In dark mode the light map tiles are recoloured to a dark style.
  Only the tile layer is filtered, so markers and labels stay correct.
*/
body.dark-mode .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9) grayscale(0.15);
}

/*
  This puts the country select box at the top centre of the map.
  It stays above the map because of the z-index.
*/
#selectContainer {
  left: 50%;
  max-width: 440px;
  position: absolute;
  top: 12px;
  transform: translateX(-50%);
  z-index: 1000;
  background-color: var(--surface) !important;
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  padding: 5px 8px !important;
  display: flex;
  align-items: center;
  gap: 8px;
}

#countrySelect {
  border: none;
  background-color: transparent;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 0;
}

#countrySelect:focus {
  box-shadow: none;
}

body.dark-mode #countrySelect option {
  background-color: var(--surface);
  color: var(--text);
}

/*
  This is the round button that switches between light and dark mode.
  It sits in the top right corner, clear of the other map controls.
*/
#themeToggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 20%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.15rem;
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

#themeToggle:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

/*
  This is the full screen loader.
  It covers the page while the first country data is loading.
*/
#preloader {
  height: 100%;
  left: 0;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 2000;
  background-color: var(--surface) !important;
  color: var(--text);
}

/*
  This makes sure the loader is really hidden when d-none is added.
*/
#preloader.d-none {
  display: none !important;
}

/*
  Bootstrap modal centering fix - ensure modals display as flexbox when shown.
*/
.modal.show {
  display: flex !important;
  align-items: center;
  justify-content: center;
}

/*
  This is the small warning message at the bottom of the screen.
*/
#statusBox {
  bottom: 20px;
  left: 50%;
  max-width: 420px;
  position: absolute;
  transform: translateX(-50%);
  width: 90%;
  z-index: 1000;
  border: none;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

/* 
   Modals: rounded, soft shadow, and theme aware bodies.
*/
.modal-content {
  border: none;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background-color: var(--surface);
  color: var(--text);
}

.modal-header {
  border-bottom: none;
  padding: 1rem 1.25rem;
}

.modal-title {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.modal-body {
  background-color: var(--surface);
  color: var(--text);
}

/* The close cross stays visible on the coloured headers. */
.modal-header .close {
  opacity: 0.9;
  text-shadow: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.modal-header .close:hover {
  opacity: 1;
  transform: scale(1.1);
}

/* 
  Tables, lists, badges and inputs follow the theme colours. 
*/
.table {
  color: var(--text);
}

.list-group-item {
  background-color: transparent;
  color: var(--text);
  border-color: var(--border);
}

.list-group-item-action:hover {
  background-color: var(--surface-2);
}

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

.form-control {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--border);
  border-radius: 10px;
}

.form-control:focus {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.18);
}

.form-control::placeholder {
  color: var(--muted);
}

.input-group-text {
  background-color: var(--surface-2);
  color: var(--muted);
  border-color: var(--border);
}

body.dark-mode .text-muted {
  color: var(--muted) !important;
}

body.dark-mode .border-top {
  border-color: var(--border) !important;
}

body.dark-mode textarea[readonly],
body.dark-mode input[readonly] {
  background-color: var(--surface-2);
}

/* 
  Buttons get a small lift on hover for a more tactile feel. 
*/
.btn {
  border-radius: 10px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

/*
  This keeps the flag image from becoming too tall inside the modal.
*/
.flagImage {
  max-height: 130px;
  border-radius: 10px;
}

/*
  Leaflet ExtraMarkers (v1.2.1) was built for Font Awesome 4/5, so its
  rule that drops the icon into the centre of the pin only targets the
  old class names (i.fa, i.fas, i.far...). This project uses Font Awesome
  6 (fa-solid / fa-regular / fa-brands), which those selectors miss, so
  the icon sat about 3px too high. These rules centre the FA6 glyph both
  ways inside the round marker.
*/
.extra-marker i.fa-solid,
.extra-marker i.fa-regular,
.extra-marker i.fa-brands {
  position: absolute;
  left: 0;
  width: 35px;
  margin-top: 10px;
  text-align: center;
}
.leaflet-bar {
  border: none !important;
  border-radius: 20%;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.leaflet-bar button,
.leaflet-bar button:hover,
.leaflet-bar a,
.leaflet-touch .leaflet-bar button,
.leaflet-touch .leaflet-bar a {
  height: 36px;
  width: 36px;
  line-height: 36px;
  border-radius: 20%;
  background-color: var(--surface);
  color: var(--text);
  border-bottom-color: var(--border);
}

.leaflet-bar button:hover,
.leaflet-bar a:hover {
  background-color: var(--surface-2);
  color: var(--accent);
}

.leaflet-control-layers,
.leaflet-control-attribution {
  border-radius: 10px;
  background-color: var(--surface) !important;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border) !important;
}

/*
  The layers control sits in the top right, the same corner as the theme
  toggle, so it is pushed down to sit just below the toggle button.
*/
.leaflet-right .leaflet-control-layers {
  margin-top: 62px;
}

/* ----------------------------------------------------------------------
   Polished layers menu: heading, hover rows, coloured checkboxes,
   sliding unit switches with the active unit highlighted.
---------------------------------------------------------------------- */
.leaflet-control-layers-expanded {
  padding: 12px 14px !important;
  min-width: 216px;
}

/* Little uppercase heading above the extra options. */
.layers-heading {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 2px 6px 8px;
}

.layers-heading i {
  margin-right: 6px;
  opacity: 0.8;
}

/* Each option is a rounded row that highlights on hover. */
.leaflet-control-layers-overlays label {
  display: flex;
  align-items: center;
  margin: 2px 0;
  padding: 7px 9px;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.leaflet-control-layers-overlays label:hover {
  background-color: var(--surface-2);
}

/* The native Cities / Airports / Show all cities checkboxes. */
.leaflet-control-layers-selector {
  width: 17px;
  height: 17px;
  margin-right: 9px;
  accent-color: #0d6efd;
  cursor: pointer;
}

.leaflet-control-layers-separator {
  margin: 9px 2px;
  border-top: 1px solid var(--border);
}

/* Sliding on/off switch built from a hidden checkbox. */
.layer-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex: 0 0 auto;
}

.layer-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.layer-slider {
  position: absolute;
  inset: 0;
  background-color: #9aa7b6;
  border-radius: 999px;
  transition: background-color 0.25s ease;
}

.layer-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background-color: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.25s ease;
}

/* The switch keeps the same colour on and off; only the knob slides. */
.layer-switch input:checked + .layer-slider::before {
  transform: translateX(18px);
}

/* Unit switch with a label on each side: KM [ o] ML, °C [ o] °F. */
.unit-toggle {
  justify-content: center;
  gap: 10px;
}

.unit-label {
  font-weight: 600;
  color: var(--muted);
  min-width: 26px;
  text-align: center;
  transition: color 0.2s ease, font-weight 0.2s ease;
}

.unit-label.unit-active {
  color: #2f9e44;
  font-weight: 800;
}

/*
  When collapsed, the layers control is a round button like the theme toggle.
  The .leaflet-touch selectors keep it round on phones and tablets too.
*/
.leaflet-control-layers.leaflet-control-layers-collapsed,
.leaflet-touch .leaflet-control-layers.leaflet-control-layers-collapsed {
  width: 44px;
  height: 44px;
  border-radius: 20% !important;
}

.leaflet-control-layers-toggle,
.leaflet-touch .leaflet-control-layers-toggle {
  width: 44px;
  height: 44px;
  border-radius: 20%;
  background-color: var(--surface);
  background-size: 22px 22px;
}

body.dark-mode .leaflet-control-attribution a {
  color: var(--accent);
}

/*
  On small screens the Leaflet controls need to move down.
  This stops them from sitting over the country select box.
*/
@media (max-width: 560px) {
  .leaflet-top {
    top: 70px;
  }

  #themeToggle {
    top: 80px;
  }

  #selectContainer {
    width: 94%;
  }
}
