* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #0a0e27;
    height: 100vh;
    overflow: hidden;
}

.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 50%, #0a0e27 100%);
    position: relative;
}

.login-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 80%, rgba(102, 126, 234, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(118, 75, 162, 0.1) 0%, transparent 50%);
    pointer-events: none;
}

.login-box {
    background: rgba(20, 25, 50, 0.9);
    backdrop-filter: blur(20px);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(102, 126, 234, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 400px;
    position: relative;
    z-index: 1;
}

.login-box::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #667eea, #764ba2, #667eea);
    border-radius: 18px;
    z-index: -1;
    opacity: 0.5;
    filter: blur(10px);
}

.login-box h1 {
    text-align: center;
    color: #e0e5ff;
    margin-bottom: 30px;
    font-size: 28px;
    text-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
}

.avatar-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
}

.current-avatar {
    width: 100px;
    height: 100px;
    border-radius: 20%;
    background: rgba(30, 35, 60, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 15px;
    border: 3px solid #667eea;
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.3);
}

.current-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-placeholder {
    font-size: 48px;
    color: #667eea;
}

.avatar-actions {
    display: flex;
    gap: 10px;
}

.avatar-hint {
    font-size: 12px;
    color: #8b9bb4;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #e0e5ff;
    font-weight: 500;
    text-shadow: 0 0 10px rgba(102, 126, 234, 0.3);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
    background: rgba(20, 25, 50, 0.6);
    color: #e0e5ff;
    font-size: 14px;
    outline: none;
    transition: all 0.3s;
}

.form-group input:focus {
    border-color: #667eea;
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.3);
}

.form-group input::placeholder {
    color: #8b9bb4;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(24, 144, 255, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(24, 144, 255, 0.4);
}

.btn-secondary {
    padding: 8px 16px;
    background: rgba(30, 35, 60, 0.8);
    color: #e0e5ff;
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-secondary:hover {
    background: rgba(102, 126, 234, 0.3);
}

.btn-small {
    padding: 6px 12px;
    background: rgba(30, 35, 60, 0.8);
    color: #e0e5ff;
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-small:hover {
    background: rgba(102, 126, 234, 0.3);
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 800px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: linear-gradient(135deg, rgba(20, 25, 50, 0.95) 0%, rgba(30, 40, 70, 0.95) 50%, rgba(20, 25, 50, 0.95) 100%);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(102, 126, 234, 0.3);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: relative;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 30%, rgba(102, 126, 234, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(118, 75, 162, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(147, 112, 219, 0.08) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.room-info {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 20%;
    background: rgba(30, 35, 60, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-avatar .avatar-placeholder {
    font-size: 20px;
    color: #52c41a;
}

.room-user-info {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 4px;
}

.room-name {
    font-weight: 600;
    color: #e0e5ff;
    font-size: 16px;
}

.user-name {
    font-size: 12px;
    color: #8b9bb4;
    margin-top: 2px;
}

/* 顶部栏用户地理位置 */
.header-location {
    display: inline;
    font-size: 11px;
    color: #5c6b8a;
    margin-left: 6px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #8b9bb4;
}

.connection-status.connected .status-dot {
    background: #52c41a;
    box-shadow: 0 0 10px rgba(82, 196, 26, 0.5);
}

.connection-status.disconnected .status-dot {
    background: #ff4d4f;
    box-shadow: 0 0 10px rgba(255, 77, 79, 0.5);
}

.connection-status.error .status-dot {
    background: #faad14;
    box-shadow: 0 0 10px rgba(250, 173, 20, 0.5);
}

.connection-status.failed .status-dot {
    background: #ff4d4f;
    box-shadow: 0 0 10px rgba(255, 77, 79, 0.5);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin-bottom: 35px;
    padding: 8px;
    background-image: linear-gradient(180deg, #0a0e27 0%, #141932 100%);
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.rotating-background-1 {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(68vw, 345px);
    height: min(68vh, 345px);
    background: url('bac.png') center/contain no-repeat;
    pointer-events: none;
    z-index: 0;
    opacity: 0.07;
    animation: rotateBackground 60s linear infinite, glowPulse 3s ease-in-out infinite;
}

.rotating-background-2 {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(100vw, 500px);
    height: min(100vh, 500px);
    background: url('bac_b.png') center/contain no-repeat;
    pointer-events: none;
    z-index: 1;
    opacity: 0.07;
    animation: rotateBackgroundReverse 60s linear infinite, glowPulse 3s ease-in-out infinite;
}

@keyframes glowPulse {
    0%, 100% {
        filter: drop-shadow(0 0 20px rgba(102, 126, 234, 0.3));
    }
    50% {
        filter: drop-shadow(0 0 40px rgba(102, 126, 234, 0.8));
    }
}

@keyframes rotateBackground {
    from {
        transform: translate(-50%, -50%) rotate(0deg);
    }
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

@keyframes rotateBackgroundReverse {
    from {
        transform: translate(-50%, -50%) rotate(360deg);
    }
    to {
        transform: translate(-50%, -50%) rotate(0deg);
    }
}

@media (max-width: 768px) {
    .chat-messages {
        padding: 15px;
    }
}

.system-message {
    text-align: center;
    color: #8b9bb4;
    font-size: 12px;
    margin: 15px auto;
    padding: 4px 12px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 4px;
    display: block;
    width: fit-content;
    max-width: 80%;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: rgba(20, 25, 50, 0.9);
    backdrop-filter: blur(10px);
    color: #e0e5ff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    animation: toastIn 0.3s ease-out;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 300px;
    text-align: center;
    border: 1px solid rgba(102, 126, 234, 0.3);
}

.toast.toast-leave {
    animation: toastOut 0.3s ease-in forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

/* 移动端消息气泡通知（私聊时其他人来消息） */
.mobile-msg-bubble {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 25, 50, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(102, 126, 234, 0.4);
    border-radius: 10px;
    padding: 10px 16px;
    z-index: 1200;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 260px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 15px rgba(102, 126, 234, 0.2);
    animation: bubbleIn 0.3s ease-out;
}

.msg-bubble-sender {
    font-size: 12px;
    color: #667eea;
    font-weight: 600;
}

.msg-bubble-preview {
    font-size: 13px;
    color: #e0e5ff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@keyframes bubbleIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.message {
    display: flex;
    margin-bottom: 12px;
    align-items: flex-start;
    max-width: 100%;
    overflow: hidden;
    flex-shrink: 0; /* 防止flex子元素被压缩，确保消息正常显示并触发父容器滚动 */
}

.message.own {
    flex-direction: row-reverse;
}

.message.other {
    flex-direction: row;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 20%;
    background: linear-gradient(135deg, #505155 0%, #2c2e36 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message.own .avatar {
    margin-left: 10px;
}

.message.other .avatar {
    margin-right: 10px;
}

.bubble {
    max-width: 70%;
    padding: 9px 13px;
    border-radius: 4px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.6;
    font-size: 14px;
}

.message.own .bubble {
    background: linear-gradient(135deg, #3e566c 0%, #265587 100%);
    color: #ffffff;
    border-radius: 4px 0 4px 4px;
    box-shadow: 0 4px 15px rgba(38, 86, 108, 0.3);
}

.message.own .bubble::before {
    content: '';
    position: absolute;
    right: -6px;
    top: 12px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 6px solid #265587;
}

.message.other .bubble {
    background: rgba(30, 35, 60, 0.9);
    backdrop-filter: blur(10px);
    color: #0bc0a2;
    border-radius: 0 4px 4px 4px;
    border: 1px solid rgba(102, 126, 234, 0.2);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.message.other .bubble::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 12px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 6px solid rgba(30, 35, 60, 0.9);
}

.sender {
    font-size: 12px;
    color: #8b9bb4;
    margin-top: 4px;
}

.message.own .sender {
    text-align: right;
    margin-right: 10px;
}

.message.other .sender {
    margin-left: 10px;
}

.voice-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 120px;
    position: relative;
}

.voice-play-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
    position: relative;
}

.voice-play-btn.playing {
    animation: pulse 1.5s ease-in-out infinite;
}

.voice-play-btn.playing::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    border: 2px solid #95ec69;
    animation: ripple 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes ripple {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

.voice-play-btn:hover {
    background: rgba(102, 126, 234, 0.3);
}

.voice-duration {
    font-size: 14px;
    color: #e0e5ff;
    font-family: monospace;
    font-weight: bold;
    animation: durationPulse 1s ease-in-out;
}

@keyframes durationPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
        color: #667eea;
    }
    100% {
        transform: scale(1);
    }
}

.image-bubble {
    padding: 5px;
}

.chat-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-image:hover {
    transform: scale(1.02);
}

.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: pointer;
}

.image-modal img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

.chat-input {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    background: rgba(20, 25, 50, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(102, 126, 234, 0.3);
    gap: 10px;
    flex-shrink: 0;
    z-index: 1000;
    position: fixed;
    bottom: env(safe-area-inset-bottom);
    left: 0;
    right: 0;
    padding-bottom: calc(5px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.input-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: rgba(30, 35, 60, 0.8);
    border: 1px solid rgba(102, 126, 234, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    color: #e0e5ff;
}

.btn-icon:hover {
    background: rgba(102, 126, 234, 0.3);
    border-color: #667eea;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.4);
}

.btn-icon svg {
    width: 24px;
    height: 24px;
}

#messageInput {
    flex: 1;
    padding: 10px 14px;
    padding-right: 40px;
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    background: rgba(30, 35, 60, 0.8);
    color: #e0e5ff;
    transition: all 0.3s;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    line-height: 1.5;
    overflow-y: auto;
    font-family: inherit;
}

#messageInput:focus {
    border-color: #667eea;
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.3);
}

#messageInput::placeholder {
    color: #8b9bb4;
}

.input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: flex-end;
}

.audio-status-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: #8b9bb4;
    transition: color 0.3s;
    pointer-events: none;
    z-index: 1;
}

.audio-status-icon svg {
    width: 100%;
    height: 100%;
}

.audio-status-icon.active {
    display: none;
}

.audio-status-icon.inactive .muted-icon {
    display: block;
}

.audio-status-icon.inactive .unmuted-icon {
    display: none;
}

.btn-send {
    padding: 8px 15px;
    background: #334eab;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgb(45 148 106 / 0%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-send svg {
    width: 20px;
    height: 20px;
}

.btn-send:hover {
    background: #73d13d;
    box-shadow: 0 6px 20px rgba(82, 196, 26, 0.6);
    transform: translateY(-2px);
}

.voice-recording {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.recording-content {
    text-align: center;
    color: white;
}

.recording-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #ff4d4f;
    margin: 0 auto 20px;
    animation: recording-pulse 1s infinite;
}

@keyframes recording-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

.recording-text {
    font-size: 18px;
    margin-bottom: 10px;
}

.recording-time {
    font-size: 24px;
    font-weight: 600;
}

.image-preview {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.preview-content {
    background: rgba(20, 25, 50, 0.95);
    backdrop-filter: blur(20px);
    padding: 20px;
    border-radius: 12px;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border: 1px solid rgba(102, 126, 234, 0.3);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.preview-content img {
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
    border-radius: 8px;
}

.preview-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

@media (max-width: 768px) {
    .chat-container {
        max-width: 100%;
        /* 移动端确保flex子元素高度计算正确 */
        min-height: 100vh;
        height: 100vh;
    }

    /* 移动端聊天消息区域：必须可滚动 */
    .chat-messages {
        padding: 15px;
        /* 关键：flex子元素需要min-height:0才能正确收缩并触发滚动 */
        min-height: 0;
        overflow-y: auto !important;
        /* 用calc减去header高度，避免依赖flex:1的不确定性 */
        flex: 1 1 0%;
    }

    .bubble {
        max-width: calc(100% - 55px);
        word-break: break-all;
    }

    .avatar {
        width: 32px;
        height: 32px;
        font-size: 13px;
        flex-shrink: 0;
    }

    .message {
        margin-bottom: 10px;
    }

    .chat-image {
        max-width: 150px;
        max-height: 150px;
    }
}

::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: rgba(20, 25, 50, 0.5);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 4px;
    transition: background 0.3s;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.8);
}

::-webkit-scrollbar-corner {
    background: rgba(20, 25, 50, 0.5);
}

.message.new-message {
    animation: messageGlow 3s ease-out;
}

@keyframes messageGlow {
    0% {
        box-shadow: 0 0 20px rgba(11, 192, 162, 0.8),
                    0 0 40px rgba(11, 192, 162, 0.6),
                    0 0 60px rgba(11, 192, 162, 0.4);
    }
    100% {
        box-shadow: 0 0 0 rgba(11, 192, 162, 0);
    }
}

/* ==================== 管理员模式布局 ==================== */
.chat-container.admin-mode {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    max-width: none;
    width: 100%;
    /* 显式继承高度，确保grid的1fr行能正确计算 */
    height: 100vh;
}

/* 管理员侧边栏 — 占满左侧全部高度 */
.admin-sidebar {
    grid-row: 1 / -1;
    grid-column: 1;
    width: auto;
    background: rgba(15, 20, 40, 0.95);
    border-right: 1px solid rgba(102, 126, 234, 0.2);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 10;
}

/* 管理模式下右侧各元素归位 */
.chat-container.admin-mode > .chat-header {
    grid-column: 2;
    grid-row: 1;
}

.chat-container.admin-mode > .chat-messages {
    grid-column: 2;
    grid-row: 2;
    margin-bottom: -17px !important; /* 与普通模式一致 */
    /* Grid子元素必须显式设置才能确保滚动 */
    overflow-y: auto;
    min-height: 0;
}

.chat-container.admin-mode > .chat-input {
    grid-column: 2;
    grid-row: 3;
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: rgba(102, 126, 234, 0.1);
    border-bottom: 1px solid rgba(102, 126, 234, 0.2);
}

.sidebar-title {
    font-size: 13px;
    font-weight: 600;
    color: #e0e5ff;
}

.sidebar-count {
    font-size: 12px;
    color: #667eea;
    background: rgba(102, 126, 234, 0.15);
    padding: 2px 8px;
    border-radius: 10px;
}

/* 用户列表 */
.sidebar-user-list {
    flex: 1;
    min-height: 0; /* 关键：允许flex子项收缩 */
    overflow-y: auto;
    padding: 6px 0;
}

.sidebar-empty {
    text-align: center;
    color: #8b9bb4;
    font-size: 13px;
    padding: 30px 10px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    border-left: 3px solid transparent;
}

.sidebar-user:hover {
    background: rgba(102, 126, 234, 0.08);
}

.sidebar-user.selected {
    background: rgba(11, 192, 162, 0.12);
    border-left-color: rgb(11, 192, 162);;
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 20%;
    background: linear-gradient(135deg, #505155 0%, #2c2e36 100%);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sidebar-avatar-letter {
    color: white;
    font-size: 16px;
    font-weight: 600;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 13px;
    color: #e0e5ff;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 用户地理位置 */
.sidebar-user-location {
    display: block;
    font-size: 11px;
    color: #8892b0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 1px;
}

/* 未读红点 */
.sidebar-red-dot {
    width: 18px;
    height: 18px;
    background: #ff4d4f;
    color: white;
    font-size: 10px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(255, 77, 79, 0.6);
    animation: redDotPulse 2s infinite;
}

@keyframes redDotPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* 管理员设置面板 */
.admin-settings-panel {
    border-top: 1px solid rgba(102, 126, 234, 0.2);
    padding: 8px 10px;
    background: rgba(20, 25, 45, 0.6);
    flex-shrink: 0;
}

.settings-header {
    font-size: 12px;
    color: #8b9bb4;
    margin-bottom: 6px;
    font-weight: 600;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
}

.settings-row label {
    font-size: 11px;
    color: #8b9bb4;
    min-width: 48px;
    flex-shrink: 0;
}

.settings-row input,
.settings-row textarea {
    flex: 1;
    background: rgba(30, 35, 60, 0.9);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 4px;
    color: #e0e5ff;
    font-size: 11px;
    padding: 4px 6px;
    outline: none;
    resize: none;
    font-family: inherit;
}

.settings-row input:focus,
.settings-row textarea:focus {
    border-color: #667eea;
}

.settings-row textarea {
    min-height: 32px;
    max-height: 60px;
}

.away-toggle-btn {
    background: rgba(255, 77, 79, 0.15);
    border: 1px solid rgba(255, 77, 79, 0.3);
    color: #ff6b6b;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.away-toggle-btn:hover {
    background: rgba(255, 77, 79, 0.25);
}

.away-toggle-btn.away-on {
    background: rgba(82, 196, 26, 0.15);
    border-color: rgba(82, 196, 26, 0.3);
    color: #52c41a;
}

.away-toggle-btn.away-on:hover {
    background: rgba(82, 196, 26, 0.25);
}

.settings-save-btn {
    width: 100%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    color: #fff;
    font-size: 12px;
    padding: 5px 0;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 4px;
    transition: opacity 0.2s;
}

.settings-save-btn:hover {
    opacity: 0.85;
}

/* 消息中的链接 */
.msg-link {
    color: #667eea;
    text-decoration: underline;
    word-break: break-all;
    cursor: pointer;
}

.msg-link:hover {
    color: #764ba2;
}

/* 快捷用语面板 */
.quick-phrases-panel {
    border-top: 1px solid rgba(102, 126, 234, 0.2);
    flex-shrink: 0;
    max-height: 220px; /* 限制总高度，避免撑开挤压用户列表 */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 快捷用语面板顶部拖拽调整高度的把手 */
.phrases-resize-handle {
    height: 5px;
    cursor: ns-resize;
    background: transparent;
    transition: background 0.2s;
    position: relative;
    flex-shrink: 0;
}
.phrases-resize-handle:hover,
.phrases-resize-handle.active {
    background: rgba(102, 126, 234, 0.6);
}
.phrases-resize-handle::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 3px;
    background: rgba(102, 126, 234, 0.4);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.2s;
}
.phrases-resize-handle:hover::after {
    opacity: 1;
}

.phrases-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    font-size: 12px;
    color: #e0e5ff;
    font-weight: 500;
    background: rgba(30, 35, 60, 0.5);
}

.phrases-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.phrase-collapse-btn {
    background: none;
    border: none;
    color: #a0b0d0;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1.4;
    transition: color 0.15s;
    border-radius: 4px;
    flex: 1;
    text-align: left;
}

.phrase-collapse-btn:hover {
    color: #e0e5ff;
    background: rgba(255,255,255,0.05);
}

/* 快捷用语面板折叠状态（移动端收缩高度） */
.quick-phrases-panel.phrases-collapsed {
    height: auto !important;
    max-height: 44px !important;
}

.phrase-add-btn {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    background: rgba(102, 126, 234, 0.3);
    border: none;
    color: #e0e5ff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.phrase-add-btn:hover {
    background: rgba(102, 126, 234, 0.5);
}

.phrases-list {
    max-height: 180px;
    overflow-y: auto;
    padding: 4px 0;
}

.phrases-empty {
    text-align: center;
    color: #8b9bb4;
    font-size: 12px;
    padding: 15px 10px;
}

.phrase-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    transition: background 0.15s;
}

.phrase-item:hover {
    background: rgba(102, 126, 234, 0.06);
}

.phrase-text {
    flex: 1;
    font-size: 12px;
    color: #c8d0e8;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    position: relative;
}

.phrase-text:hover {
    color: #e0e5ff;
}

/* 鼠标悬停显示完整内容tooltip */
.phrase-text[title]:hover::after {
    content: attr(title);
    position: absolute;
    left: 0;
    top: 100%;
    z-index: 1000;
    background: rgba(20, 25, 45, 0.95);
    border: 1px solid rgba(102, 126, 234, 0.3);
    color: #e0e5ff;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: normal;
    max-width: 220px;
    word-break: break-word;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    margin-top: 4px;
    pointer-events: none;
}

.phrase-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.phrase-item:hover .phrase-actions {
    opacity: 1;
}

.phrase-edit-btn,
.phrase-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    line-height: 1;
    transition: transform 0.15s;
}

.phrase-edit-btn:hover { transform: scale(1.2); }
.phrase-delete-btn:hover { transform: scale(1.2); }

/* ==================== 弹窗样式 ==================== */

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-card {
    background: rgba(20, 25, 50, 0.97);
    backdrop-filter: blur(20px);
    border-radius: 14px;
    border: 1px solid rgba(102, 126, 234, 0.25);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(102, 126, 234, 0.1);
    width: 90%;
    max-width: 400px;
    animation: slideUp 0.25s ease-out;
    overflow: hidden;
}

.modal-small {
    max-width: 360px;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(102, 126, 234, 0.15);
}

.modal-header h3 {
    margin: 0;
    font-size: 17px;
    color: #e0e5ff;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: #8b9bb4;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #ff4d4f;
}

.modal-body {
    padding: 20px;
}

/* 身份信息 */
.identity-info p {
    color: #c8d0e8;
    font-size: 14px;
    margin-bottom: 8px;
}

.identity-info strong {
    color: #667eea;
}

.identity-hint {
    color: #8b9bb4 !important;
    font-size: 13px !important;
    margin-top: 12px !important;
    padding: 10px;
    background: rgba(102, 126, 234, 0.08);
    border-radius: 6px;
}

.auth-error {
    color: #ff4d4f !important;
    font-size: 13px !important;
    margin-top: 10px !important;
    text-align: center;
}

.admin-badge {
    color: #52c41a !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    text-align: center;
    padding: 15px !important;
    background: rgba(82, 196, 26, 0.1) !important;
    border-radius: 8px;
    margin-bottom: 15px !important;
}

.admin-logged-in {
    text-align: left;
}

/* 弹窗内管理员设置 */
.admin-setting-row {
    margin-bottom: 12px;
}

.admin-setting-row label {
    display: block;
    font-size: 12px;
    color: #a0b0d0;
    margin-bottom: 4px;
}

.admin-setting-row input,
.admin-setting-row textarea {
    width: 100%;
    background: rgba(30, 35, 60, 0.9);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 6px;
    color: #e0e5ff;
    font-size: 13px;
    padding: 8px 10px;
    outline: none;
    resize: none;
    font-family: inherit;
    box-sizing: border-box;
}

.admin-setting-row input:focus,
.admin-setting-row textarea:focus {
    border-color: #667eea;
}

.avatar-upload-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar-preview {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #8b9bb4;
    overflow: hidden;
    flex-shrink: 0;
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.admin-settings-actions {
    display: flex;
    gap: 8px;
    margin-top: 15px;
    justify-content: flex-end;
}

/* 顶部栏离开开关 */
.away-toggle-header {
    background: rgba(255, 77, 79, 0.15) !important;
    border: 1px solid rgba(255, 77, 79, 0.3) !important;
    color: #ff6b6b !important;
    padding: 3px 8px !important;
    font-size: 11px !important;
    white-space: nowrap;
    transition: all 0.2s !important;
}

.away-toggle-header:hover {
    background: rgba(255, 77, 79, 0.25) !important;
}

.away-toggle-header.away-on {
    background: rgba(82, 196, 26, 0.15) !important;
    border-color: rgba(82, 196, 26, 0.3) !important;
    color: #52c41a !important;
}

.away-toggle-header.away-on:hover {
    background: rgba(82, 196, 26, 0.25) !important;
}

/* 表单输入增强 */
#adminUsername,
#adminPassword {
    font-size: 15px !important;
    padding: 12px 14px !important;
}

#phraseInput {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 6px;
    background: rgba(30, 35, 60, 0.8);
    color: #e0e5ff;
    font-size: 14px;
    outline: none;
    resize: vertical;
    font-family: inherit;
    transition: border-color 0.2s;
}

#phraseInput:focus {
    border-color: #667eea;
    box-shadow: 0 0 12px rgba(102, 126, 234, 0.25);
}

#phraseInput::placeholder {
    color: #8b9bb4;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

/* 响应式：移动端侧边栏改为抽屉 */
@media (max-width: 768px) {
    .admin-sidebar {
        position: fixed;
        top: 0;
        left: -280px; /* 默认隐藏在屏幕左侧外 */
        width: 280px !important;
        height: 100vh;
        z-index: 1100; /* 高于chat-input的1000，避免被输入框遮挡 */
        transition: left 0.3s ease;
        box-shadow: none;
        display: none; /* 默认不占Grid空间，只有打开时显示 */
    }

    .admin-sidebar.mobile-open {
        display: flex !important; /* 打开时才参与布局 */
        flex-direction: column;
        overflow: hidden;
        left: 0;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    }

    /* 抽屉遮罩层 */
    .mobile-sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .mobile-sidebar-overlay.show {
        display: block;
    }

    /* 移动端侧边栏关闭按钮（由JS控制显示） */
    .sidebar-close-btn {
        display: inline-block !important;
    }

    .chat-container.admin-mode {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        max-width: 100%;
        overflow: hidden;
        height: 100vh;
        min-height: 100vh;
    }

    .chat-container.admin-mode > .chat-messages {
        overflow-x: hidden;
        overflow-y: auto !important;
        min-height: 0;
        max-height: none;
    }

    /* 移动端用户列表必须可滚动且占满剩余空间 */
    .sidebar-user-list {
        min-height: 0;
        flex: 1;
        overflow-y: auto;
    }

    /* 移动端快捷用语面板占30%高度 */
    .quick-phrases-panel {
        flex: 0 0 auto;
        height: 30vh;
        max-height: none;
        display: flex;
        flex-direction: column;
    }

    /* 移动端字体加大 */
    .phrases-header {
        font-size: 14px;
        padding: 12px 14px;
    }

    .phrase-text {
        font-size: 14px;
    }

    .phrases-list {
        flex: 1;
        max-height: none;
        overflow-y: auto;
    }

    /* 移动端用户按钮徽章 */
    .user-count-badge {
        display: inline-block;
        background: #e74c3c;
        color: #fff;
        font-size: 11px;
        font-weight: bold;
        min-width: 18px;
        height: 18px;
        line-height: 18px;
        text-align: center;
        border-radius: 9px;
        padding: 0 4px;
        margin-left: 4px;
        vertical-align: middle;
    }
}

/* 强制隐藏头像文件输入框（仅通过上传按钮触发） */
#modalAvatarInput,
#avatarInput {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    height: 0 !important;
    position: absolute !important;
    opacity: 0 !important;
}
