/**
 * Pass Plus S.O.M. Chat Widget Styles
 * Modern chat bubble in bottom right corner
 */

:root {
    --pp-primary: #5f3790;
    --pp-primary-dark: #4a2b70;
    --pp-bg: #ffffff;
    --pp-surface: #ffffff;
    --pp-muted: #f9fafb;
    --pp-text: #111827;
    --pp-text-muted: #374151;
    --pp-border: #e5e7eb;
    --pp-user-bubble: var(--pp-primary);
    --pp-bot-bubble: #ffffff;
    --pp-header-gradient: linear-gradient(135deg, var(--pp-primary) 0%, var(--pp-primary-dark) 100%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --pp-bg: #0b1220;
        --pp-surface: #0f172a;
        --pp-muted: #0b1220;
        --pp-text: #e5e7eb;
        --pp-text-muted: #cbd5e1;
        --pp-border: #1f2937;
        --pp-bot-bubble: #111827;
    }
}

/* Chat Bubble (always visible) */
.ppsom-chat-bubble {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
    right: calc(env(safe-area-inset-right, 0px) + 24px);
    width: 60px;
    height: 60px;
    background: var(--pp-header-gradient);
    border-radius: 50%;
    box-shadow: 0 4px 24px rgba(37, 99, 235, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2147483647; /* ensure above any overlays */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: ppsom-bubble-appear 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.ppsom-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 32px rgba(37, 99, 235, 0.5);
}

.ppsom-chat-bubble.ppsom-bubble-hidden {
    transform: scale(0);
    opacity: 0;
}

@keyframes ppsom-bubble-appear {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.ppsom-bubble-icon {
    width: 28px;
    height: 28px;
    color: white;
}

/* Notification Badge */
.ppsom-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 3px solid white;
    animation: ppsom-badge-pulse 2s infinite;
}

@keyframes ppsom-badge-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

/* Chat Window */
.ppsom-chat-window {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
    right: calc(env(safe-area-inset-right, 0px) + 24px);
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 48px);
    background: var(--pp-surface);
    border-radius: 16px;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.2);
    z-index: 2147483647; /* ensure above any overlays */
    display: flex;
    flex-direction: column;
    transform: scale(0) translateY(20px);
    transform-origin: bottom right;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, opacity;
    backface-visibility: hidden;
}

.ppsom-chat-window.ppsom-chat-open {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Chat Header */
.ppsom-chat-header {
    background: var(--pp-header-gradient);
    color: white;
    padding: 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ppsom-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ppsom-chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ppsom-chat-avatar svg {
    width: 24px;
    height: 24px;
}

.ppsom-chat-title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 2px;
}

.ppsom-chat-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ppsom-status-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: ppsom-status-pulse 2s infinite;
}

@keyframes ppsom-status-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.ppsom-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ppsom-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.ppsom-chat-close svg {
    width: 18px;
    height: 18px;
    color: white;
}

/* Messages Area */
.ppsom-chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--pp-muted);
}

.ppsom-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ppsom-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ppsom-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.ppsom-message {
    display: flex;
    animation: ppsom-message-appear 0.3s ease;
}

@keyframes ppsom-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ppsom-message-bot {
    justify-content: flex-start;
}

.ppsom-message-user {
    justify-content: flex-end;
}

.ppsom-message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.ppsom-message-bot .ppsom-message-bubble {
    background: var(--pp-bot-bubble);
    color: var(--pp-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.ppsom-message-user .ppsom-message-bubble {
    background: var(--pp-user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Input Area */
.ppsom-chat-input-area {
    padding: 16px;
    border-top: 1px solid var(--pp-border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: var(--pp-surface);
    border-radius: 0 0 16px 16px;
}

.ppsom-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--pp-border);
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    color: var(--pp-text) !important;
    background: var(--pp-surface) !important;
    -webkit-text-fill-color: var(--pp-text);
    caret-color: var(--pp-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}
 
.ppsom-chat-input:focus {
    outline: none;
    border-color: var(--pp-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
 
/* Ensure visibility on Chrome/Safari autofill */
.ppsom-chat-input:-webkit-autofill,
.ppsom-chat-input:-webkit-autofill:hover,
.ppsom-chat-input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--pp-text) !important;
    transition: background-color 9999s ease-in-out 0s;
    box-shadow: 0 0 0px 1000px var(--pp-surface) inset !important;
    background-clip: padding-box;
}

.ppsom-send-button {
    width: 44px;
    height: 44px;
    background: var(--pp-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ppsom-send-button:hover {
    background: var(--pp-primary-dark);
    transform: scale(1.05);
}

.ppsom-send-button:active {
    transform: scale(0.95);
}

.ppsom-send-button svg {
    width: 20px;
    height: 20px;
    color: white;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .ppsom-chat-window {
        /* Bottom sheet that fits the screen with equal margins */
        left: calc(env(safe-area-inset-left, 0px) + 12px);
        right: calc(env(safe-area-inset-right, 0px) + 12px);
        width: auto; /* override fixed width */
        max-width: none;
        height: min(60dvh, calc(100vh - 56px));
        max-height: none;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
        transform: translateY(16px); /* start slightly lowered, no horizontal shift */
        opacity: 0;
        border-radius: 14px;
    }

    .ppsom-chat-bubble {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
        right: calc(env(safe-area-inset-right, 0px) + 18px);
        width: 52px;
        height: 52px;
    }

    .ppsom-bubble-icon {
        width: 22px;
        height: 22px;
    }

    .ppsom-message-bubble {
        max-width: 88%;
    }

    /* Prevent iOS zoom on focus */
    .ppsom-chat-input {
        font-size: 16px;
    }

    /* When open on phones, slide up only (no scale, no horizontal shift) */
    .ppsom-chat-window.ppsom-chat-open {
        transform: translateY(0);
        opacity: 1;
    }

    /* Compact spacing and safe-area padding on phones */
    .ppsom-chat-header {
        padding: 12px;
    }
    .ppsom-chat-title {
        font-size: 14px;
    }
    .ppsom-chat-messages {
        padding: 12px;
    }
    .ppsom-chat-input-area {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        border-radius: 0 0 14px 14px;
    }
}

/* Tablet */
@media (max-width: 768px) and (min-width: 481px) {
    .ppsom-chat-window {
        width: 360px;
        height: 500px;
    }
}


/* Improve placeholder visibility */
.ppsom-chat-input::placeholder {
    color: #9ca3af; /* slate-400 */
    opacity: 1;
}

/* Hide old widget WINDOW on mobile (but keep bubble) */
@media (max-width: 768px) {
    .ppsom-chat-window {
        display: none !important;
    }
    /* Keep the bubble visible - it will trigger ChatKit instead */
    .ppsom-chat-bubble {
        display: flex !important;
    }
}

/* Hide ChatKit on desktop (old widget will be used) */
@media (min-width: 769px) {
    #chatkit-container {
        display: none !important;
    }
}

/* ChatKit Mobile Portrait Sizing */
@media (max-width: 768px) and (orientation: portrait) {
    #chatkit-container {
        position: fixed !important;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 8px) !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 65vh !important;
        max-height: min(65vh, calc(100vh - 80px)) !important;
        z-index: 2147483646 !important; /* Below bubble */
        display: none; /* Hidden by default */
    }

    /* ChatKit chat window on mobile portrait */
    #chatkit-container > div,
    #chatkit-container iframe {
        width: 100% !important;
        height: 100% !important;
        border-radius: 16px 16px 0 0 !important;
    }

    /* Make sure bubble stays on top */
    .ppsom-chat-bubble {
        z-index: 2147483647 !important;
    }
}

/* ChatKit Mobile Landscape Sizing */
@media (max-width: 768px) and (orientation: landscape) {
    #chatkit-container {
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        width: 380px !important;
        height: 500px !important;
        max-height: calc(100vh - 40px) !important;
        z-index: 2147483646 !important; /* Below bubble */
        display: none; /* Hidden by default */
    }

    /* Ensure bubble stays on top in landscape too */
    .ppsom-chat-bubble {
        z-index: 2147483647 !important;
    }
}

/* Hide legacy widget window on short-height screens (mobile landscape) */
@media (max-height: 500px) {
    .ppsom-chat-window {
        display: none !important;
    }
}


/*
 * Pass Plus S.O.M. Chat Widget Styles
 * Modern chat bubble in bottom right corner
 */

:root {
    --pp-primary: #5f3790;
    --pp-primary-dark: #4a2b70;
    --pp-bg: #ffffff;
    --pp-surface: #ffffff;
    --pp-muted: #f9fafb;
    --pp-text: #111827;
    --pp-text-muted: #374151;
    --pp-border: #e5e7eb;
    --pp-user-bubble: var(--pp-primary);
    --pp-bot-bubble: #ffffff;
    --pp-header-gradient: linear-gradient(135deg, var(--pp-primary) 0%, var(--pp-primary-dark) 100%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --pp-bg: #0b1220;
        --pp-surface: #0f172a;
        --pp-muted: #0b1220;
        --pp-text: #e5e7eb;
        --pp-text-muted: #cbd5e1;
        --pp-border: #1f2937;
        --pp-bot-bubble: #111827;
    }
}

/* Chat Bubble (always visible) */
.ppsom-chat-bubble {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
    right: calc(env(safe-area-inset-right, 0px) + 24px);
    width: 60px;
    height: 60px;
    background: var(--pp-header-gradient);
    border-radius: 50%;
    box-shadow: 0 4px 24px rgba(37, 99, 235, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2147483647; /* ensure above any overlays */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: ppsom-bubble-appear 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.ppsom-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 32px rgba(37, 99, 235, 0.5);
}

.ppsom-chat-bubble.ppsom-bubble-hidden {
    transform: scale(0);
    opacity: 0;
}

@keyframes ppsom-bubble-appear {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.ppsom-bubble-icon {
    width: 28px;
    height: 28px;
    color: white;
}

/* Notification Badge */
.ppsom-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 3px solid white;
    animation: ppsom-badge-pulse 2s infinite;
}

@keyframes ppsom-badge-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

/* Chat Window */
.ppsom-chat-window {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
    right: calc(env(safe-area-inset-right, 0px) + 24px);
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 48px);
    background: var(--pp-surface);
    border-radius: 16px;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.2);
    z-index: 2147483647; /* ensure above any overlays */
    display: flex;
    flex-direction: column;
    transform: scale(0) translateY(20px);
    transform-origin: bottom right;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, opacity;
    backface-visibility: hidden;
}

.ppsom-chat-window.ppsom-chat-open {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Chat Header */
.ppsom-chat-header {
    background: var(--pp-header-gradient);
    color: white;
    padding: 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ppsom-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ppsom-chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ppsom-chat-avatar svg {
    width: 24px;
    height: 24px;
}

.ppsom-chat-title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 2px;
}

.ppsom-chat-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ppsom-status-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: ppsom-status-pulse 2s infinite;
}

@keyframes ppsom-status-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.ppsom-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ppsom-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.ppsom-chat-close svg {
    width: 18px;
    height: 18px;
    color: white;
}

/* Messages Area */
.ppsom-chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--pp-muted);
}

.ppsom-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ppsom-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ppsom-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.ppsom-message {
    display: flex;
    animation: ppsom-message-appear 0.3s ease;
}

@keyframes ppsom-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ppsom-message-bot {
    justify-content: flex-start;
}

.ppsom-message-user {
    justify-content: flex-end;
}

.ppsom-message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.ppsom-message-bot .ppsom-message-bubble {
    background: var(--pp-bot-bubble);
    color: var(--pp-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.ppsom-message-user .ppsom-message-bubble {
    background: var(--pp-user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Input Area */
.ppsom-chat-input-area {
    padding: 16px;
    border-top: 1px solid var(--pp-border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: var(--pp-surface);
    border-radius: 0 0 16px 16px;
}

.ppsom-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--pp-border);
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    color: var(--pp-text) !important;
    background: var(--pp-surface) !important;
    -webkit-text-fill-color: var(--pp-text);
    caret-color: var(--pp-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}
 
.ppsom-chat-input:focus {
    outline: none;
    border-color: var(--pp-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
 
/* Ensure visibility on Chrome/Safari autofill */
.ppsom-chat-input:-webkit-autofill,
.ppsom-chat-input:-webkit-autofill:hover,
.ppsom-chat-input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--pp-text) !important;
    transition: background-color 9999s ease-in-out 0s;
    box-shadow: 0 0 0px 1000px var(--pp-surface) inset !important;
    background-clip: padding-box;
}

.ppsom-send-button {
    width: 44px;
    height: 44px;
    background: var(--pp-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ppsom-send-button:hover {
    background: var(--pp-primary-dark);
    transform: scale(1.05);
}

.ppsom-send-button:active {
    transform: scale(0.95);
}

.ppsom-send-button svg {
    width: 20px;
    height: 20px;
    color: white;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .ppsom-chat-window {
        /* Bottom sheet that fits the screen with equal margins */
        left: calc(env(safe-area-inset-left, 0px) + 12px);
        right: calc(env(safe-area-inset-right, 0px) + 12px);
        width: auto; /* override fixed width */
        max-width: none;
        height: min(60dvh, calc(100vh - 56px));
        max-height: none;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
        transform: translateY(16px); /* start slightly lowered, no horizontal shift */
        opacity: 0;
        border-radius: 14px;
    }

    .ppsom-chat-bubble {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
        right: calc(env(safe-area-inset-right, 0px) + 18px);
        width: 52px;
        height: 52px;
    }

    .ppsom-bubble-icon {
        width: 22px;
        height: 22px;
    }

    .ppsom-message-bubble {
        max-width: 88%;
    }

    /* Prevent iOS zoom on focus */
    .ppsom-chat-input {
        font-size: 16px;
    }

    /* When open on phones, slide up only (no scale, no horizontal shift) */
    .ppsom-chat-window.ppsom-chat-open {
        transform: translateY(0);
        opacity: 1;
    }

    /* Compact spacing and safe-area padding on phones */
    .ppsom-chat-header {
        padding: 12px;
    }
    .ppsom-chat-title {
        font-size: 14px;
    }
    .ppsom-chat-messages {
        padding: 12px;
    }
    .ppsom-chat-input-area {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        border-radius: 0 0 14px 14px;
    }
}

/* Tablet */
@media (max-width: 768px) and (min-width: 481px) {
    .ppsom-chat-window {
        width: 360px;
        height: 500px;
    }
}


/* Improve placeholder visibility */
.ppsom-chat-input::placeholder {
    color: #9ca3af; /* slate-400 */
    opacity: 1;
}

/* Hide old widget WINDOW on mobile (but keep bubble) */
@media (max-width: 768px) {
    .ppsom-chat-window {
        display: none !important;
    }
    /* Keep the bubble visible - it will trigger ChatKit instead */
    .ppsom-chat-bubble {
        display: flex !important;
    }
}

/* Hide ChatKit on desktop (old widget will be used) */
@media (min-width: 769px) {
    #chatkit-container {
        display: none !important;
    }
}

/* ChatKit Mobile Portrait Sizing */
@media (max-width: 768px) and (orientation: portrait) {
    #chatkit-container {
        position: fixed !important;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 8px) !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 65vh !important;
        max-height: min(65vh, calc(100vh - 80px)) !important;
        z-index: 2147483646 !important; /* Below bubble */
        display: none; /* Hidden by default */
    }

    /* ChatKit chat window on mobile portrait */
    #chatkit-container > div,
    #chatkit-container iframe {
        width: 100% !important;
        height: 100% !important;
        border-radius: 16px 16px 0 0 !important;
    }

    /* Make sure bubble stays on top */
    .ppsom-chat-bubble {
        z-index: 2147483647 !important;
    }
}

/* ChatKit Mobile Landscape Sizing */
@media (max-width: 768px) and (orientation: landscape) {
    #chatkit-container {
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        width: 380px !important;
        height: 500px !important;
        max-height: calc(100vh - 40px) !important;
        z-index: 2147483646 !important; /* Below bubble */
        display: none; /* Hidden by default */
    }

    /* Ensure bubble stays on top in landscape too */
    .ppsom-chat-bubble {
        z-index: 2147483647 !important;
    }
}

/* Hide legacy widget window on short-height screens (mobile landscape) */
@media (max-height: 500px) {
    .ppsom-chat-window {
        display: none !important;
    }
}

/* Chat widget visibility - show bubble on mobile, hide window on mobile (redirects to chat page) */
@media (max-width: 768px) {
  .ppsom-chat-bubble {
    display: flex !important;
  }
  .ppsom-chat-window {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .ppsom-chat-bubble {
    display: flex !important;
  }
  .ppsom-chat-window {
    display: flex !important;
  }
}

/* Portrait visibility overrides for test/static pages */
@media (max-width: 480px) {
  body[data-test-chat="1"] .ppsom-chat-window {
    /* Make the window taller on small phones so it’s clearly visible */
    height: min(80dvh, calc(100dvh - 56px)) !important;
    max-height: none !important;
  }
}

@media (max-width: 768px) and (orientation: portrait) {
  body[data-test-chat="1"] #chatkit-container {
    /* If ChatKit is used in tests, make it taller in portrait */
    height: 80vh !important;
    max-height: min(80vh, calc(100vh - 80px)) !important;
  }
}


/* --- iMessage-like input bar sizing (scoped override, appended) --- */
.ppsom-chat-input-area {
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
    align-items: center;
    box-shadow: 0 -6px 18px rgba(0,0,0,0.12);
}
.ppsom-chat-input {
    padding: 14px 16px;
    min-height: 52px;
    font-size: 16px;
    line-height: 22px;
    border-radius: 28px;
}
.ppsom-chat-input::placeholder { color: var(--pp-text-muted); opacity: 0.7; }
.ppsom-send-button { width: 52px; height: 52px; }
.ppsom-send-button svg { width: 22px; height: 22px; }

@media (max-width: 480px) {
  .ppsom-chat-input { min-height: 56px; font-size: 17px; }
  .ppsom-send-button { width: 48px; height: 48px; }
  .ppsom-send-button svg { width: 22px; height: 22px; }
  .ppsom-chat-input-area { gap: 8px; padding-left: 10px; padding-right: 10px; }
}


/* --- Full-screen chat page: make bubbles feel like the floating chat widget (roomier) --- */
.ppsom-chat-messages { padding: 18px 16px; gap: 14px; }
.ppsom-message-bubble { line-height: 1.55; }
@media (max-width: 480px) {
  .ppsom-message-bubble { max-width: 92%; font-size: 16px; padding: 14px 16px; }
}


/* --- Message-app feel enhancements --- */
.ppsom-message-bot .ppsom-message-bubble {
  background: var(--pp-bot-bubble);
  color: var(--pp-text);
  border-radius: 20px 20px 20px 8px; /* subtle tail on left */
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.ppsom-message-user .ppsom-message-bubble {
  background: var(--pp-user-bubble);
  color: #fff;
  border-radius: 20px 20px 8px 20px; /* subtle tail on right */
}


/* --- Make input span full width; place send button inside the pill on the right --- */
.ppsom-chat-input-area { position: relative; display: block; }
.ppsom-chat-input { width: calc(100% - 8px); margin: 0 auto; display: block; padding-right: 72px; }
.ppsom-send-button { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); }
@media (max-width: 480px) {
  .ppsom-chat-input { padding-right: 68px; width: calc(100% - 8px); }
  .ppsom-send-button { right: 12px; }
}

/* Sender labels and clearer differentiation */
/* Place small labels on bubbles so it's obvious who replied */
.ppsom-message-bubble { position: relative; }
.ppsom-message-user .ppsom-message-bubble::after,
.ppsom-message-bot .ppsom-message-bubble::after {
  content: attr(data-label);
  position: absolute;
  top: 6px; /* inside bubble to avoid overlapping previous messages */
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0.9;
}
/* Fallback content if data-label is not set via JS/HTML */
.ppsom-message-user .ppsom-message-bubble::after { content: 'You'; right: 10px; color: #fff; background: rgba(95,55,144,0.9); box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.ppsom-message-bot .ppsom-message-bubble::after { content: 'Pass Plus'; left: 10px; color: #111827; background: rgba(255,255,255,0.9); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }

/* Add a bit more top padding so label fits neatly */
.ppsom-message-bubble { padding-top: 18px; }

/* Increase contrast subtly between user and bot bubbles */
.ppsom-message-bot .ppsom-message-bubble {
  border: 1px solid var(--pp-border);
}
.ppsom-message-user .ppsom-message-bubble {
  background-image: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(0,0,0,0.06));
}

/* Ensure labels remain readable in dark mode */
@media (prefers-color-scheme: dark) {
  .ppsom-message-bot .ppsom-message-bubble::after { color: #0b1220; background: rgba(255,255,255,0.9); }
  .ppsom-message-user .ppsom-message-bubble::after { color: #fff; background: rgba(129,62,242,0.9); }
}


/* Stronger differentiation: vivid user bubble color and visible speech tails */
/* Make user replies pop more so it's obvious which message is yours */
.ppsom-message-user .ppsom-message-bubble {
  background-color: #813ef2; /* brighter purple for clear contrast */
  color: #fff;
}

/* Add subtle speech tails pointing to sender side */
.ppsom-message-bot .ppsom-message-bubble,
.ppsom-message-user .ppsom-message-bubble { position: relative; }

.ppsom-message-bot .ppsom-message-bubble::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 18px;
  width: 0; height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 6px solid var(--pp-bot-bubble);
}

.ppsom-message-user .ppsom-message-bubble::before {
  content: "";
  position: absolute;
  right: -6px;
  top: 18px;
  width: 0; height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 6px solid #813ef2;
}

/* Keep things readable in dark mode as well */
@media (prefers-color-scheme: dark) {
  .ppsom-message-bot .ppsom-message-bubble::before { border-right-color: var(--pp-bot-bubble); }
  .ppsom-message-user .ppsom-message-bubble::before { border-left-color: #813ef2; }
}

/* --- iMessage-like theme and grouping --- */
/* Colors: iOS blue for user, soft gray for bot */
:root {
  --pp-imessage-blue: #0a84ff;
  --pp-imessage-gray: #e9edf1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --pp-imessage-blue: #0a84ff;
    --pp-imessage-gray: #1f2937;
  }
}

/* Base bubble colors to match iMessage */
.ppsom-message-user .ppsom-message-bubble {
  background-color: var(--pp-imessage-blue) !important;
  background-image: none !important;
}
.ppsom-message-bot .ppsom-message-bubble {
  background: var(--pp-imessage-gray) !important;
  color: var(--pp-text) !important;
}

/* Softer page/message area like Messages */
.ppsom-chat-messages {
  background: #f5f7fb;
}
@media (prefers-color-scheme: dark) {
  .ppsom-chat-messages { background: #0b1220; }
}

/* Show sender chips for clear message distinction */
.ppsom-message-user .ppsom-message-bubble::after,
.ppsom-message-bot .ppsom-message-bubble::after { display: block !important; }

/* Grouping shapes: single, mid, end; only last shows tail */
.ppsom-message-bubble { border-radius: 20px; margin-top: 8px; margin-bottom: 8px; }
.ppsom-message-user .ppsom-message-bubble.ppsom-group-single { border-radius: 20px 20px 8px 20px; }
.ppsom-message-user .ppsom-message-bubble.ppsom-group-mid    { border-radius: 20px 20px 8px 8px; }
.ppsom-message-user .ppsom-message-bubble.ppsom-group-end    { border-radius: 20px 20px 8px 20px; }

.ppsom-message-bot .ppsom-message-bubble.ppsom-group-single  { border-radius: 20px 20px 20px 8px; }
.ppsom-message-bot .ppsom-message-bubble.ppsom-group-mid     { border-radius: 20px 8px 8px 8px; }
.ppsom-message-bot .ppsom-message-bubble.ppsom-group-end     { border-radius: 20px 20px 20px 8px; }

/* Tails only for single and end bubbles */
.ppsom-message-user .ppsom-message-bubble::before { display: none; }
.ppsom-message-bot .ppsom-message-bubble::before { display: none; }
.ppsom-message-user .ppsom-message-bubble.ppsom-group-single::before,
.ppsom-message-user .ppsom-message-bubble.ppsom-group-end::before { display: block; border-left-color: var(--pp-imessage-blue); }
.ppsom-message-bot .ppsom-message-bubble.ppsom-group-single::before,
.ppsom-message-bot .ppsom-message-bubble.ppsom-group-end::before { display: block; border-right-color: var(--pp-imessage-gray); }

/* Compact vertical gaps inside groups */
.ppsom-message.ppsom-grouped { margin-top: -4px; }

/* Subtle centered time separator */
.ppsom-time-sep {
  align-self: center;
  margin: 6px 0 10px;
  font-size: 12px;
  color: #6b7280;
  background: rgba(107,114,128,0.12);
  padding: 4px 10px;
  border-radius: 999px;
}
@media (prefers-color-scheme: dark) {
  .ppsom-time-sep { color: #cbd5e1; background: rgba(203,213,225,0.12); }
}

/* Action Buttons */
.ppsom-action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding: 0 4px;
}

.ppsom-action-btn {
  background: var(--pp-primary);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(95, 55, 144, 0.2);
}

.ppsom-action-btn:hover {
  background: var(--pp-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(95, 55, 144, 0.3);
}

.ppsom-action-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(95, 55, 144, 0.2);
}

@media (prefers-color-scheme: dark) {
  .ppsom-action-btn {
    background: var(--pp-primary);
    box-shadow: 0 2px 8px rgba(95, 55, 144, 0.4);
  }

  .ppsom-action-btn:hover {
    background: var(--pp-primary-dark);
    box-shadow: 0 4px 12px rgba(95, 55, 144, 0.5);
  }
}

@media (max-width: 480px) {
  .ppsom-action-btn {
    font-size: 13px;
    padding: 8px 14px;
  }
}
