:root {
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --accent-color: #3498db;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --light-bg: #f8f9fa;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f6fa;
    overflow-x: hidden;
}

/* Layout */
.wrapper {
    display: flex;
    min-height: 100vh;
}

.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
    overflow: hidden; /* Evita doble scroll */
}

.sidebar-collapsed .main {
    margin-left: var(--sidebar-collapsed-width);
}

/* Content Area - NUEVO: Contenedor principal del contenido */
.content {
    background-color: var(--light-bg);
    min-height: calc(100vh - 80px);
    padding: 1.5rem;
    overflow: auto; /* Permite scroll en el contenido */
}

/* Container Fluid - NUEVO: Asegura que use todo el ancho */
.container-fluid {
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
}

/* Tablas Responsivas - MEJORADO */
.table-responsive {
    max-height: calc(100vh - 200px); /* Altura máxima basada en viewport */
    overflow-x: auto; /* Sin scroll horizontal */
    overflow-y: auto; /* Solo scroll vertical cuando sea necesario */
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    width: 100%; /* Ocupa todo el ancho disponible */
}

/* Estilos para las barras de scroll - SOLO VERTICAL */
.table-responsive::-webkit-scrollbar {
    width: 8px; /* Solo scroll vertical */
}

.table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Tabla principal */
.table {
    margin-bottom: 0;
    width: 100% !important; /* Fuerza el 100% del ancho */
    table-layout: fixed; /* Distribución equitativa del ancho */
}

.table th {
    background-color: var(--primary-color);
    color: white;
    border: none;
    font-weight: 600;
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    word-wrap: break-word; /* Permite que el texto se ajuste */
    white-space: normal; /* Permite múltiples líneas */
}

.table td {
    padding: 1rem;
    vertical-align: middle;
    border-color: #e9ecef;
    word-wrap: break-word; /* Permite que el texto se ajuste */
    white-space: normal; /* Permite múltiples líneas */
    overflow: hidden; /* Oculta el exceso de texto */
    text-overflow: ellipsis; /* Muestra puntos suspensivos si es muy largo */
}

/* Eliminar la columna fija ya que no hay scroll horizontal */
.table td:first-child,
.table th:first-child {
    position: static; /* Ya no es sticky */
    background: inherit;
    box-shadow: none;
}

.table th:first-child {
    background: var(--primary-color);
}

/* Ajustes específicos para columnas con contenido largo */
.table td:nth-child(2), /* Matrícula */
.table td:nth-child(3) { /* Propietario */
    min-width: 120px;
    max-width: 200px;
}

.table td:nth-child(4), /* Distrito */
.table td:nth-child(6) { /* Padrón */
    min-width: 100px;
    max-width: 150px;
}

.table td:nth-child(5) { /* Superficie */
    min-width: 80px;
    max-width: 100px;
}

.table td:nth-child(7) { /* Situación */
    min-width: 100px;
    max-width: 150px;
}


/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    position: fixed;
    height: 100vh;
    transition: width 0.3s ease;
    z-index: 1000;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    overflow-y: auto; /* Scroll en sidebar si es necesario */
}

.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-icon {
    font-size: 2rem;
    margin-right: 0.75rem;
}

.logo-text h5 {
    color: white;
    font-weight: 600;
}

.btn-close-sidebar {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.sidebar-collapsed .btn-close-sidebar {
    transform: rotate(180deg);
}

.sidebar-body {
    padding: 1rem 0;
    height: calc(100vh - 160px);
    overflow-y: auto;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
}

.sidebar-item {
    margin: 0.25rem 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.1);
    color: white;
    border-left-color: var(--accent-color);
}

.sidebar-link.active {
    background: rgba(255,255,255,0.15);
    color: white;
    border-left-color: var(--accent-color);
}

.sidebar-icon {
    font-size: 1.2rem;
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

.sidebar-collapsed .sidebar-text {
    display: none;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
}

.user-avatar {
    font-size: 2rem;
    margin-right: 0.75rem;
}

.user-details h6 {
    color: white;
    margin-bottom: 0;
}

.logout-link {
    color: rgba(255,255,255,0.8) !important;
}

.logout-link:hover {
    color: white !important;
}

/* Header */
.header {
    background: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 999;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-title h1 {
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Cards */
.card {
    border: none;
    border-radius: 12px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1) !important;
}

.metric-card {
    background: white;
}

.metric-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
}

/* Buttons */
.btn {
    border-radius: 8px;
    font-weight: 500;
    padding: 0.5rem 1.5rem;
    transition: all 0.3s ease;
}

.btn-primary {
    background: var(--accent-color);
    border-color: var(--accent-color);
}

.btn-primary:hover {
    background: #2980b9;
    border-color: #2980b9;
    transform: translateY(-1px);
}

/* Modal */
.modal-content {
    border: none;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}

.modal-header {
    border-bottom: 1px solid #e9ecef;
    padding: 1.5rem;
}

.modal-footer {
    border-top: 1px solid #e9ecef;
    padding: 1.5rem;
}

/* Forms */
.form-control, .form-select {
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    padding: 0.75rem 1rem;
    transition: all 0.3s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
}

/* Fincas Styles */
.finca-row {
    cursor: pointer;
    transition: background-color 0.2s;
}

.finca-row:hover {
    background-color: #f8f9fa;
}

.finca-row.table-active {
    background-color: #e3f2fd;
    border-left: 3px solid #0d6efd;
}

#formularioInforme {
    transition: all 0.3s ease-in-out;
}

/* Responsive Design - MEJORADO */
@media (max-width: 1200px) {
    .table-responsive {
        max-height: calc(100vh - 180px);
    }
    
    .table td:nth-child(2),
    .table td:nth-child(3) {
        min-width: 100px;
        max-width: 150px;
    }
}

@media (max-width: 992px) {
    .content {
        padding: 1rem;
    }
    
    .table-responsive {
        max-height: calc(100vh - 160px);
        font-size: 0.9rem;
    }
    
    .table th,
    .table td {
        padding: 0.75rem;
    }
    
    .table td:nth-child(2),
    .table td:nth-child(3) {
        min-width: 80px;
        max-width: 120px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-collapsed-width);
    }
    
    .main {
        margin-left: var(--sidebar-collapsed-width);
    }
    
    .sidebar-text {
        display: none;
    }
    
    .header {
        padding: 1rem;
    }
    
    .content {
        padding: 0.75rem;
    }
    
    .table-responsive {
        max-height: calc(100vh - 140px);
        font-size: 0.85rem;
    }
    
    .table th,
    .table td {
        padding: 0.5rem;
    }
    
    /* En móviles, permitir algo de scroll horizontal si es necesario */
    .table-responsive {
        overflow-x: auto;
    }
    
    .table {
        table-layout: auto; /* Layout automático en móviles */
        min-width: 600px; /* Ancho mínimo para móviles */
    }
}

@media (max-width: 576px) {
    .table-responsive {
        border-radius: 4px;
        overflow-x: auto; /* Scroll horizontal solo en móviles pequeños */
    }
    
    .table {
        min-width: 500px; /* Ancho mínimo reducido */
    }
    
    .btn {
        padding: 0.4rem 1rem;
        font-size: 0.9rem;
    }
}

/* Scroll suave */
html {
    scroll-behavior: smooth;
}

/* Estilos para cuando hay muchos datos */
.data-table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
}

.table-loading {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
}

/* Badges */
.badge {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-weight: 500;
}

/* Progress Bars */
.progress {
    height: 8px;
    border-radius: 4px;
}

.progress-bar {
    border-radius: 4px;
}

/* Toast Notifications */
.toast {
    border-radius: 8px;
    border: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.toast-header {
    border-radius: 8px 8px 0 0;
}

/* Login Page */
.login-body {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    margin: 0;
    padding: 0;
}

.login-left {
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(10px);
    position: relative;
}

.login-left::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(44, 62, 80, 0.5);
    z-index: -1;
}

/* Asegurar que el sidebar tenga z-index alto */
.sidebar {
    z-index: 1000;
}

/* Header fijo */
.header {
    z-index: 999;
    position: sticky;
    top: 0;
}

/* Responsive para móviles */
@media (max-width: 768px) {
    .login-left {
        display: none !important;
    }
}