/* TOTEM AI Chatbot Widget — Scoped styles */
:root {
    --totem-primary: #0a0a0a;
    --totem-primary-light: #1f1f1f;
    --totem-accent: #c8a96e;
    --totem-bg: #ffffff;
    --totem-bg-user: #f4f4f4;
    --totem-text: #1a1a1a;
    --totem-text-muted: #6b6b6b;
    --totem-border: #e5e5e5;
    --totem-shadow: 0 8px 32px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.08);
    --totem-radius: 16px;
    --totem-btn-radius: 50%;
    --totem-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --totem-z: 999999;
    --totem-width: 380px;
    --totem-height: 560px;
}

/* Floating button */
#totem-chatbot-root {
    position: fixed;
    z-index: var(--totem-z);
    font-family: var(--totem-font);
    box-sizing: border-box;
}

#totem-chatbot-root *,
#totem-chatbot-root *::before,
#totem-chatbot-root *::after {
    box-sizing: border-box;
}

#totem-chatbot-root.position-bottom-right {
    bottom: 24px;
    right: 24px;
}

#totem-chatbot-root.position-bottom-left {
    bottom: 24px;
    left: 24px;
}

/* Trigger button */
.totem-trigger-btn {
    width: 60px;
    height: 60px;
    border-radius: var(--totem-btn-radius);
    background: var(--totem-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.24);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    color: #000;
    position: relative;
    outline: none;
}

.totem-trigger-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.totem-trigger-btn:focus-visible {
    outline: 3px solid var(--totem-accent);
    outline-offset: 2px;
}

.totem-trigger-btn svg {
    width: 26px;
    height: 26px;
    fill: #fff;
}

.totem-trigger-btn .totem-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: var(--totem-accent);
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
}

/* Chat window */
.totem-chat-window {
    position: absolute;
    bottom: 72px;
    width: var(--totem-width);
    height: var(--totem-height);
    background: var(--totem-bg);
    border-radius: var(--totem-radius);
    box-shadow: var(--totem-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.position-bottom-right .totem-chat-window {
    right: 0;
    transform-origin: bottom right;
}

.position-bottom-left .totem-chat-window {
    left: 0;
    transform-origin: bottom left;
}

.totem-chat-window.totem-hidden {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
    pointer-events: none;
}

/* Header */
.totem-chat-header {
    background: var(--totem-primary);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.totem-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.totem-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--totem-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: #000;
    flex-shrink: 0;
}

.totem-chat-header-text h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.totem-chat-header-text p {
    margin: 0;
    font-size: 11px;
    color: rgba(255,255,255,0.65);
}

.totem-close-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.75);
    cursor: pointer;
    padding: 4px;
    line-height: 0;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.totem-close-btn:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.totem-close-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Privacy notice */
.totem-privacy-notice {
    background: #fefce8;
    border-bottom: 1px solid #fde68a;
    padding: 8px 16px;
    font-size: 11px;
    color: #854d0e;
    line-height: 1.4;
    flex-shrink: 0;
}

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

.totem-messages::-webkit-scrollbar {
    width: 4px;
}
.totem-messages::-webkit-scrollbar-thumb {
    background: #e0e0e0;
    border-radius: 2px;
}

/* Individual messages */
.totem-msg {
    display: flex;
    gap: 8px;
    animation: totemFadeUp 0.2s ease;
}

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

.totem-msg--assistant {
    align-items: flex-start;
}

.totem-msg--user {
    align-items: flex-end;
    flex-direction: row-reverse;
}

.totem-msg__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--totem-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

.totem-msg__bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--totem-text);
    word-wrap: break-word;
}

.totem-msg--assistant .totem-msg__bubble {
    background: var(--totem-bg-user);
    border-bottom-left-radius: 4px;
}

.totem-msg--user .totem-msg__bubble {
    background: var(--totem-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.totem-msg__time {
    font-size: 10px;
    color: var(--totem-text-muted);
    margin-top: 4px;
    text-align: right;
}

/* Typing indicator */
.totem-typing {
    display: flex;
    align-items: center;
    gap: 8px;
}

.totem-typing-dots {
    display: flex;
    gap: 4px;
    background: var(--totem-bg-user);
    padding: 10px 14px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.totem-typing-dots span {
    width: 7px;
    height: 7px;
    background: #b0b0b0;
    border-radius: 50%;
    animation: totemBounce 1.2s infinite;
}

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

@keyframes totemBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Suggested questions */
.totem-suggestions {
    padding: 0 16px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.totem-suggestion-btn {
    background: none;
    border: 1px solid var(--totem-border);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 12px;
    color: var(--totem-text-muted);
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--totem-font);
}

.totem-suggestion-btn:hover {
    border-color: var(--totem-primary);
    color: var(--totem-primary);
    background: #f9f9f9;
}

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

.totem-input-wrap {
    flex: 1;
    position: relative;
}

.totem-input {
    width: 100%;
    border: 1px solid var(--totem-border);
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 13.5px;
    font-family: var(--totem-font);
    resize: none;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: auto;
    color: var(--totem-text);
    background: #fafafa;
    transition: border-color 0.15s;
    outline: none;
}

.totem-input:focus {
    border-color: var(--totem-primary);
    background: #fff;
}

.totem-input::placeholder {
    color: #b0b0b0;
}

.totem-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--totem-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
    color: #fff;
}

.totem-send-btn:hover {
    background: var(--totem-primary-light);
}

.totem-send-btn:active {
    transform: scale(0.93);
}

.totem-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.totem-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
    transform: translateX(1px);
}

/* Error message */
.totem-error-msg {
    padding: 8px 16px;
    background: #fef2f2;
    border-top: 1px solid #fecaca;
    font-size: 12px;
    color: #dc2626;
    text-align: center;
}

/* Inline embed */
.totem-chatbot-inline-container {
    width: 100%;
    max-width: var(--totem-width);
    height: var(--totem-height);
    border: 1px solid var(--totem-border);
    border-radius: var(--totem-radius);
    overflow: hidden;
    box-shadow: var(--totem-shadow);
}

/* Mobile responsive */
@media (max-width: 480px) {
    :root {
        --totem-width: calc(100vw - 16px);
        --totem-height: calc(100vh - 100px);
    }

    .position-bottom-right .totem-chat-window,
    .position-bottom-left .totem-chat-window {
        right: 0;
        left: 0;
        bottom: 72px;
    }

    #totem-chatbot-root.position-bottom-right,
    #totem-chatbot-root.position-bottom-left {
        right: 8px;
        left: 8px;
        bottom: 16px;
    }
}
