/* Reset y base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-900: #111827;
    --border-radius: 8px;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--gray-900);
    background-color: var(--gray-50);
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
}

.login-box h1 {
    text-align: center;
    margin-bottom: 10px;
    color: var(--gray-900);
    font-size: 28px;
}

.subtitle {
    text-align: center;
    color: var(--gray-600);
    margin-bottom: 30px;
}

.login-info {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--gray-200);
    text-align: center;
    color: var(--gray-600);
}

/* Navbar */
.navbar {
    background: white;
    box-shadow: var(--shadow);
    padding: 15px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar h1 {
    font-size: 20px;
    color: var(--gray-900);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-user span {
    color: var(--gray-600);
    font-weight: 500;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
    overflow-x: hidden;
}

/* Dashboard Summary */
.dashboard-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.summary-card {
    background: white;
    padding: 20px 15px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
    overflow: hidden;
    min-width: 0;
}

.summary-card h3 {
    font-size: 13px;
    color: var(--gray-600);
    margin-bottom: 10px;
    text-transform: uppercase;
    font-weight: 600;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.summary-card .amount {
    font-size: 20px;
    font-weight: bold;
    color: var(--primary-color);
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.3;
    padding: 0 5px;
}

.summary-card .amount.positive {
    color: var(--success-color);
}

.summary-card .amount.negative {
    color: var(--danger-color);
}

.summary-card .amount.warning {
    color: var(--warning-color);
}

.summary-card .card-detail {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--gray-500);
    font-weight: 500;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    background: white;
    padding: 10px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.tab-btn {
    padding: 10px 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    border-radius: var(--border-radius);
    transition: all 0.3s;
    white-space: nowrap;
}

.tab-btn:hover {
    background: var(--gray-100);
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
}

.tab-content {
    display: none;
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.tab-content.active {
    display: block;
}

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 20px;
    color: var(--gray-900);
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--gray-700);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 14px;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
    display: inline-block;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
    display: block;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    min-width: 600px;
}

table th,
table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
    font-size: 13px;
    text-transform: uppercase;
}

table tbody tr:hover {
    background: var(--gray-50);
}

table tbody tr:last-child td {
    border-bottom: none;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fed7aa;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

/* Modal Styles */
.modal {
    display: none; /* Oculto por defecto */
    position: fixed; /* Se queda en su lugar incluso si se hace scroll */
    z-index: 1000; /* Se muestra por encima de todo */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto; /* Permite scroll si el contenido es muy grande */
    background-color: rgba(0, 0, 0, 0.6); /* Fondo negro semitransparente */
    padding-top: 60px;
}

.modal-content {
    background-color: #fff;
    margin: 5% auto;
    padding: 25px;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    border-radius: 10px;
    position: relative;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    animation: fadeInModal 0.3s;
}

@keyframes fadeInModal {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.close {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

#modalTitle {
    margin-top: 0;
    color: #333;
    font-size: 1.5rem;
    margin-bottom: 20px;
}

/* Messages */
.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 10px;
    border-radius: var(--border-radius);
    margin-top: 10px;
    font-size: 14px;
}

.success-message {
    background: #d1fae5;
    color: #065f46;
    padding: 10px;
    border-radius: var(--border-radius);
    margin-top: 10px;
    font-size: 14px;
}

/* Action buttons in tables */
.action-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--gray-600);
}

/* Responsive */
@media (max-width: 768px) {
    .navbar h1 {
        font-size: 14px;
    }

    .nav-user span {
        display: none;
    }

    .dashboard-summary {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .summary-card {
        padding: 12px;
    }

    .summary-card .amount {
        font-size: 18px;
    }

    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 3px;
        padding: 8px;
    }

    .tab-btn {
        padding: 8px 12px;
        font-size: 12px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .section-header h2 {
        font-size: 16px;
    }

    .section-header .btn {
        width: 100%;
    }

    table {
        font-size: 12px;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table th,
    table td {
        padding: 6px 8px;
        white-space: nowrap;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
    }

    .modal-content {
        padding: 20px;
        margin: 10px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .login-box {
        padding: 25px 15px;
    }

    .login-box h1 {
        font-size: 22px;
    }

    .charts-section {
        grid-template-columns: 1fr;
    }

    .chart-container {
        padding: 15px;
    }

    .fondos-usuarios-section {
        padding: 15px;
    }

    .fondos-usuarios-grid {
        grid-template-columns: 1fr;
    }

    .filter-bar {
        flex-direction: column;
    }

    .filter-input {
        max-width: 100%;
        width: 100%;
    }

    .mi-fondo-card {
        padding: 15px;
    }

    .mi-fondo-amount {
        font-size: 28px;
    }

    .mi-fondo-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat-item {
        padding: 8px;
    }

    .stat-label {
        font-size: 10px;
    }

    .stat-value {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .dashboard-summary {
        grid-template-columns: 1fr;
    }

    .container {
        padding: 10px;
    }

    .tab-content {
        padding: 12px;
    }

    .navbar h1 {
        font-size: 13px;
    }

    .tab-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .mi-fondo-header h2 {
        font-size: 14px;
    }

    .mi-fondo-amount {
        font-size: 24px;
    }

    .summary-card h3 {
        font-size: 11px;
    }

    .summary-card .amount {
        font-size: 16px;
    }
    
    .card-icon {
        font-size: 18px;
    }
}

/* Loading spinner */
.spinner {
    border: 3px solid var(--gray-200);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Summary Card Icons */
.summary-card {
    position: relative;
    transition: transform 0.3s, box-shadow 0.3s;
}

.summary-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.summary-card.highlight {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.summary-card.highlight h3 {
    color: rgba(255,255,255,0.9);
}

.summary-card.highlight .amount {
    color: white;
}

.card-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.summary-card .amount.info {
    color: var(--primary-color);
}

/* Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.chart-container {
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.chart-container h3 {
    margin-bottom: 15px;
    font-size: 16px;
    color: var(--gray-700);
}

.chart-container canvas {
    max-height: 250px;
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.filter-input {
    padding: 10px 15px;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 14px;
    min-width: 150px;
    flex: 1;
    max-width: 250px;
}

.filter-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Modern Table */
.table-modern {
    border-collapse: separate;
    border-spacing: 0;
}

.table-modern thead th {
    background: linear-gradient(135deg, var(--gray-100) 0%, var(--gray-50) 100%);
    position: sticky;
    top: 0;
    z-index: 10;
}

.table-modern tbody tr {
    transition: background 0.2s;
}

.table-modern tbody tr:hover {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
}

.table-modern tbody tr td:first-child {
    font-weight: 600;
    color: var(--primary-color);
}

/* Row animations */
.table-modern tbody tr {
    animation: fadeInRow 0.3s ease-in;
}

@keyframes fadeInRow {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Monto styling */
.monto-positive {
    color: var(--success-color);
    font-weight: 600;
}

.monto-negative {
    color: var(--danger-color);
    font-weight: 600;
}

/* Badge improvements */
.badge {
    animation: pulse 2s infinite;
}

.badge-warning {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.pagination button {
    padding: 8px 14px;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.pagination button:hover {
    background: var(--gray-100);
}

.pagination button.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Secondary button */
.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: var(--border-radius);
    color: white;
    font-weight: 500;
    z-index: 2000;
    animation: slideIn 0.3s ease-out;
    box-shadow: var(--shadow-lg);
}

.toast-success {
    background: var(--success-color);
}

.toast-error {
    background: var(--danger-color);
}

.toast-info {
    background: var(--primary-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Empty state improvement */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 60px 20px;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.empty-state-text {
    color: var(--gray-600);
    font-size: 16px;
}

/* Fondos por Usuario Section */
.fondos-usuarios-section {
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

.fondos-usuarios-section h3 {
    margin-bottom: 15px;
    font-size: 18px;
    color: var(--gray-700);
}

.fondos-usuarios-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
}

.usuario-fondo-card {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border-radius: var(--border-radius);
    padding: 15px;
    border-left: 4px solid var(--primary-color);
    transition: transform 0.2s, box-shadow 0.2s;
}

.usuario-fondo-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.usuario-fondo-card.admin {
    border-left-color: #8b5cf6;
    background: linear-gradient(135deg, #faf5ff 0%, #ede9fe 100%);
}

.usuario-fondo-card.operador {
    border-left-color: var(--success-color);
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
}

.usuario-fondo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.usuario-fondo-header h4 {
    font-size: 16px;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 8px;
}

.usuario-fondo-header .role-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--primary-color);
    color: white;
}

.usuario-fondo-header .role-badge.admin {
    background: #8b5cf6;
}

.usuario-fondo-header .role-badge.operador {
    background: var(--success-color);
}

.usuario-fondo-amount {
    font-size: 24px;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.usuario-fondo-amount.negative {
    color: var(--danger-color);
}

.usuario-fondo-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 12px;
    color: var(--gray-600);
}

.usuario-fondo-detail {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
    background: rgba(255,255,255,0.6);
    border-radius: 4px;
}

.usuario-fondo-detail.full-width {
    grid-column: span 2;
}

.detail-label {
    color: var(--gray-600);
}

.detail-value {
    font-weight: 600;
    color: var(--gray-900);
}

.detail-value.positive {
    color: var(--success-color);
}

.detail-value.negative {
    color: var(--danger-color);
}

/* Mi Fondo Card (Operador) */
.mi-fondo-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    margin-bottom: 30px;
}

.mi-fondo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.mi-fondo-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.fondo-badge {
    background: rgba(255,255,255,0.2);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
}

.mi-fondo-amount {
    font-size: 42px;
    font-weight: bold;
    margin-bottom: 20px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.mi-fondo-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.stat-item {
    background: rgba(255,255,255,0.15);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 12px;
    opacity: 0.9;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 16px;
    font-weight: 600;
}

.stat-value.positive {
    color: #86efac;
}

.stat-value.negative {
    color: #fca5a5;
}

/* Footer */
.footer {
    text-align: center;
    padding: 20px;
    color: var(--gray-600);
    font-size: 14px;
    margin-top: 40px;
    border-top: 1px solid var(--gray-200);
    background: white;
}

.login-page .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.8);
    border-top: none;
    margin-top: 0;
}

.login-page .footer strong {
    color: white;
}
