@font-face {
    font-family: 'Inter';
    src: url('fonts/Inter-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Inter';
    src: url('fonts/Inter-Medium.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Inter';
    src: url('fonts/Inter-SemiBold.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Inter';
    src: url('fonts/Inter-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --bg-color: #f8fafc;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --card-bg: #ffffff;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    padding: 1rem;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
    padding-top: 1rem;
}

.header-actions {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

#user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: white;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

#user-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.btn-share {
    padding: 0.5rem 0.75rem;
    background: var(--success-bg);
    color: var(--success);
    border: none;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    margin-right: 0.5rem;
}

.logo h1 {
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.05em;
    margin-bottom: 0.25rem;
}

.logo p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    font-weight: 500;
}

/* Nav styles */
nav {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 2rem;
    background: #eef2ff;
    padding: 0.5rem;
    border-radius: 1rem;
}

.nav-link {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 1.1rem;
    padding: 1rem 0.5rem;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
}

.nav-link.active {
    background-color: var(--card-bg);
    color: var(--primary);
    box-shadow: var(--shadow);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.card {
    background: var(--card-bg);
    border-radius: 1.25rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.form-group {
    margin-bottom: 1.5rem;
    position: relative;
}

label {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.625rem;
    color: var(--text-primary);
}

input {
    width: 100%;
    padding: 0.875rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    background: #fdfdfd;
    font-size: 1rem;
    transition: all 0.2s;
    appearance: none;
    font-family: inherit;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

.input-action-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Custom Select */
.custom-select {
    position: relative;
    flex: 1;
}

.select-selected {
    background-color: #fdfdfd;
    padding: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    cursor: pointer;
    font-size: 1rem;
    user-select: none;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.select-selected:after {
    content: "▼";
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.select-selected.select-arrow-active:after {
    content: "▲";
}

.select-selected:focus, .select-selected.active {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

.select-items {
    position: absolute;
    background-color: white;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 99;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    margin-top: 0.25rem;
    box-shadow: var(--shadow-md);
    max-height: 200px;
    overflow-y: auto;
}

.select-items div {
    color: var(--text-primary);
    padding: 0.875rem;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--border-color);
}

.select-items div:last-child {
    border-bottom: none;
}

.select-items div:hover, .same-as-selected {
    background-color: #f1f5f9;
}

/* Segmented Control */
.segmented-control {
    display: flex;
    background-color: #f1f5f9;
    border-radius: 0.75rem;
    padding: 0.25rem;
    gap: 0.25rem;
}

.segment-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.segment-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: var(--shadow);
}

.segment-btn[data-value="income"].active {
    color: var(--success);
}

.segment-btn[data-value="expense"].active {
    color: var(--danger);
}

.grid-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.btn-primary {
    width: 100%;
    padding: 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.75rem;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    font-family: inherit;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    padding: 0.875rem 1rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: inherit;
}

.balance-display {
    margin-top: 0.75rem;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--primary);
    text-align: right;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.table-responsive {
    overflow-x: auto;
    margin: 0 -1.5rem;
    padding: 0 1.5rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 1rem;
}

.text-right { text-align: right; }

tr.income { color: #065f46; background-color: var(--success-bg); }
tr.expense { color: #991b1b; background-color: var(--danger-bg); }
.hidden { display: none !important; }

.btn-delete {
    padding: 0.5rem 0.75rem;
    background: var(--danger-bg);
    color: var(--danger);
    border: none;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1.5rem;
}

.modal {
    background: white;
    border-radius: 1.25rem;
    width: 100%;
    max-width: 450px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    font-family: inherit;
}

.modal-body {
    padding: 1.5rem;
}

#modal-content {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 1rem;
}

.modal-footer {
    padding: 1rem 1.5rem 1.5rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.modal-footer button {
    width: auto;
    padding: 0.75rem 1.5rem;
}

/* Responsive Tables for Mobile */
@media (max-width: 639px) {
    #entries-table, #entries-table thead, #entries-table tbody, #entries-table th, #entries-table td, #entries-table tr {
        display: block;
    }
    
    #entries-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    #entries-table tr {
        border: 1px solid var(--border-color);
        border-radius: 0.75rem;
        margin-bottom: 1rem;
        padding: 0.5rem;
        background: white;
    }
    
    #entries-table td {
        border: none;
        border-bottom: 1px solid #f1f5f9;
        position: relative;
        padding: 0.75rem 1rem 0.75rem 40%;
        text-align: right;
    }

    #entries-table td:last-child {
        border-bottom: none;
    }
    
    #entries-table td:before {
        position: absolute;
        top: 0.75rem;
        left: 1rem;
        width: 35%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        font-size: 0.875rem;
        color: var(--text-secondary);
    }
    
    #entries-table td:nth-of-type(1):before { content: "Descripción"; }
    #entries-table td:nth-of-type(2):before { content: "Tipo"; }
    #entries-table td:nth-of-type(3):before { content: "Monto"; }
    #entries-table td:nth-of-type(4):before { content: "Acción"; }
    
    .backup-actions {
        flex-direction: column;
    }
}

/* Tablet and Desktop adjustments */
@media (min-width: 640px) {
    body {
        padding: 2rem;
    }
    
    .card {
        padding: 2.5rem;
    }
    
    .grid-form {
        display: grid;
        grid-template-columns: 2fr 1fr;
    }
    
    .nav-link {
        padding: 1rem 2rem;
        flex: initial;
        min-width: 160px;
    }
}