/* Resolver - Chat Widget Styles */

.rsvl-chat {
    --rsvl-accent: #0A1332;
    --rsvl-accent-hover: #363A4D;
    --rsvl-bg: #ffffff;
    --rsvl-bg-user: var(--rsvl-accent);
    --rsvl-bg-bot: #f1f5f9;
    --rsvl-text: #1a1a1a;
    --rsvl-text-user: #ffffff;
    --rsvl-text-bot: #1a1a1a;
    --rsvl-text-muted: #666666;
    --rsvl-border: #dcdcdc;
    --rsvl-border-focus: #9e9e9e;
    --rsvl-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    --rsvl-radius: 12px;
    --rsvl-panel-width: 400px;
    --rsvl-panel-height: 700px;
    --rsvl-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    position: fixed;
    z-index: 99999;
    font-family: var(--rsvl-font);
    font-weight: normal;
    letter-spacing: normal;
    -webkit-font-smoothing: auto;
    -moz-osx-font-smoothing: auto;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

    .rsvl-chat *,
    .rsvl-chat *::before,
    .rsvl-chat *::after {
        box-sizing: border-box;
    }

/* Positioning */
.rsvl-position-bottom-right {
    bottom: 40px;
    right: 40px;
}

.rsvl-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Toggle Button */
.rsvl-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--rsvl-accent);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--rsvl-shadow);
    transition: transform 0.2s;
}

    .rsvl-toggle svg {
        width: 32px;
        height: 32px;
    }

    .rsvl-toggle:hover {
        transform: scale(1.05);
    }

    .rsvl-toggle:focus-visible {
        outline: 2px solid var(--rsvl-accent);
        outline-offset: 2px;
    }

/* Panel */
.rsvl-panel {
    position: absolute;
    right: 0;
    bottom: 84px;
    width: var(--rsvl-panel-width);
    height: var(--rsvl-panel-height);
    max-height: 76vh;
    /* No background here: white under the header would show as a faint line
       along its rounded top corners. The parts below the header paint it. */
    border-radius: 12px;
    box-shadow: var(--rsvl-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.rsvl-position-bottom-right .rsvl-panel,
:host(.rsvl-position-bottom-right) .rsvl-panel {
    right: 0;
}

.rsvl-position-bottom-left .rsvl-panel,
:host(.rsvl-position-bottom-left) .rsvl-panel {
    left: 0;
    right: auto;
}

.rsvl-panel.is-admin {
    right: 0 !important;
    left: auto !important;
}

.rsvl-panel[hidden] {
    display: none;
}

.rsvl-messages,
.rsvl-input-area,
.rsvl-panel-footer {
    background: var(--rsvl-bg);
}

.rsvl-panel-footer {
    font-size: 12px;
    padding: 0 12px 12px;
    text-align: center;
}

    .rsvl-panel-footer a {
        color: var(--rsvl-text);
    }

        .rsvl-panel-footer a:hover,
        .rsvl-panel-footer a:active,
        .rsvl-panel-footer a:focus {
            text-decoration: underline;
        }

/* Header */
.rsvl-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 16px;
    background: var(--rsvl-accent);
    color: #ffffff;
    flex-shrink: 0;
}

.rsvl-bot-name {
    font-weight: 600;
    font-size: 15px;
}

.rsvl-new-chat,
.rsvl-close {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.rsvl-new-chat {
    margin-left: auto;
    padding-bottom: 1px;
}

    .rsvl-new-chat svg {
        width: 21px;
        height: 21px;
        fill: currentColor;
    }

    .rsvl-new-chat:hover,
    .rsvl-close:hover {
        opacity: 1;
    }

/* Messages Area */
.rsvl-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

    .rsvl-messages::-webkit-scrollbar {
        width: 4px;
    }

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

    .rsvl-messages::-webkit-scrollbar-thumb {
        background: var(--rsvl-border);
        border-radius: 2px;
    }

/* Messages */
.rsvl-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.rsvl-message-user {
    align-self: flex-end;
}

.rsvl-message-bot {
    align-self: flex-start;
}

/* Avatar layout — only applied when .rsvl-chat--has-avatar is present */
.rsvl-chat--has-avatar .rsvl-message-bot,
:host(.rsvl-chat--has-avatar) .rsvl-message-bot {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    max-width: 90%;
}

.rsvl-bot-avatar {
    width: 28px;
    height: 28px;
    object-fit: cover;
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 4px;
    border-radius: var(--rsvl-avatar-radius, 0);
}

.rsvl-message-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Custom toggle icon */
img.rsvl-icon-chat {
    display: block;
    width: var(--rsvl-icon-size, 28px);
    height: var(--rsvl-icon-size, 28px);
    object-fit: cover;
}

.rsvl-message-content {
    padding: 8px 14px;
    border-radius: 8px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.rsvl-message-user .rsvl-message-content {
    background: var(--rsvl-bg-user);
    color: var(--rsvl-text-user);
    border-bottom-right-radius: 0;
}

.rsvl-message-bot .rsvl-message-content {
    background: var(--rsvl-bg-bot);
    color: var(--rsvl-text-bot);
    border-bottom-left-radius: 0;
    white-space: normal;
}

    /* Markdown rendering inside bot messages */
    .rsvl-message-bot .rsvl-message-content strong {
        font-weight: 700;
    }

    .rsvl-message-bot .rsvl-message-content em {
        font-style: italic;
    }

    .rsvl-message-bot .rsvl-message-content a {
        color: var(--rsvl-accent);
        text-decoration: underline;
    }

        .rsvl-message-bot .rsvl-message-content a:hover {
            opacity: 0.8;
        }
        /* A link still streaming in, shown before its URL arrives. */
        .rsvl-message-bot .rsvl-message-content a.rsvl-link-pending:hover {
            opacity: 1;
        }

    .rsvl-message-bot .rsvl-message-content code {
        background: rgba(0, 0, 0, 0.08);
        border-radius: 3px;
        padding: 1px 5px;
        font-family: monospace;
        font-size: 0.9em;
    }

    .rsvl-message-bot .rsvl-message-content pre {
        background: rgba(0, 0, 0, 0.08);
        border-radius: 6px;
        padding: 10px 12px;
        overflow-x: auto;
        margin: 6px 0;
    }

        .rsvl-message-bot .rsvl-message-content pre code {
            background: none;
            padding: 0;
            font-size: 0.85em;
            line-height: 1.5;
        }

    .rsvl-message-bot .rsvl-message-content ul {
        list-style: disc;
    }

    .rsvl-message-bot .rsvl-message-content ul,
    .rsvl-message-bot .rsvl-message-content ol {
        margin: 4px 0;
        padding-left: 20px;
    }

    .rsvl-message-bot .rsvl-message-content li {
        margin: 2px 0;
    }

    .rsvl-message-bot .rsvl-message-content h1,
    .rsvl-message-bot .rsvl-message-content h2,
    .rsvl-message-bot .rsvl-message-content h3 {
        font-weight: 600;
        margin: 8px 0 4px;
    }

    .rsvl-message-bot .rsvl-message-content h1 {
        font-size: 1.1em;
    }

    .rsvl-message-bot .rsvl-message-content h2 {
        font-size: 1.05em;
    }

    .rsvl-message-bot .rsvl-message-content h3 {
        font-size: 1em;
    }

/* Typing indicator */
.rsvl-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 14px;
    background: var(--rsvl-bg-bot);
    border-radius: 8px;
    border-bottom-left-radius: 0;
    align-self: flex-start;
}

.rsvl-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--rsvl-text-muted);
    border-radius: 50%;
    animation: rsvl-bounce 1.4s ease-in-out infinite;
}

    .rsvl-typing-dot:nth-child(2) {
        animation-delay: 0.2s;
    }

    .rsvl-typing-dot:nth-child(3) {
        animation-delay: 0.4s;
    }

@keyframes rsvl-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-4px);
    }
}

/* Message timestamp */
.rsvl-message-time {
    font-size: 11px;
    color: var(--rsvl-text-muted);
    margin-top: 3px;
    padding: 0 2px;
}

.rsvl-message-user .rsvl-message-time {
    text-align: right;
}

/* Bot message meta row: name · time · 👍 👎 */
.rsvl-message-meta {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: 4px;
    padding: 0 2px;
}

    .rsvl-message-meta .rsvl-message-time {
        margin: 0;
        padding: 0;
    }

.rsvl-message-sender {
    font-size: 11px;
    color: var(--rsvl-text-muted);
}

.rsvl-meta-sep {
    font-size: 11px;
    color: var(--rsvl-text-muted);
    opacity: 0.4;
}

.rsvl-rate-btn {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 4px;
    background-color: var(--rsvl-bg-bot);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    transition: opacity 0.15s, transform 0.1s;
    display: inline-flex;
    align-items: center;
}

    .rsvl-rate-btn:hover {
        background-color: #DAF5E1;
    }

    .rsvl-rate-btn.rsvl-rate-down:hover {
        background-color: #FFE1DE;
    }

.rsvl-rate-btn--active {
    background-color: #DAF5E1;
}

    .rsvl-rate-btn--active.rsvl-rate-down {
        background-color: #FFE1DE;
    }

.rsvl-rate-btn svg {
    width: 10px;
    height: 10px;
    fill: currentColor;
    color: var(--rsvl-text-muted);
    display: block;
}

.rsvl-rate-btn--active svg {
    fill: #18B14E;
}

.rsvl-rate-btn--active.rsvl-rate-down svg {
    fill: #E72F22;
}

.rsvl-rate-btn:disabled {
    cursor: default;
    pointer-events: none;
}

/* Error message */
.rsvl-message-error .rsvl-message-content {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Input Area */
.rsvl-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    flex-shrink: 0;
    flex-wrap: wrap;
    position: relative;
}

/* Mobile only; the media query below shows it. */
.rsvl-scroll-bottom {
    display: none;
}

.rsvl-char-counter {
    /* Just under the message box, in the input area's bottom padding. */
    position: absolute;
    top: calc(100% + 2px);
    right: 12px;
    font-size: 10px;
    line-height: 12px;
    color: var(--rsvl-text-muted);
    pointer-events: none;
}

.rsvl-char-counter--over {
    color: #dc2626;
    font-weight: 600;
}

/* Holds the message box with the send button over its bottom right corner. */
.rsvl-composer {
    flex: 1;
    min-width: 0;
    display: flex;
    position: relative;
}

.rsvl-input {
    flex: 1 !important;
    min-width: 0;
    margin: 0 !important;
    border: 1px solid var(--rsvl-border) !important;
    /* The same corners as the chat panel. */
    border-radius: var(--rsvl-radius) !important;
    /* The top and bottom padding would center one line of text on the 32px
       button, which sits 5px inside the border. The right side keeps text
       clear of the button. */
    padding: calc((42px - 1lh) / 2) 45px calc((42px - 1lh) / 2) 14px !important;
    box-sizing: border-box !important;
    line-height: 1.4 !important;
    resize: none !important;
    font-size: 14px !important;
    font-family: var(--rsvl-font) !important;
    font-weight: normal !important;
    letter-spacing: normal !important;
    -webkit-font-smoothing: auto !important;
    -moz-osx-font-smoothing: auto !important;
    outline: none !important;
    /* No gray flash on tap in Safari; the darker border shows focus. */
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.2s;
    background: #fff !important;
    color: var(--rsvl-text) !important;
}

/* Start at 2 lines and grow with the message up to 6, then scroll. Browsers
   without field-sizing keep the fixed 2 rows. */
@supports (field-sizing: content) {
    .rsvl-input {
        field-sizing: content;
        /* 2 to 6 lines, plus the padding and border around them. */
        min-height: calc(1lh + 44px);
        max-height: calc(5lh + 44px);
    }
}

/* Past 6 lines it scrolls. Only a rounded thumb is drawn, with no track or
   arrows, and it stays clear of the rounded corners. Chrome and Safari use
   the -webkit- rules; Firefox uses the standard ones. */
.rsvl-input::-webkit-scrollbar {
    width: 12px;
}

/* A clear 3px border around the 6px thumb holds it off the box's edge. */
.rsvl-input::-webkit-scrollbar-thumb {
    background: var(--rsvl-border-focus);
    background-clip: padding-box;
    border: 3px solid transparent;
    border-radius: 6px;
}

.rsvl-input::-webkit-scrollbar-track {
    /* Clear of the rounded top corner, and stopping above the send button. */
    margin: 12px 0 46px;
}

@supports not selector(::-webkit-scrollbar) {
    .rsvl-input {
        scrollbar-width: thin;
        scrollbar-color: var(--rsvl-border-focus) transparent;
    }
}

.rsvl-input:focus {
    border-color: var(--rsvl-border-focus) !important;
    box-shadow: none;
}

.rsvl-input::placeholder {
    color: var(--rsvl-text-muted) !important;
    .rsvl-position-bottom-right
}

.rsvl-send {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    background: var(--rsvl-accent);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.2s;
}

    .rsvl-send:hover {
        background: var(--rsvl-accent-hover);
    }

    .rsvl-send:disabled {
        background: #e5e7eb;
        color: #9ca3af;
        cursor: not-allowed;
    }

/* Mobile Responsive */
@media (max-width: 768px) {

    .rsvl-toggle {
        width: 44px;
        height: 44px;
    }

        .rsvl-toggle svg {
            width: 22px;
            height: 22px;
        }

    .rsvl-position-bottom-right {
        bottom: 24px;
        right: 24px;
    }

    .rsvl-panel {
        position: fixed;
        /* Square corners here, and the panel is one scroll area that's 1px
           taller than its children, so it paints its own background. */
        background: var(--rsvl-bg);
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        border-radius: 0;
        border: none;
        /* The whole panel is the one scroll area, so a drag anywhere in it
           scrolls the chat instead of moving Safari's view. */
        overflow-y: auto;
        overscroll-behavior: contain;
    }
        /* Make the panel 1px taller than it is, so even a short chat is a scroll
       area that keeps the drag. */
        .rsvl-panel::after {
            content: "";
            position: absolute;
            top: 100%;
            width: 1px;
            height: 1px;
        }

    .rsvl-header {
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .rsvl-messages {
        /* Grow with the chat, rather than scroll on its own. */
        flex: 1 0 auto;
        overflow: visible;
    }
    /* While typing, chat-widget.js fits the panel to the part of the screen
       above the keyboard, header and all. */
    .rsvl-panel.rsvl-keyboard-open {
        top: var(--rsvl-viewport-top, 0);
        bottom: auto;
        height: var(--rsvl-viewport-height, 100%);
    }
    /* Bigger tap targets, and no dimming: there's no hover on a phone to
       bring them back to full strength. */
    .rsvl-new-chat,
    .rsvl-close {
        opacity: 1;
    }

        .rsvl-new-chat svg,
        .rsvl-close svg {
            width: 24px;
            height: 24px;
        }

    .rsvl-bot-name {
        font-size: 16px;
    }

    .rsvl-input-area {
        position: sticky;
        bottom: 0;
        background: var(--rsvl-bg);
    }
    /* Rides just above the sticky message box while you're scrolled up. */
    .rsvl-scroll-bottom:not([hidden]) {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        bottom: calc(100% + 8px);
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 32px;
        padding: 0;
        border-radius: 50%;
        border: 1px solid var(--rsvl-border);
        background: var(--rsvl-bg);
        color: var(--rsvl-text);
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
        cursor: pointer;
    }
    /* A 52px tap area around the 32px button. */
    .rsvl-scroll-bottom::before {
        content: "";
        position: absolute;
        inset: -10px;
    }

    .rsvl-input {
        /* iOS Safari zooms the page when an input under 16px gets focus. */
        font-size: 16px !important;
        /* Start at one line, as a pill whose corners curve around the send
           button: its 16px radius plus its 6px inset. */
        min-height: 0;
        border-radius: 22px !important;
    }

        .rsvl-input::-webkit-scrollbar-track {
            margin-top: 19px;
        }

    .rsvl-chat.rsvl-open .rsvl-toggle {
        display: none;
    }
}
