* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4CAF50;
    --primary-dark: #388E3C;
    --secondary-color: #FF9800;
    --danger-color: #F44336;
    --text-dark: #212121;
    --text-light: #757575;
    --bg-light: #FAFAFA;
    --border-color: #E0E0E0;
    --white: #FFFFFF;
    --success: #4CAF50;
    --warning: #FF9800;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    margin: 0;
    padding: 0;
}

/* Force no padding in standalone mode - CRITICAL FOR ANDROID */
@media (display-mode: standalone) {
    html {
        padding: 0 !important;
        margin: 0 !important;
    }
    
    body {
        padding: 0 !important;
        margin: 0 !important;
    }
    
    header {
        margin-top: 0 !important;
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    header .container {
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }
    
    header h1 {
        margin: 0 !important;
        padding: 0 !important;
        line-height: 1.2 !important;
    }
    
    /* Fix content overlap on mobile in standalone mode */
    body > .container:first-of-type {
        padding-top: calc(2rem + 60px) !important;
    }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

/* Header */
header {
    background-color: var(--primary-color);
    color: var(--white);
    padding: 1rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

header .container {
    display: flex;
    flex-direction: column;
}

header .header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    line-height: 2.2;
}

header nav {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

header nav a {
    color: var(--white);
    text-decoration: none;
    padding: 0.5rem 1rem;
    font-weight: 500;
    border-radius: 4px;
    transition: background-color 0.2s;
}

header nav a:hover,
header nav a.active {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 25px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
}

.mobile-menu-toggle span {
    width: 30px;
    height: 3px;
    background-color: var(--white);
    border-radius: 2px;
    transition: all 0.3s;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(7px, 7px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* Cards */
.card {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-dark);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--white);
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}

.stat-card.deficit {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--white);
}

.stat-card.deficit .stat-value,
.stat-card.deficit .stat-label {
    color: var(--white);
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-dark);
}
textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="file"],
input[type="date"],
select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--white);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: var(--white);
}

.btn-danger {
    background-color: var(--danger-color);
    color: var(--white);
}

.btn-block {
    display: block;
    width: 100%;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Image Upload */
.image-upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.image-upload-area:hover {
    border-color: var(--primary-color);
    background-color: rgba(76, 175, 80, 0.05);
}

.image-upload-area.active {
    border-color: var(--primary-color);
    background-color: rgba(76, 175, 80, 0.1);
}

.image-preview {
    max-width: 100%;
    max-height: 300px;
    margin: 1rem auto;
    display: block;
    border-radius: 8px;
}

/* Food List */
.food-list {
    list-style: none;
}

.food-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.food-item:hover {
    background-color: var(--bg-light);
}

.food-item:last-child {
    border-bottom: none;
}

.food-item-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    margin-right: 1rem;
}

.food-item-info {
    flex: 1;
}

.food-item-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.food-item-calories {
    color: var(--text-light);
    font-size: 0.875rem;
}

.food-item-actions {
    display: flex;
    gap: 0.5rem;
}

/* Progress Bar */
.progress {
    background-color: var(--border-color);
    border-radius: 4px;
    height: 20px;
    overflow: hidden;
    margin: 1rem 0;
}

.progress-bar {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-size: 0.75rem;
    font-weight: bold;
}

.progress-bar.over {
    background-color: var(--danger-color);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-success {
    background-color: #D4EDDA;
    color: #155724;
    border: 1px solid #C3E6CB;
}

.alert-error {
    background-color: #F8D7DA;
    color: #721C24;
    border: 1px solid #F5C6CB;
}

.alert-info {
    background-color: #D1ECF1;
    color: #0C5460;
    border: 1px solid #BEE5EB;
}

/* Loading */
.loading {
    text-align: center;
    padding: 2rem;
}

.spinner {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Auth Pages */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.auth-card {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.auth-card h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.25rem;
    }

    .mobile-menu-toggle {
        display: flex;
    }

    header nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        width: 100%;
        flex-direction: column;
        margin-top: 0;
        gap: 0;
        background-color: var(--primary-color);
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    }

    header nav.active {
        display: flex;
    }

    header nav a {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 0;
    }

    header nav a:last-child {
        border-bottom: none;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    table {
        font-size: 0.875rem;
    }
    
    table th,
    table td {
        padding: 0.5rem !important;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .food-item {
        flex-wrap: wrap;
    }

    .food-item-actions {
        width: 100%;
        margin-top: 0.5rem;
        justify-content: flex-end;
    }

    .card {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.875rem;
    }

    header h1 {
        font-size: 1.1rem;
    }

    .food-item-image {
        width: 50px;
        height: 50px;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.hidden {
    display: none;
}
/* ========== UPLOAD PAGE ========== */
/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    background: none;
    border: none;
    padding: 1rem 1.5rem;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-light);
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.tab-btn:hover {
    color: var(--primary-color);
    background: var(--bg-light);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.analysis-result {
    background: var(--white);
    border-radius: 8px;
    padding: 1.5rem;
    margin-top: 1rem;
}

.nutrient-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.nutrient-item {
    text-align: center;
    padding: 1rem;
    background: var(--bg-light);
    border-radius: 4px;
}

.nutrient-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.nutrient-label {
    font-size: 0.875rem;
    color: var(--text-light);
}

.confidence-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.confidence-high {
    background: #D4EDDA;
    color: #155724;
}

.confidence-medium {
    background: #FFF3CD;
    color: #856404;
}

.confidence-low {
    background: #F8D7DA;
    color: #721C24;
}

.save-option {
    transition: all 0.3s;
    border: 2px solid transparent;
}

.save-option.active {
    background: var(--primary-color) !important;
    color: white !important;
    border-color: var(--primary-dark);
    transform: scale(1.05);
}

.save-option small {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
}

/* ========== FOODS PAGE ========== */
.search-box {
    margin-bottom: 1.5rem;
}

.food-card {
    background: var(--white);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.food-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* ========== INGREDIENTS PAGE ========== */
.ingredient-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.ingredient-card {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    transition: box-shadow 0.3s;
}

.ingredient-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.ingredient-name {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.ingredient-brand {
    color: var(--text-light);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.ingredient-category {
    display: inline-block;
    background: var(--bg-light);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
}

.ingredient-nutrition {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin: 0.5rem 0;
    font-size: 0.875rem;
}

.filter-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-bar select {
    flex: 0 0 200px;
}

.filter-bar input {
    flex: 1;
    min-width: 200px;
}

/* ========== CREATE RECIPE PAGE ========== */
.ingredient-selector {
    background: var(--bg-light);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.selected-ingredients {
    margin-top: 1rem;
}

.selected-ingredient-row {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.autocomplete-container {
    position: relative;
}

.autocomplete-suggestions {
    position: absolute;
    background: white;
    border: 1px solid var(--border-color);
    border-top: none;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    width: 100%;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.autocomplete-suggestion {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}

.autocomplete-suggestion:hover {
    background: var(--bg-light);
}

.autocomplete-suggestion strong {
    color: var(--primary-color);
}

.nutrition-preview {
    background: var(--primary-color);
    color: white;
    padding: 1rem;
    border-radius: 8px;
    margin: 1rem 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 1rem;
    text-align: center;
}

.nutrition-preview .value {
    font-size: 1.5rem;
    font-weight: bold;
}

.nutrition-preview .label {
    font-size: 0.875rem;
    opacity: 0.9;
}

/* ========== ACTIVITIES PAGE ========== */
.activity-card {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.activity-info h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-dark);
}

.activity-details {
    font-size: 0.875rem;
    color: var(--text-light);
}

.calories-burned {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--secondary-color);
}

.suggested-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
    margin: 1rem 0;
}

.suggested-activity {
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.suggested-activity:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.total-burned-card {
    background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
    color: white;
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 1.5rem;
}

/* ========== MODALS ========== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--white);
    padding: 2rem;
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-close {
    float: right;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
}

.modal-close:hover {
    color: var(--text-dark);
}
/* ========== PWA STYLES ========== */
/* PWA Install Banner */
.pwa-install-banner {
    position: fixed;
    bottom: -100px;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1rem;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    transition: bottom 0.3s ease-in-out;
}

.pwa-install-banner.show {
    bottom: 0;
}

.pwa-banner-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.pwa-banner-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.pwa-banner-text {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.pwa-banner-text strong {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.pwa-banner-text small {
    font-size: 0.875rem;
    opacity: 0.9;
}

#pwa-install-btn {
    background: white;
    color: var(--primary-color);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

#pwa-install-btn:hover {
    background: var(--bg-light);
}

#pwa-dismiss-btn {
    background: transparent;
    color: white;
    border: 1px solid white;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}

#pwa-dismiss-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* PWA Toast */
.pwa-toast {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-dark);
    color: white;
    padding: 1rem 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1001;
    transition: top 0.3s ease-in-out;
    text-align: center;
    max-width: 90%;
}

.pwa-toast.show {
    top: 20px;
}

/* PWA Mode Adjustments */
.pwa-mode header {
    position: fixed;
    width: 100%;
    top: 0;
}

.pwa-mode .container {
    padding-top: 80px;
}

/* Offline Indicator */
.offline-indicator {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--warning);
    color: white;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.875rem;
    z-index: 99;
    display: none;
}

.offline-indicator.show {
    display: block;
}

@media (max-width: 600px) {
    .pwa-banner-content {
        flex-wrap: wrap;
    }
    
    .pwa-banner-text {
        flex-basis: 100%;
        margin-bottom: 0.5rem;
    }
    
    #pwa-install-btn,
    #pwa-dismiss-btn {
        flex: 1;
    }
}

/* Standalone Mode (App installed) */
@media (display-mode: standalone) {
    body {
        -webkit-user-select: none;
        user-select: none;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    
    /* No additional header padding - use max() from above */
    .container {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }
    
    /* Hide browser-specific elements in standalone */
    .pwa-install-banner {
        display: none !important;
    }
}

/* Pull-to-refresh prevention in standalone */
body.standalone-mode {
    overscroll-behavior-y: contain;
}

/* Loading indicator for PWA */
.pwa-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
}

.pwa-loading::after {
    content: '';
    display: block;
    width: 48px;
    height: 48px;
    border: 4px solid var(--primary-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
