*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --ink: #18181b; --ink2: #52525b; --ink3: #a1a1aa;
  --paper: #f8f8f6; --surface: #fff;
  --accent: #c0392b; --accent-light: rgba(192,57,43,0.08);
  --route: #2980b9; --route-light: rgba(41,128,185,0.10);
  --border: rgba(0,0,0,0.09); --border2: rgba(0,0,0,0.16);
  --r: 12px;
  --shadow: 0 1px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 6px 32px rgba(0,0,0,0.14);
  --font: 'Nunito', system-ui, sans-serif;
}
body { font-family: var(--font); font-size: 16px; background: var(--paper); color: var(--ink); min-height: 100dvh; display: flex; flex-direction: column; }

/* THREE-COLUMN LAYOUT */
#main-layout { display: flex; flex-direction: column; flex: 1; min-height: 0; }

@media (min-width: 860px) {
  #main-layout { flex-direction: row; align-items: stretch; height: calc(100dvh - 52px); max-height: calc(100dvh - 52px); overflow: hidden; }

  /* Col 1: titel + invoer */
  #col-input {
    width: 280px; min-width: 240px; max-width: 320px;
    flex-shrink: 0;
    display: flex; flex-direction: column;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    background: var(--surface);
  }

  /* Col 2: locatielijst */
  #col-list {
    width: 260px; min-width: 220px; max-width: 300px;
    flex-shrink: 0;
    display: flex; flex-direction: column;
    min-height: 0;
    overflow: hidden;
    border-right: 1px solid var(--border);
    background: var(--paper);
  }

  /* Col 3: kaart (50% schermbreedte) */
  #col-map {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 12px 12px 0 12px;
  }

  #map-wrap { flex: 1; margin: 0; min-height: 0; }
  #map { height: 100% !important; }
  #items-list { max-height: none; overflow-y: auto; flex: 1; min-height: 0; }
  #footer-actions { padding: 10px 12px 14px; flex-shrink: 0; }
}

/* On very wide screens, ensure map gets ~50% */
@media (min-width: 1200px) {
  #col-input { width: 300px; }
  #col-list { width: 280px; }
}

/* TOP BAR */
#topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 900;
  box-shadow: var(--shadow);
}
.logo { font-size: 17px; font-weight: 800; color: var(--accent); white-space: nowrap; flex-shrink: 0; display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px;
  border: 1.5px solid var(--border2);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: var(--ink2);
  transition: background 0.12s;
  flex-shrink: 0;
  font-family: var(--font);
  text-decoration: none;
}
.icon-btn:hover { background: var(--paper); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* HEADER (col 1) */
#header-section { margin: 14px 12px 0; background: var(--surface); border: 1.5px solid var(--border2); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); }
.field-hint { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink3); margin-bottom: 4px; }
#map-title { font-size: 19px; font-weight: 800; color: var(--ink); border: 1.5px solid transparent; background: var(--paper); font-family: var(--font); outline: none; width: 100%; border-radius: 8px; padding: 6px 10px; transition: border-color .15s; }
#map-title:hover { border-color: var(--border2); }
#map-title:focus { border-color: var(--accent); }
.divider-mini { height: 1px; background: var(--border); margin: 10px 0; }
#map-subtitle { font-size: 14px; font-weight: 500; color: var(--ink2); border: 1.5px solid transparent; background: var(--paper); font-family: var(--font); outline: none; width: 100%; border-radius: 8px; padding: 6px 10px; transition: border-color .15s; }
#map-subtitle:hover { border-color: var(--border2); }
#map-subtitle:focus { border-color: var(--accent); }

/* INPUT SECTION (col 1) */
#input-section { margin: 10px 12px 0; display: flex; flex-direction: column; gap: 8px; }
.section-label { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink3); padding: 0 2px; }
#drop-zone { border: 2px dashed var(--border2); border-radius: var(--r); padding: 14px 12px; text-align: center; cursor: pointer; transition: border-color .18s, background .18s; background: rgba(192,57,43,0.02); }
#drop-zone.drag-over { border-color: var(--accent); background: var(--accent-light); }
#drop-zone .drop-icon { font-size: 20px; display: block; margin-bottom: 4px; }
#drop-zone .drop-label { font-size: 14px; color: var(--ink2); font-weight: 600; }
#drop-zone .drop-sub { font-size: 12px; color: var(--ink3); margin-top: 3px; }
#file-input { display: none; }
#url-row { display: flex; gap: 8px; }
#url-input { flex: 1; border: 1.5px solid var(--border2); border-radius: 10px; padding: 10px 12px; font-family: var(--font); font-size: 14px; color: var(--ink); background: var(--surface); outline: none; transition: border-color .15s; min-width: 0; }
#url-input:focus { border-color: var(--accent); }
#url-input::placeholder { color: var(--ink3); }
#url-add-btn {
  padding: 10px 14px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 10px;
  font-family: var(--font); font-size: 14px; font-weight: 700;
  cursor: pointer; white-space: nowrap;
  transition: background .12s; flex-shrink: 0;
  display: flex; align-items: center; gap: 5px;
}
#url-add-btn:hover { background: #a02f23; }
#url-add-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* FOOTER ACTIONS (col 1) */
#footer-actions { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px 20px; margin-top: auto; }
.action-btn {
  flex: 1; padding: 11px 8px;
  border-radius: 10px; border: 1.5px solid var(--border2);
  background: var(--surface); font-family: var(--font);
  font-size: 14px; font-weight: 700; color: var(--ink);
  cursor: pointer; transition: background .12s, box-shadow .12s;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.action-btn:hover { background: var(--paper); box-shadow: var(--shadow); }
.action-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.action-btn.primary:hover { background: #a02f23; }
.action-btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* LOCATIONS HEADER (col 2) */
#locations-header { padding: 14px 12px 6px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }#clear-all-btn {
  font-size: 12px; font-weight: 700; color: var(--accent);
  background: none; border: none; cursor: pointer;
  font-family: var(--font); display: none;
  display: flex; align-items: center; gap: 4px;
}
#clear-all-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* COMBINED LIST (col 2) */
#items-list { padding: 0 10px; display: flex; flex-direction: column; gap: 0; max-height: 420px; overflow-y: auto; }

@media (min-width: 860px) {
  #items-list { max-height: none; }
}

/* ── LOCATION ITEM ── */
.loc-item {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 8px;
  transition: box-shadow .12s;
  position: relative;
}
.loc-item:hover { box-shadow: var(--shadow); }
.loc-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.loc-num { min-width: 20px; height: 20px; border-radius: 50%; background: var(--ink3); color: #fff; font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1; }
.loc-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.loc-name-input {
  font-size: 14px; font-weight: 700; color: var(--ink);
  border: 1px solid transparent; background: transparent;
  font-family: var(--font); outline: none; width: 100%;
  border-radius: 6px; padding: 2px 5px;
  transition: border-color .12s, background .12s;
  cursor: text;
}
.loc-name-input:hover { background: var(--paper); border-color: var(--border2); }
.loc-name-input:focus { background: var(--paper); border-color: var(--accent); }
.loc-note-input {
  font-size: 12px; font-weight: 500; color: var(--ink2);
  border: 1px solid transparent; background: transparent;
  font-family: var(--font); outline: none; width: 100%;
  border-radius: 6px; padding: 2px 5px;
  transition: border-color .12s, background .12s;
  cursor: text;
}
.loc-note-input:hover { background: var(--paper); border-color: var(--border2); }
.loc-note-input:focus { background: var(--paper); border-color: var(--accent); }
.loc-coords-small { font-size: 10px; color: var(--ink3); padding-left: 5px; }
.loc-actions { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.loc-color-dot {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border2); cursor: pointer;
  transition: transform .12s; flex-shrink: 0;
}
.loc-color-dot:hover { transform: scale(1.2); }
.loc-route-btn {
  width: 24px; height: 24px; border-radius: 7px;
  border: 1.5px solid var(--route); background: var(--route-light);
  color: var(--route); font-size: 14px; font-weight: 800;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  line-height: 1; transition: background .12s; flex-shrink: 0;
}
.loc-route-btn:hover { background: var(--route); color: #fff; }
.loc-route-btn svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.loc-del { background: none; border: none; color: var(--ink3); cursor: pointer; padding: 2px; line-height: 1; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.loc-del:hover { color: var(--accent); }
.loc-del svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.loc-tooltip-btn {
  width: 22px; height: 22px; border-radius: 6px;
  border: 1.5px solid var(--border2); background: transparent;
  color: var(--ink3); font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s, border-color .12s;
  flex-shrink: 0; line-height: 1;
}
.loc-tooltip-btn:hover { background: var(--paper); color: var(--ink); }
.loc-tooltip-btn.active { background: #fef9c3; border-color: #ca8a04; color: #92400e; }
.loc-tooltip-btn svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* permanent tooltip on map */
.leaflet-tooltip.perm-tooltip {
  background: #fff;
  border: 1.5px solid var(--border2);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  padding: 4px 9px;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
}
.leaflet-tooltip.perm-tooltip:hover { background: var(--paper); border-color: var(--accent); }
.leaflet-tooltip.perm-tooltip::before { display: none; }

/* route midpoint tooltip */
.leaflet-tooltip.route-mid-tooltip {
  background: #bfecff;
  border: 1.5px solid #2980b9;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  color: #1a5276;
  padding: 4px 9px;
  white-space: nowrap;
  pointer-events: none;
}
.leaflet-tooltip.route-mid-tooltip::before { display: none; }

/* ── ROUTE ITEM ── */
.route-connector {
  display: flex; align-items: stretch; gap: 0;
  margin: 3px 0;
  position: relative;
}
.route-line-col {
  width: 20px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 0 0 14px;
}
.route-line { width: 2px; background: var(--route); flex: 1; min-height: 100%; opacity: .4; }
.route-card {
  flex: 1; min-width: 0;
  background: var(--route-light);
  border: 1.5px solid rgba(41,128,185,0.25);
  border-radius: 10px;
  padding: 7px 9px;
  margin: 2px 0;
  position: relative;
}
.route-card.loading { opacity: .6; }
.route-header { display: flex; align-items: flex-start; gap: 5px; margin-bottom: 5px; }
.route-icon { font-size: 13px; flex-shrink: 0; margin-top: 1px; }
.route-meta { flex: 1; min-width: 0; }
.route-title { font-size: 12px; font-weight: 700; color: var(--route); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-stats { font-size: 11px; color: var(--ink2); display: flex; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.route-stat { display: flex; align-items: center; gap: 3px; }
.route-note-input {
  font-size: 12px; font-weight: 500; color: var(--ink2);
  border: 1px solid transparent; background: transparent;
  font-family: var(--font); outline: none; width: 100%;
  border-radius: 6px; padding: 3px 5px; margin-top: 4px;
  transition: border-color .12s, background .12s;
  cursor: text;
}
.route-note-input:hover { background: rgba(255,255,255,0.7); border-color: rgba(41,128,185,0.3); }
.route-note-input:focus { background: rgba(255,255,255,0.9); border-color: var(--route); }
.route-del { position: absolute; top: 5px; right: 7px; background: none; border: none; color: var(--ink3); cursor: pointer; display: flex; align-items: center; }
.route-del:hover { color: var(--accent); }
.route-del svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.route-error { font-size: 11px; color: var(--accent); font-weight: 600; }

/* drag handle */
.loc-drag-handle {
  color: var(--ink3); font-size: 15px; cursor: grab; padding: 0 1px;
  flex-shrink: 0; line-height: 1; user-select: none;
}
.loc-drag-handle:active { cursor: grabbing; }
.loc-item.drag-over-above { border-top: 2.5px solid var(--route) !important; }
.loc-item.drag-over-below { border-bottom: 2.5px solid var(--route) !important; }
.loc-item.dragging { opacity: 0.4; }

/* loc-empty */
.loc-empty { font-size: 13px; color: var(--ink3); padding: 4px 2px; font-weight: 500; }
.route-arrow { background: none !important; border: none !important; }

/* MAP (col 3) */
#map-wrap { margin: 0 0 12px; border-radius: var(--r); overflow: hidden; border: 1.5px solid var(--border2); box-shadow: var(--shadow); }
#map { height: clamp(300px, 50dvh, 600px); width: 100%; }

/* MAP CONTROLS */
#map-controls {
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 10px; flex-wrap: wrap;
}
#map-search-row { display: flex; gap: 6px; flex: 1; min-width: 200px; }
#map-search-input {
  flex: 1; border: 1.5px solid var(--border2); border-radius: 10px;
  padding: 9px 12px; font-family: var(--font); font-size: 14px;
  color: var(--ink); background: var(--surface); outline: none;
  transition: border-color .15s; min-width: 0;
}
#map-search-input:focus { border-color: var(--accent); }
#map-search-input::placeholder { color: var(--ink3); }
#map-search-btn {
  padding: 9px 14px;
  background: var(--surface); color: var(--ink2);
  border: 1.5px solid var(--border2); border-radius: 10px;
  font-family: var(--font); font-size: 14px; font-weight: 700;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: background .12s, color .12s;
  display: flex; align-items: center; gap: 5px;
}
#map-search-btn:hover { background: var(--paper); color: var(--ink); }
#map-search-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#fit-route-btn {
  padding: 9px 14px;
  background: var(--surface); color: var(--ink2);
  border: 1.5px solid var(--border2); border-radius: 10px;
  font-family: var(--font); font-size: 14px; font-weight: 700;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: background .12s, color .12s;
  display: flex; align-items: center; gap: 5px;
}
#fit-route-btn:hover { background: var(--paper); color: var(--ink); }
#fit-route-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Search results dropdown */
#map-search-results {
  position: absolute;
  z-index: 1000;
  background: var(--surface);
  border: 1.5px solid var(--border2);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  max-width: 360px;
  width: 100%;
  overflow: hidden;
  display: none;
}
#map-search-results.open { display: block; }
.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--paper); }
.search-result-sub { font-size: 12px; color: var(--ink3); font-weight: 500; margin-top: 1px; }

/* POPUP */
.leaflet-popup-content-wrapper { border-radius: 12px !important; box-shadow: var(--shadow-lg) !important; font-family: var(--font) !important; }
.popup-inner { padding: 2px 2px 4px; min-width: 160px; }
.popup-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; color: var(--ink); }
.popup-note { font-size: 13px; color: var(--ink2); margin-bottom: 8px; min-height: 12px; line-height: 1.5; white-space: pre-wrap; }
.popup-gmaps { font-size: 12px; color: var(--route); font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; gap: 3px; margin-bottom: 8px; }
.popup-gmaps:hover { text-decoration: underline; }
.popup-edit-btn { font-size: 13px; font-weight: 700; background: var(--paper); border: 1.5px solid var(--border2); border-radius: 8px; padding: 5px 14px; cursor: pointer; font-family: var(--font); color: var(--ink2); }
.popup-edit-btn:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }

/* MODALS */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1000; align-items: flex-end; justify-content: center; }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); border-radius: 20px 20px 0 0; width: 100%; max-width: 600px; max-height: 90dvh; overflow-y: auto; padding: 6px 20px 44px; box-shadow: var(--shadow-lg); animation: slideUp .22s cubic-bezier(.22,.68,0,1.2); }
@keyframes slideUp { from { transform: translateY(50px); opacity:0; } to { transform: translateY(0); opacity:1; } }
.modal-handle { width: 44px; height: 5px; background: var(--border2); border-radius: 3px; margin: 12px auto 20px; }
.modal h2 { font-size: 20px; font-weight: 800; margin-bottom: 18px; color: var(--ink); }
.modal .field-label { display: block; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink3); margin-bottom: 6px; }
.modal input[type=text], .modal textarea { width: 100%; border: 1.5px solid var(--border2); border-radius: 10px; padding: 11px 14px; font-family: var(--font); font-size: 15px; color: var(--ink); background: var(--paper); outline: none; margin-bottom: 16px; resize: vertical; }
.modal input[type=text]:focus, .modal textarea:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.color-swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; transition: transform .12s; }
.color-swatch:hover { transform: scale(1.18); }
.color-swatch.active { border-color: var(--ink); }

/* Save modal local storage notice */
.local-storage-notice {
  background: #fffbeb;
  border: 1.5px solid #fcd34d;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.local-storage-notice svg { width: 18px; height: 18px; flex-shrink: 0; stroke: #92400e; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; margin-top: 1px; }
.local-storage-notice p { font-size: 13px; color: #78350f; font-weight: 600; line-height: 1.5; }

.saved-map-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.saved-map-item:last-child { border-bottom: none; }
.saved-map-name { flex: 1; font-size: 15px; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-map-date { font-size: 12px; color: var(--ink3); white-space: nowrap; }
.saved-map-btn { background: none; border: 1.5px solid var(--border2); border-radius: 8px; padding: 5px 12px; font-size: 13px; font-weight: 700; cursor: pointer; font-family: var(--font); color: var(--ink2); }
.saved-map-btn:hover { color: var(--accent); border-color: var(--accent); }
.help-section { margin-bottom: 20px; }
.help-section h3 { font-size: 12px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
.help-step { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.step-num { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px; }
.help-step p, .help-section li, .help-section p { font-size: 15px; color: var(--ink2); line-height: 1.6; font-weight: 500; }
.help-section ul { padding-left: 18px; }

#toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(16px); background: var(--ink); color: #fff; font-family: var(--font); font-size: 14px; font-weight: 600; padding: 9px 20px; border-radius: 24px; opacity: 0; transition: opacity .18s, transform .18s; z-index: 2000; white-space: nowrap; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* RESPONSIVE: mobile stacked layout */
@media (max-width: 859px) {
  #col-input, #col-list, #col-map { width: 100%; float: none; }
  #col-map { padding: 0 12px; }
  #map-wrap { margin: 12px 0 0; }
  #map-controls { margin: 10px 0 0; }
  #footer-actions { flex-direction: row; padding: 10px 12px 24px; }
  #map-search-results { max-width: 100%; }
}

@media (min-width: 580px) {
  .modal { border-radius: 20px; margin: auto; }
  .modal-bg { align-items: center; padding: 20px; }
}
