/* ================================================================
   AI Exam Assistant — Chat Widget Styles
   Bootstrap 3 compatible. Fixed-position floating panel.
   ================================================================ */

/* ----------------------------------------------------------------
   Toggle button (bottom-right, always visible)
   ---------------------------------------------------------------- */
.ai-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    background: linear-gradient(135deg, #7c4dff, #bed7fb);
    color: #fff;
    border-radius: 50px;
    padding: 10px 16px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(124,77,255,.4);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    transition: background .2s, box-shadow .2s, transform .2s;
    user-select: none;
}

.ai-chat-toggle:hover {
    background: linear-gradient(135deg, #7c4dff, #bed7fb);
    box-shadow: 0 6px 20px rgba(124,77,255,.5);
    transform: translateY(-2px);
}

.ai-chat-toggle .fa,
.ai-chat-toggle .fa-solid {
    font-size: 18px;
}

.ai-chat-toggle-label {
    white-space: nowrap;
}

/* ----------------------------------------------------------------
   Chat panel
   ---------------------------------------------------------------- */
.ai-chat-panel {
    position: fixed;
    bottom: 80px;
    right: 24px;
    z-index: 9999;
    width: 360px;
    max-width: calc(100vw - 32px);
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,.20);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-size: 14px;
}

/* ----------------------------------------------------------------
   Header
   ---------------------------------------------------------------- */
.ai-chat-header {
    background: linear-gradient(135deg,#7c4dff, #bed7fb );
    color: #fff;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}

.ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.ai-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    opacity: .85;
}

.ai-chat-close:hover {
    opacity: 1;
}

/* Active-session indicator on the toggle button (shown when minimized) */
.ai-chat-toggle.ai-chat-has-session {
    box-shadow: 0 4px 16px rgba(124,77,255,.4), 0 0 0 3px rgba(124,77,255,.25);
}

.ai-chat-toggle.ai-chat-has-session::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #4caf50;
    border: 2px solid #fff;
    border-radius: 50%;
}

/* ----------------------------------------------------------------
   Message list
   ---------------------------------------------------------------- */
.ai-chat-body {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    min-height: 400px;
    max-height: 515px;
    background: #f8f8f8;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Base message bubble */
.ai-msg {
    padding: 8px 12px;
    border-radius: 8px;
    line-height: 1.5;
    max-width: 96%;
    word-wrap: break-word;
}

/* System / welcome message */
.ai-msg-system {
    background: #e8f0fe;
    color: #2c4a7c;
    border-left: 3px solid #337ab7;
    max-width: 100%;
    font-size: 13px;
}

/* User message (right-aligned) */
.ai-msg-user {
    background: #337ab7;
    color: #fff;
    align-self: flex-end;
    border-radius: 8px 8px 2px 8px;
}

/* AI response (left-aligned) */
.ai-msg-ai {
    background: #fff;
    color: #333;
    border: 1px solid #ddd;
    align-self: flex-start;
    border-radius: 8px 8px 8px 2px;
}

/* Formatted content inside AI messages */
.ai-msg-content {
    line-height: 1.6;
}

.ai-msg-content strong {
    font-weight: 700;
    color: #222;
}

.ai-msg-content em {
    font-style: italic;
}

.ai-msg-content .ai-heading {
    margin: 6px 0 4px;
    font-weight: 700;
    color: #222;
    line-height: 1.3;
}

.ai-msg-content h4.ai-heading { font-size: 14px; }
.ai-msg-content h5.ai-heading { font-size: 13px; }
.ai-msg-content h6.ai-heading { font-size: 12px; }

.ai-msg-content .ai-list {
    margin: 4px 0 4px 18px;
    padding: 0;
}

.ai-msg-content .ai-list li {
    margin-bottom: 2px;
}

.ai-msg-content .ai-code-inline {
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 1px 5px;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 12px;
    color: #c7254e;
}

.ai-msg-content .ai-code-block {
    background: #1e1e2e;
    color: #cdd6f4;
    border-radius: 6px;
    padding: 10px 12px;
    margin: 6px 0;
    overflow-x: auto;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.ai-msg-content .ai-code-block code {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

/* Blinking cursor shown while streaming */
.ai-cursor {
    display: inline-block;
    width: 2px;
    height: 14px;
    background: #7c4dff;
    margin-left: 1px;
    vertical-align: text-bottom;
    animation: ai-blink .6s step-end infinite;
}

@keyframes ai-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0; }
}

/* Typing indicator */
.ai-msg-typing {
    background: #fff;
    border: 1px solid #ddd;
    color: #888;
    align-self: flex-start;
    font-style: italic;
    border-radius: 8px 8px 8px 2px;
}

.ai-typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin: 0 2px;
    background: #999;
    border-radius: 50%;
    animation: ai-bounce .9s infinite;
}

.ai-typing-dots span:nth-child(2) { animation-delay: .15s; }
.ai-typing-dots span:nth-child(3) { animation-delay: .30s; }

@keyframes ai-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-5px); }
}

/* ----------------------------------------------------------------
   Footer
   ---------------------------------------------------------------- */
.ai-chat-footer {
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Quota counter (authenticated users only) */
.ai-chat-quota {
    font-size: 12px;
    color: #777;
    text-align: right;
}

/* Exhaustion message box */
.ai-chat-exhausted {
    background: rgba(253, 160, 10, 0.1);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 13px;
    color: #000;
    line-height: 1.5;
}

.ai-chat-exhausted .ai-exhausted-actions {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ai-chat-exhausted .ai-exhausted-actions a,
.ai-chat-exhausted .ai-exhausted-actions button {
    font-size: 12px;
}

.ai-premium-link {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #ffe082;
    font-size: 12px;
    color: #555;
}

/* Input row */
.ai-chat-input-row {
    display: flex;
    gap: 6px;
}

.ai-chat-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    transition: border-color .2s;
}

.ai-chat-input:focus {
    border-color: #337ab7;
}

.ai-chat-input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.ai-chat-send-btn {
    padding: 0px;
    flex-shrink: 0;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: #7c4dff !important;
    border: none !important;
}

/* ----------------------------------------------------------------
   Responsive — full-width panel on small screens
   ---------------------------------------------------------------- */
@media (max-width: 480px) {
    .ai-chat-panel {
        width: calc(100vw - 16px);
        right: 8px;
        bottom: 72px;
    }

    .ai-chat-toggle {
        right: 12px;
        bottom: 16px;
        padding: 8px 14px;
    }

    .ai-chat-toggle-label {
        display: none;
    }
}
