/* ====================================================================
   VlahX AI Chat - 100% Light Warm Restaurant Theme (La-Vali)
   ==================================================================== */

:root,
html.is-chat-app,
html.is-chat-app body.is-chat-app-body,
[data-bs-theme="light"],
[data-bs-theme="dark"] {
    /* Paletă caldă, elegantă, exclusiv LIGHT THEME pentru chat */
    --bg: #fdfbf7;
    --text: #2b1810;
    --chat-bg: #f8f5ee;
    --user-bg: linear-gradient(135deg, #c25e00, #ea580c);
    --user-text: #ffffff;
    --bot-bg: #ffffff;
    --bot-text: #2b1810;
    --bot-border: #e6ded6;
    --input-bg: #ffffff;
    --input-border: #ded5cb;
    --sidebar-bg: #f9f6f0;
    --sidebar-text: #4a3427;
    --border: #e6ded6;
    --accent: #c25e00;
    --accent-hover: #a84e00;
    --pill-bg: #f0e8de;
    --pill-text: #4a3427;
    --pill-hover-bg: #c25e00;
    --pill-hover-text: #ffffff;
    --topbar-bg: #ffffff;

    /* Forțare variabile Bootstrap pentru fundal și text light */
    --bs-body-bg: #f8f5ee !important;
    --bs-body-color: #2b1810 !important;
    --bs-emphasis-color: #1a0f0a !important;
    --bs-secondary-color: #6c584c !important;
    --bs-secondary-bg: #f0e8de !important;
    --bs-tertiary-bg: #f8f5ee !important;
    --bs-border-color: #e6ded6 !important;
    --bs-table-bg: #ffffff !important;
    --bs-table-color: #2b1810 !important;
    --bs-table-striped-bg: #fdfbf7 !important;
    --bs-table-hover-bg: #f8eee4 !important;
    --bs-table-border-color: #e8ddd2 !important;
}

/* ====================================================================
   CONTROL STRICT SCROLL PE /chat (Un singur scroll: în #chat-box)
   ==================================================================== */
html.is-chat-app {
    height: 100% !important;
    min-height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    overscroll-behavior: none;
    background-color: var(--chat-bg) !important;
}

html.is-chat-app body.is-chat-app-body {
    height: 100% !important;
    min-height: 0 !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    overscroll-behavior: none;
    display: flex;
    flex-direction: column;
    background-color: var(--chat-bg) !important;
    color: var(--text) !important;
}

/* Navbar rămâne sticky la top */
nav.navbar.sticky-top,
header.navbar.sticky-top {
    z-index: 1060;
    flex-shrink: 0;
}

/* Main app container umple fix restul înălțimii dintre navbar și ecran */
html.is-chat-app main.chat-main-app {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    margin: 0 !important;
    width: 100%;
    background: var(--chat-bg);
}

/* Sub-navbar Top Bar: status asistent */
#chat-top-bar {
    background: var(--topbar-bg) !important;
    border-bottom: 1px solid var(--border) !important;
    flex-shrink: 0;
    padding: 8px 16px;
    z-index: 20;
    box-shadow: 0 1px 4px rgba(43, 24, 16, 0.03);
}

#sessionActiveTitle {
    color: var(--sidebar-text) !important;
    font-size: 0.74rem;
    font-weight: 600;
    opacity: 0.9;
}

/* Wrapper flex pentru Sidebar + Chat principal */
#wrapper {
    display: flex;
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    align-self: stretch;
    overflow: hidden;
    position: relative;
    z-index: 1;
    background: var(--chat-bg);
}

/* ====================================================================
   SIDEBAR CONVERSAȚII (Desktop coloană 280px, Mobil offcanvas slide-in)
   ==================================================================== */
#sidebar-left {
    width: 280px;
    background: var(--sidebar-bg) !important;
    color: var(--sidebar-text) !important;
    border-right: 1px solid var(--border) !important;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    flex-shrink: 0;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.28s ease;
}

.sidebar-zone--header {
    flex-shrink: 0;
    background: var(--sidebar-bg) !important;
    border-bottom: 1px solid var(--border) !important;
}

.sidebar-zone--content {
    flex: 1 1 0;
    min-height: 0;
    height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    background: var(--sidebar-bg) !important;
}

.sidebar-zone--footer {
    flex-shrink: 0;
    background: var(--sidebar-bg) !important;
    border-top: 1px solid var(--border) !important;
}

/* Sesiuni în listă */
.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border-radius: 10px;
    color: var(--sidebar-text) !important;
    text-decoration: none;
    font-size: 0.86rem;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
    background: transparent;
}

.session-item:hover {
    background: rgba(194, 94, 0, 0.07) !important;
    color: var(--text) !important;
}

.session-item.active {
    background: rgba(194, 94, 0, 0.12) !important;
    color: var(--accent) !important;
    font-weight: 700 !important;
    border-color: rgba(194, 94, 0, 0.25) !important;
}

.session-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 185px;
    color: inherit;
}

.session-delete-btn {
    opacity: 0.45;
    color: #dc2626 !important;
    background: none;
    border: none;
    padding: 2px 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: opacity 0.15s;
}

.session-delete-btn:hover {
    opacity: 1 !important;
}

/* ====================================================================
   CONTAINER PRINCIPAL CHAT & MESAJE
   ==================================================================== */
#chat-container {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 0;
    align-self: stretch;
    background: var(--chat-bg) !important;
}

/* Zona de mesaje scrollabilă nativ */
#chat-box {
    flex: 1 1 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overflow-anchor: none;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px 20px;
    scroll-behavior: smooth;
    background: var(--chat-bg) !important;
}

/* Bule mesaje */
.msg-bubble {
    max-width: 82%;
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.55;
    position: relative;
    word-break: break-word;
    display: inline-block;
    animation: fadeInBubble 0.2s ease-in-out;
}

@keyframes fadeInBubble {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-msg {
    align-self: flex-end;
    background: var(--user-bg) !important;
    color: var(--user-text) !important;
    border-bottom-right-radius: 4px !important;
    margin-left: auto !important;
    box-shadow: 0 4px 14px rgba(194, 94, 0, 0.22);
}

.user-msg * {
    color: var(--user-text) !important;
}

.bot-msg {
    align-self: flex-start;
    background: var(--bot-bg) !important;
    color: var(--bot-text) !important;
    border: 1px solid var(--bot-border) !important;
    border-bottom-left-radius: 4px !important;
    margin-right: auto !important;
    box-shadow: 0 3px 12px rgba(43, 24, 16, 0.05);
}

.bot-msg,
.bot-msg *,
.bot-msg p,
.bot-msg div.msg-body,
.bot-msg li,
.bot-msg span:not(.badge):not(.typing-dot),
.bot-msg .text-body-secondary,
.bot-msg .text-muted,
.bot-msg .text-secondary {
    color: var(--bot-text) !important;
    opacity: 1 !important;
}

.bot-msg strong,
.bot-msg b {
    color: #1a0f0a !important;
    font-weight: 700 !important;
}

.bot-msg a {
    color: var(--accent) !important;
    text-decoration: underline;
    font-weight: 600;
}

.bot-msg a:hover {
    color: var(--accent-hover) !important;
}

.agent-name {
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--accent) !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-msg-avatar {
    width: 18px !important;
    height: 18px !important;
    min-width: 18px;
    max-width: 18px !important;
    max-height: 18px !important;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid rgba(194, 94, 0, 0.35);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    display: inline-block;
    vertical-align: middle;
}

/* ====================================================================
   TABELE RANDATE DE LLM (100% LIGHT THEME - FĂRĂ BG NEGRU!)
   ==================================================================== */
.bot-msg table,
.bot-msg .table,
table.chat-table,
.chat-table {
    width: 100% !important;
    background-color: #ffffff !important;
    color: #2b1810 !important;
    border: 1px solid #e2d5c8 !important;
    border-radius: 10px !important;
    overflow: hidden !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    margin: 12px 0 !important;
    font-size: 0.88rem !important;
    box-shadow: 0 2px 8px rgba(43, 24, 16, 0.04) !important;
}

.bot-msg table th,
.bot-msg .table th,
.bot-msg table thead th,
.chat-table th,
.chat-table thead th,
th.chat-th {
    background-color: #f7efe6 !important;
    color: #7c2d12 !important;
    font-weight: 700 !important;
    border-bottom: 2px solid #dfcfbe !important;
    border-top: none !important;
    border-left: none !important;
    border-right: 1px solid #dfcfbe !important;
    padding: 9px 12px !important;
    text-align: left !important;
}

.bot-msg table th:last-child,
.chat-table th:last-child {
    border-right: none !important;
}

.bot-msg table td,
.bot-msg .table td,
.bot-msg table tbody td,
.chat-table td,
.chat-table tbody td,
td.chat-td {
    background-color: #ffffff !important;
    color: #2b1810 !important;
    border-top: none !important;
    border-left: none !important;
    border-bottom: 1px solid #efe5da !important;
    border-right: 1px solid #efe5da !important;
    padding: 8px 12px !important;
}

.bot-msg table td:last-child,
.chat-table td:last-child {
    border-right: none !important;
}

.bot-msg table tbody tr:last-child td,
.chat-table tbody tr:last-child td {
    border-bottom: none !important;
}

.bot-msg table tbody tr:nth-child(even) td,
.chat-table tbody tr:nth-child(even) td {
    background-color: #fdfbf7 !important;
}

.bot-msg table tbody tr:hover td,
.chat-table tbody tr:hover td {
    background-color: #f8eee4 !important;
}

.bot-msg .table-responsive,
.table-responsive {
    background: transparent !important;
    border: none !important;
    margin: 8px 0;
}

/* ====================================================================
   INLINE CODE, CODE BLOCKS & BLOCKQUOTES
   ==================================================================== */
.bot-msg code,
.bot-msg .inline-code,
.bot-msg code.font-monospace {
    color: #9a3412 !important;
    background-color: #fbf3ea !important;
    border: 1px solid #dfc7b2 !important;
    border-radius: 6px !important;
    padding: 2px 7px !important;
    font-size: 0.90em !important;
    font-weight: 700 !important;
    word-break: break-word;
    display: inline-block;
    line-height: 1.4;
}

.bot-msg blockquote,
.bot-msg .inline-blockquote {
    margin: 10px 0;
    padding: 8px 14px;
    border-left: 4px solid var(--accent) !important;
    background: rgba(194, 94, 0, 0.08) !important;
    border-radius: 0 8px 8px 0;
    color: #2b1810 !important;
    font-weight: 600;
    font-style: italic;
}

.bot-msg blockquote *,
.bot-msg .inline-blockquote * {
    color: #2b1810 !important;
    font-weight: 600;
}

.bot-msg pre {
    background: #fdfbf7 !important;
    border: 1px solid #e2d5c8 !important;
    border-radius: 10px;
    padding: 12px;
    margin: 8px 0;
    position: relative;
    overflow-x: auto;
    color: #2b1810 !important;
}

.bot-msg pre code {
    color: #2b1810 !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    font-size: 0.88rem;
    font-weight: normal;
}

.copy-btn {
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 0.72rem;
    background: var(--pill-bg);
    color: var(--sidebar-text);
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.copy-btn:hover {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

/* Indicator de scriere / typing bounce */
.typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0.4;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-5px); opacity: 1; }
}

/* ====================================================================
   SUGESTII RAPIDE (Quick Pills)
   ==================================================================== */
.chat-pills-bar {
    background: var(--topbar-bg) !important;
    border-top: 1px solid var(--border) !important;
    padding: 6px 16px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    flex-shrink: 0;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.chat-pills-bar::-webkit-scrollbar {
    display: none;
}

.quick-pill {
    background: var(--pill-bg) !important;
    border: 1px solid var(--border) !important;
    color: var(--pill-text) !important;
    border-radius: 20px;
    padding: 5px 13px;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
    flex-shrink: 0;
}

.quick-pill:hover {
    background: var(--pill-hover-bg) !important;
    color: var(--pill-hover-text) !important;
    border-color: var(--pill-hover-bg) !important;
}

/* ====================================================================
   INPUT AREA (Sticky Bottom, deasupra mini-footerului)
   ==================================================================== */
.chat-input-area {
    background: var(--topbar-bg) !important;
    border-top: 1px solid var(--border) !important;
    padding: 10px 18px;
    flex-shrink: 0;
}

.chat-input-box {
    background: var(--input-bg) !important;
    border: 1.5px solid var(--input-border) !important;
    border-radius: 30px;
    padding: 4px 8px 4px 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-box:focus-within {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(194, 94, 0, 0.15) !important;
}

.chat-input-box textarea {
    flex: 1;
    background: transparent !important;
    border: none;
    color: var(--text) !important;
    resize: none;
    outline: none;
    font-size: 0.95rem;
    max-height: 140px;
    min-height: 38px;
    padding: 8px 0;
    box-shadow: none !important;
}

.chat-input-box textarea::placeholder {
    color: #9c8a7c !important;
    opacity: 1;
}

.btn-send {
    background: var(--user-bg) !important;
    color: white !important;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
    flex-shrink: 0;
}

.btn-send:hover {
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ====================================================================
   MINI-FOOTER PENTRU CHAT (Înlocuiește footer-ul uriaș al site-ului)
   ==================================================================== */
.chat-mini-footer {
    background: var(--topbar-bg) !important;
    border-top: 1px solid var(--border) !important;
    padding: 5px 12px;
    font-size: 0.72rem;
    flex-shrink: 0;
    text-align: center;
    color: var(--sidebar-text) !important;
}

/* Overlay întunecat pentru închidere sertar mobil la click afară */
.chat-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(43, 24, 16, 0.40);
    z-index: 1039;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.chat-sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* ====================================================================
   RESPONSIVE DESIGN: MOBIL & TELEFOANE (<= 991.98px / sm / md)
   ==================================================================== */
@media (max-width: 991.98px) {
    #sidebar-left {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 82% !important;
        max-width: 310px;
        z-index: 1045;
        transform: translateX(-102%);
        box-shadow: none;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    #sidebar-left.show {
        transform: translateX(0);
        box-shadow: 10px 0 35px rgba(43, 24, 16, 0.25);
    }

    #chat-top-bar {
        padding: 6px 12px;
    }

    #chat-box {
        padding: 12px 10px;
        gap: 10px;
    }

    .msg-bubble {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 0.90rem;
        border-radius: 15px;
    }

    .chat-pills-bar {
        padding: 5px 10px;
        gap: 6px;
    }

    .quick-pill {
        padding: 4px 10px;
        font-size: 0.78rem;
    }

    .chat-input-area {
        padding: 8px 10px;
    }

    .chat-input-box {
        padding: 2px 6px 2px 12px;
    }

    /* Font de 16px pe textarea pentru a preveni zoom-ul automat pe iPhone (iOS Safari) */
    .chat-input-box textarea {
        font-size: 16px !important;
    }

    .btn-send {
        width: 36px;
        height: 36px;
    }

    .session-item {
        padding: 11px 12px;
    }

    .session-delete-btn {
        opacity: 0.75;
    }
}

@media (max-width: 767.98px) {
    .bot-msg table.chat-table,
    .bot-msg table {
        display: block !important;
        width: 100% !important;
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
    }

    .bot-msg table.chat-table thead,
    .bot-msg table thead {
        display: none !important;
    }

    .bot-msg table.chat-table tbody,
    .bot-msg table tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }

    .bot-msg table.chat-table tbody tr,
    .bot-msg table tbody tr {
        display: block !important;
        background: #ffffff !important;
        border: 1px solid #e2d5c8 !important;
        border-radius: 10px !important;
        padding: 8px 10px !important;
    }

    .bot-msg table.chat-table tbody td,
    .bot-msg table tbody td {
        display: block !important;
        width: 100% !important;
        border: none !important;
        padding: 2px 0 !important;
        background: transparent !important;
        white-space: normal !important;
        word-break: normal !important;
    }

    .bot-msg table.chat-table tbody td:first-child,
    .bot-msg table tbody td:first-child {
        font-weight: 700 !important;
        color: #7c2d12 !important;
    }
}
