.calm-widget {
    position: fixed !important;
    right: 22px;
    bottom: 22px;
    z-index: 99999999999999;
    font-family: var(--font-body, Arial, sans-serif);
    display: block;
    visibility: visible;
    opacity: 1;
    transform: translateZ(0);
    isolation: isolate;
}

.calm-toggle {
    width: 62px;
    height: 62px;
    border: 0;
    border-radius: 50%;
    background: var(--color-secondary, #1a1a1a);
    color: #fff;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.26);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.45rem;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
}

.calm-toggle:hover,
.calm-toggle:focus-visible {
    background: var(--color-primary, #8b6f47);
    transform: translateY(-2px);
}

.calm-panel {
    position: absolute;
    right: 0;
    bottom: 78px;
    width: 380px;
    max-width: calc(100vw - 44px);
    height: min(620px, calc(100vh - 112px));
    box-sizing: border-box;
    background: #fff;
    border: 1px solid var(--color-border, #e5ddd1);
    border-radius: 8px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
    display: none;
    overflow: hidden;
}

.calm-widget--open .calm-panel {
    display: flex;
    flex-direction: column;
}

.calm-header {
    min-height: 76px;
    padding: 14px 16px;
    background: var(--color-secondary, #1a1a1a);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.calm-header h2 {
    margin: 3px 0 0;
    color: #fff;
    font-family: var(--font-heading, Georgia, serif);
    font-size: 1.45rem;
    line-height: 1;
}

.calm-eyebrow {
    display: block;
    color: var(--color-accent, #d4a574);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
}

.calm-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.calm-icon-btn,
.calm-send {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.calm-icon-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.calm-icon-btn:hover,
.calm-icon-btn:focus-visible {
    background: rgba(255, 255, 255, 0.22);
}

.calm-history {
    border-bottom: 1px solid var(--color-border, #e5ddd1);
    background: var(--color-bg-light, #faf8f5);
    max-height: 238px;
    overflow: hidden;
}

.calm-history-head {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.calm-text-btn,
.calm-login-link {
    border: 0;
    background: transparent;
    color: var(--color-primary, #8b6f47);
    font-size: 0.82rem;
    font-weight: 700;
    padding: 0;
    cursor: pointer;
}

.calm-history-list {
    max-height: 178px;
    overflow-y: auto;
    padding: 0 10px 12px;
}

.calm-history-item {
    width: 100%;
    border: 1px solid var(--color-border, #e5ddd1);
    background: #fff;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 8px;
    text-align: left;
    color: var(--color-text-dark, #2c2c2c);
    display: block;
    cursor: pointer;
}

.calm-history-item span,
.calm-history-item small {
    display: block;
}

.calm-history-item span {
    font-size: 0.9rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calm-history-item small {
    color: var(--color-text-light, #999);
    font-size: 0.72rem;
    margin-top: 2px;
}

.calm-empty,
.calm-history-loading {
    color: var(--color-text-medium, #666);
    font-size: 0.88rem;
    margin: 8px 4px;
}

.calm-login-link {
    display: inline-block;
    margin: 0 4px 8px;
}

.calm-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 14px;
    background: linear-gradient(180deg, #fff 0%, var(--color-bg-light, #faf8f5) 100%);
}

.calm-message {
    display: flex;
    margin-bottom: 12px;
}

.calm-message--user {
    justify-content: flex-end;
}

.calm-message--assistant {
    justify-content: flex-start;
}

.calm-bubble {
    max-width: min(78%, 290px);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.9rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.06);
}

.calm-message--user .calm-bubble {
    background: var(--color-primary, #8b6f47);
    color: #fff;
}

.calm-message--assistant .calm-bubble {
    background: #fff;
    border: 1px solid var(--color-border, #e5ddd1);
    color: var(--color-text-dark, #2c2c2c);
}

.calm-typing {
    min-width: 62px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.calm-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-primary, #8b6f47);
    animation: calmTyping 1s infinite ease-in-out;
}

.calm-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.calm-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes calmTyping {
    0%, 80%, 100% {
        opacity: 0.35;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

.calm-form {
    min-height: 68px;
    padding: 12px;
    border-top: 1px solid var(--color-border, #e5ddd1);
    background: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.calm-form input {
    flex: 1;
    min-width: 0;
    height: 44px;
    border: 1px solid var(--color-border, #e5ddd1);
    border-radius: 999px;
    padding: 0 15px;
    font-size: 0.92rem;
    outline: none;
}

.calm-form input:focus {
    border-color: var(--color-primary, #8b6f47);
    box-shadow: 0 0 0 3px rgba(139, 111, 71, 0.14);
}

.calm-send {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    background: var(--color-primary, #8b6f47);
    color: #fff;
}

.calm-send:hover,
.calm-send:focus-visible {
    background: var(--color-primary-dark, #6b5437);
}

.calm-send:disabled {
    opacity: 0.65;
    cursor: wait;
}

@media (max-width: 575px) {
    .calm-widget {
        right: 14px;
        right: max(14px, env(safe-area-inset-right));
        bottom: max(14px, env(safe-area-inset-bottom));
        position: fixed !important;
        transform: translate3d(0, 0, 0);
        z-index: 2147483647;
    }

    .calm-panel {
        right: 0;
        bottom: 74px;
        width: min(320px, calc(100vw - 28px));
        max-width: calc(100vw - 28px);
        height: min(590px, calc(100vh - 102px));
        box-sizing: border-box;
    }

    .calm-toggle {
        width: 58px;
        height: 58px;
    }
}

