/* ========== 站内消息抽屉 ========== */
.chat-send-btn,
.chat-emoji-btn,
.chat-fullscreen-btn,
.chat-drawer-toggle {
    touch-action: manipulation;
}

.chat-send-btn:focus-visible,
.chat-emoji-btn:focus-visible,
.chat-emoji-item:focus-visible,
.chat-fullscreen-btn:focus-visible,
.chat-drawer-toggle:focus-visible {
    outline: 2px solid #ffd54f;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(255, 213, 79, 0.18);
}

.chat-drawer {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    width: min(316px, calc(100vw - 8px));
    height: min(480px, calc(100vh - 16px));
    min-width: 0;
    min-height: 0;
    pointer-events: none;
    transition: width 0.24s ease, height 0.24s ease;
    z-index: 1200;
}

.chat-drawer.fullscreen {
    top: 0;
    height: 100vh;
}

.chat-drawer.collapsed {
    width: 118px;
    height: 44px;
    top: auto;
    bottom: 18px;
}

.chat-drawer-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 44px;
    height: 36px;
    min-height: 36px;
    border: 1px solid var(--border-color, #2a2e39);
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(41, 98, 255, 0.95), rgba(30, 34, 45, 0.98));
    color: var(--text-primary, #d1d4dc);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    pointer-events: auto;
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
}

.chat-drawer-toggle:hover {
    color: #ffd54f;
    background: linear-gradient(135deg, rgba(255, 213, 79, 0.18), rgba(30, 34, 45, 0.98));
}

.chat-drawer.collapsed .chat-drawer-toggle {
    top: 0;
    right: 0;
    width: 118px;
    height: 44px;
    min-height: 44px;
    border-radius: 12px;
    gap: 6px;
}

.chat-drawer.collapsed .chat-drawer-text {
    display: inline;
}

.chat-drawer-icon {
    line-height: 1;
    letter-spacing: 0;
    font-size: 16px;
}

.chat-unread-badge {
    position: absolute;
    left: -6px;
    bottom: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef5350;
    color: #fff;
    border: 2px solid var(--bg-secondary, #1e222d);
    box-shadow: 0 4px 12px rgba(239, 83, 80, 0.36);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0;
    pointer-events: none;
}

.chat-unread-badge.show {
    display: inline-flex;
}

.chat-drawer-text {
    display: none;
}

.chat-fullscreen-btn {
    position: absolute;
    top: 8px;
    right: 58px;
    z-index: 2;
    height: 36px;
    min-height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border-color, #2a2e39);
    border-radius: 12px;
    background: rgba(42, 46, 57, 0.92);
    color: var(--text-primary, #d1d4dc);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    pointer-events: auto;
}

.chat-fullscreen-btn:hover {
    color: #ffd54f;
    background: #363a45;
}

.chat-drawer.collapsed .chat-fullscreen-btn {
    display: none;
}

.chat-drawer-panel {
    position: absolute;
    inset: 0;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    pointer-events: auto;
    transition: opacity 0.18s ease, transform 0.24s ease, visibility 0.18s ease;
}

.chat-drawer.collapsed .chat-drawer-panel {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(12px);
}

#chat-bar {
    height: 100%;
    min-height: 0;
    background: var(--card-bg, #1e222d);
    border: 1px solid var(--border-color, #2a2e39);
    border-right: none;
    border-radius: 0 0 0 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: -14px 0 30px rgba(0, 0, 0, 0.28);
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 6px;
    height: auto;
    min-height: 0;
    flex: 0 0 auto;
    padding: 10px 118px 10px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #d1d2d3);
    border-bottom: 1px solid var(--border-color, #2a2e39);
    background: rgba(255,255,255,0.03);
    user-select: none;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 120px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #3a3f4b; border-radius: 2px; }

.chat-pinned-notice {
    flex: 0 0 auto;
    display: none;
    margin: 8px 8px 0;
    color: #4caf50;
    background: rgba(76, 175, 80, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    border-left: 3px solid #4caf50;
    font-size: 11px;
    line-height: 1.4;
    word-break: break-all;
}

.chat-pinned-notice.show {
    display: block;
}

.chat-msg { font-size: 14px; line-height: 1.45; word-break: break-all; }

.chat-msg-system {
    color: #4caf50;
    background: rgba(76, 175, 80, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    border-left: 3px solid #4caf50;
    font-size: 11px;
    line-height: 1.4;
}

.chat-msg-system a { color: #4fc3f7; text-decoration: none; }
.chat-msg-system a:hover { text-decoration: underline; }

.chat-observe-status {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 4px;
    padding: 1px 5px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: #d1d4dc;
    font-size: 10px;
    line-height: 1.35;
    white-space: nowrap;
    vertical-align: baseline;
}

.chat-observe-status.active {
    border-color: rgba(76, 175, 80, 0.42);
    background: rgba(76, 175, 80, 0.12);
    color: #8be28f;
}

.chat-observe-status.ended {
    border-color: rgba(255, 213, 79, 0.42);
    background: rgba(255, 213, 79, 0.12);
    color: #ffd54f;
}

.chat-observe-status.exited,
.chat-observe-status.interrupted {
    border-color: rgba(239, 83, 80, 0.42);
    background: rgba(239, 83, 80, 0.12);
    color: #ff8a80;
}

.chat-observe-link.disabled {
    color: #8a94a6;
    cursor: default;
    pointer-events: none;
    text-decoration: none;
}

.chat-msg-user { color: var(--text-secondary, #787b86); }
.chat-msg-user .chat-sender { color: #90caf9; font-weight: 500; }
.chat-msg-user .chat-sender.self { color: #ffd54f; }

.chat-empty { color: var(--text-secondary, #555); font-size: 11px; text-align: center; padding: 12px 0; }

.chat-input-row {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 6px;
    border-top: 1px solid var(--border-color, #2a2e39);
    background: rgba(255,255,255,0.02);
    flex: 0 0 auto;
}

.chat-input {
    flex: 1 1 auto;
    width: 0;
    min-width: 0;
    height: 42px;
    min-height: 42px;
    max-height: 156px;
    background: var(--input-bg, #2a2e39);
    border: 1px solid var(--border-color, #363a45);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text-primary, #d1d2d3);
    font-size: 14px;
    line-height: 1.5;
    outline: none;
    resize: none;
    overflow-y: hidden;
    box-sizing: border-box;
}

.chat-input:focus { border-color: #4fc3f7; }
.chat-input::placeholder { color: var(--text-secondary, #555); }

.chat-emoji-wrap {
    position: relative;
    flex: 0 0 auto;
}

.chat-emoji-btn,
.chat-send-btn {
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 42px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chat-emoji-btn {
    background: var(--input-bg, #2a2e39);
    border: 1px solid var(--border-color, #363a45);
    color: var(--text-primary, #d1d4dc);
    font-size: 18px;
    line-height: 1;
}

.chat-emoji-btn:hover,
.chat-emoji-btn.active {
    color: #ffd54f;
    border-color: #ffd54f;
    background: #363a45;
}

.chat-send-btn {
    background: #4fc3f7;
    color: #1a1a2e;
    font-size: 14px;
}

.chat-send-btn:hover { background: #29b6f6; }
.chat-send-btn:disabled { opacity: 0.4; cursor: default; }

.chat-emoji-panel {
    position: absolute;
    right: -42px;
    bottom: calc(100% + 8px);
    width: 286px;
    max-width: calc(100vw - 24px);
    padding: 10px;
    background: var(--card-bg, #1e222d);
    border: 1px solid var(--border-color, #2a2e39);
    border-radius: 12px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.38);
    display: none;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    z-index: 1300;
}

.chat-emoji-panel.show {
    display: grid;
}

.chat-emoji-panel::after {
    content: '';
    position: absolute;
    right: 54px;
    bottom: -7px;
    width: 12px;
    height: 12px;
    background: var(--card-bg, #1e222d);
    border-right: 1px solid var(--border-color, #2a2e39);
    border-bottom: 1px solid var(--border-color, #2a2e39);
    transform: rotate(45deg);
}

.chat-emoji-item {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary, #d1d4dc);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.chat-emoji-item:hover {
    background: var(--control-hover, #363a45);
}

.chat-sender-name {
    cursor: pointer;
    color: #90caf9;
    font-weight: 500;
}

.chat-sender-name:hover {
    text-decoration: underline;
}

.chat-sender-name.self {
    color: #ffd54f;
}

.chat-user-menu {
    position: fixed;
    background: var(--bg-card, #1e222d);
    border: 1px solid var(--border-color, #2a2e39);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    z-index: 99999;
    min-width: 120px;
    overflow: hidden;
}

.chat-user-menu-item {
    display: block;
    width: 100%;
    padding: 8px 14px;
    background: none;
    border: none;
    color: var(--text-primary, #d1d4dc);
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}

.chat-user-menu-item:hover {
    background: var(--control-hover, #363a45);
}

.chat-user-menu-divider {
    border-top: 1px solid var(--border-color, #2a2e39);
    margin: 2px 0;
}

@media (max-width: 760px),
       ((hover: none) and (pointer: coarse) and (max-width: 980px)) {
    .chat-drawer {
        display: none !important;
    }
}

@media (max-width: 980px) {
    .chat-send-btn,
    .chat-emoji-btn,
    .chat-fullscreen-btn,
    .chat-drawer-toggle {
        min-height: 44px;
    }
}

body[data-theme="light"] .chat-drawer-toggle {
    background: linear-gradient(180deg, rgba(41, 98, 255, 0.12), #ffffff) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

body[data-theme="light"] .chat-drawer-toggle:hover {
    color: #2962ff !important;
    background: linear-gradient(180deg, rgba(41, 98, 255, 0.16), #ffffff) !important;
}
