* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --vh: 1vh; /* Will be updated by JavaScript */
}

html {
    height: 100%;
    height: -webkit-fill-available;
    overflow-x: hidden;
    position: fixed;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 50%, #a5d6a7 100%);
    background-attachment: fixed;
    min-height: 100vh;
    min-height: -webkit-fill-available; /* iOS Safari */
    min-height: calc(var(--vh, 1vh) * 100);
    padding: 20px;
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    color: #4a5568;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    color: #2d5016;
    margin-bottom: 40px;
    padding: 30px 20px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

header h1 {
    font-size: 2.8rem;
    margin-bottom: 10px;
    font-weight: 300;
    letter-spacing: -0.5px;
    color: #2d5016;
    text-align: left;
}

.subtitle {
    font-size: 1.1rem;
    color: #5a7c4a;
    font-weight: 400;
    text-align: left;
}

.user-section {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info span {
    font-weight: 500;
    color: #2d5016;
    font-size: 1rem;
}

.auth-section {
    display: flex;
    gap: 10px;
}

.btn-auth {
    padding: 10px 20px;
    border: 2px solid #a8c5a0;
    background: transparent;
    color: #2d5016;
    border-radius: 10px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn-auth:hover {
    background: #a8c5a0;
    transform: translateY(-1px);
}

.btn-auth-primary {
    background: #a8c5a0;
    color: #1a3d0f;
}

.btn-auth-primary:hover {
    background: #9bb893;
}

.btn-profile {
    padding: 8px 16px;
    background: #a8c5a0;
    color: #1a3d0f;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn-profile:hover {
    background: #9bb893;
    transform: translateY(-1px);
}

.btn-logout {
    padding: 8px 16px;
    background: #d4a5a5;
    color: #5a2a2a;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn-logout:hover {
    background: #c89595;
    transform: translateY(-1px);
}

/* PWA Install Button */
.btn-install-pwa {
    padding: 10px 18px;
    background: #7fb3b8;
    color: #1a3d0f;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    display: none;
}

.btn-install-pwa:hover {
    background: #6fa3a8;
    transform: translateY(-1px);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 40px;
    max-width: 450px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    position: relative;
    animation: slideUp 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-modal {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    transition: color 0.3s;
}

.close-modal:hover {
    color: #333;
}

.modal-content h2 {
    margin-bottom: 25px;
    color: #2d5016;
    font-size: 1.8rem;
    font-weight: 400;
}

.form-switch {
    margin-top: 20px;
    text-align: center;
    color: #666;
    font-size: 0.9rem;
}

.form-switch a {
    color: #5a7c4a;
    text-decoration: none;
    font-weight: 500;
}

.form-switch a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .header-top {
        flex-direction: column;
        text-align: center;
    }

    header h1, .subtitle {
        text-align: center;
    }

    .user-section, .auth-section {
        width: 100%;
        justify-content: center;
    }
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    margin-bottom: 30px;
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 35px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.add-expense-section {
    grid-column: 1;
}

.summary-section {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

@media (max-width: 768px) {
    .summary-section {
        grid-column: 1;
    }
}

.summary-card {
    background: linear-gradient(135deg, #a8c5a0 0%, #7fb3b8 100%);
    color: #2d5016;
    padding: 28px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(127, 179, 184, 0.2);
}

.summary-card h3 {
    font-size: 0.95rem;
    margin-bottom: 12px;
    opacity: 0.85;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.total-amount {
    font-size: 2.4rem;
    font-weight: 300;
    margin: 0;
    color: #1a3d0f;
}

.total-count {
    font-size: 2.4rem;
    font-weight: 300;
    margin: 0;
    color: #1a3d0f;
}

h2 {
    margin-bottom: 25px;
    color: #2d5016;
    font-size: 1.4rem;
    font-weight: 400;
    letter-spacing: -0.3px;
}

.form-group {
    margin-bottom: 22px;
}

label {
    display: block;
    margin-bottom: 10px;
    color: #5a7c4a;
    font-weight: 500;
    font-size: 0.9rem;
    letter-spacing: 0.3px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
select {
    width: 100%;
    padding: 14px;
    border: 2px solid #d4e4d1;
    border-radius: 12px;
    font-size: 16px; /* Prevent zoom on iOS - must be 16px */
    transition: all 0.3s ease;
    background: #fafbf9;
    color: #4a5568;
    -webkit-appearance: none;
    appearance: none;
    transform: translateZ(0); /* Force hardware acceleration */
    -webkit-transform: translateZ(0);
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus {
    outline: none;
    border-color: #7fb3b8;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(127, 179, 184, 0.1);
    transform: translateZ(0); /* Prevent layout shift */
    -webkit-transform: translateZ(0);
}

/* Prevent zoom on input focus (iOS) - Critical for mobile */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px !important; /* 16px prevents zoom on iOS */
    }
    
    /* Scroll input into view when focused */
    input:focus,
    select:focus,
    textarea:focus {
        scroll-margin-top: 100px; /* Space for keyboard */
    }
}

.btn-primary {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #a8c5a0 0%, #7fb3b8 100%);
    color: #1a3d0f;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(127, 179, 184, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(127, 179, 184, 0.3);
    background: linear-gradient(135deg, #9bb893 0%, #6fa3a8 100%);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    padding: 10px 18px;
    background: #d4a5a5;
    color: #5a2a2a;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn-secondary:hover {
    background: #c89595;
    transform: translateY(-1px);
}

.expense-list-section {
    grid-column: 1 / -1;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.export-buttons {
    display: flex;
    gap: 8px;
}

.btn-export {
    padding: 10px 16px;
    background: #a8c5a0;
    color: #1a3d0f;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
}

.btn-export:hover {
    background: #9bb893;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(168, 197, 160, 0.3);
}

.expense-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.empty-message {
    text-align: center;
    color: #9ca3af;
    padding: 50px;
    font-style: italic;
    font-size: 1.05rem;
}

.expense-item {
    background: #f7faf7;
    border-left: 4px solid #a8c5a0;
    padding: 20px;
    border-radius: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.expense-item:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    background: #ffffff;
}

.expense-item-info {
    flex: 1;
}

.expense-item-description {
    font-weight: 500;
    font-size: 1.1rem;
    color: #2d5016;
    margin-bottom: 8px;
}

.expense-item-details {
    display: flex;
    gap: 15px;
    font-size: 0.9rem;
    color: #6b7280;
    align-items: center;
}

.currency-code {
    background: #d1e7dd;
    color: #0f5132;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.expense-item-amount {
    font-size: 1.3rem;
    font-weight: 500;
    color: #5a7c4a;
    margin-right: 15px;
}

.expense-item-actions {
    display: flex;
    gap: 10px;
}

.btn-delete {
    padding: 8px 14px;
    background: #d4a5a5;
    color: #5a2a2a;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn-delete:hover {
    background: #c89595;
    transform: translateY(-1px);
}

.category-badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 14px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.category-Food {
    background: #f0e6d2;
    color: #8b6f47;
}

.category-Transport {
    background: #d4e8f0;
    color: #4a6b7a;
}

.category-Shopping {
    background: #f5d7e3;
    color: #7a4a5a;
}

.category-Bills {
    background: #f5f0d7;
    color: #8b7a4a;
}

.category-Entertainment {
    background: #d7e8d4;
    color: #4a7a5a;
}

.category-Health {
    background: #f5d7d7;
    color: #7a4a4a;
}

.category-Other {
    background: #e8d7f0;
    color: #6a4a7a;
}

/* Mobile Keyboard and Layout Fixes */
@media (max-width: 768px) {
    /* Prevent layout shift when keyboard appears */
    body {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .container {
        width: 100%;
        max-width: 100%;
        padding: 0;
    }

    /* Keep form section stable */
    .add-expense-section {
        position: relative;
        z-index: 1;
        margin-bottom: 20px;
    }

    /* Smooth scroll to input when focused */
    .add-expense-section input:focus,
    .add-expense-section select:focus {
        scroll-margin-top: 150px;
    }

    /* Prevent header from moving */
    header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 50%, #a5d6a7 100%);
        padding: 15px 20px;
        margin-bottom: 20px;
    }

    /* Ensure sections don't shift */
    section {
        position: relative;
        margin-bottom: 20px;
    }

    /* Fix for date input on mobile */
    input[type="date"] {
        min-height: 44px;
    }

    /* Prevent zoom on any input focus */
    input,
    select,
    textarea {
        font-size: 16px !important;
        -webkit-text-size-adjust: 100%;
    }
}
