/* =====================================================
   Website assistant widget
   Uses the tokens defined in styles.css; RTL handled
   inline here rather than in rtl.css because the widget
   sets its own dir and ships as one self-contained unit.
   ===================================================== */

.nchat-launcher,
.nchat-panel {
    position: fixed;
    font-family: inherit;
}

/* Below the site header (1000) so an open nav menu covers it, which is the
   right precedence for a floating button. */
.nchat-launcher {
    z-index: 900;
}

/* Above the header and the mobile nav (1000/1001). On phones the panel is
   full screen, so anything drawing over it lands in the middle of the
   conversation — the site nav was doing exactly that. */
.nchat-panel {
    z-index: 1002;
}

/* ---------------------------------------------------------------- launcher */

.nchat-launcher {
    inset-inline-end: 24px;
    bottom: 24px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 13px 20px;
    border: 1px solid rgba(var(--primary-rgb), 0.35);
    border-radius: 999px;
    background: var(--gradient-primary);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: 0 12px 34px rgba(var(--primary-rgb), 0.32);
    transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.2s ease;
}

.nchat-launcher svg {
    width: 19px;
    height: 19px;
    flex-shrink: 0;
}

.nchat-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 44px rgba(var(--primary-rgb), 0.42);
}

.nchat-launcher:focus-visible {
    outline: 2px solid var(--primary-light);
    outline-offset: 3px;
}

/* While the panel is open the launcher would sit behind it on desktop and on
   top of it on mobile. Hiding it is simpler than fighting the stacking. */
body.nchat-open .nchat-launcher {
    opacity: 0;
    pointer-events: none;
}

/* ------------------------------------------------------------------- panel */

.nchat-panel {
    inset-inline-end: 24px;
    bottom: 24px;
    display: flex;
    flex-direction: column;
    width: min(392px, calc(100vw - 32px));
    height: min(596px, calc(100vh - 48px));
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    background: var(--bg-card-solid);
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.52);
    overflow: hidden;
    animation: nchat-in 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.nchat-panel[hidden] {
    display: none;
}

@keyframes nchat-in {
    from { opacity: 0; transform: translateY(14px) scale(0.985); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .nchat-panel { animation: none; }
    .nchat-launcher { transition: none; }
}

/* -------------------------------------------------------------------- head */

.nchat-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 17px 18px 15px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(var(--primary-rgb), 0.10), transparent);
}

.nchat-heading {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.nchat-heading strong {
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--text-primary);
}

.nchat-heading span {
    font-size: 0.78rem;
    line-height: 1.4;
    color: var(--text-muted);
}

.nchat-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 7px;
}

/* Always-available escape hatch to a person. Deliberately quiet — it should be
   findable without competing with the conversation. */
.nchat-human {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 500;
    font-family: inherit;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.nchat-human svg { width: 13px; height: 13px; flex-shrink: 0; }

.nchat-human:hover {
    border-color: rgba(16, 185, 129, 0.5);
    background: rgba(16, 185, 129, 0.10);
    color: var(--text-primary);
}

.nchat-human:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.nchat-human[hidden] { display: none; }

/* The same choice offered among the opening suggestions. Tinted, because it is
   a different kind of answer from the other chips — not a question for the
   assistant, but a way past it. */
.nchat-chip-human {
    border-color: rgba(16, 185, 129, 0.45);
    background: rgba(16, 185, 129, 0.08);
    color: var(--success);
    font-weight: 600;
}

.nchat-chip-human:hover {
    border-color: rgba(16, 185, 129, 0.7);
    background: rgba(16, 185, 129, 0.12);
    color: var(--text-primary);
}

.nchat-close {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.nchat-close svg { width: 15px; height: 15px; }
.nchat-close:hover { color: var(--text-primary); border-color: var(--border-light); }
.nchat-close:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* --------------------------------------------------------------------- log */

.nchat-log {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 11px;
    padding: 18px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}

.nchat-log::-webkit-scrollbar { width: 7px; }
.nchat-log::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.14);
    border-radius: 4px;
}

.nchat-msg {
    display: flex;
    max-width: 100%;
}

.nchat-user { justify-content: flex-end; }
.nchat-assistant { justify-content: flex-start; }

.nchat-bubble {
    max-width: 85%;
    padding: 11px 14px;
    border-radius: 15px;
    font-size: 0.885rem;
    line-height: 1.62;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.nchat-assistant .nchat-bubble {
    border: 1px solid var(--border);
    border-start-start-radius: 5px;
    background: rgba(255, 255, 255, 0.045);
    color: var(--text-secondary);
}

.nchat-user .nchat-bubble {
    border-end-end-radius: 5px;
    background: var(--gradient-primary);
    color: #fff;
    font-weight: 500;
}

/* A human is answering. Visually distinct from the assistant, because the
   difference between "a bot said this" and "the founder said this" matters. */

.nchat-agent {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.nchat-who {
    padding-inline-start: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--success);
}

.nchat-agent .nchat-bubble {
    max-width: 88%;
    border: 1px solid rgba(16, 185, 129, 0.32);
    border-start-start-radius: 5px;
    background: rgba(16, 185, 129, 0.10);
    color: var(--text-primary);
}

/* Status line: joined, handed back, ended. */
.nchat-notice {
    margin: 3px 0;
    padding: 7px 12px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.04);
    font-size: 0.76rem;
    line-height: 1.5;
    color: var(--text-muted);
    text-align: center;
}

/* typing indicator */

.nchat-typing .nchat-bubble {
    display: flex;
    gap: 5px;
    padding: 15px 14px;
}

.nchat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: nchat-pulse 1.3s ease-in-out infinite;
}

.nchat-typing span:nth-child(2) { animation-delay: 0.18s; }
.nchat-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes nchat-pulse {
    0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
    30%           { opacity: 1;    transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    .nchat-typing span { animation: none; opacity: 0.6; }
}

/* ------------------------------------------------------- suggestions chips */

.nchat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 2px;
}

.nchat-chip {
    padding: 8px 13px;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.79rem;
    font-family: inherit;
    text-align: start;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.nchat-chip:hover {
    border-color: rgba(var(--primary-rgb), 0.5);
    background: var(--primary-subtle);
    color: var(--text-primary);
}

.nchat-chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ------------------------------------------------- handoff prompt and card */

.nchat-handoff,
.nchat-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px;
    border: 1px solid rgba(var(--primary-rgb), 0.28);
    border-radius: 15px;
    background: var(--primary-subtle);
}

.nchat-handoff p,
.nchat-card p {
    margin: 0;
    font-size: 0.83rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.nchat-card strong {
    font-size: 0.92rem;
    color: var(--text-primary);
}

.nchat-field {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.24);
    color: var(--text-primary);
    font-size: 0.86rem;
    font-family: inherit;
    resize: vertical;
}

.nchat-field::placeholder { color: var(--text-muted); }
.nchat-field:focus {
    outline: none;
    border-color: rgba(var(--primary-rgb), 0.6);
    box-shadow: 0 0 0 3px var(--primary-subtle);
}

.nchat-cta {
    padding: 11px 16px;
    border: none;
    border-radius: 10px;
    background: var(--gradient-primary);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: filter 0.2s ease;
}

.nchat-cta:hover:not(:disabled) { filter: brightness(1.1); }
.nchat-cta:disabled { opacity: 0.6; cursor: default; }
.nchat-cta:focus-visible { outline: 2px solid var(--primary-light); outline-offset: 2px; }

.nchat-back {
    padding: 2px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-family: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.nchat-back:hover { color: var(--text-secondary); }

.nchat-error {
    margin: 0;
    color: var(--danger) !important;
    font-size: 0.79rem !important;
}

.nchat-error[hidden] { display: none; }

/* ----------------------------------------------------------------- compose */

.nchat-compose {
    display: flex;
    align-items: flex-end;
    gap: 9px;
    padding: 13px 14px 10px;
    border-top: 1px solid var(--border);
}

.nchat-input {
    flex: 1;
    max-height: 120px;
    padding: 11px 13px;
    border: 1px solid var(--border-light);
    border-radius: 13px;
    background: rgba(0, 0, 0, 0.24);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
}

.nchat-input::placeholder { color: var(--text-muted); }
.nchat-input:focus {
    outline: none;
    border-color: rgba(var(--primary-rgb), 0.6);
    box-shadow: 0 0 0 3px var(--primary-subtle);
}

.nchat-send {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 41px;
    height: 41px;
    border: none;
    border-radius: 12px;
    background: var(--gradient-primary);
    color: #fff;
    cursor: pointer;
    transition: filter 0.2s ease, opacity 0.2s ease;
}

.nchat-send svg { width: 17px; height: 17px; }
.nchat-send:hover:not(:disabled) { filter: brightness(1.1); }
.nchat-send:disabled { opacity: 0.45; cursor: default; }
.nchat-send:focus-visible { outline: 2px solid var(--primary-light); outline-offset: 2px; }

/* The send glyph is an arrow: it must point the way the text runs. */
[dir="rtl"] .nchat-send svg { transform: scaleX(-1); }

.nchat-disclaimer {
    margin: 0;
    padding: 0 16px 12px;
    font-size: 0.7rem;
    line-height: 1.5;
    color: var(--text-muted);
    text-align: center;
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 520px) {
    .nchat-launcher {
        inset-inline-end: 16px;
        bottom: 16px;
        padding: 12px 16px;
        font-size: 0.84rem;
    }

    /* Full screen on phones. A partial-height sheet leaves too little room once
       the keyboard takes half the viewport, and the strip of page showing
       behind it invites stray taps mid-conversation. JS pins the height to the
       visual viewport so the composer stays above the keyboard — see fitPanel().
       The vh/dvh values here are what applies before that runs, and on browsers
       without the VisualViewport API. */
    /* Anchored to the top, never the bottom: with the keyboard open iOS keeps
       the layout viewport full height and scrolls it, so `bottom: 0` resolves
       to a point underneath the keyboard. fitPanel() sets height and
       translateY from the visual viewport, which is the only thing that
       describes what is actually on screen. dvh is the pre-JS fallback. */
    .nchat-panel {
        inset-inline: 0;
        top: 0;
        bottom: auto;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border: none;
        border-radius: 0;
    }

    /* The panel covers the screen, so anything scrolling behind it is only a
       way to lose your place. */
    body.nchat-open {
        overflow: hidden;
    }

    /* iOS Safari zooms the entire page in when a field smaller than 16px gets
       focus. On a full-screen chat that throws the layout around on every tap
       and leaves the visitor pinching back out — the single worst thing about
       typing in this panel on a phone. 16px is the threshold; nothing about the
       design needs it smaller. */
    .nchat-input,
    .nchat-field {
        font-size: 16px;
    }

    /* The panel sits flush with the bottom of the screen, so on phones with a
       gesture bar the last line would otherwise render underneath it. */
    .nchat-disclaimer {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* Momentum scrolling in the transcript, and never chain a scroll at the
       end of it to the page underneath. */
    .nchat-log {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
}

/* Below this the header title and the label cannot both fit; the icon plus its
   aria-label still says what the control does. */
@media (max-width: 400px) {
    .nchat-human-label { display: none; }
    .nchat-human { padding: 7px 9px; }
}
