/* Tokens */
.vntech-ai-widget,
.vntech-ai-widget * {
    box-sizing: border-box;
}

.vntech-ai-widget {
    --vn-ai-primary: #2563eb;
    --vn-ai-primary-dark: #1d4ed8;
    --vn-ai-accent: #0f172a;
    --vn-ai-text: #111827;
    --vn-ai-muted: #64748b;
    --vn-ai-line: rgba(15, 23, 42, 0.1);
    --vn-ai-soft: #f8fafc;
    --vn-ai-bg: #ffffff;
    bottom: 22px;
    color: var(--vn-ai-text);
    font-family: inherit;
    position: fixed;
    right: 22px;
    z-index: 100030;
}

.vntech-ai-widget :focus-visible {
    outline: 2px solid color-mix(in srgb, var(--vn-ai-primary) 72%, #ffffff);
    outline-offset: 2px;
}

.vntech-ai-widget.is-left {
    left: 22px;
    right: auto;
}

body.vn-menu-open .vntech-ai-widget {
    opacity: 0;
    pointer-events: none;
}

/* Launcher */
.vntech-ai-widget__launcher {
    align-items: center;
    appearance: none;
    background: #0f172a;
    border: 1px solid rgba(15, 23, 42, 0.18);
    border-radius: 16px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    gap: 0;
    height: 46px;
    justify-content: center;
    min-height: 46px;
    min-width: 46px;
    overflow: hidden;
    padding: 0 10px;
    transition: box-shadow 160ms ease, transform 160ms ease, width 180ms ease;
}

.vntech-ai-widget__launcher:hover {
    box-shadow: 0 16px 34px rgba(15, 23, 42, 0.2);
    transform: translateY(-1px);
}

.vntech-ai-widget__launcher:active {
    transform: translateY(0);
}

.vntech-ai-widget__launcher-text {
    display: grid;
    gap: 2px;
    line-height: 1;
    margin-left: 0;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    text-align: left;
    transition: margin 180ms ease, max-width 180ms ease, opacity 160ms ease;
    white-space: nowrap;
}

.vntech-ai-widget__launcher:hover .vntech-ai-widget__launcher-text,
.vntech-ai-widget__launcher:focus-visible .vntech-ai-widget__launcher-text {
    margin-left: 8px;
    max-width: 150px;
    opacity: 1;
}

.vntech-ai-widget__launcher-text > span {
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 0;
}

.vntech-ai-widget__launcher-text small {
    color: rgba(255, 255, 255, 0.72);
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
}

.vntech-ai-widget__avatar {
    align-items: center;
    background: #ffffff;
    background-position: center;
    background-size: cover;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 999px;
    color: var(--vn-ai-primary);
    display: inline-flex;
    flex: 0 0 26px;
    font-size: 10px;
    font-weight: 900;
    height: 26px;
    justify-content: center;
    line-height: 1;
    overflow: hidden;
    position: relative;
    width: 26px;
}

.vntech-ai-widget__avatar::before {
    background: currentColor;
    border-radius: 2px 999px 999px 999px;
    content: "";
    height: 9px;
    opacity: 0.9;
    transform: rotate(-18deg);
    width: 9px;
}

.vntech-ai-widget__avatar.is-initials::before,
.vntech-ai-widget__avatar.has-image::before {
    content: none;
}

/* Panel shell */
.vntech-ai-widget__panel {
    background: var(--vn-ai-bg);
    border: 1px solid var(--vn-ai-line);
    border-radius: 16px;
    box-shadow: 0 18px 54px rgba(15, 23, 42, 0.18);
    display: none;
    flex-direction: column;
    height: auto;
    margin-bottom: 12px;
    max-height: min(610px, calc(100vh - 34px));
    overflow: hidden;
    width: min(374px, calc(100vw - 28px));
}

.vntech-ai-widget.is-open .vntech-ai-widget__panel {
    display: flex;
    height: min(430px, calc(100vh - 44px));
    margin-bottom: 0;
    max-height: min(430px, calc(100vh - 44px));
    width: min(360px, calc(100vw - 32px));
}

.vntech-ai-widget.is-open .vntech-ai-widget__launcher {
    display: none;
}

.vntech-ai-widget.is-open {
    bottom: 22px;
    max-height: none;
    right: 22px;
    width: min(360px, calc(100vw - 32px));
    z-index: 100040;
}

.vntech-ai-widget.is-open.is-left {
    left: 22px;
    right: auto;
}

.vntech-ai-widget__screen {
    background: #ffffff;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.vntech-ai-widget__screen[hidden] {
    display: none !important;
}

/* Header */
.vntech-ai-widget__panel header {
    align-items: center;
    background: #0f172a;
    border-bottom: 0;
    color: #ffffff;
    display: flex;
    flex: 0 0 auto;
    gap: 10px;
    min-height: 48px;
    padding: 8px 10px;
}

.vntech-ai-widget__panel header .vntech-ai-widget__avatar {
    flex-basis: 26px;
    font-size: 10px;
    height: 26px;
    width: 26px;
}

.vntech-ai-widget__header-copy {
    display: grid;
    flex: 1 1 auto;
    gap: 2px;
    min-width: 0;
}

.vntech-ai-widget__panel header strong {
    color: #ffffff;
    flex: 1;
    font-size: 14px;
    line-height: 1.15;
    min-width: 0;
}

.vntech-ai-widget__header-copy small {
    color: rgba(255, 255, 255, 0.68);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vntech-ai-widget__mode-badge {
    background: rgba(37, 99, 235, 0.22);
    border: 1px solid rgba(147, 197, 253, 0.3);
    border-radius: 999px;
    color: #dbeafe;
    font-size: 10px;
    font-weight: 800;
    padding: 4px 7px;
}

.vntech-ai-widget__panel header button {
    appearance: none;
    background: transparent;
    border: 0;
    color: rgba(255, 255, 255, 0.72);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    min-height: 34px;
    min-width: 34px;
    padding: 0 2px;
}

/* Messages */
.vntech-ai-widget__messages {
    background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 8px;
    max-height: none;
    min-height: 116px;
    overflow-y: auto;
    padding: 10px;
    scrollbar-gutter: stable;
}

.vntech-ai-widget__messages:empty {
    min-height: 160px;
}

.vntech-ai-widget__message {
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.42;
    max-width: 92%;
    padding: 9px 11px;
    white-space: pre-wrap;
}

.vntech-ai-widget__message.is-assistant {
    align-self: flex-start;
    background: #eef4ff;
    border: 1px solid rgba(37, 99, 235, 0.1);
    color: #172033;
}

.vntech-ai-widget__message.is-user {
    align-self: flex-end;
    background: var(--vn-ai-primary);
    color: #ffffff;
}

.vntech-ai-widget__message.is-error {
    align-self: flex-start;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.vntech-ai-widget.is-loading .vntech-ai-widget__messages::after {
    align-self: flex-start;
    background: #eef4ff;
    border: 1px solid rgba(37, 99, 235, 0.1);
    border-radius: 13px;
    color: #475569;
    content: "Подготвям отговор...";
    font-size: 13px;
    line-height: 1.4;
    padding: 9px 11px;
}

.vntech-ai-widget__helper {
    color: var(--vn-ai-muted);
    flex: 0 0 auto;
    font-size: 11px;
    line-height: 1.3;
    margin: 0;
    padding: 7px 10px 4px;
}

/* Suggestion chips */
.vntech-ai-widget__quick-actions {
    background: #ffffff;
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 10px 8px;
}

.vntech-ai-widget__quick-actions button {
    appearance: none;
    background: #f8fafc;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 999px;
    color: #1f2a44;
    cursor: pointer;
    flex: 0 0 auto;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.2;
    min-height: 28px;
    padding: 6px 9px;
    transition: border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.vntech-ai-widget__quick-actions button:hover {
    border-color: rgba(37, 99, 235, 0.38);
    color: var(--vn-ai-primary);
    transform: translateY(-1px);
}

.vntech-ai-widget__chat-actions {
    background: #ffffff;
    display: grid;
    flex: 0 0 auto;
    gap: 7px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 0 10px 10px;
}

.vntech-ai-widget__secondary {
    appearance: none;
    background: #f8fafc;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 9px;
    color: #334155;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.15;
    min-height: 32px;
    padding: 0 8px;
    white-space: normal;
}

.vntech-ai-widget__review-note {
    color: #64748b;
    flex: 0 0 auto;
    font-size: 10px;
    line-height: 1.3;
    margin: 0;
    padding: 0 12px 9px;
}

/* Chat form */
.vntech-ai-widget__form {
    background: #ffffff;
    border-top: 1px solid rgba(15, 23, 42, 0.07);
    display: grid;
    flex: 0 0 auto;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) 92px;
    padding: 9px 10px;
    position: sticky;
    bottom: 0;
    z-index: 2;
}

.vntech-ai-widget input,
.vntech-ai-widget textarea {
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 10px;
    color: var(--vn-ai-text);
    font: inherit;
    min-height: 44px;
    padding: 8px 12px;
    width: 100%;
}

.vntech-ai-widget input:focus,
.vntech-ai-widget textarea:focus {
    border-color: var(--vn-ai-primary, #2563eb);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
    outline: none;
}

.vntech-ai-widget textarea {
    min-height: 82px;
    resize: vertical;
}

.vntech-ai-widget button[type="submit"] {
    appearance: none;
    background: var(--vn-ai-primary, #2563eb);
    border: 0;
    border-radius: 10px;
    color: #ffffff;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    min-height: 44px;
    padding: 0 12px;
    transition: background 160ms ease, opacity 160ms ease;
    white-space: nowrap;
}

.vntech-ai-widget button[type="submit"]:hover {
    background: var(--vn-ai-primary-dark, #1d4ed8);
}

.vntech-ai-widget button:disabled,
.vntech-ai-widget input:disabled,
.vntech-ai-widget textarea:disabled {
    cursor: wait;
    opacity: 0.68;
}

.vntech-ai-widget.is-sending .vntech-ai-widget__quick-actions,
.vntech-ai-widget.is-sending [data-vn-ai-demo-action],
.vntech-ai-widget.is-sending [data-vn-ai-handoff] {
    pointer-events: none;
}

/* Lead form */
.vntech-ai-widget__lead-intro {
    background: #ffffff;
    flex: 0 0 auto;
    padding: 12px 12px 8px;
}

.vntech-ai-widget__lead-intro h2,
.vntech-ai-widget__success h2 {
    font-size: 18px;
    line-height: 1.25;
    margin: 0 0 6px;
}

.vntech-ai-widget__lead-intro p,
.vntech-ai-widget__success p {
    color: #4b5563;
    font-size: 13px;
    line-height: 1.45;
    margin: 0;
}

.vntech-ai-widget__lead-intro p {
    max-width: 310px;
}

.vntech-ai-widget__lead-form {
    display: grid;
    flex: 1 1 auto;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: min(486px, calc(100vh - 150px));
    min-height: 0;
    overflow-y: auto;
    padding: 8px 12px 12px;
    scrollbar-gutter: stable;
}

.vntech-ai-widget__lead-form input[name="interest"],
.vntech-ai-widget__lead-form textarea,
.vntech-ai-widget__optional,
.vntech-ai-widget__lead-form .vntech-ai-widget__consent,
.vntech-ai-widget__lead-form .vntech-ai-widget__privacy,
.vntech-ai-widget__lead-form button {
    grid-column: 1 / -1;
}

.vntech-ai-widget__optional {
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 10px;
    padding: 0;
}

.vntech-ai-widget__optional summary {
    color: #475569;
    cursor: pointer;
    font-size: 12px;
    font-weight: 900;
    list-style: none;
    padding: 10px 11px;
}

.vntech-ai-widget__optional summary::-webkit-details-marker {
    display: none;
}

.vntech-ai-widget__optional summary::after {
    color: var(--vn-ai-primary);
    content: "+";
    float: right;
}

.vntech-ai-widget__optional[open] summary::after {
    content: "-";
}

.vntech-ai-widget__optional input {
    margin: 0 10px 8px;
    width: calc(100% - 20px);
}

.vntech-ai-widget__consent {
    align-items: flex-start;
    display: flex;
    font-size: 12px;
    gap: 8px;
    line-height: 1.35;
}

.vntech-ai-widget__consent input {
    min-height: 0;
    width: auto;
}

.vntech-ai-widget__privacy,
.vntech-ai-widget__powered {
    color: #6b7280;
    font-size: 11px;
    line-height: 1.35;
    margin: 0;
}

.vntech-ai-widget__powered {
    flex: 0 0 auto;
    padding: 0 12px 8px;
}

.vntech-ai-widget__hp {
    left: -10000px;
    position: absolute;
}

/* Success state */
.vntech-ai-widget__success {
    align-items: flex-start;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    justify-content: center;
    min-height: 0;
    padding: 24px 16px;
}

.vntech-ai-widget__success .vntech-ai-widget__secondary {
    margin-top: 14px;
    width: 100%;
}

/* Mobile */
@media (max-width: 480px) {
    .vntech-ai-widget,
    .vntech-ai-widget.is-left {
        bottom: max(10px, env(safe-area-inset-bottom));
        left: 10px;
        right: 10px;
    }

    .vntech-ai-widget:not(.is-open),
    .vntech-ai-widget.is-left:not(.is-open) {
        left: auto;
        width: 46px;
    }

    .vntech-ai-widget__panel {
        max-height: calc(100dvh - 20px);
        width: calc(100vw - 20px);
    }

    .vntech-ai-widget.is-open {
        bottom: max(10px, env(safe-area-inset-bottom));
        left: 10px;
        right: 10px;
        width: auto;
    }

    .vntech-ai-widget.is-open .vntech-ai-widget__panel {
        height: min(76vh, calc(100dvh - 20px));
        max-height: calc(100dvh - 20px);
        width: 100%;
    }

    .vntech-ai-widget__launcher {
        max-width: calc(100vw - 20px);
        width: auto;
    }

    .vntech-ai-widget__header-copy small {
        white-space: normal;
    }

    .vntech-ai-widget__messages {
        max-height: none;
        min-height: 150px;
    }

    .vntech-ai-widget__quick-actions {
        max-height: 86px;
        overflow-y: auto;
        scrollbar-gutter: stable;
    }

    .vntech-ai-widget__form {
        grid-template-columns: minmax(0, 1fr) 86px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .vntech-ai-widget__form input[name="message"] {
        font-size: 16px;
    }

    .vntech-ai-widget__lead-form {
        grid-template-columns: 1fr;
    }

    .vntech-ai-widget__chat-actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .vntech-ai-widget__lead-form {
        max-height: calc(100dvh - 156px);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .vntech-ai-widget__launcher,
    .vntech-ai-widget__quick-actions button,
    .vntech-ai-widget button[type="submit"] {
        transition: none;
    }
}

/* VNTech final frontend UX acceptance pass: clearer portable widget UI */
.vntech-ai-widget.is-open {
    width: min(420px, calc(100vw - 32px));
}

.vntech-ai-widget.is-open .vntech-ai-widget__panel {
    height: min(620px, calc(100vh - 44px));
    max-height: min(620px, calc(100vh - 44px));
    width: min(420px, calc(100vw - 32px));
}

.vntech-ai-widget__panel header {
    min-height: 50px;
    padding: 8px 12px;
}

.vntech-ai-widget__messages {
    gap: 9px;
    min-height: 220px;
    padding: 12px;
}

.vntech-ai-widget__message {
    max-width: 88%;
    padding: 10px 12px;
}

.vntech-ai-widget__helper {
    padding: 8px 12px 5px;
}

.vntech-ai-widget.has-chat-started .vntech-ai-widget__helper,
.vntech-ai-widget.has-chat-started .vntech-ai-widget__review-note {
    display: none;
}

.vntech-ai-widget__quick-actions {
    gap: 7px;
    max-height: 76px;
    overflow: hidden;
    padding: 0 12px 8px;
}

.vntech-ai-widget.has-chat-started .vntech-ai-widget__quick-actions {
    display: none;
}

.vntech-ai-widget__quick-actions button {
    min-height: 30px;
    padding: 6px 10px;
}

.vntech-ai-widget__chat-actions {
    gap: 6px;
    padding: 0 12px 9px;
}

.vntech-ai-widget__secondary {
    border-radius: 8px;
    font-size: 11px;
    min-height: 30px;
    padding: 0 7px;
}

.vntech-ai-widget__review-note {
    padding: 0 12px 7px;
}

.vntech-ai-widget__form {
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) 94px;
    padding: 10px 12px 12px;
}

.vntech-ai-widget__form input[name="message"] {
    min-height: 48px;
}

.vntech-ai-widget button[type="submit"] {
    background: var(--vn-ai-primary, #2563eb) !important;
    color: #ffffff !important;
    min-height: 48px;
}

@media (max-width: 480px) {
    .vntech-ai-widget.is-open .vntech-ai-widget__panel {
        border-radius: 18px;
        height: min(84dvh, calc(100dvh - 16px));
        max-height: calc(100dvh - 16px);
    }

    .vntech-ai-widget__panel header {
        min-height: 44px;
        padding: 7px 10px;
    }

    .vntech-ai-widget__panel header strong {
        font-size: 13px;
    }

    .vntech-ai-widget__header-copy small {
        font-size: 9.5px;
    }

    .vntech-ai-widget__messages {
        gap: 7px;
        min-height: 0;
        padding: 9px 10px;
    }

    .vntech-ai-widget__message {
        border-radius: 12px;
        font-size: 12.5px;
        line-height: 1.36;
        max-width: 90%;
        padding: 8px 10px;
    }

    .vntech-ai-widget.is-loading .vntech-ai-widget__messages::after {
        font-size: 12.5px;
        padding: 8px 10px;
    }

    .vntech-ai-widget__helper {
        font-size: 10.5px;
        padding: 6px 10px 4px;
    }

    .vntech-ai-widget__quick-actions {
        flex-wrap: nowrap;
        max-height: 34px;
        overflow: hidden;
        padding-inline: 10px;
    }

    .vntech-ai-widget__quick-actions button {
        font-size: 11px;
        min-height: 27px;
        padding: 5px 8px;
    }

    .vntech-ai-widget__quick-actions button:nth-child(n+3) {
        display: none;
    }

    .vntech-ai-widget__chat-actions {
        gap: 6px;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding-inline: 10px;
    }

    .vntech-ai-widget__chat-actions [data-vn-ai-handoff] {
        grid-column: 1 / -1;
    }

    .vntech-ai-widget.has-chat-started .vntech-ai-widget__chat-actions {
        grid-template-columns: 1fr;
    }

    .vntech-ai-widget.has-chat-started .vntech-ai-widget__chat-actions [data-vn-ai-demo-action],
    .vntech-ai-widget.has-chat-started .vntech-ai-widget__chat-actions [data-vn-ai-handoff] {
        display: none;
    }

    .vntech-ai-widget__secondary {
        font-size: 10.5px;
        min-height: 28px;
    }

    .vntech-ai-widget__form {
        gap: 6px;
        grid-template-columns: minmax(0, 1fr) 78px;
        padding: 8px 10px max(8px, env(safe-area-inset-bottom));
    }

    .vntech-ai-widget__form input[name="message"] {
        min-height: 42px;
        padding: 7px 10px;
    }

    .vntech-ai-widget button[type="submit"] {
        border-radius: 9px;
        font-size: 12.5px;
        min-height: 42px;
        padding: 0 8px;
    }

    .vntech-ai-widget__powered {
        display: none;
    }
}
