/* Floating Action Button */
.fab-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: #198754;
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 1040;
    cursor: pointer;
    font-size: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab-chat-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.fab-chat-btn.hidden {
    display: none;
}

/* When sidebar is open, make content-wrapper the scroll container
   so its scrollbar sits at ITS right edge, not the viewport edge. */
body.chat-panel-open {
    overflow: hidden; /* kill body scrollbar */
}

body.chat-panel-open .content-wrapper {
    margin-right: 400px;
    height: calc(100vh - var(--navbar-h, 56px));
    overflow-y: auto;
    transition: margin-right 0.3s ease;
}

body.chat-panel-open .navbar {
    margin-right: 400px;
    transition: margin-right 0.3s ease;
}

.content-wrapper {
    transition: margin-right 0.3s ease;
}

.navbar {
    transition: margin-right 0.3s ease;
}

/* Chat Panel */
.chat-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100%;
    background: white;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transition: right 0.3s ease;
}

.chat-panel.open {
    right: 0;
}

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: #198754;
    color: white;
    flex-shrink: 0;
}

.chat-panel-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-panel-input {
    padding: 12px;
    border-top: 1px solid #dee2e6;
    flex-shrink: 0;
    background: #f8f9fa;
}

.chat-panel-input .input-group {
    gap: 4px;
}

.chat-panel-input .image-preview-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

/* Chat Bubbles */
.chat-bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    flex-shrink: 0;
}

.chat-bubble-wrap.user {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-bubble-wrap.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-bubble-time {
    font-size: 0.7rem;
    color: #9aa0a6;
    margin-top: 2px;
    padding: 0 6px;
}

/* Date separator pill */
.chat-date-sep {
    align-self: center;
    background-color: #e9ecef;
    color: #6c757d;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 10px;
    margin: 6px 0 2px;
    flex-shrink: 0;
}

.chat-bubble {
    max-width: 100%;
    padding: 8px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    font-size: 0.9rem;
    line-height: 1.4;
    flex-shrink: 0;
}

.chat-bubble.user {
    align-self: flex-end;
    background-color: #0d6efd;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
    align-self: flex-start;
    background-color: #e9ecef;
    color: #212529;
    border-bottom-left-radius: 4px;
}

.chat-bubble.assistant p:last-child {
    margin-bottom: 0;
}

/* Typing indicator */
.chat-typing {
    align-self: flex-start;
    padding: 8px 16px;
    background-color: #e9ecef;
    border-radius: 12px;
    color: #6c757d;
    font-style: italic;
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* Backdrop — mobile only */
.chat-panel-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1045;
}

/* Interactive Cards in Chat */
.chat-card {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    margin: 4px 0;
    max-width: 100%;
    flex-shrink: 0;
    font-size: 0.85rem;
    flex-shrink: 0; /* Prevent cards from shrinking in flex containers */
}

.chat-card-header {
    padding: 8px 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-card-header.meal {
    background-color: #d1e7dd;
    color: #0f5132;
}

.chat-card-header.recipe {
    background-color: #fff3cd;
    color: #664d03;
}

.chat-card-body {
    padding: 8px 12px;
}

.chat-card-slot {
    font-size: 0.8rem;
    color: #6c757d;
    margin-bottom: 4px;
    font-weight: 500;
}

.chat-card-nutrients {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: #6c757d;
}

.chat-card-nutrients span {
    white-space: nowrap;
}

.chat-card-actions {
    padding: 8px 12px;
    border-top: 1px solid #dee2e6;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.chat-card-actions .btn {
    font-size: 0.75rem;
    padding: 2px 8px;
}

/* Serving adjuster */
.serving-adjuster {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
}

.serving-adjuster .btn {
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.serving-adjuster .serving-count {
    min-width: 20px;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
}

/* Collapsible sections in recipe cards */
.chat-card details summary {
    cursor: pointer;
    font-weight: 500;
    font-size: 0.8rem;
    color: #495057;
    margin-bottom: 4px;
}

.chat-card details[open] summary {
    margin-bottom: 6px;
}

.chat-card details ol,
.chat-card details ul {
    margin-bottom: 0;
    padding-left: 20px;
    font-size: 0.8rem;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .chat-panel {
        width: 100%;
        right: -100%;
    }

    /* Full-screen overlay on mobile — show backdrop */
    .chat-panel-backdrop.show {
        display: block;
    }

    /* Don't shift page content on mobile (panel is full-screen overlay) */
    body.chat-panel-open {
        overflow: auto;
    }

    body.chat-panel-open .content-wrapper {
        margin-right: 0;
        height: auto;
        overflow-y: visible;
    }

    body.chat-panel-open .navbar {
        margin-right: 0;
    }

    .fab-chat-btn {
        bottom: 16px;
        right: 16px;
        width: 48px;
        height: 48px;
        font-size: 1.1rem;
    }
}
