/* ================================
   AGRINTELL MAIN STYLES
   ================================ */

:root {
    --agr-green: #19C837;
    --agr-blue:  #00B5F0;
    --agr-blue-soft: #E0F7FF;
    --agr-bg:    #F3F4F6;
    --agr-card:  #FFFFFF;
    --agr-dark:  #1B1B1B;
    --agr-muted: #6B7280;
    --agr-border:#E5E7EB;
    --agr-border-strong:#D1D5DB;
    --agr-danger:#DC2626;
    --agr-radius-lg: 14px;
    --agr-radius-md: 10px;
    --agr-radius-sm: 6px;
    --agr-shadow-soft: 0 10px 25px rgba(15, 23, 42, 0.07);
    --agr-shadow-subtle: 0 4px 12px rgba(15, 23, 42, 0.05);
    --agr-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
                sans-serif;
}

/* ========== GLOBAL ========== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: var(--agr-font);
    background: radial-gradient(circle at top left, #F8FEFF 0, var(--agr-bg) 40%, #E5F2FF 100%);
    color: var(--agr-dark);
}

a {
    color: var(--agr-blue);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.text-muted {
    color: var(--agr-muted);
}

/* ========== APP LAYOUT ========== */

.app-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-main {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ========== TOPBAR ========== */

.topbar {
    position: sticky;
    top: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 1.3rem;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--agr-border);
    backdrop-filter: blur(12px);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.topbar-logo-link {
    display: inline-flex;
    align-items: center;
}

.topbar-logo {
    height: 30px;
    width: auto;
}

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--agr-dark);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.topbar-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.78rem;
    line-height: 1.2;
}

.topbar-user .user-name {
    font-weight: 600;
}

.topbar-user .user-role {
    color: var(--agr-muted);
}

.logout-btn,
.login-btn {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    border: 1px solid var(--agr-border-strong);
    background: #FFFFFF;
    color: var(--agr-dark);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    text-decoration: none;
    box-shadow: var(--agr-shadow-subtle);
}

.logout-btn:hover,
.login-btn:hover {
    background: #F9FAFB;
    text-decoration: none;
}

/* ========== SIDEBAR ========== */

.sidebar {
    width: 230px;
    background: linear-gradient(180deg, #F4FBF7 0%, #F4FAFF 35%, #EDF2F7 100%);
    border-right: 1px solid var(--agr-border);
    padding: 0.9rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.sidebar-header {
    padding: 0 0.3rem 0.2rem;
    border-bottom: 1px solid rgba(209, 213, 219, 0.7);
    margin-bottom: 0.4rem;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    text-decoration: none;
}

.sidebar-logo {
    height: 26px;
    width: auto;
}

.sidebar-title {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.01em;
    color: var(--agr-dark);
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0 0.1rem;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.7rem;
    border-radius: 999px;
    background: rgba(255,255,255,0.9);
    border: 1px solid transparent;
    font-size: 0.86rem;
    color: #111827;
    box-shadow: 0 1px 2px rgba(15,23,42,0.03);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.menu-item:hover {
    background: #F0FDFA;
    border-color: #A7F3D0;
    text-decoration: none;
}

.menu-item i {
    font-size: 1.05rem;
    width: 20px;
    text-align: center;
    display: inline-block;
}

.menu-item span {
    flex: 1;
}

/* Bloque "Tus campos" */

.sidebar-section {
    margin-top: 0.6rem;
    padding: 0.6rem 0.45rem 0.4rem;
    border-radius: var(--agr-radius-md);
    background: rgba(255,255,255,0.9);
    border: 1px solid rgba(209, 213, 219, 0.9);
}

.sidebar-section h3 {
    margin: 0 0 0.5rem;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--agr-muted);
}

.field-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.field-list li {
    background: #ffffff;
    border-radius: 12px;
    padding: 0.45rem 0.6rem;
    font-size: 0.8rem;
    box-shadow: 0 3px 8px rgba(15,23,42,0.06);
    border: 1px solid #E5E7EB;
}

.field-list li strong {
    display: block;
    margin-bottom: 0.1rem;
    color: #111827;
}

.field-list li small {
    color: var(--agr-muted);
}

/* ========== CONTENT AREA ========== */

.content-area {
    flex: 1;
    padding: 1.2rem 1.4rem;
    background: transparent;
    min-height: calc(100vh - 56px); /* topbar */
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.9rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 650;
    color: var(--agr-dark);
}

.page-subtitle {
    margin: 0.2rem 0 0;
    font-size: 0.85rem;
    color: var(--agr-muted);
}

/* ========== CARDS & TABLES ========== */

.table-card {
    background: var(--agr-card);
    border-radius: var(--agr-radius-lg);
    border: 1px solid var(--agr-border-strong);
    box-shadow: var(--agr-shadow-soft);
    padding: 0.4rem;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table thead {
    background: #F9FAFB;
}

.data-table th,
.data-table td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--agr-border);
    text-align: left;
}

.data-table th {
    font-weight: 600;
    color: #111827;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.data-table tbody tr:nth-child(even) {
    background: #F9FAFB;
}

.data-table tbody tr:hover {
    background: #EFF6FF;
}

/* ========== FORMULARIOS ========== */

.form-card {
    background: var(--agr-card);
    border-radius: var(--agr-radius-lg);
    border: 1px solid var(--agr-border-strong);
    box-shadow: var(--agr-shadow-soft);
    padding: 1rem 1.1rem;
    max-width: 750px;
}

.form-card label {
    display: block;
    font-size: 0.86rem;
    margin-bottom: 0.55rem;
    color: #111827;
}

.form-card input,
.form-card select,
.form-card textarea {
    width: 100%;
    padding: 0.42rem 0.55rem;
    border-radius: var(--agr-radius-sm);
    border: 1px solid var(--agr-border-strong);
    font-size: 0.85rem;
    margin-top: 0.18rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-card input:focus,
.form-card select:focus,
.form-card textarea:focus {
    border-color: var(--agr-blue);
    box-shadow: 0 0 0 1px rgba(0,181,240, 0.25);
}

.form-card textarea {
    resize: vertical;
}

.form-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.8rem;
}

.form-inline {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    font-size: 0.83rem;
}

/* ========== BUTTONS ========== */

.primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--agr-green), var(--agr-blue));
    color: #FFFFFF;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: none;
    box-shadow: 0 8px 18px rgba(34, 197, 94, 0.18);
}

.primary-btn:hover {
    filter: brightness(1.04);
    text-decoration: none;
}

.link-btn {
    font-size: 0.82rem;
    color: var(--agr-blue);
}

.link-btn:hover {
    text-decoration: underline;
}

.delete-btn {
    font-size: 0.82rem;
    color: var(--agr-danger);
}

.delete-btn:hover {
    text-decoration: underline;
}

/* ========== ALERTAS ========== */

.alert {
    padding: 0.55rem 0.7rem;
    border-radius: var(--agr-radius-md);
    font-size: 0.85rem;
    margin-bottom: 0.7rem;
}

.alert.error {
    background: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FECACA;
}

.alert.success {
    background: #ECFDF5;
    color: #166534;
    border: 1px solid #BBF7D0;
}

/* ========== MAPA ========== */

.map-panel {
    position: relative;
    background: var(--agr-card);
    border-radius: var(--agr-radius-lg);
    border: 1px solid var(--agr-border-strong);
    box-shadow: var(--agr-shadow-soft);
    padding: 0.75rem;
    /* aprovechar la altura */
    min-height: calc(100vh - 160px);
}

.map-container {
    width: 100%;
    height: calc(100vh - 200px);
    border-radius: var(--agr-radius-md);
    overflow: hidden;
}

/* Leyenda del mapa */

.map-legend {
    position: absolute;
    top: 14px;
    right: 14px;
    background: rgba(255,255,255,0.95);
    padding: 0.6rem 0.8rem;
    border-radius: 12px;
    border: 1px solid #D1D5DB;
    box-shadow: var(--agr-shadow-subtle);
    font-size: 0.8rem;
    z-index: 10;
}

.map-legend h4 {
    margin: 0 0 0.3rem 0;
    font-size: 0.8rem;
    font-weight: 600;
}

.map-legend ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.map-legend li {
    display: flex;
    align-items: center;
    margin-bottom: 0.25rem;
}

.map-legend li span {
    width: 16px;
    height: 12px;
    border-radius: 3px;
    margin-right: 0.4rem;
    display: inline-block;
}

/* ========== LOGIN (fondo difuminado) ========== */

body.auth-container,
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Imagen de fondo agrícola */
    background: url('../img/fondo.jpg') center/cover no-repeat fixed;
    position: relative;
}

/* Capa que aplica blur y oscurece ligeramente */
body.auth-container::before,
.auth-container::before {
    content: "";
    position: absolute;
    inset: 0;
    backdrop-filter: blur(14px);
    background: rgba(0, 0, 0, 0.25);
    z-index: 0;
}

/* Tarjeta de login */
.auth-card {
    position: relative;
    z-index: 1;
    background: rgba(255,255,255,0.92);
    border-radius: 20px;
    padding: 1.6rem 1.9rem;
    box-shadow: 0 18px 40px rgba(0,0,0,0.22);
    border: 1px solid rgba(255,255,255,0.6);
    max-width: 380px;
    width: 100%;
}

.auth-subtitle {
    font-size: 0.85rem;
    color: var(--agr-muted);
    margin-bottom: 0.4rem;
}

.auth-card .form-card {
    box-shadow: none;
    border: none;
    padding: 0;
}

/* ========== RESPONSIVE ========== */

@media (max-width: 900px) {
    .sidebar {
        display: none;
    }

    .content-area {
        padding: 0.9rem 0.8rem 1.3rem;
    }

    .topbar {
        padding-inline: 0.7rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .map-panel {
        min-height: 420px;
    }

    .map-container {
        height: 380px;
    }
}

@media (max-width: 600px) {
    .table-card {
        padding: 0.25rem;
    }

    .form-card {
        padding: 0.75rem;
    }
}
/* Tarjetas KPI del dashboard */

.kpi-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.kpi-card {
    flex: 1 1 180px;
    min-width: 0;
    display: flex;
    align-items: center;
    padding: 0.6rem 0.75rem;
    border-radius: 14px;
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    box-shadow: 0 4px 12px rgba(15,23,42,0.06);
}

.kpi-icon {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.55rem;
    color: #FFFFFF;
    font-size: 1.1rem;
}

.kpi-icon-green {
    background: linear-gradient(135deg, #16a34a, #22c55e);
}

.kpi-icon-blue {
    background: linear-gradient(135deg, #0ea5e9, #22d3ee);
}

.kpi-icon-teal {
    background: linear-gradient(135deg, #22c55e, #0ea5e9);
}

.kpi-body {
    display: flex;
    flex-direction: column;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--agr-muted);
}

.kpi-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--agr-dark);
}
/* ============================================================
   SIDEBAR RESPONSIVE – SOLO EXTENSIONES (NO ROMPE ESCRITORIO)
   ============================================================ */

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.45rem;
    color: var(--agr-dark);
    cursor: pointer;
}

/* Sidebar overlay para móvil */
@media (max-width: 900px) {

    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0.3rem;
        margin-right: 0.4rem;
    }

    .sidebar {
        position: fixed;
        top: 56px; /* debajo del topbar */
        left: -260px;
        height: calc(100vh - 56px);
        width: 240px;
        transition: left 0.25s ease;
        z-index: 9999;
        box-shadow: 2px 0 10px rgba(0,0,0,0.10);
    }

    /* Cuando está abierto */
    body.sidebar-open .sidebar {
        left: 0;
    }

    /* Fondo oscuro detrás del sidebar */
    body.sidebar-open::before {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.35);
        z-index: 9998;
    }
}

/* ============================================================
   TABLAS RESPONSIVE
   ============================================================ */

@media (max-width: 700px) {

    .data-table thead {
        display: none;
    }

    .data-table tr {
        display: block;
        background: #ffffff;
        margin-bottom: 0.9rem;
        border-radius: 12px;
        padding: 0.7rem 0.9rem;
        box-shadow: 0 3px 8px rgba(0,0,0,0.06);
    }

    .data-table td {
        display: flex;
        justify-content: space-between;
        padding: 0.25rem 0;
        border: none;
    }

    .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--agr-muted);
        margin-right: 10px;
        flex-shrink: 0;
    }
}

/* ============================================================
   MAPA RESPONSIVE
   ============================================================ */

@media (max-width: 900px) {
    .map-container {
        height: 380px !important;
    }
}

@media (max-width: 600px) {
    .map-container {
        height: 320px !important;
    }
}

/* ============================================================
   FORMULARIOS RESPONSIVE
   ============================================================ */

@media (max-width: 650px) {
    .form-card {
        padding: 0.85rem !important;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.55rem;
    }

    .form-actions {
        flex-direction: column;
    }

    .primary-btn,
    .ghost-btn {
        width: 100%;
        justify-content: center;
    }
}
/* ========== RESPONSIVE IMPROVEMENTS (non-breaking) ========== */

/* Botón hamburguesa (oculto en escritorio por defecto) */
.menu-toggle {
    display: none;
    border: none;
    background: transparent;
    font-size: 1.4rem;
    color: var(--agr-dark);
    cursor: pointer;
    padding: 0.1rem 0.35rem;
}

/* En pantallas pequeñas: sidebar como drawer y botón visible */
@media (max-width: 900px) {
    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin-right: 0.2rem;
    }

    /* El sidebar deja de ocupar fijo la izquierda y se convierte en panel deslizante */
    .sidebar {
        position: fixed;
        top: 56px; /* altura aprox del topbar */
        left: -240px;
        height: calc(100vh - 56px);
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(15,23,42,0.18);
        transition: left 0.25s ease;
    }

    /* Cuando el body tiene .sidebar-open, mostramos el sidebar */
    body.sidebar-open .sidebar {
        left: 0;
    }

    /* Fondo semitransparente detrás del sidebar cuando está abierto */
    body.sidebar-open::before {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,0.35);
        z-index: 900;
    }

    /* Un poco menos padding para contenido en móvil */
    .content-area {
        padding: 0.9rem 0.8rem 1.3rem;
    }

    /* Header de página en columna para que no se aplaste en móvil */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    /* Ajuste de altura del panel de mapa para que no sea gigante en móvil */
    .map-panel {
        min-height: 420px;
    }

    .map-container {
        height: 360px;
    }
}

/* Pantallas muy pequeñas: map un poco más bajo */
@media (max-width: 600px) {
    .map-container {
        height: 300px;
    }
}
/* ========== FIX DEFINITIVO PARA SIDEBAR RESPONSIVE ========== */

.menu-toggle {
    display: none;
}

@media (max-width: 900px) {
    /* Botón hamburguesa visible en móvil */
    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        font-size: 1.45rem;
        cursor: pointer;
        margin-right: 0.4rem;
        color: var(--agr-dark);
        padding: 0.1rem 0.3rem;
    }

    /* Rompemos el flex horizontal para que sidebar pueda ir encima */
    .app-main {
        display: block;
    }

    /* Sidebar como panel deslizante desde la izquierda */
    .sidebar {
        position: fixed;
        top: 56px; /* altura del topbar aprox */
        left: -240px;  /* oculto por defecto */
        width: 230px;
        height: calc(100vh - 56px);
        z-index: 1000;
        background: #ffffff;
        padding: 0.9rem 0.85rem;
        box-shadow: 2px 0 10px rgba(15,23,42,0.18);
        overflow-y: auto;
        transition: left 0.25s ease;
        display: block; /* CLAVE: ya no display:none */
    }

    /* Cuando el <html> tiene la clase .sidebar-open → mostrar sidebar */
    html.sidebar-open .sidebar {
        left: 0;
    }

    /* Fondo oscuro detrás del sidebar abierto */
    html.sidebar-open::before {
    content: "";
    position: fixed;
    top: 56px;   /* altura aprox. del topbar */
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15,23,42,0.35);
    z-index: 900;
}


    .content-area {
        padding: 0.9rem 0.8rem 1.3rem;
    }

    .topbar {
        padding-inline: 0.7rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .map-panel {
        min-height: 420px;
    }

    .map-container {
        height: 380px;
    }
}
@media (max-width: 700px) {
    .kpi-row {
        gap: 0.6rem;
    }

    .kpi-card {
        flex: 1 1 100%;
    }
}

