/* ==========================================================================
   Mapa Astronómico — hoja de estilos
   ========================================================================== */

:root {
    --app-bg-dark: #0d1117;
    --app-panel-bg: rgba(255, 255, 255, 0.97);
    --app-panel-border: rgba(0, 0, 0, 0.08);
    --app-accent: #6366f1;
    --app-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
    --app-radius: 10px;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Navbar
   -------------------------------------------------------------------------- */
.app-navbar { min-height: 42px; z-index: 1030; }
.app-navbar .navbar-brand { font-size: .85rem; }
.app-navbar-title { font-size: .8rem; opacity: .75; }
.app-navbar-btn { font-size: .75rem; }
.app-navbar-credit { color: rgba(255,255,255,.5); font-size: .72rem; }
.app-navbar-credit a { color: rgba(255,255,255,.75); text-decoration: none; }
.app-navbar-credit a:hover { color: #fff; }

/* --------------------------------------------------------------------------
   Mapa
   -------------------------------------------------------------------------- */
#map {
    width: 100%;
    height: calc(100vh - 42px);
    z-index: 1;
}

#map-container { position: relative; }

.leaflet-custom-div-icon { background: transparent; border: none; }

.color-dot {
    height: 13px;
    width: 13px;
    background-color: #bbb;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
    vertical-align: middle;
    border: 1px solid rgba(0,0,0,.3);
    flex-shrink: 0;
}

/* Popup de marcador */
.popup-marker { display: flex; align-items: flex-start; gap: 8px; }
.popup-marker-body { flex: 1; min-width: 0; font-size: .85rem; }
.popup-gmaps-link { flex-shrink: 0; color: #555; font-size: 1.05em; line-height: 1; padding: 2px; }
.popup-gmaps-link:hover { color: var(--app-accent); }

/* --------------------------------------------------------------------------
   Overlay de carga
   -------------------------------------------------------------------------- */
#map-loading-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 900;
    background: rgba(13, 17, 23, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
#map-loading-overlay.active { display: flex; }
.map-loading-content { text-align: center; }
.map-loading-text {
    color: rgba(255,255,255,0.8);
    margin-top: .8rem;
    font-size: .95rem;
    font-weight: 500;
    letter-spacing: .3px;
}

/* --------------------------------------------------------------------------
   Selector de proyecto (admin)
   -------------------------------------------------------------------------- */
#project-selector-container {
    position: absolute;
    bottom: 20px;
    left: 12px;
    z-index: 1000;
    background: var(--app-panel-bg);
    padding: 10px;
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    border: 1px solid var(--app-panel-border);
    max-width: 270px;
}
#project-selector-container label {
    margin-bottom: 4px;
    font-weight: 600;
    display: block;
    font-size: .8rem;
}
#project-selector-container select { min-width: 180px; }

/* --------------------------------------------------------------------------
   Panel de capas
   -------------------------------------------------------------------------- */
.layer-panel-toggle,
.marker-list-toggle {
    position: absolute;
    z-index: 1001;
    top: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--app-panel-bg);
    border: 1px solid var(--app-panel-border);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: .82rem;
    font-weight: 600;
    color: #333;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.layer-panel-toggle { left: 54px; }
.marker-list-toggle { right: 54px; }

.layer-panel-toggle:hover,
.marker-list-toggle:hover { background: #fff; color: #000; }

.layer-panel-toggle-active,
.marker-list-toggle-active { background: var(--app-accent); color: #fff; border-color: var(--app-accent); }
.layer-panel-toggle-active:hover,
.marker-list-toggle-active:hover { background: #4f52d9; color: #fff; }

.layer-panel {
    position: absolute;
    z-index: 1002;
    top: 54px;
    left: 12px;
    width: 300px;
    max-height: calc(100% - 90px);
    background: var(--app-panel-bg);
    border: 1px solid var(--app-panel-border);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity .15s, transform .15s;
}
.layer-panel-hidden { opacity: 0; transform: translateY(-6px); pointer-events: none; }

.lp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    font-weight: 700;
    font-size: .9rem;
    border-bottom: 1px solid var(--app-panel-border);
    background: rgba(99,102,241,.06);
}
.lp-close { border: 0; background: transparent; color: #666; cursor: pointer; padding: 2px 4px; }
.lp-close:hover { color: #000; }

.lp-body { overflow-y: auto; padding: 6px 0 10px; }

.lp-section { border-bottom: 1px solid rgba(0,0,0,.05); }
.lp-section:last-child { border-bottom: 0; }

.lp-section-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: 0;
    padding: 9px 14px;
    font-size: .82rem;
    font-weight: 700;
    color: #333;
    cursor: pointer;
}
.lp-section-header i:first-child { color: var(--app-accent); }
.lp-chevron { margin-left: auto; font-size: .7rem; transition: transform .18s; }
.lp-collapsed .lp-chevron { transform: rotate(-90deg); }
.lp-collapsed .lp-section-body { display: none; }

.lp-section-body { padding: 0 14px 10px; }

.lp-row { padding: 3px 0; }
.lp-switch label { font-size: .82rem; }
.lp-switch .form-check-input { cursor: pointer; }

.lp-subrow {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 0 2px 8px;
}
.lp-sublabel {
    font-size: .74rem;
    color: #777;
    min-width: 82px;
    flex-shrink: 0;
}
.lp-slider { flex: 1; height: 4px; accent-color: var(--app-accent); }
.lp-color {
    width: 36px;
    height: 24px;
    padding: 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: none;
    cursor: pointer;
}

.lp-base-group { display: flex; gap: 6px; flex-wrap: wrap; }
.lp-base-btn {
    flex: 1;
    border: 1px solid #d5d5e0;
    background: #fff;
    border-radius: 6px;
    font-size: .76rem;
    padding: 5px 6px;
    cursor: pointer;
    color: #444;
    white-space: nowrap;
}
.lp-base-btn:hover { border-color: var(--app-accent); color: var(--app-accent); }
.lp-base-btn.active { background: var(--app-accent); border-color: var(--app-accent); color: #fff; font-weight: 600; }

.lp-fill-controls { padding-left: 8px; }
.lp-muted { font-size: .74rem; color: #999; }
.lp-note { padding: 4px 0 2px; }

/* Camino Primitivo: etiquetas de localidades de etapa */
.leaflet-tooltip.camino-town-label {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    font-size: 12px;
    font-weight: 700;
    color: #0b2a5b;
    text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff;
}
.leaflet-tooltip.camino-town-label::before { display: none; }
.camino-labels-hidden .leaflet-tooltip.camino-town-label { display: none; }

.lp-custom-picker { padding: 6px 0 0 8px; }
.lp-custom-list {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 6px;
    margin-bottom: 6px;
}
.lp-custom-item {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 0;
    background: transparent;
    padding: 4px 10px;
    font-size: .78rem;
    text-transform: capitalize;
    cursor: pointer;
    color: #333;
}
.lp-custom-item:hover { background: rgba(99,102,241,.08); }
.lp-custom-item i { color: #3cb44b; }
.lp-custom-selected { display: flex; flex-wrap: wrap; gap: 4px; }
.lp-custom-badge {
    background: var(--app-accent);
    color: #fff;
    font-size: .72rem;
    border-radius: 10px;
    padding: 2px 8px;
    text-transform: capitalize;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.lp-custom-badge i { cursor: pointer; }

.lp-categories { margin-top: 6px; }
.lp-cat-title {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #999;
    font-weight: 700;
    margin: 4px 0;
}
.lp-cat-row {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: .82rem;
    padding: 3px 4px;
    border-radius: 5px;
    cursor: pointer;
    margin: 0;
}
.lp-cat-row:hover { background: rgba(99,102,241,.07); }
.lp-cat-row input { margin: 0; cursor: pointer; accent-color: var(--app-accent); }
.lp-cat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------------------
   Lista de puntos (drawer)
   -------------------------------------------------------------------------- */
.marker-drawer {
    position: absolute;
    z-index: 1002;
    top: 54px;
    right: 12px;
    width: 320px;
    max-height: calc(100% - 90px);
    background: var(--app-panel-bg);
    border: 1px solid var(--app-panel-border);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity .15s, transform .15s;
}
.marker-drawer-hidden { opacity: 0; transform: translateY(-6px); pointer-events: none; }

.md-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    font-weight: 700;
    font-size: .9rem;
    border-bottom: 1px solid var(--app-panel-border);
    background: rgba(99,102,241,.06);
}
.md-count { color: #888; font-weight: 500; font-size: .78rem; }
.md-close { border: 0; background: transparent; color: #666; cursor: pointer; padding: 2px 4px; }
.md-close:hover { color: #000; }
.md-search { padding: 8px 12px; border-bottom: 1px solid rgba(0,0,0,.05); }
.md-body { overflow-y: auto; padding: 4px 0 10px; }
.md-empty { text-align: center; color: #999; font-size: .82rem; padding: 16px; }

.md-group { margin-bottom: 4px; }
.md-group-title {
    display: flex;
    align-items: center;
    font-size: .76rem;
    font-weight: 700;
    color: #555;
    padding: 7px 14px 3px;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.md-group-count { margin-left: auto; color: #aaa; font-weight: 500; }

.md-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 0;
}
.md-item:hover { background: rgba(99,102,241,.06); }
.md-item-main { flex: 1; min-width: 0; cursor: pointer; }
.md-item-name { font-size: .84rem; font-weight: 500; color: #222; }
.md-item-desc {
    font-size: .74rem;
    color: #888;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}
.md-item-expanded .md-item-desc { -webkit-line-clamp: unset; }
.md-item-actions { display: flex; gap: 2px; flex-shrink: 0; }
.md-action {
    border: 0;
    background: transparent;
    color: #999;
    font-size: .95rem;
    padding: 2px 5px;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.4;
}
.md-action:hover { color: var(--app-accent); }

/* --------------------------------------------------------------------------
   Leyenda flotante
   -------------------------------------------------------------------------- */
.map-legend {
    position: absolute;
    z-index: 1000;
    bottom: 26px;
    right: 12px;
    max-width: 240px;
    max-height: 42vh;
    background: var(--app-panel-bg);
    border: 1px solid var(--app-panel-border);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.map-legend-hidden { display: none; }
.map-legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 10px;
    font-size: .76rem;
    font-weight: 700;
    color: #444;
    border-bottom: 1px solid rgba(0,0,0,.06);
    background: rgba(99,102,241,.06);
}
.map-legend-close {
    border: 0;
    background: transparent;
    color: #888;
    cursor: pointer;
    padding: 0 2px;
    font-size: .7rem;
    line-height: 1;
}
.map-legend-close:hover { color: #000; }
.map-legend-items { overflow-y: auto; padding: 5px 6px; }
.map-legend-item {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: .8rem;
    color: #222;
    padding: 3px 6px;
    border-radius: 5px;
    cursor: pointer;
    user-select: none;
}
.map-legend-item:hover { background: rgba(99,102,241,.08); }
.map-legend-item-inactive { opacity: .45; text-decoration: line-through; }
.map-legend-item-static { cursor: default; }
.map-legend-item-static:hover { background: transparent; }

/* --------------------------------------------------------------------------
   Buscador del mapa
   -------------------------------------------------------------------------- */
/* Los controles Leaflet de arriba a la derecha (lupa, descarga) se bajan para
   no solaparse con el botón "Puntos" cuando el buscador se expande. */
#map-container .leaflet-top.leaflet-right { margin-top: 46px; }

.map-search-control {
    background: #fff;
    border-radius: 6px;
    padding: 6px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
    transition: width 0.25s ease, padding 0.25s ease;
    overflow: hidden;
}
.map-search-control.map-search-collapsed .map-search-inner { display: none; }
.map-search-control.map-search-collapsed { padding: 0; }
.map-search-toggle-btn {
    border: none;
    background: transparent;
    padding: 7px 9px;
    cursor: pointer;
    font-size: 16px;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
}
.map-search-toggle-btn:hover { color: #000; }
.map-search-control:not(.map-search-collapsed) .map-search-toggle-btn { display: none; }
.map-search-inner { display: flex; align-items: center; gap: 6px; }
.map-search-inner input {
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 4px 8px;
    min-width: 200px;
    font-size: 14px;
}
.map-search-inner button {
    border: 1px solid #ced4da;
    background: #ffffff;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   Botón de descarga
   -------------------------------------------------------------------------- */
.map-download-control { background: #fff; border-radius: 6px; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25); }
.map-download-control button { border: 0; background: transparent; padding: 8px 10px; cursor: pointer; }

/* --------------------------------------------------------------------------
   Modal de publicación
   -------------------------------------------------------------------------- */
.pub-options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 14px;
}
.pub-option-row-wide {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    padding-bottom: 6px;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(0,0,0,.06);
}
@media (max-width: 480px) {
    .pub-options-grid { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   Modal de proyecto (hojas asociadas)
   -------------------------------------------------------------------------- */
.pe-hoja-card { border-color: #dee2e6; }
.pe-hoja-card .card-body { background: #f8f9fa; }
.pe-hoja-card .form-text { font-size: 0.72rem; line-height: 1.2; }
.pe-sheet-chevron { transition: transform 0.2s; font-size: 0.7rem; }
.pe-cat-colors-list { max-height: 180px; overflow-y: auto; padding: 2px 0; }
.pe-cat-color-row { padding: 2px 4px; border-radius: 4px; }
.pe-cat-color-row:hover { background: #e9ecef; }

/* --------------------------------------------------------------------------
   Galería (home)
   -------------------------------------------------------------------------- */
.gallery-hero {
    text-align: center;
    padding: 2.2rem 1rem 1.4rem;
    color: #fff;
}
.gallery-hero h1 {
    font-weight: 800;
    font-size: 1.7rem;
    background: linear-gradient(135deg, #6366f1, #a78bfa, #38bdf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.gallery-hero p { color: rgba(255,255,255,0.45); font-size: .88rem; margin: 0; }

.map-card {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 14px;
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: transform .15s, border-color .2s, background .2s;
}
.map-card:hover {
    transform: translateY(-3px);
    border-color: rgba(99,102,241,0.45);
    background: rgba(99,102,241,0.07);
}

.map-card-thumb {
    display: block;
    position: relative;
    aspect-ratio: 16 / 9;
    background: rgba(0,0,0,0.25);
}
.map-card-thumb svg { width: 100%; height: 100%; display: block; }
.map-card-thumb-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.4);
}

.map-card-body { padding: .85rem 1rem 1rem; display: flex; flex-direction: column; gap: .45rem; flex: 1; }
.map-card-title { font-weight: 700; font-size: .95rem; color: #e2e8f0; line-height: 1.25; }
.map-card-meta {
    display: flex;
    align-items: center;
    gap: .9rem;
    font-size: .72rem;
    color: rgba(255,255,255,0.4);
}
.badge-public {
    background: rgba(34,197,94,0.18);
    color: #4ade80;
    font-size: .66rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    white-space: nowrap;
}
.badge-private {
    background: rgba(148,163,184,0.15);
    color: #94a3b8;
    font-size: .66rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    white-space: nowrap;
}

.map-card-url {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: .74rem;
    color: rgba(255,255,255,0.55);
    background: rgba(0,0,0,0.25);
    border-radius: 6px;
    padding: 3px 8px;
}
.map-card-url-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.btn-copy-url {
    border: 0;
    background: transparent;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    padding: 0 2px;
    font-size: .8rem;
}
.btn-copy-url:hover { color: #fff; }

.map-card-actions {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-top: auto;
    padding-top: .35rem;
}
.map-card-actions .btn { font-size: .72rem; padding: .2rem .55rem; }
.map-card-actions .form-check-input { cursor: pointer; }

.map-card-new {
    border-style: dashed;
    border-color: rgba(255,255,255,0.18);
    background: transparent;
    cursor: pointer;
    min-height: 220px;
    align-items: center;
    justify-content: center;
}
.map-card-new:hover { border-color: var(--app-accent); background: rgba(99,102,241,0.06); }
.map-card-new-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    color: rgba(255,255,255,0.45);
    font-weight: 600;
}
.map-card-new-inner i { font-size: 2rem; }
.map-card-new:hover .map-card-new-inner { color: var(--app-accent); }

/* --------------------------------------------------------------------------
   Responsive (móvil)
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .layer-panel,
    .marker-drawer {
        left: 8px;
        right: 8px;
        width: auto;
        top: auto;
        bottom: 8px;
        max-height: 62vh;
    }
    .layer-panel-toggle { left: 54px; }
    .marker-list-toggle { right: 8px; }
    #project-selector-container {
        bottom: auto;
        top: 56px;
        left: 8px;
        max-width: 230px;
        padding: 8px;
    }
    .map-search-inner input { min-width: 130px; }
}
