.rsa-root {
    --rsa-red: #f12c35;
    --rsa-red-dark: #991b1b;
    --rsa-bg: #ffffff;
    --rsa-bg-elevated: #f8f9fa;
    --rsa-surface: #ffffff;
    --rsa-text: #1a1a1a;
    --rsa-muted: #4b5563;
    --rsa-border: #e5e7eb;
    --rsa-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
    --rsa-radius: 22px;
    --rsa-font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color-scheme: light;
}

.rsa-hidden { display: none !important; }

.rsa-root .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;
}

.rsa-launcher {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 99990;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 0;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, var(--rsa-red), var(--rsa-red-dark));
    box-shadow: 0 10px 28px rgba(241, 44, 53, 0.35);
    border-radius: 999px;
    padding: 12px 16px 12px 12px;
    font-family: var(--rsa-font);
    font-weight: 700;
    letter-spacing: 0.01em;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.rsa-root.is-open .rsa-launcher {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.92);
}

.rsa-launcher:hover,
.rsa-launcher:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 14px 32px rgba(241, 44, 53, 0.45);
    outline: none;
}

.rsa-launcher-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    display: grid;
    place-items: center;
    overflow: hidden;
}

.rsa-launcher-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rsa-launcher-icon svg {
    width: 22px;
    height: 22px;
    fill: #fff;
    stroke: #fff;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.rsa-backdrop {
    position: fixed;
    inset: 0;
    z-index: 99990;
    background: rgba(10, 12, 18, 0.48);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.rsa-backdrop[hidden] { display: none !important; }

.rsa-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(920px, calc(100vw - 32px));
    height: min(860px, calc(100vh - 40px));
    z-index: 99991;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--rsa-bg);
    color: var(--rsa-text);
    border: 1px solid var(--rsa-border);
    border-radius: var(--rsa-radius);
    box-shadow: var(--rsa-shadow);
    font-family: var(--rsa-font);
}

.rsa-panel[hidden] { display: none !important; }

.rsa-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--rsa-border);
    background:
        linear-gradient(180deg, rgba(241, 44, 53, 0.08), transparent 78%),
        var(--rsa-bg);
}

.rsa-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.rsa-avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
}

.rsa-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}

.rsa-brand h2 {
    margin: 0;
    font-size: 1.08rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.rsa-brand p {
    margin: 2px 0 0;
    font-size: 0.8rem;
    color: var(--rsa-muted);
}

.rsa-header-actions {
    display: flex;
    gap: 6px;
}

.rsa-icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid var(--rsa-border);
    background: var(--rsa-bg-elevated);
    color: var(--rsa-text);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.rsa-icon-btn:hover,
.rsa-icon-btn:focus-visible {
    border-color: var(--rsa-red);
    outline: none;
}

.rsa-icon-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
}

.rsa-messages {
    flex: 1;
    overflow-y: auto;
    padding: 22px 22px 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background:
        radial-gradient(circle at top right, rgba(241, 44, 53, 0.05), transparent 28%),
        var(--rsa-bg);
}

.rsa-msg {
    max-width: min(760px, 92%);
    padding: 14px 16px;
    border-radius: 18px;
    line-height: 1.65;
    font-size: 0.98rem;
    position: relative;
}

.rsa-msg.assistant {
    align-self: flex-start;
    width: min(760px, 100%);
    max-width: min(760px, 100%);
    background: var(--rsa-surface);
    border: 1px solid var(--rsa-border);
    color: var(--rsa-text);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.rsa-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--rsa-red), var(--rsa-red-dark));
    color: #fff;
    max-width: min(640px, 88%);
}

.rsa-msg.system-note {
    align-self: center;
    max-width: 100%;
    background: transparent;
    color: var(--rsa-muted);
    font-size: 0.8rem;
    text-align: center;
}

.rsa-msg a,
.rsa-msg a.rsa-inline-link {
    color: var(--rsa-red-dark);
    text-decoration: none;
    font-weight: 650;
    border-bottom: 1.5px solid rgba(185, 28, 28, 0.35);
    padding-bottom: 1px;
    word-break: break-word;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    border-radius: 2px;
}
.rsa-msg a:hover,
.rsa-msg a.rsa-inline-link:hover,
.rsa-msg a:focus-visible {
    color: var(--rsa-red);
    border-bottom-color: var(--rsa-red);
    background: rgba(185, 28, 28, 0.06);
    outline: none;
}
.rsa-msg.user a {
    color: #fff;
    border-bottom-color: rgba(255, 255, 255, 0.55);
}
.rsa-msg.user a:hover,
.rsa-msg.user a:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    border-bottom-color: #fff;
}

.rsa-msg h1,
.rsa-msg h2,
.rsa-msg h3,
.rsa-msg h4 {
    margin: 0.85em 0 0.4em;
    line-height: 1.3;
    letter-spacing: -0.02em;
    color: inherit;
}

.rsa-msg h1 { font-size: 1.2rem; }
.rsa-msg h2 { font-size: 1.1rem; }
.rsa-msg h3 { font-size: 1.02rem; }
.rsa-msg h4 { font-size: 0.98rem; }

.rsa-msg h1:first-child,
.rsa-msg h2:first-child,
.rsa-msg h3:first-child,
.rsa-msg h4:first-child,
.rsa-msg p:first-child {
    margin-top: 0;
}

.rsa-msg p {
    margin: 0 0 0.75em;
}
.rsa-msg p:last-child { margin-bottom: 0; }

.rsa-msg ul,
.rsa-msg ol {
    margin: 0.35em 0 0.85em;
    padding-left: 1.25em;
}

.rsa-msg li {
    margin: 0.28em 0;
}

.rsa-msg li::marker {
    color: var(--rsa-red);
}

.rsa-msg strong { font-weight: 750; }

.rsa-msg hr {
    border: 0;
    border-top: 1px solid var(--rsa-border);
    margin: 1em 0;
}

.rsa-msg blockquote {
    margin: 0.75em 0;
    padding: 0.55em 0.85em;
    border-left: 3px solid var(--rsa-red);
    background: rgba(241, 44, 53, 0.05);
    color: var(--rsa-muted);
    border-radius: 0 10px 10px 0;
}

.rsa-msg code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86em;
    background: rgba(15, 23, 42, 0.06);
    padding: 0.12em 0.4em;
    border-radius: 6px;
}
.rsa-msg.user code { background: rgba(255, 255, 255, 0.16); }

.rsa-msg pre {
    overflow-x: auto;
    padding: 12px 14px;
    border-radius: 12px;
    background: #0f172a;
    color: #e2e8f0;
    margin: 0.7em 0;
    border: 1px solid rgba(255, 255, 255, 0.06);
}
.rsa-msg pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: 0.88em;
    line-height: 1.55;
}

.rsa-msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.rsa-mini {
    border: 0;
    background: transparent;
    color: var(--rsa-muted);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
}

.rsa-mini:hover { color: var(--rsa-red); }

.rsa-typing {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    min-height: 18px;
}

.rsa-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--rsa-red);
    animation: rsa-pulse 1.1s infinite ease-in-out;
}

.rsa-typing span:nth-child(2) { animation-delay: 0.15s; }
.rsa-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes rsa-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
}

.rsa-composer {
    display: flex;
    gap: 10px;
    padding: 14px 20px 18px;
    border-top: 1px solid var(--rsa-border);
    background: var(--rsa-bg);
}

.rsa-composer textarea {
    flex: 1;
    resize: none;
    min-height: 52px;
    max-height: 160px;
    border: 1px solid var(--rsa-border);
    border-radius: 14px;
    padding: 14px 14px;
    font: inherit;
    color: var(--rsa-text);
    background: var(--rsa-bg-elevated);
}

.rsa-composer textarea:focus {
    outline: 2px solid rgba(241, 44, 53, 0.28);
    border-color: var(--rsa-red);
}

.rsa-send,
.rsa-stop {
    width: 52px;
    height: 52px;
    border: 0;
    border-radius: 14px;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, var(--rsa-red), var(--rsa-red-dark));
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.rsa-stop { background: #334155; }

.rsa-send svg,
.rsa-stop svg {
    width: 18px;
    height: 18px;
    stroke: #fff;
    fill: none;
    stroke-width: 1.8;
}

.rsa-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.rsa-error {
    margin: 0 20px 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(241, 44, 53, 0.08);
    color: var(--rsa-red-dark);
    font-size: 0.82rem;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}

.rsa-lead {
    align-self: stretch;
    max-width: 100%;
    background: var(--rsa-bg-elevated);
    border: 1px solid var(--rsa-border);
    border-radius: 14px;
    padding: 14px;
}

.rsa-lead h3 {
    margin: 0 0 8px;
    font-size: 0.95rem;
}

.rsa-lead p {
    margin: 0 0 10px;
    color: var(--rsa-muted);
    font-size: 0.82rem;
}

.rsa-lead label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    margin: 8px 0 4px;
}

.rsa-lead input,
.rsa-lead select,
.rsa-lead textarea {
    width: 100%;
    border: 1px solid var(--rsa-border);
    border-radius: 10px;
    padding: 8px 10px;
    font: inherit;
    background: var(--rsa-bg);
    color: var(--rsa-text);
}

.rsa-lead textarea { min-height: 72px; resize: vertical; }

.rsa-lead-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.rsa-lead button {
    border: 0;
    border-radius: 10px;
    padding: 8px 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.rsa-lead .primary {
    background: linear-gradient(135deg, var(--rsa-red), var(--rsa-red-dark));
    color: #fff;
}

.rsa-lead .ghost {
    background: transparent;
    color: var(--rsa-muted);
}

@media (max-width: 900px) {
    .rsa-panel {
        width: min(100vw - 16px, 920px);
        height: min(100dvh - 16px, 900px);
    }
}

@media (max-width: 640px) {
    .rsa-launcher { right: 14px; bottom: 14px; }
    .rsa-launcher-label { display: none; }
    .rsa-panel {
        top: 0;
        left: 0;
        transform: none;
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
    }
    .rsa-messages { padding: 16px; }
    .rsa-composer { padding: 12px 14px 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .rsa-launcher, .rsa-typing span { animation: none; transition: none; }
}
