/* Google Fonts Import */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

/* CSS Variables for easy theme changes */
:root {
    --primary-bg-color: #5d2595; /* Deep purple, matching image background */
    --secondary-bg-color: #f76b1c; /* Orange, matching image accents */
    --card-bg-color: #ffffff; /* White for cards and main content area */
    --text-color-dark: #333;
    --text-color-light: #fff;
    --border-radius-lg: 25px; /* Large border-radius for main containers */
    --border-radius-md: 15px; /* Medium border-radius for cards, search bar */
    --border-radius-sm: 8px; /* Small border-radius for buttons */
    --shadow-soft: 0 4px 15px rgba(0, 0, 0, 0.1); /* Light shadow for elements */
    --shadow-deep: 0 8px 20px rgba(0, 0, 0, 0.2); /* Deeper shadow for main app container */
}

/* Base styles for the body */
body {
    font-family: 'Montserrat', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center; /* Center the app container horizontally */
    min-height: 100vh; /* Full viewport height */
    background: var(--primary-bg-color); /* Main background color */
    color: var(--text-color-dark); /* Default text color */
    box-sizing: border-box; /* Include padding/border in element's total width/height */
    overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Main Application Container */
.app-container {
    background: var(--primary-bg-color); /* Matches the purple background of the image */
    display: flex;
    flex-direction: column; /* Stack sections vertically */
    width: 100%;
    max-width: 450px; /* Max width to mimic a mobile app on larger screens */
    min-height: 100vh; /* Ensure it takes full height on small screens */
    box-shadow: var(--shadow-deep); /* Deep shadow for a lifted effect */
    position: relative; /* For positioning fixed elements like bottom nav */
}

/* Header Section */
.app-header {
    background: var(--primary-bg-color);
    padding: 25px 20px;
    padding-top: 40px; /* Extra top padding to resemble the mobile status bar area */
    color: var(--text-color-light); /* White text for header */
}

.welcome-section {
    margin-bottom: 25px;
}

.welcome-section span {
    font-size: 0.9em;
    font-weight: 500;
    opacity: 0.8; /* Slightly transparent for a softer look */
}

.welcome-section h1 {
    font-size: 1.8em;
    font-weight: 600;
    margin: 5px 0 0;
    line-height: 1.3; /* Adjust line height for readability */
}

/* Search Bar Styling */
.search-bar {
    display: flex;
    background: var(--secondary-bg-color); /* Orange background as in the image */
    border-radius: var(--border-radius-md);
    padding: 10px;
    align-items: center;
    box-shadow: var(--shadow-soft); /* Soft shadow for depth */
}

#recipeInput {
    flex-grow: 1; /* Allows input to fill available space */
    border: none;
    background: transparent; /* Transparent background to show orange */
    padding: 10px 15px;
    font-size: 1em;
    color: var(--text-color-light); /* White text for input */
    outline: none; /* Remove default focus outline */
}

#recipeInput::placeholder {
    color: rgba(255, 255, 255, 0.7); /* Lighter placeholder text */
}

#recipeInput:focus {
    color: var(--text-color-light); /* Ensure text stays white on focus */
}

#searchBtn {
    background: var(--text-color-light); /* White button background */
    border: none;
    border-radius: var(--border-radius-sm);
    padding: 10px 15px;
    color: var(--secondary-bg-color); /* Orange icon color */
    font-size: 1.1em;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease; /* Smooth hover effects */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

#searchBtn:hover {
    transform: translateY(-1px); /* Slight lift on hover */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

#searchBtn:active {
    transform: translateY(0); /* Return to normal on click */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Category Buttons Section */
.categories-section {
    background: var(--primary-bg-color);
    padding: 15px 20px;
    border-bottom: 5px solid var(--secondary-bg-color); /* Orange line as in the image */
}

.category-buttons {
    display: flex;
    overflow-x: auto; /* Enable horizontal scrolling for many categories */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    padding-bottom: 10px; /* Space for scrollbar if it appears */
    scrollbar-width: none; /* Hide scrollbar for Firefox */
    -ms-overflow-style: none; /* Hide scrollbar for IE/Edge */
}

.category-buttons::-webkit-scrollbar { /* Hide scrollbar for Chrome/Safari */
    display: none;
}

.category-btn {
    flex-shrink: 0; /* Prevent buttons from shrinking when space is limited */
    background: var(--secondary-bg-color); /* Orange background */
    color: var(--text-color-light);
    border: none;
    border-radius: var(--border-radius-sm);
    padding: 8px 15px;
    margin-right: 10px; /* Space between buttons */
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
    box-shadow: var(--shadow-soft);
}

.category-btn:last-child {
    margin-right: 0; /* No margin on the last button */
}

.category-btn:hover {
    background: #e65c15; /* Darker orange on hover */
    transform: translateY(-1px);
}

.category-btn.active {
    background: var(--card-bg-color); /* White background for active category */
    color: var(--secondary-bg-color); /* Orange text for active category */
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1); /* Inset shadow for active state */
}

/* Recipe Results Section */
.recipes-section {
    flex-grow: 1; /* Allows this section to fill remaining vertical space */
    background: var(--card-bg-color); /* White background for the main content area */
    padding: 25px 20px 25px; /* Adjusted padding as bottom nav is removed */
    border-top-left-radius: var(--border-radius-lg);
    border-top-right-radius: var(--border-radius-lg);
    position: relative; /* For positioning loading/error messages */
    z-index: 1; /* Ensure it's above the bottom nav bar (if it were still there) */
}

#resultsTitle {
    font-size: 1.5em;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-color-dark);
    text-align: left;
}

/* Loading and Error Message Overlays */
.loading-indicator, .error-message {
    position: absolute; /* Position relative to .recipes-section */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Center perfectly */
    font-size: 1.1em;
    font-weight: 500;
    color: #666;
    background: rgba(255, 255, 255, 0.8);
    padding: 15px 25px;
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-soft);
    white-space: nowrap; /* Prevent text wrapping */
    z-index: 10; /* Ensure it's on top of recipe grid */
}

.loading-indicator i, .error-message i {
    margin-right: 10px;
}

.loading-indicator i {
    color: var(--primary-bg-color);
}

.error-message {
    color: #e74c3c; /* Red text for errors */
    background: #ffe0e0; /* Light red background for error box */
}
.error-message i {
    color: #e74c3c; /* Red icon for errors */
}

/* Recipe Grid Layout */
.recipe-grid {
    display: grid;
    /* Responsive grid: auto-fit creates columns, minmax sets min/max width */
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px; /* Space between recipe cards */
}

.recipe-card {
    background: var(--card-bg-color);
    border-radius: var(--border-radius-md);
    overflow: hidden; /* Ensures image corners are rounded */
    box-shadow: var(--shadow-soft);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease; /* Smooth hover effects */
    position: relative; /* For heart icon positioning */
    display: flex;
    flex-direction: column; /* Stack image and info vertically */
}

.recipe-card:hover {
    transform: translateY(-5px); /* Slight lift on hover */
    box-shadow: var(--shadow-deep); /* Deeper shadow on hover */
}

.recipe-card img {
    width: 100%;
    height: 120px; /* Fixed height for recipe images */
    object-fit: cover; /* Ensures image covers the area without distortion */
    border-top-left-radius: var(--border-radius-md);
    border-top-right-radius: var(--border-radius-md);
}

.recipe-info {
    padding: 10px 10px 15px;
    text-align: left;
    flex-grow: 1; /* Allows info section to expand and push meta to bottom */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.recipe-card h3 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 5px 0 10px;
    color: var(--text-color-dark);
    line-height: 1.4;
}

.recipe-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9em;
    color: #666;
}

.recipe-meta .rating {
    display: flex;
    align-items: center;
    gap: 5px;
}

.recipe-meta .rating i {
    color: gold; /* Star icon color */
}

.recipe-meta .fav-btn {
    background: none;
    border: none;
    color: #ccc; /* Default heart color (grey) */
    cursor: pointer;
    font-size: 1.1em;
    transition: color 0.2s ease;
}

.recipe-meta .fav-btn.active {
    color: #e74c3c; /* Red heart when favorited */
}


/* Recipe Details Modal */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1000; /* Sit on top of everything */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if content overflows */
    background-color: rgba(0,0,0,0.6); /* Dark overlay background */
    justify-content: center; /* Center content horizontally */
    align-items: center; /* Center content vertically */
}

.modal-content {
    background-color: var(--card-bg-color);
    margin: auto;
    padding: 25px;
    border-radius: var(--border-radius-lg);
    width: 90%;
    max-width: 600px; /* Max width for the modal */
    box-shadow: var(--shadow-deep);
    position: relative;
    animation: fadeIn 0.3s ease-out; /* Fade-in animation */
    max-height: 90vh; /* Limit modal height to 90% of viewport height */
    overflow-y: auto; /* Enable scrolling within modal content if needed */
}

/* Modal Fade-in Animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.close-button {
    color: #aaa;
    position: absolute;
    top: 15px;
    right: 25px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s ease;
}

.close-button:hover,
.close-button:focus {
    color: var(--primary-bg-color);
}

#modalRecipeTitle {
    font-size: 1.8em;
    font-weight: 700;
    color: var(--primary-bg-color);
    margin-bottom: 15px;
}

#modalRecipeImage {
    width: 100%;
    max-height: 250px;
    object-fit: cover;
    border-radius: var(--border-radius-md);
    margin-bottom: 20px;
}

.modal-body h3 {
    font-size: 1.3em;
    color: var(--secondary-bg-color);
    margin-top: 20px;
    margin-bottom: 10px;
}

#modalIngredientsList {
    list-style-type: disc; /* Bullet points for ingredients */
    padding-left: 20px;
    font-size: 1em;
    line-height: 1.6;
    color: #555;
}

#modalIngredientsList li::marker {
    color: var(--secondary-bg-color); /* Color the bullet points orange */
}

#modalInstructions {
    font-size: 1em;
    line-height: 1.7;
    color: #555;
    white-space: pre-wrap; /* Preserves newlines and spacing from API text */
}

#modalYoutubeLink {
    display: inline-block;
    background-color: #ff0000; /* YouTube red */
    color: var(--text-color-light);
    padding: 10px 15px;
    border-radius: var(--border-radius-sm);
    text-decoration: none;
    font-weight: 600;
    margin-top: 20px;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

#modalYoutubeLink:hover {
    background-color: #cc0000;
    transform: translateY(-2px);
}

/* --- Responsive Adjustments (Media Queries) --- */

/* For Tablets and smaller desktops (max-width: 768px) */
@media (max-width: 768px) {
    .app-container {
        max-width: 100%; /* Allow full width on tablets */
        box-shadow: none; /* Remove box-shadow for a cleaner edge-to-edge look */
        border-radius: 0;
    }

    .app-header {
        padding: 20px 15px;
        padding-top: 30px;
    }

    .welcome-section h1 {
        font-size: 1.6em;
    }

    .search-bar {
        padding: 8px;
    }

    #recipeInput {
        padding: 8px 12px;
        font-size: 0.95em;
    }

    #searchBtn {
        padding: 8px 12px;
        font-size: 1em;
    }

    .categories-section {
        padding: 10px 15px;
    }

    .category-btn {
        padding: 7px 12px;
        font-size: 0.85em;
        margin-right: 8px;
    }

    .recipes-section {
        padding: 20px 15px 20px; /* Adjusted padding as bottom nav is removed */
    }

    #resultsTitle {
        font-size: 1.4em;
        margin-bottom: 15px;
    }

    .recipe-grid {
        /* Adjust minmax for slightly smaller cards on tablets */
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
        gap: 15px;
    }

    .recipe-card img {
        height: 100px; /* Smaller image height */
    }

    .recipe-card h3 {
        font-size: 1em;
    }

    .modal-content {
        width: 95%;
        padding: 20px;
        border-radius: var(--border-radius-md);
    }

    #modalRecipeTitle {
        font-size: 1.5em;
    }

    #modalRecipeImage {
        max-height: 200px;
    }

    .modal-body h3 {
        font-size: 1.2em;
    }

    #modalIngredientsList, #modalInstructions {
        font-size: 0.95em;
    }
}

/* For Mobile devices (max-width: 480px) */
@media (max-width: 480px) {
    .app-container {
        min-height: 100vh; /* Ensure it takes full viewport height */
    }

    .app-header {
        padding: 15px 10px;
        padding-top: 25px;
    }

    .welcome-section h1 {
        font-size: 1.4em;
    }

    .search-bar {
        flex-direction: column; /* Stack input and button vertically */
        padding: 8px;
    }

    #recipeInput {
        width: 100%;
        margin-bottom: 10px; /* Space between input and button when stacked */
    }

    #searchBtn {
        width: 100%; /* Full width button */
        border-radius: var(--border-radius-md); /* Make it rectangular */
    }

    .categories-section {
        padding: 10px 10px;
    }

    .category-buttons {
        padding-bottom: 5px; /* Less space for scrollbar */
    }

    .category-btn {
        padding: 6px 10px;
        font-size: 0.8em;
        margin-right: 6px;
    }

    .recipes-section {
        padding: 15px 10px 15px; /* Further adjusted padding */
    }

    #resultsTitle {
        font-size: 1.2em;
        margin-bottom: 10px;
    }

    .recipe-grid {
        grid-template-columns: 1fr; /* Single column layout on very small screens */
        gap: 10px;
    }

    .recipe-card img {
        height: 150px; /* Can be taller in single column layout */
    }

    .recipe-card h3 {
        font-size: 1.1em;
    }

    .recipe-meta {
        font-size: 0.85em;
    }

    .modal-content {
        padding: 15px;
    }

    #modalRecipeTitle {
        font-size: 1.3em;
    }

    #modalRecipeImage {
        max-height: 180px;
    }

    .modal-body h3 {
        font-size: 1.1em;
    }

    #modalIngredientsList, #modalInstructions {
        font-size: 0.9em;
    }
}
