:root {
    --ks-chat-primary: #027afd;
    --ks-chat-primary-dark: #0268d4;
    --ks-chat-primary-deep: #0159b8;
    --ks-chat-surface: #1e293b;
    --ks-chat-surface-deep: #0f172a;
}

#chat-widget-root {
    position: relative;
    z-index: 2147483000;
}

#chat-widget {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 2147483000 !important;
    pointer-events: auto !important;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

#chat-panel {
    z-index: 2147483001 !important;
    display: none;
    flex-direction: column !important;
    width: 380px;
    max-width: calc(100vw - 24px);
    height: 520px;
    max-height: calc(100vh - 100px);
    background: var(--ks-chat-surface);
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.2);
    overflow: hidden;
}

#chat-panel.ks-chat-open {
    display: flex !important;
}

.ks-chat-header {
    background: linear-gradient(135deg, var(--ks-chat-primary) 0%, var(--ks-chat-primary-dark) 55%, var(--ks-chat-primary-deep) 100%);
    color: #fff;
    padding: 14px 16px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.ks-chat-header-title {
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

#chat-close {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 20px;
    flex-shrink: 0;
    line-height: 1;
    opacity: 0.9;
}

#chat-close:hover {
    opacity: 1;
}

#chat-contact-bar {
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.5);
    border-bottom: 1px solid rgba(148, 163, 184, 0.15);
    flex-shrink: 0;
}

#chat-contact-hint {
    margin: 0 0 8px;
    font-size: 11px;
    color: #94a3b8;
    line-height: 1.35;
}

.ks-chat-contact-fields {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

#chat-contact-bar input {
    flex: 1;
    min-width: 100px;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #475569;
    background: var(--ks-chat-surface-deep);
    color: #f8fafc;
    font-size: 12px;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    min-height: 0;
    background: var(--ks-chat-surface-deep);
}

.ks-chat-footer {
    padding: 12px;
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    flex-shrink: 0;
    background: var(--ks-chat-surface);
}

.ks-chat-input-row {
    display: flex;
    gap: 8px;
}

#chat-input {
    flex: 1;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #475569;
    background: var(--ks-chat-surface-deep);
    color: #f8fafc;
    font-size: 14px;
    min-width: 0;
}

#chat-send {
    padding: 12px 18px;
    background: linear-gradient(135deg, var(--ks-chat-primary), var(--ks-chat-primary-dark));
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}

#chat-send:hover {
    filter: brightness(1.05);
}

#chat-send:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.ks-chat-toggle-wrap {
    position: relative;
    width: 112px;
    height: 145px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chat-toggle {
    position: relative;
    width: 100%;
    height: 100%;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: visible;
    box-shadow: none;
    z-index: 2147483002 !important;
    pointer-events: auto !important;
}

.ks-chat-toggle-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
    filter: drop-shadow(0 6px 14px rgba(2, 122, 253, 0.5)) drop-shadow(0 2px 6px rgba(2, 122, 253, 0.35));
}

.chat-msg-content {
    font-size: 14px;
    line-height: 1.55;
    color: #f8fafc;
}

.chat-msg-content p {
    margin: 0 0 0.65em;
}

.chat-msg-content p:last-child {
    margin-bottom: 0;
}

.chat-msg-content ul,
.chat-msg-content ol {
    margin: 0.35em 0 0.65em;
    padding-left: 1.25em;
}

.chat-msg-content li {
    margin: 0.25em 0;
}

.chat-msg-content a {
    color: #7ec8ff;
    text-decoration: underline;
}

.chat-msg-content .chat-img-wrap {
    margin: 0.5em 0;
}

.chat-msg-content .chat-img-wrap img {
    max-width: 100%;
    width: 100%;
    max-height: 180px;
    height: auto;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    cursor: pointer;
}

.chat-msg-content .chat-inline-link,
.chat-msg-content .chat-prop-link a {
    color: #7dd3fc;
    text-decoration: underline;
    font-weight: 600;
}

.chat-msg-content .chat-inline-link:hover,
.chat-msg-content .chat-prop-link a:hover {
    color: #f47d31;
}

.chat-msg-content .chat-img-wrap a {
    display: inline-block;
    border-radius: 10px;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-msg-content .chat-img-wrap a:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 18px rgba(2, 122, 253, 0.35);
}

.chat-msg-content .chat-prop-link {
    margin: 0.35em 0;
}

.chat-md-plain {
    margin: 0;
}

#chat-widget .chat-lang-select {
    background: var(--ks-chat-surface-deep);
    color: #f8fafc;
    border: 1px solid #475569;
    border-radius: 6px;
    font-size: 11px;
    padding: 4px 6px;
    max-width: 110px;
    flex-shrink: 0;
}

.ks-chat-bubble-user {
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    max-width: 85%;
    word-break: break-word;
    background: rgba(2, 122, 253, 0.28);
    margin-left: auto;
    text-align: right;
}

.ks-chat-bubble-assistant {
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    max-width: 85%;
    word-break: break-word;
    background: rgba(71, 85, 105, 0.5);
    color: #f8fafc;
}

body.in-admin #chat-widget,
body.page-sidebar-closed #chat-widget,
.bb-page #chat-widget {
    z-index: 2147483000 !important;
}

@media only screen and (max-width: 767px) {
    #chat-widget {
        bottom: 14px !important;
        right: 14px !important;
        left: auto !important;
    }

    #chat-panel {
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        height: min(72vh, 520px);
        max-height: calc(100vh - 80px);
        border-radius: 14px;
    }

    .ks-chat-toggle-wrap {
        width: 92px;
        height: 118px;
    }

    #chat-send {
        padding: 12px 14px;
        font-size: 13px;
    }

    #chat-widget .chat-lang-select {
        max-width: 88px;
        font-size: 10px;
    }
}

@media only screen and (max-width: 400px) {
    .ks-chat-header {
        padding: 12px;
        gap: 6px;
    }

    #chat-input {
        padding: 10px 12px;
        font-size: 13px;
    }
}

.ks-chat-toggle-wrap {
    width: 88px;
    height: 116px;
}

@media only screen and (max-width: 991.98px) {
    #chat-widget {
        bottom: 96px !important;
        right: 8px !important;
    }

    .ks-chat-toggle-wrap {
        width: 68px;
        height: 90px;
    }
}

@media only screen and (max-width: 480px) {
    .ks-chat-toggle-wrap {
        width: 48px;
        height: 64px;
    }
}
