:root {
    --bg-main: #061017;
    --bg-panel: rgba(7, 18, 33, 0.88);
    --bg-card: rgba(12, 28, 46, 0.78);
    --border: rgba(31, 91, 40, 0.18);
    --text-main: #e8f5ff;
    --text-muted: #94aac0;
    --primary: #1f5e32;
    --primary-hover: #86d94f;
    --success: #8eeea6;
    --danger: #f97373;
    --accent-light: #c0f9a2;
    --shadow: 0 24px 70px rgba(2, 12, 26, 0.35);
    /* Cambia esto por una imagen local si querés un splash personalizado */
    --welcome-bg-image: url("../assets/Gemini_Generated_Image_rz44r6rz44r6rz44.png");
}

html {
    font-size: 17px;
}

body {
    margin: 0;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 1rem;
    line-height: 1.45;
    background: radial-gradient(circle at top left, rgba(56, 176, 232, 0.18) 0%, transparent 28%),
                radial-gradient(circle at 80% 10%, rgba(69, 179, 235, 0.12) 0%, transparent 25%),
                linear-gradient(180deg, #061017 0%, #08181f 35%, #02070c 100%);
    color: var(--text-main);
    overflow: hidden;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background-color: rgba(5, 14, 24, 0.90);
    padding: 16px 26px;
    text-align: center;
    border-bottom: 1px solid rgba(57, 167, 224, 0.15);
    backdrop-filter: blur(18px);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
    z-index: 1000;
}

header h1 {
    margin: 0;
    font-size: 1.45rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 700;
}

main {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    gap: 18px;
    padding: 18px;
}

#map-container {
    display: flex;
    flex: 3;
    min-height: 0;
    position: relative;
    border-radius: 26px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid rgba(31, 91, 40, 0.12);
}

#map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#sidebar {
    flex: 1;
    min-width: 320px;
    background-color: var(--bg-panel);
    padding: 24px;
    border-radius: 28px;
    border: 1px solid rgba(31, 91, 40, 0.12);
    overflow-y: auto;
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow);
    font-size: 1rem;
}

#welcome-screen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background-image: var(--welcome-bg-image), radial-gradient(circle at top left, rgba(79, 153, 90, 0.20), transparent 50%), linear-gradient(180deg, rgba(4, 9, 19, 0.88), rgba(4, 9, 19, 0.98));
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    overflow: hidden;
}

#welcome-screen::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(4, 9, 19, 0.40), rgba(4, 9, 19, 0.90));
    pointer-events: none;
}

.welcome-card {
    position: relative;
    width: min(620px, 100%);
    padding: 34px 30px;
    background: rgba(4, 12, 24, 0.72);
    border: 1px solid rgba(31, 91, 40, 0.14);
    border-radius: 28px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.30);
    backdrop-filter: blur(18px);
    text-align: center;
}

.welcome-card p {
    margin: 20px 0 30px;
    color: rgba(232, 245, 255, 0.82);
    line-height: 1.7;
    font-size: 1.08rem;
    text-align: center;
}

.welcome-card button {
    width: auto;
    padding: 16px 30px;
    font-size: 1.04rem;
    letter-spacing: 0.04em;
    background: linear-gradient(135deg, #a5f62f, #6ac91f);
    color: #07120f;
    border-radius: 999px;
    box-shadow: 0 20px 40px rgba(106, 201, 31, 0.25);
    display: block;
    margin: 0 auto;
}

#panel-satelital { min-width: 0; }
#panel-satelital .satellite-hint { font-size: 0.85rem !important; color: var(--text-muted); }
#btn-subir-kmz { background: #6d28d9; }
#estado-kmz { font-size: 0.85rem; white-space: pre-line; overflow-wrap: anywhere; margin: 8px 0; }
#estado-kmz.satellite-error { color: #fca5a5; }
#lista-capas-satelitales { list-style: none; padding: 0; margin: 0; }
.satellite-layer, #detalle-satelital { margin: 12px 0; padding: 12px; background: var(--bg-card); border: 1px solid #6b4a96; border-radius: 10px; }
.satellite-layer-title { display: flex; gap: 8px; align-items: flex-start; overflow-wrap: anywhere; }
.satellite-layer-title input { width: auto; margin-top: 5px; flex: 0 0 auto; }
.satellite-layer > small { display: block; margin: 6px 0; }
.satellite-actions, .satellite-photo-row { display: flex; gap: 6px; align-items: center; margin: 8px 0; }
#panel-satelital button { padding: 8px 10px; font-size: 0.82rem; margin: 0; min-width: 0; overflow-wrap: anywhere; }
.satellite-actions button { flex: 1; }
#panel-satelital select, #panel-satelital textarea { box-sizing: border-box; width: 100%; min-width: 0; padding: 8px; color: var(--text-main); background: #142335; border: 1px solid #667085; border-radius: 6px; margin-top: 6px; font: inherit; }
#panel-satelital label { font-size: 0.85rem; }
.satellite-opacity { display: block; margin: 8px 0; }
.satellite-opacity input { width: 100%; accent-color: #c084fc; }
#detalle-satelital > label { display: block; margin: 12px 0; }
#detalle-satelital h4 { overflow-wrap: anywhere; }
.satellite-description { white-space: pre-wrap; max-height: 160px; overflow: auto; overflow-wrap: anywhere; }
#detalle-satelital dl { font-size: 0.8rem; max-height: 180px; overflow: auto; overflow-wrap: anywhere; }
#detalle-satelital dt { font-weight: bold; color: #d8b4fe; }
#detalle-satelital dd { margin: 0 0 6px; }
.satellite-photo-row > :first-child { flex: 1; }
.satellite-photo-row > :last-child { width: auto; flex: 0 0 auto; }
.satellite-layer details { font-size: 0.8rem; margin-top: 10px; overflow-wrap: anywhere; }
.satellite-layer details ul { padding-left: 16px; max-height: 180px; overflow: auto; }
#panel-satelital button:disabled { opacity: 0.55; cursor: not-allowed; }

.welcome-card button:disabled {
    opacity: 0.55;
    cursor: wait;
}

#auth-notice {
    font-size: 0.9rem;
    margin: 12px 0;
}

#btn-auth-retry {
    margin-top: 12px;
}

.account-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 8px;
    font-size: 0.85rem;
}

.account-controls button:where(:not([class*="cl-"])) {
    width: auto;
    padding: 6px 12px;
}

#welcome-screen.hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.45s ease;
}

#welcome-screen.hidden .welcome-card {
    transform: scale(0.98);
}

#sidebar h2 {
    margin-top: 0;
    margin-bottom: 14px;
    font-size: 1.22rem;
}

#sidebar h3, #sidebar h4 {
    margin: 8px 0 10px 0;
    font-size: 1.08rem;
}

#sidebar p {
    font-size: 1rem !important;
    line-height: 1.5;
}

button:where(:not([class*="cl-"])) {
    width: 100%;
    padding: 12px 14px;
    background: linear-gradient(135deg, rgba(27, 84, 42, 0.95), rgba(38, 118, 52, 0.95));
    color: var(--text-main);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    margin-bottom: 10px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    box-shadow: 0 16px 40px rgba(3, 11, 19, 0.22);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

button:where(:not([class*="cl-"])):focus-visible {
    outline: 2px solid rgba(110, 227, 98, 0.55);
    outline-offset: 3px;
}

button:where(:not([class*="cl-"])):hover {
    transform: translateY(-1px);
    background: linear-gradient(135deg, rgba(110, 227, 98, 0.98), rgba(86, 214, 80, 0.98));
}

button.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 16px;
    padding: 12px 14px;
    font-size: 1rem !important;
}

.tool-btn-tool {
    background: rgba(36, 92, 44, 0.95) !important;
}

.tool-btn-warn {
    background: rgba(233, 140, 44, 0.92) !important;
}

.tool-btn-danger {
    background: rgba(219, 62, 62, 0.92) !important;
}

#btn-borrar-todo {
    background: #dc2626 !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 156, 143, 0.28);
    box-shadow: 0 14px 30px rgba(220, 38, 38, 0.24);
    font-size: 1rem !important;
}

#btn-borrar-todo:hover {
    background: #ef4444 !important;
    box-shadow: 0 16px 34px rgba(220, 38, 38, 0.32);
}

#btn-borrar-todo:focus-visible {
    outline: 2px solid rgba(249, 115, 115, 0.65);
}

.tool-btn.is-active {
    background: linear-gradient(135deg, #8eeea6, #6ac91f) !important;
    color: #081014 !important;
    box-shadow: 0 0 0 2px rgba(134, 217, 79, 0.25), 0 10px 22px rgba(0, 0, 0, 0.22);
}

.tool-btn.is-active::after {
    content: "";
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: #86d94f;
    box-shadow: 0 0 0 2px rgba(134, 217, 79, 0.22);
}

#lista-puntos, #lista-medidas, #lista-poligonos, #lista-poligonos-manuales, #lista-poligonos-automaticos, #lista-fotos, #lista-objetivos {
    max-height: 220px;
    overflow-y: auto;
    background: rgba(17, 31, 45, 0.72);
    padding: 12px;
    border-radius: 18px;
    font-size: 1rem !important;
    list-style: none;
    margin: 10px 0;
    border: 1px solid rgba(41, 108, 57, 0.18);
}

#lista-puntos li,
#lista-medidas li,
#lista-poligonos li,
#lista-poligonos-manuales li,
#lista-poligonos-automaticos li,
#lista-fotos li,
#lista-objetivos li {
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease;
}

#lista-puntos li:hover,
#lista-medidas li:hover,
#lista-poligonos li:hover,
#lista-poligonos-manuales li:hover,
#lista-poligonos-automaticos li:hover,
#lista-fotos li:hover,
#lista-objetivos li:hover {
    background: rgba(115, 186, 99, 0.12);
    border-color: rgba(115, 186, 99, 0.22);
}

input[type="number"],
input[type="text"] {
    font: inherit;
    font-size: 1rem;
}

#btn-mobile-controles {
    display: none;
}

#install-toast {
    position: fixed;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%) translateY(20px);
    opacity: 0;
    pointer-events: none;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-radius: 18px;
    border: 1px solid rgba(31, 91, 40, 0.18);
    background: rgba(10, 21, 36, 0.95);
    backdrop-filter: blur(20px);
    color: var(--text-main);
    z-index: 1500;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#install-toast.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

#btn-install-toast {
    width: auto;
    margin: 0;
    padding: 8px 12px;
    font-size: 0.96rem;
    background: rgba(86, 214, 80, 0.95);
    border-radius: 12px;
}

#install-toast.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

#btn-install-toast {
    width: auto;
    margin: 0;
    padding: 6px 10px;
    font-size: 0.96rem;
}

.gv-compass {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(10, 36, 28, 0.92);
    border: 1px solid rgba(180, 239, 206, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #d9ffe9;
    font-weight: 700;
    font-size: 0.88rem;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

#lista-puntos li:hover,
#lista-medidas li:hover,
#lista-poligonos li:hover,
#lista-poligonos-manuales li:hover,
#lista-poligonos-automaticos li:hover,
#lista-fotos li:hover {
    background: rgba(59, 130, 246, 0.12);
    border-radius: 6px;
}

/* --- ETIQUETAS DE MEDICIÓN (LÍNEAS) --- */
.etiqueta-medicion {
    background: rgba(0, 0, 0, 0.8) !important;
    color: #3498db !important; /* Azul para líneas */
    border: 1px solid #3498db !important;
    font-weight: bold !important;
    border-radius: 4px !important;
    padding: 2px 5px !important;
    white-space: nowrap;
}

/* --- ETIQUETA DE ÁREA (EL SELLO VERDE) --- */
.etiqueta-area {
    background: rgba(0, 0, 0, 0.85) !important;
    color: #2ecc71 !important; /* Verde para polígonos */
    border: 1px solid #2ecc71 !important;
    font-weight: bold !important;
    border-radius: 4px !important;
    padding: 5px 8px !important;
    font-size: 12px !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5) !important;
    text-align: center !important;
    white-space: nowrap;
}

.btn-borrar-medida {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 1.2em;
    padding: 0 5px;
    transition: transform 0.2s;
}
.btn-borrar-medida:hover {
    background-color: #475569;
    transform: scale(1.2);
    color: #ff5e4d;
}

/* --- VÉRTICES ARRASTRABLES --- */
.vertice-poligono {
    background: white !important;
    border: 2px solid #27ae60 !important;
    border-radius: 50% !important;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

.vertice-poligono-medio {
    background: #bbf7d0 !important;
    border-color: #16a34a !important;
}

.vertice-linea {
    background: white !important;
    border: 2px solid #3498db !important;
    border-radius: 50% !important;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

/* Clase de ayuda para el icono de los puntos manuales */
.custom-div-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}
/* ===========================================
   Optimizaciones para Celulares (Responsive)
   =========================================== */

@media (max-width: 768px) {
    #app-container {
        height: 100dvh;
    }

    main {
        position: relative;
    }

    #map-container {
        flex: 1 1 auto;
        width: 100%;
        height: 100%;
    }

    #sidebar {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 900;
        height: min(86dvh, 86vh);
        overflow-y: auto;
        padding: 15px 15px calc(18px + env(safe-area-inset-bottom)) 15px;
        background: rgba(12, 33, 26, 0.9);
        backdrop-filter: blur(6px);
        border-left: none;
        border-top: 1px solid var(--border);
        border-top-left-radius: 14px;
        border-top-right-radius: 14px;
        box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.4);
        transform: translateY(105%);
        transition: transform 0.24s ease;
    }

    #sidebar.mobile-open {
        transform: translateY(0%);
        scroll-padding-bottom: 100px;
    }

    #panel-satelital button {
        font-size: 0.85rem !important;
        line-height: 1.35;
        min-height: 40px;
        padding: 8px !important;
    }

    #btn-mobile-controles {
        display: block;
        position: absolute;
        left: 50%;
        bottom: calc(12px + env(safe-area-inset-bottom));
        transform: translateX(-50%);
        z-index: 950;
        width: auto;
        min-width: 140px;
        margin: 0;
        padding: 10px 16px !important;
        border-radius: 999px;
        background: rgba(169, 67, 72, 0.92);
        color: #ffffff;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(210, 125, 130, 0.25);
        transition: background 0.2s ease, border-color 0.2s ease;
    }

    #btn-mobile-controles:hover {
        background: rgba(216, 97, 99, 0.92);
    }

    #btn-mobile-controles.activo {
        background: rgba(203, 80, 84, 0.98);
        border-color: rgba(234, 110, 113, 0.35);
    }

    #btn-mobile-controles.activo:hover {
        background: rgba(228, 105, 109, 0.95);
    }

    /* Agrandamos botones para que sean fáciles de tocar con el dedo */
    button:where(:not([class*="cl-"])) {
        padding: 15px !important;
        font-size: 1.12rem !important;
        margin-bottom: 10px;
    }

    #lista-fotos button {
        width: auto !important;
        padding: 8px 10px !important;
        margin-bottom: 0 !important;
        font-size: 0.96rem !important;
    }

    #btn-install-toast {
        width: auto !important;
        padding: 6px 10px !important;
        margin-bottom: 0 !important;
        font-size: 0.96rem !important;
    }

    /* Ajustamos entradas de texto y números */
    input[type="number"], input[type="text"] {
        padding: 12px;
        font-size: 1.05rem;
    }

    /* Ocultamos scrollbars feos en el panel en móviles */
    #sidebar::-webkit-scrollbar {
        width: 0px;
        background: transparent;
    }
}

/* Estilo para las etiquetas de los puntos */
.etiqueta-punto {
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-main);
    border: 1px solid #27ae60;
    font-weight: bold;
    font-size: 0.86rem;
    border-radius: 4px;
    padding: 2px 5px;
}
/* Efecto para los botones al pasar el mouse */
button:where(:not([class*="cl-"])):hover {
    filter: brightness(1.2); /* Aumenta un poco el brillo del color original */
    transform: translateY(-2px); /* El botón sube 2 píxeles (da sensación de clic) */
    box-shadow: 0 4px 8px rgba(0,0,0,0.3); /* Agrega una sombrita para dar profundidad */
    cursor: pointer; /* Asegura que el puntero cambie a la manito */
}

/* Para que el cambio de color sea suave y no de golpe */
button:where(:not([class*="cl-"])) {
    transition: all 0.3s ease; /* Hace que el efecto dure 0.3 segundos */
}
/* Hacer que el globo del Pop-up sea oscuro como el panel */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
    background: rgba(16, 43, 34, 0.9) !important;
    color: white !important;
    border: 1px solid rgba(181, 244, 211, 0.35);
    box-shadow: 0 3px 14px rgba(0,0,0,0.4);
    backdrop-filter: blur(10px);
}

/* Ajustar el botón de cerrar del pop-up */
.leaflet-popup-close-button {
    color: #fff !important;
    padding: 8px !important;
}

.leaflet-popup-content {
    margin: 15px;
    line-height: 1.4;
    font-size: 0.96rem;
}
.popup-drone-grande .leaflet-popup-content {
    width: 350px !important; 
    margin: 15px !important;
}

/* Quick win: paneles principales con estilo unificado */
#panel-medicion-total,
#panel-puntos,
#panel-mira {
    background: var(--bg-card) !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    font-size: 1rem !important;
}

#info-coords,
#estado-importacion,
#telemetria-drone,
#info-clima,
#resultado-mira {
    border-radius: 8px;
    font-size: 1rem !important;
    line-height: 1.45;
}

#sidebar hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 14px 0;
}

#sidebar small {
    color: var(--text-muted);
    font-size: 0.92rem !important;
}

/* Estilos modernos para selectores */
#tamano-baldosa-auto, #modo-poligono-auto {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    background: rgba(17, 31, 45, 0.78);
    border: 1px solid rgba(41, 108, 57, 0.18);
    border-radius: 16px;
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 600;
    backdrop-filter: blur(8px);
    box-shadow: 0 8px 24px rgba(3, 11, 19, 0.15);
    transition: all 0.2s ease;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 40px;
}

#tamano-baldosa-auto:hover, #modo-poligono-auto:hover {
    border-color: rgba(115, 186, 99, 0.35);
    background: rgba(26, 51, 34, 0.92);
    transform: translateY(-1px);
    box-shadow: 0 12px 32px rgba(3, 11, 19, 0.22);
}

#tamano-baldosa-auto:focus, #modo-poligono-auto:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(134, 217, 79, 0.15);
}

#tamano-baldosa-auto option, #modo-poligono-auto option {
    background: rgba(12, 28, 46, 0.95);
    color: var(--text-main);
    padding: 8px;
}

