/* ============================
   CHAT SHELL
   ============================ */

.moa-chat-shell {
    max-width: 960px;
    margin: 0 auto;
    background: #f8faff;
    border: 1px solid #d0d9ff;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.08);
    font-family: Inter, system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 100%;
    height: calc(100vh - 140px);
    max-height: calc(100vh - 140px);
    overflow: hidden;
}

@media (min-width: 769px) {
    .moa-chat-shell {
        width: 100%;
        max-width: 100%;
    }
}

/* Mobile: chat shell must fill full screen */
@media (max-width: 768px) {
    .moa-chat-shell {
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
}

/* DARK MODE FIXES */
.moa-chat-shell.moa-dark {
    background: #0f172a;
    border-color: #1e293b;
    color: #e5e7eb;
}

.moa-chat-shell.moa-dark textarea {
    background: #0f172a;
    color: #e5e7eb;
    border-color: #1e293b;
}

/* ============================
   HEADER
   ============================ */

.moa-chat-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid #e2e8f8;
    flex-shrink: 0;
}

.moa-chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.moa-chat-header-left img {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    object-fit: cover;
}

/* RIGHT SIDE (DESKTOP INLINE UNDER GREETING) */
.moa-chat-header-right {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Dropdown expands to fill remaining space */
.moa-thread-select {
    flex: 1;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid #cbd5f5;
    background: #ffffff;
    font-size: 0.85rem;
    color: #334155;
    cursor: pointer;
    transition: 0.15s ease;
    min-width: 180px;
}

/* Buttons inline on desktop */
.moa-chat-header-right button {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
}

/* ============================
   MOBILE HEADER STACKING
   ============================ */

@media (max-width: 768px) {

    .moa-chat-header-right {
        flex-wrap: wrap;
        gap: 10px;
    }

    /* Dropdown full width */
    .moa-thread-select {
        width: 100%;
        min-width: 100%;
        flex: none;
    }

    /* Buttons full width */
    .moa-chat-header-right button {
        flex: 1;
        min-width: calc(33% - 10px);
    }
}

/* Dropdown hover/focus */
.moa-thread-select:hover {
    border-color: #94a3f0;
}

.moa-thread-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.25);
}

.moa-chat-shell.moa-dark .moa-thread-select {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

/* ============================
   LOG
   ============================ */

.moa-chat-log {
    background: #ffffff;
    border: 1px solid #e2e8f8;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 10px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.moa-chat-shell.moa-dark .moa-chat-log {
    background: #020617;
    border-color: #1e293b;
}

/* ============================
   MESSAGE ROWS
   ============================ */

.moa-message-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.moa-message-row.user {
    justify-content: flex-end;
}

/* AVATARS */
.moa-avatar {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    background: #1d4ed8;
    color: white;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.moa-message-row.user .moa-avatar {
    background: #059669;
}

/* ============================
   BUBBLES (LIGHT MODE)
   ============================ */

.moa-chat-shell .agent-message,
.moa-chat-shell .user-message {
    position: relative;
    padding: 9px 11px;
    padding-right: 32px; /* space for pin */
    border-radius: 10px;
    max-width: 80%;
    border: 1px solid rgba(0,0,0,0.05);
}

.moa-chat-shell .agent-message {
    background: #e9f0ff;
}

.moa-chat-shell .user-message {
    background: #d1ffe0;
}

/* ============================
   PIN BUTTON (INSIDE BUBBLE)
   ============================ */

.moa-pin-btn {
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    transition: 0.15s ease;
    padding: 2px;
}

.moa-pin-btn:hover {
    color: #facc15;
}

/* Highlight pinned messages */
.moa-chat-shell .agent-message.pinned,
.moa-chat-shell .user-message.pinned {
    box-shadow: 0 0 0 2px #facc15, 0 0 12px rgba(250, 204, 21, 0.4);
}

/* ============================
   DARK MODE BUBBLES
   ============================ */

.moa-chat-shell.moa-dark .agent-message {
    background: #1e293b;
    color: #e5e7eb;
    border: 1px solid rgba(255,255,255,0.15);
}

.moa-chat-shell.moa-dark .user-message {
    background: #065f46;
    color: #e5e7eb;
    border: 1px solid rgba(16,185,129,0.4);
}

.moa-chat-shell.moa-dark .moa-pin-btn {
    color: #cbd5e1;
}

.moa-chat-shell.moa-dark .moa-pin-btn:hover {
    color: #facc15;
}

/* ============================
   INPUT
   ============================ */

.moa-chat-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    padding-top: 10px;
    border-top: 1px solid #e2e8f8;
    flex-shrink: 0;
}

.moa-chat-input-row textarea {
    flex: 1;
    resize: none;
    min-height: 40px;
    max-height: 140px;
    padding: 9px 11px;
    border-radius: 10px;
    border: 1px solid #c5d0f0;
}

/* Chat buttons */
.moa-chat-btn,
.moa-chat-header-right .btn {
    background: #1d4ed8;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: 0.15s ease;
}

.moa-chat-btn:hover,
.moa-chat-header-right .btn:hover {
    background: #1e40af;
}

.moa-chat-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.moa-chat-shell.moa-dark .moa-chat-btn {
    background: #3b82f6;
}

/* ============================
   SLIDE-OVER PANEL (DESKTOP)
   ============================ */

.moa-chat-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: none;
}

.moa-chat-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.35);
}

.moa-chat-overlay-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 40vw;
    max-width: 800px;
    height: 100%;
    background: #f8faff;
    box-shadow: -12px 0 32px rgba(0,0,0,0.25);
    padding: 16px;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease-out;
}

.moa-chat-overlay-panel.moa-open {
    transform: translateX(0);
}

/* ============================
   MOBILE FULL-SCREEN CHAT
   ============================ */

@media (max-width: 768px) {
    .moa-chat-overlay-panel {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        left: 0;
        right: 0;
        top: 0;
        transform: translateY(100%);
    }

    .moa-chat-overlay-panel.moa-open {
        transform: translateY(0) !important;
    }
}

/* Ensure chat shell fills panel */
.moa-chat-overlay-panel .moa-chat-shell {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ============================
   CLOSE BUTTON
   ============================ */

.moa-chat-overlay-close {
    position: absolute;
    top: 20px;
    right: 24px;
    font-size: 2rem;
    padding: 4px;
    line-height: 1;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #475569;
}

.moa-chat-overlay-close:hover {
    color: #1e293b;
}