/* ============================================
   AGROCOMERCIAL - TEMA AGRO PREMIUM
   Paleta: Verdes naturales + dorado trigo
   ============================================ */

:root {
    --agro-dark: #0f2818;
    --agro-primary: #1e4620;
    --agro-secondary: #4a8b2c;
    --agro-accent: #7cb342;
    --agro-light: #c5e1a5;
    --agro-gold: #c9a961;
    --agro-cream: #f7f5ef;
    --agro-bg: #f0ede3;
    --agro-text: #2c3e2d;
    --agro-border: #d4d0c0;
    --agro-success: #4a8b2c;
    --agro-danger: #c62828;
    --agro-warning: #f9a825;
    --agro-info: #2e7d32;
    --sidebar-width: 260px;
    --header-height: 65px;
    --shadow-sm: 0 2px 4px rgba(30, 70, 32, 0.08);
    --shadow-md: 0 4px 12px rgba(30, 70, 32, 0.12);
    --shadow-lg: 0 8px 24px rgba(30, 70, 32, 0.16);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--agro-bg);
    color: var(--agro-text);
    margin: 0;
    padding: 0;
    font-size: 14px;
    line-height: 1.5;
}

/* ============================================
   HEADER / NAVBAR
   ============================================ */
.navbar {
    background: linear-gradient(135deg, var(--agro-primary) 0%, var(--agro-dark) 100%) !important;
    height: var(--header-height);
    box-shadow: var(--shadow-md);
    border-bottom: 3px solid var(--agro-gold);
    padding: 0 1.5rem;
}

.navbar-brand {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-brand i {
    color: var(--agro-gold);
    font-size: 1.5rem;
}

.navbar-brand::after {
    content: '';
    display: inline-block;
    width: 4px;
    height: 24px;
    background: var(--agro-gold);
    margin-left: 0.75rem;
    border-radius: 2px;
}

#sidebarToggle {
    color: white !important;
    font-size: 1.2rem;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s;
}

#sidebarToggle:hover {
    background: rgba(255,255,255,0.1);
}

.user-badge {
    background: rgba(255,255,255,0.1);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    color: white;
    font-size: 0.875rem;
    border: 1px solid rgba(201, 169, 97, 0.3);
}

.btn-salir {
    background: rgba(201, 169, 97, 0.15);
    border: 1px solid var(--agro-gold);
    color: var(--agro-gold) !important;
    font-weight: 500;
    padding: 0.4rem 1rem;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-salir:hover {
    background: var(--agro-gold);
    color: var(--agro-dark) !important;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    min-height: calc(100vh - var(--header-height));
    background: linear-gradient(180deg, var(--agro-dark) 0%, #0a1f12 100%);
    margin-top: var(--header-height);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transition: all 0.3s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.2);
    overflow-y: auto;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid rgba(201, 169, 97, 0.2);
    background: rgba(0,0,0,0.15);
}

.sidebar-header h6 {
    color: var(--agro-gold);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-section {
    padding: 1rem 0.75rem 0.5rem;
    color: rgba(255,255,255,0.4);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 600;
}

.sidebar .nav-link {
    color: rgba(255,255,255,0.75) !important;
    padding: 0.75rem 1.25rem;
    margin: 2px 0.5rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
    border-left: 3px solid transparent;
}

.sidebar .nav-link i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    color: var(--agro-accent);
}

.sidebar .nav-link:hover {
    background: rgba(124, 179, 66, 0.1);
    color: white !important;
    border-left-color: var(--agro-accent);
}

.sidebar .nav-link.active {
    background: linear-gradient(90deg, var(--agro-secondary) 0%, rgba(74, 139, 44, 0.3) 100%);
    color: white !important;
    border-left-color: var(--agro-gold);
    box-shadow: 0 2px 8px rgba(74, 139, 44, 0.3);
}

.sidebar .nav-link.active i {
    color: var(--agro-gold);
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    margin-top: auto;
    border-top: 1px solid rgba(201, 169, 97, 0.2);
    text-align: center;
}

.sidebar-footer small {
    color: rgba(201, 169, 97, 0.6);
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

/* ============================================
   CONTENIDO PRINCIPAL
   ============================================ */
.content {
    margin-top: var(--header-height);
    margin-left: var(--sidebar-width);
    transition: all 0.3s ease;
    width: calc(100% - var(--sidebar-width));
    min-height: calc(100vh - var(--header-height));
    padding: 0;
}

.content.expanded {
    margin-left: 0;
    width: 100%;
}

.page-header {
    background: white;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--agro-border);
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--agro-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-title i {
    color: var(--agro-secondary);
    background: var(--agro-light);
    padding: 0.5rem;
    border-radius: 8px;
    font-size: 1.2rem;
}

.page-breadcrumb {
    font-size: 0.85rem;
    color: #6c757d;
}

.page-breadcrumb a {
    color: var(--agro-secondary);
    text-decoration: none;
}

.content-body {
    padding: 2rem;
}

/* ============================================
   CARDS / TARJETAS
   ============================================ */
.card {
    background: white;
    border: 1px solid var(--agro-border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-header {
    background: linear-gradient(135deg, #fafaf5 0%, #f0ede3 100%);
    border-bottom: 2px solid var(--agro-light);
    padding: 1rem 1.5rem;
    font-weight: 600;
    color: var(--agro-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-header i {
    color: var(--agro-secondary);
}

.card-body {
    padding: 1.5rem;
}

/* ============================================
   TARJETAS DE ESTADÍSTICAS (KPIs)
   ============================================ */
.stat-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--agro-border);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--agro-secondary);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-card.success::before { background: var(--agro-success); }
.stat-card.danger::before { background: var(--agro-danger); }
.stat-card.warning::before { background: var(--agro-warning); }
.stat-card.info::before { background: var(--agro-info); }
.stat-card.gold::before { background: var(--agro-gold); }

.stat-card .stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.stat-card.success .stat-icon {
    background: rgba(74, 139, 44, 0.12);
    color: var(--agro-success);
}

.stat-card.danger .stat-icon {
    background: rgba(198, 40, 40, 0.12);
    color: var(--agro-danger);
}

.stat-card.warning .stat-icon {
    background: rgba(249, 168, 37, 0.12);
    color: var(--agro-warning);
}

.stat-card.info .stat-icon {
    background: rgba(46, 125, 50, 0.12);
    color: var(--agro-info);
}

.stat-card.gold .stat-icon {
    background: rgba(201, 169, 97, 0.15);
    color: var(--agro-gold);
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--agro-primary);
    margin: 0;
    line-height: 1.2;
}

.stat-card .stat-change {
    font-size: 0.8rem;
    margin-top: 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
}

.stat-change.up {
    background: rgba(74, 139, 44, 0.1);
    color: var(--agro-success);
}

.stat-change.down {
    background: rgba(198, 40, 40, 0.1);
    color: var(--agro-danger);
}

/* ============================================
   BOTONES
   ============================================ */
.btn {
    font-weight: 500;
    padding: 0.5rem 1.25rem;
    border-radius: 8px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.btn-agro {
    background: linear-gradient(135deg, var(--agro-secondary) 0%, var(--agro-primary) 100%);
    color: white;
    border: none;
    box-shadow: 0 2px 8px rgba(74, 139, 44, 0.3);
}

.btn-agro:hover {
    background: linear-gradient(135deg, var(--agro-primary) 0%, var(--agro-dark) 100%);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 139, 44, 0.4);
}

.btn-agro-outline {
    background: transparent;
    color: var(--agro-secondary);
    border: 1.5px solid var(--agro-secondary);
}

.btn-agro-outline:hover {
    background: var(--agro-secondary);
    color: white;
}

.btn-gold {
    background: linear-gradient(135deg, var(--agro-gold) 0%, #a88842 100%);
    color: white;
    border: none;
}

.btn-gold:hover {
    background: linear-gradient(135deg, #a88842 0%, #8a6e30 100%);
    color: white;
}

/* ============================================
   TABLAS
   ============================================ */
.table {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table thead th {
    background: linear-gradient(135deg, var(--agro-primary) 0%, var(--agro-dark) 100%);
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    padding: 1rem;
    border: none;
}

.table tbody tr {
    transition: all 0.2s;
}

.table tbody tr:hover {
    background: rgba(124, 179, 66, 0.05);
}

.table tbody td {
    padding: 0.875rem 1rem;
    vertical-align: middle;
    border-color: var(--agro-border);
}

/* ============================================
   BADGES / ESTADOS
   ============================================ */
.badge-agro {
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.badge-success {
    background: rgba(74, 139, 44, 0.15);
    color: var(--agro-success);
}

.badge-warning {
    background: rgba(249, 168, 37, 0.15);
    color: #e65100;
}

.badge-danger {
    background: rgba(198, 40, 40, 0.15);
    color: var(--agro-danger);
}

.badge-info {
    background: rgba(46, 125, 50, 0.15);
    color: var(--agro-info);
}

/* ============================================
   FORMULARIOS
   ============================================ */
.form-label {
    font-weight: 600;
    color: var(--agro-primary);
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
}

.form-control, .form-select {
    border: 1.5px solid var(--agro-border);
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--agro-secondary);
    box-shadow: 0 0 0 3px rgba(74, 139, 44, 0.15);
}

.input-group-text {
    background: var(--agro-cream);
    border: 1.5px solid var(--agro-border);
    color: var(--agro-secondary);
    border-radius: 8px 0 0 8px;
}

/* ============================================
   LOGIN
   ============================================ */
.login-wrapper {
    min-height: 100vh;
    background: 
        linear-gradient(135deg, rgba(15, 40, 24, 0.92) 0%, rgba(30, 70, 32, 0.88) 100%),
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M50 20 Q55 35 70 40 Q55 45 50 60 Q45 45 30 40 Q45 35 50 20" fill="none" stroke="%234a8b2c" stroke-width="0.5" opacity="0.3"/></svg>');
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 440px;
    width: 100%;
    overflow: hidden;
    border-top: 4px solid var(--agro-gold);
}

.login-header {
    background: linear-gradient(135deg, var(--agro-primary) 0%, var(--agro-dark) 100%);
    padding: 2.5rem 2rem;
    text-align: center;
    color: white;
    position: relative;
}

.login-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 30px;
    background: white;
    clip-path: polygon(0 100%, 100% 100%, 100% 0, 50% 100%, 0 0);
}

.login-logo {
    width: 80px;
    height: 80px;
    background: rgba(201, 169, 97, 0.2);
    border: 2px solid var(--agro-gold);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 2.5rem;
    color: var(--agro-gold);
}

.login-header h2 {
    font-weight: 700;
    margin: 0;
    font-size: 1.5rem;
}

.login-header p {
    color: rgba(255,255,255,0.7);
    margin: 0.5rem 0 0;
    font-size: 0.9rem;
}

.login-body {
    padding: 2.5rem 2rem 2rem;
}

/* ============================================
   CHAT IA / ASISTENTE
   ============================================ */
.ai-chat-card {
    background: linear-gradient(135deg, white 0%, #fafaf5 100%);
    border: 1px solid var(--agro-border);
    border-radius: 12px;
    overflow: hidden;
}

.ai-chat-header {
    background: linear-gradient(135deg, var(--agro-primary) 0%, var(--agro-dark) 100%);
    color: white;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.ai-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--agro-gold) 0%, #a88842 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
}

/* ============================================
   ALERTAS Y NOTIFICACIONES
   ============================================ */
.alert-agro {
    background: white;
    border: 1px solid var(--agro-border);
    border-left: 4px solid var(--agro-secondary);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.alert-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--agro-border);
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--agro-secondary);
    margin-top: 0.5rem;
    flex-shrink: 0;
}

.alert-dot.urgent { background: var(--agro-danger); }
.alert-dot.warning { background: var(--agro-warning); }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 992px) {
    .sidebar {
        margin-left: calc(-1 * var(--sidebar-width));
    }
    .sidebar.show {
        margin-left: 0;
    }
    .content {
        margin-left: 0;
        width: 100%;
    }
    .content-body {
        padding: 1rem;
    }
    .page-header {
        padding: 1rem;
    }
}

/* ============================================
   SCROLLBAR PERSONALIZADO
   ============================================ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--agro-cream);
}

::-webkit-scrollbar-thumb {
    background: var(--agro-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--agro-primary);
}

/* ============================================
   UTILIDADES
   ============================================ */
.text-agro { color: var(--agro-primary) !important; }
.text-agro-light { color: var(--agro-secondary) !important; }
.text-gold { color: var(--agro-gold) !important; }
.bg-agro { background-color: var(--agro-primary) !important; }
.bg-agro-light { background-color: var(--agro-light) !important; }
.bg-agro-cream { background-color: var(--agro-cream) !important; }

.border-agro { border-color: var(--agro-secondary) !important; }
.shadow-agro { box-shadow: var(--shadow-md) !important; }

.divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--agro-border), transparent);
    margin: 1.5rem 0;
}
/* ============================================
   MODO ULTRA COMPACTO + FIXES (Agregar al final)
   ============================================ */

/* 1. Variables más compactas */
:root {
    --header-height: 50px !important; /* Antes 65px */
    --sidebar-width: 220px !important; /* Antes 260px */
}

/* 2. Header más chico */
.navbar {
    height: var(--header-height) !important;
    padding: 0 1rem !important;
}
.navbar-brand {
    font-size: 1.1rem !important;
}
.navbar-brand i {
    font-size: 1.2rem !important;
}
.user-badge, .btn-salir {
    padding: 0.2rem 0.6rem !important;
    font-size: 0.75rem !important;
}

/* 3. Sidebar más chica, con scrollbar y responsive */
.sidebar {
    width: var(--sidebar-width) !important;
    min-height: calc(100vh - var(--header-height)) !important;
    margin-top: var(--header-height) !important;
    overflow-y: auto !important; /* Barra de scroll si hay muchos módulos */
    overflow-x: hidden !important;
}

/* Scrollbar fino y elegante solo para la sidebar */
.sidebar::-webkit-scrollbar {
    width: 4px !important;
}
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(201, 169, 97, 0.4) !important;
    border-radius: 2px !important;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent !important;
}

.sidebar-header {
    padding: 0.6rem 1rem !important;
}
.sidebar-header h6 {
    font-size: 0.7rem !important;
}
.sidebar-section {
    padding: 0.6rem 0.75rem 0.2rem !important;
    font-size: 0.65rem !important;
}
.sidebar .nav-link {
    padding: 0.45rem 1rem !important;
    margin: 1px 0.5rem !important;
    font-size: 0.8rem !important;
    gap: 0.5rem !important;
}
.sidebar .nav-link i {
    width: 16px !important;
    font-size: 0.85rem !important;
}
.sidebar-footer {
    padding: 0.6rem 1rem !important;
    font-size: 0.65rem !important;
}

/* 4. Contenido principal ajustado */
.content {
    margin-top: var(--header-height) !important;
    margin-left: var(--sidebar-width) !important;
    width: calc(100% - var(--sidebar-width)) !important;
}
.page-header {
    padding: 0.6rem 1.25rem !important;
}
.page-title {
    font-size: 1.1rem !important;
    gap: 0.5rem !important;
}
.page-title i {
    padding: 0.3rem !important;
    font-size: 0.95rem !important;
}
.content-body {
    padding: 1rem !important;
}

/* 5. FIX DEL GRÁFICO: Evita que se estire hacia abajo infinitamente */
canvas#chartOperaciones {
    max-height: 280px !important;
    width: 100% !important;
}
/* Forzar altura al contenedor del gráfico */
.card:has(#chartOperaciones) .card-body, 
div[id*="chart"] {
    position: relative !important;
    height: 280px !important;
    max-height: 280px !important;
    overflow: hidden;
}

/* 6. Refuerzo compacto para tablas, forms y botones */
.table thead th { padding: 0.4rem 0.6rem !important; font-size: 0.7rem !important; }
.table tbody td { padding: 0.4rem 0.6rem !important; font-size: 0.8rem !important; }
.form-control, .form-select { padding: 0.3rem 0.5rem !important; font-size: 0.8rem !important; }
.form-label { font-size: 0.75rem !important; margin-bottom: 0.2rem !important; }
.btn { padding: 0.3rem 0.7rem !important; font-size: 0.8rem !important; }
.btn-sm { padding: 0.2rem 0.5rem !important; font-size: 0.7rem !important; }
.stat-card { padding: 0.75rem !important; }
.stat-card .stat-value { font-size: 1.2rem !important; }
.stat-card .stat-icon { width: 36px !important; height: 36px !important; font-size: 1rem !important; }

/* 7. Responsive Mobile (Sidebar colapsable) */
@media (max-width: 992px) {
    .sidebar {
        margin-left: calc(-1 * var(--sidebar-width)) !important;
        z-index: 1050 !important;
        transition: margin-left 0.3s ease !important;
    }
    .sidebar.show {
        margin-left: 0 !important;
        box-shadow: 4px 0 15px rgba(0,0,0,0.4) !important;
    }
    .content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    /* Overlay oscuro cuando se abre el menú en mobile */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: var(--header-height);
        left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
    }
    .sidebar.show ~ .sidebar-overlay,
    .sidebar.show + .sidebar-overlay {
        display: block !important;
    }
}