/* ============================================================
   Inghe Chatbot – Frontend widget
   FJP Warm Vietnamese Palette
   ============================================================ */

/* Scoped design tokens — self-contained, no external CSS deps */
#inghe-widget {
    --ic-navy:        #0D1B3E;
    --ic-navy-mid:    #1a3e60;
    --ic-maroon:      #8C2020;
    --ic-crimson:     #C0281C;
    --ic-orange:      #E03A10;
    --ic-teal:        #1E6B68;
    --ic-gold:        #BF8B3F;
    --ic-gold-light:  #F2E4C2;
    --ic-cream:       #FEF5EC;
    --ic-peach:       #F5E2D2;
    --ic-peach-dark:  #E8C9B2;
    --ic-text:        #2D1A14;
    --ic-text-mid:    #5C3D34;
    --ic-text-muted:  #8B6E65;
    --ic-white:       #FFFFFF;
    --ic-shadow:      0 8px 32px rgba(13,27,61,.14);
    --ic-shadow-lg:   0 16px 48px rgba(13,27,61,.22);
    --ic-radius-box:  20px;

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

/* ── Compact position (non-inghe pages) ── */
#inghe-widget.inghe-widget--compact {
    bottom: 60px;
    right: 16px;
}

/* ── Toggle button ── */
#inghe-chat-toggle {
    width: 60px;
    height: 60px;
    background-color: #fb7516;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 18px rgba(13,27,62,.42);
    transition: transform .25s cubic-bezier(.22,1,.36,1), box-shadow .25s;
    margin-left: auto;
    position: relative;
    overflow: visible;
}

/* Pulse rings — invite the user to click */
#inghe-chat-toggle::before,
#inghe-chat-toggle::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    border: 2px solid rgba(13,27,62,.28);
    animation: ic-toggle-ring 2.6s ease-out infinite;
}
#inghe-chat-toggle::before { inset: -7px; }
#inghe-chat-toggle::after  { inset: -16px; border-width: 1.5px; border-color: rgba(13,27,62,.13); animation-delay: .9s; }

@keyframes ic-toggle-ring {
    0%   { transform: scale(1);    opacity: .75; }
    70%  { opacity: .10; }
    100% { transform: scale(1.38); opacity: 0;   }
}

#inghe-chat-toggle:hover {
    transform: scale(1.10);
    box-shadow: 0 8px 24px rgba(13,27,62,.52);
}
#inghe-chat-toggle img {
    width: 100%;
    height: 100%;
    max-width: none;
    filter: brightness(0) invert(1);
}


/* ── Chat box ── */
#inghe-chat-box {
    width: 380px;
    max-width: calc(100vw - 48px);
    background: var(--ic-white);
    border-radius: var(--ic-radius-box);
    box-shadow: var(--ic-shadow-lg);
    display: flex;
    flex-direction: column;
    margin-bottom: 14px;
    overflow: hidden;
    border: 1px solid rgba(13,27,61,.08);
    animation: ic-slide-up .30s cubic-bezier(.22,1,.36,1);
}
#inghe-chat-box[hidden] { display: none !important; }

@keyframes ic-slide-up {
    from { opacity: 0; transform: translateY(22px) scale(.96); }
    to   { opacity: 1; transform: translateY(0)    scale(1);   }
}

/* ── Header ── */
#inghe-chat-header {
    background: linear-gradient(135deg, var(--ic-navy) 0%, var(--ic-navy-mid) 100%);
    color: var(--ic-white);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: .01em;
    position: relative;
    overflow: hidden;
}

.inghe-header-actions { display: flex; align-items: center; gap: 4px; }
#inghe-chat-close,
#inghe-chat-clear {
    background: none;
    border: none;
    color: var(--ic-white);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 7px;
    opacity: .70;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: opacity .15s, background .15s;
}
#inghe-chat-close:hover,
#inghe-chat-clear:hover { opacity: 1; background: rgba(255,255,255,.14); }

/* ── Messages area ── */
#inghe-chat-messages {
    flex: 1;
    max-height: 360px;
    overflow-y: auto;
    padding: 16px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: #fef8f3;
    /* subtle seigaiha wave tile */
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='20'%3E%3Cpath d='M0,20A20,20,0,0,1,40,20' fill='none' stroke='rgba(191,139,63,.09)' stroke-width='1'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='20'%3E%3Cpath d='M0,20A20,20,0,0,1,40,20' fill='none' stroke='rgba(191,139,63,.09)' stroke-width='1'/%3E%3C/svg%3E");
    background-size: 40px 20px, 40px 20px;
    background-position: 0 0, 20px 20px;
    scroll-behavior: smooth;
}

.inghe-msg {
    display: flex;
    flex-direction: column;
    max-width: 84%;
    animation: ic-msg-in .22s cubic-bezier(.22,1,.36,1);
}
@keyframes ic-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.inghe-msg.user { align-self: flex-end;   align-items: flex-end; }
.inghe-msg.bot  { align-self: flex-start; align-items: flex-start; }

.inghe-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.58;
    word-break: break-word;
    font-size: 13.5px;
}
.inghe-msg.user .inghe-bubble {
    background: var(--ic-navy);
    color: var(--ic-white);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
    box-shadow: 0 2px 8px rgba(13,27,62,.25);
}
.inghe-msg.bot .inghe-bubble {
    background: var(--ic-white);
    color: var(--ic-text);
    border-bottom-left-radius: 4px;
    white-space: normal;
    box-shadow: 0 2px 8px rgba(13,27,61,.09);
    border: 1px solid rgba(232,201,178,.65);
}

.inghe-typing { display: flex; gap: 5px; padding: 11px 14px; }
.inghe-typing span {
    width: 7px; height: 7px;
    background: var(--ic-navy-mid);
    border-radius: 50%;
    opacity: .55;
    animation: ic-typing-bounce .9s ease-in-out infinite;
}
.inghe-typing span:nth-child(2) { animation-delay: .18s; }
.inghe-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes ic-typing-bounce {
    0%, 100% { transform: translateY(0);    opacity: .40; }
    45%       { transform: translateY(-6px); opacity: 1;   }
}


/* ── Footer / input ── */
#inghe-chat-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--ic-peach-dark);
    background: var(--ic-white);
}
#inghe-chat-input {
    width: 100%;
    resize: none;
    border: 1.5px solid var(--ic-peach-dark);
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 13.5px;
    line-height: 1.45;
    outline: none;
    box-sizing: border-box;
    transition: border-color .2s, box-shadow .2s;
    font-family: inherit;
    background: #fef8f3;
    color: var(--ic-text);
    scrollbar-width: auto;
    min-height: auto;
    height: unset;
}
#inghe-chat-input:focus {
    border-color: var(--ic-navy);
    background: var(--ic-white);
    box-shadow: 0 0 0 3px rgba(13,27,62,.08);
}
#inghe-chat-input::placeholder { color: var(--ic-text-muted); }

#inghe-chat-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
}
#inghe-char-count { font-size: 11px; color: var(--ic-text-muted); }
#inghe-char-count.warn { color: var(--ic-crimson); }

#inghe-chat-send {
    background: var(--ic-navy);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ic-white);
    transition: background .2s, transform .18s cubic-bezier(.22,1,.36,1), box-shadow .2s;
    box-shadow: 0 2px 8px rgba(13,27,62,.30);
}
#inghe-chat-send:hover:not(:disabled) {
    background: var(--ic-navy-mid);
    transform: scale(1.12);
    box-shadow: 0 4px 14px rgba(13,27,62,.42);
}
#inghe-chat-send:disabled { background: var(--ic-peach-dark); cursor: not-allowed; box-shadow: none; }

/* Cooldown countdown */
#inghe-cooldown { font-size: 11px; color: var(--ic-crimson); text-align: right; margin-top: 3px; min-height: 16px; }

/* ── Markdown formatting inside bot bubbles ── */
.inghe-msg.bot .inghe-bubble p        { margin: 0 0 6px; }
.inghe-msg.bot .inghe-bubble p:last-child { margin-bottom: 0; }
.inghe-msg.bot .inghe-bubble ul,
.inghe-msg.bot .inghe-bubble ol       { margin: 4px 0 6px 16px; padding: 0; }
.inghe-msg.bot .inghe-bubble li       { margin-bottom: 2px; }
.inghe-msg.bot .inghe-bubble strong   { font-weight: 700; color: var(--ic-navy); }
.inghe-msg.bot .inghe-bubble em       { font-style: italic; }
.inghe-msg.bot .inghe-bubble code     { background: rgba(13,27,62,.07); padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: monospace; color: var(--ic-maroon); }
.inghe-msg.bot .inghe-bubble pre      { background: rgba(13,27,62,.07); padding: 8px 10px; border-radius: 8px; overflow-x: auto; margin: 6px 0; }
.inghe-msg.bot .inghe-bubble pre code { background: none; padding: 0; color: inherit; }
.inghe-msg.bot .inghe-bubble hr       { border: none; border-top: 1px solid var(--ic-peach-dark); margin: 8px 0; }
.inghe-msg.bot .inghe-bubble a        { color: var(--ic-teal); text-decoration: underline; word-break: break-all; }
.inghe-msg.bot .inghe-bubble a:hover  { color: var(--ic-navy); }
.inghe-msg.bot .inghe-bubble img      { max-width: 100%; height: auto; border-radius: 8px; margin: 4px 0; display: block; }

/* Table */
.inghe-msg.bot .inghe-bubble table    { border-collapse: collapse; width: 100%; margin: 6px 0; font-size: 12px; }
.inghe-msg.bot .inghe-bubble th,
.inghe-msg.bot .inghe-bubble td       { border: 1px solid var(--ic-peach-dark); padding: 5px 10px; text-align: left; }
.inghe-msg.bot .inghe-bubble th       { background: var(--ic-peach); font-weight: 700; color: var(--ic-navy); }
.inghe-msg.bot .inghe-bubble tr:nth-child(even) td { background: #fef8f3; }

/* ── File upload button ── */
#inghe-file-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--ic-text-muted);
    padding: 4px;
    border-radius: 4px;
    transition: color .2s, background .2s;
}
#inghe-file-btn:hover { color: var(--ic-navy); background: rgba(13,27,62,.07); }
#inghe-file-btn.uploading { opacity: .5; pointer-events: none; }

/* File preview area */
#inghe-file-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 0 8px;
}
#inghe-file-preview[hidden] { display: none !important; }

.inghe-file-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--ic-gold-light);
    border: 1px solid var(--ic-peach-dark);
    border-radius: 12px;
    padding: 3px 8px 3px 10px;
    font-size: 12px;
    color: var(--ic-maroon);
    max-width: 160px;
}
.inghe-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.inghe-file-remove {
    background: none;
    border: none;
    color: var(--ic-crimson);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    opacity: .7;
}
.inghe-file-remove:hover { opacity: 1; }

/* Anonymity prompt bubble (legacy, kept for graceful degradation) */
.inghe-anon-bubble .inghe-anon-desc { font-size: 0.88em; color: var(--ic-text-mid); margin: 4px 0 10px; }
.inghe-anon-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.inghe-anon-btn {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 16px;
    border: 1px solid currentColor;
    font-size: 13px;
    cursor: pointer;
    background: var(--ic-white);
    transition: background .15s, color .15s;
}
.inghe-anon-yes { color: var(--ic-text-mid);  border-color: var(--ic-peach-dark); }
.inghe-anon-yes:hover:not(:disabled) { background: var(--ic-peach); }
.inghe-anon-no  { color: var(--ic-navy);       border-color: var(--ic-navy); }
.inghe-anon-no:hover:not(:disabled)  { background: var(--ic-navy); color: var(--ic-white); }
.inghe-anon-btn:disabled { opacity: 0.5; cursor: default; }

/* ─── State-machine choice buttons (rendered from [BUTTONS]...[/BUTTONS]) ─── */
.inghe-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.inghe-btn-choice {
    background: var(--ic-white);
    color: var(--ic-navy);
    border: 1.5px solid var(--ic-navy);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background .18s, color .18s, transform .15s;
    line-height: 1.4;
}
.inghe-btn-choice:hover:not(:disabled) {
    background: var(--ic-navy);
    color: var(--ic-white);
    transform: translateY(-1px);
}
.inghe-btn-choice:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}