/* nd-chat — modern, accessible consultation widget (left side to avoid overlap with conversion widget) */

.nd-chat {
    position: fixed;
    z-index: 9015;
    bottom: max(20px, env(safe-area-inset-bottom));
    left: max(20px, env(safe-area-inset-left));
    font-family: inherit;
    pointer-events: none;
}

/* FAB button (visible, the only thing shown when closed) */
.nd-chat__fab {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #008001 0%, #00a83d 100%);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 28px rgba(0, 128, 1, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.4) inset;
    pointer-events: auto;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.nd-chat__fab:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 16px 36px rgba(0, 128, 1, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
}

.nd-chat__fab:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(0, 128, 1, 0.45);
}

.nd-chat__fab-icon {
    width: 26px;
    height: 26px;
    display: block;
    transition: opacity 0.18s ease, transform 0.22s ease;
}

.nd-chat__fab-icon--close {
    display: none;
}

.nd-chat.is-open .nd-chat__fab-icon--open {
    display: none;
}

.nd-chat.is-open .nd-chat__fab-icon--close {
    display: block;
}

.nd-chat__fab-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(0, 128, 1, 0.5);
    animation: nd-chat-pulse 1.8s ease-out infinite;
    pointer-events: none;
}

.nd-chat.is-open .nd-chat__fab-pulse {
    display: none;
}

@keyframes nd-chat-pulse {
    0%   { transform: scale(0.95); opacity: 0.9; }
    70%  { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* Panel */
.nd-chat__panel {
    position: absolute;
    bottom: calc(60px + 14px);
    left: 0;
    width: min(380px, calc(100vw - 32px));
    max-height: min(560px, calc(100vh - 110px));
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    border-radius: 20px;
    border: 1px solid rgba(0, 128, 1, 0.18);
    background: #ffffff;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22), 0 0 0 1px rgba(255, 255, 255, 0.6) inset;
    overflow: hidden;
    transform-origin: bottom left;
    transform: translateY(12px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.nd-chat.is-open .nd-chat__panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.nd-chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 14px 14px 16px;
    background: linear-gradient(135deg, #008001 0%, #00a83d 100%);
    color: #fff;
    position: relative;
}

.nd-chat__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.45);
}

.nd-chat__heading {
    flex: 1;
    min-width: 0;
}

.nd-chat__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #fff;
}

.nd-chat__subtitle {
    margin: 2px 0 0;
    font-size: 0.74rem;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 500;
}

.nd-chat__close {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.15s ease;
}

.nd-chat__close:hover {
    background: rgba(255, 255, 255, 0.32);
    transform: scale(1.05);
}

/* Body / messages */
.nd-chat__body {
    flex: 1 1 auto;
    min-height: 160px;
    max-height: 320px;
    overflow-y: auto;
    padding: 14px 14px 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8fafc;
    -webkit-overflow-scrolling: touch;
}

.nd-chat__msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    animation: nd-chat-msg-in 0.22s ease-out;
}

.nd-chat__msg--bot {
    align-self: flex-start;
    background: #ffffff;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.nd-chat__msg--user {
    align-self: flex-end;
    background: linear-gradient(145deg, #008001 0%, #00a83d 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.nd-chat__msg--thinking {
    color: #475569;
    background: #ffffff;
    border: 1px solid #e2e8f0;
}

@keyframes nd-chat-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Typing indicator */
.nd-chat__typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 6px;
    vertical-align: middle;
}

.nd-chat__typing > span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    display: inline-block;
    animation: nd-chat-bounce 1.2s infinite ease-in-out;
}

.nd-chat__typing > span:nth-child(2) { animation-delay: 0.15s; }
.nd-chat__typing > span:nth-child(3) { animation-delay: 0.3s; }

@keyframes nd-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%            { transform: translateY(-4px); opacity: 1; }
}

.nd-chat__thinking-text {
    font-size: 0.82rem;
}

/* Quick actions */
.nd-chat__quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    max-height: 132px;
    overflow-y: auto;
}

.nd-chat__chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    font-size: 0.74rem;
    font-weight: 600;
    border-radius: 999px;
    border: 1px solid rgba(0, 128, 1, 0.25);
    background: #f1fdf5;
    color: #0f172a;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.nd-chat__chip:hover {
    border-color: #008001;
    background: #008001;
    color: #fff;
    transform: translateY(-1px);
}

.nd-chat__chip--link {
    color: #0f172a;
}

/* Form */
.nd-chat__form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
}

.nd-chat__input {
    flex: 1;
    min-width: 0;
    padding: 11px 14px;
    border-radius: 24px;
    border: 1px solid #cbd5e1;
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.nd-chat__input:focus {
    border-color: #008001;
    box-shadow: 0 0 0 3px rgba(0, 128, 1, 0.15);
}

.nd-chat__send {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: #008001;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
}

.nd-chat__send svg {
    width: 20px;
    height: 20px;
}

.nd-chat__send:hover {
    background: #006902;
    transform: scale(1.05);
}

.nd-chat__send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.nd-chat--busy .nd-chat__quick { pointer-events: none; opacity: 0.62; }
.nd-chat--busy .nd-chat__send  { position: relative; color: transparent; }
.nd-chat--busy .nd-chat__send::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: nd-chat-spin 0.7s linear infinite;
}

@keyframes nd-chat-spin {
    to { transform: rotate(360deg); }
}

/* Markdown elements in bot messages */
.nd-chat__msg--bot strong,
.nd-chat__msg--bot b {
    font-weight: 600;
    color: #008001;
}

.nd-chat__msg--bot em,
.nd-chat__msg--bot i {
    font-style: italic;
}

.nd-chat__msg--bot code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.85em;
    color: #0f172a;
}

.nd-chat__msg--bot ul {
    margin: 8px 0;
    padding-left: 18px;
    list-style: none;
}

.nd-chat__msg--bot ul li {
    position: relative;
    padding-left: 12px;
    margin-bottom: 4px;
}

.nd-chat__msg--bot ul li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: #008001;
    font-weight: bold;
}

/* Visually hidden helper (a11y) */
.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

/* Responsive */
@media (max-width: 640px) {
    .nd-chat {
        left: max(12px, env(safe-area-inset-left));
        bottom: max(12px, env(safe-area-inset-bottom));
    }
    .nd-chat__panel {
        left: 0;
        right: auto;
        width: min(94vw, 360px);
        max-height: 70vh;
    }
    .nd-chat__fab {
        width: 54px;
        height: 54px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .nd-chat__panel,
    .nd-chat__fab,
    .nd-chat__msg,
    .nd-chat__typing > span,
    .nd-chat__fab-pulse,
    .nd-chat__send::after {
        animation: none !important;
        transition: none !important;
    }
}