/* ============================================================
   QllmDocs Chatbot  —  /wwwroot/css/chatbot.css
   Brand colours:  navy #0F2D5E  |  blue #1565C0  |  gold #F0C842
   ============================================================ */

/* ── Variables ────────────────────────────────────────────── */
:root {
    --qd-navy:    #0F2D5E;
    --qd-blue:    #1565C0;
    --qd-blue2:   #174d96;
    --qd-gold:    #F0C842;
    --qd-bg:      #F4F6FA;
    --qd-white:   #FFFFFF;
    --qd-border:  rgba(15,45,94,0.12);
    --qd-shadow:  0 8px 40px rgba(15,45,94,0.18);
    --qd-radius:  14px;
    --qd-ease:    200ms ease;
    --qd-font:    'DM Sans', 'Helvetica Neue', Arial, sans-serif;
}

/* ── Trigger button ────────────────────────────────────────── */
.qd-chat-trigger {
    position: fixed;
    bottom: 24px;   /* sits just below the WhatsApp button at ~58px */
    right:  26px;
    width:  52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--qd-blue) 0%, var(--qd-navy) 100%);
    color: var(--qd-white);
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(21,101,192,0.40);
    transition: transform var(--qd-ease), box-shadow var(--qd-ease);
    z-index: 1039;   /* just below WhatsApp (1040) */
}
.qd-chat-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(21,101,192,0.55);
}
.qd-chat-trigger:active { transform: scale(0.96); }

/* Unread badge */
.qd-chat-trigger-badge {
    position: absolute;
    top: 4px; right: 4px;
    width: 17px; height: 17px;
    background: #e53e3e;
    border-radius: 50%;
    border: 2px solid var(--qd-white);
    font-size: 9px;
    font-weight: 700;
    color: var(--qd-white);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ── Chat Panel ─────────────────────────────────────────────── */
.qd-chat-panel {
    position: fixed;
    bottom: 80px;
    right:  24px;
    width:  590px;
    height: 500px;
    background: var(--qd-white);
    border-radius: var(--qd-radius);
    box-shadow: var(--qd-shadow);
    display: flex;
    flex-direction: column;
    z-index: 10500;
    font-family: var(--qd-font);
    animation: qdSlideUp 0.28s cubic-bezier(.22,.68,0,1.2) both;
    border: 1px solid var(--qd-border);
    overflow: hidden;
}

@keyframes qdSlideUp {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ── Header ─────────────────────────────────────────────────── */
.qd-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(90deg, var(--qd-navy) 0%, var(--qd-blue) 100%);
    flex-shrink: 0;
}
.qd-chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.qd-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.qd-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 5px;
    filter: brightness(0) invert(1);
}
.qd-chat-header-name {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--qd-white);
    line-height: 1.2;
}
.qd-chat-header-status {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.78);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 1px;
}
.qd-status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #4ADE80;
    display: inline-block;
    animation: qdDotBlink 1.8s ease-in-out infinite;
}
@keyframes qdDotBlink {
    0%,100% { box-shadow: 0 0 0 2px rgba(74,222,128,0.3); }
    50%     { box-shadow: 0 0 0 4px rgba(74,222,128,0.1); }
}
.qd-chat-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.80);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    transition: all var(--qd-ease);
    line-height: 1;
}
.qd-chat-close:hover {
    color: var(--qd-white);
    background: rgba(255,255,255,0.15);
}

/* ── Messages container ──────────────────────────────────────── */
.qd-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8fafd;
    scroll-behavior: smooth;
}
.qd-chat-messages::-webkit-scrollbar { width: 5px; }
.qd-chat-messages::-webkit-scrollbar-track { background: transparent; }
.qd-chat-messages::-webkit-scrollbar-thumb { background: #c7d5e8; border-radius: 3px; }

/* ── Welcome state ───────────────────────────────────────────── */
.qd-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 10px 8px 6px;
    gap: 6px;
}
.qd-welcome-icon {
    width: 60px; height: 60px;
    border-radius: 50%;
    background: #EDF3FB;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    margin-bottom: 4px;
}
.qd-welcome-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.qd-welcome h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--qd-navy);
}
.qd-welcome p {
    margin: 0;
    font-size: 0.8rem;
    color: #5a7089;
}

/* ── Individual messages ──────────────────────────────────────── */
.qd-msg {
    display: flex;
    flex-direction: column;
    gap: 3px;
    animation: qdMsgIn 0.22s ease both;
}
@keyframes qdMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0);   }
}
.qd-msg-user { align-items: flex-end; }
.qd-msg-bot  { align-items: flex-start; }

.qd-msg-bubble {
    max-width: 82%;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 0.82rem;
    line-height: 1.5;
    word-break: break-word;
}
.qd-msg-user .qd-msg-bubble {
    background: linear-gradient(135deg, var(--qd-blue) 0%, var(--qd-navy) 100%);
    color: var(--qd-white);
    border-bottom-right-radius: 3px;
}
.qd-msg-bot .qd-msg-bubble {
    background: var(--qd-white);
    color: #1a2a3a;
    border: 1px solid var(--qd-border);
    border-bottom-left-radius: 3px;
    box-shadow: 0 1px 4px rgba(15,45,94,0.06);
}

/* Markdown inside bot bubble */
.qd-msg-bubble h1,.qd-msg-bubble h2 { font-size: 0.92rem; font-weight: 700; color: var(--qd-navy); margin: 6px 0 3px; }
.qd-msg-bubble h3,.qd-msg-bubble h4 { font-size: 0.85rem; font-weight: 700; color: var(--qd-blue); margin: 5px 0 2px; }
.qd-msg-bubble p  { margin: 3px 0 5px; }
.qd-msg-bubble ul { list-style: disc; padding-left: 18px; margin: 4px 0 6px; }
.qd-msg-bubble ol { list-style: decimal; padding-left: 18px; margin: 4px 0 6px; }
.qd-msg-bubble li { margin-bottom: 2px; line-height: 1.4; }
.qd-msg-bubble strong,.qd-msg-bubble b { font-weight: 700; color: var(--qd-navy); }
.qd-msg-bubble a  { color: var(--qd-blue); font-weight: 600; text-decoration: none; border-bottom: 1px solid var(--qd-blue); transition: color var(--qd-ease); }
.qd-msg-bubble a:hover { color: var(--qd-navy); border-bottom-color: var(--qd-navy); }
.qd-msg-bubble table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 0.78rem; }
.qd-msg-bubble th,.qd-msg-bubble td { border: 1px solid #dce6f4; padding: 4px 7px; text-align: left; }
.qd-msg-bubble th { background: #EDF3FB; font-weight: 700; color: var(--qd-navy); }
.qd-msg-bubble tr:nth-child(even) { background: #f7faff; }
.qd-msg-bubble code { background: #f0f4fb; padding: 1px 4px; border-radius: 3px; font-size: 0.78rem; color: #c0392b; }
.qd-msg-bubble pre  { background: #f0f4fb; border: 1px solid #dce6f4; border-radius: 6px; padding: 8px; overflow-x: auto; margin: 5px 0; font-size: 0.75rem; }
.qd-msg-bubble blockquote { border-left: 3px solid var(--qd-blue); padding-left: 10px; margin: 4px 0; color: #5a7089; font-style: italic; }
.qd-msg-bubble hr { border: none; border-top: 1px solid #dce6f4; margin: 6px 0; }

.qd-msg-time {
    font-size: 0.68rem;
    color: #99aabb;
    padding: 0 3px;
}

/* ── Typing indicator ─────────────────────────────────────────── */
.qd-typing .qd-msg-bubble {
    padding: 10px 14px;
    display: flex;
    align-items: center;
}
.qd-typing-dots {
    display: flex;
    gap: 5px;
    align-items: flex-end;
    height: 18px;
}
.qd-typing-dots span {
    width: 7px; height: 7px;
    background: var(--qd-blue);
    border-radius: 50%;
    opacity: 0.8;
    animation: qdBounce 1.4s infinite ease-in-out;
}
.qd-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.qd-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes qdBounce {
    0%,80%,100% { transform: translateY(0);   opacity: 0.8; }
    40%         { transform: translateY(-7px); opacity: 1;   }
}

/* ── Error bar ───────────────────────────────────────────────── */
.qd-error-bar {
    margin: 0 12px 6px;
    padding: 7px 12px;
    background: #fff5f5;
    border: 1px solid #fed7d7;
    border-left: 3px solid #e53e3e;
    border-radius: 6px;
    font-size: 0.78rem;
    color: #c53030;
}

/* ── Quick-question pills ────────────────────────────────────── */
.qd-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 5px 12px 7px;
    background: #eef2f8;
    flex-shrink: 0;
}
.qd-pill {
    padding: 5px 10px;
    background: #dce8fb;
    border: 1.5px solid var(--qd-blue);
    border-radius: 20px;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--qd-navy);
    cursor: pointer;
    transition: all var(--qd-ease);
    font-family: var(--qd-font);
    white-space: nowrap;
}
.qd-pill:hover {
    background: var(--qd-blue);
    color: var(--qd-white);
    transform: translateY(-1px);
}
.qd-pill:active { transform: translateY(0); }

/* ── Input area ──────────────────────────────────────────────── */
.qd-chat-input-area {
    padding: 8px 12px 10px;
    border-top: 1px solid var(--qd-border);
    background: var(--qd-white);
    flex-shrink: 0;
}
.qd-input-row {
    display: flex;
    gap: 7px;
    align-items: center;
}
.qd-input {
    flex: 1;
    height: 38px;
    border: 1.5px solid #c7d5e8;
    border-radius: 8px;
    padding: 0 12px;
    font-size: 0.84rem;
    font-family: var(--qd-font);
    outline: none;
    transition: border-color var(--qd-ease), box-shadow var(--qd-ease);
    background: var(--qd-white);
    color: #1a2a3a;
}
.qd-input:focus {
    border-color: var(--qd-blue);
    box-shadow: 0 0 0 3px rgba(21,101,192,0.12);
}
.qd-input:disabled {
    background: #f4f6fa;
    cursor: not-allowed;
}
.qd-send-btn {
    width: 38px; height: 38px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--qd-blue) 0%, var(--qd-navy) 100%);
    color: var(--qd-white);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--qd-ease);
    flex-shrink: 0;
}
.qd-send-btn:hover:not(:disabled) {
    transform: scale(1.07);
    box-shadow: 0 3px 10px rgba(21,101,192,0.35);
}
.qd-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.qd-send-btn .qd-spin { animation: qdSpin 0.8s linear infinite; display: inline-block; }
@keyframes qdSpin { to { transform: rotate(360deg); } }

.qd-input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 5px;
}
.qd-char-count {
    font-size: 0.68rem;
    color: #99aabb;
}
.qd-clear-btn {
    font-size: 0.70rem;
    font-weight: 600;
    color: #99aabb;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 2px 5px;
    border-radius: 4px;
    font-family: var(--qd-font);
    transition: all var(--qd-ease);
}
.qd-clear-btn:hover { color: #e53e3e; background: #fff5f5; }
    .qd-bot-icon {
        width: 28px;
        height: 28px;
        color: var(--qd-white);
    }
.qd-chat-trigger:hover .qd-bot-icon {
    animation: qdBotBob 0.6s ease-in-out infinite;
}

@keyframes qdBotBob {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }

    50% {
        transform: translateY(-2px) rotate(-3deg);
    }
}

/* Blinking eyes (always animating, subtle) */
.qd-bot-eye {
    animation: qdBotBlink 3.2s ease-in-out infinite;
    transform-origin: center;
}

    .qd-bot-eye:nth-of-type(2) {
        animation-delay: 0.05s;
    }

@keyframes qdBotBlink {
    0%, 92%, 100% {
        transform: scaleY(1);
    }

    95% {
        transform: scaleY(0.15);
    }
}

/* Antenna ping */
.qd-bot-antenna-dot {
    animation: qdAntennaPing 2s ease-in-out infinite;
    transform-origin: center;
}

@keyframes qdAntennaPing {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(1.5);
    }
}

/* Side arm wiggle on hover */
.qd-chat-trigger:hover line:first-of-type,
.qd-chat-trigger:hover line:last-of-type {
    animation: none;
}

.qd-bot-greeting {
    position: fixed;
    bottom: 20px;
    right: 90px;
    max-width: 220px;
    background: var(--qd-white);
    color: #1a2a3a;
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.4;
    padding: 12px 28px 12px 14px;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 6px 24px rgba(15,45,94,0.18);
    z-index: 1039;
    font-family: var(--qd-font);
    animation: qdGreetIn 0.4s ease both;
}

.qd-bot-greeting-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    font-size: 14px;
    color: #99aabb;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

    .qd-bot-greeting-close:hover {
        color: #e53e3e;
    }

@keyframes qdGreetIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}


/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 480px) {
    .qd-chat-panel {
        width:  100vw;
        height: 100dvh;
        bottom: 0; right: 0;
        border-radius: 0;
    }
    .qd-chat-trigger { bottom: 24px; right: 17px; }
    .qd-bot-greeting { right: 75px; bottom: 25px; }
}
@media (min-width: 481px) and (max-width: 768px) {
    .qd-chat-panel { width: calc(100vw - 40px); }
    .qd-chat-trigger { bottom: 24px; right: 26px; }
}
