/* ==========================================================================
   Global AI Chat Panel
   Floating panel docked to the right side of the main content area.
   ========================================================================== */

/* ---- FAB toggle button (bottom-right corner) ---- */
#gaiChatFab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9000;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #337ab7;
    color: #fff;
    border: none;
    box-shadow: 0 4px 14px rgba(0,0,0,0.35);
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
}
#gaiChatFab:hover {
    background: #286090;
    transform: scale(1.08);
}
#gaiChatFab .gai-fab-icon-open  { display: block; }
#gaiChatFab .gai-fab-icon-close { display: none; }
#gaiChatFab.open .gai-fab-icon-open  { display: none; }
#gaiChatFab.open .gai-fab-icon-close { display: block; }

/* Hide the FAB entirely when the panel is open — the header already has a close button,
   and the floating button at the same corner as the input area caused them to overlap. */
#gaiChatFab.open {
    display: none;
}

/* ---- Panel container ---- */
#gaiChatPanel {
    position: fixed;
    top: 64px;          /* below MDL header */
    right: 0;
    bottom: 0;
    width: 380px;
    min-width: 260px;
    max-width: 900px;
    z-index: 8999;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-left: 1px solid #ddd;
    box-shadow: -4px 0 16px rgba(0,0,0,0.14);
    transform: translateX(100%);
    transition: transform 0.25s ease;
    will-change: transform;
}
#gaiChatPanel.open {
    transform: translateX(0);
}

/* ---- Drag handle (left edge of panel) ---- */
#gaiPanelDivider {
    position: absolute;
    left: -5px;
    top: 0;
    bottom: 0;
    width: 10px;
    cursor: ew-resize;
    z-index: 9001;
    background: transparent;
}
#gaiPanelDivider:hover,
#gaiPanelDivider.dragging {
    background: rgba(51,122,183,0.18);
}

/* ---- Header bar ---- */
#gaiChatHeader {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px 7px 14px;
    background: #337ab7;
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    flex-shrink: 0;
    user-select: none;
}
#gaiChatHeader .gai-header-title {
    flex: 1;
}
/* Header buttons — force our own styling to win over _Layout / MDL button resets
   which were blanking the label text (white-on-white / transparent color). */
#gaiChatPanel #gaiChatHeader .btn,
#gaiChatPanel #gaiChatHeader .btn.btn-default {
    font-size: 13px;
    padding: 3px 10px;
    color: #fff !important;
    background: rgba(255,255,255,0.08) !important;
    background-color: rgba(255,255,255,0.08) !important;
    border: 1px solid rgba(255,255,255,0.5) !important;
    border-radius: 3px;
    text-shadow: none !important;
    box-shadow: none !important;
    line-height: 1.4;
    height: auto;
    white-space: nowrap;
    opacity: 1;
}
#gaiChatPanel #gaiChatHeader .btn .glyphicon {
    color: #fff !important;
}
#gaiChatPanel #gaiChatHeader .btn:hover,
#gaiChatPanel #gaiChatHeader .btn.btn-default:hover {
    background: rgba(255,255,255,0.22) !important;
    background-color: rgba(255,255,255,0.22) !important;
    color: #fff !important;
}

/* ---- Session picker dropdown ---- */
#gaiSessionMenu {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 220px;
    max-height: 240px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 9100;
    color: #333;
}
.gai-session-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 8px;
    cursor: pointer;
    font-size: 12px;
    border-bottom: 1px solid #f0f0f0;
}
.gai-session-item:hover { background: #f5f5f5; }
.gai-session-item.active { background: #e8f0fe; font-weight: bold; }
.gai-session-name  { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gai-session-delete { color: #c00; margin-left: 8px; font-size: 11px; cursor: pointer; }
.gai-session-delete:hover { color: #900; }

/* ---- Message history ---- */
#gaiChatHistory {
    flex: 1;
    overflow-y: scroll;
    padding: 10px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.gai-msg-user {
    text-align: right;
    margin-bottom: 6px;
}
.gai-msg-user span {
    display: inline-block;
    background: #337ab7;
    color: #fff;
    padding: 5px 10px;
    border-radius: 12px 12px 0 12px;
    max-width: 88%;
    word-break: break-word;
    font-size: 13px;
}
.gai-msg-ai {
    text-align: left;
    margin-bottom: 6px;
}
.gai-msg-ai > div {
    display: inline-block;
    background: #eee;
    padding: 6px 10px;
    border-radius: 12px 12px 12px 0;
    max-width: 95%;
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 13px;
}
.gai-msg-ai code {
    background: #ddd;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 12px;
}
.gai-msg-ai pre {
    background: #272822;
    color: #f8f8f2;
    padding: 8px;
    border-radius: 0 0 4px 4px;
    overflow-x: auto;
    font-size: 12px;
    font-family: monospace;
    margin: 0;
    white-space: pre;
}

/* ---- Code block toolbar ---- */
.gai-code-block {
    margin: 6px 0;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #444;
}
.gai-code-toolbar {
    display: flex;
    gap: 6px;
    padding: 3px 6px;
    background: #3d3d3d;
    align-items: center;
}
.gai-code-btn {
    font-size: 11px;
    padding: 2px 8px;
    border: 1px solid #666;
    border-radius: 3px;
    background: #555;
    color: #eee;
    cursor: pointer;
    line-height: 1.4;
}
.gai-code-btn:hover { background: #6a6a6a; color: #fff; }

/* ---- Input area ---- */
#gaiChatInputWrap {
    flex-shrink: 0;
    padding: 8px 10px;
    border-top: 1px solid #ddd;
    background: #f9f9f9;
}
#gaiChatInput {
    min-height: 38px;
    max-height: 140px;
    overflow-y: auto;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    background: #fff;
    color: #333;
    resize: none;
    word-break: break-word;
}
#gaiChatInput:empty:before {
    content: attr(data-placeholder);
    color: #aaa;
    pointer-events: none;
}
#gaiChatInput:focus { border-color: #337ab7; }
.gai-input-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 5px;
    gap: 6px;
}
#gaiChatSpinner {
    font-size: 11px;
    color: #888;
    text-align: center;
    padding: 3px 0;
}

/* ---- Utility ---- */
.gai-hidden { display: none !important; }
