/**
 * cultivalo.css — Estilos personalizados de Cultivalo
 *
 * Complementa a Tailwind CSS con componentes y patrones propios de la aplicación.
 *
 * Secciones:
 *   1.  Base
 *   2.  Animaciones
 *   3.  Accesibilidad
 *   4.  Formularios
 *   5.  Botones
 *   6.  Spinners y overlays de carga
 *   7.  Alertas
 *   8.  Badges (etiquetas de estado)
 *   9.  Modales
 *   10. Tabs / Pestañas
 *   11. Árbol de usuarios (tree view)
 *   12. Mapas (páginas con Leaflet)
 *   13. Responsive
 */

/* =========================================================
   1. BASE
   ========================================================= */

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* =========================================================
   2. ANIMACIONES
   ========================================================= */

.transition-shadow {
    transition: box-shadow 0.3s ease;
}

.transition-colors {
    transition: background-color 0.3s ease, color 0.3s ease;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

/* Clase utilitaria de animación */
.fadeIn { animation: fadeIn 0.3s ease; }

/* =========================================================
   3. ACCESIBILIDAD
   ========================================================= */

a:focus, button:focus, input:focus, select:focus, textarea:focus {
    outline: 2px solid #10b981;
    outline-offset: 2px;
}

/* =========================================================
   4. FORMULARIOS
   ========================================================= */

.form-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    background-color: white;
}

.form-input:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
}

.error-message {
    color: #ef4444;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

input::-webkit-calendar-picker-indicator {
    opacity: 0.5;
    cursor: pointer;
}

/* Select personalizado con flecha propia */
.custom-select-wrapper {
    position: relative;
    width: 100%;
}

.custom-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    background-color: white;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1.5em 1.5em;
    cursor: pointer;
}

datalist {
    position: absolute;
    max-height: 20em;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    background-color: white;
    overflow-y: auto;
    z-index: 50;
}

/* =========================================================
   5. BOTONES
   ========================================================= */

.btn {
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-weight: 500;
}

.btn-primary {
    background-color: #10b981;
    color: white;
}

.btn-primary:hover {
    background-color: #059669;
}

.btn-secondary {
    background-color: #e5e7eb;
    color: #374151;
}

.btn-secondary:hover {
    background-color: #d1d5db;
}

/* =========================================================
   6. SPINNERS Y OVERLAYS DE CARGA
   ========================================================= */

/* Spinner pequeño — para usar inline o dentro de botones */
.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-left-color: #10b981;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Spinner mediano — para secciones de contenido (ej: resultados cargando) */
.loading-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #10b981;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

/* Spinner grande — para indicadores de carga de página */
.spinner-lg {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #10b981;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

/* Overlay de carga a pantalla completa */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

/* Spinner extra-grande cuando va dentro del overlay de página completa */
.loading-overlay .spinner-lg {
    width: 50px;
    height: 50px;
    border-width: 4px;
}

/* =========================================================
   7. ALERTAS
   ========================================================= */

.alert {
    padding: 0.75rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: 0.375rem;
}

.alert-success {
    background-color: #d1fae5;
    border-color: #a7f3d0;
    color: #065f46;
}

.alert-error {
    background-color: #fee2e2;
    border-color: #fecaca;
    color: #b91c1c;
}

.alert-info {
    background-color: #e0f2fe;
    border-color: #bae6fd;
    color: #0369a1;
}

.alert-hidden {
    display: none;
}

/* =========================================================
   8. BADGES (etiquetas de estado)
   ========================================================= */

.badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-weight: 600;
}

/* Estado de módulos — dashboard */
.badge-disponible   { background-color: #10b981; color: white; }
.badge-desarrollo   { background-color: #f59e0b; color: white; }
.badge-proximamente { background-color: #6b7280; color: white; }

/* Roles de usuario */
.badge-admin { background-color: #fef3c7; color: #92400e; }
.badge-inter { background-color: #dbeafe; color: #1e40af; }
.badge-user  { background-color: #d1fae5; color: #065f46; }

/* Tipos en mapas (balsas = azul agua, canales/acequias = ámbar) */
.badge-ag { background-color: #dbeafe; color: #1e40af; }
.badge-ch { background-color: #fef3c7; color: #92400e; }

/* =========================================================
   9. MODALES
   ========================================================= */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fefefe;
    padding: 20px;
    border-radius: 8px;
    max-width: 90%;
    max-height: 90%;
    overflow: auto;
}

/* =========================================================
   10. TABS / PESTAÑAS
   ========================================================= */

.tab-button {
    position: relative;
    transition: all 0.3s ease;
}

.tab-button.active {
    font-weight: 600;
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 3px;
    background-color: currentColor;
    border-radius: 3px 3px 0 0;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in;
}

.tab-content.active {
    display: block;
}

/* Menú de tabs en móvil (colapsable) */
.mobile-tab-menu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.mobile-tab-menu.open {
    max-height: 600px;
}

/* =========================================================
   11. ÁRBOL DE USUARIOS (tree view)
   ========================================================= */

.tree-node {
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.25rem;
    margin: 0.25rem 0;
    transition: background-color 0.2s;
}

.tree-node:hover {
    background-color: #f3f4f6;
}

.tree-node.selected {
    background-color: #dbeafe;
    border-left: 3px solid #3b82f6;
}

.tree-node-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tree-toggle {
    width: 1rem;
    height: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

.tree-children {
    margin-left: 1.5rem;
    border-left: 1px solid #e5e7eb;
    padding-left: 0.5rem;
}

.tree-children.collapsed {
    display: none;
}

/* Grid y tabla de usuarios */
.grid-container {
    overflow-x: auto;
}

.user-grid {
    min-width: 800px;
}

/* =========================================================
   12. MAPAS (páginas con Leaflet)
   ========================================================= */

/* Contenedor principal en páginas de mapa — z-index bajo para que los modales queden encima */
.main-content {
    position: relative;
    z-index: 1;
}

/* Barra lateral en páginas de mapa */
.sidebar {
    overflow-y: auto;
    position: relative;
    z-index: 2;
}

/* Control de capas Leaflet — tamaño mejorado para pantallas táctiles */
.leaflet-control-layers {
    font-size: 14px;
    padding: 8px 12px;
}

.leaflet-control-layers-toggle {
    width: 40px;
    height: 40px;
    background-size: 26px 26px;
}

.leaflet-control-layers-list {
    padding: 8px;
}

.leaflet-control-layers label {
    margin-bottom: 6px;
    display: block;
}

.leaflet-control-layers-base label span {
    font-size: 14px;
    margin-left: 6px;
}

/* Items en listas de mapa (balsas, canales, sectores) */
.balsa-item,
.canal-item,
.sector-item {
    transition: all 0.2s ease;
}

.balsa-item:hover,
.canal-item:hover,
.sector-item:hover {
    background-color: #f0fdfa;
}

.balsa-item.selected,
.canal-item.selected,
.sector-item.selected {
    background-color: #ccfbf1;
    border-left: 4px solid #14b8a6;
}

/* Punto indicador de alerta en mapas */
.alerta-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Toast / notificación flotante */
.toast-notification {
    animation: slideIn 0.3s ease-out;
}

/* Barra de porcentaje (uso en varios módulos de mapa) */
.barra-pct {
    height: 8px;
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* =========================================================
   13. RESPONSIVE
   ========================================================= */

@media (max-width: 640px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* Páginas de mapa con sidebar — colapsa a pantalla completa en móvil */
@media (max-width: 768px) {
    .sidebar {
        width: 100% !important;
        min-width: 100% !important;
        height: auto !important;
        max-height: 40vh;
    }

    .main-content {
        flex-direction: column-reverse;
    }

    #map {
        height: 60vh !important;
    }
}

/* Página de usuarios — paneles árbol/grid apilados en tablet */
@media (max-width: 1024px) {
    .main-layout {
        flex-direction: column;
    }

    .tree-panel,
    .grid-panel {
        width: 100% !important;
    }
}

/* ============================================================ */
/* Navegador Agrícola — animación del marcador GPS              */
/* ============================================================ */
@keyframes gps-pulse {
    0%   { transform: scale(1);   opacity: 0.6; }
    100% { transform: scale(2.8); opacity: 0;   }
}

