.chat-widget {
    --chat-accent: #ef4056;
    --chat-surface: #ffffff;
    --chat-border: #e4e7ec;
    --chat-text: #212121;
    --chat-muted: #757575;
    position: fixed;
    left: 20px;
    bottom: 20px;
    z-index: 1060;
    font-family: var(--font-yekan-bakh, 'Yekan Bakh', sans-serif);
}

.chat-widget__toggle {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--chat-accent);
    color: #fff;
    box-shadow: 0 8px 24px rgba(239, 64, 86, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-widget__toggle:hover {
    transform: scale(1.05);
}

.chat-widget__toggle-icon {
    font-size: 26px;
    line-height: 1;
}

.chat-widget__toggle-icon--close {
    display: none;
}

.chat-widget.is-open .chat-widget__toggle-icon--open {
    display: none;
}

.chat-widget.is-open .chat-widget__toggle-icon--close {
    display: block;
}

.chat-widget__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #212529;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

.chat-widget__panel {
    position: absolute;
    left: 0;
    bottom: 72px;
    width: min(380px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 120px));
    background: var(--chat-surface);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.14);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--chat-border);
}

.chat-widget__header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 20px;
    background: var(--chat-surface);
    flex-shrink: 0;
    border-bottom: 1px solid var(--chat-border);
}

.chat-widget__brand {
    display: flex;
    align-items: center;
    min-width: 0;
}

.chat-widget__header-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.chat-widget__title {
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-text);
    line-height: 1.2;
}

.chat-widget__status {
    display: block;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    color: var(--chat-muted);
}

.chat-widget__header-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.chat-widget__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--chat-text);
    cursor: pointer;
    font-size: 22px;
}

.chat-widget__close:hover {
    background: #f3f3f3;
}

.chat-widget__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--chat-surface);
}

.chat-widget__messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-widget__date-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0;
    font-size: 0.875rem;
    color: var(--chat-muted);
}

.chat-widget__date-divider::before,
.chat-widget__date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e0e0e0;
}

.chat-widget__date-divider span {
    flex-shrink: 0;
}

.chat-widget__message-row {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    width: max-content;
    gap: 4px;
}

.chat-widget__message-row--customer {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-widget__message-row--admin {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-widget__message-time {
    margin: 0;
    padding: 0 4px;
    font-size: 11px;
    line-height: 1.4;
    font-weight: 500;
    color: #667085;
    white-space: nowrap;
}

.chat-widget__message {
    box-sizing: border-box;
    width: max-content;
    max-width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.6;
    word-break: normal;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.chat-widget__message-text {
    margin: 0;
    font-size: inherit;
    line-height: inherit;
}

.chat-widget__message--customer {
    background: #465fff;
    color: #fff;
    border-radius: 8px 8px 8px 4px;
}

.chat-widget__message--admin {
    background: #f2f4f7;
    color: #1d2939;
    border-radius: 8px 8px 4px 8px;
}

.chat-widget__message--system {
    align-self: center;
    background: transparent;
    color: var(--chat-muted);
    font-size: 12px;
    max-width: 95%;
    text-align: center;
    padding: 4px 8px;
}

.chat-widget__composer {
    padding: 4px 20px calc(20px + env(safe-area-inset-bottom, 0px));
    background: transparent;
    flex-shrink: 0;
}

.chat-widget__composer-form {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 8px 14px;
    border-radius: 7px;
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
}

.chat-widget__composer-input {
    flex: 1;
    min-width: 0;
    height: 32px;
    border: none;
    background: transparent;
    padding: 0 4px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    color: var(--chat-text);
    font-family: inherit;
    outline: none;
}

.chat-widget__composer-input::placeholder {
    color: var(--chat-muted);
    opacity: 0.7;
    font-weight: 500;
}

.chat-widget__composer-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 0;
    padding-inline-start: 10px;
}

.chat-widget__composer-emoji,
.chat-widget__composer-action,
.chat-widget__send {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 6px;
}

.chat-widget__composer-action {
    margin-inline-end: 8px;
}

.chat-widget__composer-emoji,
.chat-widget__composer-action {
    color: var(--chat-text);
    opacity: 0.85;
    transition: opacity 0.15s ease;
}

.chat-widget__composer-emoji:hover,
.chat-widget__composer-action:hover {
    opacity: 1;
}

.chat-widget__send {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    margin-inline-start: 12px;
    color: #fff;
    background: #465fff;
    flex-shrink: 0;
    border-radius: 8px;
    transition: background 0.15s ease;
}

.chat-widget__send:hover {
    background: #3641f5;
}

.chat-widget__send svg {
    transform: scaleX(-1);
}

@media (max-width: 991.98px) {
    .chat-widget {
        bottom: 86px;
    }

    .chat-widget.is-open {
        inset: 0;
    }

    .chat-widget.is-open .chat-widget__toggle {
        display: none;
    }

    .chat-widget__panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
        border: none;
        box-shadow: none;
    }

    .chat-widget__header {
        padding-top: calc(20px + env(safe-area-inset-top, 0px));
    }

    body.chat-widget-open,
    html.chat-widget-open {
        overflow: hidden;
        overscroll-behavior: none;
    }

    body.chat-widget-open {
        position: fixed;
        left: 0;
        right: 0;
        width: 100%;
    }

    html.chat-widget-restoring,
    html.chat-widget-restoring body {
        scroll-behavior: auto !important;
    }

    html.chat-widget-open .chat-widget.is-open .chat-widget__messages {
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 575.98px) {
    .chat-widget {
        left: 12px;
        bottom: 82px;
    }
}
