.kef-chat {
    --chat-accent: #1f6feb;
    --chat-accent-hot: #0b5bd3;
    --chat-online: #22c55e;
    position: fixed;
    z-index: 180;
    right: clamp(12px, 2vw, 28px);
    bottom: clamp(12px, 2vw, 28px);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    width: min(380px, calc(100vw - 24px));
    font-family: var(--font-sans);
    color: var(--color-ink);
}

.kef-chat__promo {
    position: relative;
    width: min(290px, 100%);
    padding: 14px 16px 16px;
    color: #fff;
    background: linear-gradient(145deg, #1f6feb 0%, #0b4fbf 100%);
    border-radius: 18px;
    box-shadow: 0 14px 34px rgba(15, 76, 189, 0.35);
}

.kef-chat__promo[hidden] {
    display: none;
}

.kef-chat__promo-close {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    cursor: pointer;
}

.kef-chat__promo-title {
    margin: 0 28px 6px 0;
    font-size: 0.98rem;
    font-weight: 700;
}

.kef-chat__promo-text {
    margin: 0 0 12px;
    font-size: 0.86rem;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.9);
}

.kef-chat__promo-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    border: 0;
    border-radius: 999px;
    background: #fff;
    color: #0b4fbf;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
}

.kef-chat__toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.55em;
    padding: 0.95em 1.4em;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1;
    color: #fff;
    background: linear-gradient(135deg, var(--chat-accent) 0%, var(--chat-accent-hot) 100%);
    border: 0;
    border-radius: var(--radius-pill);
    box-shadow: 0 12px 28px rgba(15, 76, 189, 0.32);
    cursor: pointer;
}

.kef-chat__toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 32px rgba(15, 76, 189, 0.4);
}

.kef-chat.is-open .kef-chat__toggle,
.kef-chat.is-open .kef-chat__promo {
    display: none;
}

.kef-chat__toggle-online,
.kef-chat__online {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--chat-online);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    animation: kef-chat-ripple 1.8s infinite;
}

.kef-chat__toggle-online {
    top: 8px;
    right: 10px;
    border: 2px solid #fff;
}

.kef-chat__badge {
    position: absolute;
    top: -6px;
    left: -6px;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.3rem;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0;
    line-height: 1;
    box-shadow: 0 0 0 2px #fff;
}

.kef-chat__badge[hidden] {
    display: none;
}

.kef-chat__online {
    right: 0;
    bottom: 0;
    border: 2px solid #fff;
}

.kef-chat__toggle-online[hidden],
.kef-chat__online[hidden] {
    display: none;
}

@keyframes kef-chat-ripple {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.65);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

.kef-chat__panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: min(520px, calc(100vh - 120px));
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(31, 111, 235, 0.18);
    border-radius: 18px;
    box-shadow: 0 18px 40px rgba(17, 24, 39, 0.18);
}

.kef-chat__panel[hidden] {
    display: none;
}

.kef-chat__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 14px 12px;
    background: linear-gradient(135deg, #123a8a 0%, #1f6feb 100%);
    color: #fff;
}

.kef-chat__person {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.kef-chat__avatar {
    position: relative;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
}

.kef-chat__avatar img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.55);
}

.kef-chat__title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.kef-chat__status {
    margin: 4px 0 0;
    color: rgba(245, 245, 245, 0.82);
    font-size: 0.78rem;
}

.kef-chat__close {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 50%;
    cursor: pointer;
}

.kef-chat__close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.kef-chat__log {
    flex: 1;
    overflow: auto;
    padding: 16px;
    background: #f4f8ff;
}

.kef-chat__hello,
.kef-chat__bubble {
    max-width: 88%;
    margin: 0 0 10px;
    padding: 10px 12px;
    font-size: 0.92rem;
    line-height: 1.45;
}

.kef-chat__hello {
    max-width: none;
    color: #334155;
    background: #fff;
    border-radius: 16px;
    border: 1px solid rgba(31, 111, 235, 0.12);
}

.kef-chat__bubble p {
    margin: 0;
}

.kef-chat__bubble--visitor {
    margin-left: auto;
    color: #fff;
    background: linear-gradient(135deg, var(--chat-accent) 0%, var(--chat-accent-hot) 100%);
    border-radius: 16px 16px 4px 16px;
}

.kef-chat__bubble--staff {
    color: var(--color-ink);
    background: #fff;
    border-radius: 16px 16px 16px 4px;
    border: 1px solid rgba(31, 111, 235, 0.12);
}

.kef-chat__bubble--system {
    max-width: none;
    color: var(--color-muted);
    background: transparent;
    padding: 0;
    font-size: 0.78rem;
    text-align: center;
}

.kef-chat__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    background: #fff;
    border-top: 1px solid rgba(31, 111, 235, 0.12);
}

.kef-chat__field {
    flex: 1;
    min-width: 0;
}

.kef-chat__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.kef-chat__form input {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    color: var(--color-ink);
    background: #f4f8ff;
    border: 1px solid rgba(31, 111, 235, 0.2);
    border-radius: var(--radius-pill);
    outline: none;
}

.kef-chat__form input:focus {
    border-color: var(--chat-accent);
}

.kef-chat__send {
    height: 44px;
    padding: 0 16px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(135deg, var(--chat-accent) 0%, var(--chat-accent-hot) 100%);
    border: 0;
    border-radius: var(--radius-pill);
    cursor: pointer;
}

.kef-chat__send:hover {
    transform: translateY(-1px);
}

@media (max-width: 640px) {
    .kef-chat__toggle span:last-child {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .kef-chat__toggle {
        width: 56px;
        height: 56px;
        justify-content: center;
        padding: 0;
    }

    .kef-chat__toggle-online {
        top: 8px;
        right: 8px;
    }
}

@media print {
    .kef-chat {
        display: none;
    }
}
