/* AI chat widget styles — extracted from the inline template block. */
    /* ── Scrollbar ──────────────────────────────── */
    #chat-messages {
        scrollbar-gutter: stable;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: rgba(0, 212, 255, 0.45) rgba(255, 255, 255, 0.08);
    }
    #chat-messages::-webkit-scrollbar { width: 10px; }
    #chat-messages::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.06);
        border-radius: 999px;
    }
    #chat-messages::-webkit-scrollbar-thumb {
        background: linear-gradient(180deg, rgba(0, 212, 255, 0.85), rgba(123, 47, 247, 0.75));
        border: 2px solid rgba(10, 10, 15, 0.9);
        border-radius: 999px;
    }
    #chat-messages::-webkit-scrollbar-thumb:hover {
        background: linear-gradient(180deg, rgba(0, 212, 255, 1), rgba(123, 47, 247, 0.9));
    }

    /* ── Grounding Panel Transitions ───────────── */
    #chat-widget details[data-grounding] summary::-webkit-details-marker { display: none; }
    #chat-widget details[data-grounding] .grounding-chevron {
        transition: transform 150ms ease-out;
    }
    #chat-widget details[data-grounding][open] .grounding-chevron {
        transform: rotate(180deg);
    }
    #chat-widget details[data-grounding] .grounding-panel {
        overflow: hidden;
        max-height: 0;
        opacity: 0;
        transform: translateY(-3px);
        transition: max-height 170ms ease-out, opacity 140ms ease-out, transform 150ms ease-out;
    }
    #chat-widget details[data-grounding][open] .grounding-panel {
        max-height: 520px;
        opacity: 1;
        transform: translateY(0);
    }

    /* ── Copy Buttons ──────────────────────────── */
    .chat-copy-btn {
        display: inline-flex;
        align-items: center;
        gap: 0.25rem;
        padding: 0.2rem 0.5rem;
        border-radius: 0.375rem;
        font-size: 0.65rem;
        font-weight: 500;
        color: #8888a0;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid rgba(255, 255, 255, 0.08);
        cursor: pointer;
        transition: all 0.15s ease;
        font-family: var(--font-body);
    }
    .chat-copy-btn:hover {
        color: #e8e8ed;
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.15);
    }
    .chat-copy-btn.copied {
        color: #00e676;
        border-color: rgba(0, 230, 118, 0.3);
    }

    /* Code block copy button */
    .chat-code-copy-btn {
        position: absolute;
        top: 0.4rem;
        right: 0.4rem;
        display: flex;
        align-items: center;
        gap: 0.25rem;
        padding: 0.2rem 0.45rem;
        border-radius: 0.3rem;
        font-size: 0.625rem;
        font-weight: 500;
        color: #8888a0;
        background: rgba(13, 17, 23, 0.9);
        border: 1px solid rgba(255, 255, 255, 0.1);
        cursor: pointer;
        transition: all 0.15s ease;
        opacity: 0;
        font-family: var(--font-body);
        z-index: 2;
    }
    .chat-markdown pre:hover .chat-code-copy-btn,
    .chat-code-copy-btn:focus-visible {
        opacity: 1;
    }
    .chat-code-copy-btn:hover {
        color: #e8e8ed;
        background: rgba(13, 17, 23, 1);
        border-color: rgba(255, 255, 255, 0.2);
    }
    .chat-code-copy-btn.copied {
        color: #00e676;
        border-color: rgba(0, 230, 118, 0.3);
        opacity: 1;
    }

    /* ── Action Bar (copy + feedback + regenerate) ── */
    .chat-action-bar {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid rgba(255, 255, 255, 0.04);
    }
    .chat-action-bar .chat-action-spacer {
        flex: 1;
    }

    /* Feedback buttons */
    .chat-feedback-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 26px;
        height: 26px;
        border-radius: 0.375rem;
        color: #77778c;
        background: transparent;
        border: 1px solid transparent;
        cursor: pointer;
        transition: all 0.15s ease;
        padding: 0;
    }
    .chat-feedback-btn:hover {
        color: #8888a0;
        background: rgba(255, 255, 255, 0.04);
        border-color: rgba(255, 255, 255, 0.08);
    }
    .chat-feedback-btn.active-positive {
        color: #00e676;
        background: rgba(0, 230, 118, 0.1);
        border-color: rgba(0, 230, 118, 0.25);
    }
    .chat-feedback-btn.active-negative {
        color: #ff5252;
        background: rgba(255, 82, 82, 0.1);
        border-color: rgba(255, 82, 82, 0.25);
    }

    /* Regenerate button */
    .chat-regenerate-btn {
        display: inline-flex;
        align-items: center;
        gap: 0.25rem;
        padding: 0.2rem 0.5rem;
        border-radius: 0.375rem;
        font-size: 0.65rem;
        font-weight: 500;
        color: #8888a0;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid rgba(255, 255, 255, 0.08);
        cursor: pointer;
        transition: all 0.15s ease;
        font-family: var(--font-body);
    }
    .chat-regenerate-btn:hover {
        color: #e8e8ed;
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.15);
    }
    .chat-regenerate-btn:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }

    /* Follow-up suggestion buttons */
    .chat-follow-up-btn {
        cursor: pointer;
        font-family: var(--font-body);
    }

    /* ── Resize Handle ─────────────────────────── */
    .chat-resize-handle {
        position: absolute;
        top: 4px;
        left: 4px;
        width: 24px;
        height: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: nw-resize;
        z-index: 10;
        border-radius: 1rem 0 0 0;
    }
    .chat-resize-handle:hover svg {
        color: rgba(255, 255, 255, 0.4);
    }

    /* ── Error Bubble ──────────────────────────── */
    .chat-error-bubble {
        border: 1px solid rgba(255, 82, 82, 0.15);
        background: rgba(255, 82, 82, 0.05);
    }
    .chat-error-retry-btn {
        display: inline-flex;
        align-items: center;
        gap: 0.25rem;
        padding: 0.25rem 0.6rem;
        border-radius: 0.375rem;
        font-size: 0.7rem;
        font-weight: 500;
        color: #ff5252;
        background: rgba(255, 82, 82, 0.1);
        border: 1px solid rgba(255, 82, 82, 0.2);
        cursor: pointer;
        transition: all 0.15s ease;
        margin-top: 0.5rem;
        font-family: var(--font-body);
    }
    .chat-error-retry-btn:hover {
        background: rgba(255, 82, 82, 0.2);
        border-color: rgba(255, 82, 82, 0.35);
        color: #ff8a80;
    }

    /* ── Mobile Bottom Sheet ───────────────────── */
    .chat-panel-mobile-fullscreen {
        position: fixed;
        inset: 0;
        border-radius: 0;
        border: none;
        /* Use visualViewport height (set by JS) for keyboard-aware sizing,
           falling back to 100dvh when JS hasn't set --vvh yet. */
        height: var(--vvh, 100dvh);
        max-height: var(--vvh, 100dvh);
        /* Fully opaque on mobile — no profile content should bleed through */
        background-color: #12121a;
        z-index: 50;
    }

    /* ── Mode-specific Panels ──────────────────── */
    .chat-panel-floating {
        position: fixed;
        right: 1.5rem;
        bottom: 1.5rem;
        border-radius: 1rem;
        border: 1px solid rgba(255, 255, 255, 0.08);
        background-color: rgba(18, 18, 26, 0.95);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
        max-height: min(600px, calc(100dvh - 2rem));
    }

    .chat-panel-sidebar {
        position: fixed;
        right: 0;
        top: 64px;  /* below the fixed nav header (matches main's pt-16) */
        bottom: 0;
        width: 480px;
        border-radius: 0;
        border-left: 1px solid rgba(255, 255, 255, 0.08);
        border-top: 1px solid rgba(255, 255, 255, 0.06);
        border-right: none;
        border-bottom: none;
        background-color: rgba(18, 18, 26, 0.98);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        box-shadow: -8px 0 30px rgba(0, 0, 0, 0.4);
        max-height: calc(100dvh - 64px);
    }

    .chat-panel-fullscreen {
        position: fixed;
        inset: 0;
        border-radius: 0;
        border: none;
        background-color: rgba(18, 18, 26, 0.98);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        max-height: 100dvh;
    }

    /* ── AI bubble width constraint ──────────────
       Prevent bubbles from stretching edge-to-edge
       in fullscreen/sidebar, and stop grounding panel
       from changing the bubble width when opened. */
    #chat-messages .chat-answer-bubble > .chat-markdown {
        max-width: 720px;
        min-width: 0;
    }
    #chat-messages .chat-answer-bubble > .chat-markdown details[data-grounding] {
        overflow: hidden;
    }

    /* ── Streaming Cursor ───────────────────────── */
    .chat-streaming-cursor {
        display: inline-block;
        width: 2px;
        height: 1em;
        background: var(--accent-primary, #00d4ff);
        margin-left: 2px;
        vertical-align: text-bottom;
        animation: chat-cursor-blink 0.8s ease-in-out infinite;
    }
    @keyframes chat-cursor-blink {
        0%, 100% { opacity: 1; }
        50% { opacity: 0; }
    }

    /* ── Panel open/close transitions ──────────── */
    /* Mobile: slide up from bottom (no opacity fade — prevents page bleed-through).
       Desktop: fade + scale for a polished floating/sidebar feel. */
    .chat-transition-enter {
        transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    }
    .chat-transition-leave {
        transition: transform 0.2s ease-in, opacity 0.2s ease-in;
    }
    /* Desktop: fade + scale + slight translate */
    .chat-transition-enter-start {
        opacity: 0;
        transform: translateY(1rem) scale(0.95);
    }
    .chat-transition-enter-end {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    /* Mobile: slide from bottom, no opacity change */
    @media (max-width: 639px) {
        .chat-transition-enter-start {
            opacity: 1;
            transform: translateY(100%);
        }
        .chat-transition-enter-end {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* ── Drag dismissal transition ─────────────── */
    .chat-dragging {
        transition: none !important;
    }

    @media (prefers-reduced-motion: reduce) {
        #chat-widget details[data-grounding] .grounding-chevron,
        #chat-widget details[data-grounding] .grounding-panel {
            transition: none;
        }
    }

    /* Safe area padding for notched devices */
    @supports (padding-bottom: env(safe-area-inset-bottom)) {
        .chat-panel-mobile-fullscreen {
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
