/* ═══════════════════════════════════════════════
   Rotas — Design System
   ═══════════════════════════════════════════════ */

:root {
  --bg-dark: #1a1f2e;
  --bg-card: #232939;
  --bg-card-hover: #2a3148;
  --accent: #e8a838;
  --accent-light: #f0c060;
  --accent-dim: rgba(232, 168, 56, 0.15);
  --text: #e8e6e1;
  --text-muted: #8b8d95;
  --text-dim: #5c5e66;
  --border: rgba(255,255,255,0.06);
  --green: #4ade80;
  --blue: #60a5fa;
  --red: #f87171;
  --orange: #fbbf24;
  --cyan: #22d3ee;
  --shadow: 0 8px 32px rgba(0,0,0,0.3);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  padding-top: 48px;
}

/* --- Auth Header Bar --- */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 16px;
  z-index: 2000;
  gap: 10px;
}

.app-header .app-brand {
  margin-right: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'DM Serif Display', serif;
  font-size: 1.2rem;
  color: var(--text);
  letter-spacing: -0.02em;
}

.app-header .app-brand-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.app-header .header-suggest-btn {
  padding: 6px 14px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg-dark);
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.2s;
}
.app-header .header-suggest-btn:hover { background: var(--accent-light); }
/* Sugestões: texto no desktop, lâmpada (poupa espaço) em mobile */
.app-header .header-suggest-btn { display: inline-flex; align-items: center; gap: 6px; }
.app-header .header-suggest-btn .hs-ico { display: none; }
.app-header .header-suggest-btn .hs-label { display: inline; }
@media (max-width: 768px) {
  .app-header .header-suggest-btn { padding: 6px 9px; }
  .app-header .header-suggest-btn .hs-ico { display: block; }
  .app-header .header-suggest-btn .hs-label { display: none; }
}

.app-header .header-auth {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Login mudou para um ícone discreto na barra do topo (#topAuth). Os slots
   antigos (login grande no sidebar e no topo) ficam ocultos. */
.header-auth,
.sidebar-auth,
#mediaSection { display: none !important; }

/* Ações à direita da barra do topo: ícone de sessão + Sugestões */
.app-header .header-right { display: flex; align-items: center; gap: 10px; }
#topAuth { position: relative; display: inline-flex; }
.auth-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; min-width: 170px; z-index: 1400; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.auth-menu-name { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.auth-menu-logout {
  width: 100%; padding: 7px 10px; border: none; border-radius: var(--radius-sm);
  background: var(--red); color: #fff; font-weight: 600; font-size: 0.8rem; cursor: pointer;
}
.auth-menu-logout:hover { filter: brightness(1.08); }
.header-auth-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 50%;
  cursor: pointer; transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.header-auth-icon:hover { color: var(--text); border-color: var(--text-muted); }
.header-auth-icon.is-in { color: var(--accent); border-color: var(--accent); }

/* Caixa de comentários — botão e formulário no fundo */
.add-comment-btn { margin-top: 10px; }
.comment-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.comment-err { color: var(--red); font-size: 0.78rem; margin: 6px 0; display: none; }

/* Pega e backdrop do drawer — só no mobile (ver media query) */
.drawer-handle { display: none; }
.drawer-backdrop { display: none; }

.app-header .header-greeting,
.sidebar-auth .header-greeting {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.app-header .header-greeting strong,
.sidebar-auth .header-greeting strong {
  color: var(--accent);
  font-weight: 600;
}

.app-header .header-login-btn,
.sidebar-auth .header-login-btn {
  padding: 6px 16px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg-dark);
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.78rem;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

.app-header .header-login-btn:hover,
.sidebar-auth .header-login-btn:hover {
  background: var(--accent-light);
}

.app-header .header-logout-btn,
.sidebar-auth .header-logout-btn {
  padding: 4px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.2s;
}

.app-header .header-logout-btn:hover,
.sidebar-auth .header-logout-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

/* ─── Sidebar ─── */
.sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--bg-dark);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  position: relative;
  height: calc(100vh - 48px);
}

/* Conteúdo do sidebar com scroll (a pega do drawer fica fora, não é cortada) */
.sidebar-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 28px 24px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.6rem;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.sidebar-header h1 span { color: var(--accent); }

.sidebar-header p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ─── Search ─── */
.search-container {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  transition: border-color 0.2s;
}

.search-box:focus-within {
  border-color: var(--accent);
}

.search-box svg {
  width: 16px;
  height: 16px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.88rem;
}

.search-box input::placeholder {
  color: var(--text-dim);
}

.search-clear {
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 2px;
  margin: -4px -6px -4px 0;
  cursor: pointer;
  color: var(--text-dim);
  border-radius: 50%;
  line-height: 0;
}
.search-clear svg { width: 15px; height: 15px; }
.search-clear:hover { color: var(--text); background: var(--border); }
.search-box.has-text .search-clear { display: inline-flex; }

/* ─── Filters ─── */
.filters-container {
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  position: relative;       /* ancora o painel de camadas */
}

/* ─── Camadas (caixa colapsável com checkboxes) ─── */
.layers-btn { display: inline-flex; align-items: center; gap: 6px; }
.layers-btn .layers-chevron { transition: transform 0.2s ease; opacity: 0.8; }
.layers-btn[aria-expanded="true"] .layers-chevron { transform: rotate(180deg); }

.layers-panel {
  position: absolute;
  top: calc(100% - 4px);
  left: 16px;
  z-index: 1500;
  min-width: 230px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  padding: 12px 14px;
}
.layers-panel[hidden] { display: none; }

.layers-section + .layers-section {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 8px;
}
.layers-section-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px; cursor: pointer;
  padding: 7px 10px; border-radius: 8px;
  background: var(--bg-card, rgba(255,255,255,0.04));
  border: 1px solid var(--border);
}
.layers-section-head:hover { background: var(--bg-card-hover, rgba(255,255,255,0.07)); }
.layers-section-head span {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text); font-weight: 700;
}
/* chevron à direita: ▾ aberto / ▸ fechado */
.layers-section-head::after {
  content: ''; width: 9px; height: 9px; margin-left: 4px;
  border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg); transition: transform 0.2s; flex-shrink: 0;
}
.layers-section.collapsed .layers-section-head::after { transform: rotate(-45deg); }
.layers-section.collapsed .layer-check { display: none; }
.layers-allnone {
  font-size: 0.68rem; padding: 2px 9px; margin-left: auto; border: 1px solid var(--border);
  border-radius: 12px; background: transparent; color: var(--text-muted); cursor: pointer;
}
.layers-allnone:hover { color: var(--text); border-color: var(--text-muted); }

.layer-check {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 2px; font-size: 0.86rem; color: var(--text); cursor: pointer;
  user-select: none;
}
.layer-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.layer-check .lc-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
/* BTT/Centros BTT são coloridos por dificuldade: o dot mostra a escala */
.layer-check .lc-dot-dif { background: linear-gradient(90deg,#16a34a 0 25%,#2563eb 25% 50%,#dc2626 50% 75%,#111827 75% 100%); border-radius: 2px; }

/* Sub-filtros Centros Cyclin' (BTT/Gravel × dificuldade) */
.cyclin-sub { display:flex; flex-direction:column; gap:6px; margin:6px 0 4px 22px; }
.cyclin-sub[hidden] { display:none; }
.cyc-row { display:flex; align-items:center; gap:7px; font-size:.74rem; color:var(--text-muted); }
.cyc-row .cyc-label { width:46px; }
.cyc-dot { width:15px; height:15px; border-radius:50%; border:2px solid #fff; box-shadow:0 0 0 1px var(--border); cursor:pointer; padding:0; opacity:.45; transition:opacity .15s, transform .15s; }
.cyc-dot.active { opacity:1; transform:scale(1.15); }

.dif-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  margin: 6px 2px 2px; padding-top: 8px; border-top: 1px dashed var(--border);
  font-size: 0.72rem; color: var(--text-muted);
}
.dif-legend > span:first-child { width: 100%; opacity: 0.8; }
.dif-chip { display: inline-flex; align-items: center; gap: 5px; }
.dif-chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.filter-chip {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.filter-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.filter-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* Botão Todos/Nenhum — destaque neutro */
.filter-all {
  border-color: var(--text-dim);
  color: var(--text);
  font-weight: 600;
}
.filter-all.active {
  background: rgba(255,255,255,0.06);
  border-color: var(--text-muted);
  color: var(--text);
}

.filter-dropdown {
  position: relative;
}

.filter-dropdown-btn {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.filter-dropdown-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.filter-dropdown-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.filter-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  display: none;
}

.filter-dropdown-menu.open {
  display: block;
}

.filter-dropdown-menu .filter-option {
  padding: 8px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}

.filter-dropdown-menu .filter-option:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

.filter-dropdown-menu .filter-option.selected {
  color: var(--accent);
  font-weight: 600;
}

.filter-dropdown-menu::-webkit-scrollbar { width: 4px; }
.filter-dropdown-menu::-webkit-scrollbar-track { background: transparent; }
.filter-dropdown-menu::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 4px; }

/* ─── Results Count ─── */
.results-count {
  padding: 8px 16px;
  font-size: 0.75rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.results-count strong {
  color: var(--accent);
  font-weight: 600;
}

.sort-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.sort-bar .sort-label { font-size: 0.74rem; color: var(--text-dim); }
.sort-bar .sort-chip { font-size: 0.74rem; padding: 4px 11px; }

/* ─── Meus tracks (GPX importados) ─── */
.mytracks-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.mytracks-import { flex: 1 1 0; justify-content: center; text-align: center; color: var(--accent); border-color: rgba(232, 168, 56, 0.3); }
.mytracks-import:hover { border-color: var(--accent); color: var(--accent); }
.mytracks-clear { color: var(--red); border-color: rgba(248, 113, 113, 0.3); }
.mytracks-clear:hover { background: var(--red); color: #fff; border-color: var(--red); }
.filter-mytracks.active {
  background: rgba(255, 77, 109, 0.18);
  border-color: #ff4d6d;
  color: #ff4d6d;
  font-weight: 600;
}
.mytracks-status { font-size: 0.72rem; color: var(--text-dim); flex-basis: 100%; }

/* ─── Breadcrumb ─── */
.breadcrumb {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

.breadcrumb-item {
  cursor: pointer;
  transition: color 0.2s;
}

.breadcrumb-item:hover { color: var(--accent); }
.breadcrumb-link { text-decoration: none; cursor: pointer; color: inherit; }
.breadcrumb-link:visited { color: inherit; }
.breadcrumb-link:hover { text-decoration: underline; }
.breadcrumb-item.active { color: var(--accent); font-weight: 600; }
.breadcrumb-sep { opacity: 0.3; font-size: 0.7rem; }

/* ─── Sidebar Content / List ─── */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.sidebar-content::-webkit-scrollbar { width: 4px; }
.sidebar-content::-webkit-scrollbar-track { background: transparent; }
.sidebar-content::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 4px; }

/* ─── Route Card ─── */
.route-card {
  padding: 14px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.route-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border);
}

.route-card.active {
  background: var(--accent-dim);
  border-color: rgba(232, 168, 56, 0.25);
}

.route-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.route-card-ref {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.04em;
}

.route-card-ref.type-PR { background: rgba(217,119,6,0.18); color: #fbbf24; }
.route-card-ref.type-GR { background: rgba(147,51,234,0.18); color: #c084fc; }
.route-card-ref.type-BTT { background: rgba(74,222,128,0.18); color: var(--green); }
.route-card-ref.type-Ecopista { background: rgba(34,211,238,0.18); color: var(--cyan); }
.route-card-ref.type-Ciclovias { background: rgba(219,39,119,0.18); color: #f472b6; }
.route-card-ref.type-Peregrinação { background: rgba(79,70,229,0.18); color: #a5b4fc; }
.route-card-ref.type-Ecovia { background: rgba(34,211,238,0.18); color: var(--cyan); }
.route-card-ref.type-Diogo { background: rgba(217,79,0,0.18); color: #f97316; }
.route-card-ref.type-default { background: rgba(139,141,149,0.15); color: var(--text-muted); }

.route-card-title {
  font-weight: 600;
  font-size: 0.92rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.route-card-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 6px;
}

.route-card-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05);
  color: var(--text-muted);
  font-size: 0.72rem;
}

.meta-tag .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.diff-easy .dot { background: var(--green); }
.diff-moderate .dot { background: var(--orange); }
.diff-hard .dot { background: var(--red); }
.diff-easy { color: var(--green); }
.diff-moderate { color: var(--orange); }
.diff-hard { color: var(--red); }

/* ─── Map ─── */
#map {
  flex: 1;
  height: calc(100vh - 48px);
}

/* ─── Layout Mapa/Lista (sidebar de controlos sempre visível) ─── */
.sidebar { overflow-y: auto; }
.filters-container { flex-direction: column; align-items: stretch; gap: 10px; }
.filters-container .filter-dropdown { width: 100%; }
.filters-container .filter-dropdown-btn { width: 100%; justify-content: space-between; }
.layers-inline { width: 100%; }

.main-area { flex: 1; position: relative; height: calc(100vh - 48px); min-width: 0; }
.main-area #map { position: absolute; inset: 0; height: 100%; width: 100%; flex: none; }

.list-view {
  position: absolute; inset: 0; z-index: 600;
  background: var(--bg-dark); display: none; flex-direction: column;
}
body.mode-list .list-view { display: flex; }
.list-view-head { border-bottom: 1px solid var(--border); padding: 58px 12px 8px; flex-shrink: 0; }
.list-view-head .sort-bar { border-bottom: none; padding: 4px 4px 0; }
.list-view #routeList { flex: 1; overflow-y: auto; padding: 8px 12px; }

/* Pesquisa + camadas ativas no topo da Lista (só visível em mobile; no desktop a sidebar já mostra) */
.list-filters { display: none; }
.list-filters .search-box { margin-bottom: 8px; }
.active-layers { display: flex; flex-wrap: wrap; gap: 6px; }
/* Etiquetas de filtro (toggle on/off) no topo da Lista */
.filter-chip-tag {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.74rem;
  padding: 5px 11px; border-radius: 14px; border: 1px solid var(--border);
  background: transparent; color: var(--text-dim); cursor: pointer;
  opacity: 0.5; transition: opacity 0.15s, border-color 0.15s, color 0.15s;
  font-family: 'DM Sans', sans-serif; font-weight: 500;
}
.filter-chip-tag.active { opacity: 1; color: var(--text); border-color: var(--text-muted); }
.filter-chip-tag .lc-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.filter-chip-tag .lc-dot-dif { border-radius: 2px; }

/* Toggle Mapa / Lista — segmentado, flutua sobre a área principal */
.view-toggle {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 1100; display: inline-flex; gap: 2px;
  background: rgba(35,41,57,0.95); border: 1px solid var(--border);
  border-radius: 22px; padding: 3px; box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
.view-toggle-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 13px;
  border: none; background: none; cursor: pointer; color: var(--text-muted);
  font-family: 'DM Sans', sans-serif; font-size: 0.82rem; font-weight: 600;
  border-radius: 18px; transition: all 0.2s;
}
.view-toggle-btn.active { background: var(--accent); color: var(--bg-dark); }
.view-toggle-btn svg { display: block; }
a.view-toggle-btn { text-decoration: none; }

body.mode-list .mytracks-bar { display: none; }
body.mode-list .nav-controls { display: none; }
body.mode-list .cb-legend { display: none !important; }

@media (max-width: 768px) {
  /* A sidebar é drawer; na Lista mostramos pesquisa + camadas ativas no topo */
  .main-area { width: 100%; }
  .list-filters { display: block; }
  .list-view-head { padding-top: 60px; }
  .view-toggle-btn { padding: 6px 13px; font-size: 0.78rem; }
  /* Na Lista o mapa está coberto — esconder a atribuição/controlos Leaflet */
  body.mode-list .leaflet-control-container { display: none; }
}

/* ─── Leaflet Overrides ─── */
.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-card-hover) !important; }

/* ─── Filtro de distância (dual-range) ─── */
.filter-dist { padding: 6px 2px 2px; }
.fd-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.fd-title { font-size: 0.8rem; font-weight: 600; color: var(--text, #1a1a1a); }
.fd-val { font-size: 0.72rem; color: var(--text-muted, #777); margin-left: auto; }
.fd-reset { width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border, #d4d6db); background: var(--bg-card, #fff); color: var(--text, #444); border-radius: 6px; cursor: pointer; padding: 0; flex: 0 0 auto; }
.fd-reset:hover { background: var(--bg-card-hover, #f0f0f3); color: var(--accent, #e8a838); }
.fd-sliders { position: relative; height: 26px; touch-action: none; -webkit-user-select: none; user-select: none; }
.fd-track { position: absolute; top: 11px; left: 0; right: 0; height: 4px; background: var(--border, #d9dbe0); border-radius: 2px; }
.fd-fill { position: absolute; top: 11px; left: 0; width: 100%; height: 4px; background: var(--accent, #e8a838); border-radius: 2px; }
.fd-thumb {
  position: absolute; top: 13px; width: 20px; height: 20px; margin-top: -10px;
  border-radius: 50%; background: #fff; border: 2px solid var(--accent, #e8a838);
  box-shadow: 0 1px 3px rgba(0,0,0,0.35); cursor: pointer; touch-action: none; z-index: 2;
}
/* posições por defeito (estado 0–150), válidas mesmo antes de o JS posicionar */
#fdThumbMin { left: 0; }
#fdThumbMax { left: calc(100% - 20px); }
.fd-thumb:active { box-shadow: 0 0 0 5px var(--accent-dim, rgba(232,168,56,0.18)); }

/* ─── Camada Meteorologia ─── */
.wx-arrow-icon { background: none !important; border: 0 !important; }
.wx-arrow { width: 24px; height: 24px; transform-origin: 50% 50%; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.55)); }
.wx-temp-icon { background: none !important; border: 0 !important; }
.wx-temp {
  width: 100%; height: 100%; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  line-height: 1; white-space: nowrap; color: #fff; font-family: 'DM Sans', Arial, sans-serif;
  border: 1.5px solid rgba(255,255,255,0.9); border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.wx-temp b { font-size: 13px; font-weight: 800; letter-spacing: -0.3px; }
.wx-temp span { font-size: 10px; font-weight: 600; opacity: 0.78; }
.wx-slider {
  display: flex; align-items: center; gap: 7px; background: #1a1f2e; color: #fff;
  padding: 5px 10px; border-radius: 8px; border: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3); margin: 0 0 6px 6px;
}
.wx-slider .wx-cap { font-size: 0.62rem; font-weight: 700; color: #fff; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.4px; }
.wx-slider input[type=range] { width: 120px; height: 4px; accent-color: var(--accent, #e8a838); cursor: pointer; }
.wx-slider #wxTimeLbl { font-size: 0.74rem; font-weight: 700; color: #fff; min-width: 50px; text-align: center; }
.wx-legend { background: var(--bg-card, #fff); padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border, #d4d6db); font-family: Arial, sans-serif; box-shadow: 0 1px 4px rgba(0,0,0,0.2); }
.wx-leg-title { font-size: 0.7rem; font-weight: 700; color: var(--text, #1a1a1a); margin-bottom: 3px; }
.wx-leg-bar { display: flex; width: 120px; height: 8px; border-radius: 3px; overflow: hidden; }
.wx-leg-bar span { flex: 1; }
.wx-leg-scale { display: flex; justify-content: space-between; font-size: 0.6rem; color: var(--text-muted, #777); margin-top: 1px; }
.wx-leg-src { font-size: 0.58rem; color: var(--text-muted, #999); margin-top: 2px; text-align: right; }
@media (max-width: 640px) { .wx-slider input[type=range] { width: 110px; } }

/* Botão Mapa ↔ Satélite (header): estado ativo quando o satélite está ligado */
.header-auth-icon#basemapBtn.is-sat {
  background: var(--accent, #d4a23e);
  color: #fff;
  border-color: var(--accent, #d4a23e);
}

.district-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  font-family: 'DM Serif Display', serif;
  font-size: 13px;
  color: var(--accent);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.5);
  white-space: nowrap;
  pointer-events: none !important;
}

.elev-tooltip {
  background: rgba(26, 31, 46, 0.92) !important;
  border: 1px solid rgba(232, 168, 56, 0.3) !important;
  border-radius: 6px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4) !important;
  padding: 4px 10px !important;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: #e8e6e1 !important;
  white-space: nowrap;
  pointer-events: none !important;
}

.elev-tooltip::before {
  border-top-color: rgba(26, 31, 46, 0.92) !important;
}

/* ─── Trail Popup ─── */
.trail-popup {
  font-family: 'DM Sans', sans-serif;
}
.trail-popup .bs-addr { font-size: 0.82rem; color: #5c5e66; margin-bottom: 4px; }

.trail-popup h3 {
  font-family: 'DM Serif Display', serif;
  margin-bottom: 4px;
  font-size: 1rem;
  color: #1a1f2e;
}

.trail-popup p {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 2px;
}

.trail-popup .popup-meta {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.trail-popup .popup-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.trail-popup .popup-actions { display: flex; gap: 6px; align-items: stretch; margin-top: 8px; }
.trail-popup .popup-actions .popup-btn { margin-top: 0; flex: 1; text-align: center; }
.trail-popup .popup-actions .popup-btn-icon { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; padding: 5px 11px; }

/* ─── Legenda Comboios ─── */
.cb-legend {
  position: fixed;
  z-index: 1100;
  bottom: 16px;
  left: 16px;
  background: rgba(35, 41, 57, 0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.74rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.cb-legend-title {
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.cb-legend-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
  color: var(--text-muted);
}

.cb-swatch {
  width: 16px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}
.cb-swatch-dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid #fff; }
/* 2ª legenda (fontes) empilha por cima da dos comboios */
.cb-legend-2 { bottom: 200px; }
@media (max-width: 768px) { .cb-legend-2 { bottom: 130px; } }

@media (min-width: 769px) {
  /* No desktop o sidebar ocupa a esquerda — afasta a legenda para a área do mapa */
  .cb-legend { left: 396px; }
}

@media (max-width: 768px) {
  /* Legenda compacta no telemóvel */
  .cb-legend {
    left: 8px;
    bottom: 8px;
    padding: 7px 9px;
    font-size: 0.6rem;
    max-width: 46vw;
  }
  .cb-legend-title { margin-bottom: 3px; font-size: 0.66rem; }
  .cb-legend-row { gap: 5px; padding: 1px 0; line-height: 1.2; }
  .cb-swatch { width: 12px; height: 3px; }
}

/* Pilha de legendas (comboios + água/fontes) — empilham sem se sobreporem */
.legend-stack { position: fixed; z-index: 1100; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.legend-stack .cb-legend { position: static; left: auto; bottom: auto; }
@media (min-width: 769px) { .legend-stack { left: 396px; } }
@media (max-width: 768px) { .legend-stack { left: 8px; bottom: 8px; gap: 6px; } }
body.mode-list .legend-stack { display: none !important; }

/* ─── Loading ─── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}

.loading-overlay.fade-out { opacity: 0; pointer-events: none; }

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Back Button ─── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  margin: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.back-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

.back-btn svg { width: 16px; height: 16px; }

/* ─── Trail Detail (rota.html) ─── */
.trail-detail-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
/* linha de topo: ref à esquerda + ações (GPX/Partilhar) à direita; o título ocupa a largura toda por baixo */
.thr-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.thr-top .trail-ref { margin-bottom: 0; }
.trail-detail-header .trail-header-main { flex: 1; min-width: 0; }

.trail-detail-header h2 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.3rem;
  margin-bottom: 6px;
}

/* Descarregar GPX no cabeçalho — à direita, alinhado com o badge */
.gpx-btn-header {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 0.78rem;
}
@media (max-width: 480px) {
  .gpx-btn-header { padding: 8px; }
  .gpx-btn-header span { display: none; }   /* em ecrãs estreitos fica só o ícone */
}

.trail-detail-header .trail-ref {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  display: inline-block;
  margin-bottom: 8px;
}

.trail-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  padding: 12px 24px;
}
.stat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.98rem; color: var(--text);
}
.stat-chip svg { color: var(--accent); flex-shrink: 0; }
.stat-chip b { font-weight: 700; }
/* Menu "No mapa" dentro da página de rota */
.route-layers { padding: 4px 24px 10px; border-bottom: 1px solid var(--border); }
.route-layers .layers-section { margin: 0; }

/* Caixa do cabeçalho da rota: agrupa itens + ações + No Mapa num só bloco */
.detail-card { margin: 10px 24px 4px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; flex-shrink: 0; }
.detail-card .trail-detail-header { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.detail-card .route-layers { padding: 2px 16px 8px; border-bottom: none; }
/* Ações do cabeçalho (GPX + Partilhar) — proporcionadas e alinhadas */
.trail-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.hdr-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: 10px;
  font-family: 'DM Sans', sans-serif; font-size: 0.8rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--bg-card-hover, rgba(255,255,255,0.06));
  color: var(--text); text-decoration: none; cursor: pointer;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
}
.hdr-btn:hover { transform: translateY(-1px); }
.hdr-btn svg { flex-shrink: 0; }
.hdr-btn-primary { background: var(--accent); color: var(--bg-dark); border-color: var(--accent); }
.hdr-btn-primary:hover { background: var(--accent-light, #f0b94e); }
.hdr-btn-icon { width: 38px; padding: 0; }
@media (max-width: 480px) {
  .hdr-btn-primary span { display: none; }      /* em ecrãs estreitos fica só o ícone */
  .hdr-btn-primary { width: 38px; padding: 0; }
}
/* Toast (ex.: link copiado) */
.rota-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(12px);
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 18px; font-size: 0.85rem; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 4000; max-width: 86vw; text-align: center;
}
.rota-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
/* Caixa "Percursos + No Mapa" no mapa geral */
.layers-inline { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; background: rgba(255,255,255,0.02); }
/* Tipo de piso — barra retangular integrada no perfil (padding L/R por JS p/ alinhar) */
.surf-inline { margin-top: 8px; }
.surf-bar { display: flex; height: 12px; border-radius: 0; overflow: hidden; cursor: crosshair; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }
.surf-bar span { display: block; height: 100%; }
.surf-chip { display: inline-flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text); }
.surf-chip i { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.surf-chip b { font-weight: 700; }
/* barra de piso DENTRO da caixa do perfil (mesma largura do gráfico, com gap) */
#elevationSection .elevation-chart-wrap { display: flex; flex-direction: column; height: 180px; }
.elev-canvas-area { flex: 1 1 auto; position: relative; min-height: 0; }
#elevationSection .surf-inline { margin-top: 10px; }
/* distância (0 / total) por baixo da barra de piso */
.surf-dist { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-dim); margin-top: 5px; }
.surf-dist:empty { display: none; }
/* em mobile mantém-se o perfil E a barra de tipo (por baixo do perfil) */
/* resumo de km por tipo de via — separado dos valores globais, um por linha */
.surf-summary { padding: 14px 24px 4px; border-top: 1px solid var(--border); }
.surf-summary-head { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); font-weight: 600; margin-bottom: 9px; }
.surf-stats { display: flex; flex-direction: column; gap: 4px; }
.surf-stats .surf-chip { padding: 4px 8px; border-radius: 6px; cursor: pointer; transition: background .12s; }
.surf-stats .surf-chip:hover { background: rgba(255,255,255,.07); }
.surf-stats .surf-chip b { margin-left: auto; }
.elevation-pinned .surf-inline { margin-top: 8px; padding: 0 10px 8px; }
/* perfil colapsado em mobile → esconde também a barra de tipo */
.elevation-pinned.collapsed .surf-inline { display: none; }

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
}

.stat-card .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

/* ─── GPX Button ─── */
.gpx-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg-dark);
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.gpx-btn:hover { background: var(--accent-light); transform: translateY(-1px); }

/* ─── Elevation Chart ─── */
.elevation-container {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

/* Perfil de elevação FIXO ao fundo do mapa em MOBILE (#elevPinned, fora do
   drawer → sempre visível, mesmo com o menu fechado). No desktop usa-se a
   versão em scroll (#elevationSection, dentro do sidebar). */
.elevation-pinned {
  border-top: 1px solid var(--border);
  border-bottom: none;
  background: var(--bg-dark);
}
#elevPinned {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1200;
  padding: 6px 12px 8px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}

/* Botão para recolher/expandir o perfil */
.elev-toggle {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  width: 100%; background: none; border: none; cursor: pointer; padding: 0 0 6px;
}
.elev-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--text-dim); }
.elev-row { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.elev-toggle-label { font-family: 'DM Serif Display', serif; font-size: 0.9rem; color: var(--text); }
.elev-chevron { width: 16px; height: 16px; color: var(--text-muted); transition: transform 0.25s ease; }
.elevation-pinned.collapsed .elev-chevron { transform: rotate(180deg); }
.elevation-pinned .elevation-chart-wrap { transition: height 0.25s ease, opacity 0.2s ease; height: 120px; }
.elevation-pinned.collapsed .elevation-chart-wrap {
  height: 0 !important; min-height: 0; padding: 0; margin: 0; border: none; opacity: 0; overflow: hidden;
}

@media (max-width: 768px) {
  /* mobile: vale a barra fixa; a versão em scroll do sidebar esconde-se */
  #elevationSection { display: none !important; }
}
@media (min-width: 769px) {
  /* desktop: vale a versão em scroll; a barra fixa esconde-se */
  #elevPinned { display: none !important; }
  body.rota-page .back-btn { margin: 8px 16px 2px; padding: 6px 14px; }
  body.rota-page .breadcrumb { padding: 8px 24px; }
  body.rota-page .detail-card .trail-detail-header { padding: 14px 16px; }
  body.rota-page .trail-stats { padding: 10px 24px; gap: 8px; }
  body.rota-page #elevationSection .elevation-chart-wrap { height: 170px; }
}

.elevation-container h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1rem;
  margin-bottom: 12px;
}

.elevation-chart-wrap {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 12px;
  height: 200px;
  position: relative;
}

/* ─── Feedback Section ─── */
.feedback-section {
  padding: 16px 24px;
}

.feedback-section h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1rem;
  margin-bottom: 12px;
}

.feedback-card {
  background: linear-gradient(135deg, rgba(30,37,56,0.95), rgba(24,30,46,0.98));
  border: 1px solid rgba(232,168,56,0.08);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.feedback-card:hover {
  border-color: rgba(232,168,56,0.2);
}

.feedback-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.feedback-author {
  background: rgba(232,168,56,0.12);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.feedback-time {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.feedback-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.feedback-tag {
  background: rgba(78,203,113,0.08);
  color: var(--green);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  font-weight: 500;
}

.feedback-text {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 10px;
}

/* Resposta oficial (admin) dentro de um comentário */
.feedback-admin-reply {
  background: rgba(232,168,56,0.10);
  border: 1px solid rgba(232,168,56,0.22);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin: 4px 0 10px;
  font-size: 0.84rem;
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
}
.feedback-admin-reply-head {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.74rem;
  margin-bottom: 4px;
}
.feedback-admin-reply-head .feedback-time { font-weight: 400; }

.feedback-estado {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.estado-excelente { background: rgba(78,203,113,0.12); color: var(--green); }
.estado-bom { background: rgba(78,203,113,0.08); color: #8bc78b; }
.estado-razoavel { background: rgba(232,168,56,0.12); color: var(--accent); }
.estado-mau { background: rgba(240,96,80,0.12); color: var(--red); }
.estado-fechado { background: rgba(139,141,149,0.12); color: var(--text-muted); }

.confirm-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.confirm-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.confirm-btn.confirmed {
  background: rgba(78,203,113,0.12);
  border-color: var(--green);
  color: var(--green);
}

/* ─── Auth Forms ─── */
.auth-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}

.auth-form h4 {
  font-family: 'DM Serif Display', serif;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--accent);
}

.form-textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px 14px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  outline: none;
  resize: vertical;
  transition: border-color 0.2s;
}

.form-textarea:focus {
  border-color: var(--accent);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg-dark);
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-primary:hover { background: var(--accent-light); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--red);
  background: rgba(248, 113, 113, 0.14);
  color: var(--red);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

/* --- Auth Modal --- */
.auth-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-modal {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  position: relative;
}

.auth-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

.auth-modal-close:hover {
  color: var(--text);
}

/* --- Password Strength --- */
.password-strength {
  margin: 6px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.password-strength-bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  position: relative;
  overflow: hidden;
}

.password-strength-bar::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: var(--strength, 0%);
  background: var(--strength-color, var(--red));
  border-radius: 2px;
  transition: width 0.3s, background 0.3s;
}

.password-strength-text {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ─── Tag Selector ─── */
.tag-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tag-chip {
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tag-chip:hover {
  border-color: var(--green);
  color: var(--green);
}

.tag-chip.active {
  background: rgba(78,203,113,0.12);
  border-color: var(--green);
  color: var(--green);
  font-weight: 600;
}

/* ─── Empty State ─── */
.empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-dim);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 0.88rem;
}

/* ─── Sheet Handle (bottom sheet on mobile) ─── */
.sheet-handle {
  display: none;
}

.sheet-handle-bar {
  width: 40px;
  height: 4px;
  background: var(--text-dim);
  border-radius: 2px;
}

/* Label de afford. — só visível quando o sheet está recolhido */
.sheet-handle-label {
  display: none;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.sheet-handle-label svg {
  width: 15px;
  height: 15px;
  color: var(--accent);
}

.sidebar[data-state="collapsed"] .sheet-handle-label {
  display: flex;
}

/* ─── Sidebar Scroll Wrapper ─── */
.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 4px; }

/* ─── Floating Elements (rota.html) ─── */
.float-back-btn {
  display: none;
  position: fixed;
  top: 64px;
  left: 16px;
  z-index: 1001;
  padding: 8px 16px;
  border-radius: 20px;
  background: rgba(35, 41, 57, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  align-items: center;
  gap: 6px;
  transition: opacity 0.2s;
}

.float-back-btn svg { width: 14px; height: 14px; }

.float-locate-btn {
  display: flex;
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(35, 41, 57, 0.92);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s;
}

/* Inside nav-controls, reset positioning (parent is the container) */
.nav-controls .float-locate-btn {
  position: static;
}

.float-locate-btn svg { width: 18px; height: 18px; }
.float-sat { top: 108px; }   /* satélite por baixo do localização (top:64) */

.float-locate-btn.active {
  color: #4a90d9;
  border-color: rgba(74, 144, 217, 0.4);
}

.float-locate-btn.loading {
  color: var(--accent);
  animation: pulse-locate 1s ease infinite;
}

@keyframes pulse-locate {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.elev-float-overlay {
  position: fixed;
  bottom: 48px;
  left: 0;
  right: 0;
  height: 120px;
  z-index: 999;
  background: rgba(26, 31, 46, 0.92);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  display: none;
}

/* ─── Rota.html specific layout ─── */
body.rota-page {
  flex-direction: row;
}

body.rota-page .sidebar {
  overflow: hidden;
}


body.rota-page .sidebar::-webkit-scrollbar { width: 4px; }
body.rota-page .sidebar::-webkit-scrollbar-track { background: transparent; }
body.rota-page .sidebar::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 4px; }

/* ─── Mobile Responsive ─── */
@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  /* Top bar mobile: nome à esquerda, Sugestões à direita (brand tem margin-right:auto) */
  .app-header .header-auth { display: none; }

  /* Login dentro do sidebar */
  .sidebar-auth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 6px 16px 12px;
    border-bottom: 1px solid var(--border);
  }

  /* Drawer lateral: desliza da esquerda. Mapa fica em ecrã inteiro por trás. */
  .sidebar {
    width: 86%;
    max-width: 360px;
    min-width: 0;
    border-right: 1px solid var(--border);
    position: fixed;
    top: 48px;
    bottom: 0;
    left: 0;
    right: auto;
    height: auto;
    max-height: none;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    z-index: 1500;
    border-radius: 0 16px 16px 0;
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
    overflow: visible;
    display: flex;
    flex-direction: column;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Pega: protunde da margem direita do painel; visível mesmo fechado (na borda esquerda do ecrã) */
  .drawer-handle {
    display: flex;
    position: absolute;
    top: 50%;
    right: -36px;
    transform: translateY(-50%);
    width: 36px;
    height: 84px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 14px 14px 0;
    box-shadow: 4px 0 16px rgba(0,0,0,0.3);
    color: var(--accent);
    cursor: pointer;
  }

  .drawer-handle-icon { width: 18px; height: 18px; }

  .drawer-handle-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform 0.28s ease;
  }

  .sidebar.open .drawer-handle-chevron { transform: rotate(180deg); }

  /* Backdrop por baixo do drawer, por cima do mapa */
  .drawer-backdrop {
    display: block;
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
  }

  .drawer-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }

  #map {
    height: calc(100vh - 48px);
    width: 100%;
  }

  /* rota.html mobile */
  body.rota-page {
    flex-direction: column;
  }

  /* rota.html usa o mesmo drawer lateral da base.
     Anular o overflow:hidden do desktop para a pega poder sobressair. */
  body.rota-page .sidebar {
    overflow: visible;
  }

  /* Botão flutuante para voltar ao mapa (drawer fechado) */
  body.rota-page .float-back-btn {
    display: flex;
  }

  body.rota-page #map {
    height: calc(100vh - 48px);
    min-height: calc(100vh - 48px);
    order: unset;
  }

  .trail-stats {
    grid-template-columns: 1fr 1fr;
  }

  .elevation-chart-wrap {
    height: 150px;
  }

  .elev-float-overlay.visible {
    display: block;
  }

}

@media (max-width: 480px) {
  .sidebar-header {
    padding: 16px;
  }

  .sidebar-header h1 {
    font-size: 1.3rem;
  }

  .trail-stats {
    grid-template-columns: 1fr;
  }
}

/* ─── Navigation Active: hide header ─── */
body.nav-active .app-header {
  display: none;
}

body.nav-active .sidebar {
  top: 0;
  height: 100vh;
}

body.nav-active #map {
  top: 0;
  height: 100vh;
}

/* ═══════════════════════════════════════════════
   Navigation Mode
   ═══════════════════════════════════════════════ */

/* ─── HUD (Heads-Up Display) ─── */
.nav-hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1002;
  display: none;
  justify-content: space-around;
  padding: 8px 12px;
  background: rgba(26, 31, 46, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  gap: 4px;
}

.nav-hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}

.nav-hud-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.nav-hud-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.nav-accuracy-bad {
  color: var(--red) !important;
}

/* ─── User Marker ─── */
.nav-user-marker {
  background: none !important;
  border: none !important;
}

.nav-arrow {
  transition: transform 0.3s ease;
}


/* ─── Battery Warning ─── */
.nav-battery-warn {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1003;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: rgba(251, 191, 36, 0.92);
  color: var(--bg-dark);
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(251, 191, 36, 0.3);
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Navigation Controls ─── */
.nav-controls {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.float-nav-btn {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(74, 144, 217, 0.92);
  border: 1px solid rgba(74, 144, 217, 0.6);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s;
}

.float-nav-btn svg { width: 18px; height: 18px; }
.float-nav-btn:hover { background: rgba(74, 144, 217, 1); transform: scale(1.05); }

.float-nav-stop {
  background: rgba(248, 113, 113, 0.92);
  border-color: rgba(248, 113, 113, 0.6);
}
.float-nav-stop:hover { background: rgba(248, 113, 113, 1); }

.float-nav-btn-sm {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(35, 41, 57, 0.92);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s;
}

.float-nav-btn-sm svg { width: 16px; height: 16px; }

.float-nav-btn-sm.active {
  color: #4a90d9;
  border-color: rgba(74, 144, 217, 0.4);
  background: rgba(74, 144, 217, 0.15);
}

.float-nav-btn-sm:hover {
  color: var(--text);
  border-color: rgba(255,255,255,0.15);
}

/* ═══════════════════════════════════════════════
   Media Gallery & Upload
   ═══════════════════════════════════════════════ */

/* ─── Media Section ─── */
.media-section {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.media-section h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1rem;
  margin-bottom: 12px;
}

.media-empty {
  font-size: 0.82rem;
  color: var(--text-dim);
  text-align: center;
  padding: 16px 0;
}

.media-login-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  margin-top: 8px;
  background: var(--bg-card);
  border: 2px dashed var(--text-dim);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

/* ─── Media Grid ─── */
.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.media-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.media-thumb:hover {
  border-color: var(--accent);
}

.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}

.media-thumb-placeholder svg {
  width: 28px;
  height: 28px;
}

.media-badge-video {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

/* ─── Dropzone ─── */
.media-dropzone {
  background: var(--bg-card);
  border: 2px dashed var(--text-dim);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 10px;
}

.media-dropzone:hover,
.media-dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.media-dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.85rem;
  min-height: 60px;
}

.media-dropzone-content svg {
  color: var(--accent);
  width: 28px;
  height: 28px;
}

/* ─── Preview ─── */
.media-preview {
  position: relative;
  max-height: 200px;
  overflow: hidden;
  border-radius: var(--radius-sm);
}

.media-preview img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.media-preview-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── Progress bar ─── */
.media-progress {
  height: 4px;
  background: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.media-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ─── Lightbox ─── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
}

.lightbox.visible {
  display: flex;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  cursor: pointer;
}

.lightbox-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 95vw;
  max-height: 95vh;
}

.lightbox-media {
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.lightbox-close:hover { background: rgba(255,255,255,0.25); }

.lightbox-prev,
.lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.lightbox-prev { left: -50px; }
.lightbox-next { right: -50px; }
.lightbox-prev:hover,
.lightbox-next:hover { background: rgba(255,255,255,0.2); }

.lightbox-caption {
  color: #fff;
  font-size: 0.9rem;
  margin-top: 12px;
  text-align: center;
}

.lightbox-author {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 4px;
}

/* ─── Mobile adjustments for nav & media ─── */
@media (max-width: 768px) {
  .nav-hud {
    padding: 6px 8px;
  }

  .nav-hud-value {
    font-size: 0.82rem;
  }

  .nav-controls {
    top: 60px;
    right: 12px;
  }

  .lightbox-prev { left: 8px; }
  .lightbox-next { right: 8px; }
  .lightbox-close { top: 8px; right: 8px; }

  .media-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
}
