/* ============================================================
   AI Chat Panel Styles
   ============================================================ */

/* Toggle button in header */
.ai-chat-toggle {
    position: relative;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(90, 103, 114, 0.25);
    border-radius: 0.5rem;
    background: transparent;
    color: #5a6772;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ai-chat-toggle:hover {
    background: rgba(90, 103, 114, 0.08);
    border-color: rgba(90, 103, 114, 0.4);
}

.ai-chat-toggle.active {
    background: #321fdb;
    border-color: #321fdb;
    color: #fff;
}

.ai-chat-toggle .badge-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2eb85c;
    display: none;
}

.ai-chat-toggle.has-session .badge-dot {
    display: block;
}

/* Panel overlay (right side) */
.ai-chat-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 100vw;
    z-index: 1050;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    background: #fff;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
}

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

/* Panel header */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #321fdb;
    color: #fff;
    flex-shrink: 0;
}

.ai-chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
}

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

.ai-chat-header-actions button {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 16px;
    transition: all 0.15s;
}

.ai-chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* Messages area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f4f5f7;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

/* Welcome message */
.ai-chat-welcome {
    text-align: center;
    padding: 32px 16px;
    color: #636f83;
}

.ai-chat-welcome-icon {
    font-size: 48px;
    margin-bottom: 12px;
    color: #321fdb;
}

.ai-chat-welcome h4 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #303c54;
}

.ai-chat-welcome p {
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
}

.ai-chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-chat-suggestion {
    padding: 8px 14px;
    background: #fff;
    border: 1px solid #d8dbe0;
    border-radius: 8px;
    font-size: 13px;
    color: #303c54;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}

.ai-chat-suggestion:hover {
    border-color: #321fdb;
    background: #f0eeff;
}

/* Message bubbles */
.ai-msg {
    display: flex;
    gap: 8px;
    max-width: 100%;
}

.ai-msg.user {
    flex-direction: row-reverse;
}

.ai-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.ai-msg.assistant .ai-msg-avatar {
    background: #321fdb;
    color: #fff;
}

.ai-msg.user .ai-msg-avatar {
    background: #5a6772;
    color: #fff;
}

.ai-msg-body {
    max-width: calc(100% - 46px);
}

.ai-msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.65;
    word-break: break-word;
}

.ai-msg.assistant .ai-msg-bubble {
    background: #fff;
    color: #303c54;
    border-top-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.ai-msg.user .ai-msg-bubble {
    background: #321fdb;
    color: #fff;
    border-top-right-radius: 4px;
}

.ai-msg-bubble p {
    margin: 0 0 8px 0;
}

.ai-msg-bubble p:last-child {
    margin-bottom: 0;
}

.ai-msg-bubble strong {
    font-weight: 600;
}

.ai-msg-bubble ul,
.ai-msg-bubble ol {
    margin: 4px 0;
    padding-left: 20px;
}

.ai-msg-bubble li {
    margin-bottom: 2px;
}

/* Tool execution indicator */
.ai-tool-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #e8f5e9;
    border-radius: 8px;
    font-size: 12px;
    color: #2e7d32;
    margin: 4px 0;
}

.ai-tool-indicator .spinner-border {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

/* Brand cards in results */
.ai-brand-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.ai-brand-card {
    background: #f8f9fa;
    border: 1px solid #e4e7ea;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 12.5px;
    transition: all 0.15s;
}

.ai-brand-card:hover {
    border-color: #321fdb;
    box-shadow: 0 2px 6px rgba(50, 31, 219, 0.1);
}

.ai-brand-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.ai-brand-card-name {
    font-weight: 600;
    font-size: 13px;
    color: #303c54;
}

.ai-brand-card-score {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    background: #321fdb;
    color: #fff;
    font-weight: 500;
}

.ai-brand-card-meta {
    color: #636f83;
    line-height: 1.5;
}

.ai-brand-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.ai-brand-card-actions button {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 4px;
    border: 1px solid #d8dbe0;
    background: #fff;
    color: #303c54;
    cursor: pointer;
    transition: all 0.15s;
}

.ai-brand-card-actions button:hover {
    border-color: #321fdb;
    color: #321fdb;
}

/* Typing indicator */
.ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #fff;
    border-radius: 12px;
    border-top-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #636f83;
    animation: aiTypingBounce 1.4s infinite ease-in-out both;
}

.ai-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0s; }

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

/* Input area */
.ai-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #d8dbe0;
    background: #fff;
    flex-shrink: 0;
}

.ai-chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f4f5f7;
    border: 1px solid #d8dbe0;
    border-radius: 12px;
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.ai-chat-input-wrapper:focus-within {
    border-color: #321fdb;
    box-shadow: 0 0 0 2px rgba(50, 31, 219, 0.15);
}

.ai-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 14px;
    line-height: 1.5;
    max-height: 120px;
    min-height: 22px;
    outline: none;
    font-family: inherit;
    color: #303c54;
}

.ai-chat-input::placeholder {
    color: #9da5b1;
}

.ai-chat-send {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: #321fdb;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.ai-chat-send:hover {
    background: #2a19b5;
}

.ai-chat-send:disabled {
    background: #9da5b1;
    cursor: not-allowed;
}

/* Info notice */
.ai-info-notice {
    text-align: center;
    font-size: 11px;
    color: #6c757d;
    padding: 4px 12px;
    margin: 4px 0;
}

.ai-info-notice i {
    margin-right: 3px;
}

/* Grounding sources */
.ai-grounding-sources {
    margin-top: 8px;
    padding: 8px 10px;
    background: #f0f7ff;
    border-radius: 8px;
    border: 1px solid #d0e3f7;
}

.ai-grounding-label {
    font-size: 11px;
    font-weight: 600;
    color: #4a7ab5;
    margin-bottom: 5px;
}

.ai-grounding-label i {
    margin-right: 3px;
}

.ai-grounding-link {
    display: block;
    font-size: 11px;
    color: #1a73e8;
    text-decoration: none;
    padding: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-grounding-link:hover {
    text-decoration: underline;
    color: #0d47a1;
}

.ai-grounding-link i {
    font-size: 9px;
    margin-right: 3px;
}

/* Backdrop for mobile */
.ai-chat-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1049;
}

.ai-chat-backdrop.show {
    display: block;
}

/* Responsive */
@media (max-width: 576px) {
    .ai-chat-overlay {
        width: 100vw;
    }
}
