/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light Theme Colors */
    --bg-primary: #F8FAFC;
    --bg-secondary: #FFFFFF;
    --text-primary: #1F2937;
    --text-secondary: #6B7280;
    --border-color: #E5E7EB;
    --primary-color: #3B82F6;
    --success-color: #10B981;
    --warning-color: #F59E0B;
    --error-color: #EF4444;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    /* Dark Theme Colors */
    --bg-primary: #0F172A;
    --bg-secondary: #1E293B;
    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --border-color: #334155;
    --primary-color: #60A5FA;
    --success-color: #34D399;
    --warning-color: #FBBF24;
    --error-color: #F87171;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    padding-bottom: 80px;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 8px 0;
    z-index: 1000;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.2s;
}

.nav-item.active {
    color: var(--primary-color);
}

.nav-item i {
    font-size: 20px;
    margin-bottom: 4px;
}

.nav-item span {
    font-size: 12px;
    font-weight: 600;
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Headers */
.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 500;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.section-header {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
}

.section-header i {
    color: var(--primary-color);
    margin-right: 8px;
    font-size: 18px;
}

.section-header h2 {
    font-size: 18px;
    font-weight: 600;
}

/* Progress Bars */
.progress-bar-container {
    margin-bottom: 16px;
}

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

.progress-label {
    font-size: 14px;
    font-weight: 600;
}

.progress-values {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.progress-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.progress-percentage {
    font-size: 12px;
    font-weight: 600;
}

.progress-remaining {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Water Tracker */
.water-progress {
    margin-bottom: 16px;
}

.water-info {
    margin-bottom: 8px;
}

.current-amount {
    font-size: 24px;
    font-weight: 700;
}

.goal-amount {
    font-size: 16px;
    color: var(--text-secondary);
    margin-left: 4px;
}

.remaining {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
    margin-top: 8px;
}

.quick-add {
    display: flex;
    gap: 8px;
}

.quick-button {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Quick Stats */
.quick-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    flex: 1;
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 12px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-card i {
    color: var(--success-color);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    margin: 4px 0;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Meals */
.meals-section h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 16px;
}

.meal-card {
    background: var(--bg-secondary);
    border-radius: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.meal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-left: 4px solid;
}

.meal-header.breakfast { border-left-color: #F97316; }
.meal-header.lunch { border-left-color: #3B82F6; }
.meal-header.dinner { border-left-color: #10B981; }
.meal-header.snacks { border-left-color: #8B5CF6; }

.meal-left {
    display: flex;
    align-items: center;
    flex: 1;
}

.meal-icon {
    font-size: 24px;
    margin-right: 12px;
}

.meal-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.meal-summary {
    font-size: 14px;
    color: var(--text-secondary);
}

.meal-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.add-food-btn {
    width: 32px;
    height: 32px;
    border-radius: 16px;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.add-food-btn.breakfast { background: #F97316; }
.add-food-btn.lunch { background: #3B82F6; }
.add-food-btn.dinner { background: #10B981; }
.add-food-btn.snacks { background: #8B5CF6; }

.expand-icon {
    color: var(--text-secondary);
    cursor: pointer;
}

.meal-content {
    border-top: 1px solid var(--border-color);
    display: none;
}

.meal-content.expanded {
    display: block;
}

.macro-summary {
    display: flex;
    justify-content: space-around;
    padding: 16px;
    background: var(--bg-primary);
}

.macro-item {
    text-align: center;
}

.macro-value {
    font-size: 16px;
    font-weight: 600;
}

.macro-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.food-list {
    padding: 16px;
    padding-top: 0;
}

.food-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.food-item:last-child {
    border-bottom: none;
}

.food-info {
    flex: 1;
}

.food-name {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
}

.food-details {
    font-size: 12px;
    color: var(--text-secondary);
}

.remove-food-btn {
    padding: 8px;
    background: #FEE2E2;
    color: var(--error-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.remove-food-btn:hover {
    background: #FECACA;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.nutrition-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.nutrition-grid input {
    text-align: center;
}

/* Buttons */
.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    width: 100%;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.button-row {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.button-row .btn-secondary,
.button-row .btn-primary {
    flex: 1;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.tab-button {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: none;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.tab-button.active {
    background: var(--primary-color);
    color: white;
}

.subtab-content {
    display: none;
}

.subtab-content.active {
    display: block;
}

/* Settings */
.goal-inputs {
    margin-bottom: 20px;
}

.goal-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.goal-row label {
    font-size: 16px;
    font-weight: 500;
    flex: 1;
}

.goal-row input {
    width: 80px;
    text-align: center;
    margin-right: 8px;
}

.goal-row span {
    font-size: 14px;
    color: var(--text-secondary);
    min-width: 30px;
}

.preference-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.preference-label {
    font-size: 16px;
    font-weight: 500;
}

.preference-description {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
    max-width: 250px;
}

/* Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: 0.4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* App Info */
.app-info {
    text-align: center;
    padding: 40px 20px;
}

.app-info h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.app-info p {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* History */
.week-navigation {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.nav-button {
    padding: 8px;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    box-shadow: var(--shadow);
}

.week-title {
    font-size: 18px;
    font-weight: 600;
}

.calendar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.day-button {
    flex: 1;
    padding: 12px 8px;
    border-radius: 12px;
    border: none;
    color: white;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.day-name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
}

.day-number {
    font-size: 16px;
    font-weight: 700;
}

.goal-met { background: var(--success-color); }
.partial { background: var(--warning-color); }
.missed { background: var(--error-color); }

.legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 24px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 6px;
}

.legend span {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.stats-grid .stat-card {
    margin-bottom: 0;
}

/* Macro Chart */
.macro-chart {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.macro-chart-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.macro-chart-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.macro-chart-fill {
    height: 100%;
    border-radius: 4px;
}

.macro-chart-label {
    font-size: 14px;
    font-weight: 500;
}

/* Weight Section */
.weight-summary {
    display: flex;
    justify-content: space-around;
    margin-bottom: 24px;
}

.weight-stat {
    text-align: center;
}

.weight-value {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.weight-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.weight-chart {
    margin-top: 16px;
}

.chart-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

.chart-container {
    display: flex;
    align-items: end;
    justify-content: space-around;
    height: 100px;
}

.chart-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.bar {
    width: 20px;
    background: var(--primary-color);
    border-radius: 4px;
    margin-bottom: 8px;
}

.bar-label {
    font-size: 10px;
    color: var(--text-secondary);
}

/* Weight History */
.weight-history h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 20px 0 12px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.weight-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 8px;
    margin-bottom: 8px;
}

.weight-entry-info {
    flex: 1;
}

.weight-entry-value {
    font-size: 16px;
    font-weight: 600;
}

.weight-entry-date {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.weight-entry-notes {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
    font-style: italic;
}

.delete-weight-btn {
    padding: 4px 8px;
    background: none;
    border: none;
    color: var(--error-color);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

/* Insights */
.insights {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.insight {
    padding: 16px;
    background: var(--bg-primary);
    border-radius: 12px;
}

.insight-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

.insight-text {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    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: var(--bg-primary);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 16px 16px 0 0;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    font-size: 18px;
}

.search-container {
    padding: 16px 20px;
    background: var(--bg-secondary);
}

.search-bar {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 12px 16px;
}

.search-bar i {
    color: var(--text-secondary);
    margin-right: 12px;
}

.search-bar input {
    flex: 1;
    border: none;
    background: none;
    font-size: 16px;
    color: var(--text-primary);
}

.search-bar input:focus {
    outline: none;
}

.category-filter {
    display: flex;
    gap: 6px;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.category-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: none;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

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

.food-list {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.food-picker-item {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.food-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.food-picker-info {
    flex: 1;
}

.food-picker-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.food-picker-details {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.food-picker-category {
    font-size: 12px;
    color: var(--primary-color);
    font-weight: 500;
}

.add-to-meal-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.add-to-meal-btn:hover {
    opacity: 0.9;
}

.servings-control {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.servings-buttons {
    display: flex;
    align-items: center;
    gap: 16px;
}

.serving-btn {
    width: 32px;
    height: 32px;
    border-radius: 16px;
    background: var(--bg-primary);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.servings-text {
    font-size: 14px;
    font-weight: 500;
    min-width: 80px;
    text-align: center;
}

.total-nutrition {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-state-text {
    font-size: 16px;
    color: var(--text-secondary);
}

/* Templates */
.template-card {
    background: var(--bg-primary);
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 12px;
}

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

.template-name {
    font-size: 16px;
    font-weight: 600;
}

.template-category {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.template-date {
    font-size: 12px;
    color: var(--text-secondary);
}

.delete-template-btn {
    padding: 4px 8px;
    background: none;
    border: none;
    color: var(--error-color);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }
    
    .nutrition-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .quick-stats {
        flex-direction: column;
        gap: 8px;
    }
    
    .modal-content {
        width: 95%;
        margin: 20px;
    }
}

@media (max-width: 480px) {
    .nutrition-grid {
        grid-template-columns: 1fr;
    }
    
    .button-row {
        flex-direction: column;
    }
    
    .goal-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .goal-row label {
        flex-basis: 100%;
    }
}