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

:root {
    --primary: #ff6b35;
    --primary-dark: #e55a2b;
    --secondary: #2c3e50;
    --background: #fafafa;
    --surface: #ffffff;
    --text: #333333;
    --text-light: #666666;
    --border: #e0e0e0;
    --success: #4caf50;
    --danger: #e74c3c;
    --tag-home: #3498db;
    --tag-takeout: #f39c12;
    --tag-grill: #e67e22;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
    --radius: 8px;
    --radius-lg: 12px;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Loading Screen */
.loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--background);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Header */
.header {
    background: var(--primary);
    color: white;
    padding: calc(var(--safe-area-top) + 12px) 16px 12px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 600px;
    margin: 0 auto;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    text-align: center;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-version {
    font-size: 0.625rem;
    font-weight: 400;
    opacity: 0.6;
}

.header-spacer {
    width: 36px;
}

/* Navigation */
.nav {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: calc(var(--safe-area-top) + 68px);
    left: 0;
    right: 0;
    z-index: 99;
}

.nav-link {
    flex: 1;
    padding: 12px 16px;
    text-align: center;
    text-decoration: none;
    color: var(--text-light);
    font-size: 0.875rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.nav-link:active {
    background: var(--background);
}

.nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 16px;
    padding-top: calc(var(--safe-area-top) + 140px);
    padding-bottom: calc(var(--safe-area-bottom) + 16px);
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    min-height: 44px;
    min-width: 44px;
}

.btn:active {
    transform: scale(0.98);
}

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

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

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.875rem;
}

.btn-icon {
    padding: 8px;
    background: transparent;
    color: white;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-full {
    width: 100%;
}

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

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color 0.2s;
}

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

/* Tags */
.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tag-home { background: var(--tag-home); color: white; }
.tag-takeout { background: var(--tag-takeout); color: white; }
.tag-grill { background: var(--tag-grill); color: white; }

.tag-filter {
    background: var(--background);
    color: var(--text-light);
    border: 1px solid var(--border);
    cursor: pointer;
    min-height: 36px;
    transition: all 0.2s;
}

.tag-filter:active {
    transform: scale(0.95);
}

.tag-filter.active {
    border-color: transparent;
}

.tag-filter.active.tag-home { background: var(--tag-home); color: white; }
.tag-filter.active.tag-takeout { background: var(--tag-takeout); color: white; }
.tag-filter.active.tag-grill { background: var(--tag-grill); color: white; }

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-content {
    padding: 16px;
}

/* Meal Card */
.meal-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.meal-card:active {
    transform: scale(0.98);
}

.meal-card-name {
    font-size: 0.9375rem;
    font-weight: 500;
    flex: 1;
    min-width: 0;
}

.meal-card-tags {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    flex-shrink: 0;
}

.meal-card-tags .tag {
    font-size: 0.5625rem;
    padding: 3px 6px;
}

/* Login View */
.login-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-logo {
    font-size: 3rem;
    margin-bottom: 8px;
}

.login-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-light);
    margin-bottom: 32px;
}

.login-form {
    width: 100%;
    max-width: 320px;
}

.login-error {
    background: #fdeaea;
    color: var(--danger);
    padding: 12px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 16px;
    text-align: center;
}

/* Home View */
.home-greeting {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.home-date {
    color: var(--text-light);
    margin-bottom: 12px;
}

.home-saying {
    font-style: italic;
    color: var(--text-light);
    font-size: 0.9375rem;
    margin-bottom: 24px;
    line-height: 1.4;
}

.home-section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.empty-state-text {
    font-size: 1rem;
}

/* Calendar View */
.calendar-day {
    background: var(--surface);
    border-radius: var(--radius);
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.calendar-day.is-today {
    border: 2px solid var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    scroll-margin-top: calc(var(--safe-area-top) + 120px);
}

.calendar-day.is-past {
    opacity: 0.75;
}

.calendar-day.is-past .calendar-day-header {
    background: #fafafa;
}

.calendar-day-header {
    padding: 12px;
    background: #DADADA;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.calendar-day-date {
    font-weight: 600;
    font-size: 0.875rem;
}

.calendar-day.is-today .calendar-day-date {
    color: var(--primary);
}

.today-badge {
    background: var(--primary);
    color: white;
    font-size: 0.5625rem;
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: 600;
    text-transform: uppercase;
}

.calendar-day-meals {
    padding: 6px 12px;
}

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

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

.calendar-meal-name {
    font-size: 0.875rem;
}

.calendar-meal-remove {
    color: var(--text-light);
    padding: 6px;
    cursor: pointer;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calendar-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 8px;
    background: transparent;
    border: none;
    color: var(--primary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    border-top: 1px solid var(--border);
}

.calendar-add-btn:active {
    background: var(--background);
}

.calendar-no-meals {
    color: #666666;
    font-size: 0.8125rem;
    padding: 4px 0;
}

/* Meals Library View */
.meals-header {
    margin-bottom: 16px;
}

.meals-search {
    margin-bottom: 12px;
}

.meals-filters {
    margin-bottom: 16px;
}

.meals-list {
    margin-bottom: 80px;
}

.meals-fab {
    position: fixed;
    bottom: calc(var(--safe-area-bottom) + 24px);
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: var(--primary);
    color: white;
    font-size: 1.5rem;
    box-shadow: var(--shadow-lg);
    z-index: 50;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

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

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-light);
    cursor: pointer;
}

.modal-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    padding-bottom: calc(var(--safe-area-bottom) + 16px);
}

.modal-footer .btn {
    flex: 1;
}

/* Meal Picker */
.meal-picker-search {
    margin-bottom: 12px;
}

.meal-picker-list {
    max-height: 50vh;
    overflow-y: auto;
}

.meal-picker-item {
    display: flex;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.meal-picker-item:active {
    background: var(--background);
}

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

/* Confirmation Dialog */
.confirm-dialog {
    align-items: center;
    padding: 20px;
}

.confirm-dialog .modal {
    border-radius: var(--radius-lg);
    max-width: 320px;
    animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.confirm-message {
    text-align: center;
    padding: 20px 16px;
    color: var(--text);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

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

.mt-16 {
    margin-top: 16px;
}

.mb-16 {
    margin-bottom: 16px;
}

/* Checkbox Styles */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.checkbox-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 36px;
    color: var(--text);
}

.checkbox-tag input {
    display: none;
}

.checkbox-tag.checked {
    border-color: transparent;
}

.checkbox-tag.checked.tag-home { background: var(--tag-home); color: white; }
.checkbox-tag.checked.tag-takeout { background: var(--tag-takeout); color: white; }
.checkbox-tag.checked.tag-grill { background: var(--tag-grill); color: white; }

.checkbox-tag-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
