* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f7fa;
    min-height: 100vh;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

body.loaded {
    opacity: 1;
}

.navbar {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    color: white;
    padding: 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 3px solid #d4a017;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-logo {
    height: 40px;
    width: auto;
}

.nav-title {
    font-size: 1.4em;
    font-weight: 700;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.user-email {
    font-size: 0.95em;
    opacity: 0.95;
}

.btn-logout {
    padding: 8px 20px;
    background: #d4a017;
    color: #1a1a1a;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.3s;
}

.btn-logout:hover {
    background: #e5b429;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(212, 160, 23, 0.4);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 30px 20px;
}

.saldo-card {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    color: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    margin-bottom: 30px;
    text-align: center;
    border: 3px solid #d4a017;
}

.saldo-header h2 {
    font-size: 1.5em;
    margin-bottom: 10px;
}

.saldo-update {
    opacity: 0.9;
    font-size: 0.9em;
}

.saldo-amount {
    font-size: 3.5em;
    font-weight: 700;
    margin-top: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: all 0.3s;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.stat-card.ingreso {
    border-left: 5px solid #28a745;
}

.stat-card.egreso {
    border-left: 5px solid #dc3545;
}

.stat-card.total {
    border-left: 5px solid #d4a017;
}

.stat-icon {
    font-size: 2.5em;
    width: 70px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.stat-card.ingreso .stat-icon {
    background: #d4edda;
    color: #28a745;
}

.stat-card.egreso .stat-icon {
    background: #f8d7da;
    color: #dc3545;
}

.stat-card.total .stat-icon {
    background: #fff3cd;
    color: #d4a017;
}

.stat-label {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 5px;
}

.stat-value {
    color: #333;
    font-size: 1.8em;
    font-weight: 700;
}

.form-card, .filters-card, .table-card {
    background: white;
    padding: 35px;
    border-radius: 20px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
    margin-bottom: 30px;
    max-width: 100%;
    overflow: hidden;
    border: 1px solid #f0f0f0;
}

.form-card h2 {
    color: #1a1a1a;
    margin-bottom: 30px;
    font-size: 1.6em;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}

.form-card h2 i {
    color: #d4a017;
    font-size: 0.9em;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 25px;
    margin-bottom: 25px;
    max-width: 100%;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-weight: 600;
    color: #2d2d2d;
    margin-bottom: 10px;
    font-size: 0.95em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group label i {
    color: #d4a017;
    font-size: 0.9em;
}

.form-group label::after {
    content: '';
}

label:has(+ .tipo-buttons)::after,
label[for="monto"]::after,
label[for="motivo"]::after,
label:has(+ .foto-buttons)::after {
    content: '*';
    color: #f44336;
    margin-left: 4px;
    font-weight: 700;
    font-size: 1.1em;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 14px 16px;
    border: 2px solid #e5e5e5;
    border-radius: 12px;
    font-size: 1em;
    font-family: inherit;
    transition: all 0.3s ease;
    background: #fafafa;
    width: 100%;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #d4a017;
    background: white;
    box-shadow: 0 0 0 4px rgba(212, 160, 23, 0.1);
    transform: translateY(-1px);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.tipo-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.tipo-btn {
    padding: 18px 24px;
    border: 2px solid #e5e5e5;
    background: #fafafa;
    border-radius: 12px;
    font-size: 1.05em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.tipo-btn:hover {
    border-color: #d4a017;
    background: white;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(212, 160, 23, 0.15);
}

.tipo-btn.active {
    color: white;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

.tipo-btn[data-tipo="ingreso"].active {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    border-color: #4CAF50;
}

.tipo-btn[data-tipo="egreso"].active {
    background: linear-gradient(135deg, #f44336 0%, #da190b 100%);
    border-color: #f44336;
}

.tipo-btn i {
    font-size: 1.3em;
}

@keyframes shake-error {
    0%, 100% { 
        border-color: #f44336;
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

@keyframes pulse-error {
    0%, 100% {
        border-color: #f44336;
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.7);
    }
    50% {
        border-color: #d32f2f;
        box-shadow: 0 0 0 8px rgba(244, 67, 54, 0);
    }
}

.campo-error {
    animation: shake-error 0.5s, pulse-error 1.5s;
    border-color: #f44336 !important;
}

.campo-error-foto {
    animation: pulse-error 1.5s;
    border-color: #f44336 !important;
}

.foto-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.btn-foto {
    padding: 18px 24px;
    border: 2px solid #e5e5e5;
    background: #fafafa;
    border-radius: 12px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-foto:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.btn-foto:active {
    transform: translateY(-1px);
}

.btn-camara {
    border-color: #2196F3;
    color: #2196F3;
}

.btn-camara:hover {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    color: white;
    border-color: #2196F3;
}

.btn-galeria {
    border-color: #9C27B0;
    color: #9C27B0;
}

.btn-galeria:hover {
    background: linear-gradient(135deg, #9C27B0 0%, #7B1FA2 100%);
    color: white;
    border-color: #9C27B0;
}

.btn-foto i {
    font-size: 1.2em;
}

#foto-preview {
    margin-top: 15px;
    padding: 20px;
    background: linear-gradient(135deg, #fffbf0 0%, #fff9e6 100%);
    border-radius: 12px;
    border: 2px dashed #d4a017;
    width: 100%;
    max-width: 500px;
    height: auto;
    max-height: 450px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    overflow: hidden;
    box-sizing: border-box;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 0 4px 15px rgba(212, 160, 23, 0.1);
}

#foto-preview img {
    width: 100%;
    height: auto;
    max-height: 350px;
    object-fit: contain;
    border-radius: 10px;
    display: block;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.preview-filename {
    font-size: 0.9em;
    color: #666;
    text-align: center;
    margin: 0;
    padding: 8px 12px;
    background: white;
    border-radius: 8px;
    word-break: break-word;
    max-width: 100%;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.form-actions {
    display: flex;
    gap: 15px;
    margin-top: 30px;
}

.btn {
    padding: 16px 32px;
    border: none;
    border-radius: 12px;
    font-size: 1.05em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-primary {
    background: linear-gradient(135deg, #d4a017 0%, #b8860b 100%);
    color: white;
    flex: 1;
    box-shadow: 0 4px 15px rgba(212, 160, 23, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(212, 160, 23, 0.4);
    background: linear-gradient(135deg, #e5b429 0%, #d4a017 100%);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-primary i {
    font-size: 1.1em;
}

.filters-card {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.search-input,
.filter-select {
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1em;
    flex: 1;
    min-width: 200px;
}

.search-input:focus,
.filter-select:focus {
    outline: none;
    border-color: #d4a017;
    box-shadow: 0 0 0 3px rgba(212, 160, 23, 0.1);
}

.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    color: white;
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
}

tbody tr {
    border-bottom: 1px solid #e0e0e0;
    transition: all 0.2s;
}

tbody tr:hover {
    background: #fffbf0;
    transform: scale(1.01);
    box-shadow: 0 2px 8px rgba(212, 160, 23, 0.2);
}

tbody tr.transferencia-row:hover {
    cursor: pointer;
}

td {
    padding: 15px;
    color: #333;
}

.badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
}

.badge-ingreso {
    background: #d4edda;
    color: #155724;
}

.badge-egreso {
    background: #f8d7da;
    color: #721c24;
}

.monto-ingreso {
    color: #28a745;
    font-weight: 700;
}

.monto-egreso {
    color: #dc3545;
    font-weight: 700;
}

.foto-link {
    color: #d4a017;
    text-decoration: none;
    font-weight: 600;
}

.foto-link:hover {
    text-decoration: underline;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #d4a017;
    font-size: 1.2em;
    font-weight: 600;
}

.message {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

@media (max-width: 768px) {
    .nav-container {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }

    .nav-user {
        width: 100%;
        justify-content: center;
        flex-direction: column;
        gap: 10px;
    }

    .saldo-amount {
        font-size: 2.5em;
    }

    .form-card, .filters-card, .table-card {
        padding: 25px 20px;
        border-radius: 16px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .tipo-buttons {
        grid-template-columns: 1fr;
    }

    .foto-buttons {
        grid-template-columns: 1fr;
    }

    .btn-foto {
        padding: 16px 20px;
    }

    #foto-preview {
        padding: 15px;
        max-width: 100%;
    }

    .form-actions {
        margin-top: 25px;
    }

    .btn-primary {
        padding: 14px 24px;
        font-size: 1em;
    }

    table {
        font-size: 0.9em;
    }

    th, td {
        padding: 10px;
    }
    
    .confirm-content {
        margin: 30% auto;
        width: 95%;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 20px 15px;
    }

    .saldo-card {
        padding: 25px 20px;
    }

    .saldo-amount {
        font-size: 2em;
    }

    .stat-icon {
        font-size: 2em;
    }

    .stat-value {
        font-size: 1.4em;
    }

    .form-card h2 {
        font-size: 1.3em;
    }

    .form-group label {
        font-size: 0.9em;
    }

    .tipo-btn {
        padding: 14px 18px;
        font-size: 0.95em;
    }

    .btn-foto {
        padding: 14px 18px;
        font-size: 0.95em;
    }

    #foto-preview {
        width: 90%;
        height: auto;
    }
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    animation: fadeIn 0.3s;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 15px;
    width: 90%;
    max-width: 800px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-close {
    color: #aaa;
    float: right;
    font-size: 32px;
    font-weight: bold;
    padding: 15px 25px;
    cursor: pointer;
    transition: color 0.3s;
}

.modal-close:hover {
    color: #d4a017;
}

#modal-title {
    padding: 25px 30px 15px;
    margin: 0;
    color: #1a1a1a;
    font-size: 1.5em;
    border-bottom: 3px solid #d4a017;
}

.modal-body {
    padding: 30px;
}

.detalle-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 25px;
}

.detalle-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.detalle-item.full {
    grid-column: 1 / -1;
}

.detalle-item label {
    font-weight: 600;
    color: #666;
    font-size: 0.9em;
}

.detalle-item span {
    font-size: 1.1em;
    color: #1a1a1a;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
}

.modal-foto {
    margin-top: 25px;
    max-width: 100%;
    overflow: hidden;
}

.modal-foto label {
    display: block;
    font-weight: 600;
    color: #666;
    font-size: 0.9em;
    margin-bottom: 15px;
}

.modal-foto img {
    width: 100%;
    max-width: 100%;
    max-height: 500px;
    height: auto;
    object-fit: contain;
    border-radius: 10px;
    border: 2px solid #e0e0e0;
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Modal de confirmación personalizado */
.confirm-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.2s;
}

.confirm-content {
    background-color: white;
    margin: 20% auto;
    padding: 0;
    border-radius: 15px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s;
}

.confirm-header {
    padding: 20px 25px;
    background: linear-gradient(135deg, #d4a017 0%, #b8860b 100%);
    border-radius: 15px 15px 0 0;
    color: white;
}

.confirm-header h3 {
    margin: 0;
    font-size: 1.3em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.confirm-body {
    padding: 25px;
    font-size: 1.05em;
    color: #333;
    line-height: 1.5;
}

.confirm-footer {
    padding: 15px 25px 25px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.confirm-btn {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.confirm-btn-cancel {
    background: #e0e0e0;
    color: #333;
}

.confirm-btn-cancel:hover {
    background: #d0d0d0;
}

.confirm-btn-yes {
    background: #d4a017;
    color: white;
}

.confirm-btn-yes:hover {
    background: #b8860b;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(212, 160, 23, 0.4);
}

/* Controles para prevenir desbordamiento de imágenes */
img {
    max-width: 100%;
    height: auto;
}

.container {
    max-width: 100%;
    overflow-x: hidden;
}

/* Asegurar que todas las cards contengan el contenido */
.card, .form-card, .filters-card, .table-card, .stat-card {
    overflow: hidden;
    word-wrap: break-word;
}

/* Controlar imágenes en el modal */
.modal-content {
    max-width: 95vw;
    max-height: 95vh;
    overflow-y: auto;
}

/* Preview de foto responsive */
#foto-preview {
    width: 90%;
    height: auto;
    box-sizing: border-box;
}

#preview-img {
    max-width: 100%;
    width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: cover;
}

/* Ajuste para formulario */
.form-group.full-width {
    display: block;
}

#card-ingresos, #card-egresos {
    cursor: pointer;
}

.btn-icon {
    background: none;
    border: none;
    color: #d4a017;
    font-size: 1.2em;
    cursor: pointer;
    padding: 5px;
    transition: transform 0.2s;
}

.btn-icon:hover {
    transform: scale(1.2);
    color: #e5b429;
}
