/* ============================================
   RESET Y ESTILOS GENERALES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8fafc;
    color: #1e293b;
    line-height: 1.6;
}

/* ============================================
   MENÚ LATERAL (SIDEBAR)
   ============================================ */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background-color: #1e293b;
    color: white;
    padding: 0;
    box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    z-index: 1000;
    transition: transform 0.3s ease;
}

/* Botón hamburguesa para móvil */
.menu-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 2000;
    background-color: #2563eb;
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 8px;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.sidebar .logo {
    text-align: center;
    padding: 30px 20px;
    background-color: #0f172a;
    border-bottom: 2px solid #334155;
    margin-bottom: 10px;
}

.sidebar .logo h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    color: #f8fafc;
}

.sidebar .logo p {
    font-size: 12px;
    color: #94a3b8;
    margin: 0;
    font-weight: 400;
}

.sidebar .menu {
    list-style: none;
    padding: 10px 0;
}

.sidebar .menu li {
    margin: 3px 0;
}

.sidebar .menu li a {
    display: flex;
    align-items: center;
    padding: 16px 25px;
    color: #cbd5e1;
    text-decoration: none;
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
    font-size: 15px;
    font-weight: 500;
}

.sidebar .menu li a:hover {
    background-color: #334155;
    border-left-color: #2563eb;
    color: #f8fafc;
    padding-left: 30px;
}

.sidebar .menu li a.active {
    background-color: #2563eb;
    border-left-color: #2563eb;
    color: #ffffff;
    font-weight: 600;
}

.sidebar .menu li a .icon {
    font-size: 22px;
    margin-right: 15px;
    width: 30px;
    text-align: center;
}

.sidebar .menu li.logout {
    position: absolute;
    bottom: 20px;
    width: 100%;
}

.sidebar .menu li.logout a {
    color: #fca5a5;
    background-color: rgba(220, 38, 38, 0.1);
}

.sidebar .menu li.logout a:hover {
    background-color: rgba(220, 38, 38, 0.2);
    border-left-color: #dc2626;
    color: #fecaca;
}

/* ============================================
   CONTENIDO PRINCIPAL
   ============================================ */
.main-content {
    margin-left: 280px;
    min-height: 100vh;
    background-color: #f8fafc;
    transition: margin-left 0.3s ease;
}

/* Barra superior */
.topbar {
    background-color: #2563eb;
    padding: 20px 35px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left h1 {
    font-size: 26px;
    color: white;
    font-weight: 600;
}

.topbar-right .user-info {
    font-size: 14px;
    color: white;
    padding: 10px 20px;
    background-color: rgba(255,255,255,0.2);
    border-radius: 25px;
    font-weight: 500;
}

/* Contenido */
.content {
    padding: 35px;
}

/* ============================================
   CARDS
   ============================================ */
.card {
    background-color: white;
    border-radius: 12px;
    padding: 28px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 25px;
    border: 1px solid #e2e8f0;
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.card-header {
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 18px;
    margin-bottom: 25px;
}

.card-header h2 {
    font-size: 22px;
    color: #1e293b;
    font-weight: 600;
}

/* Grid de resumen */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 25px;
    margin-bottom: 35px;
}

.summary-card {
    background-color: #2563eb;
    color: white;
    padding: 28px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    transition: all 0.3s ease;
}

.summary-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
}

.summary-card.blue {
    background-color: #2563eb;
}

.summary-card.green {
    background-color: #16a34a;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}

.summary-card.green:hover {
    box-shadow: 0 8px 20px rgba(22, 163, 74, 0.4);
}

.summary-card.orange {
    background-color: #ea580c;
    box-shadow: 0 4px 12px rgba(234, 88, 12, 0.3);
}

.summary-card.orange:hover {
    box-shadow: 0 8px 20px rgba(234, 88, 12, 0.4);
}

.summary-card.red {
    background-color: #dc2626;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.summary-card.red:hover {
    box-shadow: 0 8px 20px rgba(220, 38, 38, 0.4);
}

.summary-card.purple {
    background-color: #9333ea;
    box-shadow: 0 4px 12px rgba(147, 51, 234, 0.3);
}

.summary-card.purple:hover {
    box-shadow: 0 8px 20px rgba(147, 51, 234, 0.4);
}

.summary-card.teal {
    background-color: #0891b2;
    box-shadow: 0 4px 12px rgba(8, 145, 178, 0.3);
}

.summary-card.teal:hover {
    box-shadow: 0 8px 20px rgba(8, 145, 178, 0.4);
}

.summary-card h3 {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
    opacity: 0.95;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-card .value {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.2;
    word-break: break-word;
}

.summary-card .label {
    font-size: 13px;
    opacity: 0.9;
}

/* ============================================
   BOTONES
   ============================================ */
.btn {
    display: inline-block;
    padding: 12px 28px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    text-align: center;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: #2563eb;
    color: white;
}

.btn-primary:hover {
    background-color: #1d4ed8;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-success {
    background-color: #16a34a;
    color: white;
}

.btn-success:hover {
    background-color: #15803d;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}

.btn-danger {
    background-color: #dc2626;
    color: white;
}

.btn-danger:hover {
    background-color: #b91c1c;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.btn-secondary {
    background-color: #64748b;
    color: white;
}

.btn-secondary:hover {
    background-color: #475569;
    box-shadow: 0 4px 12px rgba(100, 116, 139, 0.3);
}

.btn-warning {
    background-color: #ea580c;
    color: white;
}

.btn-warning:hover {
    background-color: #c2410c;
    box-shadow: 0 4px 12px rgba(234, 88, 12, 0.3);
}

.btn-info {
    background-color: #0891b2;
    color: white;
}

.btn-info:hover {
    background-color: #0e7490;
    box-shadow: 0 4px 12px rgba(8, 145, 178, 0.3);
}

/* ============================================
   TABLAS
   ============================================ */
.table-container {
    overflow-x: auto;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    position: relative;
}

/* Scroll horizontal solo dentro del contenedor */
.table-container::-webkit-scrollbar {
    height: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb {
    background-color: #2563eb;
    border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background-color: #1d4ed8;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background-color: white;
    min-width: 600px;
    margin-bottom: 0;
}

.table thead {
    background-color: #1e293b;
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.table th {
    padding: 16px 15px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    white-space: nowrap;
}

.table td {
    padding: 16px 15px;
    font-size: 14px;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

.table tbody tr:nth-child(odd) {
    background-color: #ffffff;
}

.table tbody tr:nth-child(even) {
    background-color: #f8fafc;
}

.table tbody tr:hover {
    background-color: #dbeafe;
    transition: background-color 0.2s ease;
}

.table tbody tr.pagado {
    background-color: #dcfce7 !important;
}

.table tbody tr.vencido {
    background-color: #fee2e2 !important;
}

.table tbody tr.pendiente {
    background-color: #ffedd5 !important;
}

.table tfoot {
    background-color: #334155;
    color: white;
    font-weight: 600;
}

.table tfoot td {
    padding: 16px 15px;
    border: none;
}

/* ============================================
   FORMULARIOS
   ============================================ */
.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #1e293b;
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
    background-color: white;
}

.form-control:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%232563eb' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
    padding-right: 40px;
}

/* ============================================
   ALERTAS Y MENSAJES
   ============================================ */
.alert {
    padding: 16px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.alert::before {
    margin-right: 12px;
    font-size: 20px;
}

.alert-success {
    background-color: #dcfce7;
    color: #166534;
    border-left: 4px solid #16a34a;
}

.alert-success::before {
    content: '✅';
}

.alert-danger {
    background-color: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #dc2626;
}

.alert-danger::before {
    content: '❌';
}

.messages .alert-danger,
.messages .error {
    background-color: #fee2e2 !important;
    color: #991b1b !important;
    border-left: 4px solid #dc2626 !important;
}

.alert-warning {
    background-color: #ffedd5;
    color: #9a3412;
    border-left: 4px solid #ea580c;
}

.alert-warning::before {
    content: '⚠️';
}

.alert-info {
    background-color: #cffafe;
    color: #164e63;
    border-left: 4px solid #0891b2;
}

.alert-info::before {
    content: 'ℹ️';
}

/* ============================================
   BADGES
   ============================================ */
.badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.badge-success {
    background-color: #16a34a;
    color: white;
}

.badge-danger {
    background-color: #dc2626;
    color: white;
}

.badge-warning {
    background-color: #ea580c;
    color: white;
}

.badge-info {
    background-color: #0891b2;
    color: white;
}

/* ============================================
   MODALES
   ============================================ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.75);
    z-index: 2000;
    animation: fadeIn 0.3s ease;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-overlay.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal {
    background-color: white;
    border-radius: 15px;
    width: 100%;
    max-width: 650px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s ease;
    margin: auto;
    position: relative;
}

.modal-header {
    padding: 22px 28px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header.crear {
    background-color: #16a34a;
}

.modal-header.editar {
    background-color: #ea580c;
}

.modal-header.eliminar {
    background-color: #dc2626;
}

.modal-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    word-break: break-word;
}

.modal-close {
    background-color: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 26px;
    cursor: pointer;
    line-height: 1;
    padding: 5px 10px;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: 8px;
    flex-shrink: 0;
}

.modal-close:hover {
    background-color: rgba(255,255,255,0.3);
    transform: rotate(90deg);
}

.modal-body {
    padding: 28px;
    max-height: calc(90vh - 160px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    padding: 20px 28px;
    background-color: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.modal-body::-webkit-scrollbar {
    width: 10px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb {
    background-color: #2563eb;
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background-color: #1d4ed8;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ============================================
   UTILIDADES
   ============================================ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.flex { display: flex; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-10 { gap: 10px; }

/* ============================================
   PREVENIR SCROLL HORIZONTAL EN TODO EL SITIO
   ============================================ */
html, body {
    overflow-x: hidden;
    max-width: 100%;
    position: relative;
}

body {
    transition: none;
}

body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Los cards y content con tablas SÍ pueden hacer scroll */
.main-content {
    overflow-x: hidden;
}

.card {
    overflow: visible;
}

.content {
    overflow: visible;
}

/* ============================================
   SCROLL MEJORADO PARA TABLAS
   ============================================ */
@media (max-width: 768px) {
    .table-container::-webkit-scrollbar {
        height: 12px !important;
        display: block !important;
    }
    
    .table-container::-webkit-scrollbar-track {
        background: #dbeafe !important;
        border-radius: 10px !important;
    }
    
    .table-container::-webkit-scrollbar-thumb {
        background-color: #2563eb !important;
        border-radius: 10px !important;
        border: 2px solid #dbeafe !important;
    }
    
    .table-container::-webkit-scrollbar-thumb:hover {
        background-color: #1d4ed8 !important;
    }
}

/* ============================================
   OCULTAR TEXTO EN BOTONES (SOLO MÓVIL)
   ============================================ */
@media (max-width: 768px) {
    /* Ocultar texto de botones en tablas, dejar solo íconos */
    .table .btn {
        padding: 8px 10px !important;
        font-size: 16px !important;
        min-width: auto !important;
        width: auto !important;
    }
    
    /* Ocultar texto, mostrar solo emoji */
    .table .btn-text {
        display: none;
    }
}

/* ============================================
   ESTILOS PARA TFOOT (PIE DE TABLA)
   ============================================ */
.table tfoot td {
    padding: 16px 15px;
    border: none;
    color: #1e293b; /* ✅ Texto oscuro para mejor legibilidad */
}

.table tfoot strong {
    color: #1e293b; /* ✅ Asegurar que los strong también sean oscuros */
}

/* Mantener colores específicos para montos positivos/negativos */
.table tfoot td span[style*="color: #16a34a"],
.table tfoot td strong[style*="color: #16a34a"] {
    color: #16a34a !important; /* Verde para positivos */
}

.table tfoot td span[style*="color: #dc2626"],
.table tfoot td strong[style*="color: #dc2626"] {
    color: #dc2626 !important; /* Rojo para negativos */
}

/* ============================================
   RESPONSIVE - TABLET (max-width: 1024px)
   ============================================ */
@media (max-width: 1024px) {
    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .topbar-left h1 {
        font-size: 20px;
    }
    
    .card {
        padding: 20px;
    }
    
    .content {
        padding: 25px;
    }
}

/* ============================================
   RESPONSIVE - MÓVIL (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
    /* Mostrar botón hamburguesa */
    .menu-toggle {
        display: block;
    }
    
    /* Ocultar sidebar por defecto en móvil */
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    /* Ajustar contenido sin margen izquierdo */
    .main-content {
        margin-left: 0;
    }
    
    /* Topbar ajustado */
    .topbar {
        padding: 15px 20px;
        padding-left: 70px;
    }
    
    .topbar-left h1 {
        font-size: 18px;
    }
    
    .topbar-right .user-info {
        font-size: 12px;
        padding: 8px 12px;
    }
    
    /* Contenido */
    .content {
        padding: 15px;
    }
    
    /* Cards */
    .card {
        padding: 18px;
        margin-bottom: 15px;
    }
    
    .card-header h2 {
        font-size: 18px;
    }
    
    /* Grid de una columna */
    .summary-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .summary-card {
        padding: 20px;
    }
    
    .summary-card .value {
        font-size: 22px;
    }
    
    /* Botones más pequeños */
    .btn {
        padding: 10px 18px;
        font-size: 13px;
        width: 100%;
        margin-bottom: 8px;
    }
    
    /* Flex responsive */
    .flex {
        flex-direction: column;
        align-items: stretch !important;
    }
    
    .flex.gap-10 {
        gap: 10px;
    }
    
    /* Tabla responsive */
    .table {
        font-size: 12px;
    }
    
    .table th,
    .table td {
        padding: 10px 8px;
    }
    
    /* Modal más pequeño */
    .modal {
        width: 95%;
        max-height: 95vh;
    }
    
    .modal-header h2 {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-footer {
        padding: 15px;
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
    }
    
    /* Form controls */
    .form-control {
        font-size: 16px;
    }
    
    /* Ocultar texto largo en móvil */
    .hide-mobile {
        display: none;
    }
}

/* ============================================
   RESPONSIVE - MÓVIL PEQUEÑO (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    .topbar-left h1 {
        font-size: 16px;
    }
    
    .topbar-right .user-info {
        font-size: 11px;
        padding: 6px 10px;
    }
    
    .summary-card h3 {
        font-size: 12px;
    }
    
    .summary-card .value {
        font-size: 20px;
    }
    
    .summary-card .label {
        font-size: 11px;
    }
    
    .card-header h2 {
        font-size: 16px;
    }
    
    .table {
        font-size: 11px;
    }
    
    .table th,
    .table td {
        padding: 8px 6px;
    }
    
    .badge {
        font-size: 10px;
        padding: 4px 10px;
    }
}

/* ============================================
   LANDSCAPE MÓVIL
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .modal {
        max-height: 95vh;
    }
    
    .modal-body {
        max-height: calc(95vh - 140px);
    }
}