#ruby-widget-root {
    /* Default matches .backtotop-wrap on landing theme (#6c3beb); overridden by JS from back-to-top */
    --ruby-primary: var(--td-primary, #6c3beb);
    --ruby-primary-dark: color-mix(in srgb, var(--ruby-primary) 78%, #000);
    --ruby-primary-light: color-mix(in srgb, var(--ruby-primary) 72%, #fff);
    --ruby-glow: color-mix(in srgb, var(--ruby-primary) 42%, transparent);
    --ruby-accent-soft: color-mix(in srgb, var(--ruby-primary) 28%, transparent);
    --ruby-accent-border: color-mix(in srgb, var(--ruby-primary) 40%, transparent);
    --ruby-launcher-bg: var(--ruby-primary);
    --ruby-user-bubble-bg: linear-gradient(135deg, var(--ruby-primary), var(--ruby-primary-dark));
    --ruby-surface: #0f172a;
    --ruby-surface-2: #1e293b;
    --ruby-text: #f8fafc;
    --ruby-muted: #94a3b8;
}

#ruby-widget-root {
    position: fixed;
    z-index: 2147483000;
    right: 22px;
    bottom: 22px;
    font-family: inherit;
    pointer-events: none;
}

#ruby-widget-root .ruby-launcher,
#ruby-widget-root .ruby-panel,
#ruby-widget-root.is-open {
    pointer-events: auto;
}

.ruby-widget-root .ruby-launcher {
    pointer-events: auto;
}

.ruby-widget-root .ruby-panel {
    pointer-events: auto;
}

.ruby-launcher {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--ruby-launcher-bg);
    box-shadow: 0 12px 40px var(--ruby-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.ruby-launcher:hover {
    transform: scale(1.06);
    box-shadow: 0 16px 48px var(--ruby-glow);
}

.ruby-launcher img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.ruby-launcher-fallback {
    font-size: 1.35rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
}

.ruby-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: min(400px, calc(100vw - 32px));
    height: min(640px, calc(100vh - 100px));
    background: linear-gradient(165deg, #1a1f35 0%, var(--ruby-surface) 45%, #0b1020 100%);
    border-radius: 22px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s ease, visibility 0.28s ease;
    z-index: 1;
}

.ruby-panel.is-open,
#ruby-widget-root.is-open .ruby-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.ruby-header {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(90deg, var(--ruby-accent-soft), transparent);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ruby-header img {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.ruby-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--ruby-text);
}

.ruby-header small {
    display: block;
    color: var(--ruby-muted);
    font-size: 0.72rem;
}

.ruby-header-actions {
    margin-left: auto;
    display: flex;
    gap: 6px;
}

.ruby-icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--ruby-text);
    cursor: pointer;
    font-size: 14px;
}

.ruby-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ruby-msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--ruby-text);
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

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

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

.ruby-msg strong {
    font-weight: 700;
}

.ruby-msg em {
    font-style: italic;
    opacity: 0.95;
}

.ruby-msg-list {
    margin: 0.35em 0 0.75em;
    padding-left: 1.35em;
    list-style-position: outside;
}

.ruby-msg-list li {
    margin-bottom: 0.5em;
    line-height: 1.5;
    padding-left: 0.15em;
}

.ruby-msg-list li:last-child {
    margin-bottom: 0;
}

.ruby-msg-list--bullet {
    list-style-type: disc;
}

.ruby-msg--assistant strong {
    color: #f1f5f9;
}

.ruby-msg--assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.07);
    border-bottom-left-radius: 4px;
}

.ruby-msg--user {
    align-self: flex-end;
    background: var(--ruby-user-bubble-bg);
    border-bottom-right-radius: 4px;
}

.ruby-msg--system {
    align-self: center;
    background: rgba(251, 191, 36, 0.12);
    color: #fde68a;
    font-size: 0.8rem;
    max-width: 95%;
    text-align: center;
}

.ruby-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 8px;
}

.ruby-quick button {
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--ruby-muted);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.72rem;
    cursor: pointer;
}

.ruby-quick button:hover {
    border-color: var(--ruby-primary);
    color: var(--ruby-text);
}

.ruby-verify {
    margin: 0 16px 10px;
    padding: 12px;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px dashed var(--ruby-accent-border);
}

.ruby-verify h5 {
    margin: 0 0 8px;
    font-size: 0.8rem;
    color: var(--ruby-primary-light);
}

.ruby-verify-note {
    margin: 0 0 10px;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--ruby-muted);
}

.ruby-verify input {
    width: 100%;
    margin-bottom: 6px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.25);
    color: var(--ruby-text);
    font-size: 0.82rem;
}

.ruby-verify button {
    width: 100%;
    margin-top: 4px;
    padding: 8px;
    border: none;
    border-radius: 10px;
    background: var(--ruby-primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.ruby-compose {
    padding: 12px 14px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.2);
}

.ruby-speech-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.ruby-speech-lang-wrap {
    flex: 1;
    min-width: 140px;
    margin: 0;
}

.ruby-speech-lang {
    width: 100%;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background-color: var(--ruby-surface-2, #1e293b);
    color: var(--ruby-text, #f8fafc);
    font-size: 0.78rem;
    cursor: pointer;
    color-scheme: dark;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23f8fafc' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.ruby-speech-lang:focus {
    outline: none;
    border-color: var(--ruby-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--ruby-primary) 35%, transparent);
}

#ruby-widget-root .ruby-speech-lang option,
.ruby-speech-lang option {
    background-color: #0f172a;
    color: #f8fafc;
}

#ruby-widget-root .ruby-speech-lang option:checked,
.ruby-speech-lang option:checked {
    background-color: var(--ruby-primary, #6c3beb);
    color: #fff;
}

.ruby-speech-status {
    flex: 1;
    min-width: 80px;
    font-size: 0.72rem;
    color: var(--ruby-muted);
    text-align: right;
}

.ruby-speech-bar .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.ruby-compose-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ruby-compose textarea {
    flex: 1;
    resize: none;
    min-height: 42px;
    max-height: 100px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--ruby-text);
    font-size: 0.88rem;
}

.ruby-compose textarea:focus {
    outline: none;
    border-color: var(--ruby-primary);
}

.ruby-send,
.ruby-mic {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    color: #fff;
}

.ruby-send {
    background: linear-gradient(135deg, var(--ruby-primary), var(--ruby-primary-dark));
}

.ruby-mic {
    background: rgba(255, 255, 255, 0.1);
}

.ruby-mic.is-recording {
    background: #dc2626;
    animation: ruby-pulse 1s infinite;
}

@keyframes ruby-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
    50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

.ruby-typing {
    padding: 4px 16px 8px;
    font-size: 0.75rem;
    color: var(--ruby-muted);
    display: none;
}

.ruby-typing.is-visible {
    display: block;
}

.ruby-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.62);
    backdrop-filter: blur(6px);
    z-index: 2147483647 !important;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px 12px;
    isolation: isolate;
}

.ruby-modal-backdrop.is-open {
    display: flex;
}

/* Gift-style wrapper (inspired by promotional card UI) */
.ruby-modal-gift-shell {
    position: relative;
    width: min(392px, 94vw);
    padding-top: 30px;
    animation: ruby-modal-in 0.35s ease;
}

@keyframes ruby-modal-in {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ruby-modal-gift-bow {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    width: 58px;
    height: 58px;
    border-radius: 18px;
    background: linear-gradient(145deg, #7dd3fc 0%, #38bdf8 55%, #2563eb 100%);
    border: 3px solid #fff;
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ruby-modal-gift-emoji {
    font-size: 1.65rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.ruby-modal-top-icon {
    display: block;
    width: 28px;
    height: 28px;
    color: #ffffff;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.ruby-modal-top-icon--call {
    stroke: #ffffff;
}

.ruby-modal.ruby-modal--gift {
    position: relative;
    overflow: hidden;
    width: 100%;
    padding: 38px 22px 20px;
    border-radius: 28px;
    border: 2px solid rgba(255, 255, 255, 0.75);
    background: linear-gradient(165deg, #ecfdf5 0%, #d1fae5 38%, #bae6fd 100%);
    box-shadow:
        0 28px 70px rgba(15, 23, 42, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    color: #0f172a;
}

.ruby-modal--supervisor.ruby-modal--gift {
    background: linear-gradient(165deg, #eff6ff 0%, #dbeafe 40%, #e0e7ff 100%);
}

.ruby-modal-card-deco {
    position: absolute;
    right: 8px;
    bottom: 56px;
    width: 92px;
    height: 58px;
    border-radius: 12px;
    background: linear-gradient(135deg, #6ee7b7 0%, #34d399 100%);
    border: 2px solid rgba(255, 255, 255, 0.55);
    box-shadow: 0 12px 28px rgba(16, 185, 129, 0.35);
    transform: rotate(-8deg);
    pointer-events: none;
    z-index: 0;
}

.ruby-modal-card-deco::before,
.ruby-modal-card-deco::after {
    content: '';
    position: absolute;
    left: 14px;
    height: 6px;
    border-radius: 4px;
    background: rgba(15, 23, 42, 0.22);
}

.ruby-modal-card-deco::before {
    top: 34px;
    width: 52px;
}

.ruby-modal-card-deco::after {
    top: 44px;
    width: 36px;
    opacity: 0.65;
}

.ruby-modal-card-chip {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 18px;
    height: 14px;
    border-radius: 3px;
    background: linear-gradient(135deg, #cbd5e1, #94a3b8);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.ruby-modal-sparkle {
    position: absolute;
    font-size: 1rem;
    color: rgba(37, 99, 235, 0.35);
    pointer-events: none;
    z-index: 0;
}

.ruby-modal-sparkle--1 {
    top: 52px;
    left: 14px;
}

.ruby-modal-sparkle--2 {
    top: 72px;
    right: 108px;
    color: rgba(16, 185, 129, 0.45);
}

.ruby-modal-head {
    position: relative;
    z-index: 1;
    text-align: center;
    margin-bottom: 16px;
}

.ruby-modal-head h4,
.ruby-modal.ruby-modal--gift .ruby-modal-head h4,
.ruby-modal-backdrop .ruby-modal-head h4 {
    margin: 0 0 6px;
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #0f172a !important;
    text-shadow: none !important;
    -webkit-text-fill-color: #0f172a !important;
}

.ruby-modal-sub,
.ruby-modal.ruby-modal--gift .ruby-modal-sub {
    margin: 0;
    font-size: 0.88rem;
    font-weight: 500;
    color: #334155 !important;
    line-height: 1.45;
    -webkit-text-fill-color: #334155 !important;
}

.ruby-modal-body {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ruby-modal-field {
    display: block;
    margin: 0;
}

.ruby-modal-field-label,
.ruby-modal.ruby-modal--gift .ruby-modal-field-label {
    display: block;
    margin: 0 0 5px 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #1e293b !important;
    -webkit-text-fill-color: #1e293b !important;
}

.ruby-modal-field input,
.ruby-modal-field select,
.ruby-modal-field textarea,
.ruby-modal.ruby-modal--gift .ruby-modal-field input,
.ruby-modal.ruby-modal--gift .ruby-modal-field select,
.ruby-modal.ruby-modal--gift .ruby-modal-field textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 16px;
    border-radius: 999px;
    border: 2px solid rgba(15, 23, 42, 0.22);
    background: #ffffff !important;
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.35;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ruby-modal-field textarea {
    border-radius: 20px;
    resize: vertical;
    min-height: 72px;
}

.ruby-modal-field input::placeholder,
.ruby-modal-field textarea::placeholder {
    color: #64748b !important;
    opacity: 1;
}

.ruby-modal-field select option {
    color: #0f172a;
    background: #fff;
}

.ruby-modal-field input:focus,
.ruby-modal-field select:focus,
.ruby-modal-field textarea:focus {
    outline: none;
    border-color: var(--ruby-primary, #6c3beb);
    box-shadow:
        0 0 0 3px color-mix(in srgb, var(--ruby-primary, #6c3beb) 22%, transparent),
        0 6px 18px rgba(15, 23, 42, 0.08);
}

.ruby-modal-field select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

.ruby-modal-field:nth-child(3) input {
    background: #f0fdf4;
    border-color: rgba(16, 185, 129, 0.28);
}

.ruby-modal-actions {
    position: relative;
    z-index: 2;
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.ruby-modal-actions button {
    flex: 1;
    padding: 12px 16px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ruby-modal-actions button:hover {
    transform: translateY(-1px);
}

.ruby-modal-actions .primary {
    background: var(--ruby-launcher-bg, linear-gradient(90deg, var(--ruby-primary, #6c3beb), color-mix(in srgb, var(--ruby-primary, #6c3beb) 70%, #fff)));
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    box-shadow: 0 8px 24px color-mix(in srgb, var(--ruby-primary, #6c3beb) 40%, transparent);
}

.ruby-modal-actions .ghost {
    background: rgba(255, 255, 255, 0.95);
    color: #1e293b !important;
    -webkit-text-fill-color: #1e293b !important;
    border: 2px solid rgba(15, 23, 42, 0.18);
}

@media (max-width: 768px) {
    .ruby-modal-backdrop {
        z-index: 2147483647 !important;
        align-items: center;
        justify-content: center;
        padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
    }

    .ruby-modal-gift-shell {
        width: min(392px, 100%);
        max-height: min(90vh, calc(100dvh - 24px));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .ruby-modal.ruby-modal--gift {
        max-height: inherit;
    }

    /* Keep pop-ups above the chat panel & launcher on mobile */
    body.ruby-modal-open #ruby-widget-root {
        z-index: 2147482000 !important;
    }

    body.ruby-modal-open #ruby-widget-root .ruby-panel,
    body.ruby-modal-open #ruby-widget-root .ruby-launcher {
        pointer-events: none !important;
    }
}

@media (max-width: 480px) {
    #ruby-widget-root {
        right: 12px;
        bottom: 12px;
    }
    .ruby-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 88px);
    }

    .ruby-modal-gift-shell {
        width: 100%;
    }
}
