:root {
    --primary: #2c3e50;
    --secondary: #34495e;
    --accent1: #3498db;    /* Inversiones - Azul */
    --accent2: #e74c3c;    /* Gastos - Rojo */
    --accent3: #2ecc71;    /* Fondo seguridad - Verde */
    --accent4: #f39c12;    /* Disfrute - Naranja */
    --light: #ecf0f1;
    --dark: #2c3e50;
    --gray: #95a5a6;
    --border: #bdc3c7;
    --background: #f8f9fa;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    min-height: 100vh;
    color: var(--dark);
    line-height: 1.5;
    font-size: 14px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
}

/* Header Styles */
.header {
    background: white;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.header h1 {
    color: var(--primary);
    margin-bottom: 8px;
    font-size: 1.4rem;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    color: var(--gray);
    font-size: 0.85rem;
}

.user-info > div {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Dashboard Layout */
.dashboard {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 15px;
    margin-bottom: 15px;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Card Styles */
.card {
    background: white;
    border-radius: 8px;
    padding: 18px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.card h2 {
    color: var(--primary);
    margin-bottom: 15px;
    font-size: 1.1rem;
    font-weight: 600;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* Form Styles */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 10px;
    align-items: end;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--dark);
    font-size: 0.8rem;
}

.form-control {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.2s ease;
    background: white;
    width: 100%;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

/* Button Styles */
.btn {
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: white;
    color: var(--dark);
    text-align: center;
    min-height: 44px; /* Minimum touch target size */
}

.btn:hover {
    background: var(--light);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--secondary);
    border-color: var(--secondary);
}

.btn-danger {
    background: #e74c3c;
    color: white;
    border-color: #e74c3c;
}

.btn-danger:hover {
    background: #c0392b;
    border-color: #c0392b;
}

.btn-success {
    background: #27ae60;
    color: white;
    border-color: #27ae60;
}

.btn-success:hover {
    background: #229954;
    border-color: #229954;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 0.8rem;
    min-height: 36px;
}

/* Table Styles */
.table-responsive {
    overflow-x: auto;
    border-radius: 6px;
    border: 1px solid var(--border);
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 0.8rem;
    min-width: 600px; /* Minimum table width for small screens */
}

.table th {
    background: var(--light);
    color: var(--dark);
    font-weight: 600;
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover {
    background: rgba(52, 152, 219, 0.05);
}

/* Chart Container */
.chart-container {
    background: white;
    border-radius: 8px;
    padding: 15px;
    height: 250px;
    position: relative;
    border: 1px solid var(--border);
}

/* Categories Grid */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.category-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    transition: border-color 0.2s ease;
}

.category-card:hover {
    border-color: var(--primary);
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.category-name {
    font-weight: 600;
    color: var(--dark);
    font-size: 0.85rem;
}

.category-amount {
    font-weight: 700;
    color: var(--dark);
    font-size: 0.85rem;
}

.category-input-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.category-input-group input {
    flex: 1;
    min-width: 0; /* Allow input to shrink */
}

/* Modal Styles */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 15px;
}

.modal-backdrop.show {
    display: flex;
}

.modal {
    background: white;
    border-radius: 8px;
    padding: 20px;
    width: 100%;
    max-width: 450px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
}

.modal h3 {
    margin-bottom: 15px;
    color: var(--primary);
    font-size: 1.1rem;
}

/* Toast Styles */
.toast {
    background: var(--dark);
    color: white;
    padding: 12px 16px;
    border-radius: 6px;
    margin-top: 8px;
    font-size: 0.85rem;
    animation: toastSlideIn 0.3s ease;
    max-width: 300px;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Payroll Selector */
.payroll-selector {
    margin-bottom: 15px;
}

.selector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 10px;
}

.selector-header h3 {
    color: var(--primary);
    margin: 0;
    font-size: 1rem;
}

/* Recent Withdrawals */
.withdrawal-item {
    padding: 10px;
    border-left: 3px solid var(--primary);
    background: var(--light);
    margin-bottom: 8px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.withdrawal-category {
    font-weight: 600;
    color: var(--dark);
}

.withdrawal-amount {
    font-weight: 700;
    color: var(--dark);
}

.withdrawal-desc {
    color: var(--gray);
    font-size: 0.75rem;
    margin-top: 2px;
}

/* Color coding for categories */
.category-inversiones { border-left-color: var(--accent1); }
.category-gastos { border-left-color: var(--accent2); }
.category-fondo { border-left-color: var(--accent3); }
.category-disfrute { border-left-color: var(--accent4); }

/* Total After Withdrawals */
.total-after-withdrawals {
    text-align: center;
    margin: 12px 0;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #3498db;
}

.total-label {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 4px;
}

.total-amount {
    font-size: 1.3rem;
    font-weight: bold;
    color: #2c3e50;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablets and small laptops */
@media (max-width: 1024px) {
    .dashboard {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr 1fr;
    }

    .categories-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }
}

/* Tablets */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .card {
        padding: 15px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .categories-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .chart-container {
        height: 220px;
        padding: 12px;
    }

    .header h1 {
        font-size: 1.2rem;
    }

    .user-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

/* Mobile Phones */
@media (max-width: 480px) {
    body {
        font-size: 13px;
    }

    .container {
        padding: 8px;
    }

    .header {
        padding: 12px;
    }

    .header h1 {
        font-size: 1.1rem;
        margin-bottom: 6px;
    }

    .card {
        padding: 12px;
        border-radius: 6px;
    }

    .card h2 {
        font-size: 1rem;
        margin-bottom: 12px;
    }

    .btn {
        padding: 12px 16px;
        font-size: 0.85rem;
        width: 100%; /* Full width buttons on mobile */
    }

    .form-control {
        padding: 12px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .selector-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .selector-header h3 {
        text-align: center;
    }

    .table {
        font-size: 0.75rem;
        min-width: 500px;
    }

    .table th,
    .table td {
        padding: 8px 6px;
    }

    .modal {
        padding: 15px;
        margin: 0;
        border-radius: 0;
        max-height: 100vh;
        max-width: 100vw;
    }

    .modal h3 {
        font-size: 1rem;
    }

    .category-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .category-input-group {
        flex-direction: column;
        gap: 6px;
        width: 100%;
    }

    .category-input-group .btn {
        width: 100%;
    }

    .total-amount {
        font-size: 1.1rem;
    }

    .chart-container {
        height: 200px;
        padding: 10px;
    }
}

/* Small Mobile Phones */
@media (max-width: 360px) {
    .container {
        padding: 5px;
    }

    .card {
        padding: 10px;
    }

    .header {
        padding: 10px;
    }

    .header h1 {
        font-size: 1rem;
    }

    .btn {
        padding: 10px 12px;
        font-size: 0.8rem;
    }

    .form-control {
        padding: 10px;
    }

    .table {
        min-width: 450px;
        font-size: 0.7rem;
    }

    .categories-grid {
        gap: 6px;
    }

    .category-card {
        padding: 10px;
    }
}

/* Landscape Orientation */
@media (max-height: 500px) and (orientation: landscape) {
    .modal {
        max-height: 80vh;
    }

    .chart-container {
        height: 180px;
    }

    .container {
        padding: 8px;
    }
}

/* High-resolution displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .card {
        border-width: 0.5px;
    }
}

/* Print Styles */
@media print {
    .btn, .modal-backdrop, .toast {
        display: none !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid #000;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --light: #2c3e50;
        --dark: #ecf0f1;
        --background: #1a1a1a;
        --border: #34495e;
    }

    body {
        background: var(--background);
        color: var(--dark);
    }

    .card, .header, .modal, .table-responsive, .chart-container {
        background: #2c3e50;
        color: var(--dark);
        border-color: var(--border);
    }

    .form-control {
        background: #34495e;
        color: var(--dark);
        border-color: var(--border);
    }

    .table th {
        background: var(--primary);
        color: var(--dark);
    }
}

/* Touch device improvements */
@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        background: inherit;
    }

    .category-card:hover {
        border-color: var(--border);
    }

    .table tr:hover {
        background: inherit;
    }
}

/* Ensure proper scrolling on iOS */
body {
    -webkit-overflow-scrolling: touch;
}

/* Fix for iOS form elements */
input, select, textarea {
    -webkit-appearance: none;
    border-radius: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ===== LOGIN STYLES ===== */
.login-body {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 450px;
    margin: 0 auto;
}

.login-card {
    background: white;
    border-radius: 16px;
    padding: 40px 35px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.login-card h1 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 35px;
    font-size: 2rem;
    font-weight: 700;
}

.login-card .form-group {
    margin-bottom: 25px;
}

.login-card label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--dark);
    font-size: 1rem;
}

.login-card input {
    width: 100%;
    padding: 18px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    background: var(--background);
}

.login-card input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(44, 62, 80, 0.1);
}

.btn-login {
    width: 100%;
    padding: 18px;
    font-size: 1.2rem;
    font-weight: 600;
    margin-top: 10px;
    border-radius: 10px;
    background: var(--primary);
    border: none;
    transition: all 0.3s ease;
}

.btn-login:hover {
    background: var(--secondary);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.login-links {
    text-align: center;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.login-links a {
    color: var(--accent1);
    text-decoration: none;
    font-weight: 500;
    font-size: 1rem;
    transition: color 0.3s ease;
}

.login-links a:hover {
    color: var(--secondary);
    text-decoration: underline;
}

.error-message {
    color: #e74c3c;
    padding: 15px;
    background: #fdf2f2;
    border-radius: 8px;
    margin-top: 20px;
    text-align: center;
    font-weight: 500;
    border: 1px solid #f5c6cb;
}

/* ===== LOGIN RESPONSIVE ===== */

/* Tablets */
@media (max-width: 768px) {
    .login-card {
        padding: 35px 30px;
        margin: 20px;
    }

    .login-card h1 {
        font-size: 1.8rem;
        margin-bottom: 30px;
    }

    .login-card input {
        padding: 16px 14px;
        font-size: 1rem;
    }

    .btn-login {
        padding: 16px;
        font-size: 1.1rem;
    }
}

/* Mobile Phones */
@media (max-width: 480px) {
    .login-body {
        padding: 15px;
        align-items: flex-start;
        padding-top: 40px;
    }

    .login-card {
        padding: 30px 25px;
        margin: 0;
        border-radius: 12px;
    }

    .login-card h1 {
        font-size: 1.6rem;
        margin-bottom: 25px;
    }

    .login-card input {
        padding: 14px 12px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .btn-login {
        padding: 15px;
        font-size: 1rem;
    }

    .login-links {
        margin-top: 20px;
        padding-top: 15px;
    }
}

/* Small Mobile Phones */
@media (max-width: 360px) {
    .login-card {
        padding: 25px 20px;
    }

    .login-card h1 {
        font-size: 1.4rem;
    }

    .login-card input {
        padding: 12px 10px;
    }
}

/* Landscape Orientation for Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .login-body {
        align-items: flex-start;
        padding-top: 20px;
        padding-bottom: 20px;
    }

    .login-card {
        padding: 25px;
    }
}