/* =========================================================
   น้องหนุมาน — chat widget
   Floating bubble + slide-up panel · CI-styled
   ========================================================= */

.nk-chat {
    position: fixed;
    right: 20px; bottom: 20px;
    z-index: 9998;
    font-family: 'Anuphan', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ---------- Trigger bubble ---------- */
.nk-chat__trigger {
    position: relative;
    width: 60px; height: 60px;
    border: 0;
    border-radius: 50%;
    background: var(--nk-gradient-navy);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 16px 36px rgba(11, 31, 74, .35), 0 0 0 1px rgba(244, 196, 48, .3);
    display: flex; align-items: center; justify-content: center;
    transition: transform .25s var(--nk-easing), box-shadow .25s var(--nk-easing);
}
.nk-chat__trigger:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 24px 48px rgba(11, 31, 74, .50), 0 0 0 2px rgba(244, 196, 48, .55);
}
.nk-chat__trigger::before {
    /* gold ring pulse */
    content: '';
    position: absolute; inset: -6px;
    border-radius: 50%;
    border: 2px solid rgba(244, 196, 48, .5);
    animation: nk-pulse 2.4s ease-out infinite;
    pointer-events: none;
}
@keyframes nk-pulse {
    0%   { transform: scale(.85); opacity: .9; }
    80%  { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

.nk-chat__avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--nk-gradient);
    color: var(--nk-primary);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
    font-weight: 800;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.4);
}

.nk-chat__badge {
    position: absolute;
    top: -5px; right: -5px;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 999px;
    background: var(--nk-secondary);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
}

/* ---------- Panel ---------- */
.nk-chat__panel {
    position: absolute;
    right: 0; bottom: 78px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border: 1px solid var(--nk-border);
    border-radius: 18px;
    box-shadow: 0 30px 80px rgba(11, 31, 74, .25);
    display: flex; flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: translateY(12px) scale(.96);
    opacity: 0;
    pointer-events: none;
    transition: transform .25s var(--nk-easing), opacity .25s var(--nk-easing);
}
.nk-chat.is-open .nk-chat__panel {
    transform: none;
    opacity: 1;
    pointer-events: auto;
}
.nk-chat.is-open .nk-chat__trigger::before { display: none; }

/* ---------- Header ---------- */
.nk-chat__header {
    position: relative;
    padding: 1rem 1.1rem;
    background: var(--nk-gradient-hero);
    color: #fff;
    display: flex; align-items: center; gap: .75rem;
    border-bottom: 1px solid rgba(244, 196, 48, .25);
}
.nk-chat__header::after {
    /* gold accent line */
    content: '';
    position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
    background: var(--nk-gradient);
}
.nk-chat__title { font-weight: 700; font-size: 1rem; line-height: 1.1; margin: 0; }
.nk-chat__subtitle {
    font-size: .75rem;
    color: rgba(255,255,255,.75);
    display: flex; align-items: center; gap: .35rem;
    margin-top: 2px;
}
.nk-chat__subtitle::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, .25);
}
.nk-chat__close {
    margin-left: auto;
    width: 32px; height: 32px;
    border: 0;
    border-radius: 50%;
    background: rgba(255,255,255,.10);
    color: #fff;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .2s var(--nk-easing), transform .2s var(--nk-easing);
}
.nk-chat__close:hover { background: rgba(255,255,255,.18); transform: rotate(90deg); }

/* ---------- Body / messages ---------- */
.nk-chat__body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: linear-gradient(180deg, #fafbfd 0%, #f3f5fa 100%);
    scroll-behavior: smooth;
}
.nk-chat__body::-webkit-scrollbar { width: 6px; }
.nk-chat__body::-webkit-scrollbar-thumb {
    background: rgba(11, 31, 74, .15);
    border-radius: 6px;
}

.nk-msg {
    display: flex; gap: .55rem;
    margin-bottom: .85rem;
    animation: nk-msg-in .35s var(--nk-easing) both;
}
@keyframes nk-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}
.nk-msg__avatar {
    flex-shrink: 0;
    width: 32px; height: 32px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .85rem; font-weight: 800;
    background: var(--nk-gradient);
    color: var(--nk-primary);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
.nk-msg__bubble {
    max-width: 78%;
    padding: .65rem .9rem;
    border-radius: 14px;
    font-size: .9rem; line-height: 1.55;
    color: var(--nk-text);
    background: #fff;
    border: 1px solid var(--nk-border);
    box-shadow: 0 2px 6px rgba(11, 31, 74, .04);
    white-space: pre-wrap;
    word-wrap: break-word;
}
.nk-msg__bubble strong { color: var(--nk-primary); font-weight: 700; }
.nk-msg__time {
    font-size: .7rem;
    color: var(--nk-text-muted);
    margin-top: .25rem;
}

/* User message — right aligned, navy gradient */
.nk-msg.nk-msg--user { flex-direction: row-reverse; }
.nk-msg.nk-msg--user .nk-msg__avatar {
    background: var(--nk-gradient-navy);
    color: #fff;
}
.nk-msg.nk-msg--user .nk-msg__bubble {
    background: var(--nk-gradient-navy);
    border-color: transparent;
    color: #fff;
    border-top-right-radius: 4px;
}
.nk-msg.nk-msg--user .nk-msg__bubble strong { color: var(--nk-gold-2); }

.nk-msg.nk-msg--bot .nk-msg__bubble {
    border-top-left-radius: 4px;
}

/* Typing indicator */
.nk-typing {
    display: inline-flex; align-items: center; gap: 4px;
    padding: .4rem .6rem;
}
.nk-typing span {
    width: 6px; height: 6px;
    background: var(--nk-text-muted);
    border-radius: 50%;
    animation: nk-bounce 1.2s infinite;
}
.nk-typing span:nth-child(2) { animation-delay: .15s; }
.nk-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes nk-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: .5; }
    40%           { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Suggestions ---------- */
.nk-chat__suggestions {
    display: flex; flex-wrap: wrap; gap: .35rem;
    padding: .5rem 1rem .75rem;
    background: linear-gradient(180deg, transparent, #f3f5fa);
    border-top: 1px solid var(--nk-border);
}
.nk-chat__suggestions:empty { display: none; }
.nk-chip {
    padding: .35rem .75rem;
    border-radius: 999px;
    border: 1px solid rgba(11, 31, 74, .15);
    background: #fff;
    color: var(--nk-primary);
    font-size: .8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s var(--nk-easing), border-color .15s var(--nk-easing), transform .15s var(--nk-easing);
}
.nk-chip:hover {
    background: var(--nk-gradient-soft);
    border-color: rgba(184, 134, 11, .35);
    transform: translateY(-1px);
}

/* ---------- Footer / input ---------- */
.nk-chat__footer {
    padding: .65rem .75rem;
    background: #fff;
    border-top: 1px solid var(--nk-border);
    display: flex; gap: .5rem; align-items: flex-end;
}
.nk-chat__input {
    flex: 1;
    border: 1px solid var(--nk-border);
    border-radius: 14px;
    padding: .55rem .8rem;
    font-size: .9rem;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    max-height: 100px;
    min-height: 42px;
    outline: none;
    transition: border-color .15s var(--nk-easing), box-shadow .15s var(--nk-easing);
    background: #f6f7fb;
}
.nk-chat__input:focus {
    border-color: var(--nk-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(11, 31, 74, .10);
}
.nk-chat__send {
    flex-shrink: 0;
    width: 42px; height: 42px;
    border: 0;
    border-radius: 50%;
    background: var(--nk-gradient-navy);
    color: #fff;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: transform .15s var(--nk-easing), box-shadow .15s var(--nk-easing), opacity .15s var(--nk-easing);
    box-shadow: 0 6px 14px rgba(11, 31, 74, .25);
}
.nk-chat__send:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(11, 31, 74, .35); }
.nk-chat__send:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.nk-chat__hint {
    text-align: center;
    font-size: .7rem;
    color: var(--nk-text-muted);
    padding: .35rem 1rem .5rem;
    background: #fff;
    border-top: 1px solid var(--nk-border);
}
.nk-chat__hint .nk-gold-text {
    background: var(--nk-gradient);
    -webkit-background-clip: text;
            background-clip: text;
    color: transparent;
    font-weight: 700;
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
    .nk-chat { right: 12px; bottom: 12px; }
    .nk-chat__panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        right: 0; bottom: 74px;
    }
    .nk-chat__trigger { width: 56px; height: 56px; }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .nk-chat__trigger::before, .nk-msg, .nk-typing span { animation: none !important; }
    .nk-chat__panel { transition: none !important; }
}
