/* ==========================================================================
   nbit.center — AI Chat widget (CSP-safe; external styles only)
   ========================================================================== */

.nb-chat {
    --c-bg: #0c0e1a;
    --c-surface: #141833;
    --c-border: rgba(255, 255, 255, 0.12);
    --c-text: #e9ebf5;
    --c-muted: #9aa1bd;
    --c-cyan: #22d3ee;
    --c-violet: #2f5bff;
    position: fixed;
    right: clamp(1rem, 3vw, 2rem);
    bottom: clamp(1rem, 3vw, 2rem);
    z-index: 1100;
    font-family: var(--font-family, "Roboto", system-ui, sans-serif);
}

/* Launcher button */
.nb-chat__launcher {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.8rem 1.2rem;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    background: #004efe;
    box-shadow: 0 10px 28px -10px rgba(0, 78, 254, 0.55);
    transition: transform 0.2s ease, box-shadow 0.3s ease, background 0.2s ease;
}

.nb-chat__launcher:hover {
    transform: translateY(-2px);
    background: #003ad1;
    box-shadow: 0 16px 38px -10px rgba(0, 78, 254, 0.6);
}

.nb-chat__launcher i {
    font-size: 1.2rem;
}

/* Panel */
.nb-chat__panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.75rem);
    width: min(92vw, 380px);
    height: min(70vh, 540px);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border-radius: 18px;
    border: 1px solid var(--c-border);
    background: var(--c-bg);
    box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.7);
}

.nb-chat.is-open .nb-chat__panel {
    display: flex;
    animation: nb-chat-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.nb-chat.is-open .nb-chat__launcher {
    display: none;
}

@keyframes nb-chat-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.nb-chat__header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.9rem 1rem;
    background: linear-gradient(120deg, rgba(34, 211, 238, 0.16), rgba(47, 91, 255, 0.16));
    border-bottom: 1px solid var(--c-border);
}

.nb-chat__avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
    flex-shrink: 0;
}

.nb-chat__avatar img {
    width: 36px;
    height: 36px;
    display: block;
}

.nb-chat__launcher-img {
    display: block;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
    animation: bitty-bob 2.6s ease-in-out infinite;
}

@keyframes bitty-bob {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-2px) rotate(-4deg); }
}

@media (prefers-reduced-motion: reduce) {
    .nb-chat__launcher-img { animation: none; }
}

.nb-chat__title {
    font-weight: 700;
    color: var(--c-text);
    font-size: 0.95rem;
    line-height: 1.1;
}

.nb-chat__subtitle {
    font-size: 0.75rem;
    color: var(--c-muted);
}

.nb-chat__close {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--c-muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 8px;
}

.nb-chat__close:hover {
    color: var(--c-text);
    background: rgba(255, 255, 255, 0.06);
}

/* Welcome / hero greeting */
.nb-chat__welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    padding: 0.5rem 0.5rem 0.25rem;
}

.nb-chat__hero {
    width: 104px;
    height: 104px;
    display: block;
    animation: bitty-walk-in 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.nb-chat__welcome-text {
    color: var(--c-text);
    font-size: 0.95rem;
    line-height: 1.5;
    max-width: 28ch;
    animation: bitty-fade-up 0.5s ease 0.25s both;
}

@keyframes bitty-walk-in {
    0%   { opacity: 0; transform: translateX(-48px) rotate(-6deg); }
    60%  { opacity: 1; transform: translateX(6px) rotate(2deg); }
    100% { opacity: 1; transform: translateX(0) rotate(0); }
}

@keyframes bitty-fade-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .nb-chat__hero,
    .nb-chat__welcome-text { animation: none; }
}

/* Messages */
.nb-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.nb-chat__msg {
    max-width: 85%;
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.nb-chat__msg--bot {
    align-self: flex-start;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    color: var(--c-text);
    border-bottom-left-radius: 4px;
}

.nb-chat__msg--user {
    align-self: flex-end;
    color: #fff;
    background: var(--primary, #007bff);
    border-bottom-right-radius: 4px;
}

.nb-chat__msg--bot a {
    color: var(--c-cyan);
    font-weight: 600;
    text-decoration: underline;
    word-break: break-word;
}

.nb-chat__msg--bot a:hover {
    color: #67e8f9;
}

/* Typing indicator */
.nb-chat__typing {
    align-self: flex-start;
    display: inline-flex;
    gap: 4px;
    padding: 0.7rem 0.9rem;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 14px;
}

.nb-chat__typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--c-muted);
    animation: nb-chat-bounce 1.2s infinite ease-in-out;
}

.nb-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.nb-chat__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes nb-chat-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-5px); opacity: 1; }
}

/* Input */
.nb-chat__form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--c-border);
    background: var(--c-bg);
}

.nb-chat__input {
    flex: 1;
    resize: none;
    max-height: 110px;
    padding: 0.65rem 0.85rem;
    border-radius: 12px;
    border: 1px solid var(--c-border);
    background: rgba(7, 8, 15, 0.6);
    color: var(--c-text);
    font: inherit;
    font-size: 0.9rem;
}

.nb-chat__input:focus {
    outline: none;
    border-color: var(--c-cyan);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.18);
}

.nb-chat__send {
    flex-shrink: 0;
    width: 42px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    color: #fff;
    background: #004efe;
    font-size: 1.1rem;
    transition: background 0.2s ease;
}

.nb-chat__send:hover {
    background: #003ad1;
}

.nb-chat__send:disabled {
    opacity: 0.5;
    cursor: default;
}

.nb-chat__disclaimer {
    padding: 0 0.75rem 0.6rem;
    font-size: 0.68rem;
    color: var(--c-muted);
    text-align: center;
}

@media (prefers-reduced-motion: reduce) {
    .nb-chat.is-open .nb-chat__panel { animation: none; }
    .nb-chat__typing span { animation: none; }
}

/* Per-message character counter (cost/abuse limit, user-friendly) */
.nb-chat__counter {
    font-size: 0.72rem;
    color: var(--c-muted, #9aa1bd);
    text-align: right;
    padding: 0 14px 8px;
    min-height: 1em;
}

.nb-chat__counter.is-near {
    color: #f59e0b;
}
