/* ===== Chat Widget ===== */
#chatWidget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.chat-bubble-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: block;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    transition: transform var(--transition), box-shadow var(--transition);
}

.chat-bubble-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 18px rgba(0,0,0,.32);
}

.chat-bubble-img {
    width: 64px;
    height: 64px;
    display: block;
    object-fit: cover;
}

.chat-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* ===== Chat Panel ===== */
.chat-panel {
    width: 340px;
    max-height: 480px;
    background: #fff;
    border-radius: var(--radius-card);
    box-shadow: 0 8px 40px rgba(6,47,110,.18);
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
    overflow: hidden;
    animation: chatSlideUp .22s ease;
}

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

/* ===== Header ===== */
.chat-header {
    background: var(--cro-blue);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

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

.chat-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,.18);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.chat-bot-name {
    font-weight: 600;
    font-size: .88rem;
    line-height: 1.2;
}

.chat-bot-status {
    font-size: .7rem;
    opacity: .78;
}

.chat-close-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: .95rem;
    padding: 4px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: background .15s;
}

.chat-close-btn:hover { background: rgba(255,255,255,.15); }

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

.chat-msg { display: flex; }
.chat-msg-bot  { justify-content: flex-start; }
.chat-msg-user { justify-content: flex-end; }

.chat-bubble {
    max-width: 82%;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: .855rem;
    line-height: 1.48;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-msg-bot  .chat-bubble {
    background: var(--cro-blue-light, #e3ebf7);
    color: var(--cro-dark, #1a1a2e);
    border-bottom-left-radius: 4px;
}

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

/* ===== Typing indicator ===== */
.chat-typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 2px;
}

.chat-typing-dots span {
    width: 7px;
    height: 7px;
    background: var(--cro-gray, #6c757d);
    border-radius: 50%;
    animation: typingDot 1.1s infinite ease-in-out;
}

.chat-typing-dots span:nth-child(2) { animation-delay: .18s; }
.chat-typing-dots span:nth-child(3) { animation-delay: .36s; }

@keyframes typingDot {
    0%,60%,100% { opacity: .25; transform: scale(.8); }
    30%          { opacity: 1;   transform: scale(1.1); }
}

/* ===== Input area ===== */
.chat-input-area {
    display: flex;
    padding: 10px 12px;
    border-top: 1px solid var(--cro-border, #dee2e6);
    gap: 8px;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--cro-border, #dee2e6);
    border-radius: 20px;
    padding: 7px 14px;
    font-size: .855rem;
    outline: none;
    transition: border-color .15s;
    font-family: inherit;
}

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

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cro-blue);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .82rem;
    transition: background .15s;
    flex-shrink: 0;
}

.chat-send-btn:hover    { background: var(--cro-blue-hover, #041f4a); }
.chat-send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Links inside bot messages */
.chat-msg-bot .chat-bubble a {
    color: var(--cro-blue);
    font-weight: 500;
    text-decoration: underline;
    word-break: break-all;
}

.chat-msg-bot .chat-bubble a:hover { color: var(--cro-blue-hover, #041f4a); }

/* ===== Responsive ===== */
@media (max-width: 420px) {
    #chatWidget { bottom: 16px; right: 16px; }
    .chat-panel { width: calc(100vw - 32px); max-height: 420px; }
}

/* ===== Koko Greeting Popup ===== */
.koko-greeting {
    position: relative;
    background: #fff;
    border: 1.5px solid var(--cro-blue, #062f6e);
    border-radius: 14px;
    padding: 9px 28px 9px 13px;
    font-size: .78rem;
    font-weight: 600;
    color: var(--cro-dark, #1a1a2e);
    white-space: nowrap;
    box-shadow: 0 4px 18px rgba(6,47,110,.18);
    margin-bottom: 8px;
    animation: kokoPopIn .32s cubic-bezier(.34,1.56,.64,1);
    z-index: 10000;
}

/* outer border triangle tail */
.koko-greeting::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 19px;
    border: 9px solid transparent;
    border-top-color: var(--cro-blue, #062f6e);
    border-bottom: none;
    z-index: 1;
}

/* inner white fill triangle tail */
.koko-greeting::before {
    content: '';
    position: absolute;
    bottom: -7.5px;
    right: 20.5px;
    border: 7.5px solid transparent;
    border-top-color: #fff;
    border-bottom: none;
    z-index: 2;
}

.koko-greeting-close {
    position: absolute;
    top: 4px;
    right: 5px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: .58rem;
    color: var(--cro-gray, #6c757d);
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    transition: color .15s;
    z-index: 3;
}

.koko-greeting-close:hover { color: var(--cro-dark, #1a1a2e); }

@keyframes kokoPopIn {
    from { opacity: 0; transform: scale(.75) translateY(8px); }
    to   { opacity: 1; transform: scale(1)   translateY(0); }
}
