/* ==========================================================================
   Modal «Bitácora Ciudadana de Avistamientos» (notas): escritorio y móvil.
   Escritorio: tarjeta de dos columnas (evidencia a la izquierda, campos a la derecha).
   Móvil (≤ 768 px): hoja a pantalla completa, UNA columna, cabecera y botones fijos, campos de 16 px.
   ========================================================================== */

/* Nota: en escritorio los campos conservan su caja original (content-box), igual que antes del rediseño móvil. */

/* ---------- Estructura ---------- */
.cm-grid { display: block; }
.cm-grid--dos { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.cm-grid > *, .cm-campos > *, .cm-fila > *, .cm-evidencia > * { min-width: 0; }

/* Escritorio: los bloques van apilados sin separación extra (así se veía; Alpine quitaba el display:flex en línea) */
.cm-evidencia { display: block; }
.cm-campos { display: flex; flex-direction: column; gap: 12px; }
.cm-campo { display: flex; flex-direction: column; gap: 3px; }
.cm-ubicacion { display: flex; flex-direction: column; gap: 4px; }
.cm-fila { display: flex; gap: 10px; }
.cm-fila > .cm-campo { flex: 1; }

/* ---------- Etiquetas y notas ---------- */
.cm-label { display: block; font-size: 11px; font-weight: 600; color: #cbd5e1; margin-bottom: 4px; }
.cm-campo .cm-label, .cm-ubicacion .cm-label { margin-bottom: 0; }
.cm-nota { display: block; margin-top: 2px; font-size: 9.5px; color: #777; }
.cm-campo .cm-nota { margin-top: 0; color: #6b7280; }
.cm-sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- Campos ---------- */
.cm-input {
    width: 100%;
    background: #111111;
    border: 1px solid #333333;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12px;
    color: #ffffff;
    outline: none;
}
.cm-input:focus { border-color: #2e7d32; }
.cm-input--chico { background: #111; border-radius: 6px; font-size: 11px; padding: 6px 10px; }
.cm-input--referencia { margin-top: 4px; }
.cm-input--area { resize: none; }

.cm-buscar-lugar { display: flex; gap: 6px; margin-bottom: 4px; }
.cm-buscar-lugar .cm-input { flex: 1; width: auto; }
.cm-btn-buscar { background: #2e7d32; color: #ffffff; border: none; padding: 0 10px; border-radius: 6px; cursor: pointer; font-size: 11px; }

.cm-mapa { width: 100%; height: 190px; border-radius: 8px; border: 1px solid #333; }

/* ---------- Evidencia ---------- */
.cm-bloque { min-width: 0; }
.cm-foto {
    width: 100%;
    height: 130px;
    background: #111111;
    border: 2px dashed #333333;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    margin-bottom: 6px;
}
.cm-foto img { width: 100%; height: 100%; object-fit: cover; }
.cm-foto__vacio { text-align: center; color: #4b5563; font-size: 20px; }
.cm-btn-archivo {
    display: block;
    width: 100%;
    text-align: center;
    background: #222222;
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    padding: 7px;
    border-radius: 6px;
    border: 1px solid #333333;
    cursor: pointer;
}
.cm-archivo {
    width: 100%;
    background: #111;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 6px;
    font-size: 11px;
    color: #aaa;
}

/* ---------- Botones de acción ---------- */
.cm-acciones { display: flex; gap: 10px; margin-top: 6px; }
.cm-btn { flex: 1; font-weight: 600; font-size: 12px; padding: 9px; border-radius: 8px; border: none; cursor: pointer; }
.cm-btn--enviar { background: #059669; color: #ffffff; }
.cm-btn--cancelar { background: #222222; color: #d1d5db; }

/* La X de la cabecera solo existe en móvil */
.cm-cab .cm-cerrar-cab { display: none; }

.cm-cerrar:focus-visible, .cm-cerrar-cab:focus-visible, .cm-btn:focus-visible, .cm-btn-buscar:focus-visible, .cm-btn-archivo:focus-within { outline: 2px solid #4ade80; outline-offset: 2px; }
.cm-sheet:focus { outline: none; }

/* ==========================================================================
   MÓVIL (≤ 768 px): hoja a pantalla completa
   ========================================================================== */
@media (max-width: 768px), (max-height: 520px) and (pointer: coarse) {
    html.cm-abierto, body.cm-abierto { overflow: hidden; }

    /* En escritorio estos elementos conservan su medida original; en móvil todo mide el 100% disponible */
    .cm-input, .cm-mapa, .cm-foto, .cm-btn-archivo, .cm-archivo, .cm-btn, .cm-btn-buscar { box-sizing: border-box; }

    /* El fondo ocupa la parte visible de la pantalla (se ajusta cuando sale el teclado: ver notas_script.js) */
    .comunidad-modal-backdrop.cm-backdrop {
        position: fixed;
        left: 0;
        top: var(--cm-top, 0);
        height: 100vh;
        height: var(--cm-vh, 100dvh);
        width: 100%;
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
        background: #161616;
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    .comunidad-modal-container.cm-sheet {
        box-sizing: border-box;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        padding: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scroll-padding-top: 110px;
        scroll-padding-bottom: 120px;
    }

    /* La X grande de escritorio se oculta en el formulario (hay otra fija en la cabecera) */
    .cm-sheet:not(.is-result) > .cm-cerrar { display: none; }
    .cm-cab .cm-cerrar-cab {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: calc(8px + env(safe-area-inset-top, 0px));
        right: calc(8px + env(safe-area-inset-right, 0px));
        width: 44px;
        height: 44px;
        border: 0;
        border-radius: 50%;
        background-color: #fee2e2;
        color: #dc2626;
        font-size: 26px;
        line-height: 1;
        cursor: pointer;
    }
    .cm-cab .cm-cerrar-cab:active { background-color: #dc2626; color: #ffffff; }

    /* Cabecera fija */
    .cm-cab {
        position: sticky;
        top: 0;
        z-index: 20;
        margin: 0;
        padding: calc(14px + env(safe-area-inset-top, 0px)) 64px 12px calc(16px + env(safe-area-inset-left, 0px));
        background: #161616;
        border-bottom: 1px solid #262626;
    }
    .cm-cab h3 { margin: 0 0 4px; font-size: 18px; line-height: 1.25; }
    /* Sin texto justificado ni guiones */
    .cm-sheet .cm-intro, .cm-sheet p, .cm-sheet label, .cm-sheet .cm-nota {
        text-align: left;
        -webkit-hyphens: none;
        hyphens: none;
        overflow-wrap: break-word;
    }
    .cm-sheet .cm-intro { margin: 0; font-size: 14px; line-height: 1.45; color: #9ca3af; }

    /* Los controles del mapa no deben quedar por encima de los botones fijos */
    .cm-sheet .mini-mapa { position: relative; z-index: 0; isolation: isolate; }

    /* UNA columna: los campos primero y la evidencia después de la descripción */
    .cm-form { padding: 16px calc(16px + env(safe-area-inset-right, 0px)) 0 calc(16px + env(safe-area-inset-left, 0px)); }
    .cm-grid, .cm-grid--dos { display: flex; flex-direction: column; align-items: stretch; gap: 18px; max-width: 720px; margin: 0 auto; }
    .cm-campos { display: contents; }
    .cm-o1 { order: 1; } .cm-o2 { order: 2; } .cm-o3 { order: 3; } .cm-o4 { order: 4; } .cm-o5 { order: 5; }
    .cm-evidencia { order: 6; display: flex; flex-direction: column; gap: 18px; }
    .cm-o9 { order: 9; }

    .cm-campo { gap: 6px; }
    .cm-ubicacion { gap: 8px; }
    .cm-fila { flex-direction: column; gap: 18px; }

    .cm-label { font-size: 13px; margin-bottom: 6px; }
    .cm-campo .cm-label, .cm-ubicacion .cm-label { margin-bottom: 0; }
    .cm-nota { font-size: 12px; line-height: 1.4; }

    /* Campos de 16 px (iOS no hace zoom al enfocar) y 48 px de alto */
    .cm-input, .cm-input--chico {
        min-height: 48px;
        padding: 10px 12px;
        border-radius: 10px;
        font-size: 16px;
        line-height: 1.3;
    }
    .cm-input--area { min-height: 130px; resize: vertical; }
    .cm-input--referencia { margin-top: 0; }
    .cm-sheet select.cm-input { appearance: auto; }

    /* Buscador de lugar + «Buscar»: en una fila que no desborda */
    .cm-buscar-lugar { gap: 8px; margin-bottom: 0; }
    .cm-btn-buscar { flex: none; min-width: 88px; min-height: 48px; padding: 0 16px; border-radius: 10px; font-size: 16px; font-weight: 600; }

    /* Mapa a todo el ancho, 280 px de alto; botones táctiles */
    .cm-mapa { height: 280px; border-radius: 10px; }
    .cm-sheet .mini-mapa__ampliar { min-height: 44px; padding: 8px 14px; font-size: 14px; right: 8px; top: 8px; }
    .cm-sheet .mini-mapa .leaflet-control-zoom a { width: 40px; height: 40px; line-height: 40px; font-size: 20px; }
    .cm-sheet .mini-mapa .leaflet-control-attribution { max-width: 100%; font-size: 10px; }
    .mini-mapa__pista { font-size: 12px; line-height: 1.4; margin-top: 2px; }

    /* Evidencia */
    .cm-foto { height: 200px; margin-bottom: 8px; }
    .cm-foto__vacio { font-size: 32px; }
    .cm-btn-archivo { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px; border-radius: 10px; font-size: 16px; }
    .cm-archivo { min-height: 52px; padding: 8px; border-radius: 10px; font-size: 16px; color: #cbd5e1; }
    .cm-archivo::file-selector-button {
        min-height: 36px;
        margin-right: 12px;
        padding: 6px 14px;
        border: 1px solid #4b5563;
        border-radius: 8px;
        background: #222222;
        color: #ffffff;
        font-size: 16px;
        font-family: inherit;
        white-space: nowrap;
    }

    /* Botones de enviar y cancelar: fijos al pie, a todo el ancho */
    .cm-acciones {
        align-self: stretch;
        position: sticky;
        bottom: 0;
        z-index: 15;
        gap: 12px;
        margin: 4px calc(-16px - env(safe-area-inset-right, 0px)) 0 calc(-16px - env(safe-area-inset-left, 0px));
        padding: 12px calc(16px + env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
        background: #161616;
        border-top: 1px solid #262626;
    }
    .cm-btn { min-height: 48px; font-size: 16px; border-radius: 10px; }
    .cm-btn--enviar { flex: 2; }
    .cm-btn:active { filter: brightness(1.15); }

    .cm-sheet .nr__btn { min-height: 48px; font-size: 16px; }

    /* Resultado del envío: tarjeta centrada, no hoja completa */
    .comunidad-modal-container.cm-sheet.is-result {
        align-self: center;
        width: calc(100% - 28px);
        height: auto;
        max-height: calc(100% - 28px);
        margin: 14px;
        padding: 44px 22px 28px;
        border: 1px solid #333;
        border-radius: 16px;
    }
    .cm-sheet.is-result .cm-cerrar { top: 10px; right: 10px; width: 44px; height: 44px; font-size: 24px; }
    .comunidad-modal-backdrop.cm-backdrop:has(.cm-sheet.is-result) { align-items: center; background: rgba(0, 0, 0, 0.85); padding: 0; }
}

/* Horizontal en teléfono: cabecera más baja y sin la introducción */
@media (max-height: 500px) {
    .cm-cab { min-height: 52px; box-sizing: border-box; display: flex; align-items: center; padding-top: calc(4px + env(safe-area-inset-top, 0px)); padding-bottom: 4px; }
    .cm-cab h3 { font-size: 16px; margin: 0; }
    .cm-sheet .cm-intro { display: none; }
    .cm-mapa { height: 220px; }
    .cm-acciones { padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
    .cm-btn { min-height: 44px; }
    .cm-sheet { scroll-padding-top: 60px; scroll-padding-bottom: 70px; }
}

@media (prefers-reduced-motion: reduce) {
    .cm-btn, .cm-btn-buscar { transition: none; }
}
