/* =========================================================================
   PenChat Web UI —— 零依赖、无 CDN 的移动优先样式
   设计目标：2C2G 自托管实例上单文件加载、无构建链、手机浏览器可用。
   结构：变量 → 基础 → 认证页 → 主界面（侧栏/聊天）→ 消息 → 输入区 → 弹层 → 响应式
   ========================================================================= */

/* ---------- 设计变量 ---------- */
:root {
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --bg: #f4f6f8;
    --bg-elevated: #ffffff;
    --bg-soft: #eceff3;
    --bg-sidebar: #ffffff;
    --text: #1a1f26;
    --text-muted: #68727f;
    --text-faint: #97a1ad;
    --border: #dfe4ea;
    --border-strong: #c8d0da;
    --accent: #2f6fed;
    --accent-strong: #1f56c8;
    --accent-soft: #e6edfd;
    --bubble-in: #ffffff;
    --bubble-out: #2f6fed;
    --bubble-out-text: #ffffff;
    --danger: #d9363e;
    --danger-soft: #fdebec;
    --success: #17945c;
    --warning: #b7791f;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.14);
    --shadow-lg: 0 24px 64px rgba(16, 24, 40, 0.28);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 999px;
    --sidebar-width: 320px;
    --header-height: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1217;
        --bg-elevated: #161c24;
        --bg-soft: #1d242e;
        --bg-sidebar: #141a21;
        --text: #e8edf3;
        --text-muted: #9aa6b3;
        --text-faint: #6f7b88;
        --border: #262f3a;
        --border-strong: #34404e;
        --accent: #5b8def;
        --accent-strong: #7aa4f5;
        --accent-soft: #1a2740;
        --bubble-in: #1d242e;
        --bubble-out: #2f6fed;
        --bubble-out-text: #ffffff;
        --danger: #f2636b;
        --danger-soft: #3a1d22;
        --success: #38b87c;
        --warning: #d9a441;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
        --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.6);
    }
}

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

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overscroll-behavior: none;
}

button,
input,
textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

.is-hidden {
    display: none !important;
}

.mobile-only {
    display: none;
}

.muted {
    color: var(--text-muted);
}

.empty {
    margin: 16px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- 通用按钮/表单 ---------- */
.primary-button,
.danger-button,
.ghost-button,
.send-button {
    border: 0;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-weight: 600;
    transition: background-color 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}

.primary-button {
    background: var(--accent);
    color: #fff;
}

.primary-button:hover {
    background: var(--accent-strong);
}

.primary-button:disabled,
.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.danger-button {
    background: var(--danger-soft);
    color: var(--danger);
}

.danger-button:hover {
    background: var(--danger);
    color: #fff;
}

.ghost-button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.ghost-button:hover {
    background: var(--bg-soft);
    color: var(--text);
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
}

.icon-button:hover {
    background: var(--bg-soft);
    color: var(--text);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.field > span {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.field > small {
    font-size: 12px;
    color: var(--text-faint);
}

.field input,
.field textarea,
.field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    outline: none;
}

.form-error {
    min-height: 18px;
    margin: 0 0 10px;
    color: var(--danger);
    font-size: 13px;
}

.inline-fields {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.inline-fields .field {
    flex: 1 1 120px;
    margin-bottom: 10px;
}

.kv {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 16px;
    margin: 0 0 12px;
    font-size: 14px;
}

.kv dt {
    color: var(--text-muted);
}

.kv dd {
    margin: 0;
}

/* =========================================================================
   认证页
   ========================================================================= */
.auth {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px calc(24px + var(--safe-bottom));
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(47, 111, 237, 0.18), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, rgba(23, 148, 92, 0.14), transparent 55%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 28px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    box-shadow: var(--shadow-md);
}

.auth-brand {
    text-align: center;
    margin-bottom: 20px;
}

.brand-mark {
    width: 52px;
    height: 52px;
    margin: 0 auto 12px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--accent), #7b5cff);
    color: #fff;
    font-size: 26px;
    font-weight: 800;
    box-shadow: var(--shadow-sm);
}

.auth-brand h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: 0.5px;
}

.auth-tagline {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

.tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 18px;
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
}

.tab {
    flex: 1;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
}

.tab.is-active {
    background: var(--bg-elevated);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.auth-form {
    display: block;
}

.auth-form .primary-button {
    width: 100%;
    margin-top: 4px;
}

.auth-hint {
    margin: 18px 0 0;
    color: var(--text-faint);
    font-size: 12px;
    text-align: center;
}

.auth-status {
    margin: 12px 0 0;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

/* =========================================================================
   主界面骨架
   ========================================================================= */
.app,
.main {
    height: 100%;
}

.main {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100%;
}

/* ---------- 侧栏 ---------- */
.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--border);
}

.me-button {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    text-align: left;
}

.me-button:hover {
    background: var(--bg-soft);
}

.avatar {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #7b5cff);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    text-transform: uppercase;
    overflow: hidden;
}

.avatar-bot {
    background: linear-gradient(135deg, #17945c, #38b87c);
}

.me-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.me-nickname {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.conn-state {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-faint);
    font-size: 12px;
}

.conn-state::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: background-color 0.2s ease;
}

.conn-state[data-state="online"]::before {
    background: var(--success);
}

.conn-state[data-state="connecting"]::before {
    background: var(--warning);
    animation: pulse 1.2s ease-in-out infinite;
}

.conn-state[data-state="offline"]::before {
    background: var(--danger);
}

@keyframes pulse {
    50% {
        opacity: 0.35;
    }
}

.sidebar-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}

.sidebar-actions .icon-button {
    min-width: auto;
    padding: 0 10px;
    font-size: 13px;
}

.room-list-wrap {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.room-list {
    list-style: none;
    margin: 0;
    padding: 6px;
}

.room-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px;
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    text-align: left;
    color: var(--text);
}

.room-item:hover {
    background: var(--bg-soft);
}

.room-item.is-active {
    background: var(--accent-soft);
}

.room-item .avatar {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    font-size: 17px;
}

.room-main {
    flex: 1;
    min-width: 0;
}

.room-topline {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.room-name {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-time {
    flex: none;
    color: var(--text-faint);
    font-size: 11px;
}

.room-bottomline {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

.room-preview {
    flex: 1;
    min-width: 0;
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    flex: none;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

.room-kind {
    flex: none;
    padding: 0 6px;
    border-radius: 4px;
    background: var(--bg-soft);
    color: var(--text-faint);
    font-size: 10px;
    line-height: 16px;
}

/* ---------- 聊天区 ---------- */
.chat {
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--header-height);
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}

.chat-title-wrap {
    flex: 1;
    min-width: 0;
}

.chat-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 14px 6px;
    overscroll-behavior: contain;
}

.load-more-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 4px 0 12px;
}

.load-more-hint {
    color: var(--text-faint);
    font-size: 12px;
}

.message-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ---------- 消息 ---------- */
.day-divider {
    align-self: center;
    margin: 12px 0 8px;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    background: var(--bg-soft);
    color: var(--text-muted);
    font-size: 11px;
}

.msg-row {
    display: flex;
    gap: 8px;
    padding: 2px 0;
    align-items: flex-end;
}

.msg-row.is-own {
    flex-direction: row-reverse;
}

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

.msg-row.is-first .msg-avatar {
    visibility: visible;
}

.msg-body {
    max-width: min(72%, 560px);
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.msg-row.is-own .msg-body {
    align-items: flex-end;
}

.msg-sender {
    padding: 0 4px;
    color: var(--text-muted);
    font-size: 11px;
}

.msg-sender .bot-tag {
    margin-left: 4px;
    padding: 0 5px;
    border-radius: 4px;
    background: var(--success);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
}

.msg-bubble {
    position: relative;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
    background: var(--bubble-in);
    box-shadow: var(--shadow-sm);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.msg-row.is-own .msg-bubble {
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: 4px;
    background: var(--bubble-out);
    color: var(--bubble-out-text);
}

.msg-row.is-own .msg-bubble a {
    color: #dbe7ff;
}

.msg-bubble.is-system {
    background: transparent;
    box-shadow: none;
    color: var(--text-muted);
    font-size: 12px;
    padding: 2px 4px;
}

.msg-bubble.is-failed {
    border: 1px dashed var(--danger);
    background: var(--danger-soft);
    color: var(--danger);
}

.msg-text {
    margin: 0;
    white-space: pre-wrap;
}

.msg-text a {
    color: var(--accent);
}

.msg-files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.msg-files:first-child {
    margin-top: 0;
}

.msg-image {
    display: block;
    max-width: 260px;
    max-height: 260px;
    border-radius: 10px;
    cursor: zoom-in;
    background: var(--bg-soft);
    object-fit: cover;
}

.msg-row.is-own .msg-image {
    background: rgba(255, 255, 255, 0.12);
}

.file-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: rgba(127, 127, 127, 0.12);
    color: inherit;
    text-decoration: none;
    font-size: 13px;
    min-width: 0;
}

.file-card:hover {
    background: rgba(127, 127, 127, 0.22);
}

.file-card .file-icon {
    flex: none;
    font-size: 18px;
}

.file-card .file-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.file-card .file-name {
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.file-card .file-size {
    color: var(--text-muted);
    font-size: 11px;
}

.msg-row.is-own .file-card .file-size {
    color: rgba(255, 255, 255, 0.75);
}

.audio-player {
    width: 240px;
    max-width: 100%;
    display: block;
}

.reply-quote {
    margin: 0 0 6px;
    padding: 6px 8px;
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    background: rgba(127, 127, 127, 0.1);
    color: var(--text-muted);
    font-size: 12px;
    white-space: pre-wrap;
    max-height: 72px;
    overflow: hidden;
}

.msg-row.is-own .reply-quote {
    border-left-color: rgba(255, 255, 255, 0.75);
    color: rgba(255, 255, 255, 0.85);
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
    color: var(--text-faint);
    font-size: 11px;
    min-height: 16px;
}

.msg-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.msg-row:hover .msg-actions,
.msg-row:focus-within .msg-actions {
    opacity: 1;
}

@media (hover: none) {
    .msg-actions {
        opacity: 1;
    }
}

.msg-actions .icon-button {
    min-width: 26px;
    height: 24px;
    font-size: 12px;
}

.msg-status {
    color: var(--text-faint);
    font-size: 11px;
}

.msg-status.is-failed {
    color: var(--danger);
}

.msg-status .retry-link {
    margin-left: 4px;
    border: 0;
    background: transparent;
    color: var(--accent);
    font-size: 11px;
    text-decoration: underline;
    padding: 0;
}

/* ---------- 输入中 / 已读 ---------- */
.typing-row {
    padding: 2px 18px 4px;
    color: var(--text-muted);
    font-size: 12px;
    min-height: 20px;
}

/* ---------- 输入区 ---------- */
.composer {
    position: relative;
    padding: 8px 12px calc(10px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
}

.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.composer-input {
    flex: 1;
    min-height: 38px;
    max-height: 160px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
    color: var(--text);
    resize: none;
    line-height: 1.4;
}

.composer-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    outline: none;
}

.send-button {
    flex: none;
    height: 38px;
    padding: 0 16px;
    background: var(--accent);
    color: #fff;
}

.send-button:hover {
    background: var(--accent-strong);
}

.composer.is-recording .composer-input {
    border-color: var(--danger);
}

.record-state {
    color: var(--danger);
    font-size: 12px;
    font-weight: 700;
    padding: 4px 2px;
}

.reply-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 6px 8px;
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    background: var(--bg-soft);
}

.reply-bar-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.reply-bar-label {
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
}

.reply-bar-text {
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pending-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.pending-attachments:empty {
    display: none;
}

.pending-chip {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 200px;
    padding: 4px 8px 4px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 12px;
}

.pending-chip img {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
}

.pending-chip .pending-name {
    max-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pending-chip .icon-button {
    min-width: 22px;
    height: 22px;
    font-size: 11px;
}

.pending-chip .file-icon {
    font-size: 16px;
}

.upload-progress {
    position: relative;
    height: 22px;
    margin-bottom: 8px;
    border-radius: var(--radius-pill);
    background: var(--bg-soft);
    overflow: hidden;
}

.upload-progress-bar {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0;
    background: var(--accent);
    transition: width 0.15s ease;
}

.upload-progress-label {
    position: relative;
    display: block;
    text-align: center;
    font-size: 11px;
    line-height: 22px;
    color: var(--text);
    mix-blend-mode: normal;
}

/* ---------- @ 提及弹层 ---------- */
.mention-popup {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(100% + 6px);
    max-height: 220px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    box-shadow: var(--shadow-md);
    z-index: 10;
}

.mention-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    text-align: left;
}

.mention-item:hover,
.mention-item.is-active {
    background: var(--bg-soft);
}

/* =========================================================================
   弹层 / 弹窗
   ========================================================================= */
.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(8, 12, 18, 0.5);
    backdrop-filter: blur(2px);
}

.modal-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 520px;
    max-height: min(86vh, 760px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    flex: 1;
    margin: 0;
    font-size: 17px;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.settings-section + .settings-section {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.settings-section h3 {
    margin: 0 0 12px;
    font-size: 14px;
}

.plain-list {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.plain-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.plain-list .list-main {
    flex: 1;
    min-width: 0;
}

.plain-list .list-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plain-list .list-sub {
    color: var(--text-muted);
    font-size: 12px;
}

.invite-result {
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 13px;
}

.invite-code {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 1px;
    user-select: all;
}

.member-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
}

.member-item:hover {
    background: var(--bg-soft);
}

.member-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.member-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.member-role {
    color: var(--text-faint);
    font-size: 11px;
}

.online-dot {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
}

.online-dot.is-online {
    background: var(--success);
}

/* ---------- 图片查看器 ---------- */
.viewer {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.88);
    cursor: zoom-out;
}

.viewer-image {
    max-width: 100%;
    max-height: 100%;
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
}

/* ---------- Toast ---------- */
.toast-container {
    position: fixed;
    left: 50%;
    bottom: calc(24px + var(--safe-bottom));
    z-index: 70;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transform: translateX(-50%);
    pointer-events: none;
    width: min(92vw, 420px);
}

.toast {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: rgba(20, 26, 34, 0.94);
    color: #f4f6f8;
    font-size: 13px;
    text-align: center;
    box-shadow: var(--shadow-md);
    animation: toast-in 0.16s ease;
}

.toast.is-error {
    background: var(--danger);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
}

/* =========================================================================
   响应式：手机单栏
   ========================================================================= */
@media (max-width: 860px) {
    .main {
        grid-template-columns: 1fr;
        position: relative;
    }

    .sidebar,
    .chat {
        grid-column: 1;
        grid-row: 1;
        height: 100vh;
        height: 100dvh;
    }

    .sidebar {
        border-right: 0;
    }

    /* 默认显示房间列表；进入聊天时切换为单栏聊天 */
    .app[data-view="rooms"] .chat {
        display: none;
    }

    .app[data-view="chat"] .sidebar {
        display: none;
    }

    .mobile-only {
        display: inline-flex;
    }

    .chat-header {
        padding-left: 6px;
    }

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

    .msg-image {
        max-width: 200px;
        max-height: 200px;
    }

    .audio-player {
        width: 200px;
    }

    .modal {
        align-items: flex-end;
        padding: 0;
    }

    .modal-card {
        max-width: 100%;
        max-height: 88vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .toast-container {
        bottom: calc(84px + var(--safe-bottom));
    }
}

/* 横屏手机/小平板 */
@media (max-width: 860px) and (orientation: landscape) {
    .chat,
    .sidebar {
        height: 100vh;
        height: 100dvh;
    }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
/* =========================================================================
   盆盆设置（admin）
   ========================================================================= */
.modal-card-wide {
    max-width: 760px;
}

.agent-settings-body {
    display: flex;
    flex-direction: column;
}

.agent-note {
    margin: 0 0 14px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.6;
    word-break: break-word;
}

.agent-note.is-warn {
    color: var(--danger);
}

.agent-note code {
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--bg-soft);
    font-size: 11px;
    word-break: break-all;
}

.agent-grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0 12px;
}

.agent-plugin-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.agent-plugin {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
}

.agent-plugin input[type="checkbox"] {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin: 3px 0 0;
    accent-color: var(--accent);
}

.agent-plugin-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.agent-plugin-text strong {
    font-weight: 600;
}

.agent-plugin-text small {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.5;
    word-break: break-word;
}

.agent-input[readonly] {
    background: var(--bg-soft);
    color: var(--text-muted);
    cursor: not-allowed;
}

.agent-secret-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
}

.agent-secret {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    min-width: 0;
}

.agent-secret-label {
    font-weight: 600;
}

.agent-secret-state.is-ok {
    color: var(--accent);
    font-weight: 600;
}

.agent-secret-state.is-missing {
    color: var(--danger);
    font-weight: 600;
}

.agent-secret-hint {
    color: var(--text-muted);
    line-height: 1.5;
    word-break: break-word;
}

.modal-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 16px calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
}

.modal-footer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-wrap: wrap;
}

.modal-status {
    flex: 1 1 100%;
    min-height: 16px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.5;
    word-break: break-word;
}

.modal-status.is-ok {
    color: var(--accent);
}

.modal-status.is-error {
    color: var(--danger);
}

@media (max-width: 720px) {
    .agent-grid-2,
    .agent-secret-list {
        grid-template-columns: minmax(0, 1fr);
    }

    .agent-settings-body {
        padding: 12px;
    }

    .modal-footer-actions {
        width: 100%;
        margin-left: 0;
    }

    .modal-footer-actions .primary-button,
    .modal-footer-actions .ghost-button {
        flex: 1 1 auto;
    }
}
