/* Variables */
:root {
    --primary-color: #4CAF50;
    /* Green accent */
    --background-color: #f4f7f6;
    --card-background: #ffffff;
    --text-color: #333;
    --border-color: #eee;
}

/* Global Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px;
}

h3 {
    margin-top: .5em;
    margin-bottom: .25em;
}

ol {
    margin-bottom: .25em;
}

#app-container {
    background: var(--card-background);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 1200px;
    min-height: 80vh;
    overflow: hidden;
}

/* --- Login Section --- */
#login-section,
#login-container {
    padding: 40px;
    text-align: center;
    max-width: 400px;
    margin: 50px auto;
}

#login-form input,
#signup-form input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
}

#login-form button,
#signup-form button {
    width: 100%;
    padding: 12px;
    margin-top: 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s;
}

#login-form button:hover,
#signup-form button:hover {
    background-color: #388e3c;
}

.error-text {
    color: #e53935;
    margin-top: 10px;
}

/* --- Main Application Layout --- */
#main-app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
    background-color: #fcfcfc;
}

header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
}

#header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

#user-info {
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 4px;
    background: #e8f5e9;
    font-size: 80%;
    /* Light green background */
}

/* NEW: Chat Button */
#chat-toggle-btn,
#refresh-btn,
#logout-btn,
#share-list-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 24px;
    padding: 0;
    margin: 0;
    color: var(--primary-color);
    transition: color 0.2s;
}

#logout-btn {
    color: #D0D0D0;
}


#chat-toggle-btn:hover {
    color: #388e3c;
}

main {
    display: flex;
    flex-grow: 1;
    min-height: calc(80vh - 70px);
    /* Adjust based on header height */
}

/* --- Sidebar (5. Display all list_names) --- */
#sidebar {
    width: 300px;
    padding: 20px;
    background-color: #f9f9f9;
    border-right: 1px solid var(--border-color);
}

#sidebar h3 {
    margin: 0;
    font-weight: 600;
    color: var(--primary-color);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

#new-list-toggle-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 18px;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#new-list-toggle-btn:hover {
    background-color: #e6ffe6;
}

#list-names {
    list-style: none;
}

#list-names li {
    padding: 12px 15px;
    margin-bottom: 8px;
    background-color: var(--card-background);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#list-names li:hover {
    background-color: #e6ffe6;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

#list-names li.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
}

.item-count {
    background-color: #e0e0e0;
    color: var(--text-color);
    padding: 3px 8px;
    color: var(--text-color);
}

#new-list-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#new-list-form input,
#new-list-form select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    background-color: #fff;
    /* Default to white or var(--card-background) if set to white */
    color: var(--text-color);
    font-family: inherit;
}

#new-list-form button {
    width: 100%;
    padding: 8px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: background-color 0.2s;
}

#new-list-form button:hover {
    background-color: #388e3c;
}

/* --- Main Pane (6. Display list items) --- */
#main-pane {
    flex-grow: 1;
    padding: 30px;
    display: flex;
    flex-direction: column;
    position: relative;
}

#current-list-title {
    font-size: 22px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

/* Scrollable container (10. List items should scroll) */
#list-items-container {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 10px;
    margin-bottom: 80px;
    /* Space for the anchored form */
}

/* Grouping by Section (7. Grouped by item_section) */
.section-group {
    margin-bottom: 25px;
}

.section-group h4 {
    background-color: #f0f0f0;
    padding: 8px 10px;
    border-radius: 6px;
    margin-bottom: 10px;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 14px;
    color: #666;
}

/* Individual List Item (8. Checklist) */
.list-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border-color);
}

.list-item:last-child {
    border-bottom: none;
}

.list-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 15px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.item-details {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.item-name {
    font-weight: 600;
    font-size: 16px;
}

.item-notes,
.item-price {
    font-size: 13px;
    color: #777;
    margin-top: 2px;
}

.item-price {
    font-weight: 700;
    color: var(--primary-color);
    margin-left: 15px;
}

/* Completed item styling */
.list-item input[type="checkbox"]:checked+.item-details .item-name {
    text-decoration: line-through;
    color: #a0a0a0;
}

/* Delete Button (12. Small delete button) */
.delete-btn {
    background: none;
    border: none;
    color: #e53935;
    /* Red color */
    cursor: pointer;
    font-size: 18px;
    margin-left: 15px;
    padding: 5px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.delete-btn:hover {
    opacity: 1;
}


/* --- New Item Anchor (10. Anchored at the bottom) --- */
#new-item-form-anchor {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--card-background);
    border-top: 1px solid var(--border-color);
    padding: 15px 30px;
    box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.03);
}

#new-item-form {
    display: flex;
    gap: 10px;
}

#new-item-name {
    flex-grow: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
}

#new-item-form button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.3s;
}

#new-item-form button:hover {
    background-color: #388e3c;
}

/* Utility Class */
.hidden {
    display: none !important;
}

/* --- Mobile Sidebar Styles --- */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        /* Hidden by default */
        height: 100%;
        width: 260px;
        background-color: #ffffff;
        box-shadow: 3px 0 12px rgba(0, 0, 0, 0.1);
        z-index: 1000;
        transition: left 0.3s ease;
        padding-top: 80px;
        /* So it's below the header */
    }

    #sidebar.open {
        left: 0;
        /* Slide in */
    }

    /* Show menu toggle button only on mobile */
    .hidden-desktop {
        display: block;
        font-size: 26px;
        background: none;
        border: none;
        cursor: pointer;
    }

    /* Prevent body from scrolling when menu is open */
    body.menu-open {
        overflow: hidden;
    }
}

/* Desktop: hide mobile menu button */
@media (min-width: 769px) {
    .hidden-desktop {
        display: none;
    }
}

#sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 900;
}

#sidebar-overlay.hidden {
    display: none;
}

/* ------------------------------------------- */
/* --- MODIFIED: Chat Window Styles (1, 2, 3) --- */
/* ------------------------------------------- */

/* Default/Large Screen Chat Window (Item 1: 450px width/height, but now adjusted for large screens) */
#chat-window {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 450px;
    /* Default for medium/large screens */
    height: 450px;
    background: var(--card-background);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1010;
}

/* Item 1: Large Monitor (e.g., > 1200px) - 40% screen width */
@media (min-width: 1200px) {
    #chat-window {
        width: 40vw;
        /* 40% of viewport width */
        max-width: 600px;
        /* Optional cap to prevent it from getting too large */
        height: 60vh;
        /* Make it a bit taller on large screens for better proportions */
    }
}

#chat-header {
    background-color: var(--primary-color);
    color: white;
    padding: 15px;
    font-weight: 600;
    font-size: 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chat-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
}

#chat-messages {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-message {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 15px;
    line-height: 1.4;
    font-size: 14px;
}

.user-message {
    align-self: flex-end;
    background-color: #e8f5e9;
    /* Light green */
    color: var(--text-color);
    border-bottom-right-radius: 2px;
}

.assistant-message {
    align-self: flex-start;
    background-color: #f0f0f0;
    color: var(--text-color);
    border-bottom-left-radius: 2px;
    padding-left: .5em;
}

#chat-input-form {
    display: flex;
    padding: 10px 15px;
    border-top: 1px solid var(--border-color);
    background-color: #fcfcfc;
    /* anchored at the bottom */
}

#chat-input-form input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 14px;
    margin-right: 10px;
}

#chat-input-form button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0 15px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.3s;
}

#chat-input-form button:hover {
    background-color: #388e3c;
}

.loading-container {
    /* Enable Flexbox on the container */
    display: flex;
    /* Align items along the cross-axis (vertically, since default flex-direction is row) */
    align-items: center;
    /* Optional: Add some space between the spinner and the text */
    gap: 8px;
}

.loading-text {
    /* Basic text styling */
    font-size: 1em;
    color: var(--primary-color);
}

#loading-spinner {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 12px;
    color: var(--primary-color);
}

/* The Spinner Animation */
.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #fff;
    border: 4px solid #f3f3f3;
    /* 1. Light gray for the base ring */
    /* Match assistant bubble text color */
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
    margin-right: 8px;
    width: 20px;
    height: 20px;
    color: var(--primary-color);
    border-top-color: var(--primary-color);
}

/* Spinner Animation Keyframes */
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Utility Class */
.hidden {
    display: none !important;
}

/* Item 2: iPhone Portrait Mode (max-width 480px, portrait orientation) */
@media (max-width: 480px) and (orientation: portrait) {
    #chat-window {
        width: 90vw;
        height: 90vh;
        /* Center the window */
        top: 50%;
        left: 50%;
        right: auto;
        bottom: auto;
        transform: translate(-50%, -50%);
        border-radius: 12px;
    }
}

/* Item 3: iPhone Landscape Mode (max-height 480px, landscape orientation) */
@media (max-height: 480px) and (orientation: landscape) {
    #chat-window {
        width: 40vw;
        height: 90vh;
        /* Keep it anchored to bottom right */
        top: auto;
        left: auto;
        right: 15px;
        bottom: 15px;
        transform: none;
        border-radius: 12px;
    }
}

/* --- Recipe Section Styles --- */

.menu-list {
    list-style: none;
    margin-bottom: 20px;
}

.menu-list li {
    padding: 12px 15px;
    margin-bottom: 8px;
    background-color: var(--card-background);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.menu-list li:hover {
    background-color: #e6ffe6;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.menu-list li.active {
    background-color: var(--primary-color);
    color: white;
}

#recipe-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: flex-end;
}

#recipe-search {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    width: 200px;
}

.recipe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding-bottom: 20px;
}

.recipe-card {
    background: var(--card-background);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    padding: 20px;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.recipe-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    border-color: #e0e0e0;
}

.recipe-header {
    margin-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 10px;
}

.recipe-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recipe-meta {
    font-size: 12px;
    color: #888;
    display: flex;
    justify-content: space-between;
}

.recipe-body {
    flex-grow: 1;
    font-size: 14px;
    color: #555;
    margin-bottom: 15px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
}

.recipe-footer {
    margin-top: auto;
    display: flex;
    justify-content: flex-end;
}

.view-recipe-btn {
    background-color: #f0f0f0;
    color: #333;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.view-recipe-btn:hover {
    background-color: #e0e0e0;
}

/* Recipe Actions */
.recipe-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.btn-standard,
.btn-cook,
.btn-add-list,
.btn-delete {
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background-color 0.2s;
}

.btn-standard {
    background-color: var(--primary-color);
    color: white;
    flex-grow: 1;
}

.btn-standard:hover {
    background-color: #388e3c;
}

.btn-cook {
    background-color: #FF9800;
    /* Orange for Cook Mode */
    color: white;
    flex-grow: 1;
}

.btn-cook:hover {
    background-color: #F57C00;
}

.btn-delete {
    background-color: #ffebee;
    color: #e53935;
    padding: 8px 10px;
}

.btn-delete:hover {
    background-color: #ffcdd2;
}

.btn-add-list {
    background-color: #2196F3;
    /* Blue */
    color: white;
    padding: 8px 10px;
}

.btn-add-list:hover {
    background-color: #1976D2;
}

.btn-share {
    background-color: #e3f2fd;
    color: #1976d2;
    padding: 8px 10px;
    /* Match btn-delete padding */
}

.btn-share:hover {
    background-color: #bbdefb;
}

/* Recipe Overlay */
#recipe-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.overlay-content {
    background-color: white;
    width: 90%;
    max-width: 800px;
    height: 85%;
    border-radius: 12px;
    position: relative;
    padding: 30px;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

#close-overlay-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    transition: color 0.2s;
}

#close-overlay-btn:hover {
    color: #000;
}

/* Cook View Styles */
.cook-view .overlay-content {
    width: 100%;
    height: 100%;
    max-width: none;
    border-radius: 0;
    padding: 40px;
}

.cook-view h2 {
    font-size: 3em;
    margin-bottom: 30px;
    text-align: center;
}

.cook-view .ingredient-item {
    font-size: 1.5em;
    /* Large text */
    padding: 15px 0;
    border-bottom: 1px solid #eee;
}

.cook-view .instruction-step {
    font-size: 1.8em;
    line-height: 1.6;
    margin-bottom: 30px;
    padding: 20px;
    background-color: #f9f9f9;
    border-left: 6px solid var(--primary-color);
}

/* Standard View Styles */
.standard-view h2 {
    font-size: 2em;
    margin-bottom: 20px;
    color: var(--primary-color);
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
}

.standard-view h3 {
    margin-top: 25px;
    margin-bottom: 15px;
    color: #555;
    text-transform: uppercase;
    font-size: 14px;
    letter-spacing: 1px;
}

.section-header {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--primary-color);
    margin-top: 20px;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 2px solid #e0f2f1;
    /* Light teal underline */
}

/* Cook View specifics for headers */
.cook-view .section-header {
    font-size: 2em;
    margin-top: 40px;
    margin-bottom: 20px;
    border-bottom: 3px solid var(--primary-color);
}

.standard-view ul {
    list-style: none;
}

/* --- Confirmation Modal & Generic Overlay --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    /* Slightly clearer overlay */
    z-index: 3000;
    /* Higher than recipe overlay */
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
    /* Blur behind */
}

.confirmation-box {
    background: white;
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-icon {
    font-size: 40px;
    margin-bottom: 15px;
}

.confirmation-box h3 {
    margin-top: 0;
    color: #333;
    font-size: 1.5em;
    margin-bottom: 10px;
}

.confirmation-box p {
    color: #666;
    margin-bottom: 25px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}



.btn-secondary,
.btn-primary,
.btn-danger {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.1s;
    min-width: 100px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: #388e3c;
}

.btn-secondary {
    background-color: #f0f0f0;
    color: #333;
}



.btn-secondary:hover {
    background-color: #e0e0e0;
}

.btn-danger {
    background-color: #ffebee;
    color: #e53935;
}

.btn-danger:hover {
    background-color: #ffcdd2;
}

.btn-secondary:active,
.btn-danger:active {
    transform: scale(0.95);
}

.standard-view .ingredient-item {
    padding: 8px 0;
    border-bottom: 1px dashed #eee;
    display: flex;
    justify-content: space-between;
}

.standard-view .instruction-step {
    margin-bottom: 15px;
    line-height: 1.6;
    white-space: pre-wrap;
}