/* ============================================================
 * TelegramService 客服组件样式
 * 设计令牌化：浅色 / 深色 / 跟随系统 三套由 data-theme 驱动，
 * 所有组件只引用令牌，不写死颜色。
 * ============================================================ */

.telegram-service {
    /* —— 浅色令牌（默认） —— */
    --tgs-ink: #16233d;
    --tgs-ink-strong: #0f1c33;
    --tgs-muted: #5f6f8b;
    --tgs-faint: #96a2b6;
    --tgs-border: rgba(21, 40, 74, 0.08);
    --tgs-border-soft: rgba(21, 40, 74, 0.06);
    --tgs-surface: #ffffff;
    --tgs-surface-veil: rgba(255, 255, 255, 0.94);
    --tgs-surface-dim: #f4f7fc;
    --tgs-panel-bg:
        radial-gradient(circle at top right, color-mix(in srgb, var(--telegram-service-color) 9%, transparent), transparent 34%),
        linear-gradient(180deg, #ffffff 0%, #f7f9fd 52%, #f4f7fc 100%);
    --tgs-header-bg:
        radial-gradient(circle at top right, color-mix(in srgb, var(--telegram-service-color) 10%, transparent), transparent 36%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(249, 251, 255, 0.95));
    --tgs-messages-bg:
        radial-gradient(circle at top left, color-mix(in srgb, var(--telegram-service-color) 5%, transparent), transparent 26%),
        radial-gradient(circle at bottom right, rgba(72, 193, 255, 0.05), transparent 26%),
        linear-gradient(180deg, #ffffff 0%, #f8fafe 100%);
    --tgs-composer-bg: rgba(255, 255, 255, 0.96);
    --tgs-bubble-agent-bg: rgba(255, 255, 255, 0.96);
    --tgs-bubble-system-bg: rgba(255, 255, 255, 0.9);
    --tgs-chip-bg: rgba(233, 238, 247, 0.92);
    --tgs-chip-bg-hover: rgba(224, 232, 245, 1);
    --tgs-shadow-panel: 0 12px 32px rgba(18, 33, 61, 0.08), 0 32px 80px rgba(18, 33, 61, 0.14);
    --tgs-shadow-bubble: 0 8px 22px rgba(23, 37, 66, 0.07);
    --tgs-shadow-float: 0 18px 42px rgba(34, 72, 159, 0.16);
    --tgs-good: #2f9a66;
    --tgs-busy: #4d7cff;
    --tgs-warn: #d67c1c;
    --tgs-error: #d05454;
    --tgs-scrollbar: rgba(21, 40, 74, 0.16);

    position: fixed;
    bottom: var(--telegram-service-bottom);
    z-index: 998;
    font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--tgs-ink);
}

/* —— 深色令牌 —— */
.telegram-service[data-theme="dark"] {
    --tgs-ink: #e6ecf8;
    --tgs-ink-strong: #f4f7ff;
    --tgs-muted: #9aa8c2;
    --tgs-faint: #6d7c97;
    --tgs-border: rgba(255, 255, 255, 0.09);
    --tgs-border-soft: rgba(255, 255, 255, 0.06);
    --tgs-surface: #1b2232;
    --tgs-surface-veil: rgba(30, 38, 56, 0.94);
    --tgs-surface-dim: #232c40;
    --tgs-panel-bg:
        radial-gradient(circle at top right, color-mix(in srgb, var(--telegram-service-color) 16%, transparent), transparent 36%),
        linear-gradient(180deg, #1c2434 0%, #161d2b 60%, #141a27 100%);
    --tgs-header-bg:
        radial-gradient(circle at top right, color-mix(in srgb, var(--telegram-service-color) 18%, transparent), transparent 40%),
        linear-gradient(180deg, rgba(32, 41, 60, 0.98), rgba(26, 33, 49, 0.96));
    --tgs-messages-bg:
        radial-gradient(circle at top left, color-mix(in srgb, var(--telegram-service-color) 8%, transparent), transparent 28%),
        linear-gradient(180deg, #182031 0%, #151c2a 100%);
    --tgs-composer-bg: rgba(27, 34, 50, 0.96);
    --tgs-bubble-agent-bg: rgba(38, 47, 68, 0.96);
    --tgs-bubble-system-bg: rgba(34, 42, 61, 0.9);
    --tgs-chip-bg: rgba(52, 62, 86, 0.9);
    --tgs-chip-bg-hover: rgba(62, 74, 102, 1);
    --tgs-shadow-panel: 0 12px 32px rgba(0, 0, 0, 0.32), 0 32px 80px rgba(0, 0, 0, 0.42);
    --tgs-shadow-bubble: 0 8px 22px rgba(0, 0, 0, 0.24);
    --tgs-shadow-float: 0 18px 42px rgba(0, 0, 0, 0.4);
    --tgs-scrollbar: rgba(255, 255, 255, 0.16);
}

@media (prefers-color-scheme: dark) {
    .telegram-service[data-theme="auto"] {
        --tgs-ink: #e6ecf8;
        --tgs-ink-strong: #f4f7ff;
        --tgs-muted: #9aa8c2;
        --tgs-faint: #6d7c97;
        --tgs-border: rgba(255, 255, 255, 0.09);
        --tgs-border-soft: rgba(255, 255, 255, 0.06);
        --tgs-surface: #1b2232;
        --tgs-surface-veil: rgba(30, 38, 56, 0.94);
        --tgs-surface-dim: #232c40;
        --tgs-panel-bg:
            radial-gradient(circle at top right, color-mix(in srgb, var(--telegram-service-color) 16%, transparent), transparent 36%),
            linear-gradient(180deg, #1c2434 0%, #161d2b 60%, #141a27 100%);
        --tgs-header-bg:
            radial-gradient(circle at top right, color-mix(in srgb, var(--telegram-service-color) 18%, transparent), transparent 40%),
            linear-gradient(180deg, rgba(32, 41, 60, 0.98), rgba(26, 33, 49, 0.96));
        --tgs-messages-bg:
            radial-gradient(circle at top left, color-mix(in srgb, var(--telegram-service-color) 8%, transparent), transparent 28%),
            linear-gradient(180deg, #182031 0%, #151c2a 100%);
        --tgs-composer-bg: rgba(27, 34, 50, 0.96);
        --tgs-bubble-agent-bg: rgba(38, 47, 68, 0.96);
        --tgs-bubble-system-bg: rgba(34, 42, 61, 0.9);
        --tgs-chip-bg: rgba(52, 62, 86, 0.9);
        --tgs-chip-bg-hover: rgba(62, 74, 102, 1);
        --tgs-shadow-panel: 0 12px 32px rgba(0, 0, 0, 0.32), 0 32px 80px rgba(0, 0, 0, 0.42);
        --tgs-shadow-bubble: 0 8px 22px rgba(0, 0, 0, 0.24);
        --tgs-shadow-float: 0 18px 42px rgba(0, 0, 0, 0.4);
        --tgs-scrollbar: rgba(255, 255, 255, 0.16);
    }
}

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

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

.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 var(--tgs-border);
    border-radius: 999px;
    color: var(--tgs-ink);
    background:
        radial-gradient(circle at top left, color-mix(in srgb, var(--telegram-service-color) 12%, transparent), transparent 40%),
        linear-gradient(180deg, var(--tgs-surface-veil), var(--tgs-surface));
    box-shadow: var(--tgs-shadow-float);
    cursor: pointer;
    overflow: visible;
    transition: transform 0.22s cubic-bezier(0.34, 1.3, 0.5, 1), box-shadow 0.22s ease, border-color 0.22s ease;
}

.telegram-service__button:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--telegram-service-color) 24%, transparent);
}

.telegram-service__button:active {
    transform: translateY(0) scale(0.985);
}

.telegram-service__button-pulse {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    overflow: hidden;
    pointer-events: none;
}

.telegram-service__button-pulse::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(115deg, transparent 18%, color-mix(in srgb, var(--telegram-service-color) 10%, transparent) 50%, transparent 76%);
    transform: translateX(-120%);
    animation: telegramServiceSweep 3.6s 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 10px 22px color-mix(in srgb, var(--telegram-service-color) 32%, transparent);
}

.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: var(--tgs-ink-strong);
}

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

/* 未读角标 */
.telegram-service__unread {
    position: absolute;
    top: -6px;
    right: -4px;
    z-index: 2;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    color: #ffffff;
    background: linear-gradient(160deg, #ff5f6d, #e6455e);
    box-shadow: 0 6px 14px rgba(230, 69, 94, 0.4), 0 0 0 2.5px var(--tgs-surface);
    box-sizing: border-box;
    animation: telegramServicePop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

/* ============================================================
 * 面板
 * ============================================================ */
.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(--tgs-border);
    border-radius: 28px;
    overflow: hidden;
    background: var(--tgs-panel-bg);
    box-shadow: var(--tgs-shadow-panel);
    opacity: 0;
    transform: translateY(18px) scale(0.97);
    transform-origin: bottom;
    pointer-events: none;
    transition: opacity 0.24s ease, transform 0.26s cubic-bezier(0.34, 1.2, 0.5, 1);
}

.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(--tgs-ink);
    border-bottom: 1px solid var(--tgs-border-soft);
    background: var(--tgs-header-bg);
}

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

.telegram-service__avatar-shell {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
}

.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%, var(--tgs-surface) 84%), var(--tgs-surface));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 8px 18px rgba(57, 95, 181, 0.12);
}

/* 在线呼吸点 */
.telegram-service__presence {
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--tgs-good);
    box-shadow: 0 0 0 2.5px var(--tgs-surface);
    animation: telegramServiceBreathe 2.6s ease-in-out infinite;
}

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

.telegram-service__brand-copy strong {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--tgs-ink-strong);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.telegram-service__status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 18px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--tgs-muted);
    transition: color 0.25s ease;
}

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

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

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

.telegram-service__status[data-state="busy"]::before,
.telegram-service__status[data-state="warn"]::before {
    animation: telegramServiceBlink 1.1s ease-in-out infinite;
}

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

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

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

.telegram-service__close {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--tgs-muted);
    background: var(--tgs-chip-bg);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.telegram-service__close:hover {
    color: var(--tgs-ink);
    background: var(--tgs-chip-bg-hover);
    transform: rotate(90deg);
}

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

/* ============================================================
 * 错误横幅（开窗自愈提示，不覆盖消息区）
 * ============================================================ */
.telegram-service__notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 10px 14px 0;
    padding: 10px 12px;
    border: 1px solid color-mix(in srgb, var(--tgs-warn) 26%, transparent);
    border-radius: 14px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--tgs-warn);
    background: color-mix(in srgb, var(--tgs-warn) 8%, var(--tgs-surface));
    animation: telegramServiceRise 0.24s ease;
}

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

.telegram-service__notice-text {
    min-width: 0;
    word-break: break-word;
}

.telegram-service__notice-retry {
    flex: 0 0 auto;
    border: 1px solid color-mix(in srgb, var(--tgs-warn) 36%, transparent);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--tgs-warn);
    background: transparent;
    cursor: pointer;
    transition: background 0.18s ease;
}

.telegram-service__notice-retry:hover {
    background: color-mix(in srgb, var(--tgs-warn) 12%, transparent);
}

/* ============================================================
 * 消息区
 * ============================================================ */
.telegram-service__messages-shell {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.telegram-service__messages {
    flex: 1;
    min-height: 0;
    padding: 18px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--tgs-messages-bg);
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--tgs-scrollbar) transparent;
}

.telegram-service__messages::-webkit-scrollbar {
    width: 5px;
}

.telegram-service__messages::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: var(--tgs-scrollbar);
}

.telegram-service__messages::-webkit-scrollbar-track {
    background: transparent;
}

/* 「N 条新消息」浮标：用户在翻历史时不抢滚动位置 */
.telegram-service__jump {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    z-index: 3;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border: 1px solid var(--tgs-border);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: var(--telegram-service-color);
    background: var(--tgs-surface-veil);
    box-shadow: 0 10px 26px rgba(23, 37, 66, 0.16);
    backdrop-filter: blur(10px);
    cursor: pointer;
    animation: telegramServiceRise 0.26s cubic-bezier(0.34, 1.3, 0.5, 1);
}

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

.telegram-service__jump svg {
    width: 15px;
    height: 15px;
}

/* ============================================================
 * 气泡
 * ============================================================ */
.telegram-service__bubble {
    max-width: min(82%, 320px);
    display: flex;
    flex-direction: column;
    gap: 6px;
    animation: telegramServiceBubbleIn 0.28s cubic-bezier(0.26, 1.1, 0.48, 1);
}

.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: var(--tgs-shadow-bubble);
}

.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: #ffffff;
    background: linear-gradient(145deg, var(--telegram-service-color), color-mix(in srgb, var(--telegram-service-color) 76%, #7dbfff 24%));
    box-shadow: 0 8px 22px color-mix(in srgb, var(--telegram-service-color) 24%, transparent);
}

.telegram-service__bubble--agent .telegram-service__bubble-box {
    border: 1px solid var(--tgs-border-soft);
    border-bottom-left-radius: 8px;
    color: var(--tgs-ink);
    background: var(--tgs-bubble-agent-bg);
}

.telegram-service__bubble--system .telegram-service__bubble-box {
    color: var(--tgs-muted);
    background: var(--tgs-bubble-system-bg);
}

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

.telegram-service__bubble--failed .telegram-service__bubble-box {
    border: 1px solid rgba(196, 90, 64, 0.22);
    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 var(--tgs-border-soft);
    background: var(--tgs-surface);
}

.telegram-service__bubble-box img[data-role="zoomable"] {
    cursor: zoom-in;
    transition: filter 0.2s ease;
}

.telegram-service__bubble-box img[data-role="zoomable"]:hover {
    filter: brightness(0.94);
}

.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;
    transition: background 0.18s ease;
}

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

.telegram-service__bubble--visitor .telegram-service__file:hover {
    background: rgba(255, 255, 255, 0.2);
}

.telegram-service__bubble--agent .telegram-service__file,
.telegram-service__bubble--system .telegram-service__file,
.telegram-service__bubble--failed .telegram-service__file {
    color: var(--tgs-ink);
    background: var(--tgs-surface-dim);
}

.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 {
    color: var(--telegram-service-color);
    background: color-mix(in srgb, var(--telegram-service-color) 10%, transparent);
}

.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: var(--tgs-faint);
}

.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: var(--tgs-busy);
    background: color-mix(in srgb, var(--tgs-busy) 12%, transparent);
}

.telegram-service__meta-state--failed {
    color: var(--tgs-error);
    background: color-mix(in srgb, var(--tgs-error) 12%, transparent);
}

.telegram-service__meta-retry {
    border: 0;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    color: #ffffff;
    background: var(--telegram-service-color);
    cursor: pointer;
    transition: transform 0.16s ease, opacity 0.16s ease;
}

.telegram-service__meta-retry:hover {
    opacity: 0.88;
    transform: translateY(-1px);
}

/* ============================================================
 * 输入区
 * ============================================================ */
.telegram-service__composer {
    display: block;
    padding: 8px 14px 12px;
    border-top: 1px solid var(--tgs-border);
    background: var(--tgs-composer-bg);
    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;
}

.telegram-service__input {
    flex: 1;
    min-height: 48px;
    max-height: 108px;
    padding: 0;
    border: 0;
    resize: none;
    outline: none;
    color: var(--tgs-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;
}

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

.telegram-service__input::placeholder {
    color: var(--tgs-faint);
}

.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: var(--tgs-faint);
    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: var(--telegram-service-color);
    background: color-mix(in srgb, var(--telegram-service-color) 8%, transparent);
}

.telegram-service__tool:active {
    transform: scale(0.92);
}

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

/* 字数统计（接近上限时出现） */
.telegram-service__counter {
    align-self: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: var(--tgs-muted);
    background: var(--tgs-chip-bg);
}

.telegram-service__counter.is-over {
    color: var(--tgs-error);
    background: color-mix(in srgb, var(--tgs-error) 12%, transparent);
}

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

.telegram-service__send {
    width: 116px;
    height: 54px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    background: linear-gradient(140deg, var(--telegram-service-color), color-mix(in srgb, var(--telegram-service-color) 74%, #78d2ff 26%));
    box-shadow: 0 12px 22px color-mix(in srgb, var(--telegram-service-color) 30%, transparent);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.3, 0.5, 1), box-shadow 0.2s ease, filter 0.2s ease;
}

.telegram-service__send:hover {
    transform: translateY(-1px);
    filter: brightness(1.04);
}

.telegram-service__send:active {
    transform: translateY(0) scale(0.96);
}

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

/* ============================================================
 * 表情面板
 * ============================================================ */
.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 var(--tgs-border);
    border-radius: 28px;
    background: var(--tgs-surface-veil);
    backdrop-filter: blur(14px);
    box-shadow: var(--tgs-shadow-panel);
    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;
    animation: telegramServiceRise 0.22s cubic-bezier(0.34, 1.2, 0.5, 1);
}

.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: var(--tgs-chip-bg);
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.telegram-service__emoji-item:hover {
    background: var(--tgs-chip-bg-hover);
    transform: translateY(-1px) scale(1.04);
    box-shadow: 0 8px 18px rgba(52, 90, 170, 0.14);
}

/* ============================================================
 * 空态
 * ============================================================ */
.telegram-service__empty {
    margin: auto;
    max-width: 320px;
    padding: 18px 20px;
    border: 1px solid var(--tgs-border-soft);
    border-radius: 22px;
    text-align: left;
    font-size: 13px;
    line-height: 1.7;
    color: var(--tgs-muted);
    background: var(--tgs-surface);
    box-shadow: var(--tgs-shadow-bubble);
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.telegram-service__empty--notice {
    color: var(--tgs-error);
    background: color-mix(in srgb, var(--tgs-error) 6%, var(--tgs-surface));
    border-color: color-mix(in srgb, var(--tgs-error) 16%, transparent);
}

/* ============================================================
 * 图片灯箱
 * ============================================================ */
.telegram-service__lightbox {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4vmin;
    background: rgba(10, 15, 26, 0.82);
    backdrop-filter: blur(6px);
    cursor: zoom-out;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.telegram-service__lightbox.is-visible {
    opacity: 1;
}

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

.telegram-service__lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
    animation: telegramServicePop 0.24s cubic-bezier(0.34, 1.3, 0.5, 1);
}

/* ============================================================
 * 禁用态 / 动画 / 无障碍
 * ============================================================ */
.telegram-service__tool:disabled,
.telegram-service__send:disabled,
.telegram-service__input:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.telegram-service__send:disabled {
    transform: none;
    filter: grayscale(0.3);
}

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

/* —— 手机端悬浮按钮拖动 —— */
.telegram-service.is-dragging,
.telegram-service.is-dragging .telegram-service__button {
    transition: none !important;
}

.telegram-service.is-dragging .telegram-service__button {
    transform: scale(1.06);
    box-shadow: 0 26px 56px rgba(18, 33, 61, 0.3);
    cursor: grabbing;
}

.telegram-service.is-dragging .telegram-service__button-pulse::before {
    animation: none;
}

.telegram-service.is-snapping {
    transition: left 0.24s cubic-bezier(0.3, 1.1, 0.4, 1);
}

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

@keyframes telegramServiceBubbleIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes telegramServiceRise {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes telegramServicePop {
    from {
        opacity: 0;
        transform: scale(0.6);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes telegramServiceBreathe {
    0%, 100% {
        box-shadow: 0 0 0 2.5px var(--tgs-surface), 0 0 0 0 color-mix(in srgb, var(--tgs-good) 40%, transparent);
    }
    50% {
        box-shadow: 0 0 0 2.5px var(--tgs-surface), 0 0 0 5px color-mix(in srgb, var(--tgs-good) 0%, transparent);
    }
}

@keyframes telegramServiceBlink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.35;
    }
}

@media (prefers-reduced-motion: reduce) {
    .telegram-service *,
    .telegram-service *::before,
    .telegram-service *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .telegram-service__jump svg {
        display: none;
    }
}

/* ============================================================
 * 移动端
 * ============================================================ */
@media (max-width: 640px) {
    /* 这里原来把 left/right/bottom 全写死了（12px/12px/14px），后台配的偏移和
       左右位置在手机端一律失效 —— 只能调 PC。而手机端底部往往是登录按钮、支付
       方式选择条，按钮压上去就点不到了。见 issue #815。
       改成走 --telegram-service-*-m 变量：站长没单独填手机端偏移时，服务端会把
       PC 的值兜进来，行为和以前一致；填了就按手机端这套走。 */
    .telegram-service {
        display: flex;
        flex-direction: column;
        bottom: var(--telegram-service-bottom-m, 14px);
    }

    /* 左右不再双向拉满：按后台选的位置贴边，另一侧留 auto，
       否则容器横跨整屏，button_position 选「左侧」在手机端也没有意义 */
    .telegram-service--right {
        align-items: flex-end;
        right: var(--telegram-service-side-m, 12px);
        left: auto;
    }

    .telegram-service--left {
        align-items: flex-start;
        left: var(--telegram-service-side-m, 12px);
        right: auto;
    }

    .telegram-service__button {
        width: auto;
        min-width: 0;
        padding: 0;
        border-radius: 22px;
        justify-content: center;
        /* 拖动支持：手势从按钮上开始时交给 JS 处理，不触发页面滚动/长按菜单 */
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    .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__unread {
        top: -5px;
        right: -5px;
    }

    .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;
    }

    .telegram-service__jump {
        bottom: 10px;
    }
}
