* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --topbar-h: 50px;
  --sidebar-w: 340px;
  --panel: #171b26;
  --panel-2: #212736;
  --panel-hover: #2a3143;
  --border: rgba(255,255,255,0.08);
  --text: #e9e7e2;
  --muted: #8b8f9c;
  --accent: #e8a838;
  --blue: #2563eb;
  --red: #dc2626;
  --green: #059669;
}

html, body { height: 100%; font-family: 'DM Sans', system-ui, sans-serif; color: var(--text); background: var(--panel); }
#map { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 1; background: #aadaff; }

/* ── Topbar (index) ── */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 600;
  display: flex; align-items: center; gap: 9px; height: var(--topbar-h);
  padding: 0 14px; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar .logo { width: 26px; height: 26px; flex: none; }
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.topbar .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.topbar a.back { flex: none; display: inline-flex; color: var(--text); }
.topbar a.back svg { width: 22px; height: 22px; }
.topbar h1 .q { color: var(--accent); }
.multi-head { padding: 10px 14px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--border); }
.multi-head b { color: var(--text); font-weight: 600; }
.sidebar-toggle {
  display: none; flex: none; width: 30px; height: 30px; padding: 4px;
  background: none; border: none; color: var(--text); cursor: pointer;
}
.sidebar-toggle svg { width: 22px; height: 22px; }
.edit-toggle {
  flex: none; width: 30px; height: 30px; padding: 5px; margin-left: 6px;
  background: none; border: none; color: var(--muted); cursor: pointer;
}
.edit-toggle:hover { color: var(--text); }
.edit-toggle.active { color: #ff6b6b; }
.edit-toggle svg { width: 20px; height: 20px; }

/* Balão de resumo do track */
.leaflet-popup-content-wrap { border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,0.25); }
.leaflet-popup-content { margin: 12px 14px; }
.pop-name { font-weight: 700; font-size: 14px; color: #1a1f2e; line-height: 1.25; }
.pop-meta { font-size: 12.5px; color: #5c5e66; margin-top: 3px; }
/* seletor específico p/ vencer o `.leaflet-container a` (cor de link do Leaflet) */
.leaflet-popup-content a.pop-btn {
  display: inline-block; margin-top: 10px; padding: 7px 15px;
  background: var(--blue); color: #fff; border-radius: 8px;
  text-decoration: none; font-size: 12.5px; font-weight: 600;
}
.leaflet-popup-content a.pop-btn:hover { filter: brightness(1.08); color: #fff; }

/* Zoom abaixo da barra */
.leaflet-top { top: calc(var(--topbar-h) + 8px); }
.leaflet-bar a { background: var(--panel-2); color: var(--text); border-bottom-color: var(--border); }
.leaflet-bar a:hover { background: var(--panel-hover); }
.locate-ctrl a { display: flex; align-items: center; justify-content: center; }
.locate-ctrl a svg { width: 17px; height: 17px; }
.locate-ctrl.locating a { color: var(--accent); }
@keyframes locpulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.locate-ctrl.locating a svg { animation: locpulse 1s ease-in-out infinite; }

/* ── Sidebar / lista ── */
.sidebar {
  position: absolute; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidebar-w);
  z-index: 450; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}

/* Filtros (tabs) */
.tabs { display: flex; gap: 5px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.tabs .tab {
  flex: 1; padding: 8px 4px; font-family: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--muted); background: var(--panel-2); border: 1px solid transparent; border-radius: 8px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tabs .tab:hover { background: var(--panel-hover); color: var(--text); }
.tabs .tab.active { background: var(--accent); color: #1a1305; }

/* Pesquisa */
.search { padding: 10px 12px 8px; border-bottom: 1px solid var(--border); }
.search-row { position: relative; display: flex; align-items: center; }
.search-row svg { position: absolute; left: 10px; width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; padding: 9px 30px 9px 32px; font-family: inherit; font-size: 13.5px;
  color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); }
.search-clear {
  position: absolute; right: 6px; width: 22px; height: 22px; border: none; background: none;
  color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; display: none;
}
.search-clear.show { display: block; }
.open-all {
  display: none; width: 100%; margin-top: 8px; padding: 9px; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600; color: #1a1305;
  background: var(--accent); border: none; border-radius: 9px;
}
.open-all.show { display: block; }
.open-all:hover { filter: brightness(1.06); }

.track-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.track-list .empty { padding: 18px 16px; color: var(--muted); font-size: 13px; }
.track-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 14px; background: none; border: none; cursor: pointer;
  border-bottom: 1px solid var(--border); font-family: inherit; color: inherit;
}
.track-item:hover { background: var(--panel-2); }
.track-item .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; cursor: pointer; }
.track-item .dot.plan { border-radius: 2px; }
.track-item .ti-main { flex: 1; min-width: 0; display: flex; flex-direction: column; cursor: pointer; }
.track-item .del {
  display: none; flex: none; width: 30px; height: 30px; margin-left: 6px; margin-right: -4px;
  align-items: center; justify-content: center; border: none; background: none;
  color: var(--muted); cursor: pointer; border-radius: 7px;
}
.track-item .del:hover { background: rgba(220,38,38,0.16); color: #ff6b6b; }
.track-item .del svg { width: 16px; height: 16px; }
body.edit-mode .track-item .del,
.track-item.can-del .del { display: inline-flex; }
.track-item .ti-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-item .ti-meta { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

/* Desktop: mapa à direita da sidebar */
@media (min-width: 700px) {
  #map { left: var(--sidebar-w); }
}

/* Mobile: sidebar como gaveta */
@media (max-width: 699px) {
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    width: 86%; max-width: 360px; transform: translateX(-100%);
    transition: transform 0.22s ease; box-shadow: 2px 0 22px rgba(0,0,0,0.5);
  }
  .sidebar.open { transform: none; }
}

/* ═══ Página de track individual ═══ */
.track-page .sidebar { top: 0; }
.tp-head { padding: 12px 16px 10px; border-bottom: 1px solid var(--border); }
.tp-back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: 12.5px; margin-bottom: 8px; }
.tp-back:hover { color: var(--text); }
.tp-back svg { width: 15px; height: 15px; }
.tp-name { font-size: 18px; font-weight: 700; line-height: 1.2; }
.tp-date { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

.tp-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.stat { background: var(--panel-2); border-radius: 10px; padding: 9px 11px; }
.stat .k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .v { font-size: 17px; font-weight: 700; margin-top: 2px; }
.stat .v small { font-size: 12px; font-weight: 600; color: var(--muted); }

.tp-gallery { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.tp-gallery .gal-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 8px; }
.tp-gallery .gal-strip { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tp-gallery .gal-strip img {
  flex: none; width: 76px; height: 76px; object-fit: cover; border-radius: 8px;
  cursor: pointer; background: var(--panel-2);
}
.gal-lightbox {
  position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.gal-lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }
.gal-lightbox .gal-close {
  position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.12); border: none; color: #fff; font-size: 22px; line-height: 1;
  cursor: pointer;
}
.gal-lightbox .gal-close:hover { background: rgba(255,255,255,0.22); }

.tp-elev {
  position: absolute; right: 0; bottom: 0; z-index: 450; height: var(--elev-h);
  background: var(--panel); border-top: 1px solid var(--border);
  padding: 8px 12px 6px; flex-direction: column;
}
.tp-elev .elev-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 4px 4px; }
.tp-elev .elev-wrap { position: relative; flex: 1; min-height: 0; }
.tp-foot { padding: 10px 16px 14px; border-top: 1px solid var(--border); }
.tp-dl { display: inline-flex; align-items: center; gap: 7px; color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 600; }
.tp-dl:hover { text-decoration: underline; }

.msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px; z-index: 700; background: var(--panel); text-align: center; padding: 24px; color: var(--text); }
.msg a { color: var(--accent); }

/* Track individual — desktop: sidebar à esquerda; mapa + perfil (largura do mapa) à direita */
.track-page { --elev-h: 190px; }
@media (min-width: 700px) {
  .track-page #map { left: var(--sidebar-w); }
  .track-page.has-elev #map { bottom: var(--elev-h); }
  .track-page .tp-elev { left: var(--sidebar-w); }
}
/* Track individual — mobile: mapa, perfil, e painel de dados em baixo */
@media (max-width: 699px) {
  .track-page { --elev-h: 150px; --sheet-h: 36vh; }
  .track-page #map { left: 0; bottom: var(--sheet-h); }
  .track-page.has-elev #map { bottom: calc(var(--sheet-h) + var(--elev-h)); }
  .track-page .tp-elev { left: 0; bottom: var(--sheet-h); }
  .track-page .sidebar {
    top: auto; bottom: 0; width: 100%; max-width: none; height: var(--sheet-h); transform: none;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    border-right: none; border-top: 1px solid var(--border); box-shadow: 0 -3px 18px rgba(0,0,0,0.4);
  }
}

/* Fundo da gaveta (mobile): toque fora fecha */
.drawer-backdrop { display: none; }
@media (max-width: 699px) {
  .drawer-backdrop.show {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; top: var(--topbar-h);
    z-index: 440; background: rgba(0,0,0,0.4);
  }
}

/* Balão: ações (Ver track + Apagar) */
.pop-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.pop-actions a.pop-btn { margin-top: 0; }
.pop-del {
  padding: 6px 13px; background: #fff; color: #dc2626; border: 1px solid #dc2626;
  border-radius: 8px; font: 600 12.5px 'DM Sans', system-ui, sans-serif; cursor: pointer;
}
.pop-del:hover { background: #fef2f2; }

.tp-foot { display: flex; flex-direction: column; gap: 8px; }
.tp-foot .tp-plan { color: var(--text); }
