.cw-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    font-family: var(--font-body);
}

.cw-toggle {
    position: relative;
    display: flex;
    width: 56px;
    height: 56px;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--accent);
    border: 0;
    border-radius: var(--radius-pill);
    box-shadow: 0 4px 20px var(--accent-glow);
    cursor: pointer;
    transition: var(--transition);
}

.cw-toggle:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.cw-toggle:active {
    transform: scale(.96);
}

.cw-toggle i {
    font-size: 22px;
}

.cw-toggle__badge {
    position: absolute;
    top: -5px;
    right: -5px;
    display: flex;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--danger);
    border: 2px solid var(--bg-primary);
    border-radius: var(--radius-pill);
    font-family: var(--font-heading);
    font-size: 10px;
    font-weight: 700;
}

.cw-toggle__badge[hidden] {
    display: none;
}

.cw-box {
    position: absolute;
    right: 0;
    bottom: 68px;
    display: none;
    width: 360px;
    height: min(520px, calc(100vh - 120px));
    overflow: hidden;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.cw-box.is-open {
    display: flex;
}

.cw-header,
.cw-header__info {
    display: flex;
    align-items: center;
}

.cw-header {
    flex-shrink: 0;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--accent);
}

.cw-header__info {
    gap: 10px;
}

.cw-header__avatar {
    display: flex;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: rgb(255 255 255 / 20%);
    border-radius: var(--radius-pill);
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
}

.cw-header__name {
    color: #fff;
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: .03em;
}

.cw-header__status {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
    color: rgb(255 255 255 / 78%);
    font-size: 11px;
}

.cw-header__status-dot {
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    opacity: .85;
}

.cw-header__close {
    display: flex;
    padding: 4px;
    align-items: center;
    justify-content: center;
    color: rgb(255 255 255 / 85%);
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 20px;
}

.cw-header__close:hover {
    color: #fff;
    background: rgb(255 255 255 / 15%);
}

.cw-contact-bar {
    flex-shrink: 0;
    padding: 7px 12px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
}

.cw-contact-toggle {
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: center;
    gap: 7px;
    padding: 4px;
    color: var(--text-secondary);
    background: none;
    border: 0;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 11px;
    text-align: left;
}

.cw-contact-toggle > span {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cw-contact-toggle > i:first-child {
    color: var(--accent);
    font-size: 15px;
}

.cw-contact-toggle__edit {
    color: var(--text-muted);
    font-size: 13px;
}

.cw-contact-form {
    flex-shrink: 0;
    padding: 11px 12px 10px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.cw-contact-form[hidden] {
    display: none;
}

.cw-contact-form__title {
    margin-bottom: 8px;
    color: var(--text-primary);
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 700;
}

.cw-contact-form__fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
}

.cw-contact-input {
    min-width: 0;
    padding: 8px 9px;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    outline: none;
    font-family: var(--font-body);
    font-size: 12px;
}

.cw-contact-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.cw-contact-error {
    margin-top: 6px;
    color: var(--danger);
    font-size: 10px;
}

.cw-contact-error[hidden] {
    display: none;
}

.cw-contact-form__actions {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
    margin-top: 8px;
}

.cw-contact-cancel,
.cw-contact-save {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 11px;
}

.cw-contact-cancel {
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-subtle);
}

.cw-contact-save {
    color: #fff;
    background: var(--accent);
    border: 1px solid var(--accent);
}

.cw-contact-save:disabled {
    cursor: wait;
    opacity: .55;
}

.cw-contact-form__hint {
    margin-top: 7px;
    color: var(--text-muted);
    font-size: 9px;
    line-height: 1.4;
}

.cw-contact-form__hint a {
    color: var(--accent);
}

.cw-messages {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    overflow-y: auto;
    scrollbar-color: var(--border-subtle) transparent;
    scrollbar-width: thin;
}

.cw-messages::-webkit-scrollbar {
    width: 4px;
}

.cw-messages::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: var(--radius-pill);
}

.cw-msg {
    display: flex;
    max-width: 84%;
    flex-direction: column;
}

.cw-msg--user {
    align-self: flex-end;
    align-items: flex-end;
}

.cw-msg--admin {
    align-self: flex-start;
    align-items: flex-start;
}

.cw-msg__author {
    margin-bottom: 3px;
    padding: 0 4px;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
}

.cw-msg--user .cw-msg__author {
    color: var(--accent);
}

.cw-msg__text {
    padding: 9px 13px;
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.cw-msg--user .cw-msg__text {
    color: #fff;
    background: var(--accent);
    border-bottom-right-radius: 4px;
}

.cw-msg--admin .cw-msg__text {
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: 4px;
}

.cw-msg__time {
    margin-top: 3px;
    padding: 0 4px;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-size: 10px;
    letter-spacing: .02em;
}

.cw-system-message {
    display: flex;
    width: calc(100% - 16px);
    align-self: center;
    align-items: flex-start;
    gap: 7px;
    padding: 8px 10px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 11px;
    line-height: 1.45;
}

.cw-system-message i {
    flex-shrink: 0;
    margin-top: 1px;
    color: var(--accent);
    font-size: 14px;
}

.cw-notice {
    margin: 0 12px 8px;
    padding: 7px 10px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-size: 11px;
    line-height: 1.4;
}

.cw-notice[data-kind="error"] {
    color: var(--danger);
}

.cw-notice[hidden] {
    display: none;
}

.cw-input-wrap {
    display: flex;
    flex-shrink: 0;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px 4px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-subtle);
}

.cw-input {
    min-height: 38px;
    max-height: 96px;
    flex: 1;
    padding: 8px 13px;
    overflow-y: auto;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    outline: none;
    resize: none;
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.4;
    transition: var(--transition);
}

.cw-input::placeholder {
    color: var(--text-muted);
}

.cw-input:focus {
    background: var(--bg-card);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.cw-send-btn {
    display: flex;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--accent);
    border: 0;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px var(--accent-glow);
    cursor: pointer;
    transition: var(--transition);
}

.cw-send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.cw-send-btn:disabled {
    cursor: wait;
    opacity: .55;
}

.cw-send-btn i {
    font-size: 18px;
}

.cw-input-hint {
    flex-shrink: 0;
    padding: 2px 13px 8px;
    color: var(--text-muted);
    background: var(--bg-card);
    font-size: 9px;
    text-align: left;
}

@media (max-width: 480px) {
    .cw-widget {
        right: 12px;
        bottom: 12px;
    }

    .cw-box {
        position: fixed;
        right: 10px;
        bottom: 78px;
        left: 10px;
        width: auto;
        height: min(540px, calc(100dvh - 98px));
    }

    .cw-contact-form__fields {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cw-toggle,
    .cw-send-btn {
        transition: none;
    }
}

/* ── График работы поддержки ─────────────────────────────────────────────── */

.cw-header__hours {
    margin-top: 2px;
    color: rgb(255 255 255 / 62%);
    font-size: 10px;
    letter-spacing: .02em;
}

/* Вне часов работы точка статуса перестаёт быть «живой» */
.cw-header__status[data-open="0"] .cw-header__status-dot {
    background: var(--warning);
    opacity: 1;
}

.cw-hours-notice {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    margin: 0 12px 8px;
    padding: 8px 10px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius-sm);
    font-size: 11px;
    line-height: 1.45;
}

.cw-hours-notice i {
    flex-shrink: 0;
    margin-top: 1px;
    color: var(--warning-text);
    font-size: 14px;
}

.cw-hours-notice[hidden] {
    display: none;
}
