.modal,
.chat-window {
    --g4w-app-bg: #161717;
    --g4w-surface-bg: #1d2020;
    --g4w-panel-bg: #242626;
    --g4w-panel-bg-hover: #2d2e2e;
    --g4w-border: #000000;
    --g4w-border-soft: #2c2f2f;
    --g4w-input-bg: #121414;
    --g4w-input-border: #3c4141;
    --g4w-text: #f9fafb;
    --g4w-text-muted: #d1d5db;
    --g4w-text-soft: #9ca3af;
    --g4w-text-subtle: #6b7280;
    --g4w-accent: #3857d6;
    --g4w-accent-contrast: #ffffff;
    --g4w-badge-bg: #242626;
    --g4w-badge-text: #7fa0ff;
    --g4w-button-secondary-bg: #1d2020;
    --g4w-button-secondary-border: #3c4141;
    --g4w-bubble-me: #144d37;
    --g4w-bubble-them: #242626;
    --g4w-reply-preview-bg: #1b2b26;
    --g4w-reply-preview-border: #6ee7b7;
    --g4w-reply-preview-author: #a7f3d0;
    --g4w-reply-author-me: #d1fae5;
    --g4w-reply-author-them: #93c5fd;
    --g4w-quote-panel-me: rgba(0, 0, 0, 0.16);
    --g4w-quote-panel-them: rgba(255, 255, 255, 0.05);
    --g4w-quote-frame-me: rgba(255, 255, 255, 0.07);
    --g4w-quote-frame-them: rgba(255, 255, 255, 0.06);
    --g4w-quote-accent-out: var(--g4w-bubble-me);
    --g4w-quote-accent-in: #53bdeb;
    --g4w-quote-author-out: #b7f5cd;
    --g4w-quote-author-in: #7fd3ff;
    --g4w-quote-text-me: rgba(255, 255, 255, 0.92);
    --g4w-quote-text-them: rgba(255, 255, 255, 0.78);
    --g4w-composer-hint: rgba(255, 255, 255, 0.75);
    --g4w-menu-bg: #ffffff;
    --g4w-menu-text: #111827;
    --g4w-menu-border: #e5e5e5;
    --g4w-menu-hover: #cccccc;
    --g4w-float-bg: #333333;
    --g4w-float-border: #000000;
    --g4w-lock-badge-bg: rgba(56, 87, 214, 0.16);
    --g4w-lock-badge-text: #8ea6ff;
    --g4w-overlay-backdrop: rgba(10, 12, 12, 0.78);
    --g4w-test-bg: #272b2b;
}

.modal.g4w-theme-light,
.chat-window.g4w-theme-light {
    --g4w-app-bg: #f4f6f8;
    --g4w-surface-bg: #ffffff;
    --g4w-panel-bg: #eef2f5;
    --g4w-panel-bg-hover: #e2e8f0;
    --g4w-border: #d6dde5;
    --g4w-border-soft: #d6dde5;
    --g4w-input-bg: #ffffff;
    --g4w-input-border: #c3ccd7;
    --g4w-text: #0f172a;
    --g4w-text-muted: #334155;
    --g4w-text-soft: #64748b;
    --g4w-text-subtle: #64748b;
    --g4w-accent: #2563eb;
    --g4w-accent-contrast: #ffffff;
    --g4w-badge-bg: #dbe7ff;
    --g4w-badge-text: #1d4ed8;
    --g4w-button-secondary-bg: #ffffff;
    --g4w-button-secondary-border: #c3ccd7;
    --g4w-bubble-me: #d7f3df;
    --g4w-bubble-them: #ffffff;
    --g4w-reply-preview-bg: #edf8f0;
    --g4w-reply-preview-border: #22c55e;
    --g4w-reply-preview-author: #166534;
    --g4w-reply-author-me: #166534;
    --g4w-reply-author-them: #1d4ed8;
    --g4w-quote-panel-me: rgba(15, 23, 42, 0.08);
    --g4w-quote-panel-them: rgba(15, 23, 42, 0.04);
    --g4w-quote-frame-me: rgba(15, 23, 42, 0.08);
    --g4w-quote-frame-them: rgba(15, 23, 42, 0.08);
    --g4w-quote-accent-out: #22c55e;
    --g4w-quote-accent-in: #2563eb;
    --g4w-quote-author-out: #166534;
    --g4w-quote-author-in: #1d4ed8;
    --g4w-quote-text-me: rgba(15, 23, 42, 0.92);
    --g4w-quote-text-them: rgba(15, 23, 42, 0.76);
    --g4w-composer-hint: rgba(15, 23, 42, 0.72);
    --g4w-menu-bg: #ffffff;
    --g4w-menu-text: #0f172a;
    --g4w-menu-border: #d6dde5;
    --g4w-menu-hover: #edf2f7;
    --g4w-float-bg: #ffffff;
    --g4w-float-border: #d6dde5;
    --g4w-lock-badge-bg: rgba(37, 99, 235, 0.12);
    --g4w-lock-badge-text: #1d4ed8;
    --g4w-overlay-backdrop: rgba(148, 163, 184, 0.55);
    --g4w-test-bg: #e8edf3;
}

.modal.g4w-theme-light input,
.modal.g4w-theme-light textarea,
.modal.g4w-theme-light select,
.chat-window.g4w-theme-light input,
.chat-window.g4w-theme-light textarea,
.chat-window.g4w-theme-light select {
    color-scheme: light;
    background: #ffffff !important;
    color: #0f172a !important;
    caret-color: #0f172a;
    -webkit-text-fill-color: #0f172a;
}

.modal.g4w-theme-light input:focus,
.modal.g4w-theme-light textarea:focus,
.modal.g4w-theme-light select:focus,
.chat-window.g4w-theme-light input:focus,
.chat-window.g4w-theme-light textarea:focus,
.chat-window.g4w-theme-light select:focus {
    background: #ffffff !important;
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a;
}

.chat-window {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    /*max-width: 820px;*/
    height: 70vh;
    border: 1px solid var(--g4w-border);
    border-radius: 12px;
    overflow: hidden;
    font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Arial;
    background: var(--g4w-app-bg);
    color: var(--g4w-text);
    box-sizing: border-box;
}

.g4w-setup-overlay {
    position: absolute;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: var(--g4w-overlay-backdrop);
    box-sizing: border-box;
}

.g4w-setup-overlay[hidden],
.g4w-setup-step[hidden] {
    display: none !important;
}

.g4w-setup-card {
    width: min(920px, calc(100% - 24px));
    max-height: min(780px, calc(100% - 24px));
    overflow: auto;
    position: relative;
    padding: 14px;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 14px;
    background:
        radial-gradient(circle at top right, rgba(56, 87, 214, 0.12), transparent 24%),
        radial-gradient(circle at top left, rgba(125, 211, 163, 0.14), transparent 22%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 22%),
        var(--g4w-surface-bg);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
    color: var(--g4w-text);
}

.g4w-setup-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.g4w-setup-card-header > div {
    flex: 1 1 auto;
    min-width: 0;
}

.g4w-setup-title {
    margin: 0;
    font-size: 20px;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.g4w-setup-close {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border: 1px solid var(--g4w-button-secondary-border);
    border-radius: 8px;
    background: var(--g4w-button-secondary-bg);
    color: var(--g4w-text);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.g4w-setup-close:hover {
    background: var(--g4w-panel-bg);
    border-color: var(--g4w-input-border);
    transform: translateY(-1px);
}

.g4w-setup-close[hidden] {
    display: none !important;
}

.g4w-setup-copy {
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid rgba(56, 87, 214, 0.12);
    border-radius: 10px;
    background: rgba(56, 87, 214, 0.06);
    color: var(--g4w-text-muted);
    max-width: none;
    line-height: 1.55;
}

.g4w-setup-webhook,
.g4w-setup-webhook-status {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.g4w-setup-webhook-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.g4w-setup-webhook-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--g4w-text-muted);
}

.g4w-setup-webhook-value {
    padding: 8px 10px;
    border: 1px solid var(--g4w-input-border);
    border-radius: 8px;
    background: var(--g4w-input-bg);
    color: var(--g4w-text);
    font-family: monospace;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-all;
}

.g4w-setup-hint {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--g4w-text-soft);
}

.g4w-setup-alert,
.g4w-setup-test {
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--g4w-test-bg);
    color: var(--g4w-text);
}

.g4w-setup-alert.is-error {
    background: #3a1f1f;
    color: #fecaca;
}

.g4w-setup-alert.is-success,
.g4w-setup-test.is-success {
    background: #183325;
    color: #bbf7d0;
}

.g4w-setup-test.is-error {
    background: #3a1f1f;
    color: #fecaca;
}

.g4w-setup-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.g4w-setup-step {
    padding: 10px;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.g4w-setup-field {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.035);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
    box-sizing: border-box;
    justify-self: stretch;
    align-self: stretch;
}

.g4w-setup-field--wide {
    grid-column: 1 / -1;
}

.g4w-setup-field span {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--g4w-text-muted);
}

.g4w-setup-field-hint {
    font-size: 11px;
    line-height: 1.45;
    color: var(--g4w-text-soft);
}

.g4w-setup-field input {
    width: 100%;
    margin-top: 2px;
    padding: 10px 12px;
    border: 1px solid var(--g4w-input-border);
    border-radius: 8px;
    background: var(--g4w-input-bg);
    color: var(--g4w-text);
    font-size: 14px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
    box-sizing: border-box;
}

.g4w-setup-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.g4w-setup-secondary {
    border: 1px solid var(--g4w-button-secondary-border);
    background: rgba(255, 255, 255, 0.02);
    color: var(--g4w-text);
    padding: 7px 11px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.g4w_modal__body > .chat-window {
    border-radius: 0 !important;
}

.chat-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--g4w-border);
    background: var(--g4w-panel-bg);
}

.chat-title {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-self: start;
}

.chat-header__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-self: end;
}

.chat-contact-link {
    position: relative;
    justify-self: center;
    max-width: min(460px, 100%);
}

.chat-contact-link[hidden] {
    display: none !important;
}

.chat-contact-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 100%;
    max-width: min(460px, 100%);
    padding: 7px 12px;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--g4w-text-muted);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    text-align: center;
    box-sizing: border-box;
    cursor: pointer;
    transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.chat-contact-label:hover,
.chat-contact-label[aria-expanded="true"] {
    border-color: var(--g4w-input-border);
    background: rgba(255, 255, 255, 0.05);
}

.chat-contact-label:focus-visible {
    outline: 2px solid rgba(56, 87, 214, 0.45);
    outline-offset: 2px;
}

.chat-contact-label__text {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-contact-label__meta {
    display: block;
    max-width: 100%;
    font-size: 11px;
    font-weight: 500;
    color: var(--g4w-text-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-contact-link-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(420px, calc(100vw - 32px));
    max-height: min(420px, calc(100vh - 220px));
    padding: 8px;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 12px;
    background: var(--g4w-panel-bg);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.22);
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.chat-contact-link-menu[hidden] {
    display: none !important;
}

.chat-contact-link-menu__hint,
.chat-contact-link-menu__empty {
    padding: 8px 10px;
    font-size: 12px;
    color: var(--g4w-text-soft);
}

.chat-contact-link-menu__list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-contact-link-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
    color: var(--g4w-text);
    text-align: left;
    cursor: pointer;
    transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.chat-contact-link-option:hover {
    border-color: var(--g4w-input-border);
    background: rgba(255, 255, 255, 0.05);
    transform: translateY(-1px);
}

.chat-contact-link-option.is-current {
    border-color: rgba(56, 87, 214, 0.45);
    background: rgba(56, 87, 214, 0.10);
}

.chat-contact-link-option__title {
    font-size: 13px;
    font-weight: 600;
    color: var(--g4w-text);
}

.chat-contact-link-option__meta {
    font-size: 11px;
    color: var(--g4w-text-soft);
}

.chat-contact-link-option__badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(56, 87, 214, 0.12);
    color: var(--g4w-badge-text);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chat-notify-toggle {
    display: inline-flex;
    align-items: center;
    width: auto;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--g4w-text-muted);
}

.chat-notify-toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
}

.chat-notify-toggle input[type="checkbox"]:disabled + span {
    opacity: 0.5;
}

.badge {
    background: var(--g4w-badge-bg);
    color: var(--g4w-badge-text);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

@media (max-width: 900px) {
    .chat-header {
        grid-template-columns: 1fr;
        align-items: flex-start;
    }

    .chat-header__meta {
        justify-self: start;
    }

    .chat-contact-label {
        max-width: 100%;
        text-align: left;
        align-items: flex-start;
    }

    .chat-contact-link {
        justify-self: start;
        width: 100%;
        max-width: 100%;
    }

    .chat-contact-link-menu {
        left: 0;
        transform: none;
        width: min(420px, calc(100vw - 32px));
        max-height: min(360px, calc(100vh - 180px));
    }

    .chat-composer-status {
        display: flex;
        align-items: flex-start;
        flex-wrap: wrap;
    }
}

.chat-messages {
    flex: 1;
    padding: 12px;
    overflow: auto;
    background: var(--g4w-app-bg);
    max-width: 1500px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    box-sizing: border-box;
}

.g4w-chat-placeholder {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.g4w-chat-placeholder .bubble {
    margin: 0;
    opacity: 0.85;
}

.bubble {
    max-width: 70%;
    margin: 8px 0;
    padding: 8px 10px;
    border-radius: 12px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.from-me {
    margin-left: auto;
    background: var(--g4w-bubble-me);
    border-top-right-radius: 4px;
}

.from-them {
    margin-right: auto;
    background: var(--g4w-bubble-them);
    border-top-left-radius: 4px;
}

.meta {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 4px;
    opacity: 0.7;
    font-size: 12px;
}

.reply-preview {
    margin: 0 22px 6px 0;
    padding: 7px 10px 8px 12px;
    border: 0;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.from-me .reply-preview {
    background: var(--g4w-quote-panel-me);
    box-shadow: inset 0 0 0 1px var(--g4w-quote-frame-me);
}

.from-them .reply-preview {
    background: var(--g4w-quote-panel-them);
    box-shadow: inset 0 0 0 1px var(--g4w-quote-frame-them);
}

.reply-preview::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    border-radius: 4px 0 0 4px;
    background: var(--g4w-quote-accent-in);
}

.reply-preview.reply-preview--from-me::before {
    background: var(--g4w-quote-accent-out);
}

.reply-preview__author {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--g4w-quote-author-in);
}

.reply-preview.reply-preview--from-me .reply-preview__author {
    color: var(--g4w-quote-author-out);
}

.reply-preview__text {
    font-size: 12px;
    line-height: 1.35;
    word-break: break-word;
    color: var(--g4w-quote-text-them);
}

.from-me .reply-preview .reply-preview__text {
    color: var(--g4w-quote-text-me);
}

.media {
    display: block;
    margin-top: 6px;
}

.media img {
    max-width: 240px;
    max-height: 240px;
    display: block;
    border-radius: 8px;
}

.chat-composer {
    border-top: 1px solid var(--g4w-border);
    background: var(--g4w-panel-bg);
    padding: 10px;
}

#chatForm {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-composer-status {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
}

.chat-composer-hint {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--g4w-composer-hint);
    font-size: 12px;
}

.chat-notify-toggle--composer {
    justify-self: end;
    white-space: nowrap;
}

.chat-reply-preview {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border-left: 3px solid var(--g4w-reply-preview-border);
    border-radius: 8px;
    background: var(--g4w-reply-preview-bg);
    box-sizing: border-box;
}

.chat-reply-preview[hidden] {
    display: none !important;
}

.chat-reply-preview__body {
    flex: 1 1 auto;
    min-width: 0;
}

.chat-reply-preview__author {
    font-size: 12px;
    font-weight: 600;
    color: var(--g4w-reply-preview-author);
    margin-bottom: 2px;
}

.chat-reply-preview__text {
    font-size: 12px;
    color: var(--g4w-text-muted);
    line-height: 1.35;
    word-break: break-word;
}

.chat-reply-preview__close {
    border: 0;
    background: transparent;
    color: var(--g4w-text);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 2px 4px;
}

#chatInput {
    flex: 1;
    resize: vertical;
    padding: 8px;
    border: 1px solid var(--g4w-input-border);
    border-radius: 8px;
    background: var(--g4w-input-bg);
    color: var(--g4w-text);
}

#clientFilesBtn,
#attachBtn {
    padding: 8px 12px;
    border: 1px solid var(--g4w-input-border);
    border-radius: 8px;
    background: var(--g4w-button-secondary-bg);
    color: var(--g4w-text);
    cursor: pointer;
}

#clientFilesBtn[hidden] {
    display: none !important;
}

#clientFilesBtn[disabled],
#attachBtn[disabled] {
    opacity: 0.6;
    cursor: default;
}

#chatSendBtn {
    padding: 8px 14px;
    border: 0;
    background: #2f7d32;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
}

#chatSendBtn[disabled] {
    opacity: 0.6;
    cursor: default;
}

.tick {
    font-size: 12px;
}

/* Make bubble the positioning context for the menu */
.bubble {
    position: relative;
}

/* Kebab button */
.bubble .menu {
    position: absolute;
    top: 6px;
    right: 6px;
}

.bubble .menu-btn {
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    font-size: 16px;
    opacity: 0.7;
    color: var(--g4w-text);
}

.bubble .menu-btn:hover {
    opacity: 1;
}

/* Dropdown */
.bubble .menu-list {
    position: absolute;
    top: 24px;
    right: 0;
    display: none;
    min-width: 160px;
    background: var(--g4w-menu-bg);
    border: 1px solid var(--g4w-menu-border);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    padding: 6px 0;
    z-index: 50;
    width: 230px;
}

.bubble .menu.open .menu-list {
    display: block;
}

.bubble .menu-list button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    background: none;
    border: 0;
    cursor: pointer;
    font-size: 14px;
    color: var(--g4w-menu-text);
}

.bubble .menu-list button:hover {
    background: var(--g4w-menu-hover);
}

/* Highlight bubble when its menu is open */
.bubble.menu-active {
    outline: 2px solid rgba(56, 87, 214, 0.35);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px rgba(56, 87, 214, 0.12) inset;
}

/* Slight variant for your own messages (optional) */
.bubble.from-me.menu-active {
    outline-color: rgba(47, 125, 50, 0.35);
    box-shadow: 0 0 0 2px rgba(47, 125, 50, 0.12) inset;
}

/* Make chat area a positioning context */
.chat-messages {
    position: relative;
}

/* Floating window; top/height are set via JS to pin to viewport */
.chat-float {
    position: absolute;
    left: 12px; /* horizontal margin — keep in sync with JS margin */
    right: 12px;
    background: var(--g4w-float-bg);
    border: 1px solid var(--g4w-float-border);
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, .12), 0 2px 4px rgba(0, 0, 0, .08);
    z-index: 100; /* above bubbles/menus */
    display: flex;
    flex-direction: column; /* header + body layout */
    overflow: hidden;
}

/* Optional subtle backdrop inside the chat area */
.chat-float::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .03);
    pointer-events: none;
}

/* Title bar */
.chat-float-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--g4w-panel-bg);
    border-bottom: 1px solid var(--g4w-border);
    user-select: none;
    font-weight: 600;
}

/* Close (X) */
.chat-float-close {
    border: 0;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 4px;
    opacity: .75;
    color: var(--g4w-text) !important;
}

.chat-float-close:hover {
    opacity: 1;
}

/* Content fills remaining height */
.chat-float-body {
    flex: 1 1 auto;
    overflow: auto;
    padding: 12px;
    overscroll-behavior: contain; /* Chrome/Edge/Firefox */
    -ms-scroll-chaining: none; /* Old Edge (legacy) */
}

/* Container that will slide over the chat (inside your page layout) */
.contacts-panel {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 320px;
    background: var(--g4w-panel-bg);
    border-right: 1px solid var(--g4w-float-border) !important;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
    transform: translateX(-100%);
    transition: transform 200ms ease;
    z-index: 200; /* above chat */
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.contacts-panel.open {
    transform: translateX(0);
}

.contacts-header {
    padding: 10px 12px;
    background: var(--g4w-panel-bg);
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.chat-window.drawer-open .chat-messages {
    width: calc(100% - 320px);
    margin-right: 0px;
    transition: width 200ms ease-in-out;
}

.chat-window.drawer-open .chat-header,
.chat-window.drawer-open .chat-composer {
    margin-left: 320px;
    transition: margin-left 200ms ease-in-out;
}

.contacts-search {
    width: 100%;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    box-sizing: border-box;
    background: var(--g4w-panel-bg);
}

.contacts-search input {
    width: 100%;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--g4w-input-border);
    background: var(--g4w-input-bg);
    color: var(--g4w-text);
}

.contacts-list {
    flex: 1 1 auto;
    overflow: auto;
    background: var(--g4w-panel-bg);
}

.contacts-footer {
    padding: 8px 12px 12px;
    border-top: 1px solid var(--g4w-border);
    background: var(--g4w-panel-bg);
}

.contact-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    padding: 10px 12px;
    cursor: pointer;
}

.contact-item:hover {
    background: var(--g4w-panel-bg-hover);
}

.contact-item.active {
    background: var(--g4w-panel-bg-hover);
}

.contact-name {
    font-weight: 600;
}

.contact-name-row {
    grid-column: 1 / span 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.contact-unread-dot {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: #2fdb6a;
    box-shadow: 0 0 0 2px rgba(47, 219, 106, 0.2);
    flex: 0 0 auto;
}

.contact-preview {
    font-size: 13px;
    color: var(--g4w-text-subtle);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-meta-row {
    grid-column: 1 / span 2;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.contact-meta-row .contact-preview {
    flex: 1 1 auto;
    min-width: 0;
}

.contact-lock-badge {
    flex: 0 1 46%;
    min-width: 0;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--g4w-lock-badge-bg);
    color: var(--g4w-lock-badge-text);
    font-size: 12px;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contacts-toggle {
    border: 0;
    background: var(--g4w-accent);
    color: var(--g4w-accent-contrast);
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
}

.g4w-settings-button {
    border: 1px solid var(--g4w-button-secondary-border);
    background: var(--g4w-button-secondary-bg);
    color: var(--g4w-text);
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
}

.g4w-theme-switch-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px 0 2px;
}

.g4w-theme-switch-wrap--compact {
    gap: 6px;
    padding: 0;
}

.g4w-theme-switch-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--g4w-text-soft);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.g4w-theme-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: transparent;
    color: var(--g4w-text);
    padding: 0;
    cursor: pointer;
}

.g4w-theme-switch__track {
    position: relative;
    width: 44px;
    height: 24px;
    border-radius: 999px;
    background: rgba(100, 116, 139, 0.35);
    transition: background 180ms ease;
}

.g4w-theme-switch__thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
    transition: transform 180ms ease;
}

.g4w-theme-switch__text {
    min-width: 38px;
    font-size: 13px;
    font-weight: 600;
}

.g4w-theme-switch--compact {
    gap: 6px;
}

.g4w-theme-switch--compact .g4w-theme-switch__track {
    width: 36px;
    height: 20px;
}

.g4w-theme-switch--compact .g4w-theme-switch__thumb {
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
}

.g4w-theme-switch--compact .g4w-theme-switch__text {
    min-width: 32px;
    font-size: 12px;
}

.g4w-theme-switch--compact[aria-checked="true"] .g4w-theme-switch__thumb {
    transform: translateX(16px);
}

.g4w-theme-switch[aria-checked="true"] .g4w-theme-switch__track {
    background: var(--g4w-accent);
}

.g4w-theme-switch[aria-checked="true"] .g4w-theme-switch__thumb {
    transform: translateX(20px);
}

.g4w-client-files-picker {
    position: absolute;
    inset: 0;
    z-index: 120;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    box-sizing: border-box;
}

.g4w-client-files-picker[hidden] {
    display: none !important;
}

.g4w-client-files-picker__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 12, 12, 0.72);
}

.g4w-client-files-picker__dialog {
    position: relative;
    z-index: 1;
    width: min(760px, 100%);
    max-height: min(680px, calc(100% - 24px));
    display: flex;
    flex-direction: column;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 14px;
    background:
        radial-gradient(circle at top right, rgba(56, 87, 214, 0.14), transparent 22%),
        radial-gradient(circle at top left, rgba(125, 211, 163, 0.12), transparent 20%),
        var(--g4w-surface-bg);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
    overflow: hidden;
}

.g4w-client-files-picker__header,
.g4w-client-files-picker__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--g4w-border-soft);
}

.g4w-client-files-picker__footer {
    border-top: 1px solid var(--g4w-border-soft);
    border-bottom: 0;
}

.g4w-client-files-picker__title {
    margin: 0;
    font-size: 16px;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.g4w-client-files-picker__close {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border: 1px solid var(--g4w-button-secondary-border);
    border-radius: 8px;
    background: var(--g4w-button-secondary-bg);
    color: var(--g4w-text);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.g4w-client-files-picker__status {
    margin: 12px 14px 0;
    padding: 10px 12px;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--g4w-text-muted);
}

.g4w-client-files-picker__status.is-error {
    border-color: rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

.g4w-client-files-picker__status.is-success {
    border-color: rgba(34, 197, 94, 0.3);
    color: #86efac;
}

.g4w-client-files-picker__categories {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px 14px 0;
}

.g4w-client-files-picker__category {
    padding: 5px 9px;
    border: 1px solid var(--g4w-input-border);
    border-radius: 999px;
    background: var(--g4w-button-secondary-bg);
    color: var(--g4w-text-muted);
    font-size: 12px;
    cursor: pointer;
}

.g4w-client-files-picker__category.is-active {
    border-color: transparent;
    background: var(--g4w-accent);
    color: var(--g4w-accent-contrast);
}

.g4w-client-files-picker__list {
    flex: 1 1 auto;
    overflow: auto;
    margin: 12px 14px 14px;
    padding: 0;
    display: block;
    border: 1px solid var(--g4w-border-soft);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.05);
}

.g4w-client-files-picker__empty {
    padding: 14px;
    border: 0;
    border-radius: 8px;
    color: var(--g4w-text-muted);
    text-align: center;
}

.g4w-client-files-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.g4w-client-files-table th,
.g4w-client-files-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--g4w-border-soft);
    font-size: 12px;
    text-align: left;
    vertical-align: top;
}

.g4w-client-files-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--g4w-panel-bg);
    color: var(--g4w-text-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.g4w-client-files-table tbody tr:last-child td {
    border-bottom: 0;
}

.g4w-client-files-table__row:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.g4w-client-files-table__row.is-disabled {
    opacity: 0.65;
}

.g4w-client-files-table__check {
    width: 34px;
}

.g4w-client-file__checkbox {
    margin: 1px 0 0;
}

.g4w-client-files-table__name {
    color: var(--g4w-text);
    font-weight: 500;
    word-break: break-word;
}

.g4w-client-files-table__uploaded {
    width: 140px;
    color: var(--g4w-text-soft);
    white-space: nowrap;
}

.g4w-client-files-table__description {
    color: var(--g4w-text-soft);
    word-break: break-word;
}

.g4w-client-files-table__description.is-error {
    color: #fca5a5;
}

.g4w-client-files-picker__count {
    color: var(--g4w-text-muted);
    font-size: 12px;
    font-weight: 600;
}

.g4w-client-files-picker__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Page demo styles (optional) */
.page {
    min-height: 100 svh;
    display: grid;
    place-items: center;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
}

.btn {
    padding: 0.625rem 1rem;
    border: 1px solid #d0d5dd;
    border-radius: 0.5rem;
    background: #fff;
    cursor: pointer;
}

/* Modal layout */
.modal {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-areas: "stack";
    align-items: center;
    justify-items: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
    z-index: 2147483647;
}

.modal.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.g4w_modal__backdrop {
    grid-area: stack;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .45);
}

.g4w_modal__dialog {
    grid-area: stack;
    width: min(920px, 92vw);
    max-height: 92vh;
    background: var(--g4w-app-bg);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.g4w_modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--g4w-border);
    background: var(--g4w-panel-bg) !important;
    color: var(--g4w-text);
}

.g4w_modal__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.g4w_modal__close {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--g4w-text);
}

.g4w_modal__body {
    padding: 0;
    overflow: auto;
}

/* Floating WhatsApp button */
.floating-whatsapp {
    position: fixed;
    right: 25px;    /* margin from right edge */
    bottom: 50px;   /* margin from bottom edge */
    width: 50px;
    height: 50px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    z-index: 2147483646;
    display: flex;
    align-items: center;
    justify-content: center;
}

.floating-whatsapp.has-unread::after {
    content: "";
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: #ef4444;
    border: 2px solid #ffffff;
    box-sizing: border-box;
}

.floating-whatsapp img {
    max-width: 100%;
    height: auto;
    display: block;
}

.floating-whatsapp:hover, .floating-whatsapp:active, .floating-whatsapp:focus {
    background: none !important;
}

.whatsapp_inline_logo {
    height: 1em;
    width: 18px;
    display: inline-block;
    background-image: url("/tools/whatsapp_lib/inc/whatsapp_logo.png");
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;
    letter-spacing: 1em;
}

@media (max-width: 700px) {
    .g4w-setup-overlay {
        padding: 10px;
    }

    .g4w-setup-card {
        width: 100%;
        max-height: 100%;
        padding: 12px;
        border-radius: 12px;
    }

    .g4w-setup-title {
        font-size: 18px;
    }

    .g4w-setup-copy {
        padding: 10px 12px;
    }

    .g4w-setup-step {
        padding: 10px;
        border-radius: 10px;
    }

    .g4w-setup-field {
        padding: 10px;
        border-radius: 10px;
    }

    .g4w-setup-actions {
        flex-wrap: wrap;
    }

    .g4w-setup-grid {
        grid-template-columns: 1fr;
    }

    .g4w-client-files-picker {
        padding: 10px;
    }

    .g4w-client-files-picker__dialog {
        width: 100%;
        max-height: 100%;
        border-radius: 12px;
    }

    .g4w-client-files-picker__header,
    .g4w-client-files-picker__footer {
        flex-wrap: wrap;
        padding: 10px 12px;
    }

    .g4w-client-files-picker__status,
    .g4w-client-files-picker__categories,
    .g4w-client-files-picker__list {
        margin-top: 0;
        padding-left: 16px;
        padding-right: 16px;
    }

    .g4w-client-files-picker__list {
        margin: 12px;
    }

    .g4w-client-files-picker__title {
        font-size: 15px;
    }

    .g4w-client-files-table th,
    .g4w-client-files-table td {
        padding: 9px 10px;
        font-size: 12px;
    }

    .g4w-client-files-table__uploaded {
        width: 120px;
        white-space: normal;
    }

    .g4w-client-files-picker__actions {
        width: 100%;
        justify-content: flex-end;
    }
}
