/* css/chat.css */

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    overflow: hidden;
    backdrop-filter: blur(10px); /* Add backdrop blur for depth */
    -webkit-backdrop-filter: blur(10px); /* Safari support */
    transition: transform var(--duration-normal) var(--ease-out-material),
                opacity var(--duration-normal) var(--ease-out-material),
                background-color var(--duration-fast) var(--ease-out-material);
}

.chat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 18px;
    word-wrap: break-word; /* Fallback */
    overflow-wrap: break-word; /* Standard */
    white-space: pre-wrap; /* Preserve whitespace and wrap lines */
    transition: transform var(--duration-fast) var(--ease-out-material),
                opacity var(--duration-fast) var(--ease-out-material),
                background-color var(--duration-fast) var(--ease-out-material);
    transform: translateZ(0);
    will-change: transform, opacity;
}

.chat-message.user {
    background-color: var(--color-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-message.ai {
    background-color: var(--color-bg-surface-alt);
    color: var(--color-text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* Styling for code blocks */
.chat-message pre {
    background-color: #2d2d2d;
    color: #f8f8f2;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto; /* Allow horizontal scrolling for long code lines */
    white-space: pre; /* Do not wrap lines in code blocks */
}

/* Styling for inline code snippets */
.chat-message code {
    font-family: monospace;
    background-color: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 4px;
}

/* Reset styles for code inside a pre block */
.chat-message pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
}

.chat-form {
    display: flex;
    padding: 15px;
    border-top: 1px solid #ddd;
}

.chat-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 20px;
    margin-right: 10px;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color var(--duration-fast) var(--ease-out-material),
                box-shadow var(--duration-fast) var(--ease-out-material),
                background-color var(--duration-fast) var(--ease-out-material);
}

.chat-send-btn {
    padding: 10px 20px;
    background-color: var(--color-primary);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color var(--duration-fast) var(--ease-out-material),
                transform var(--duration-fast) var(--ease-out-material),
                box-shadow var(--duration-fast) var(--ease-out-material);
}

.chat-send-btn:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Override padding for the AI chat modal */
#top-sheet .modal-content, #rules-top-sheet .modal-content {
    padding: 0;
    flex-grow: 1;
    overflow-y: auto;
    min-height: 0; /* Prevent flexbox overflow issues */
}

/* Position the modal header for absolute child elements */
#top-sheet .modal-header,
#rules-top-sheet .modal-header {
    position: relative;
    justify-content: center; /* Keep title centered */
}

/* Meal Planner Specific Styles */
.meal-planner-form-container {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.meal-planner-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-weight: bold;
    color: var(--color-text-primary);
}

.form-group input[type="text"],
.form-group input[type="number"] {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1rem;
    width: 100%;
    box-sizing: border-box; /* Include padding and border in the element's total width and height */
}

/* Style for range inputs (sliders) */
.form-group input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    background: #ddd;
    outline: none;
    opacity: 0.7;
    -webkit-transition: .2s;
    transition: opacity .2s;
    border-radius: 5px;
}

.form-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
}

.form-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
}

/* Tag input for allergies */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 5px;
}

.tag-item {
    background-color: var(--color-gray-200);
    padding: 5px 10px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    font-size: 0.9em;
}

.tag-close {
    margin-left: 8px;
    cursor: pointer;
    font-weight: bold;
    color: #555;
}

.tag-close:hover {
    color: #000;
}


/* Toggle Switch specific to modal header */
.switch.small {
    width: 40px; /* Smaller width */
    height: 24px; /* Smaller height */
}

.switch.small .slider {
    border-radius: 24px;
}

.switch.small .slider:before {
    height: 18px; /* Smaller thumb */
    width: 18px; /* Smaller thumb */
    left: 3px;
    bottom: 3px;
    border-radius: 50%;
}

input:checked + .switch.small .slider:before {
    -webkit-transform: translateX(16px);
    -ms-transform: translateX(16px);
    transform: translateX(16px);
}

/* Buttons */
.generate-button, .download-button {
    padding: 12px 20px;
    background-color: #28a745; /* Green for generate */
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    transition: background-color 0.3s ease;
    margin-top: 10px;
}

.generate-button:hover {
    background-color: #218838;
}

.download-button {
    background-color: var(--color-primary); /* Blue for download */
}

.download-button:hover {
    background-color: #0056b3;
}

/* Meal Planner Results */
.meal-planner-results {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.meal-planner-results h3 {
    margin-bottom: 10px;
    color: var(--color-text-primary);
}

.meal-planner-results pre {
    background-color: var(--color-bg-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: 5px;
    padding: 15px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.9em;
    color: var(--color-text-primary);
    margin-bottom: 15px;
}

/* Meal Planner Result Custom Styling */
.mp-result-header {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--color-border-light);
}

.mp-result-header h2 {
    font-size: 1.8em;
    color: var(--color-text-primary);
    margin-bottom: 5px;
}

.mp-result-header p {
    color: var(--color-text-muted);
    font-size: 0.95em;
    margin: 2px 0;
}

.mp-result-header a {
    color: var(--color-primary);
    text-decoration: none;
}

.mp-result-section {
    margin-bottom: 25px;
}

.mp-result-section h3 {
    font-size: 1.2em;
    color: var(--color-text-primary);
    border-left: 4px solid var(--color-success);
    padding-left: 10px;
    margin-bottom: 15px;
}

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

.mp-ingredient-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px;
    background-color: var(--color-bg-surface-alt);
    border-radius: 8px;
    border: 1px solid var(--color-border);
    flex-wrap: wrap; /* Wrap on small screens */
}

.mp-ing-name {
    flex: 1;
    min-width: 120px;
    font-size: 1em;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
}

.mp-ing-match {
    flex: 1;
    display: flex;
    justify-content: flex-end;
}

.mp-match-card {
    background-color: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 8px;
    font-size: 0.9em;
    width: 100%;
    max-width: 200px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.mp-match-name {
    font-weight: bold;
    color: var(--color-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mp-match-details {
    color: #70757a;
    font-size: 0.85em;
}

.mp-match-price {
    color: var(--color-success);
    font-weight: bold;
    text-align: right;
    margin-top: 4px;
}

.mp-no-match {
    color: #999;
    font-style: italic;
    font-size: 0.9em;
}

.mp-total-price {
    text-align: right;
    font-size: 1.2em;
    color: var(--color-text-primary);
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #ccc;
}

.mp-instructions-list {
    padding-left: 20px;
    color: #3c4043;
    line-height: 1.6;
}

.mp-instructions-list li {
    margin-bottom: 10px;
}

.mp-result-actions {
    flex-direction: column; /* Stack buttons on mobile by default */
}

@media (min-width: 600px) {
    .mp-result-actions {
        flex-direction: row; /* Row on larger screens */
    }
}