/* mapsbin styles. Colors are driven by CSS custom properties that flip with the
   OS color-scheme preference; app.js additionally swaps the Leaflet tile layer
   so the basemap matches. */

:root {
  --bg: #f6f7f9;
  --panel-bg: #ffffff;
  --text: #1b1f24;
  --muted: #5b6470;
  --border: #d8dde3;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --pin-bg: #2f6fed;
  --pin-text: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel-bg: #1b1f26;
    --text: #e7ebf0;
    --muted: #9aa4b1;
    --border: #2c333d;
    --accent: #5b8bff;
    --accent-text: #0c1016;
    --danger: #ff6b5e;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    --pin-bg: #5b8bff;
    --pin-text: #0c1016;
  }
}

* {
  box-sizing: border-box;
}

/* Make the hidden attribute reliable even on elements with an explicit display
   (e.g. #layout is display:flex, which would otherwise win over [hidden]). */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  /* Belt-and-suspenders: this app never wants the page to scroll sideways. */
  overflow-x: hidden;
}

/* Hard-cap every form control to just under the viewport so none can ever
   stretch past the screen edge (mobile browsers otherwise let a <textarea>
   fall back to its intrinsic `cols` width). 1.5rem leaves a small gutter. */
input,
textarea,
select {
  max-width: calc(100vw - 1.5rem);
  min-width: 0;
  font-family: inherit;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#topbar {
  position: relative;
  /* Keep the menu dropdown above the map. Must clear Leaflet's controls, whose
     .leaflet-top/.leaflet-bottom panes use z-index:1000 (see vendor/leaflet.css);
     #map is also isolated below so its z-indexes stay contained, but we raise the
     bar above 1000 as belt-and-suspenders. */
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.brand-link {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
}

.tagline {
  color: var(--muted);
  font-size: 0.85rem;
}

.badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.navlink {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.navlink:hover {
  color: var(--text);
}

/* Hamburger control — the checkbox is the (visually hidden) state, the label is
   the button. Hidden on wide screens; shown on narrow ones. */
.nav-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.nav-burger {
  display: none;
  padding: 0.1rem 0.4rem;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
}

.nav-toggle:focus-visible + .nav-burger {
  outline: 2px solid var(--accent);
}

#layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

#map {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  /* Make #map its own stacking context so Leaflet's internal high z-indexes
     (tile/control panes up to 1000) stay contained below #topbar and don't
     paint over the nav dropdown. */
  isolation: isolate;
}

/* "My maps" list view (shown instead of #layout on /mine). */
.mine {
  flex: 1;
  overflow-y: auto;
  padding: 1.4rem 1rem;
}

.mine h2 {
  margin: 0 0 0.3rem;
}

.mine h2,
.mine > .hint,
.mine-list {
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

.mine-list {
  list-style: none;
  padding: 0;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mine-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
}

.mine-link {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mine-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.mine-link:hover {
  color: var(--accent);
}

.mine-meta {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Offline capture screen (/capture) and account page (/account). */
.capture,
.account {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.account .cap-card {
  max-width: 420px;
  margin: 1rem auto;
}

.auth-tabs {
  display: flex;
  gap: 0.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.3rem;
}

.auth-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.4rem 0.2rem;
  margin-bottom: -1px;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.auth-tab.is-active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.auth-field {
  width: 100%;
  padding: 0.55rem 0.6rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

#reset-request-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.3rem;
}

.linklike {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.cap-card {
  max-width: 680px;
  margin: 0 auto 1rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.cap-title {
  width: 100%;
  padding: 0.5rem 0.6rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.cap-actions .btn {
  width: 100%;
  padding: 0.7rem;
}

.cap-coords {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.cap-drafts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cap-drafts-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.netpill {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.netpill[data-online="yes"] {
  color: #1f9d55;
  border-color: #1f9d55;
}

.netpill[data-online="no"] {
  color: var(--danger);
  border-color: var(--danger);
}

.msg {
  margin: 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
}

.msg.error {
  color: var(--danger);
  border-color: var(--danger);
}

.mine-list li.is-active {
  border-color: var(--accent);
}

.draft-open {
  flex: 1;
  min-width: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draft-open:hover {
  color: var(--accent);
}

.draft-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.draft-upload {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

#panel {
  width: 340px;
  max-width: 42vw;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.9rem;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

#title-input,
#share-url {
  width: 100%;
  padding: 0.5rem 0.6rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

#title-view {
  margin: 0;
  font-size: 1.2rem;
}

.map-notes {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.5rem 0.6rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
  min-height: 3rem;
}

.map-notes-view {
  margin: 0.5rem 0 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--muted);
  font-size: 0.9rem;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.coord-entry {
  display: flex;
  gap: 0.4rem;
}

.coord-entry input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.waypoints {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.wp {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.6rem;
  background: var(--bg);
}

.wp-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.wp-num {
  flex: 0 0 auto;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--pin-bg);
  color: var(--pin-text);
  font-size: 0.8rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.wp-label {
  flex: 1;
  min-width: 0;
  padding: 0.3rem 0.4rem;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.wp-note {
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.4rem 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  /* Accent edge marks this as the note/annotation field, distinct from the
     name input above it. */
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  resize: vertical;
  min-height: 2.8rem;
}

.wp-label[readonly] {
  background: transparent;
  border-color: transparent;
  padding-left: 0;
}

/* Read-only waypoint note: wraps long lines and breaks long unbroken tokens.
   The accent edge matches the editor note field so a note reads as a note. */
.wp-note-view {
  margin-top: 0.4rem;
  padding-left: 0.5rem;
  border-left: 3px solid var(--accent);
  font-size: 0.85rem;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.wp-ctl {
  display: flex;
  gap: 0.25rem;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--muted);
  border-radius: 5px;
  width: 1.6rem;
  height: 1.6rem;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--accent);
}

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

.icon-btn.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.ttl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.ttl-select {
  flex: 1;
  max-width: 60%;
  padding: 0.4rem 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn {
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: var(--accent-text);
  border-color: var(--danger);
}

.share {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.share label {
  font-size: 0.8rem;
  color: var(--muted);
}

.share-row {
  display: flex;
  gap: 0.4rem;
}

.share-row input {
  flex: 1;
  min-width: 0;
}

.error {
  margin: 0;
  padding: 0.5rem 0.6rem;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 6px;
  font-size: 0.85rem;
}

/* Theme Leaflet's own controls (zoom buttons, layer switcher) so they read in
   both light and dark mode. */
.leaflet-bar a,
.leaflet-control-layers {
  background: var(--panel-bg);
  color: var(--text);
  border-color: var(--border);
}

.leaflet-bar a {
  border-bottom-color: var(--border);
}

.leaflet-bar a.leaflet-disabled {
  background: var(--bg);
  color: var(--muted);
}

.leaflet-control-layers-expanded {
  padding: 0.5rem 0.7rem 0.5rem 0.5rem;
  color: var(--text);
}

.leaflet-control-attribution {
  background: var(--panel-bg) !important;
  color: var(--muted);
}

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

/* Wrap long words in marker popups instead of overflowing the bubble. */
.leaflet-popup-content {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* The layer-switcher toggle is a dark PNG; invert it in dark mode so it stays
   visible on the dark control background. */
@media (prefers-color-scheme: dark) {
  .leaflet-control-layers-toggle {
    filter: invert(1);
  }
}

/* Numbered map marker (divIcon). */
.pin-marker {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--pin-bg);
  border: 2px solid var(--pin-text);
  box-shadow: var(--shadow);
}

.pin-marker span {
  transform: rotate(45deg);
  color: var(--pin-text);
  font-weight: 700;
  font-size: 0.8rem;
}

/* Collapse the nav into a hamburger dropdown when the bar gets crowded. */
@media (max-width: 720px) {
  .nav-burger {
    display: block;
  }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    right: 0.5rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    min-width: 170px;
    padding: 0.3rem;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }
  .nav-toggle:checked ~ .nav-links {
    display: flex;
  }
  .nav-links .navlink {
    padding: 0.55rem 0.6rem;
    border-radius: 6px;
    font-size: 0.95rem;
  }
  .nav-links .navlink:hover {
    background: var(--bg);
    color: var(--text);
  }
}

/* Stack the layout on narrow screens OR any portrait (height >= width)
   orientation — portrait never has the horizontal room for a map plus a side
   panel. */
@media (max-width: 720px), (orientation: portrait) {
  /* Stop forcing a single viewport-height pane; let the document flow and
     scroll. The map gets a definite height (Leaflet needs one) and the panel
     sits below it. Avoids the percentage-height/flex ambiguity that could
     collapse the panel off-screen. */
  html,
  body {
    height: auto;
  }
  #app {
    height: auto;
  }
  #layout {
    flex: none;
    flex-direction: column;
  }
  #map {
    flex: none;
    height: 55vh;
  }
  #panel {
    width: 100%;
    max-width: none;
    border-left: none;
    border-top: 1px solid var(--border);
    overflow-y: visible;
  }
  /* Reclaim topbar space on narrow screens. */
  .tagline {
    display: none;
  }
}
