/* GPXpress — map/trail palette with light + dark themes */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Source+Serif+4:opsz,wght@8..60,600;8..60,700&display=swap');

:root,
[data-theme="light"] {
  --bg: #eef3ef;
  --bg-elevated: #f7faf7;
  --surface: #ffffff;
  --ink: #14201a;
  --ink-muted: #4a5c52;
  --line: #c5d2c9;
  --brand: #1f6b4a;
  --brand-deep: #145238;
  --brand-soft: #d7ebe1;
  --accent: #2f6f8f;
  --danger: #a33b2b;
  --danger-soft: #f8e4e0;
  --info-soft: #e3eef4;
  --shadow: 0 18px 40px rgba(20, 32, 26, 0.08);
  --radius: 14px;
  --font-sans: "DM Sans", "Segoe UI", sans-serif;
  --font-display: "Source Serif 4", Georgia, serif;
  --map-grid: rgba(31, 107, 74, 0.06);
}

[data-theme="dark"] {
  --bg: #0f1612;
  --bg-elevated: #162019;
  --surface: #1c2821;
  --ink: #e7efe9;
  --ink-muted: #9bb0a4;
  --line: #2e4036;
  --brand: #5fbf92;
  --brand-deep: #3d9a70;
  --brand-soft: #1e3a2d;
  --accent: #6ea8c4;
  --danger: #e08a7a;
  --danger-soft: #3a2220;
  --info-soft: #1d3038;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --map-grid: rgba(95, 191, 146, 0.05);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--bg-elevated), var(--bg) 40%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 31px,
      var(--map-grid) 31px,
      var(--map-grid) 32px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 31px,
      var(--map-grid) 31px,
      var(--map-grid) 32px
    );
  background-color: var(--bg);
  line-height: 1.5;
}

a {
  color: var(--accent);
}

code {
  font-size: 0.92em;
  background: var(--brand-soft);
  padding: 0.1em 0.35em;
  border-radius: 6px;
}

/* Auth / setup */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}

.auth-card-wide {
  width: min(100%, 560px);
}

.brand-block {
  text-align: center;
  margin-bottom: 1.25rem;
}

.brand-mark {
  display: inline-block;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50% 50% 45% 55%;
  background:
    radial-gradient(circle at 30% 30%, #9ad7b8, transparent 45%),
    linear-gradient(145deg, var(--brand), var(--accent));
  margin-bottom: 0.65rem;
}

.brand-mark-sm {
  width: 1.35rem;
  height: 1.35rem;
  margin: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.brand-tagline {
  margin: 0.35rem 0 0;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.stack-form {
  display: grid;
  gap: 0.85rem;
}

.stack-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.stack-form input,
.stack-form select {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--ink);
  font: inherit;
}

.stack-form input:focus,
.stack-form select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

[data-theme="dark"] .btn-primary {
  color: #0f1612;
}

.btn-primary:hover {
  background: var(--brand-deep);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn-ghost:hover {
  background: var(--brand-soft);
}

.btn-sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.875rem;
}

.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  margin: 0 0 1rem;
}

.form-info {
  background: var(--info-soft);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  margin: 0 0 1rem;
}

.setup-steps {
  margin: 0 0 1.25rem;
  padding-left: 1.2rem;
  color: var(--ink-muted);
  font-size: 0.92rem;
}

.setup-steps .done {
  color: var(--brand);
}

.setup-section-title {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.setup-hint {
  margin: 0;
  font-size: 0.85rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 5.5rem;
  gap: 0.75rem;
}

.setup-checks {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.setup-check {
  display: grid;
  gap: 0.1rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.88rem;
}

.setup-check-ok {
  border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
  background: var(--brand-soft);
}

.setup-check-warn {
  border-color: color-mix(in srgb, #b45309 40%, var(--line));
  background: color-mix(in srgb, #b45309 10%, var(--surface));
}

.setup-check-fail {
  border-color: color-mix(in srgb, #be123c 40%, var(--line));
  background: color-mix(in srgb, #be123c 8%, var(--surface));
}

.setup-check-label {
  font-weight: 600;
}

.setup-check-detail {
  color: var(--ink-muted);
  font-size: 0.82rem;
}

.setup-check-inline {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.setup-check-inline input {
  width: auto;
}

/* App chrome */
.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.topbar-brand .brand-name {
  font-size: 1.2rem;
}

.topbar-nav {
  display: flex;
  gap: 0.35rem;
  flex: 1;
}

.nav-link {
  text-decoration: none;
  color: var(--ink-muted);
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  font-weight: 500;
}

.nav-link.is-active,
.nav-link:hover {
  color: var(--ink);
  background: var(--brand-soft);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-chip {
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.inline-form {
  display: inline;
  margin: 0;
}

.app-main {
  padding: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.empty-state h1,
.empty-state h2 {
  font-family: var(--font-display);
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
}

.empty-state p {
  color: var(--ink-muted);
  margin: 0 0 1rem;
}

.muted {
  color: var(--ink-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Library */
.library-page {
  display: grid;
  gap: 1.25rem;
}

.library-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.library-heading h1 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1.85rem;
}

.library-heading p {
  margin: 0.25rem 0 0;
}

.search-field input {
  width: min(100%, 280px);
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.upload-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--brand-soft) 55%, var(--surface));
  transition: border-color 0.15s ease, background 0.15s ease;
}

.upload-panel.is-dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.upload-panel.is-busy {
  opacity: 0.7;
  pointer-events: none;
}

.upload-copy {
  display: grid;
  gap: 0.15rem;
}

.upload-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}

.tags-field {
  display: grid;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.tags-field input {
  width: min(100vw - 4rem, 220px);
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.library-status {
  margin: 0;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: var(--info-soft);
  color: var(--ink);
}

.library-status.is-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.route-card {
  display: grid;
  grid-template-rows: 150px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.route-preview {
  width: 100%;
  height: 150px;
  background: var(--bg);
}

.route-preview .leaflet-control-container {
  display: none;
}

.route-body {
  padding: 0.9rem 1rem 1rem;
  display: grid;
  gap: 0.65rem;
}

.route-name {
  margin: 0;
  font-size: 1.1rem;
  font-family: var(--font-display);
  line-height: 1.25;
  word-break: break-word;
}

.route-name a,
.route-preview-link {
  color: inherit;
  text-decoration: none;
}

.route-name a:hover {
  color: var(--brand);
}

.route-preview-link {
  display: block;
}

.compare-check {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0.35rem 0.5rem;
}

.compare-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--brand-soft);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, var(--line));
}

.compare-bar-actions {
  display: flex;
  gap: 0.4rem;
}

.route-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.75rem;
  margin: 0;
}

.route-stats div {
  display: grid;
  gap: 0.1rem;
}

.route-stats dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

.route-stats dd {
  margin: 0;
  font-weight: 600;
  font-size: 0.92rem;
}

.route-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 1.4rem;
}

.tag-chip {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 0.78rem;
  font-weight: 600;
}

[data-theme="dark"] .tag-chip {
  color: var(--brand);
}

.route-meta {
  font-size: 0.8rem;
}

.route-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}

.btn-danger:hover {
  background: var(--danger-soft);
}

/* Map / Plan (and Edit): lock map pane; scroll sidebar only */
.map-page-body {
  height: 100vh;
  height: 100dvh;
  min-height: 0; /* override .app-shell min-height so the page cannot grow */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-page-body .topbar {
  position: relative;
  flex: 0 0 auto;
}

.map-layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  min-height: 0;
  overflow: hidden;
}

.map-stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.map-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem 1.1rem 1.25rem;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.map-sidebar-head h1 {
  font-family: var(--font-display);
  font-size: 1.45rem;
  margin: 0;
}

.map-sidebar-head p {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
}

.map-sidebar-section {
  display: grid;
  gap: 0.5rem;
}

.sidebar-title {
  margin: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.stack-label {
  font-size: 0.85rem;
  font-weight: 600;
}

.map-add-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
}

.map-add-row select {
  width: 100%;
  padding: 0.5rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--ink);
  font: inherit;
}

.map-route-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.map-route-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.4rem 0.45rem;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
}

.map-route-item-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  cursor: pointer;
  font-size: 0.9rem;
}

.map-route-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: -0.05em;
  margin-right: 0.25rem;
}

.point-stats {
  margin: 0;
  display: grid;
  gap: 0.45rem;
}

.point-stats div {
  display: grid;
  gap: 0.1rem;
}

.point-stats dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

.point-stats dd {
  margin: 0;
  font-weight: 600;
  font-size: 0.92rem;
}

.point-stats .coords {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 500;
}

.map-canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Plan page puts the canvas wrap directly in the layout grid */
.map-layout > .map-canvas-wrap {
  height: 100%;
}

.map-canvas {
  width: 100%;
  height: 100%;
  z-index: 0;
  background: #d7e0d9;
}

/* Map overlay toggles (distance markers, elevation profile) */
.map-overlay-toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.elev-toggle {
  width: 100%;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.28rem 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.elev-toggle.is-active {
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
  color: var(--ink);
}

.elev-toggle-icon {
  display: inline-block;
  width: 0.9rem;
  height: 0.65rem;
  background:
    linear-gradient(135deg, transparent 40%, var(--brand) 40% 55%, transparent 55%),
    linear-gradient(to top, var(--accent) 0 35%, transparent 35%);
  border-bottom: 2px solid var(--brand);
  border-radius: 2px;
  flex-shrink: 0;
}

.dist-toggle-icon {
  display: inline-grid;
  place-items: center;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  border: 1.5px solid var(--brand);
  font-size: 0.48rem;
  font-weight: 700;
  line-height: 1;
  color: var(--brand);
  flex-shrink: 0;
}

.dist-toggle-icon::before {
  content: '1';
}

.elev-panel {
  flex: 0 0 auto;
  height: 210px;
  padding: 0.65rem 0.85rem 0.75rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.06);
}

.elev-panel[hidden] {
  display: none !important;
}

.elev-chart-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.elev-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.elev-empty {
  margin: 0;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
  pointer-events: none;
  z-index: 1;
}

/* Class rule must not override [hidden] — otherwise the empty message
   stays painted on top of the canvas after a successful draw. */
.elev-empty[hidden] {
  display: none !important;
}

.elev-chart-wrap canvas[hidden] {
  display: none !important;
}

.dist-marker {
  background: transparent;
  border: none;
}

.dist-marker span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  border: 2px solid var(--marker-color, var(--brand));
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.dist-marker small {
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.dir-arrow-marker {
  background: transparent;
  border: none;
}

.dir-arrow {
  display: block;
  width: 0;
  height: 0;
  margin: 3px 0 0 2px;
  border-style: solid;
  border-width: 5px 0 5px 12px;
  border-color: transparent transparent transparent var(--arrow-color, var(--brand));
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
  transform: rotate(var(--arrow-rot, 0deg));
  transform-origin: center center;
}

.leaflet-container {
  font-family: var(--font-sans);
}

/* Route planner */
.plan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.plan-actions .btn-primary {
  flex: 1 1 100%;
}

#plan-profile,
#edit-name,
#edit-description,
#edit-tags {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--ink);
  font: inherit;
}

#edit-description {
  resize: vertical;
  min-height: 4.5rem;
}

.plan-waypoint-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.plan-waypoint-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.45rem;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.plan-wp-name-input {
  width: 100%;
  min-width: 0;
  padding: 0.3rem 0.4rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
}

.plan-wp-name-input:hover,
.plan-wp-name-input:focus {
  border-color: var(--line);
  background: var(--surface);
  outline: none;
}

.plan-wp-name-input:focus {
  border-color: var(--accent);
}

.plan-wp-index {
  display: grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.plan-wp-marker {
  background: transparent;
  border: none;
}

.plan-wp-marker span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

@media (max-width: 900px) {
  .map-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 38vh) minmax(0, 1fr);
  }

  .map-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }

  .map-stage,
  .map-layout > .map-canvas-wrap {
    min-height: 0;
  }

  .elev-panel {
    height: 160px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0.75rem;
  }

  .user-chip {
    display: none;
  }

  .app-main {
    padding: 1rem;
  }

  .upload-panel {
    align-items: stretch;
  }

  .upload-controls {
    width: 100%;
  }

  .tags-field,
  .tags-field input {
    width: 100%;
  }
}
