/* ==========================================================================
   QQ Bot 聊天 —— 样式表
   纯手写 CSS，无需构建工具，颜色和原 React 版本保持一致（蓝 / 灰配色）
   ========================================================================== */

/* ------------------------------ 基础 ------------------------------ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    color: #1f2937;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button,
input,
textarea,
select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

a {
    color: #2563eb;
}

[hidden] {
    display: none !important;
}

.icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.icon-sm {
    width: 16px;
    height: 16px;
}

:focus-visible {
    outline: 2px solid #93c5fd;
    outline-offset: 2px;
}

/* ------------------------------ 按钮 ------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    height: 40px;
    padding: 0 18px;
    background: #3b82f6;
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
}

.btn-outline {
    height: 38px;
    padding: 0 16px;
    border-color: #e5e7eb;
    background: #fff;
    color: #374151;
}

.btn-outline:hover:not(:disabled) {
    background: #f9fafb;
}

.btn-ghost {
    color: #6b7280;
}

.btn-ghost:hover:not(:disabled) {
    background: #f3f4f6;
}

.btn-sm {
    height: 32px;
    padding: 0 8px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
    height: 44px;
    font-size: 15px;
}

.btn-logout:hover:not(:disabled) {
    background: #fef2f2;
    color: #ef4444;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #6b7280;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
    background: #eff6ff;
    color: #3b82f6;
}

.icon-btn-warn:hover {
    background: #fff7ed;
    color: #f97316;
}

/* ------------------------------ 表单 ------------------------------ */
.field {
    display: block;
    margin-bottom: 16px;
}

.field-label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
}

.input {
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
    color: #9ca3af;
}

.input:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px #dbeafe;
}

.form-error {
    margin-bottom: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    background: #fef2f2;
    color: #dc2626;
    font-size: 13px;
    line-height: 1.5;
}

/* ------------------------------ 登录页 ------------------------------ */
.login-body {
    background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 100%);
}

.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    padding: 24px 16px;
    background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 100%);
}

/* 浏览器里有登录凭证时直接显示聊天界面；没有时只显示登录页 */
html.has-session .login-page {
    display: none;
}

html:not(.has-session) .app {
    display: none;
}

.login-card {
    width: 100%;
    max-width: 448px;
    padding: 32px;
    border: 1px solid rgba(229, 231, 235, 0.8);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 20px 45px -20px rgba(30, 64, 175, 0.35), 0 8px 20px -12px rgba(15, 23, 42, 0.12);
}

.login-logo {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: #dbeafe;
    color: #3b82f6;
}

.login-logo .icon {
    width: 28px;
    height: 28px;
}

.login-title {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    color: #111827;
    text-align: center;
}

.login-sub {
    margin: 8px 0 0;
    font-size: 14px;
    color: #6b7280;
    text-align: center;
}

.login-form {
    margin-top: 24px;
}

.login-tip {
    margin-top: 20px;
    padding: 12px;
    border: 1px solid #fde68a;
    border-radius: 8px;
    background: #fffbeb;
    color: #b45309;
    font-size: 12px;
    line-height: 1.7;
}

.login-tip a {
    color: #b45309;
    font-weight: 600;
}

.login-foot {
    margin: 16px 0 0;
    font-size: 12px;
    color: #94a3b8;
    text-align: center;
}

/* ------------------------------ 应用骨架 ------------------------------ */
.app-body {
    overflow: hidden;
    background: #f9fafb;
}

.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ------------------------------ 侧边栏 ------------------------------ */
.sidebar {
    display: flex;
    flex-direction: column;
    width: 288px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #e5e7eb;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
}

.sidebar-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.sidebar-title h1 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #111827;
}

.count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 19px;
    padding: 0 6px;
    border-radius: 999px;
    background: #eff6ff;
    color: #2563eb;
    font-size: 11px;
    font-weight: 600;
}

.group-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.group-empty {
    margin: 0;
    padding: 18px 12px;
    color: #9ca3af;
    font-size: 13px;
    line-height: 1.8;
    text-align: center;
}

.group-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.group-item:hover {
    background: #f9fafb;
}

.group-item.is-active {
    background: #eff6ff;
}

.group-item.is-active .group-name {
    color: #1d4ed8;
    font-weight: 600;
}

.avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #f3f4f6;
    color: #4b5563;
    font-size: 15px;
    font-weight: 600;
    text-transform: uppercase;
}

.group-item.is-active .avatar {
    background: #3b82f6;
    color: #fff;
}

.group-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    padding-right: 4px;
}

.group-name {
    font-size: 14px;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-sub {
    margin-top: 2px;
    font-size: 12px;
    color: #9ca3af;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.unread {
    display: grid;
    place-items: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}

.group-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 14px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

.group-item:hover .group-remove,
.group-remove:focus-visible {
    opacity: 1;
}

.group-remove:hover {
    background: #fee2e2;
    color: #dc2626;
}

.sidebar-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
}

.sidebar-foot-text {
    font-size: 11px;
    color: #d1d5db;
}

/* ------------------------------ WebSocket 状态 ------------------------------ */
.ws-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #9ca3af;
    white-space: nowrap;
}

.ws-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db;
}

.ws-badge.is-connected {
    color: #16a34a;
}

.ws-badge.is-connected .dot {
    background: #22c55e;
    animation: ws-pulse 1.8s ease-in-out infinite;
}

.ws-badge.is-connecting {
    color: #d97706;
}

.ws-badge.is-connecting .dot {
    background: #f59e0b;
    animation: ws-pulse 1.2s ease-in-out infinite;
}

@keyframes ws-pulse {
    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
    }
    50% {
        opacity: 0.65;
        box-shadow: 0 0 0 4px rgba(34, 197, 94, 0);
    }
}

/* ------------------------------ 聊天区 ------------------------------ */
.chat {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    background: #f9fafb;
}

.chat-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.chat-head-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.avatar-blue {
    width: 36px;
    height: 36px;
    background: #3b82f6;
    color: #fff;
    font-size: 14px;
}

.chat-head-text {
    min-width: 0;
}

.chat-title {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-sub {
    margin-top: 2px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    color: #9ca3af;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-head-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.menu-btn {
    display: none;
}

/* 空状态 */
.chat-empty {
    position: relative;
    display: grid;
    place-items: center;
    flex: 1;
    padding: 24px;
}

.menu-btn-float {
    position: absolute;
    top: 12px;
    left: 12px;
}

.empty-inner {
    text-align: center;
}

.empty-icon {
    display: grid;
    place-items: center;
    width: 80px;
    height: 80px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: #dbeafe;
    color: #3b82f6;
}

.empty-icon .icon {
    width: 40px;
    height: 40px;
}

.empty-inner h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #374151;
}

.empty-inner > p {
    margin: 8px 0 0;
    font-size: 14px;
    color: #6b7280;
}

.empty-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}

.empty-status-text {
    font-size: 12px;
    color: #9ca3af;
}

.empty-inner .btn-logout {
    margin-top: 12px;
}

/* 消息列表 */
.chat-body {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px max(24px, calc((100% - 768px) / 2));
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.messages-empty {
    padding: 48px 12px;
    color: #9ca3af;
    font-size: 13px;
    line-height: 1.8;
    text-align: center;
}

.msg {
    display: flex;
    margin-bottom: 16px;
}

.msg:last-child {
    margin-bottom: 0;
}

.msg.is-bot {
    justify-content: flex-end;
}

.msg.is-member {
    justify-content: flex-start;
}

.msg.is-system {
    justify-content: center;
}

.msg-body {
    max-width: 75%;
    min-width: 0;
}

.msg.is-system .msg-body {
    width: 100%;
    text-align: center;
}

/* 消息头像（qlogo） */
.msg-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    margin-top: 18px;
    border-radius: 50%;
    overflow: hidden;
    background: #e5e7eb;
}

.msg.is-member .msg-avatar {
    margin-right: 8px;
}

.msg.is-bot .msg-avatar {
    margin-left: 8px;
}

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

.avatar-fallback {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    background: #dbeafe;
    color: #2563eb;
    font-size: 13px;
    font-weight: 600;
}

.msg.is-bot .avatar-fallback {
    background: #3b82f6;
    color: #fff;
}

.msg-meta {
    margin-bottom: 4px;
    font-size: 11px;
    color: #9ca3af;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msg.is-bot .msg-meta {
    text-align: right;
}

.bubble {
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.65;
    overflow-wrap: break-word;
    word-break: break-word;
}

.msg.is-bot .bubble {
    background: #3b82f6;
    color: #fff;
    border-top-right-radius: 4px;
}

.msg.is-member .bubble {
    background: #fff;
    color: #1f2937;
    border-top-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.system-pill {
    display: inline-block;
    max-width: 100%;
    padding: 3px 12px;
    border-radius: 999px;
    background: #e5e7eb;
    color: #6b7280;
    font-size: 12px;
    overflow-wrap: break-word;
}

/* 气泡内的 Markdown 排版 */
.bubble p {
    margin: 0 0 8px;
}

.bubble p:last-child {
    margin-bottom: 0;
}

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
    margin: 4px 0 8px;
    font-size: 1.05em;
    font-weight: 700;
    line-height: 1.4;
}

.bubble h1 {
    font-size: 1.25em;
}

.bubble h2 {
    font-size: 1.15em;
}

.bubble strong {
    font-weight: 700;
}

.bubble code {
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(15, 23, 42, 0.08);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88em;
}

.msg.is-bot .bubble code {
    background: rgba(255, 255, 255, 0.22);
}

.bubble pre {
    margin: 8px 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.06);
    overflow-x: auto;
    line-height: 1.5;
}

.msg.is-bot .bubble pre {
    background: rgba(15, 23, 42, 0.18);
}

.bubble pre code {
    padding: 0;
    background: none;
    font-size: 0.86em;
}

.bubble a {
    color: #1d4ed8;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.msg.is-bot .bubble a {
    color: #dbeafe;
}

.bubble blockquote {
    margin: 8px 0;
    padding-left: 10px;
    border-left: 3px solid rgba(15, 23, 42, 0.16);
    color: inherit;
    opacity: 0.9;
}

.msg.is-bot .bubble blockquote {
    border-left-color: rgba(255, 255, 255, 0.4);
}

.bubble ul,
.bubble ol {
    margin: 6px 0;
    padding-left: 22px;
}

.bubble li {
    margin: 2px 0;
}

.bubble hr {
    margin: 10px 0;
    border: 0;
    border-top: 1px solid currentColor;
    opacity: 0.2;
}

.bubble img {
    display: block;
    max-width: 100%;
    max-height: 200px;
    margin: 4px 0;
    border-radius: 8px;
}

.msg-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.img-fallback {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 8px;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 12px;
}

.msg.is-bot .img-fallback {
    background: rgba(255, 255, 255, 0.2);
    color: #eff6ff;
}

/* 点开的图片 */
.msg-img {
    cursor: zoom-in;
}

/* 图片全屏预览（lightbox） */
body.lightbox-open {
    overflow: hidden;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
        max(56px, calc(env(safe-area-inset-bottom) + 40px)) max(16px, env(safe-area-inset-left));
    background: rgba(0, 0, 0, 0.92);
}

.lightbox-img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    border-radius: 6px;
    object-fit: contain;
    box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.65);
    user-select: none;
    -webkit-user-select: none;
}

.lightbox-close {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.26);
}

.lightbox-hint {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(14px + env(safe-area-inset-bottom));
    padding: 0 16px;
    color: rgba(255, 255, 255, 0.65);
    font-size: 12px;
    text-align: center;
    pointer-events: none;
}

.scroll-btn {
    position: absolute;
    right: 32px;
    bottom: 16px;
    z-index: 5;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #3b82f6;
    color: #fff;
    box-shadow: 0 8px 20px -6px rgba(37, 99, 235, 0.55);
    transition: background-color 0.15s ease;
}

.scroll-btn:hover {
    background: #2563eb;
}

/* ------------------------------ 输入区 ------------------------------ */
.composer {
    flex-shrink: 0;
    padding: 14px 24px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
}

.composer-inner {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: 768px;
    margin: 0 auto;
}

.input-wrap {
    flex: 1;
    min-width: 0;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #f9fafb;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-wrap:focus-within {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px #dbeafe;
}

.input-wrap textarea {
    display: block;
    width: 100%;
    max-height: 120px;
    padding: 12px 16px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    font-size: 14px;
    line-height: 1.5;
    color: #1f2937;
    resize: none;
    outline: none;
}

.input-wrap textarea::placeholder {
    color: #9ca3af;
}

.composer-side {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.select {
    height: 34px;
    padding: 0 6px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    color: #4b5563;
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

.send-btn {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #3b82f6;
    color: #fff;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}

.send-btn:hover:not(:disabled) {
    background: #2563eb;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.composer-hint {
    max-width: 768px;
    margin: 8px auto 0;
    color: #9ca3af;
    font-size: 12px;
    line-height: 1.6;
}

/* ------------------------------ 弹窗 ------------------------------ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 16px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
}

.modal-card {
    position: relative;
    width: 100%;
    max-width: 384px;
    padding: 24px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.35);
}

.modal-card h2 {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}

.modal-hint {
    margin: 12px 0 0;
    color: #9ca3af;
    font-size: 12px;
    line-height: 1.7;
}

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

/* ------------------------------ 移动端 ------------------------------ */
@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 40;
        width: min(288px, 86vw);
        max-width: 320px;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 0 20px 40px -12px rgba(15, 23, 42, 0.35);
    }

    .app.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 30;
        background: rgba(15, 23, 42, 0.35);
    }

    .menu-btn {
        display: inline-flex;
    }

    .chat-head {
        padding: 8px 12px;
        padding-top: calc(8px + env(safe-area-inset-top));
        gap: 8px;
    }

    .chat-head-right {
        gap: 4px;
    }

    .btn-logout .btn-text {
        display: none;
    }

    .btn-logout {
        padding: 0 6px;
    }

    .messages {
        padding: 16px 14px;
    }

    .msg-body {
        max-width: 86%;
    }

    .msg-avatar {
        width: 28px;
        height: 28px;
        margin-top: 16px;
    }

    /* iOS 上输入框字号小于 16px 会自动放大页面 */
    .input-wrap textarea {
        font-size: 16px;
    }

    .composer {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .scroll-btn {
        right: 16px;
        bottom: 12px;
    }

    .login-card {
        padding: 24px;
    }

    .sidebar-foot-text {
        display: none;
    }
}

/* 手机（≤520px）：更紧凑的气泡、16px 输入框（防 iOS 自动放大）、刘海安全区 */
@media (max-width: 520px) {
    .chat-head {
        gap: 4px;
        padding: 6px 8px;
        padding-top: calc(6px + env(safe-area-inset-top));
    }

    .chat-head-left {
        gap: 8px;
    }

    .chat-head-text {
        flex: 1;
    }

    .avatar-blue {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .chat-title {
        font-size: 13px;
    }

    .chat-sub {
        display: none;
    }

    .chat-head-right {
        gap: 2px;
    }

    .ws-badge {
        font-size: 11px;
        gap: 4px;
    }

    .icon-btn {
        width: 30px;
        height: 30px;
    }

    .menu-btn {
        width: 32px;
        height: 32px;
    }

    .messages {
        padding: 12px 10px;
    }

    .msg {
        margin-bottom: 12px;
    }

    .msg-body {
        max-width: 84%;
    }

    .msg-avatar {
        width: 26px;
        height: 26px;
        margin-top: 15px;
    }

    .msg-meta {
        font-size: 10px;
    }

    .bubble {
        padding: 8px 11px;
        border-radius: 14px;
        font-size: 14px;
    }

    .bubble img {
        max-height: 140px;
    }

    .msg-images {
        gap: 6px;
    }

    .system-pill {
        font-size: 11px;
        padding: 3px 10px;
    }

    .composer {
        padding: 8px 8px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    .composer-inner {
        gap: 8px;
    }

    .input-wrap textarea {
        padding: 10px 12px;
        font-size: 16px;
        line-height: 1.45;
    }

    .composer-side {
        gap: 6px;
        flex-direction: row;
        align-items: center;
    }

    .select {
        height: 30px;
        font-size: 11px;
    }

    .send-btn {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }

    .composer-hint {
        margin-top: 6px;
        font-size: 11px;
    }

    .scroll-btn {
        right: 12px;
        bottom: 10px;
        width: 40px;
        height: 40px;
    }

    .login-page {
        padding: 16px 12px;
        padding-top: calc(16px + env(safe-area-inset-top));
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    .login-card {
        padding: 22px 18px;
        border-radius: 14px;
    }

    .login-title {
        font-size: 22px;
    }

    .modal-card {
        max-height: calc(100dvh - 32px);
        max-height: calc(100vh - 32px);
        overflow-y: auto;
        padding: 20px;
    }

    .lightbox {
        padding: 12px;
        padding-top: calc(12px + env(safe-area-inset-top));
        padding-bottom: calc(48px + env(safe-area-inset-bottom));
    }

    /* 登录表单同样避免 iOS 聚焦时放大 */
    .input {
        font-size: 16px;
    }
}

@media (min-width: 861px) {
    .sidebar-overlay {
        display: none;
    }
}

/* 触屏设备上让移除按钮常显 */
@media (hover: none) {
    .group-remove {
        opacity: 0.8;
    }
}

/* 细滚动条 */
.messages::-webkit-scrollbar,
.group-list::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-thumb,
.group-list::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #d1d5db;
}

.messages::-webkit-scrollbar-thumb:hover,
.group-list::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

.messages::-webkit-scrollbar-track,
.group-list::-webkit-scrollbar-track {
    background: transparent;
}
