.chat-widget {
    position: fixed;
    right: 126px;
    bottom: 28px;
    z-index: 1200;
    display: grid;
    grid-template-rows: auto auto minmax(220px, 1fr) auto auto;
    width: min(390px, calc(100vw - 32px));
    height: min(620px, calc(100vh - 112px));
    overflow: hidden;
    color: #261c17;
    background: #fff;
    border: 1px solid #ded8d2;
    border-radius: 6px;
    box-shadow: 0 24px 70px rgba(38, 19, 8, 0.24);
    opacity: 0;
    visibility: hidden;
    transform: translateY(18px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.chat-widget.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.chat-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 68px;
    padding: 12px 14px 12px 18px;
    color: #fff;
    background: #171411;
}

.chat-widget-header strong {
    display: block;
    font-size: 16px;
}

.chat-connection {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    color: rgba(255, 255, 255, 0.68);
    font-size: 11px;
}

.chat-connection i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #f5b942;
}

.chat-connection[data-state="online"] i { background: #65b96e; }
.chat-connection[data-state="offline"] i { background: #d65b51; }

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-header-actions button {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    color: #fff;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-profile-panel {
    display: none;
    grid-template-columns: 1fr 1fr auto;
    gap: 8px;
    align-items: end;
    padding: 12px;
    background: #faf7f4;
    border-bottom: 1px solid #eadfd8;
}

.chat-widget.profile-open .chat-profile-panel {
    display: grid;
}

.chat-profile-panel label {
    color: #74665f;
    font-size: 10px;
}

.chat-profile-panel input {
    width: 100%;
    height: 36px;
    margin-top: 4px;
    padding: 0 9px;
    border: 1px solid #d9d1cc;
    border-radius: 3px;
    background: #fff;
    color: #261c17;
    font-size: 12px;
}

.chat-profile-save {
    height: 36px;
    padding: 0 13px;
    color: #fff;
    background: #c84d08;
    border: 0;
    border-radius: 3px;
    cursor: pointer;
}

.chat-message-list {
    overflow-y: auto;
    padding: 18px 16px;
    background: #faf9f7;
}

.chat-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 14px;
}

.chat-message-visitor {
    align-items: flex-end;
}

.chat-message-bubble {
    max-width: 82%;
    padding: 10px 12px;
    color: #2f241f;
    background: #fff;
    border: 1px solid #e5ded9;
    border-radius: 6px;
    line-height: 1.55;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.chat-message-visitor .chat-message-bubble {
    color: #fff;
    background: #c84d08;
    border-color: #c84d08;
}

.chat-message-system .chat-message-bubble {
    max-width: 100%;
    color: #675a53;
    background: #fff7ed;
    border-color: #fed7aa;
    font-size: 12px;
}

.chat-message-requirement {
    align-items: stretch;
}

.chat-message-requirement .chat-message-label {
    margin: 0 0 5px 2px;
    color: #17636d;
    font-size: 11px;
}

.chat-message-requirement .chat-message-bubble {
    max-width: 100%;
    color: #164e55;
    background: #eaf6f8;
    border-color: #80bbc3;
    border-left-width: 4px;
}

.chat-message time {
    margin-top: 3px;
    color: #9a8d86;
    font-size: 10px;
}

.chat-inline-notice {
    margin: 8px 0;
    padding: 8px 10px;
    color: #675a53;
    background: #f1eee9;
    font-size: 12px;
    text-align: center;
}

.chat-inline-notice.error { color: #9f2f27; background: #fff0ef; }
.chat-inline-notice.success { color: #246b38; background: #edf8f0; }

.chat-composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
    align-items: end;
    padding: 12px;
    border-top: 1px solid #eadfd8;
    background: #fff;
}

.chat-composer textarea {
    width: 100%;
    max-height: 112px;
    resize: none;
    padding: 10px 11px;
    border: 1px solid #d9d1cc;
    border-radius: 4px;
    outline: none;
    line-height: 1.45;
}

.chat-composer textarea:focus {
    border-color: #f97316;
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.12);
}

.chat-composer button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 42px;
    padding: 0;
    color: #fff;
    background: #c84d08;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}

.chat-composer button:disabled {
    cursor: default;
    opacity: 0.4;
}

.chat-privacy {
    margin: 0;
    padding: 0 12px 10px;
    color: #8b7d76;
    background: #fff;
    font-size: 10px;
    text-align: center;
}

.chat-privacy a {
    color: #c84d08;
    text-decoration: underline;
}

@media (max-width: 640px) {
    .chat-widget {
        inset: 76px 0 0;
        width: 100%;
        height: calc(100dvh - 76px);
        max-height: none;
        border: 0;
        border-radius: 0;
    }

    .chat-profile-panel {
        grid-template-columns: 1fr;
    }

    .chat-profile-save {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-widget { transition: none; }
}
