/* CSS Variables */
:root {
    --primary: #FF7043;
    --primary-dark: #E64A19;
    --secondary: #FFCCBC;
    --accent: #4CAF50;
    --background: #F5F5F5;
    --surface: #FFFFFF;
    --error: #F44336;
    --text-primary: #212121;
    --text-secondary: #757575;
    --text-hint: #9E9E9E;
    --divider: #E0E0E0;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-elevated: 0 4px 8px rgba(0,0,0,0.15);
    --shadow-fab: 0 6px 12px rgba(0,0,0,0.2);
    --app-bar-height: 56px;
    --bottom-nav-height: 56px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Roboto', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    width: 100vw;
    height: 100vh;
    max-width: 480px;
    margin: 0 auto;
    background: var(--background);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* App Bar */
.app-bar {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: var(--app-bar-height);
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-elevated);
    z-index: 100;
}

.app-bar-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 4px;
}

.app-bar-title {
    font-size: 20px;
    font-weight: 500;
    flex: 1;
    text-align: center;
}

.icon-btn {
    width: 48px;
    height: 48px;
    border: none;
    background: transparent;
    color: inherit;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.icon-btn:active {
    background: rgba(255,255,255,0.2);
}

/* Content Area */
.content-area {
    flex: 1;
    margin-top: var(--app-bar-height);
    margin-bottom: var(--bottom-nav-height);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.screen {
    display: none;
    padding: 16px;
    min-height: calc(100vh - var(--app-bar-height) - var(--bottom-nav-height));
    animation: slideIn 0.3s ease-out;
}

.screen.active {
    display: block;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.stat-icon .material-icons {
    font-size: 28px;
}

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

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

/* Section Header */
.section-header {
    margin: 24px 0 12px;
}

.section-header h2 {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Quick Actions */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.action-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
}

.action-card:active {
    transform: scale(0.95);
    box-shadow: var(--shadow-elevated);
}

.action-card .material-icons {
    font-size: 32px;
    color: var(--primary);
}

.action-card span:last-child {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
}

/* Card */
.card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}

/* Search Bar */
.search-bar {
    background: var(--surface);
    border-radius: 28px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.search-bar .material-icons {
    color: var(--text-hint);
    font-size: 24px;
}

.search-bar input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: 'Roboto', sans-serif;
    background: transparent;
    color: var(--text-primary);
}

.search-bar input::placeholder {
    color: var(--text-hint);
}

/* Filter Chips */
.filter-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 16px;
    -webkit-overflow-scrolling: touch;
}

.filter-chips::-webkit-scrollbar {
    display: none;
}

.chip {
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow);
}

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

.chip:active {
    transform: scale(0.95);
}

/* Recipe Grid */
.recipe-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.recipe-card {
    background: var(--surface);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform var(--transition);
}

.recipe-card:active {
    transform: scale(0.97);
}

.recipe-card-image {
    width: 100%;
    height: 140px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 48px;
}

.recipe-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.recipe-card-content {
    padding: 12px;
}

.recipe-card-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.recipe-card-meta {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.recipe-card-meta .material-icons {
    font-size: 14px;
}

/* Recipe List */
.recipe-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.recipe-list-item {
    background: var(--surface);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform var(--transition);
}

.recipe-list-item:active {
    transform: scale(0.98);
}

.recipe-list-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    flex-shrink: 0;
}

.recipe-list-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

.recipe-list-content {
    flex: 1;
    min-width: 0;
}

.recipe-list-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recipe-list-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recipe-list-chevron {
    color: var(--text-hint);
}

/* Meal Plan List */
.meal-plan-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.meal-plan-item {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    position: relative;
}

.meal-plan-date {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    margin-bottom: 8px;
}

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

.meal-type-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
}

.meal-type-badge.breakfast { background: #FFF3E0; color: #EF6C00; }
.meal-type-badge.lunch { background: #E8F5E9; color: #2E7D32; }
.meal-type-badge.dinner { background: #E3F2FD; color: #1565C0; }
.meal-type-badge.snack { background: #F3E5F5; color: #6A1B9A; }

.meal-plan-recipe {
    flex: 1;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

.meal-plan-delete {
    color: var(--text-hint);
    cursor: pointer;
}

/* Shopping List */
.shopping-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.shopping-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
}

.shopping-checkbox {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 2px solid var(--text-hint);
    cursor: pointer;
}

.shopping-checkbox.checked {
    background: var(--accent);
    border-color: var(--accent);
    position: relative;
}

.shopping-checkbox.checked::after {
    content: '✓';
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
}

.shopping-text {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
}

.shopping-text.checked {
    text-decoration: line-through;
    color: var(--text-hint);
}

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

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    min-height: 300px;
}

.empty-icon {
    font-size: 80px !important;
    color: var(--text-hint);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 20px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Roboto', sans-serif;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.btn-primary:active {
    transform: scale(0.97);
    background: var(--primary-dark);
}

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

.btn-secondary:active {
    background: rgba(255, 112, 67, 0.1);
}

.btn-danger {
    background: var(--error) !important;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: var(--bottom-nav-height);
    background: var(--surface);
    display: flex;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.1);
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    color: var(--text-hint);
    transition: color var(--transition);
    padding: 8px 0;
}

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

.nav-item .material-icons {
    font-size: 24px;
}

.nav-label {
    font-size: 12px;
    font-weight: 500;
}

/* FAB */
.fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 16px);
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    box-shadow: var(--shadow-fab);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    z-index: 99;
}

.fab:active {
    transform: scale(0.9);
}

.fab .material-icons {
    font-size: 28px;
}

/* Bottom Sheet */
.bottom-sheet {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: 100vh;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.bottom-sheet.active {
    display: block;
}

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

.bottom-sheet-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 90vh;
    background: var(--surface);
    border-radius: 24px 24px 0 0;
    overflow-y: auto;
    animation: slideUp 0.3s ease-out;
}

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

.bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--divider);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.bottom-sheet-header h2 {
    font-size: 20px;
    font-weight: 500;
}

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

.form-group {
    position: relative;
    margin-bottom: 24px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 16px 12px 8px;
    border: 1px solid var(--divider);
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Roboto', sans-serif;
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color var(--transition);
    outline: none;
}

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

.form-group label {
    position: absolute;
    left: 12px;
    top: 16px;
    font-size: 16px;
    color: var(--text-hint);
    pointer-events: none;
    transition: all var(--transition);
}

.form-group input:focus + label,
.form-group input:not(:placeholder-shown) + label,
.form-group input:valid + label,
.form-group textarea:focus + label,
.form-group textarea:not(:placeholder-shown) + label,
.form-group textarea:valid + label,
.form-group select:focus + label,
.form-group select:not([value=""]) + label {
    top: 4px;
    font-size: 12px;
    color: var(--primary);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

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

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions button {
    flex: 1;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: 100vh;
    background: var(--surface);
    z-index: 200;
    display: none;
    overflow-y: auto;
    animation: slideInRight 0.3s ease-out;
}

.modal.active {
    display: block;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%) translateX(-50%);
    }
    to {
        transform: translateX(0) translateX(-50%);
    }
}

.modal-content {
    min-height: 100vh;
}

.modal-header {
    position: sticky;
    top: 0;
    background: var(--surface);
    padding: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow);
    z-index: 1;
}

.modal-header h2 {
    flex: 1;
    font-size: 18px;
    font-weight: 500;
}

.modal-actions {
    display: flex;
    gap: 4px;
}

.modal-body {
    padding: 16px;
}

.detail-image {
    width: calc(100% + 32px);
    margin: -16px -16px 16px;
    height: 240px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 80px;
}

.detail-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail-meta {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 14px;
}

.meta-item .material-icons {
    font-size: 18px;
}

.detail-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.tag {
    padding: 6px 12px;
    border-radius: 16px;
    background: var(--secondary);
    color: var(--primary);
    font-size: 12px;
    font-weight: 500;
}

.detail-section {
    margin-bottom: 24px;
}

.detail-section h3 {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.ingredients-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ingredient-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
}

.ingredient-item::before {
    content: '•';
    color: var(--primary);
    font-weight: bold;
    font-size: 18px;
}

.instructions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.instruction-item {
    display: flex;
    gap: 12px;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.6;
}

.instruction-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 500;
    flex-shrink: 0;
}

/* Dialog */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: 100vh;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn 0.2s ease-out;
}

.dialog-overlay.active {
    display: flex;
}

.dialog {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    animation: scaleIn 0.2s ease-out;
}

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

.dialog h3 {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.dialog p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Snackbar */
.snackbar {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #323232;
    color: white;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: var(--shadow-elevated);
    z-index: 400;
    transition: transform var(--transition);
    max-width: calc(100% - 32px);
}

.snackbar.show {
    transform: translateX(-50%) translateY(0);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--divider);
    border-radius: 4px;
}

/* Loading Animation */
@keyframes shimmer {
    0% { background-position: -468px 0; }
    100% { background-position: 468px 0; }
}

.skeleton {
    background: linear-gradient(to right, #f0f0f0 8%, #e0e0e0 18%, #f0f0f0 33%);
    background-size: 800px 100px;
    animation: shimmer 1.5s infinite linear;
}

/* Responsive */
@media (max-width: 360px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 481px) {
    #app {
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
    }
}
