/* Tools4Web — floating consultant chat (same UX as IT-Aegis) */

:root {
    --t4w-chat-z: 2147483000;
    --t4w-chat-gap: max(0.75rem, env(safe-area-inset-right, 0px));
    --t4w-chat-reserve: 5rem;
    --t4w-chat-green: #22c55e;
    --t4w-chat-green-dark: #16a34a;
}

body.t4w-chat-active {
    --t4w-chat-reserve: 5.5rem;
}

body.t4w-chat-open .scroll-top,
body.t4w-chat-open .cookie-banner,
body.t4w-chat-open #cookie-banner,
body.t4w-chat-open .pwa-install-banner {
    z-index: calc(var(--t4w-chat-z) - 2) !important;
}

body.t4w-chat-open .scroll-top {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

body.t4w-chat-active:not(.t4w-chat-open) .scroll-top {
    bottom: 110px !important;
    right: 15px !important;
}

.t4w-chat {
    position: fixed;
    right: var(--t4w-chat-gap);
    bottom: var(--t4w-chat-gap);
    z-index: var(--t4w-chat-z);
    font-family: var(--t4w-font, system-ui, -apple-system, sans-serif);
}

.t4w-chat__launcher {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3.75rem;
    height: 3.75rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(180deg, #2bd975 0%, var(--t4w-chat-green) 48%, var(--t4w-chat-green-dark) 100%);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22), 0 2px 4px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    overflow: visible;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.t4w-chat__launcher::before {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid rgba(34, 197, 94, 0.45);
    animation: t4w-chat-pulse 2.4s ease-out infinite;
    pointer-events: none;
}

.t4w-chat__launcher-icon {
    position: relative;
    z-index: 1;
    font-size: 1.65rem;
    line-height: 1;
    color: #fff;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.12));
}

@keyframes t4w-chat-pulse {
    0% {
        transform: scale(0.92);
        opacity: 0.75;
    }
    70% {
        transform: scale(1.08);
        opacity: 0;
    }
    100% {
        transform: scale(1.08);
        opacity: 0;
    }
}

.t4w-chat__launcher:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.26), 0 2px 4px rgba(0, 0, 0, 0.12);
}

.t4w-chat__launcher:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

.t4w-chat__head-photo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: 0;
    flex-shrink: 0;
    background: linear-gradient(180deg, #2bd975 0%, var(--t4w-chat-green) 100%);
    color: #fff;
    font-size: 1.1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.t4w-chat__launcher-badge {
    position: absolute;
    right: 0.1rem;
    bottom: 0.1rem;
    z-index: 2;
    width: 0.8rem;
    height: 0.8rem;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--t4w-chat-green);
    box-shadow: 0 0 0 2px #fff;
}

.t4w-chat__launcher-badge::after {
    content: '';
    position: absolute;
    inset: 1px;
    border-radius: 50%;
    background: #22c55e;
}

.t4w-chat__panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.75rem);
    width: min(22rem, calc(100vw - 1.5rem));
    max-height: min(32rem, calc(100vh - 7rem));
    display: flex;
    flex-direction: column;
    border-radius: 1rem;
    border: 1px solid color-mix(in srgb, var(--t4w-primary, #e8b84a) 28%, #2a3344);
    background: linear-gradient(180deg, #151b28 0%, #101622 100%);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.t4w-chat.is-open .t4w-chat__panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.t4w-chat.is-open .t4w-chat__launcher {
    transform: scale(0.94);
}

.t4w-chat.is-open .t4w-chat__launcher::before {
    animation: none;
    opacity: 0;
}

.t4w-chat__head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    background: color-mix(in srgb, var(--t4w-primary, #e8b84a) 10%, #121824);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.t4w-chat__head-text {
    flex: 1;
    min-width: 0;
}

.t4w-chat__head-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #f3f6fb;
}

.t4w-chat__head-sub {
    margin: 0.15rem 0 0;
    font-size: 0.78rem;
    color: #9aa7bd;
}

.t4w-chat__close {
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: #9aa7bd;
    cursor: pointer;
}

.t4w-chat__close:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #f3f6fb;
}

.t4w-chat__messages {
    flex: 1;
    overflow: auto;
    padding: 0.85rem 0.85rem 0.35rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.t4w-chat__bubble {
    max-width: 92%;
    padding: 0.65rem 0.8rem;
    border-radius: 0.85rem;
    font-size: 0.875rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.t4w-chat__bubble--bot {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.06);
    color: #e8edf5;
    border-bottom-left-radius: 0.25rem;
}

.t4w-chat__bubble--user {
    align-self: flex-end;
    background: color-mix(in srgb, var(--t4w-primary, #e8b84a) 88%, #fff);
    color: #1a1408;
    border-bottom-right-radius: 0.25rem;
}

.t4w-chat__bubble--system {
    align-self: center;
    background: transparent;
    color: #8b97ab;
    font-size: 0.78rem;
    padding: 0.2rem 0.4rem;
}

.t4w-chat__form {
    padding: 0.75rem 0.85rem 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.t4w-chat__fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
}

.t4w-chat__field {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border-radius: 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.22);
    color: #f3f6fb;
    font-size: 0.82rem;
}

.t4w-chat__field::placeholder {
    color: #7f8ba0;
}

.t4w-chat__field:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--t4w-primary, #e8b84a) 55%, transparent);
}

.t4w-chat__field--full {
    grid-column: 1 / -1;
}

.t4w-chat__compose {
    display: flex;
    gap: 0.45rem;
    align-items: flex-end;
}

.t4w-chat__textarea {
    flex: 1;
    min-height: 2.6rem;
    max-height: 6.5rem;
    resize: vertical;
    padding: 0.55rem 0.65rem;
    border-radius: 0.65rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.22);
    color: #f3f6fb;
    font-size: 0.875rem;
    line-height: 1.4;
}

.t4w-chat__textarea:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--t4w-primary, #e8b84a) 55%, transparent);
}

.t4w-chat__send {
    flex-shrink: 0;
    width: 2.6rem;
    height: 2.6rem;
    border: 0;
    border-radius: 50%;
    background: var(--t4w-primary, #e8b84a);
    color: #1a1408;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.t4w-chat__send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.t4w-chat__send:not(:disabled):hover {
    filter: brightness(1.05);
}

.t4w-chat__hp {
    position: absolute;
    left: -9999px;
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 767.98px) {
    :root {
        --t4w-chat-gap: 0.65rem;
        --t4w-chat-reserve: 4.75rem;
    }

    .t4w-chat__panel {
        width: min(20rem, calc(100vw - 1.25rem));
        max-height: min(70vh, 28rem);
    }

    .t4w-chat__fields {
        grid-template-columns: 1fr;
    }
}
