/* =====================================================
   STYLE: the style RULES of the page (what goes where).
   There are no colors, sizes or fonts to tweak here: all of them live in
   settings/visual.js (see the "Where do I change...?" table at the top of
   that file). map.js reads them when the page opens and hands them to the rules
   below as CSS variables (--text-size, --accent, --pin-size...).
   The only things written here are the font FILES (@font-face below) and the
   screen width where the menu becomes a drawer (@media at the bottom).
   ===================================================== */
/* inter-regular - latin */
@font-face {
  font-display: swap; /* Check https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display for other options. */
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  src: url('fonts/inter-v20-latin-regular.woff2') format('woff2'); /* Chrome 36+, Opera 23+, Firefox 39+, Safari 12+, iOS 10+ */
}
/* inter-500 - latin */
@font-face {
  font-display: swap; /* Check https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display for other options. */
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  src: url('fonts/inter-v20-latin-500.woff2') format('woff2'); /* Chrome 36+, Opera 23+, Firefox 39+, Safari 12+, iOS 10+ */
}
/* inter-600 - latin */
@font-face {
  font-display: swap; /* Check https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display for other options. */
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  src: url('fonts/inter-v20-latin-600.woff2') format('woff2'); /* Chrome 36+, Opera 23+, Firefox 39+, Safari 12+, iOS 10+ */
}
/* inter-700 - latin */
@font-face {
  font-display: swap; /* Check https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display for other options. */
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  src: url('fonts/inter-v20-latin-700.woff2') format('woff2'); /* Chrome 36+, Opera 23+, Firefox 39+, Safari 12+, iOS 10+ */
}

/* space-grotesk-500 - latin */
@font-face {
  font-display: swap; /* Check https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display for other options. */
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 500;
  src: url('fonts/space-grotesk-v22-latin-500.woff2') format('woff2'); /* Chrome 36+, Opera 23+, Firefox 39+, Safari 12+, iOS 10+ */
}
/* space-grotesk-600 - latin */
@font-face {
  font-display: swap; /* Check https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display for other options. */
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 600;
  src: url('fonts/space-grotesk-v22-latin-600.woff2') format('woff2'); /* Chrome 36+, Opera 23+, Firefox 39+, Safari 12+, iOS 10+ */
}

/* ---------- PAGE LAYOUT ---------- */
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  font-size: var(--text-size);
  color: var(--text);
  background: var(--bg-sidebar);
  -webkit-font-smoothing: antialiased;
}

/* The map fills everything to the right of the sidebar */
#map {
  position: absolute; top: 0; right: 0; bottom: 0; left: var(--sidebar-width);
  background: var(--bg-map);
  font-family: var(--font-body);
}

/* While the ruler or route tool is on, clicks go straight to the map */
#map.tool-active,
#map.tool-active .leaflet-interactive { cursor: crosshair !important; }
#map.tool-active .leaflet-interactive { pointer-events: none !important; }

/* ---------- SIDEBAR ---------- */
#sidebar, #sidebar * { box-sizing: border-box; }
#sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 1200;
  width: var(--sidebar-width);
  display: flex; flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  color-scheme: dark;   /* makes native controls (scrollbars, dropdowns) dark */
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 24px 20px 18px;
}
.sidebar-header h1 {
  margin: 0; font-family: var(--font-heading); font-size: var(--title-size);
  font-weight: 600; letter-spacing: -0.01em; line-height: 1.2;
}

.sidebar-body {
  flex: 1; overflow-y: auto; padding: 0 20px 28px;
  scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent;
}

.section { margin-top: 26px; }
.section-title {
  margin: 0 0 8px; font-size: var(--label-size); font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-muted);
}

/* Inputs and dropdowns */
.field {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-ui);
}
.field::placeholder { color: var(--text-muted); }
.field:focus { outline: none; border-color: var(--accent); }

/* Search: the field and the list of results under it */
.search-wrap { position: relative; }
#search-results {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1300;
  max-height: 320px; overflow-y: auto; padding: 4px;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-ui);
  box-shadow: var(--shadow-medium);
}
.search-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 7px 9px; cursor: pointer; border-radius: var(--radius-ui);
}
.search-item.active { background: var(--bg-surface-hover); }
.search-type { flex: none; font-size: var(--label-size); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.search-empty { padding: 8px 9px; color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 12px; font: inherit; font-weight: 500; color: var(--text); cursor: pointer;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-ui);
}
.btn:hover { background: var(--bg-surface-hover); }
.btn.active { border-color: var(--accent); color: var(--accent); }
.btn svg { flex: none; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

/* ---------- LAYER SWITCHES ---------- */
#layers .section-title { margin-top: 22px; }
#layers .section-title:first-child { margin-top: 0; }
.layer-row {
  display: flex; align-items: center; gap: 12px;
  margin: 0 -8px; padding: 7px 8px; border-radius: var(--radius-ui); cursor: pointer;
}
.layer-row:hover { background: var(--bg-surface); }
.layer-row input { width: 16px; height: 16px; margin: 0; cursor: pointer; accent-color: var(--accent); }
.layer-count {
    color: var(--text-muted);
}
/* the "(60)" after a layer name */

/* The little colored shape next to each layer name */
.swatch { flex: none; width: 14px; height: 14px; border-radius: 3px; }
.swatch-circle { border-radius: 50%; }
.swatch-diamond { border-radius: 0; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }

/* ---------- TOOLS: RULER AND ROUTE ---------- */
.tool-tabs { display: grid; grid-template-columns: 1fr; gap: 8px; }
.tool-panel { display: none; margin-top: 16px; }
.tool-panel p { margin: 0; color: var(--text-muted); line-height: 1.5; }
.tool-panel label {
  display: block; margin: 14px 0 6px; font-size: var(--small-size);
  font-weight: 500; color: var(--text-muted);
}
#ruler-result { margin-top: 12px; font-size: 15px; line-height: 1.55; }

/* ---------- MENU GROUPS (Camadas, Marcadores, Rotas): fold and unfold ---------- */
.group { margin-top: 18px; border-top: 1px solid var(--border); }
.group > summary {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 0 8px; cursor: pointer;
  list-style: none; user-select: none;
  font-size: var(--label-size); font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-muted);
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary:hover { color: var(--text); }
.group > summary::after {   /* the little arrow: down when open, to the right when folded */
  content: ""; width: 7px; height: 7px; margin-right: 3px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(-3px) rotate(45deg); transition: transform 0.15s ease;
}
.group:not([open]) > summary::after { transform: rotate(-45deg); }
.group-body { padding-bottom: 8px; }

/* ---------- THE RULER: button above the zoom buttons, and its box ---------- */
body > #ruler-control { display: none; }   /* until map.js puts it in the map corner */
#ruler-control a { display: flex; align-items: center; justify-content: center; }
#ruler-control svg { width: var(--ruler-icon); height: var(--ruler-icon); }
#ruler-control a.active { color: var(--accent); }
.ruler-card {
  display: none; position: fixed; right: 62px; bottom: 10px; z-index: 1000; width: var(--ruler-card-width); max-width: calc(100vw - 80px);
  padding: 14px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-ui);
  box-shadow: var(--shadow-popup);
}
.ruler-card p { margin: 0; color: var(--text-muted); line-height: 1.5; font-size: var(--small-size); }
.ruler-card .btn-row { margin-top: 10px; }

/* Route stops: one row per stop (letter badge, place list, remove button) */
.stop-row { position: relative; display: flex; align-items: center; gap: 8px; margin-top: 8px; }
/* Reordering by dragging the badge: the row being moved is dimmed, and a line shows where it will go */
.stop-row.dragging { opacity: 0.5; }
.stop-row.drop-before::before, .stop-row.drop-after::after {
  content: ""; position: absolute; left: 0; right: 0; height: 3px; border-radius: 2px; background: var(--accent);
}
.stop-row.drop-before::before { top: -6px; }
.stop-row.drop-after::after { bottom: -6px; }
.stop-row .field { flex: 1; min-width: 0; }
.stop-badge {
  flex: none; display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; color: var(--on-color); font-size: 12px; font-weight: 700;
  cursor: grab; touch-action: none; user-select: none;   /* the handle to reorder the stops */
}
.icon-btn {
  flex: none; width: 34px; height: 38px; padding: 0; font: inherit; color: var(--text-muted); cursor: pointer;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-ui);
}
.icon-btn:hover { color: var(--text); background: var(--bg-surface-hover); }
.btn-wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:hover { background: var(--bg-surface); }

/* "Considerar rotas fluviais" tick box */
.tool-panel label.check-row,
#editor label.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0 0;
    font-size: var(--text-size);
    font-weight: 400;
    color: var(--text);
    cursor: pointer;
}
.check-row input { width: 16px; height: 16px; margin: 0; cursor: pointer; accent-color: var(--accent); }

.note { margin-top: 12px; font-size: var(--small-size); color: var(--text-muted); }

/* Route result: one row per stretch (A -> B, how, how long) and the total at the end.
   The colored bar on the left matches the line drawn on the map: --route for roads and
   the wilderness (dotted), --route-water for rivers and sea. */
.trip-row {
  margin-top: 10px; padding: 9px 12px; background: var(--bg-surface);
  border: 1px solid var(--border); border-left: 4px solid var(--route); border-radius: var(--radius-ui);
}
.trip-row.trip-river, .trip-row.trip-sea { border-left-color: var(--route-water); }
.trip-row.trip-wild { border-left-style: dotted; }
.trip-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-weight: 600; }
.trip-time { white-space: nowrap; }
.trip-detail {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px;
  font-size: var(--small-size); color: var(--text-muted);
}
.trip-mode { width: auto; flex: none; padding: 4px 8px; font-size: var(--small-size); }
.trip-total {
  margin-top: 12px; padding: 10px 12px; font-weight: 700; font-size: 15px; color: var(--accent);
  border: 1px solid var(--accent); border-radius: var(--radius-ui);
}

/* ---------- PERSONAL MARKERS ("Marcadores pessoais") ---------- */
/* The X on the map. Colors and size: "personal" in settings/visual.js (each marker has its own color). */
.personal-marker { background: transparent; border: none; }
.personal-marker svg { display: block; overflow: visible; }
.personal-marker.moving svg { filter: drop-shadow(0 0 4px var(--on-color)); }

/* The list in the menu: one row per marker, a click flies to it */
#personal-hint { margin: 0; color: var(--text-muted); line-height: 1.5; }
#personal-toggle { margin-top: 10px; }
.swatch-personal { background: var(--personal); border: 1px solid var(--marker-border); clip-path: polygon(0 12%, 12% 0, 50% 38%, 88% 0, 100% 12%, 62% 50%, 100% 88%, 88% 100%, 50% 62%, 12% 100%, 0 88%, 38% 50%); border: none; }
#personal-list { margin-top: 8px; }
.personal-row {
  display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 4px; padding: 7px 8px;
  font: inherit; color: var(--text); text-align: left; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-ui);
}
.personal-row:hover { background: var(--bg-surface); border-color: var(--border); }
.personal-row .swatch { width: 12px; height: 12px; border: 1px solid var(--marker-border); }
.personal-row .personal-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.personal-empty { margin-top: 8px; font-size: var(--small-size); color: var(--text-muted); }
#personal-clear { margin-top: 10px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }

/* Inside the popup of a personal marker */
.personal-popup { min-width: 200px; }
.personal-popup .field { box-sizing: border-box; width: 100%; margin-top: 6px; padding: 7px 9px; }   /* border-box: the fields stay inside the popup */
.personal-popup textarea.field { min-height: 70px; resize: vertical; }
.personal-popup .color-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: var(--small-size); color: var(--popup-muted); }
.personal-popup input[type="color"] { width: 36px; height: 26px; padding: 0; background: transparent; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.personal-popup .popup-text { white-space: pre-wrap; }
.personal-popup .btn-row { margin-top: 10px; gap: 6px; flex-wrap: wrap; }
.personal-popup .btn { flex: 1 1 auto; padding: 5px 8px; font-size: var(--small-size); }

/* The confirmation window ("Limpar marcadores") */
.modal {
  position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: var(--overlay);
}
.modal[hidden] { display: none; }
.modal-box {
  width: min(380px, 100%); padding: 20px; background: var(--bg-sidebar);
  border: 1px solid var(--border); border-radius: var(--radius-ui); box-shadow: var(--shadow-popup);
}
.modal-box h3 { margin: 0 0 8px; font-family: var(--font-heading); font-size: 17px; }
.modal-box p { margin: 0; color: var(--text-muted); line-height: 1.5; }
.modal-box .btn-row { margin-top: 18px; }
.btn.btn-confirm { background: var(--danger); border-color: var(--danger); color: var(--on-color); }

/* Coordinate editor (only shown with ?edit=1) */
#editor { display: none; }
#editor-output {
  width: 100%; height: 170px; margin-top: 12px; padding: 10px 12px; resize: vertical;
  font-family: var(--font-mono); font-size: var(--small-size); line-height: 1.5; color: var(--text);
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-ui);
}
#editor .btn-row { flex-wrap: wrap; }
#editor .btn-row .btn { flex: 1 1 45%; }

/* ---------- MARKERS ON THE MAP ---------- */
/* Diamond marker (capitals and forts): a square turned 45 degrees, with a white border like the circles */
.diamond { background: transparent; border: none; }
    .diamond span {
        display: block;
        box-sizing: border-box;
        border: var(--marker-border-width) solid var(--marker-border);
        transform: rotate(45deg);
    }

/* Little arrows that show the direction of a waterway's current (flow in data.js).
   Fill and outline colors are here; the spacing is "arrowSpacing" in config.js. */
.flow-arrow { background: transparent; border: none; }
.flow-arrow svg { display: block; fill: var(--flow-arrow); stroke: var(--flow-arrow-outline); stroke-width: var(--flow-arrow-outline-width); stroke-linejoin: round; }

/* Ruler points: click to remove, press and hold to drag.
   The handle is a bigger target than the visible dot, so it is easy to grab (sizes: ruler in settings/visual.js). */
.ruler-handle { background: transparent; border: none; }
.ruler-handle span {
  display: block; width: var(--ruler-dot); height: var(--ruler-dot); margin: calc((var(--ruler-handle) - var(--ruler-dot)) / 2); box-sizing: border-box;
  background: var(--on-color); border: 2px solid var(--ruler); border-radius: 50%;
  box-shadow: var(--shadow-small); transition: transform 0.12s ease, background 0.12s ease;
}
.ruler-handle:hover span { transform: scale(1.3); }
.ruler-handle.leaflet-drag-target span { transform: scale(1.4); background: var(--ruler); }
/* While the ruler is on, the map ignores clicks on shapes; the ruler points are the exception */
#map.tool-active .leaflet-interactive.ruler-handle { pointer-events: auto !important; cursor: grab !important; }
#map.tool-active .leaflet-interactive.ruler-handle.leaflet-drag-target { cursor: grabbing !important; }

/* Route pins can be dragged (while a tool is on the map ignores clicks on shapes: pins are the exception) */
#map.tool-active .leaflet-interactive.route-pin { pointer-events: auto !important; cursor: grab !important; }
#map.tool-active .leaflet-interactive.route-pin.leaflet-drag-target { cursor: grabbing !important; }
/* Ring around a pin that is snapping onto a place while being dragged */
.route-pin.snapped span { box-shadow: 0 0 0 5px var(--pin-ring), var(--shadow-small); }

/* Route pins "A" and "B" */
.route-pin { background: transparent; border: none; }
.route-pin span {
  display: flex; align-items: center; justify-content: center; width: var(--pin-size); height: var(--pin-size);
  border-radius: 50%; border: 2px solid var(--on-color); color: var(--on-color); font-weight: 700; font-size: var(--pin-font);
  box-shadow: var(--shadow-small);
}

/* ---------- POPUPS (the boxes that open when you click a place) ---------- */
.leaflet-popup-content-wrapper {
  background: var(--popup-bg); color: var(--popup-text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-popup);
}
.leaflet-popup-tip { background: var(--popup-bg); box-shadow: none; }
.leaflet-popup-content { margin: 14px 16px; font-family: var(--font-body); font-size: var(--text-size); line-height: 1.5; }
.leaflet-container a.leaflet-popup-close-button { color: var(--popup-muted); }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--popup-text); background: transparent; }
.popup-title { margin-bottom: 2px; font-family: var(--font-heading); font-size: 16px; font-weight: 600; }
.popup-type { margin-bottom: 8px; font-size: var(--label-size); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--popup-muted); }
.popup-image { display: block; max-width: 220px; margin-bottom: 8px; border-radius: var(--radius); }

/* ---------- HOVER LABELS (the name that shows when the mouse is over a place) ---------- */
.leaflet-tooltip {
  padding: 4px 9px; font-family: var(--font-body); font-size: var(--small-size); font-weight: 500;
  color: var(--popup-text); background: var(--popup-bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-medium);
}
.leaflet-tooltip-top:before { border-top-color: var(--popup-bg); }
.leaflet-tooltip-bottom:before { border-bottom-color: var(--popup-bg); }
.leaflet-tooltip-left:before { border-left-color: var(--popup-bg); }
.leaflet-tooltip-right:before { border-right-color: var(--popup-bg); }

/* Ruler distance labels */
.leaflet-tooltip.ruler-tooltip { color: var(--ruler-label-text); font-weight: 700; background: var(--ruler); border-color: var(--ruler); }
.leaflet-tooltip.ruler-tooltip.leaflet-tooltip-top:before { border-top-color: var(--ruler); }

/* ---------- ZOOM BUTTONS ---------- */
.leaflet-touch .leaflet-bar, .leaflet-bar {
  border: 1px solid var(--border); border-radius: var(--radius-ui);
  box-shadow: var(--shadow-medium); overflow: hidden;
}
.leaflet-bar a, .leaflet-bar a:hover {
  color: var(--text); background-color: var(--bg-surface); border-bottom: 1px solid var(--border);
}
.leaflet-bar a:hover { background-color: var(--bg-surface-hover); }
.leaflet-bar a:last-child { border-bottom: none; }

/* ---------- NOTICES (image could not be loaded) ---------- */
#notice {
  display: none; position: absolute; top: 12px; right: 12px; z-index: 1000;
  max-width: min(420px, 60%); padding: 10px 14px; font-size: var(--text-size); line-height: 1.45;
  color: var(--notice-text); background: var(--notice-bg); border: 1px solid var(--notice-border); border-radius: var(--radius-ui);
}

/* ---------- PHONES AND NARROW WINDOWS ----------
   The sidebar turns into a drawer that slides in over the map. */
#sidebar-toggle, #sidebar-close { display: none; }
@media (max-width: 760px) {
  #map { left: 0; }
  #sidebar {
    width: min(var(--sidebar-width), 88vw);
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  body.sidebar-open #sidebar { transform: none; box-shadow: var(--shadow-drawer); }
  #sidebar-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 12px; left: 12px; z-index: 1100; width: 42px; height: 42px; padding: 0;
    font-size: 20px; color: var(--text); cursor: pointer;
    background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: var(--radius-ui);
  }
  body.sidebar-open #sidebar-toggle { display: none; }
  #sidebar-close {
    display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0;
    font-size: 16px; color: var(--text-muted); cursor: pointer;
    background: transparent; border: 1px solid var(--border); border-radius: var(--radius-ui);
  }
}
