/* ─── HERITAGE ART — Chat Widget ─────────────────────────────────────────── */

:root {
    --chat-primary: #1B2A4A;
    --chat-accent: #E8732C;
    --chat-bg: #ffffff;
    --chat-light: #f4f6f8;
    --chat-border: #e2e6ea;
    --chat-text: #2d3748;
    --chat-muted: #8896a6;
    --chat-radius: 16px;
    --chat-shadow: 0 8px 32px rgba(27, 42, 74, 0.18);
}

/* ─── Toggle Button — Astou ──────────────────────────────────────────────── */

.chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), #2a3f6a);
    border: 3px solid rgba(255,255,255,0.25);
    cursor: pointer;
    box-shadow: 0 4px 24px rgba(27, 42, 74, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: astouBounce 3s ease-in-out 2s 3;
    overflow: hidden;
    padding: 0;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 32px rgba(27, 42, 74, 0.5);
    border-color: var(--chat-accent);
}

.chat-toggle .astou-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
    pointer-events: none;
}

.chat-toggle:hover .astou-avatar {
    transform: scale(1.05);
}

.chat-toggle svg.icon-close {
    width: 28px;
    height: 28px;
    fill: white;
    display: none;
}

.chat-toggle.active .astou-avatar { display: none; }
.chat-toggle.active svg.icon-close { display: block; }

.chat-toggle .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--chat-accent);
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(232,115,44,0.4);
}

.chat-toggle .chat-badge.visible {
    display: flex;
}

/* ─── Astou Tooltip Bubble ───────────────────────────────────────────────── */

.astou-tooltip {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: 9998;
    background: white;
    color: var(--chat-text);
    padding: 12px 18px;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    max-width: 260px;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Inter', sans-serif;
    border: 1px solid var(--chat-border);
}

.astou-tooltip.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    cursor: pointer;
}

.astou-tooltip .astou-tooltip-name {
    color: var(--chat-accent);
    font-weight: 700;
}

.astou-tooltip .astou-tooltip-close {
    position: absolute;
    top: 4px;
    right: 8px;
    background: none;
    border: none;
    color: var(--chat-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 2px;
    line-height: 1;
}

.astou-tooltip .astou-tooltip-close:hover {
    color: var(--chat-text);
}

/* Online dot on avatar */
.chat-toggle .online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #22c55e;
    border: 2.5px solid white;
    box-shadow: 0 0 0 0 rgba(34,197,94,0.5);
    animation: onlinePulse 2s ease-in-out infinite;
}

@keyframes onlinePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
    50% { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
}

@keyframes astouBounce {
    0%, 100% { transform: translateY(0); }
    15% { transform: translateY(-8px); }
    30% { transform: translateY(0); }
    45% { transform: translateY(-5px); }
    60% { transform: translateY(0); }
}

/* ─── Chat Window ────────────────────────────────────────────────────────── */

.chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: 9998;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 140px);
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */

.chat-header {
    background: linear-gradient(135deg, var(--chat-primary), #2a3f6a);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
}

.chat-header-title {
    font-weight: 700;
    font-size: 15px;
    margin: 0;
}

.chat-header-status {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-header-status .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
}

.chat-header-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.chat-header-close:hover {
    opacity: 1;
}

/* ─── Messages Area ──────────────────────────────────────────────────────── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--chat-light);
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 3px;
}

/* ─── Message Bubbles ────────────────────────────────────────────────────── */

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: chatFadeIn 0.3s ease;
}

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

.chat-msg.visitor {
    align-self: flex-end;
}

.chat-msg.ai,
.chat-msg.agent,
.chat-msg.system {
    align-self: flex-start;
}

.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-msg.visitor .chat-msg-bubble {
    background: var(--chat-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg.ai .chat-msg-bubble {
    background: white;
    color: var(--chat-text);
    border: 1px solid var(--chat-border);
    border-bottom-left-radius: 4px;
}

.chat-msg.agent .chat-msg-bubble {
    background: white;
    color: var(--chat-text);
    border: 1px solid var(--chat-accent);
    border-bottom-left-radius: 4px;
}

.chat-msg.system .chat-msg-bubble {
    background: #fef3c7;
    color: #92400e;
    font-size: 12px;
    text-align: center;
    align-self: center;
    border-radius: 8px;
    max-width: 100%;
}

.chat-msg-meta {
    font-size: 11px;
    color: var(--chat-muted);
    margin-top: 3px;
    padding: 0 4px;
}

.chat-msg.visitor .chat-msg-meta {
    text-align: right;
}

/* Markdown-like formatting in messages */
.chat-msg-bubble strong,
.chat-msg-bubble b {
    font-weight: 600;
}

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

.chat-msg-bubble li {
    margin: 2px 0;
}

/* ─── Typing Indicator ───────────────────────────────────────────────────── */

.chat-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 16px;
    background: white;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

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

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-muted);
    animation: typingDot 1.4s infinite;
}

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

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ─── Input Area ─────────────────────────────────────────────────────────── */

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

.chat-input {
    flex: 1;
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 80px;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.4;
}

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

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

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--chat-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: #d4631f;
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    background: var(--chat-border);
    cursor: not-allowed;
    transform: none;
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* ─── Quick Actions ──────────────────────────────────────────────────────── */

.chat-quick-actions {
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    background: var(--chat-light);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chat-quick-btn {
    padding: 6px 12px;
    border: 1px solid var(--chat-border);
    border-radius: 16px;
    background: white;
    font-size: 12px;
    color: var(--chat-primary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.chat-quick-btn:hover {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
}

/* ─── Escalation Banner ──────────────────────────────────────────────────── */

.chat-escalate-bar {
    display: none;
    padding: 8px 16px;
    background: #fef3c7;
    border-top: 1px solid #fcd34d;
    text-align: center;
    flex-shrink: 0;
}

.chat-escalate-bar.visible {
    display: block;
}

.chat-escalate-btn {
    padding: 6px 16px;
    border: none;
    border-radius: 16px;
    background: var(--chat-accent);
    color: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-escalate-btn:hover {
    background: #d4631f;
}

/* ─── Mobile Responsive ──────────────────────────────────────────────────── */

/* ─── Pulse Animation ────────────────────────────────────────────────────── */

.chat-toggle.pulse {
    animation: chatPulse 1.5s ease !important;
}

@keyframes chatPulse {
    0% { box-shadow: 0 4px 24px rgba(27, 42, 74, 0.4); }
    25% { box-shadow: 0 0 0 14px rgba(232, 115, 44, 0.35); }
    50% { box-shadow: 0 0 0 22px rgba(232, 115, 44, 0); }
    100% { box-shadow: 0 4px 24px rgba(27, 42, 74, 0.4); }
}

@media (max-width: 480px) {
    .chat-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .chat-toggle {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }

    .astou-tooltip {
        bottom: 78px;
        right: 16px;
        max-width: 220px;
        font-size: 13px;
    }
}
