.livechat-widget {
    --livechat-primary: #176b87;
    --livechat-primary-dark: #0f4f63;
    --livechat-accent: #d7a84f;
    --livechat-text: #1f2933;
    --livechat-muted: #667085;
    --livechat-border: #d9e2ec;
    --livechat-surface: #ffffff;
    --livechat-soft: #f5f8fb;
    bottom: 22px;
    font-family: inherit;
    position: fixed;
    right: 22px;
    z-index: 1050;
}

.livechat-widget,
.livechat-widget * {
    box-sizing: border-box;
}

.livechat-toggle {
    align-items: center;
    background: var(--livechat-primary);
    border: 0;
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(15, 79, 99, 0.22);
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    font-size: 13px;
    font-weight: 700;
    gap: 7px;
    min-height: 42px;
    padding: 0 13px 0 7px;
}

.livechat-toggle:hover,
.livechat-toggle:focus {
    background: var(--livechat-primary-dark);
    outline: 3px solid rgba(23, 107, 135, 0.18);
}

.livechat-toggle__icon {
    align-items: center;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    display: inline-flex;
    font-size: 16px;
    height: 30px;
    justify-content: center;
    line-height: 1;
    width: 30px;
}

.livechat-panel {
    background: var(--livechat-surface);
    border: 1px solid var(--livechat-border);
    border-radius: 8px;
    bottom: 54px;
    box-shadow: 0 22px 55px rgba(31, 41, 51, 0.22);
    display: flex;
    flex-direction: column;
    max-height: min(680px, calc(100vh - 110px));
    max-height: min(680px, calc(100dvh - 110px));
    min-height: 420px;
    overflow: hidden;
    position: absolute;
    right: 0;
    width: clamp(320px, 34vw, 390px);
}

.livechat-panel[hidden] {
    display: none;
}

.livechat-panel__header {
    align-items: flex-start;
    background: var(--livechat-primary);
    color: #ffffff;
    display: flex;
    flex: 0 0 auto;
    gap: 16px;
    justify-content: space-between;
    padding: 16px;
}

.livechat-panel__title,
.livechat-panel__subtitle {
    margin: 0;
}

.livechat-panel__title {
    font-size: 17px;
    font-weight: 700;
}

.livechat-panel__subtitle {
    color: rgba(255, 255, 255, 0.86);
    font-size: 13px;
    line-height: 1.35;
    margin-top: 4px;
}

.livechat-panel__close {
    background: transparent;
    border: 0;
    color: #ffffff;
    cursor: pointer;
    font-size: 26px;
    line-height: 1;
    padding: 0;
}

.livechat-messages {
    background: var(--livechat-soft);
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 10px;
    height: clamp(210px, 34vh, 300px);
    min-height: 150px;
    overflow-y: auto;
    padding: 14px;
}

.livechat-message {
    display: flex;
}

.livechat-message--visitor {
    justify-content: flex-end;
}

.livechat-message--admin,
.livechat-message--system {
    justify-content: flex-start;
}

.livechat-message__bubble {
    background: #ffffff;
    border: 1px solid var(--livechat-border);
    border-radius: 8px;
    color: var(--livechat-text);
    font-size: 14px;
    line-height: 1.4;
    max-width: 82%;
    padding: 9px 11px;
    white-space: pre-wrap;
    word-break: break-word;
}

.livechat-message--visitor .livechat-message__bubble {
    background: var(--livechat-primary);
    border-color: var(--livechat-primary);
    color: #ffffff;
}

.livechat-message--system .livechat-message__bubble {
    background: #fff8e8;
    border-color: #f0dca8;
    color: #5d4713;
}

.livechat-message__time {
    display: block;
    font-size: 11px;
    margin-top: 5px;
    opacity: 0.72;
}

.livechat-form {
    display: grid;
    flex: 0 0 auto;
    gap: 10px;
    padding: 14px;
}

.livechat-field {
    display: grid;
    gap: 5px;
    margin: 0;
}

.livechat-field span {
    color: var(--livechat-muted);
    font-size: 12px;
    font-weight: 700;
}

.livechat-field input,
.livechat-field textarea {
    border: 1px solid var(--livechat-border);
    border-radius: 6px;
    color: var(--livechat-text);
    font: inherit;
    font-size: 14px;
    min-height: 40px;
    padding: 9px 10px;
    width: 100%;
}

.livechat-field textarea {
    min-height: 74px;
    resize: vertical;
}

.livechat-field input:focus,
.livechat-field textarea:focus {
    border-color: var(--livechat-primary);
    box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.13);
    outline: 0;
}

.livechat-send {
    background: var(--livechat-primary);
    border: 0;
    border-radius: 6px;
    color: #ffffff;
    cursor: pointer;
    font-weight: 700;
    min-height: 42px;
    padding: 10px 14px;
}

.livechat-send:hover,
.livechat-send:focus {
    background: var(--livechat-primary-dark);
}

.livechat-send:disabled {
    cursor: not-allowed;
    opacity: 0.62;
}

.livechat-error,
.livechat-form-error {
    background: #fff1f1;
    border: 1px solid #f3b6b6;
    border-radius: 6px;
    color: #8a1f1f;
    font-size: 13px;
    padding: 8px 10px;
}

.livechat-closed {
    color: var(--livechat-muted);
    font-size: 13px;
    margin: 0;
    text-align: center;
}

.livechat-dashboard {
    display: grid;
    gap: 18px;
}

.livechat-dashboard__filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.livechat-filter {
    align-items: center;
    background: #ffffff;
    border: 1px solid #d9e2ec;
    border-radius: 6px;
    color: #1f2933;
    display: inline-flex;
    font-weight: 700;
    gap: 8px;
    padding: 9px 12px;
    text-decoration: none;
}

.livechat-filter span {
    background: #edf2f7;
    border-radius: 999px;
    color: #4a5568;
    font-size: 12px;
    min-width: 24px;
    padding: 2px 7px;
    text-align: center;
}

.livechat-filter.is-active {
    background: #176b87;
    border-color: #176b87;
    color: #ffffff;
}

.livechat-filter.is-active span {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

.livechat-table-wrap {
    background: #ffffff;
    border: 1px solid #d9e2ec;
    border-radius: 8px;
    overflow-x: auto;
}

.livechat-table {
    margin-bottom: 0;
    min-width: 900px;
}

.livechat-table th,
.livechat-table td {
    vertical-align: middle;
}

.livechat-table__message {
    max-width: 320px;
}

.livechat-table__actions {
    text-align: right;
    white-space: nowrap;
}

.livechat-muted {
    color: #667085;
    display: block;
    font-size: 12px;
    margin-top: 2px;
}

.livechat-badge,
.livechat-read,
.livechat-unread {
    border-radius: 999px;
    display: inline-flex;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 9px;
}

.livechat-badge--open {
    background: #e8f6ef;
    color: #166534;
}

.livechat-badge--closed {
    background: #edf2f7;
    color: #4a5568;
}

.livechat-read {
    background: #edf2f7;
    color: #475569;
}

.livechat-unread {
    background: #fff1f1;
    color: #a61b1b;
}

.livechat-empty {
    color: #667085;
    padding: 22px;
    text-align: center;
}

.livechat-pagination {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.livechat-dashboard-dock {
    background: #ffffff;
    border: 1px solid #c8d8e2;
    border-radius: 8px;
    bottom: 18px;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.18);
    overflow: hidden;
    position: fixed;
    right: 18px;
    width: min(360px, calc(100vw - 36px));
    z-index: 1040;
}

.livechat-dashboard-dock__head {
    background: #102f3d;
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
    min-height: 38px;
}

.livechat-dashboard-dock__toggle {
    align-items: center;
    background: transparent;
    border: 0;
    color: inherit;
    cursor: pointer;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) auto auto;
    min-height: 38px;
    padding: 9px 12px;
    text-align: left;
    width: 100%;
}

.livechat-dashboard-dock__toggle:hover,
.livechat-dashboard-dock__toggle:focus {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    outline: 0;
}

.livechat-dashboard-dock__title,
.livechat-dashboard-dock__counts {
    align-items: center;
    display: inline-flex;
    gap: 8px;
    min-width: 0;
}

.livechat-dashboard-dock__title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.livechat-dashboard-dock__counts {
    justify-content: flex-end;
}

.livechat-dashboard-dock__count,
.livechat-dashboard-dock__unanswered {
    align-items: center;
    border-radius: 999px;
    display: inline-flex;
    justify-content: center;
    line-height: 1;
    white-space: nowrap;
}

.livechat-dashboard-dock__count {
    background: #ffffff;
    color: #102f3d;
    min-height: 22px;
    min-width: 22px;
    padding: 0 7px;
}

.livechat-dashboard-dock__unanswered {
    background: #f59e0b;
    color: #102f3d;
    font-size: 11px;
    min-height: 22px;
    padding: 0 9px;
}

.livechat-dashboard-dock__unanswered.is-empty {
    background: rgba(255, 255, 255, 0.16);
    color: rgba(255, 255, 255, 0.78);
}

.livechat-dashboard-dock__chevron {
    font-size: 11px;
    transition: transform 160ms ease;
}

.livechat-dashboard-dock.is-collapsed {
    width: min(290px, calc(100vw - 36px));
}

.livechat-dashboard-dock.is-collapsed .livechat-dashboard-dock__body {
    display: none;
}

.livechat-dashboard-dock.is-collapsed .livechat-dashboard-dock__chevron {
    transform: rotate(180deg);
}

.livechat-dashboard-dock__tabs {
    display: grid;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
    padding: 10px;
}

.livechat-dashboard-tab {
    background: #f5f8fb;
    border: 1px solid #d9e2ec;
    border-left: 5px solid #7aa6b8;
    border-radius: 8px;
    color: #1f2933;
    display: grid;
    gap: 4px;
    padding: 9px 10px;
    text-decoration: none;
}

.livechat-dashboard-tab:hover,
.livechat-dashboard-tab:focus {
    background: #eef8fb;
    border-color: #77bdcc;
    color: #102f3d;
    text-decoration: none;
}

.livechat-dashboard-tab.is-unread {
    background: #fff7df;
    border-color: #efc96b;
    border-left-color: #c88408;
}

.livechat-dashboard-tab.is-typing {
    background: #ecfeff;
    border-color: #67d6e0;
    border-left-color: #0891b2;
}

.livechat-dashboard-tab__name {
    font-size: 13px;
    font-weight: 800;
    line-height: 1.2;
}

.livechat-dashboard-tab__meta {
    align-items: center;
    color: #667085;
    display: flex;
    font-size: 11px;
    gap: 7px;
    justify-content: space-between;
}

.livechat-dashboard-tab__meta b {
    background: #c88408;
    border-radius: 999px;
    color: #ffffff;
    font-size: 10px;
    padding: 2px 7px;
}

.livechat-dashboard-tab__message {
    color: #475569;
    font-size: 12px;
    line-height: 1.25;
}

.livechat-dashboard-tab__typing {
    background: rgba(8, 145, 178, 0.1);
    border: 1px solid rgba(8, 145, 178, 0.2);
    border-radius: 6px;
    color: #0e7490;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.25;
    padding: 6px 7px;
}

.livechat-dashboard-tab__typing em {
    color: #164e63;
    font-style: normal;
    font-weight: 700;
}

.livechat-dashboard-dock__all {
    border-top: 1px solid #d9e2ec;
    color: #0f4f63;
    display: block;
    font-size: 12px;
    font-weight: 800;
    padding: 9px 12px;
    text-align: center;
}

.livechat-dashboard-dock__all:hover,
.livechat-dashboard-dock__all:focus {
    background: #eef8fb;
    color: #0f4f63;
    text-decoration: none;
}

.livechat-detail {
    align-items: start;
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(250px, 340px) minmax(0, 1fr);
}

.livechat-detail__info,
.livechat-detail__thread {
    background: #ffffff;
    border: 1px solid #d9e2ec;
    border-radius: 8px;
    padding: 18px;
}

.livechat-detail__info h2 {
    font-size: 18px;
    margin: 0 0 14px;
}

.livechat-detail__info dl {
    display: grid;
    gap: 8px;
    margin: 0;
}

.livechat-detail__info dt {
    color: #667085;
    font-size: 12px;
    font-weight: 700;
}

.livechat-detail__info dd {
    margin: 0 0 8px;
    word-break: break-word;
}

.livechat-user-agent {
    font-size: 12px;
}

.livechat-detail__actions {
    margin-top: 16px;
}

.livechat-thread-tools {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.livechat-thread-tools form {
    margin: 0;
}

.livechat-admin-messages {
    display: grid;
    gap: 12px;
    margin-bottom: 18px;
}

.livechat-admin-message {
    border: 1px solid #d9e2ec;
    border-left-width: 5px;
    border-radius: 8px;
    padding: 12px;
}

.livechat-admin-message--visitor {
    background: #edf6ff;
    border-color: #9ec9ff;
    border-left-color: #2563eb;
}

.livechat-admin-message--admin {
    background: #ecfdf3;
    border-color: #96d8ad;
    border-left-color: #16834a;
}

.livechat-admin-message--system {
    background: #fff7df;
    border-color: #efc96b;
    border-left-color: #c88408;
}

.livechat-admin-message__meta {
    align-items: center;
    color: #667085;
    display: flex;
    font-size: 12px;
    gap: 10px;
    justify-content: space-between;
    margin-bottom: 8px;
}

.livechat-admin-message__tools {
    align-items: center;
    display: inline-flex;
    gap: 8px;
    justify-content: flex-end;
}

.livechat-admin-message__tools form {
    margin: 0;
}

.livechat-admin-message__meta strong {
    border-radius: 999px;
    display: inline-flex;
    font-size: 11px;
    letter-spacing: 0;
    line-height: 1.2;
    padding: 4px 9px;
}

.livechat-admin-message--visitor .livechat-admin-message__meta strong {
    background: #dbeafe;
    color: #1e3a8a;
}

.livechat-admin-message--admin .livechat-admin-message__meta strong {
    background: #d9fbe7;
    color: #14532d;
}

.livechat-admin-message--system .livechat-admin-message__meta strong {
    background: #ffedbd;
    color: #7a4a05;
}

.livechat-bubble-translate {
    align-items: center;
    background: rgba(15, 23, 42, 0.08);
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 999px;
    color: #0f172a;
    cursor: pointer;
    display: inline-flex;
    font-size: 11px;
    font-weight: 700;
    gap: 5px;
    min-height: 26px;
    padding: 4px 9px;
}

.livechat-bubble-translate:hover,
.livechat-bubble-translate:focus {
    background: #0f4f63;
    border-color: #0f4f63;
    color: #ffffff;
    outline: 0;
}

.livechat-admin-message p {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.livechat-message-translation {
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(15, 79, 99, 0.22);
    border-radius: 8px;
    margin-top: 10px;
    padding: 10px;
}

.livechat-message-translation strong {
    color: #0f4f63;
    display: block;
    font-size: 12px;
    margin-bottom: 6px;
}

.livechat-admin-reply {
    display: grid;
    gap: 10px;
}

.livechat-admin-reply label {
    font-weight: 700;
    margin: 0;
}

.livechat-ai-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.livechat-ai-actions .btn {
    white-space: normal;
}

@media (max-width: 760px) {
    .livechat-widget {
        bottom: max(14px, env(safe-area-inset-bottom));
        right: max(14px, env(safe-area-inset-right));
    }

    .livechat-toggle__label {
        display: none;
    }

    .livechat-toggle {
        min-height: 44px;
        padding: 7px;
        width: 44px;
    }

    .livechat-panel {
        bottom: calc(56px + env(safe-area-inset-bottom));
        max-height: calc(100vh - 96px);
        max-height: calc(100dvh - 96px);
        min-height: 0;
        position: fixed;
        right: max(10px, env(safe-area-inset-right));
        width: min(390px, calc(100vw - 20px));
    }

    .livechat-messages {
        height: auto;
        min-height: 150px;
    }

    .livechat-detail {
        grid-template-columns: 1fr;
    }

    .livechat-ai-actions {
        flex-direction: column;
    }

    .livechat-ai-actions .btn {
        width: 100%;
    }

    .livechat-thread-tools,
    .livechat-thread-tools .btn {
        width: 100%;
    }

    .livechat-dashboard-dock {
        bottom: 10px;
        right: 10px;
        width: min(340px, calc(100vw - 20px));
    }

    .livechat-dashboard-dock.is-collapsed {
        width: min(300px, calc(100vw - 20px));
    }

    .livechat-dashboard-dock__toggle {
        grid-template-columns: minmax(0, 1fr) auto auto;
    }

    .livechat-admin-message__meta,
    .livechat-admin-message__tools {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .livechat-panel {
        border-radius: 8px 8px 0 0;
        bottom: calc(54px + env(safe-area-inset-bottom));
        left: max(8px, env(safe-area-inset-left));
        max-height: calc(100vh - 82px);
        max-height: calc(100dvh - 82px);
        right: max(8px, env(safe-area-inset-right));
        width: auto;
    }

    .livechat-panel__header {
        padding: 13px 14px;
    }

    .livechat-panel__title {
        font-size: 16px;
    }

    .livechat-panel__subtitle {
        font-size: 12px;
    }

    .livechat-messages {
        gap: 8px;
        min-height: 120px;
        padding: 12px;
    }

    .livechat-message__bubble {
        max-width: 90%;
        padding: 8px 10px;
    }

    .livechat-form {
        gap: 8px;
        padding: 12px;
    }

    .livechat-field {
        gap: 4px;
    }

    .livechat-field input,
    .livechat-field textarea {
        min-height: 38px;
        padding: 8px 9px;
    }

    .livechat-field textarea {
        min-height: 64px;
    }

    .livechat-send {
        min-height: 40px;
    }
}

@media (max-height: 620px) {
    .livechat-panel {
        bottom: calc(54px + env(safe-area-inset-bottom));
        max-height: calc(100vh - 76px);
        max-height: calc(100dvh - 76px);
    }

    .livechat-panel__header {
        padding-bottom: 11px;
        padding-top: 11px;
    }

    .livechat-panel__subtitle {
        display: none;
    }

    .livechat-messages {
        min-height: 104px;
    }

    .livechat-form {
        gap: 7px;
    }

    .livechat-field span {
        font-size: 11px;
    }

    .livechat-field textarea {
        min-height: 56px;
    }
}
