.beirai-widget,
.beirai-widget * {
    box-sizing: border-box;
}

.beirai-widget {
    --beirai-accent: #0ea5e9;
    --beirai-accent-text: #ffffff;
    --beirai-ink: #0f172a;
    --beirai-muted: #64748b;
    --beirai-line: #e2e8f0;
    --beirai-surface: #ffffff;
    --beirai-canvas: #f8fafc;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--beirai-ink);
}

.beirai-widget button,
.beirai-widget input {
    font: inherit;
}

.beirai-widget h2,
.beirai-widget p {
    margin: 0;
}

.beirai-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2147483000;
    display: flex;
    width: 60px;
    height: 60px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--beirai-accent);
    color: var(--beirai-accent-text);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.22);
    cursor: pointer;
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.beirai-launcher:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 16px 34px rgba(15, 23, 42, 0.28);
}

.beirai-launcher:focus-visible,
.beirai-icon-button:focus-visible,
.beirai-quick-reply:focus-visible,
.beirai-send:focus-visible {
    outline: 3px solid rgba(14, 165, 233, 0.45);
    outline-offset: 2px;
}

.beirai-pos-left .beirai-launcher {
    right: auto;
    left: 24px;
}

.beirai-panel {
    position: fixed;
    right: 24px;
    bottom: 96px;
    z-index: 2147483000;
    display: none;
    width: 390px;
    max-width: calc(100vw - 32px);
    height: min(640px, calc(100vh - 120px));
    max-height: calc(100vh - 120px);
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 22px;
    background: var(--beirai-surface);
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.beirai-panel.beirai-open {
    display: flex;
    animation: beirai-rise 220ms ease both;
}

.beirai-pos-left .beirai-panel {
    right: auto;
    left: 24px;
}

@keyframes beirai-rise {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.beirai-header {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    background: var(--beirai-accent);
    color: var(--beirai-accent-text);
}

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

.beirai-avatar {
    display: flex;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
}

.beirai-brand-text {
    min-width: 0;
}

.beirai-title {
    overflow: hidden;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.beirai-subtitle {
    overflow: hidden;
    font-size: 12px;
    opacity: 0.82;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.beirai-header-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
}

.beirai-icon-button {
    display: flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: inherit;
    cursor: pointer;
    transition: background 150ms ease;
}

.beirai-icon-button:hover {
    background: rgba(255, 255, 255, 0.24);
}

.beirai-messages {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding: 16px;
    background: var(--beirai-canvas);
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

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

.beirai-messages::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #cbd5e1;
}

.beirai-message {
    display: flex;
    max-width: 88%;
}

.beirai-message.beirai-assistant {
    align-self: flex-start;
}

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

.beirai-bubble {
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.beirai-assistant .beirai-bubble {
    border: 1px solid var(--beirai-line);
    border-bottom-left-radius: 5px;
    background: var(--beirai-surface);
    color: var(--beirai-ink);
}

.beirai-user .beirai-bubble {
    border-bottom-right-radius: 5px;
    background: var(--beirai-accent);
    color: var(--beirai-accent-text);
}

.beirai-typing {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
    padding: 4px 18px 10px;
    background: var(--beirai-canvas);
}

.beirai-typing[hidden] {
    display: none;
}

.beirai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--beirai-accent);
    opacity: 0.55;
    animation: beirai-bounce 1.2s infinite ease-in-out;
}

.beirai-typing span:nth-child(2) {
    animation-delay: 0.16s;
}

.beirai-typing span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes beirai-bounce {
    0%, 70%, 100% {
        transform: translateY(0);
        opacity: 0.45;
    }
    35% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.beirai-quick-replies {
    display: flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 98px;
    overflow-y: auto;
    padding: 9px 14px;
    border-top: 1px solid var(--beirai-line);
    background: var(--beirai-surface);
}

.beirai-quick-replies:empty {
    display: none;
}

.beirai-quick-reply {
    padding: 7px 11px;
    border: 1px solid #bae6fd;
    border: 1px solid color-mix(in srgb, var(--beirai-accent) 42%, white);
    border-radius: 999px;
    background: transparent;
    color: var(--beirai-accent);
    font-size: 12px;
    line-height: 1.2;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease;
}

.beirai-quick-reply:hover {
    border-color: var(--beirai-accent);
    background: #f0f9ff;
    background: color-mix(in srgb, var(--beirai-accent) 9%, white);
}

.beirai-form {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 11px 14px;
    border-top: 1px solid var(--beirai-line);
    background: var(--beirai-surface);
}

.beirai-form input {
    min-width: 0;
    flex: 1 1 auto;
    padding: 11px 14px;
    border: 1px solid var(--beirai-line);
    border-radius: 999px;
    outline: none;
    background: #fff;
    color: var(--beirai-ink);
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.beirai-form input::placeholder {
    color: #94a3b8;
}

.beirai-form input:focus {
    border-color: var(--beirai-accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.17);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--beirai-accent) 17%, transparent);
}

.beirai-send {
    display: flex;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--beirai-accent);
    color: var(--beirai-accent-text);
    cursor: pointer;
    transition: transform 150ms ease, opacity 150ms ease;
}

.beirai-send:hover {
    transform: scale(1.04);
}

.beirai-send:disabled {
    cursor: wait;
    opacity: 0.55;
    transform: none;
}

.beirai-footer {
    display: flex;
    flex-shrink: 0;
    justify-content: center;
    gap: 14px;
    padding: 0 14px 10px;
    background: var(--beirai-surface);
    font-size: 11px;
}

.beirai-footer a {
    color: var(--beirai-muted);
    text-decoration: underline;
}

.beirai-footer a:hover {
    color: var(--beirai-accent);
}

.beirai-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 560px) {
    .beirai-launcher,
    .beirai-pos-left .beirai-launcher {
        right: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        left: auto;
    }

    .beirai-panel,
    .beirai-pos-left .beirai-panel {
        inset: 0;
        width: 100%;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border: 0;
        border-radius: 0;
    }

    .beirai-header {
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
    }

    .beirai-form {
        padding-bottom: calc(11px + env(safe-area-inset-bottom, 0px));
    }

    .beirai-footer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

@media (prefers-reduced-motion: reduce) {
    .beirai-widget *,
    .beirai-widget *::before,
    .beirai-widget *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
