/* Chat Widget Styles
   Prefix: --chat-*
   z-index: 1100 (above back-to-top: 1000)
*/

:root {
    --chat-accent: #dc7603;
    --chat-accent-hover: #b85e00;
    --chat-accent-light: rgba(220, 118, 3, 0.12);
    --chat-bg: #1e1e1e;
    --chat-bg-panel: #252525;
    --chat-bg-header: #1a1a1a;
    --chat-bg-input: #2e2e2e;
    --chat-bg-user: #dc7603;
    --chat-bg-ai: #2e2e2e;
    --chat-text: #e8e8e8;
    --chat-text-muted: #888;
    --chat-border: rgba(255, 255, 255, 0.08);
    --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    --chat-radius: 16px;
    --chat-radius-msg: 12px;
    --chat-z-index: 1100;
    --chat-fab-size: 56px;
    --chat-fab-bottom: 20px;
    --chat-fab-right: 20px;
    --chat-panel-width: 380px;
    --chat-panel-height: 500px;
    --chat-panel-bottom: 86px;
    --chat-transition: 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* FAB button */
.chat-fab {
    position: fixed;
    bottom: var(--chat-fab-bottom);
    right: var(--chat-fab-right);
    width: var(--chat-fab-size);
    height: var(--chat-fab-size);
    border-radius: 50%;
    background-color: var(--chat-accent);
    border: none;
    cursor: pointer;
    z-index: var(--chat-z-index);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(220, 118, 3, 0.4);
    transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

.chat-fab:hover {
    background-color: var(--chat-accent-hover);
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(220, 118, 3, 0.55);
}

.chat-fab:focus-visible {
    outline: 2px solid var(--chat-accent);
    outline-offset: 3px;
}

.chat-fab svg {
    width: 24px;
    height: 24px;
    fill: #fff;
    pointer-events: none;
    transition: transform 0.2s ease;
}

/* Pulse animation while closed */
@keyframes chat-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(220, 118, 3, 0.5); }
    70%  { box-shadow: 0 0 0 12px rgba(220, 118, 3, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 118, 3, 0); }
}

.chat-fab--pulse {
    animation: chat-pulse 2.4s ease-out infinite;
}

/* Chat panel */
.chat-panel {
    position: fixed;
    bottom: var(--chat-panel-bottom);
    right: var(--chat-fab-right);
    width: var(--chat-panel-width);
    height: var(--chat-panel-height);
    background: var(--chat-bg-panel);
    border-radius: var(--chat-radius);
    border: 1px solid var(--chat-border);
    box-shadow: var(--chat-shadow);
    z-index: var(--chat-z-index);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Hidden state */
    opacity: 0;
    visibility: hidden;
    transform: scale(0.85) translateY(16px);
    transform-origin: bottom right;
    transition: opacity var(--chat-transition),
                visibility var(--chat-transition),
                transform var(--chat-transition);
}

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

/* Panel header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--chat-bg-header);
    border-bottom: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chat-header-icon {
    width: 32px;
    height: 32px;
    background: var(--chat-accent-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-header-icon svg {
    width: 16px;
    height: 16px;
    fill: var(--chat-accent);
}

.chat-header-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--chat-text);
    line-height: 1.2;
}

.chat-header-subtitle {
    font-size: 11px;
    color: var(--chat-text-muted);
    font-weight: 400;
}

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

.chat-header-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--chat-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease;
    padding: 0;
    font-size: 14px;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--chat-text);
}

.chat-header-btn:focus-visible {
    outline: 2px solid var(--chat-accent);
    outline-offset: 1px;
}

.chat-header-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

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

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

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

/* Message bubbles */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: chat-msg-in 0.2s ease-out;
}

@keyframes chat-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

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

.chat-bubble {
    padding: 9px 13px;
    border-radius: var(--chat-radius-msg);
    font-size: 13.5px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-message--user .chat-bubble {
    background: var(--chat-bg-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message--ai .chat-bubble {
    background: var(--chat-bg-ai);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
}

.chat-message--error .chat-bubble {
    background: rgba(200, 50, 50, 0.2);
    color: #ff8080;
    border: 1px solid rgba(200, 50, 50, 0.3);
}

/* Typing indicator */
.chat-typing-indicator {
    align-self: flex-start;
    padding: 10px 14px;
    background: var(--chat-bg-ai);
    border-radius: var(--chat-radius-msg);
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.chat-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-text-muted);
    animation: chat-typing-bounce 1.2s ease-in-out infinite;
}

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

@keyframes chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-5px); opacity: 1; }
}

/* Input area */
.chat-input-area {
    padding: 12px 14px;
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: var(--chat-bg-input);
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    padding: 9px 12px;
    color: var(--chat-text);
    font-size: 13.5px;
    font-family: inherit;
    resize: none;
    min-height: 38px;
    max-height: 100px;
    line-height: 1.45;
    outline: none;
    transition: border-color 0.15s ease;
    overflow-y: auto;
}

.chat-input::placeholder {
    color: var(--chat-text-muted);
}

.chat-input:focus {
    border-color: var(--chat-accent);
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--chat-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.15s ease, transform 0.1s ease;
    padding: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--chat-accent-hover);
}

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.94);
}

.chat-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.chat-send-btn svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

.chat-send-btn:focus-visible {
    outline: 2px solid var(--chat-accent);
    outline-offset: 2px;
}

/* Raise back-to-top when chat is present */
body.has-chat .back-to-top {
    bottom: 88px;
    transition: bottom 0.3s ease;
}

/* Print: hide chat */
@media print {
    .chat-fab,
    .chat-panel {
        display: none !important;
    }
}

/* Mobile */
@media (max-width: 480px) {
    .chat-panel {
        --chat-panel-width: calc(100vw - 16px);
        right: 8px;
        left: 8px;
        width: auto;
    }

    .chat-fab {
        --chat-fab-right: 12px;
        right: 12px;
    }
}
