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

/* Ensure proper rendering across browsers */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
    font-size: 16px;
}

body {
    font-family: 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Mobile-first responsive images */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    width: 100%;
}

/* Improved container for different screen sizes */
@media (min-width: 480px) {
    .container {
        padding: 20px;
    }
}

@media (min-width: 768px) {
    .container {
        padding: 24px;
    }
}

header {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 30px;
    border-radius: 20px;
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

h1 {
    font-size: 2.5em;
    font-weight: 300;
}

.month-selector select {
    padding: 10px 15px;
    font-size: 16px;
    border: none;
    border-radius: 5px;
    background: white;
    color: #333;
    cursor: pointer;
}

.expense-form, .expense-summary, .expense-list {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 30px;
    border-radius: 20px;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

h2 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 1.8em;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

input, select {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-color: white;
}

/* Custom select arrow */
select {
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3E%3Cpath fill='%23666' d='M2 0L0 2h4zm0 5L0 3h4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    padding-right: 40px;
}

input:focus, select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Better checkbox styling */
input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    transform: scale(1.2);
}

button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    touch-action: manipulation; /* Prevent double-tap zoom */
    min-height: 44px; /* Touch-friendly on mobile */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Fix button appearance on iOS */
button::-moz-focus-inner {
    border: 0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.dashboard {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 30px;
    margin-bottom: 30px;
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
}

.chart-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 25px;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    height: 350px;
}

#categoryChart {
    max-height: 280px;
}

.chart-container h3 {
    margin-bottom: 15px;
    color: #667eea;
    font-size: 1.2em;
}

.recurring-expenses {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 30px;
    border-radius: 20px;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.recurring-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    border-left: 4px solid #28a745;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.no-recurring {
    text-align: center;
    color: #666;
    font-style: italic;
}

.stat {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.stat-label {
    display: block;
    color: #666;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.5em;
    font-weight: bold;
    color: #333;
}

.filters {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.filters select {
    width: auto;
    min-width: 200px;
}

#clearAll {
    background: #dc3545;
}

#clearAll:hover {
    background: #c82333;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

th {
    background: #f8f9fa;
    font-weight: bold;
    color: #555;
}

.delete-btn {
    background: #dc3545;
    padding: 5px 10px;
    font-size: 12px;
}

.delete-btn:hover {
    background: #c82333;
}

.amount {
    font-weight: bold;
    color: #28a745;
}

/* Mobile optimizations */
@media (max-width: 480px) {
    .container {
        padding: 12px;
    }
    
    h1 {
        font-size: 1.8em;
    }
    
    .auth-card {
        padding: 20px;
        margin: 10px;
    }
    
    .auth-tab {
        padding: 12px 8px;
        font-size: 0.9em;
    }
    
    .auth-tab .tab-icon {
        font-size: 1.2em;
    }
    
    .summary-stats {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    
    .stat {
        padding: 15px;
    }
    
    button {
        min-height: 44px; /* Touch-friendly */
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    input, select {
        min-height: 44px; /* Touch-friendly */
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Tablet portrait */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }
    
    header {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }
    
    .user-header {
        flex-direction: column;
        gap: 15px;
    }
    
    h1 {
        font-size: 2em;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .dashboard {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .chart-container {
        height: 300px;
    }
    
    .summary-stats {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 15px;
    }
    
    .filters {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .filters select {
        width: 100%;
        min-width: auto;
    }
    
    table {
        font-size: 14px;
        overflow-x: auto;
        display: block;
        white-space: nowrap;
    }
    
    thead, tbody, th, td, tr {
        display: block;
    }
    
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    tr {
        border: 1px solid #ccc;
        margin-bottom: 10px;
        padding: 10px;
        border-radius: 8px;
        background: white;
        display: flex;
        flex-direction: column;
        gap: 5px;
    }
    
    td {
        border: none;
        position: relative;
        padding: 5px 0;
        display: flex;
        justify-content: space-between;
    }
    
    td:before {
        content: attr(data-label);
        font-weight: bold;
        color: #666;
    }
}

/* Tablet landscape and small desktop */
@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard {
        grid-template-columns: 1fr 350px;
    }
    
    .chart-container {
        height: 320px;
    }
}

/* Authentication Styles */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 100%;
    max-width: 400px;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    color: #667eea;
}

.auth-header p {
    color: #666;
    margin: 0;
}

.auth-tabs {
    display: flex;
    margin-bottom: 30px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    padding: 8px;
    gap: 8px;
}

.auth-tab {
    flex: 1;
    padding: 16px 20px;
    border: none;
    background: transparent;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
}

.auth-tab .tab-icon {
    font-size: 1.5em;
    margin-bottom: 4px;
}

.auth-tab .tab-text {
    font-size: 1em;
    font-weight: 600;
    margin-bottom: 2px;
}

.auth-tab .tab-subtitle {
    font-size: 0.75em;
    opacity: 0.7;
    font-weight: 400;
}

.auth-tab.active {
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    color: #667eea;
    transform: translateY(-1px);
}

.auth-tab:hover:not(.active) {
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(-1px);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.auth-button {
    width: 100%;
    padding: 15px;
    font-size: 16px;
    font-weight: 600;
    margin-top: 10px;
}

.auth-footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.auth-footer p {
    color: #666;
    font-size: 14px;
    margin: 0;
}

.user-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.9);
}

.logout-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    font-size: 14px;
}

/* Enhanced auth form styling */
.auth-form h3 {
    text-align: center;
    color: #667eea;
    margin-bottom: 8px;
    font-size: 1.5em;
}

.form-subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 25px;
    font-size: 0.9em;
}

.auth-form input {
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.auth-form input:focus {
    background: white;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.switch-form {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9em;
    color: #666;
}

.link-btn {
    background: none;
    border: none;
    color: #667eea;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
    font-size: inherit;
}

.link-btn:hover {
    color: #5a6fd8;
}

.login-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.register-btn {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
}