/* ============================================
   AI STUDY ASSISTANT CHAT STYLES
   ============================================ */

/* Floating Action Button */
.ai-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2f6f5b 0%, #1d4a3d 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 20px rgba(47, 111, 91, 0.45), 0 0 0 1px rgba(47, 111, 91, 0.2);
    z-index: 9998;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
    user-select: none;
}

.ai-chat-fab:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 6px 28px rgba(47, 111, 91, 0.55), 0 0 0 2px rgba(47, 111, 91, 0.25);
}

.ai-chat-fab:active {
    transform: scale(0.95);
}

.ai-chat-fab.active {
    transform: scale(0.9) rotate(45deg);
    background: linear-gradient(135deg, #52645d 0%, #3a4a44 100%);
}

.ai-chat-fab-icon {
    position: relative;
    z-index: 2;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

.ai-chat-fab-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: rgba(47, 111, 91, 0.25);
    animation: aiChatPulse 2.5s ease-in-out infinite;
    z-index: 1;
}

@keyframes aiChatPulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.15); opacity: 0; }
}

/* Chat Drawer */
.ai-chat-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: linear-gradient(180deg, rgba(18, 24, 22, 0.97) 0%, rgba(12, 16, 15, 0.98) 100%);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    border-left: 1px solid rgba(113, 133, 125, 0.18);
    box-shadow: -12px 0 48px rgba(2, 5, 4, 0.55);
    z-index: 9997;
    display: flex;
    flex-direction: column;
    transform: translateX(110%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    will-change: transform;
}

.ai-chat-drawer.open {
    transform: translateX(0);
}

/* Header */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid rgba(113, 133, 125, 0.14);
    background: rgba(22, 28, 26, 0.6);
    flex-shrink: 0;
}

.ai-chat-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-header-icon {
    font-size: 1.4rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(47, 111, 91, 0.18);
    border-radius: 10px;
    border: 1px solid rgba(47, 111, 91, 0.22);
}

.ai-chat-header-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: #edf3ef;
    letter-spacing: -0.01em;
}

.ai-chat-header-status {
    font-size: 0.72rem;
    color: #71857d;
    margin-top: 1px;
}

.ai-chat-header-actions {
    display: flex;
    gap: 6px;
}

.ai-chat-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(113, 133, 125, 0.18);
    background: rgba(15, 20, 18, 0.5);
    color: #9aa9a2;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.15s ease;
}

.ai-chat-header-btn:hover {
    background: rgba(47, 111, 91, 0.18);
    color: #edf3ef;
    border-color: rgba(47, 111, 91, 0.35);
}

/* Settings */
.ai-chat-settings {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(113, 133, 125, 0.1);
    background: rgba(15, 20, 18, 0.4);
    flex-shrink: 0;
}

.ai-chat-setting-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.ai-chat-setting-row:last-child {
    margin-bottom: 0;
}

.ai-chat-setting-row label {
    font-size: 0.8rem;
    color: #9aa9a2;
    font-weight: 500;
    white-space: nowrap;
}

.ai-chat-setting-row select {
    flex: 1;
    background: rgba(15, 20, 18, 0.7);
    border: 1px solid rgba(113, 133, 125, 0.2);
    border-radius: 8px;
    padding: 5px 10px;
    color: #d7e0db;
    font-size: 0.82rem;
    cursor: pointer;
    outline: none;
}

.ai-chat-setting-row select:focus {
    border-color: rgba(47, 111, 91, 0.5);
}

.ai-chat-toggle-row {
    justify-content: space-between;
}

.ai-chat-toggle-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #2f6f5b;
    cursor: pointer;
}

.ai-chat-api-key {
    width: 100%;
    background: rgba(15, 20, 18, 0.7);
    border: 1px solid rgba(113, 133, 125, 0.2);
    border-radius: 8px;
    padding: 6px 10px;
    color: #d7e0db;
    font-size: 0.82rem;
    outline: none;
    margin-top: 4px;
    display: none;
}

.ai-chat-api-key:focus {
    border-color: rgba(47, 111, 91, 0.5);
}

.ai-chat-api-key::placeholder {
    color: #5a6b63;
}

/* Pre-built Prompts */
.ai-chat-prebuilt {
    display: flex;
    gap: 6px;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(113, 133, 125, 0.1);
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(113, 133, 125, 0.2) transparent;
}

.ai-chat-prebuilt::-webkit-scrollbar {
    height: 4px;
}

.ai-chat-prebuilt::-webkit-scrollbar-thumb {
    background: rgba(113, 133, 125, 0.25);
    border-radius: 4px;
}

.ai-chat-prebuilt-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border-radius: 20px;
    border: 1px solid rgba(113, 133, 125, 0.18);
    background: linear-gradient(180deg, rgba(25, 33, 30, 0.7) 0%, rgba(15, 20, 18, 0.8) 100%);
    color: #c5d1cb;
    font-size: 0.78rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.ai-chat-prebuilt-btn:hover {
    background: rgba(47, 111, 91, 0.18);
    border-color: rgba(47, 111, 91, 0.4);
    color: #edf3ef;
    transform: translateY(-1px);
}

.ai-chat-prebuilt-btn:active {
    transform: scale(0.97);
}

.ai-chat-prebuilt-label {
    display: inline;
}

@media (max-width: 480px) {
    .ai-chat-prebuilt-label {
        display: none;
    }
    .ai-chat-prebuilt-btn {
        padding: 6px 8px;
    }
}

/* Messages Area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(113, 133, 125, 0.2) transparent;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(113, 133, 125, 0.25);
    border-radius: 4px;
}

/* Message Bubbles */
.ai-chat-bubble {
    display: flex;
    flex-direction: column;
    max-width: 92%;
    animation: aiChatBubbleIn 0.3s ease both;
}

@keyframes aiChatBubbleIn {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

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

.ai-chat-bubble-content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.55;
    position: relative;
    word-wrap: break-word;
}

.ai-chat-user .ai-chat-bubble-content {
    background: linear-gradient(135deg, #2f6f5b 0%, #23614d 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(47, 111, 91, 0.25);
}

.ai-chat-assistant .ai-chat-bubble-content {
    background: linear-gradient(135deg, rgba(35, 44, 40, 0.9) 0%, rgba(25, 33, 30, 0.92) 100%);
    color: #d7e0db;
    border: 1px solid rgba(113, 133, 125, 0.14);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.ai-chat-bubble-text strong {
    color: #a8c4b8;
    font-weight: 600;
}

.ai-chat-bubble-text em {
    color: #b8ccc4;
}

.ai-chat-bubble-time {
    font-size: 0.68rem;
    color: #5a6b63;
    margin-top: 3px;
    padding: 0 4px;
}

.ai-chat-copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 1px solid rgba(113, 133, 125, 0.15);
    background: rgba(15, 20, 18, 0.6);
    color: #71857d;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.ai-chat-assistant .ai-chat-bubble-content:hover .ai-chat-copy-btn {
    opacity: 1;
}

.ai-chat-copy-btn:hover {
    background: rgba(47, 111, 91, 0.25);
    color: #edf3ef;
}

/* Typing Indicator */
.ai-chat-typing .ai-chat-bubble-content {
    padding: 12px 16px;
    display: flex;
    align-items: center;
}

.ai-chat-typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.ai-chat-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #71857d;
    animation: aiChatTypingBounce 1.4s ease-in-out infinite both;
}

.ai-chat-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.ai-chat-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes aiChatTypingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.ai-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px 16px;
    border-top: 1px solid rgba(113, 133, 125, 0.12);
    background: rgba(15, 20, 18, 0.5);
    flex-shrink: 0;
}

.ai-chat-input {
    flex: 1;
    background: rgba(15, 20, 18, 0.7);
    border: 1px solid rgba(113, 133, 125, 0.18);
    border-radius: 14px;
    padding: 10px 14px;
    color: #d7e0db;
    font-size: 0.9rem;
    line-height: 1.4;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 40px;
    font-family: inherit;
    transition: border-color 0.15s ease;
}

.ai-chat-input:focus {
    border-color: rgba(47, 111, 91, 0.5);
    box-shadow: 0 0 0 3px rgba(47, 111, 91, 0.08);
}

.ai-chat-input::placeholder {
    color: #5a6b63;
}

.ai-chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #2f6f5b 0%, #23614d 100%);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s ease;
    box-shadow: 0 2px 8px rgba(47, 111, 91, 0.3);
}

.ai-chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 14px rgba(47, 111, 91, 0.4);
}

.ai-chat-send-btn:active {
    transform: scale(0.95);
}

/* Mobile Responsive */
@media (max-width: 520px) {
    .ai-chat-drawer {
        width: 100vw;
        border-left: none;
    }

    .ai-chat-fab {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
    }
}

/* Light theme overrides */
body[data-theme="light"] .ai-chat-drawer {
    background: linear-gradient(180deg, rgba(245, 248, 246, 0.97) 0%, rgba(235, 240, 237, 0.98) 100%);
    border-left-color: rgba(93, 111, 104, 0.12);
}

body[data-theme="light"] .ai-chat-header {
    background: rgba(255, 255, 255, 0.6);
    border-bottom-color: rgba(93, 111, 104, 0.1);
}

body[data-theme="light"] .ai-chat-header-name {
    color: #202b27;
}

body[data-theme="light"] .ai-chat-header-status {
    color: #6b7d76;
}

body[data-theme="light"] .ai-chat-header-btn {
    background: rgba(235, 240, 237, 0.7);
    color: #6b7d76;
    border-color: rgba(93, 111, 104, 0.12);
}

body[data-theme="light"] .ai-chat-header-btn:hover {
    background: rgba(47, 111, 91, 0.1);
    color: #202b27;
}

body[data-theme="light"] .ai-chat-settings {
    background: rgba(235, 240, 237, 0.4);
}

body[data-theme="light"] .ai-chat-setting-row select,
body[data-theme="light"] .ai-chat-api-key,
body[data-theme="light"] .ai-chat-input {
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(93, 111, 104, 0.15);
    color: #202b27;
}

body[data-theme="light"] .ai-chat-input::placeholder {
    color: #8a9a93;
}

body[data-theme="light"] .ai-chat-prebuilt {
    border-bottom-color: rgba(93, 111, 104, 0.08);
}

body[data-theme="light"] .ai-chat-prebuilt-btn {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.8) 0%, rgba(235, 240, 237, 0.9) 100%);
    color: #3f524b;
    border-color: rgba(93, 111, 104, 0.12);
}

body[data-theme="light"] .ai-chat-prebuilt-btn:hover {
    background: rgba(47, 111, 91, 0.1);
    border-color: rgba(47, 111, 91, 0.3);
    color: #202b27;
}

body[data-theme="light"] .ai-chat-assistant .ai-chat-bubble-content {
    background: linear-gradient(135deg, rgba(235, 240, 237, 0.95) 0%, rgba(225, 232, 228, 0.97) 100%);
    color: #3f524b;
    border-color: rgba(93, 111, 104, 0.1);
}

body[data-theme="light"] .ai-chat-bubble-text strong {
    color: #2a5c4a;
}

body[data-theme="light"] .ai-chat-bubble-text em {
    color: #4a6358;
}

body[data-theme="light"] .ai-chat-bubble-time {
    color: #8a9a93;
}

body[data-theme="light"] .ai-chat-copy-btn {
    background: rgba(235, 240, 237, 0.7);
    color: #6b7d76;
}

body[data-theme="light"] .ai-chat-copy-btn:hover {
    background: rgba(47, 111, 91, 0.15);
    color: #202b27;
}

body[data-theme="light"] .ai-chat-input-area {
    background: rgba(235, 240, 237, 0.4);
    border-top-color: rgba(93, 111, 104, 0.08);
}

body[data-theme="light"] .ai-chat-typing-dots span {
    background: #8a9a93;
}
