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

html, body {
    height: 100%;
    /* Evita el "rebote" (rubber-band) de iOS al hacer scroll, que puede dejar
       ver un hueco en blanco por debajo del contenido en la PWA instalada. */
    overscroll-behavior: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: 100dvh;
}

/* Capa de fondo fija a pantalla completa, detrás de todo (z-index negativo).
   En el iPhone probado, innerHeight/100dvh se quedan un poco cortos respecto
   al marco real (position:fixed sí se ancla bien al borde real, como se ve en
   la barra de depuración) — así que en vez de perseguir el pixel exacto, este
   fondo fijo cubre siempre el marco real completo y no puede dejar hueco en
   blanco por más que el contenido en flujo normal se quede corto. */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.icon {
    width: 1em;
    height: 1em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.125em;
    flex-shrink: 0;
}

.icon-filled {
    fill: currentColor;
    stroke: none;
}

.btn {
    background: linear-gradient(45deg, #3498db, #2980b9);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
}

.btn-success {
    background: linear-gradient(45deg, #27ae60, #229954);
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
}

.btn-neutral {
    background: linear-gradient(45deg, #8e9aab, #5f6c7d);
    box-shadow: 0 4px 15px rgba(95, 108, 125, 0.3);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
}

/* El mapa ocupa toda la pantalla; no hay cabecera ni tarjeta contenedora. */
#map {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: var(--app-height, 100dvh);
}

/* Botones flotantes redondos sobre el mapa (estilo Google/Apple Maps). Cada
   uno vive en su propia esquina para no chocar entre sí ni con los controles
   de zoom de Leaflet (que se mueven a abajo-izquierda, ver js/app.js). */
.map-fab {
    position: fixed;
    z-index: 700;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    color: #2c3e50;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.map-fab .icon {
    width: 22px;
    height: 22px;
}

.map-fab:active {
    transform: scale(0.92);
}

.map-fab-primary {
    width: 60px;
    height: 60px;
    background: linear-gradient(45deg, #3498db, #2980b9);
    color: white;
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.5);
}

.map-fab-primary .icon {
    width: 26px;
    height: 26px;
}

.map-fab-active {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    color: white;
}

.fab-top-left {
    top: max(16px, calc(env(safe-area-inset-top) + 10px));
    left: max(16px, calc(env(safe-area-inset-left) + 10px));
}

.fab-top-right {
    top: max(16px, calc(env(safe-area-inset-top) + 10px));
    right: max(16px, calc(env(safe-area-inset-right) + 10px));
}

.fab-bottom-right {
    bottom: max(20px, calc(env(safe-area-inset-bottom) + 14px));
    right: max(16px, calc(env(safe-area-inset-right) + 10px));
}

.fab-bottom-right-2 {
    bottom: max(84px, calc(env(safe-area-inset-bottom) + 78px));
    right: max(16px, calc(env(safe-area-inset-right) + 10px));
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    margin: 5% auto;
    padding: 18px;
    border-radius: 18px;
    width: 90%;
    max-width: 440px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal h2 {
    color: #2c3e50;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    color: #34495e;
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 9px 12px;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.8);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.coords-input {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 14px;
    flex-wrap: wrap;
}

.close-btn {
    background: #95a5a6;
    box-shadow: 0 4px 15px rgba(149, 165, 166, 0.3);
}

.sidebar {
    position: fixed;
    right: -320px;
    top: 0;
    width: 320px;
    height: 100vh;
    height: 100dvh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.1);
    transition: right 0.3s ease;
    z-index: 950;
    overflow-y: auto;
}

.sidebar.active {
    right: 0;
}

.sidebar-header {
    position: relative;
    padding: 20px;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-right: 50px;
    border-bottom: 1px solid #ecf0f1;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

.sidebar-close-btn {
    position: absolute;
    top: max(15px, env(safe-area-inset-top));
    right: 15px;
}

.sidebar-content {
    padding: 20px;
}

.data-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.mark-item {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #ecf0f1;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.mark-item:hover {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.mark-item.favorite {
    border-left: 4px solid #e74c3c;
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.05), rgba(255, 255, 255, 0.8));
}

.mark-title {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mark-type {
    background: #3498db;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
}

.mark-coords {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin: 5px 0;
}

.mark-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.btn-small {
    padding: 5px 10px;
    font-size: 0.8rem;
    border-radius: 15px;
}

.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.filter-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.filter-controls select,
.filter-controls input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
}

/* Posición del usuario en el mapa */
.user-location-dot {
    width: 18px;
    height: 18px;
    background: #3498db;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.5), 0 2px 8px rgba(0,0,0,0.3);
}

/* Panel de descarga de tiles offline */
.offline-download-panel {
    position: fixed;
    left: 50%;
    bottom: max(20px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 900;
    background: rgba(255, 255, 255, 0.97);
    border-radius: 14px;
    padding: 14px 18px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.25);
    width: min(90%, 360px);
    text-align: center;
}

.offline-download-panel .progress-bar {
    width: 100%;
    height: 10px;
    background: #ecf0f1;
    border-radius: 6px;
    overflow: hidden;
    margin: 10px 0;
}

.offline-download-panel .progress-bar-fill {
    height: 100%;
    background: linear-gradient(45deg, #3498db, #2980b9);
    width: 0%;
    transition: width 0.2s ease;
}

/* HUD de navegación GPS */
.nav-hud {
    position: fixed;
    top: max(15px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    background: rgba(255, 255, 255, 0.97);
    border-radius: 16px;
    padding: 14px 20px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: 90%;
}

.nav-hud .nav-compass {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2c3e50, #1a252f);
    position: relative;
    flex-shrink: 0;
}

.nav-hud .nav-arrow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 22px solid #e74c3c;
    transform-origin: 50% 70%;
    transform: translate(-50%, -70%) rotate(0deg);
    transition: transform 0.15s linear;
}

.nav-hud .nav-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-hud .nav-target {
    font-weight: 600;
    color: #2c3e50;
}

.nav-hud .nav-distance {
    font-size: 1.3rem;
    font-weight: 700;
    color: #2980b9;
}

.nav-hud .nav-bearing {
    font-size: 0.8rem;
    color: #7f8c8d;
}

.nav-hud .nav-exit {
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Lat/Lng se mantienen en la misma fila también en móvil: apiladas hacían
       el modal de nueva marca demasiado largo. */
    .coords-input {
        gap: 8px;
    }

    .sidebar {
        width: 100vw;
        right: -100vw;
    }

    .modal-content {
        margin: 8% auto;
        width: 92%;
        padding: 16px;
    }

    .nav-hud {
        flex-wrap: wrap;
        justify-content: center;
    }

    .map-fab {
        width: 46px;
        height: 46px;
    }

    .map-fab-primary {
        width: 56px;
        height: 56px;
    }
}


/* Pantalla de acceso (login/registro) */
.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.auth-card {
    background: rgba(255, 255, 255, 0.97);
    border-radius: 20px;
    padding: 30px 25px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.auth-card h1 {
    color: #2c3e50;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.auth-card h2 {
    color: #34495e;
    font-size: 1.1rem;
    margin-bottom: 15px;
}

.auth-card form {
    text-align: left;
}

.auth-error {
    color: #e74c3c;
    font-size: 0.85rem;
    min-height: 1.2em;
    margin-bottom: 10px;
}

.auth-toggle {
    margin-top: 18px;
    font-size: 0.9rem;
    color: #7f8c8d;
}

.auth-toggle a {
    color: #3498db;
    font-weight: 600;
    text-decoration: none;
}

/* Fila de usuario/logout y estado de sincronización en la sidebar */
.sidebar-user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
}

.sync-status {
    margin-top: 6px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.85);
}

.btn-icon-only {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sección "Compartido conmigo" */
.shared-with-me-section {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #ecf0f1;
}

.shared-with-me-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.shared-with-me-header h4 {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #2c3e50;
    font-size: 1rem;
}

.shared-with-me-header .btn-icon-only {
    background: #ecf0f1;
    color: #7f8c8d;
}

.share-suggestions {
    margin-top: 6px;
}

.share-suggestion {
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #2c3e50;
}

.share-suggestion:hover {
    background: #ecf0f1;
}

/* Custom Leaflet Popup Styles */
.custom-popup {
    font-family: inherit;
}

.custom-popup h3 {
    color: #2c3e50;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-popup .popup-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

/* Sección "Capturas" (histórico + gastos) */
.catches-section {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #ecf0f1;
}

.catches-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.catches-header h4,
.catches-subheader {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #2c3e50;
    font-size: 1rem;
}

.catches-subheader {
    margin-top: 18px;
    margin-bottom: 10px;
    padding-top: 12px;
    border-top: 1px dashed #ecf0f1;
}

.catches-header-actions {
    display: flex;
    gap: 8px;
}

.catches-header-actions .btn-icon-only {
    background: #ecf0f1;
    color: #7f8c8d;
}

.stats-card {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.08), rgba(142, 68, 173, 0.08));
    border: 1px solid #ecf0f1;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 15px;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: #34495e;
    padding: 3px 0;
}

.stats-row-total {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    font-weight: 600;
}

.catch-item {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #ecf0f1;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 12px;
}
