.telegram-service {
    --telegram-service-shadow: 0 30px 80px rgba(18, 33, 61, 0.14);
    --telegram-service-border: rgba(21, 40, 74, 0.08);
    --telegram-service-ink: #16233d;
    --telegram-service-muted: #5f6f8b;
    --telegram-service-surface: #f7f8fc;
    --telegram-service-surface-strong: #ffffff;
    --telegram-service-soft: #e8edf7;
    position: fixed;
    bottom: var(--telegram-service-bottom);
    z-index: 998;
    font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--telegram-service-ink);
}

.telegram-service--right {
    right: var(--telegram-service-side);
}

.telegram-service--left {
    left: var(--telegram-service-side);
}

.telegram-service__overlay {
    display: none;
}

.telegram-service.is-open .telegram-service__overlay {
    display: none;
}

.telegram-service__button {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 14px;
    min-width: 228px;
    padding: 14px 20px 14px 16px;
    border: 1px solid rgba(21, 40, 74, 0.08);
    border-radius: 999px;
    color: var(--telegram-service-ink);
    background:
        radial-gradient(circle at top left, rgba(90, 132, 255, 0.12), transparent 40%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(246, 249, 255, 0.96));
    box-shadow: 0 18px 42px rgba(34, 72, 159, 0.16);
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.telegram-service__button:hover {
    transform: translateY(-2px);
    border-color: rgba(52, 94, 196, 0.16);
    box-shadow: 0 24px 50px rgba(34, 72, 159, 0.18);
}

.telegram-service__button-pulse {
    position: absolute;
    inset: 0;
    background: linear-gradient(115deg, transparent 18%, rgba(84, 120, 232, 0.08) 50%, transparent 76%);
    transform: translateX(-100%);
    animation: telegramServiceSweep 3.4s ease-in-out infinite;
}

.telegram-service__button-mark,
.telegram-service__button-copy {
    position: relative;
    z-index: 1;
}

.telegram-service__button-mark {
    width: 44px;
    height: 44px;
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    background: linear-gradient(135deg, var(--telegram-service-color), color-mix(in srgb, var(--telegram-service-color) 70%, #76d1ff 30%));
    box-shadow: 0 12px 24px rgba(42, 106, 245, 0.24);
}

.telegram-service__button-mark svg {
    width: 22px;
    height: 22px;
}

.telegram-service__button-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    text-align: left;
}

.telegram-service__button-copy strong {
    font-size: 15px;
    font-weight: 700;
    color: #13233f;
}

.telegram-service__button-copy span {
    font-size: 12px;
    color: var(--telegram-service-muted);
}

.telegram-service__panel {
    position: absolute;
    bottom: 92px;
    width: min(var(--telegram-service-width), calc(100vw - 24px));
    height: min(var(--telegram-service-height), calc(100vh - 130px));
    display: flex;
    flex-direction: column;
    border: 1px solid var(--telegram-service-border);
    border-radius: 28px;
    overflow: hidden;
    background:
        radial-gradient(circle at top right, rgba(64, 116, 255, 0.08), transparent 32%),
        linear-gradient(180deg, #ffffff 0%, #f7f9fd 52%, #f4f7fc 100%);
    box-shadow: var(--telegram-service-shadow);
    opacity: 0;
    transform: translateY(18px) scale(0.97);
    transform-origin: bottom;
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.telegram-service--right .telegram-service__panel {
    right: 0;
}

.telegram-service--left .telegram-service__panel {
    left: 0;
}

.telegram-service.is-open .telegram-service__panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.telegram-service__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 16px;
    color: var(--telegram-service-ink);
    border-bottom: 1px solid rgba(21, 40, 74, 0.06);
    background:
        radial-gradient(circle at top right, rgba(64, 116, 255, 0.09), transparent 32%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(249, 251, 255, 0.96));
}

.telegram-service__brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.telegram-service__avatar {
    width: 48px;
    height: 48px;
    border-radius: 18px;
    object-fit: cover;
    background: linear-gradient(180deg, color-mix(in srgb, var(--telegram-service-color) 16%, #ffffff 84%), #ffffff);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 8px 18px rgba(57, 95, 181, 0.12);
}

.telegram-service__brand-copy {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.telegram-service__brand-copy strong {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.2;
}

.telegram-service__status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 18px;
    font-size: 12px;
    line-height: 1.4;
    color: #6f7f99;
}

.telegram-service__status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 12%, transparent 88%);
}

.telegram-service__status[data-state="good"] {
    color: #2f9a66;
}

.telegram-service__status[data-state="busy"] {
    color: #4d7cff;
}

.telegram-service__status[data-state="warn"] {
    color: #d67c1c;
}

.telegram-service__status[data-state="error"] {
    color: #d05454;
}

.telegram-service__status[data-state="muted"] {
    color: var(--telegram-service-muted);
}

.telegram-service__close {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--telegram-service-muted);
    background: rgba(233, 238, 247, 0.9);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.telegram-service__close:hover {
    color: #334f80;
    background: rgba(224, 232, 245, 1);
}

.telegram-service__close svg {
    width: 18px;
    height: 18px;
}

.telegram-service__messages {
    flex: 1;
    min-height: 0;
    padding: 18px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background:
        radial-gradient(circle at top left, rgba(82, 128, 255, 0.05), transparent 24%),
        radial-gradient(circle at bottom right, rgba(72, 193, 255, 0.05), transparent 24%),
        linear-gradient(180deg, #ffffff 0%, #f8fafe 100%);
}

.telegram-service__bubble {
    max-width: min(82%, 320px);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.telegram-service__bubble-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 13px 14px;
    border-radius: 20px;
    line-height: 1.65;
    word-break: break-word;
    overflow-wrap: anywhere;
    box-shadow: 0 10px 24px rgba(23, 37, 66, 0.08);
}

.telegram-service__bubble--visitor {
    margin-left: auto;
    align-items: flex-end;
}

.telegram-service__bubble--agent {
    margin-right: auto;
    align-items: flex-start;
}

.telegram-service__bubble--system {
    max-width: 100%;
    margin: 0 auto;
    align-items: center;
}

.telegram-service__bubble--visitor .telegram-service__bubble-box {
    border-bottom-right-radius: 8px;
    color: #fff;
    background: linear-gradient(145deg, var(--telegram-service-color), color-mix(in srgb, var(--telegram-service-color) 76%, #7dbfff 24%));
}

.telegram-service__bubble--agent .telegram-service__bubble-box {
    border: 1px solid rgba(21, 40, 74, 0.06);
    border-bottom-left-radius: 8px;
    color: var(--telegram-service-ink);
    background: rgba(255, 255, 255, 0.94);
}

.telegram-service__bubble--system .telegram-service__bubble-box {
    color: var(--telegram-service-muted);
    background: rgba(255, 255, 255, 0.9);
}

.telegram-service__bubble--pending {
    opacity: 0.8;
}

.telegram-service__bubble--failed .telegram-service__bubble-box {
    border: 1px solid rgba(196, 90, 64, 0.18);
    box-shadow: 0 10px 24px rgba(196, 90, 64, 0.12);
}

.telegram-service__bubble-box img,
.telegram-service__bubble-box video {
    width: 100%;
    max-width: 264px;
    border-radius: 14px;
    display: block;
    border: 1px solid rgba(21, 40, 74, 0.06);
    background: #ffffff;
}

.telegram-service__bubble-box video {
    max-height: 260px;
}

.telegram-service__file {
    width: 100%;
    min-width: 0;
    padding: 12px 13px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    box-sizing: border-box;
}

.telegram-service__bubble--visitor .telegram-service__file {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.14);
}

.telegram-service__bubble--agent .telegram-service__file,
.telegram-service__bubble--system .telegram-service__file,
.telegram-service__bubble--failed .telegram-service__file {
    color: var(--telegram-service-ink);
    background: #f4f7fc;
}

.telegram-service__file-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    background: rgba(255, 255, 255, 0.14);
}

.telegram-service__bubble--agent .telegram-service__file-icon,
.telegram-service__bubble--system .telegram-service__file-icon,
.telegram-service__bubble--failed .telegram-service__file-icon {
    background: rgba(82, 118, 202, 0.1);
}

.telegram-service__file-icon svg {
    width: 22px;
    height: 22px;
}

.telegram-service__file-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.telegram-service__file-name {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.45;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.telegram-service__file-hint {
    font-size: 11px;
    line-height: 1.35;
    opacity: 0.72;
}

.telegram-service__meta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
    font-size: 11px;
    line-height: 1.4;
    color: #96a2b6;
}

.telegram-service__bubble--visitor .telegram-service__meta {
    justify-content: flex-end;
    text-align: right;
}

.telegram-service__bubble--system .telegram-service__meta {
    justify-content: center;
}

.telegram-service__meta-time {
    white-space: nowrap;
}

.telegram-service__meta-state {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #4d7cff;
    background: rgba(77, 124, 255, 0.12);
}

.telegram-service__meta-state--failed {
    color: #8d4c3d;
    background: rgba(196, 90, 64, 0.12);
}

.telegram-service__composer {
    display: block;
    padding: 8px 14px 12px;
    border-top: 1px solid rgba(21, 40, 74, 0.08);
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
}

.telegram-service__composer-main {
    min-width: 0;
}

.telegram-service__input-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 0 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.telegram-service__input-shell:focus-within {
    border-color: transparent;
    box-shadow: none;
}

.telegram-service__input {
    flex: 1;
    min-height: 48px;
    max-height: 108px;
    padding: 0;
    border: 0;
    border-radius: 0;
    resize: none;
    outline: none;
    color: var(--telegram-service-ink);
    background: transparent;
    font: inherit;
    font-size: 16px;
    line-height: 1.62;
    box-sizing: border-box;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    transition: color 0.2s ease;
}

.telegram-service__input:focus {
    border-color: transparent;
    box-shadow: none;
}

.telegram-service__input::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.telegram-service__input::placeholder {
    color: #98a3b7;
}

.telegram-service__composer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.telegram-service__tools {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.telegram-service__tool {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #8591a5;
    background: transparent;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.telegram-service__tool:hover,
.telegram-service__tool[aria-expanded="true"] {
    color: #5f6f8b;
    background: rgba(232, 238, 248, 0.7);
}

.telegram-service__tool svg {
    width: 29px;
    height: 29px;
}

.telegram-service__emoji-panel {
    position: absolute;
    left: 0;
    bottom: calc(100% + 12px);
    z-index: 4;
    width: min(100%, 440px);
    max-height: min(360px, 56vh);
    padding: 14px;
    box-sizing: border-box;
    border: 1px solid rgba(21, 40, 74, 0.08);
    border-radius: 28px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(246, 249, 255, 0.98)),
        radial-gradient(circle at top right, rgba(94, 142, 255, 0.08), transparent 38%);
    box-shadow: 0 24px 48px rgba(28, 51, 97, 0.16);
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 8px;
    align-content: start;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

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

.telegram-service__emoji-panel::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.telegram-service__emoji-item {
    aspect-ratio: 1;
    border: 0;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 26px;
    line-height: 1;
    background: rgba(241, 245, 252, 0.92);
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.telegram-service__emoji-item:hover {
    background: rgba(225, 233, 248, 0.98);
    transform: translateY(-1px) scale(1.04);
    box-shadow: 0 8px 18px rgba(52, 90, 170, 0.14);
}

.telegram-service__send {
    width: 122px;
    height: 56px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(140deg, var(--telegram-service-color), color-mix(in srgb, var(--telegram-service-color) 74%, #78d2ff 26%));
    box-shadow: 0 12px 22px rgba(46, 96, 215, 0.24);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.telegram-service__send:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 28px rgba(46, 96, 215, 0.28);
}

.telegram-service__send svg {
    width: 22px;
    height: 22px;
}

.telegram-service__empty {
    margin: auto;
    max-width: 320px;
    padding: 18px 20px;
    border: 1px solid rgba(21, 40, 74, 0.06);
    border-radius: 22px;
    text-align: left;
    font-size: 13px;
    line-height: 1.7;
    color: var(--telegram-service-muted);
    background: #ffffff;
    box-shadow: 0 12px 28px rgba(21, 40, 74, 0.08);
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.telegram-service__empty--notice {
    color: #8b4331;
    background: linear-gradient(180deg, rgba(255, 244, 240, 0.98), rgba(255, 248, 245, 0.96));
    border-color: rgba(189, 108, 81, 0.12);
}

.telegram-service__tool:disabled,
.telegram-service__send:disabled,
.telegram-service__input:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

html.telegram-service-mobile-open,
body.telegram-service-mobile-open {
    overflow: hidden;
}

@keyframes telegramServiceSweep {
    0% {
        transform: translateX(-120%);
    }
    50% {
        transform: translateX(120%);
    }
    100% {
        transform: translateX(120%);
    }
}

@media (max-width: 640px) {
    .telegram-service {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        left: 12px;
        right: 12px;
        bottom: 14px;
    }

    .telegram-service--left,
    .telegram-service--right {
        left: 12px;
        right: 12px;
    }

    .telegram-service__button {
        width: auto;
        min-width: 0;
        padding: 0;
        border-radius: 22px;
        justify-content: center;
        box-shadow: 0 16px 38px rgba(34, 72, 159, 0.18);
    }

    .telegram-service__button-copy {
        display: none;
    }

    .telegram-service__button-mark {
        width: 54px;
        height: 54px;
        border-radius: 22px;
        margin: 4px;
    }

    .telegram-service__button-mark svg {
        width: 24px;
        height: 24px;
    }

    .telegram-service__panel {
        left: 0;
        right: 0;
        width: auto;
        bottom: 82px;
        height: min(var(--telegram-service-height), calc(100vh - 116px));
        border-radius: 24px;
    }

    .telegram-service.is-open {
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        align-items: stretch;
        z-index: 999;
    }

    .telegram-service.is-open .telegram-service__button {
        opacity: 0;
        pointer-events: none;
        transform: translateY(10px);
    }

    .telegram-service.is-open .telegram-service__panel {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        bottom: auto;
        left: 0;
        right: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .telegram-service.is-open .telegram-service__header {
        padding-top: calc(18px + env(safe-area-inset-top, 0px));
    }

    .telegram-service.is-open .telegram-service__messages {
        padding-bottom: 16px;
    }

    .telegram-service.is-open .telegram-service__composer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .telegram-service__bubble {
        max-width: 88%;
    }

    .telegram-service__composer {
        padding: 6px 12px 10px;
    }

    .telegram-service__input-shell {
        gap: 8px;
        padding: 8px 0 0;
    }

    .telegram-service__emoji-panel {
        width: min(100%, 360px);
        max-height: min(300px, 46vh);
        grid-template-columns: repeat(7, minmax(0, 1fr));
        gap: 8px;
    }

    .telegram-service__tool {
        width: 40px;
        height: 40px;
        border-radius: 12px;
    }

    .telegram-service__tool svg {
        width: 26px;
        height: 26px;
    }

    .telegram-service__composer-toolbar {
        gap: 12px;
    }

    .telegram-service__tools {
        gap: 4px;
    }

    .telegram-service__input {
        min-height: 44px;
        font-size: 15px;
    }

    .telegram-service__send {
        width: 92px;
        height: 50px;
    }
}
