.saig-chat {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 9999;
    font-family: inherit;
}

.saig-chat-button {
    border: 0;
    border-radius: 999px;
    padding: 14px 20px;
    background: #EA333E;
    color: #ffffff;
    font-weight: 800;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
    cursor: pointer;
}

.saig-chat-button:hover,
.saig-chat-button:focus {
    background: #ff4a55;
}

.saig-chat-panel {
    position: absolute;
    right: 0;
    bottom: 64px;
    width: min(390px, calc(100vw - 28px));
    height: min(620px, calc(100vh - 110px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(234, 51, 62, 0.28);
    border-radius: 24px;
    background: #111111;
    color: #ffffff;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.saig-chat-header {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px 13px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    background: linear-gradient(135deg, #111111 0%, #2a0d14 100%);
}

.saig-chat-header strong {
    display: block;
    font-size: 1rem;
    line-height: 1.2;
}

.saig-chat-header span {
    display: block;
    margin-top: 4px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.82rem;
}

.saig-chat-close {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.saig-chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding: 16px;
    background: #151515;
    overscroll-behavior: contain;
}

.saig-chat-message {
    max-width: 92%;
    border-radius: 18px;
    padding: 12px 14px;
    font-size: 0.9rem;
    line-height: 1.42;
    overflow-wrap: anywhere;
}

.saig-chat-message p {
    margin: 0 0 9px;
}

.saig-chat-message p:last-child {
    margin-bottom: 0;
}

.saig-chat-message ul,
.saig-chat-message ol {
    margin: 8px 0 8px 18px;
    padding: 0;
}

.saig-chat-message li {
    margin: 4px 0;
}

.saig-chat-message a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.saig-chat-message.assistant {
    align-self: flex-start;
    background: #ffffff;
    color: #171717;
}

.saig-chat-message.user {
    align-self: flex-end;
    background: #EA333E;
    color: #ffffff;
}

.saig-chat-message.loading {
    opacity: 0.78;
}

.saig-chat-prompts {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 14px;
    background: #151515;
}

.saig-chat-prompts button {
    border: 1px solid rgba(234, 51, 62, 0.45);
    border-radius: 999px;
    padding: 8px 10px;
    background: rgba(234, 51, 62, 0.12);
    color: #ffffff;
    font-size: 0.78rem;
    cursor: pointer;
}

.saig-chat-prompts button:hover,
.saig-chat-prompts button:focus {
    background: rgba(234, 51, 62, 0.28);
}

.saig-chat-form {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    background: #111111;
}

.saig-chat-form textarea {
    width: 100%;
    max-height: 92px;
    resize: none;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    padding: 10px 12px;
    background: #ffffff;
    color: #111111;
    font: inherit;
}

.saig-chat-form button {
    align-self: stretch;
    border: 0;
    border-radius: 14px;
    padding: 0 16px;
    background: #EA333E;
    color: #ffffff;
    font-weight: 800;
    cursor: pointer;
}

.saig-chat-form button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.saig-chat-privacy {
    flex: 0 0 auto;
    margin: 0;
    padding: 0 16px 14px;
    background: #111111;
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.72rem;
    line-height: 1.35;
}

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

@media (max-width: 640px) {
    .saig-chat {
        right: 12px;
        bottom: 12px;
    }

    .saig-chat-panel {
        right: -2px;
        bottom: 60px;
        width: calc(100vw - 24px);
        height: min(620px, calc(100vh - 90px));
        border-radius: 20px;
    }

    .saig-chat-message {
        max-width: 96%;
    }
}

/* Live tuning: smaller, more compact chat layout */
.saig-chat-panel {
    height: min(700px, calc(100vh - 82px));
    bottom: 56px;
}

.saig-chat-header {
    padding: 12px 14px 10px;
}

.saig-chat-header strong {
    font-size: 0.92rem;
}

.saig-chat-header span {
    font-size: 0.74rem;
}

.saig-chat-messages {
    padding: 12px;
    gap: 9px;
}

.saig-chat-message {
    font-size: 0.78rem;
    line-height: 1.32;
    padding: 9px 11px;
    border-radius: 14px;
}

.saig-chat-message p {
    margin-bottom: 7px;
}

.saig-chat-message ul,
.saig-chat-message ol {
    margin: 6px 0 6px 16px;
}

.saig-chat-prompts {
    gap: 6px;
    padding: 0 12px 10px;
}

.saig-chat-prompts button {
    font-size: 0.68rem;
    padding: 6px 8px;
}

.saig-chat-form {
    padding: 10px 12px;
    gap: 8px;
}

.saig-chat-form textarea {
    font-size: 0.8rem;
    padding: 8px 10px;
}

.saig-chat-form button {
    font-size: 0.78rem;
    padding: 0 12px;
}

.saig-chat-privacy {
    font-size: 0.63rem;
    padding: 0 12px 10px;
}

/* Chat usability fixes */
.saig-chat-close {
    position: relative;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
}

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