/* ===================================
   FINBOT — Vintage Financial Chatbot
   =================================== */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&display=swap');

/* --- Chatbot Design Tokens --- */
:root {
    --cb-accent: var(--accent);
    --cb-accent-hover: var(--accent-hover);
    --cb-accent-subtle: var(--accent-subtle);
    --cb-accent-border: var(--accent-border);
    --cb-bg: #F7F0E5;
    --cb-bg-elevated: #EDE1D0;
    --cb-bg-msg-user: var(--accent-subtle);
    --cb-bg-msg-bot: rgba(192, 138, 62, 0.10);
    --cb-width: 380px;
    --cb-bubble-size: 56px;
}

/* ===================================
   FLOATING BUBBLE — Dynamic Island Glass
   =================================== */
.chatbot-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--cb-bubble-size);
    height: var(--cb-bubble-size);
    border-radius: 50%;
    background: rgba(28, 28, 30, 0.72);
    backdrop-filter: blur(24px) saturate(1.8);
    -webkit-backdrop-filter: blur(24px) saturate(1.8);
    border: 1px solid rgba(255, 255, 255, 0.10);
    color: rgba(255, 255, 255, 0.92);
    font-size: 1.25rem;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.18),
        0 0 0 1px rgba(255, 255, 255, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

.chatbot-bubble::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: conic-gradient(
        from 180deg,
        rgba(192, 138, 62, 0.0),
        rgba(192, 138, 62, 0.25),
        rgba(192, 138, 62, 0.0)
    );
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: -1;
    animation: bubbleGlowSpin 4s linear infinite;
}

.chatbot-bubble:hover {
    transform: scale(1.08);
    background: rgba(28, 28, 30, 0.82);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.25),
        0 0 0 1px rgba(255, 255, 255, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.chatbot-bubble:hover::before {
    opacity: 1;
}

@keyframes bubbleGlowSpin {
    to { transform: rotate(360deg); }
}

.chatbot-bubble.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* ===================================
   CHAT PANEL
   =================================== */
.chatbot-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--cb-width);
    height: 560px;
    max-height: 80vh;
    background-color: var(--cb-bg);
    border: 1px solid var(--cb-accent-border);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    z-index: 1001;
    box-shadow: 0 16px 42px rgba(35, 28, 20, 0.20), 0 0 0 1px rgba(192, 138, 62, 0.18);
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.chatbot-panel.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}

/* ===================================
   HEADER
   =================================== */
.chatbot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: linear-gradient(180deg, #E3D6C5, var(--cb-bg));
    border-bottom: 1px solid var(--cb-accent-border);
    position: relative;
    flex-shrink: 0;
}

.chatbot-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 16px;
    right: 16px;
    height: 1px;
    background: linear-gradient(90deg,
        transparent, var(--cb-accent) 20%,
        var(--cb-accent) 80%, transparent);
    opacity: 0.3;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.chatbot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cb-accent-subtle);
    border: 1px solid var(--cb-accent-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cb-accent);
    font-size: 1rem;
    flex-shrink: 0;
}

.chatbot-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--cb-accent);
    letter-spacing: 0.5px;
    margin: 0;
    line-height: 1.2;
}

.chatbot-status {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    font-style: italic;
}

.chatbot-header-actions {
    display: flex;
    gap: var(--space-xs);
}

.chatbot-header-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: all var(--transition-fast);
}

.chatbot-header-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

/* ===================================
   MESSAGES AREA
   =================================== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-base);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    scrollbar-width: thin;
    scrollbar-color: var(--cb-accent-border) transparent;
}

.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background-color: var(--cb-accent-border);
    border-radius: var(--radius-full);
}

/* ===================================
   MESSAGE BUBBLES
   =================================== */
.chat-message {
    display: flex;
    gap: var(--space-sm);
    max-width: 88%;
    animation: cbMsgSlide 0.3s ease;
}

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

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.assistant {
    align-self: flex-start;
}

.chat-message .message-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-message.assistant .message-avatar {
    background: var(--cb-accent-subtle);
    color: var(--cb-accent);
    border: 1px solid var(--cb-accent-border);
}

.chat-message.user .message-avatar {
    background: var(--accent-subtle);
    color: var(--accent);
    border: 1px solid var(--accent-border);
}

.chat-message .message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 0.84rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-message.assistant .message-bubble {
    background-color: var(--cb-bg-msg-bot);
    border: 1px solid rgba(192, 138, 62, 0.12);
    color: var(--text-primary);
    border-bottom-left-radius: var(--space-xs);
}

.chat-message.user .message-bubble {
    background-color: var(--cb-bg-msg-user);
    border: 1px solid var(--accent-border);
    color: var(--text-primary);
    border-bottom-right-radius: var(--space-xs);
}

.chat-message .message-bubble strong {
    color: var(--cb-accent);
}

/* --- Markdown inside bubbles --- */
.chat-message .message-bubble p {
    margin: 0 0 0.45em;
}

.chat-message .message-bubble p:last-child {
    margin-bottom: 0;
}

.chat-message .message-bubble ul,
.chat-message .message-bubble ol {
    margin: 0.3em 0;
    padding-left: 1.4em;
}

.chat-message .message-bubble li {
    margin-bottom: 0.2em;
}

.chat-message .message-bubble code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.82em;
}

.chat-message .message-bubble pre {
    background: rgba(0,0,0,0.06);
    padding: 8px 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.4em 0;
}

.chat-message .message-bubble pre code {
    background: none;
    padding: 0;
}

.chat-message .message-bubble h1,
.chat-message .message-bubble h2,
.chat-message .message-bubble h3 {
    font-size: 0.92em;
    font-weight: 700;
    margin: 0.5em 0 0.25em;
    color: var(--cb-accent);
}

.chat-message .message-bubble hr {
    border: none;
    border-top: 1px solid var(--cb-accent-border);
    margin: 0.5em 0;
}

.chat-message .message-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.4em 0;
    font-size: 0.82em;
}

.chat-message .message-bubble th,
.chat-message .message-bubble td {
    border: 1px solid var(--cb-accent-border);
    padding: 4px 8px;
    text-align: left;
}

.chat-message .message-bubble th {
    background: var(--cb-accent-subtle);
    font-weight: 600;
}

/* ===================================
   TYPING INDICATOR
   =================================== */
.chatbot-typing-wrapper {
    display: none;
}

.chatbot-typing-wrapper.visible {
    display: flex;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--cb-accent);
    opacity: 0.35;
    animation: cbTypingDot 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cbTypingDot {
    0%, 60%, 100% { opacity: 0.35; transform: scale(1); }
    30% { opacity: 1; transform: scale(1.25); }
}

/* ===================================
   FOLLOW-UP OPTIONS
   =================================== */
.chatbot-followup-options {
    padding: var(--space-sm) var(--space-base);
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chatbot-followup-options.visible {
    display: flex;
}

.followup-btn {
    padding: 6px 14px;
    font-size: 0.73rem;
    font-weight: 500;
    border-radius: var(--radius-full);
    border: 1px solid var(--cb-accent-border);
    background: var(--cb-accent-subtle);
    color: var(--cb-accent);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: 'Inter', sans-serif;
}

.followup-btn:hover {
    background: var(--cb-accent);
    color: #FFFFFF;
    border-color: var(--cb-accent);
}

/* ===================================
   SUGGESTION CHIPS
   =================================== */
.chatbot-suggestions {
    padding: var(--space-sm) var(--space-base);
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chatbot-suggestions::-webkit-scrollbar {
    display: none;
}

.chatbot-suggestions.hidden {
    display: none;
}

.suggestion-chip {
    padding: 6px 12px;
    font-size: 0.7rem;
    white-space: nowrap;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: 'Inter', sans-serif;
    display: flex;
    align-items: center;
    gap: 4px;
}

.suggestion-chip:hover {
    border-color: var(--cb-accent-border);
    color: var(--cb-accent);
    background: var(--cb-accent-subtle);
}

.suggestion-chip i {
    font-size: 0.65rem;
}

/* ===================================
   INPUT AREA
   =================================== */
.chatbot-input-area {
    display: flex;
    padding: var(--space-md) var(--space-base);
    gap: var(--space-sm);
    border-top: 1px solid var(--cb-accent-border);
    background-color: var(--cb-bg-elevated);
    flex-shrink: 0;
}

.chatbot-input-area input {
    flex: 1;
    padding: 10px 14px;
    font-size: 0.84rem;
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    outline: none;
    font-family: 'Inter', sans-serif;
    transition: all var(--transition-fast);
    /* Override global width: 100% from styles.css */
    width: auto;
}

.chatbot-input-area input:focus {
    border-color: var(--cb-accent);
    box-shadow: 0 0 0 3px var(--cb-accent-subtle);
}

.chatbot-input-area input::placeholder {
    color: var(--text-tertiary);
}

.chatbot-input-area button {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    border: none;
    background: var(--cb-accent);
    color: #FFFFFF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    font-size: 0.85rem;
    flex-shrink: 0;
}

.chatbot-input-area button:hover {
    background: var(--cb-accent-hover);
}

.chatbot-input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===================================
   RESPONSIVE
   =================================== */
@media (max-width: 480px) {
    .chatbot-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        max-height: none;
        bottom: 8px;
        right: 8px;
        border-radius: var(--radius-lg);
    }

    .chatbot-bubble {
        bottom: 16px;
        right: 16px;
    }
}
