/* public/style.css */

/* --- CSS Variables --- */
:root {
    --bg-color: #121212;
    --sidebar-bg-color: #000000;
    --surface-color: #181818;
    --surface-highlight-color: #282828;
    --primary-accent-color: #1DB954; 
    --secondary-accent-color: #B3B3B3;
    --text-color: #FFFFFF;
    --text-secondary-color: #B3B3B3;
    --danger-color: #E57373;
    --border-color: #282828;
    --border-radius: 8px;
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    --font-primary: 'Inter', sans-serif;
}

/* --- Base & Typography --- */
*, *::before, *::after { box-sizing: border-box; }
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevent body scrolling */
}
body {
    font-family: var(--font-primary);
    line-height: 1.5; /* Reduced line-height */
    background-color: var(--bg-color);
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 14px; /* Slightly smaller base font */
}

h1, h2, h3, h4, h5 {
    font-weight: 700;
    margin-top: 0;
    color: var(--text-color);
}
h2 { font-size: 1.5rem; margin-bottom: 1rem; text-align: left; } /* Reduced font size and margin */
h3 { font-size: 1.1rem; margin-bottom: 0.75rem; } /* Reduced font size and margin */
/* UPDATE: Added styles for links within headers */
h3 a {
    color: inherit;
    text-decoration: none;
}
h3 a:hover {
    text-decoration: underline;
}
h4 {
    margin-top: 1.5rem; /* Reduced margin */
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.4rem;
    font-weight: 500;
    color: var(--text-secondary-color);
}
p { color: var(--text-secondary-color); margin-top: 0; margin-bottom: 0.75rem; }
hr { border: none; border-top: 1px solid var(--border-color); margin: 1.5rem 0; } /* Reduced margin */
ul { list-style-type: none; padding: 0; }
li {
    background-color: var(--surface-highlight-color);
    padding: 0.3rem; /* Reduced padding */
    border-radius: var(--border-radius);
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
}
a { color: var(--text-color); text-decoration: none; }
a:hover { color: var(--primary-accent-color); }

/* --- Main App Layout --- */
#app-container {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 1fr;
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height */
    width: 100vw;
    position: relative; /* ADDED: This makes it the positioning context for the toast */
}

/* --- Sidebar --- */
.sidebar {
    background-color: var(--sidebar-bg-color);
    padding: 1rem; /* Reduced padding */
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.sidebar-header { margin-bottom: 1.5rem; }
.sidebar-logo { width: 100%; max-width: 200px; height: auto; }
.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* Reduced gap */
    padding: 0.3rem; /* Further reduced padding */
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.85rem; /* Reduced font size */
    color: var(--text-secondary-color);
    transition: color 0.2s, background-color 0.2s;
}
.sidebar-nav li a:hover, .sidebar-nav li a.active {
    color: var(--text-color);
    background-color: var(--surface-highlight-color);
}
.sidebar-nav li a i { font-size: 1.25rem; width: 20px; text-align: center; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar-footer a {
    color: var(--text-secondary-color);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem;
    border-radius: 4px;
}
.sidebar-footer a:hover { color: var(--text-color); background-color: var(--surface-highlight-color); }

/* --- Sidebar Calendar --- */
#sidebar-calendar-container-desktop, #sidebar-calendar-container-mobile {
    background-color: transparent; /* Removed background */
    border-radius: var(--border-radius);
    padding: 0.75rem;
    margin-top: 1rem;
}
.sidebar-calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.sidebar-calendar-header h5 {
    margin: 0;
    font-size: 0.9rem;
    flex-grow: 1;
    text-align: center;
}
/* UPDATED: Styles for the new navigation buttons */
.sidebar-calendar-header button {
    background: none;
    border: none;
    color: var(--text-secondary-color);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.5rem;
    line-height: 1; /* Ensure button height is minimal */
    text-transform: none; /* Override global button styles */
    letter-spacing: normal; /* Override global button styles */
}
.sidebar-calendar-header button:hover {
    color: var(--text-color);
}

.sidebar-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    text-align: center;
}
.sidebar-calendar-day-name {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary-color);
}
.sidebar-calendar-day {
    font-size: 0.8rem;
    padding: 2px;
    border-radius: 3px;
    position: relative;
    cursor: pointer;
}
.sidebar-calendar-day.has-meal {
    background-color: rgba(29, 185, 84, 0.3);
}
.sidebar-calendar-day.current-week {
    box-shadow: 0 0 0 1px var(--primary-accent-color) inset;
}


/* --- Main Content Area (MODIFIED) --- */
.main-content {
    display: grid;
    grid-template-rows: auto 1fr; /* Header takes auto height, wrapper takes the rest */
    overflow: hidden; /* Prevent this container from scrolling */
    min-width: 0; /* ADDED: Prevents grid blowout */
}
.top-bar {
    background: linear-gradient(to bottom, rgba(0,0,0,0.7), rgba(0,0,0,0));
    padding: 0.75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}
.content-wrapper {
    overflow-y: auto; /* This is now the main scrollable area */
    padding: 0.75rem 1.5rem;
}
.content-section { display: none; }
.content-section.active { display: block; }

/* --- Auth & Household --- */
#auth-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Align items to the top */
    width: 100%;
    gap: 1rem;
}
.auth-left, .auth-right {
    display: flex;
    flex-direction: column;
}
.auth-left {
    align-items: flex-start;
}
.auth-right {
    align-items: flex-end;
}
#welcome-message {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}
#household-status-info {
    font-size: 0.8rem;
    margin: 0;
}
.household-code-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--surface-highlight-color);
    padding: 4px 8px;
    border-radius: 50px;
    margin-bottom: 0.5rem;
}
.invite-code-wrapper {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    text-align: left;
}
.invite-code-wrapper span {
    font-size: 0.7em;
}
.invite-code-wrapper strong {
    font-size: 1em;
}
#sign-out-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.auth-view { max-width: 400px; margin: 3rem auto; padding: 1.5rem; background-color: var(--surface-color); border-radius: var(--border-radius); text-align: center; }
.household-action { margin: 1rem 0; }

/* --- General UI Elements --- */
section {
    background-color: transparent;
    padding: 0;
    border: none;
    box-shadow: none;
    margin-top: 0;
}
button {
    background-color: var(--primary-accent-color);
    color: #000;
    padding: 10px 20px; /* Reduced padding */
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-size: 0.9em; /* Reduced font size */
    font-weight: 700;
    transition: transform 0.1s ease-in-out, background-color 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}
button:hover:not(:disabled) { transform: scale(1.05); background-color: #1ed760; }
button:disabled { background-color: #535353; color: #a7a7a7; cursor: not-allowed; }
button.secondary { background-color: var(--surface-highlight-color); color: var(--text-color); }
button.secondary:hover:not(:disabled) { background-color: #3e3e3e; }
button.danger { background-color: #d9534f; color: var(--text-color); }
button.upgrade-button { background-color: #fff; color: #000; }
.social-signin-btn.google { background-color: #4285F4; color: #fff;}
.link-button { background: none; border: none; color: var(--primary-accent-color); text-decoration: underline; cursor: pointer; padding: 0; font-size: 0.9em; margin-top: 1rem; text-transform: none; letter-spacing: normal;}

input, select, textarea {
    background-color: var(--surface-highlight-color);
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-color);
    padding: 10px; /* Reduced padding */
    font-size: 0.9em; /* Reduced font size */
    width: 100%;
    margin-bottom: 8px; /* Reduced margin */
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-accent-color); background-color: #333; }

/* --- Recipe Cards --- */
#recipe-results, #favorite-recipes-container .recipe-card-row, #community-recipes-container .recipe-card-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
}
.recipe-card {
    background-color: var(--surface-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: background-color 0.3s;
    /* cursor: pointer; */
    padding: 0.75rem; /* Reduced padding */
    position: relative;
    display: flex;
    flex-direction: column;
}
/*.recipe-card:hover { background-color: var(--surface-highlight-color); }*/
.recipe-card img.recipe-image { width: 100%; height: 150px; object-fit: cover; border-radius: var(--border-radius); margin-bottom: 0.75rem; }
.recipe-card h3 { font-size: 0.95rem; margin: 0 0 0.25rem 0; white-space: normal; }
.recipe-card p {
    font-size: 0.85rem;
    color: var(--text-secondary-color);
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 0.5rem;
    flex-grow: 1; /* Allow description to take up space */
}
/* NEW: Serving size info */
.serving-size-info {
    font-size: 0.8rem;
    color: var(--text-secondary-color);
    margin: 0.25rem 0 0.5rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
/* NEW: Adjust modal serving size style */
#recipe-detail-content .serving-size-info,
.modal-recipe-item .serving-size-info {
    font-size: 1rem;
    margin-bottom: 1rem;
}
/* NEW: Nutrition Info on Recipe Card */
.recipe-card .nutrition-info {
    display: flex;
    justify-content: space-around;
    font-size: 0.7rem;
    color: var(--text-secondary-color);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--surface-highlight-color);
    gap: 4px;
    text-align: center;
}
.nutrition-info .nutrition-item {
    display: flex;
    flex-direction: column;
}
.nutrition-info .nutrition-value {
    font-weight: 700;
    color: var(--text-color);
}
.recipe-card.expanded p {
    -webkit-line-clamp: unset;
}
.save-recipe-btn { position: absolute; top: 1rem; right: 1rem; background: none; border: none; font-size: 1.5rem; color: rgba(255,255,255,0.7); text-shadow: 0 1px 3px rgba(0,0,0,0.5); cursor: pointer; }
.save-recipe-btn.is-favorite { color: var(--primary-accent-color); }

/* --- Meal Planner --- */
.meal-plan-container { margin-top: 1.5rem; }
#meal-planner-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.75rem;
}
.day-card { background-color: var(--surface-color); border-radius: var(--border-radius); padding: 0.75rem; }
.day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    cursor: pointer;
}
.day-card.today .day-header { color: var(--primary-accent-color); }
.day-card.collapsed > *:not(.day-header) {
    display: none;
}
.meal-slot { min-height: 50px; background-color: var(--bg-color); border: 2px dashed var(--surface-highlight-color); border-radius: 4px; padding: 4px; }
.meal-slot.drag-over { border-color: var(--primary-accent-color); }
.meal-slot .recipe-title {
    background-color: var(--surface-highlight-color);
    color: var(--text-color);
    font-size: 0.8em;
    padding: 4px 6px;
    border-radius: 4px;
}
.meal-slot .recipe-title span {
    white-space: normal;
    word-break: break-word;
    display: inline-block;
}


/* --- Modals --- */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.7); backdrop-filter: blur(5px); }
.modal-content { background-color: var(--surface-color); margin: 5% auto; padding: 1.5rem; border: 1px solid var(--border-color); width: 90%; max-width: 600px; border-radius: var(--border-radius); box-shadow: var(--shadow-md); position: relative; }
.close-btn { color: var(--secondary-accent-color); position: absolute; top: 0.75rem; right: 1rem; font-size: 2rem; font-weight: bold; cursor: pointer; }
.close-btn:hover { color: var(--text-color); }

/* --- Add to Plan Calendar --- */
#calendar-container {
    margin: 1rem 0;
}
#calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
#calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    text-align: center;
}
.calendar-day-name {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text-secondary-color);
}
.calendar-day {
    padding: 0.5rem 0;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s;
}
.calendar-day:hover {
    background-color: var(--surface-highlight-color);
}
.calendar-day.today {
    border: 1px solid var(--primary-accent-color);
}
.calendar-day.selected {
    background-color: var(--primary-accent-color);
    color: #000;
    font-weight: 700;
}

/* --- Specific Component Styles (Adapted) --- */
.inline-form {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}
.inline-form > input,
.inline-form > select {
    flex: 1; /* Allows the element to grow and fill available space */
    min-width: 0; /* Prevents overflow in flex containers */
}
.pantry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 1rem;
    margin-bottom: 1rem;
}
.pantry-header h2 {
    margin-bottom: 0; /* Remove default margin from h2 */
}
.pantry-controls, .button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.pantry-item, .grocery-item { display: flex; justify-content: space-between; align-items: center; padding: .3rem; }
.pantry-item .item-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-grow: 1; /* Allow this section to take up available space */
    min-width: 0; /* Crucial for allowing long text to wrap correctly in a flex item */
}
.pantry-item.checked .item-info {
    text-decoration: line-through;
    color: var(--text-secondary-color);
}
.pantry-item .item-info input[type="checkbox"] {
    /* Override global input styles for the checkbox */
    width: auto; /* Prevent it from taking 100% width */
    margin-bottom: 0; /* Remove the default margin for inputs */
    flex-shrink: 0; /* Prevent the checkbox from being squished */
}
.pantry-item .item-info span {
    white-space: normal;
    word-break: break-word;
}
.grocery-item .item-info { display: flex; align-items: center; gap: 0.5rem; }
.grocery-item.checked .item-info { text-decoration: line-through; color: var(--text-secondary-color); }
.grocery-item .item-info input[type="checkbox"] {
    /* Override global input styles for the checkbox */
    width: auto; /* Prevent it from taking 100% width */
    margin-bottom: 0; /* Remove the default margin for inputs */
    flex-shrink: 0; /* Prevent the checkbox from being squished */
}
.grocery-item-controls { display: flex; align-items: center; gap: 0.5rem; }
.walmart-search-btn {
    background-color: #0071ce;
    color: #ffc220;
    border-radius: 50px;
    width: auto;
    height: 28px;
    padding: 0 12px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    text-decoration: none;
    font-size: 0.8rem;
    line-height: 1;
    font-family: sans-serif;
}

.week-navigation { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.week-navigation h3 {
    flex-grow: 1;
    text-align: center;
}
.source-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-color); margin-bottom: 1.5rem; }
.source-tabs button { background: none; border: none; border-bottom: 3px solid transparent; color: var(--text-secondary-color); padding: 6px 10px; font-size: 1em; font-weight: 500; text-transform: none; letter-spacing: 0; border-radius: 0; }
.source-tabs button.active { color: var(--primary-accent-color); border-bottom-color: var(--primary-accent-color); }

.meal-type-selector {
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 0.75rem;
    margin: 1.5rem auto;
    max-width: 500px;
}
.meal-type-selector label { cursor: pointer; flex: 1; min-width: 120px; }
.meal-type-selector input { position: absolute; opacity: 0; }
.meal-type-selector span {
    display: block; /* Make span fill the label */
    text-align: center; /* Center the text */
    padding: 6px 14px;
    border-radius: 50px;
    border: 1px solid var(--surface-highlight-color);
    transition: all 0.2s;
    background-color: var(--surface-highlight-color);
    font-size: 0.9rem;
}
.meal-type-selector input:checked + span { background-color: var(--primary-accent-color); color: #000; border-color: var(--primary-accent-color); }

.recipe-criteria { background-color: var(--surface-color); padding: 1rem; border-radius: var(--border-radius); margin: 1.5rem 0; }
.collapsible-header { cursor: pointer; }
.collapsible-content { max-height: 0; overflow: hidden; transition: max-height 0.4s ease-out; }

.recipe-options-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end; /* Vertically align items to their bottom edge */
    width: 100%;
    margin-bottom: 1rem;
}

.form-control-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex-grow: 1;
    flex-basis: 200px; /* Base width before wrapping */
}

.form-control-wrapper label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-secondary-color);
    margin-bottom: 0.25rem;
}

.form-control-wrapper button {
    width: 100%; /* Make button fill its wrapper */
}

.form-control-wrapper .toggle-switch {
   width: fit-content; /* Prevent the toggle switch from expanding */
}

.criteria-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
}
.criteria-row {
    display: flex;
    gap: 1.5rem;
}
.criteria-row .criteria-group {
    flex: 1;
}
.criteria-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.sub-criteria-group {
    min-width: 0; /* Fix for flexbox overflow */
    overflow: hidden; /* Contain the horizontally-scrolling checkbox group */
    display: grid; /* Use grid layout for more robust containment of the scrolling child */
}
.sub-criteria-group h4 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    border-bottom: none;
    padding-bottom: 0;
}
.criteria-group > label {
    font-weight: 700;
    margin-bottom: -4px;
}

.checkbox-group {
    display: flex;
    flex-wrap: nowrap; /* Reverted to horizontal scroll */
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 10px; /* Space for scrollbar */
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}
.checkbox-group::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}
.checkbox-group label {
    display: block;
    position: relative;
}
.checkbox-group input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.checkbox-group span {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 50px;
    border: 1px solid var(--surface-highlight-color);
    background-color: var(--surface-highlight-color);
    color: var(--text-color);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.checkbox-group input[type="checkbox"]:checked + span {
    background-color: var(--primary-accent-color);
    color: #000;
    border-color: var(--primary-accent-color);
}

.premium-feature.disabled { 
    opacity: 0.5; 
    /* pointer-events: none; - REMOVED */
}
.premium-tag { background-color: var(--primary-accent-color); color: #000; font-size: 0.7em; padding: 2px 6px; border-radius: 4px; margin-left: 0.5rem; font-weight: bold; }
.toggle-switch {
    display: flex;
    border: 1px solid var(--surface-highlight-color);
    border-radius: 50px;
    overflow: hidden; /* Ensures children conform to the rounded corners */
    background-color: var(--surface-highlight-color);
}
.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-switch label {
    flex: 1; /* Each label takes up equal space */
    padding: 6px 14px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0; /* Override global input/label margins */
    font-size: 0.9rem;
}
.toggle-switch input:checked + label {
    background-color: var(--primary-accent-color);
    color: #000;
    font-weight: 700;
    border-radius: 50px;
}

/* --- Scan Modal (MODIFIED) --- */
#scan-item-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: none; /* Toggled by JS to 'flex' */
    align-items: center;
    justify-content: center;
    z-index: 1001;
    padding: 1rem;
}

.scan-modal-content {
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative; /* For the close button */
}

#camera-controls { display: flex; gap: 1rem; justify-content: center; margin-top: 1rem; }
#camera-container { width: 100%; position: relative; padding-top: 75%; background-color: #000; border-radius: var(--border-radius); overflow: hidden; }
#camera-stream { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
#captured-image { max-width: 100%; border-radius: var(--border-radius); }

/* --- Toast Notification --- */
#toast-notification {
    visibility: hidden;
    min-width: 250px;
    background-color: var(--primary-accent-color);
    color: #000;
    text-align: center;
    border-radius: 4px;
    padding: 16px;
    position: absolute; /* Changed from fixed */
    z-index: 2000;
    left: 50%;
    transform: translateX(-50%);
    bottom: 30px;
    font-size: 1rem;
    font-weight: 700;
}
#toast-notification.show {
    visibility: visible;
    -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
    animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@-webkit-keyframes fadein { from {bottom: 0; opacity: 0;} to {bottom: 30px; opacity: 1;} }
@keyframes fadein { from {bottom: 0; opacity: 0;} to {bottom: 30px; opacity: 1;} }
@-webkit-keyframes fadeout { from {bottom: 30px; opacity: 1;} to {bottom: 0; opacity: 0;} }
@keyframes fadeout { from {bottom: 30px; opacity: 1;} to {bottom: 0; opacity: 0;} }


/* --- NEW RECIPE DETAIL MODAL --- */
#recipe-detail-content {
    max-height: 80vh;
    overflow-y: auto;
}
#recipe-detail-content .recipe-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
}
#recipe-detail-content h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}
#recipe-detail-content .star-rating {
    margin-bottom: 1rem;
    font-size: 1.5rem;
}
#recipe-detail-content .star {
    cursor: pointer;
    color: var(--surface-highlight-color);
}
#recipe-detail-content .star.filled {
    color: var(--primary-accent-color);
}
#recipe-detail-content .nutrition-info {
    display: flex;
    justify-content: space-around;
    background-color: var(--bg-color);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin-top: 1rem;
    text-align: center;
}
/* UPDATED: Unified margin for all button containers in recipe detail modal */
#recipe-detail-content .card-actions,
#recipe-detail-content .ingredients-container,
#recipe-detail-content .instructions-container {
    margin-top: 1rem;
    margin-bottom: 0.75rem; /* Ensures spacing below each button/group */
}

/* --- NEW: Loading Animation --- */
.loading-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
    background-color: var(--surface-color);
    border-radius: var(--border-radius);
    color: var(--text-secondary-color);
}

.loading-card .chef-loader {
    font-size: 3rem;
    color: var(--primary-accent-color);
    animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.7;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* FIX: How-To Modal Styles */
.how-to-slider {
    position: relative;
    min-height: 150px; /* Give it some space */
    text-align: center;
}
.how-to-slide {
    display: none; /* Hide all slides by default */
}
.how-to-slide.active {
    display: block; /* Show only the active slide */
    animation: fadein 0.5s;
}
.how-to-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
}
.how-to-dots {
    display: flex;
    gap: 8px;
}
.how-to-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--surface-highlight-color);
    transition: background-color 0.3s;
}
.how-to-dot.active {
    background-color: var(--primary-accent-color);
}

/* NEW: Upgrade Modal Styles */
#upgrade-modal .modal-content {
    text-align: center;
    max-width: 450px;
}
#upgrade-modal h3 {
    color: var(--primary-accent-color);
    font-size: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}
#upgrade-modal .premium-features-list {
    list-style: none;
    padding: 0;
    margin: 1.5rem 0;
    text-align: left;
    display: inline-block;
}
#upgrade-modal .premium-features-list li {
    background: none;
    border: none;
    padding: 0.5rem 0;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
#upgrade-modal .premium-features-list .fa-check-circle {
    color: var(--primary-accent-color);
}
#upgrade-modal .upgrade-button {
    width: 100%;
    padding: 12px 24px;
    font-size: 1.1rem;
    background-color: var(--primary-accent-color);
    color: #000;
}
#upgrade-modal .upgrade-button:hover {
    background-color: #1ed760;
}

/* NEW: Onboarding Tour Styles */
#tour-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    pointer-events: none; /* Allows clicks to pass through */
    display: none;
}

.tour-highlight {
    position: relative;
    z-index: 10001;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    pointer-events: all !important; /* Make sure highlighted element is clickable */
}

#tour-tooltip {
    position: fixed;
    background-color: var(--surface-color);
    color: var(--text-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    z-index: 10002;
    max-width: 300px;
    border: 1px solid var(--border-color);
    display: none;
    /* ADDED: visibility property for smoother rendering */
    visibility: hidden;
}
#tour-tooltip h4 { margin-top: 0; color: var(--primary-accent-color); }
#tour-tooltip .tour-navigation { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }
#tour-tooltip .tour-navigation .tour-step-counter { font-size: 0.8rem; color: var(--text-secondary-color); white-space: nowrap; }
#tour-tooltip .tour-navigation div { display: flex; gap: 0.5rem; }
#tour-tooltip #tour-skip-btn { margin-top: 0.5rem; display: block; margin-left: auto; margin-right: auto; }

/* NEW: Mobile "More" Modal Styles */
.mobile-links-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.mobile-links-container a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    font-weight: 500;
}
.mobile-links-container a:hover {
    background-color: var(--surface-highlight-color);
}


/* --- Responsive Styles --- */
@media (min-width: 769px) {
    /* UPDATE: Horizontal scrolling for recipe results on desktop */
    #recipe-results, #community-recipes-container .recipe-card-row {
        display: flex;
        overflow-x: auto;
        gap: 1rem;
        padding-bottom: 1rem; /* Make space for scrollbar if visible */
    }
    #recipe-results .recipe-card, #community-recipes-container .recipe-card {
        flex: 0 0 220px; /* Don't shrink, don't grow, fixed width */
        width: 220px;
    }
    /* Hide scrollbar but keep it functional */
    #recipe-results::-webkit-scrollbar, #community-recipes-container .recipe-card-row::-webkit-scrollbar {
        height: 8px;
    }
    #recipe-results::-webkit-scrollbar-track, #community-recipes-container .recipe-card-row::-webkit-scrollbar-track {
        background: transparent;
    }
    #recipe-results::-webkit-scrollbar-thumb, #community-recipes-container .recipe-card-row::-webkit-scrollbar-thumb {
        background: var(--surface-highlight-color);
        border-radius: 4px;
    }
    #recipe-results::-webkit-scrollbar-thumb:hover, #community-recipes-container .recipe-card-row::-webkit-scrollbar-thumb:hover {
        background: #555;
    }
    #sidebar-calendar-container-mobile { display: none; } /* Hide mobile calendar on desktop */
    .mobile-only-nav { display: none; } /* Hide "More" button on desktop */
}

@media (max-width: 1400px) {
    #meal-planner-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
}

@media (max-width: 768px) {
    #app-container {
        grid-template-columns: 1fr; /* Single column layout */
        grid-template-rows: 1fr auto; /* Content on top, sidebar at bottom */
        height: 100vh; /* Fallback for older browsers */
        height: 100dvh; /* Dynamic viewport height */
        overflow: hidden; /* Prevent the whole container from scrolling */
    }
    .main-content {
        grid-row: 1 / 2;
    }
    .sidebar { 
        grid-row: 2 / 3;
        position: static; /* No longer fixed */
        flex-direction: row; 
        align-items: stretch;
        justify-content: space-around; 
        padding: 0; 
        border-top: 1px solid var(--border-color);
        background-color: var(--sidebar-bg-color);
        height: 55px; /* Fixed height for the nav bar */
        overflow: hidden; /* Prevent nav bar itself from scrolling */
    }
    .sidebar-header { display: none; }
    /* UPDATED: Hide the desktop footer and show the mobile "More" button */
    .sidebar-footer { display: none; }
    .mobile-only-nav { display: list-item; } /* Use list-item to match other nav items */

    .sidebar-nav { display: flex; justify-content: space-around; width: 100%; }
    .sidebar-nav li {
        flex: 1;
        margin-bottom: 0;
        background: none;
        border: none;
    }
    .sidebar-nav li a { 
        flex-direction: column; 
        gap: 2px; 
        font-size: 0.8rem; 
        text-align: center;
        padding: 0.4rem;
        height: 100%;
        border-radius: 0;
    }
    .sidebar-nav li a.active {
        background: var(--surface-highlight-color);
    }
    .sidebar-nav li a i { font-size: 1.1rem; }
    #sidebar-calendar-container-desktop { display: none; } /* Hide desktop calendar on mobile */

    .top-bar { background: var(--bg-color); padding: 0.75rem; }
    #auth-container {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        width: 100%;
        gap: 0.25rem 1rem;
        align-items: center;
    }
    .auth-left {
        grid-column: 1 / 2;
        grid-row: 1 / 3;
    }
    .auth-right {
        grid-column: 2 / 3;
        grid-row: 1 / 3;
    }
    .content-wrapper { padding: 0.75rem; }
    h2 { font-size: 1.4rem; }
    #recipe-results, #favorite-recipes-container .recipe-card-row, #community-recipes-container .recipe-card-row { 
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); 
        gap: 0.75rem; 
    }
    .recipe-card img.recipe-image { height: 120px; }
    #meal-planner-grid {
        grid-template-columns: 1fr;
    }
    .criteria-row {
        flex-direction: column;
    }
    .meal-type-selector {
        display: grid; /* Switch to grid on mobile */
        grid-template-columns: repeat(2, 1fr); /* 2x2 grid on mobile */
    }
    /* UPDATE: Smaller bulk action buttons on mobile */
    .bulk-controls button {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}
/* Style for the 'Remove from Plan' button in the modal */
.modal-recipe-item .remove-from-plan-btn {
    /* Positioning */
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10; /* Make sure it's on top of the image */

    /* Appearance */
    background-color: rgba(0, 0, 0, 0.6); /* Dark semi-transparent background */
    color: #FFFFFF; /* White 'X' */
    border: none;
    border-radius: 50%; /* Make it circular */
    width: 32px;
    height: 32px;
    font-size: 16px;
    font-weight: bold;
    line-height: 32px; /* Vertically center the 'X' */
    text-align: center;
    
    /* Remove default button padding and text transformations */
    padding: 0;
    text-transform: none;
    letter-spacing: normal;
    
    /* Add a subtle shadow for depth */
    text-shadow: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);

    /* Smooth transition for hover effect */
    transition: background-color 0.2s, transform 0.2s;
}

/* Hover effect */
.modal-recipe-item .remove-from-plan-btn:hover {
    background-color: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}