/* CSS Variables */
:root {
    --primary: #4CAF50;
    --primary-dark: #388E3C;
    --primary-light: #C8E6C9;
    --secondary: #FF9800;
    --secondary-dark: #F57C00;
    --background: #FAFAFA;
    --card: #FFFFFF;
    --text: #333333;
    --text-light: #666666;
    --text-hint: #999999;
    --border: #E0E0E0;
    --danger: #F44336;
    --success: #4CAF50;
    --warning: #FF9800;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --nav-height: 60px;
}

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

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Page Structure */
.page {
    display: none;
    padding-bottom: calc(var(--nav-height) + 16px);
}

.page.active {
    display: block;
}

.hidden {
    display: none !important;
}

/* Auth Page */
#auth-page {
    display: none;
    min-height: 100vh;
    padding: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

#auth-page.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-container {
    background: var(--card);
    padding: 40px 30px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 320px;
    text-align: center;
}

.auth-logo {
    font-size: 48px;
    margin-bottom: 16px;
}

.auth-container h1 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text);
}

.auth-subtitle {
    color: var(--text-light);
    margin-bottom: 24px;
    font-size: 14px;
}

.auth-hint {
    color: var(--text-light);
    font-size: 13px;
    margin-bottom: 16px;
}

#auth-form input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    margin-bottom: 12px;
    transition: border-color 0.2s;
}

#auth-form input:focus {
    outline: none;
    border-color: var(--primary);
}

.error-msg {
    color: var(--danger);
    font-size: 13px;
    margin-top: 8px;
}

/* App Header */
.app-header {
    background: var(--primary);
    color: white;
    padding: 16px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    font-size: 20px;
    font-weight: 600;
}

#current-date {
    font-size: 14px;
    opacity: 0.9;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 16px;
    border: none;
    background: none;
    color: var(--text-light);
    font-size: 12px;
    cursor: pointer;
    transition: color 0.2s;
}

.nav-item .nav-icon {
    font-size: 22px;
}

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

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    margin: 12px 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
}

.card-date {
    font-size: 13px;
    color: var(--text-light);
}

/* Today Overview */
.overview-stats {
    display: flex;
    justify-content: space-around;
    padding: 20px 16px;
}

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

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

.today-tags {
    padding: 0 16px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Forms */
.meal-form {
    padding: 16px;
}

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

.form-group label {
    display: block;
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.2s;
}

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

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

/* Meal Type Selector */
.meal-type-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.meal-type-btn {
    flex: 1;
    min-width: 60px;
}

.meal-type-btn input {
    display: none;
}

.meal-type-btn span {
    display: block;
    padding: 10px 8px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.meal-type-btn input:checked + span {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Autocomplete */
.autocomplete-wrapper {
    position: relative;
}

.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
}

.suggestion-item {
    padding: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

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

.suggestion-item:hover {
    background: var(--background);
}

.suggestion-item .food-name {
    font-weight: 500;
}

.suggestion-item .food-ingredients {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
}

/* Preview Tags */
.preview-tags {
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.preview-label {
    font-size: 13px;
    color: var(--text-light);
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

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

.btn-secondary {
    background: var(--border);
    color: var(--text);
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-block {
    width: 100%;
}

/* Tags */
.tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.tag-protein {
    background: #E3F2FD;
    color: #1565C0;
}

.tag-carb {
    background: #FFF3E0;
    color: #E65100;
}

.tag-vegetable {
    background: #E8F5E9;
    color: #2E7D32;
}

.tag-fruit {
    background: #FCE4EC;
    color: #C2185B;
}

.tag-dairy {
    background: #F3E5F5;
    color: #7B1FA2;
}

.tag-healthy {
    background: #E8F5E9;
    color: #2E7D32;
}

.tag-warning {
    background: #FFF8E1;
    color: #F57F17;
}

.tag-balance {
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* Meals List */
.meals-list {
    padding: 8px 16px 16px;
}

.meal-item {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 8px;
}

.meal-item:last-child {
    margin-bottom: 0;
}

.meal-time-badge {
    min-width: 50px;
    padding: 4px 8px;
    background: var(--primary);
    color: white;
    border-radius: 6px;
    font-size: 12px;
    text-align: center;
    margin-right: 12px;
}

.meal-content {
    flex: 1;
}

.meal-food {
    font-weight: 500;
    margin-bottom: 4px;
}

.meal-ingredients {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 6px;
}

.meal-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.meal-actions {
    display: flex;
    gap: 8px;
    margin-left: 8px;
}

.meal-actions button {
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    background: var(--border);
    color: var(--text);
}

.empty-hint {
    text-align: center;
    color: var(--text-hint);
    padding: 20px;
    font-size: 14px;
}

/* Time Filter */
.time-filter {
    display: flex;
    padding: 12px 16px;
    gap: 8px;
    overflow-x: auto;
}

.filter-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--card);
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}

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

/* Charts */
.chart-container {
    padding: 16px;
    height: 250px;
}

.freq-chart {
    padding: 16px;
}

.freq-item {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}

.freq-name {
    width: 60px;
    font-size: 13px;
    color: var(--text-light);
}

.freq-bar-wrapper {
    flex: 1;
    height: 20px;
    background: var(--background);
    border-radius: 10px;
    overflow: hidden;
    margin: 0 12px;
}

.freq-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 10px;
    transition: width 0.3s;
}

.freq-count {
    width: 30px;
    font-size: 13px;
    color: var(--text);
    text-align: right;
}

/* Balance Score */
.balance-score {
    padding: 16px;
    text-align: center;
}

.score-circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 6px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.score-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
}

.score-bars {
    text-align: left;
    margin-bottom: 16px;
}

.score-bar-item {
    margin-bottom: 12px;
}

.score-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 4px;
}

.score-bar-track {
    height: 8px;
    background: var(--background);
    border-radius: 4px;
    overflow: hidden;
}

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

.balance-advice {
    font-size: 14px;
    color: var(--text-light);
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
}

/* Calendar */
.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--card);
    margin: 12px 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.calendar-header h2 {
    font-size: 18px;
}

.nav-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--background);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    padding: 8px 16px;
    text-align: center;
    font-size: 12px;
    color: var(--text-light);
}

.calendar-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    padding: 0 16px 16px;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    background: var(--card);
    transition: background 0.2s;
}

.calendar-day.other-month {
    color: var(--text-hint);
}

.calendar-day.today {
    border: 2px solid var(--primary);
}

.calendar-day.selected {
    background: var(--primary);
    color: white;
}

.calendar-day.has-record::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--secondary);
    margin-top: 2px;
}

.calendar-day.balanced::after {
    background: var(--success);
}

.calendar-day.unbalanced::after {
    background: var(--warning);
}

/* Settings */
.settings-list {
    padding: 8px 0;
}

.setting-item {
    display: flex;
    align-items: center;
    padding: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.setting-item:hover {
    background: var(--background);
}

.setting-icon {
    font-size: 20px;
    margin-right: 12px;
}

.setting-text {
    flex: 1;
    font-size: 15px;
}

.setting-arrow {
    color: var(--text-hint);
}

.about-info {
    padding: 20px;
    text-align: center;
}

.about-desc {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
}

.modal-content {
    background: var(--card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--background);
    font-size: 20px;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    gap: 12px;
    padding: 0 16px 16px;
}

.modal-actions button {
    flex: 1;
}

#delete-meal {
    background: var(--danger);
    color: white;
}

/* Toast */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 20px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 3000;
    opacity: 0;
    transition: opacity 0.3s;
}

.toast.show {
    opacity: 1;
}

/* Responsive */
@media (max-width: 360px) {
    .meal-type-btn span {
        padding: 8px 4px;
        font-size: 12px;
    }

    .stat-value {
        font-size: 24px;
    }
}
