/* ============================================================
   超级聊天室 · 样式（无外部 CDN 依赖）
   ============================================================ */

:root {
    --bg: #eef2f8;
    --surface: #ffffff;
    --surface-2: #f2f5fa;
    --text: #0f172a;
    --text-soft: #475569;
    --muted: #8792a2;
    --line: #e3e8f0;
    --accent: #2f6df6;
    --accent-dark: #1c4fd0;
    --accent-soft: #e5edff;
    --danger: #e5484d;
    --success: #16a34a;
    --warn: #d97706;
    --radius: 16px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow-md: 0 8px 28px rgba(15, 23, 42, .08);
    --shadow-lg: 0 24px 60px rgba(15, 23, 42, .18);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
            "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background:
        radial-gradient(1200px 600px at 15% -10%, #dbe7ff 0%, rgba(219, 231, 255, 0) 60%),
        radial-gradient(900px 500px at 90% 0%, #e8e2ff 0%, rgba(232, 226, 255, 0) 55%),
        var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

svg { width: 1em; height: 1em; fill: currentColor; }

/* ---------------------------------------------------------- 布局 */

.app {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 880px;
    height: 100dvh;
    margin: 0 auto;
    background: var(--surface-2);
    overflow: hidden;
}

@media (min-width: 900px) {
    .app {
        height: calc(100dvh - 36px);
        margin: 18px auto;
        border-radius: 22px;
        box-shadow: var(--shadow-lg);
    }
}

/* ---------------------------------------------------------- 顶栏 */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, .86);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(140deg, #4d8bff, #2f6df6 55%, #1c4fd0);
    box-shadow: 0 6px 16px rgba(47, 109, 246, .32);
    flex-shrink: 0;
}

.brand-mark svg { width: 21px; height: 21px; }

.brand-text { display: flex; flex-direction: column; min-width: 0; }

.brand-text strong {
    font-size: 16px;
    font-weight: 650;
    letter-spacing: .2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    color: var(--muted);
    line-height: 1.5;
}

.conn .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
}

.conn[data-state="live"] .dot { background: var(--success); box-shadow: 0 0 0 3px rgba(22, 163, 74, .16); }
.conn[data-state="connecting"] .dot { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
.conn[data-state="poll"] .dot { background: var(--accent); }
.conn[data-state="offline"] .dot { background: var(--danger); }

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

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 13.5px;
    font-family: inherit;
    font-weight: 550;
    cursor: pointer;
    transition: background .18s ease, color .18s ease, border-color .18s ease, transform .12s ease;
    background: none;
    color: var(--text-soft);
    white-space: nowrap;
}

.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(47, 109, 246, .25);
}

.btn-primary:hover { background: var(--accent-dark); }

.btn-ghost { border-color: var(--line); background: var(--surface); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-block { width: 100%; padding: 11px 14px; font-size: 14.5px; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
    text-decoration: none;
    transition: background .18s ease, color .18s ease;
    flex-shrink: 0;
}

.icon-btn:hover { background: rgba(15, 23, 42, .06); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.tiny { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn.tiny svg { width: 14px; height: 14px; }
.icon-btn.toggle[aria-pressed="true"] { background: var(--accent); color: #fff; }

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 550;
    max-width: 190px;
}

.user-chip:hover { background: #e8edf6; }
.user-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(140deg, #93b4ff, #5d8cf7);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
    user-select: none;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-sm { width: 26px; height: 26px; font-size: 11px; }

/* ---------------------------------------------------------- 消息区 */

.chat-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
}

.chat {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 14px 16px 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, .14); border-radius: 8px; }
.chat::-webkit-scrollbar-track { background: transparent; }

.chat-inner { display: flex; flex-direction: column; gap: 12px; min-height: 100%; }

.list-head { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.load-more {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-soft);
    border-radius: 999px;
    padding: 6px 16px;
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.load-more:hover { background: var(--surface-2); }
.load-more[disabled] { opacity: .6; cursor: default; }

.welcome {
    width: 100%;
    border-radius: 14px;
    padding: 10px 14px;
    background: linear-gradient(120deg, var(--accent-soft), #f6f0ff);
    color: #2b4a8f;
    font-size: 13px;
    line-height: 1.6;
    border: 1px solid rgba(47, 109, 246, .12);
}

.messages { display: flex; flex-direction: column; gap: 14px; }

.msg-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-margin: 80px;
}

.msg-block.flash { animation: flash 1.4s ease; }

@keyframes flash {
    0%, 55% { box-shadow: 0 0 0 6px rgba(47, 109, 246, .16); border-radius: 14px; }
    100% { box-shadow: 0 0 0 6px rgba(47, 109, 246, 0); border-radius: 14px; }
}

/* 消息行 */
.msg {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    contain: content;
}

.msg.enter { animation: enter .2s ease-out both; }

@keyframes enter {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.msg.mine { flex-direction: row-reverse; }

.msg-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: min(78%, 620px);
    min-width: 0;
    /* 关键：默认 stretch 会把气泡拉满整行，短消息右侧就会多出一块空白，
       加上表态后又会被表态行撑宽。改成按内容收缩。 */
    align-items: flex-start;
}

.msg.mine .msg-main { align-items: flex-end; }

.meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
    flex-wrap: wrap;
}

.meta .name { color: var(--text-soft); font-weight: 550; }
.msg.mine .meta { flex-direction: row-reverse; }

.role {
    font-size: 10.5px;
    line-height: 16px;
    height: 16px;
    padding: 0 6px;
    border-radius: 5px;
    font-weight: 600;
    letter-spacing: .2px;
}

.role-owner { color: #d13438; background: #fde8e8; }
.role-admin { color: #b45309; background: #fdf0dc; }
.role-member { color: #64748b; background: #eef1f6; }
.role-bot { color: #fff; background: linear-gradient(135deg, #5b8cff, #2f6df6); }

.bubble {
    position: relative;
    padding: 9px 13px;
    background: var(--surface);
    border-radius: 4px 16px 16px 16px;
    box-shadow: var(--shadow-sm);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
    max-width: 100%;
    width: fit-content;
}

.msg.mine .bubble {
    background: linear-gradient(135deg, #3f7bf8, #2f6df6);
    color: #fff;
    border-radius: 16px 4px 16px 16px;
    box-shadow: 0 4px 14px rgba(47, 109, 246, .22);
    white-space: pre-wrap;
}

.bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.msg.mine .bubble a { color: #eaf2ff; }

.bubble img {
    display: block;
    max-width: min(320px, 100%);
    max-height: 320px;
    border-radius: 12px;
    cursor: zoom-in;
    object-fit: cover;
    background: var(--surface-2);
}

.bubble.plain-img { padding: 0; background: transparent; box-shadow: none; }

.msg.mine .bubble.plain-img { background: transparent; box-shadow: none; }

/* 时间分隔 */
.time-sep {
    align-self: center;
    font-size: 11.5px;
    color: var(--muted);
    background: rgba(255, 255, 255, .75);
    padding: 3px 10px;
    border-radius: 999px;
    margin: 2px 0;
    user-select: none;
}

/* 撤回 */
.withdrawn {
    align-self: center;
    font-size: 12px;
    color: var(--muted);
    font-style: italic;
    padding: 4px 0;
}

/* 引用 */
.quote {
    border-left: 3px solid var(--accent);
    background: rgba(47, 109, 246, .07);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    line-height: 1.5;
    color: #4a5568;
    max-width: 100%;
    cursor: pointer;
}

.quote b { display: block; font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 1px; }
.quote span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.msg.mine .quote { background: rgba(255, 255, 255, .18); color: #eaf2ff; }
.msg.mine .quote b { color: #fff; }

/* 表态 */
.reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 1px;
}

.reactions:empty { display: none; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 12px;
    line-height: 18px;
    color: var(--text-soft);
    cursor: pointer;
    font-family: inherit;
    transition: background .15s ease, border-color .15s ease, transform .1s ease;
}

.chip:hover { border-color: #c8d5ec; background: var(--surface-2); }
.chip:active { transform: scale(.94); }
.chip.active { background: var(--accent-soft); border-color: #bcd0fb; color: var(--accent-dark); font-weight: 600; }
.chip .emoji { font-size: 13px; }

/* 卡片消息 */
.card {
    width: min(330px, 100%);
    background: var(--surface);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    color: var(--text);
    white-space: normal;
}

.card-head { padding: 13px 16px 6px; font-size: 15px; font-weight: 650; }
.card-body { display: flex; gap: 12px; padding: 4px 16px 14px; }
.card-text { flex: 1; min-width: 0; font-size: 13px; line-height: 1.6; color: var(--text-soft); }
.card-text p { margin: 0; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.card-img { width: 72px; height: 72px; border-radius: 10px; overflow: hidden; flex-shrink: 0; background: var(--surface-2); }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-line { height: 1px; background: var(--line); margin: 0 16px; }
.card-foot { display: flex; align-items: center; gap: 6px; padding: 9px 16px; font-size: 12px; color: var(--muted); }
.card-foot svg { width: 13px; height: 13px; color: var(--accent); }

.msg.mine .bubble .card { color: var(--text); }

/* 按钮消息 */
.btn-msg { display: flex; flex-direction: column; gap: 7px; white-space: normal; min-width: 200px; }
.btn-row { display: flex; gap: 7px; }
.msg-btn {
    flex: 1;
    min-width: 0;
    border: 0;
    border-radius: 9px;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 550;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: filter .15s ease, transform .1s ease;
}
.msg-btn:active { transform: scale(.98); }
.msg-btn:hover { filter: brightness(.96); }
.msg-btn.primary { background: var(--accent); color: #fff; }
.msg-btn.success { background: #22c55e; color: #fff; }
.msg-btn.warning { background: #f59e0b; color: #3b2600; }
.msg-btn.danger { background: var(--danger); color: #fff; }
.msg-btn.secondary { background: #64748b; color: #fff; }
.msg-btn.outline { background: transparent; border: 1px solid currentColor; color: var(--accent); }

/* Markdown */
.md { white-space: normal; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: .35em 0; }
.md h1, .md h2, .md h3, .md h4 { margin: .6em 0 .3em; line-height: 1.35; font-size: 1.05em; }
.md ul, .md ol { margin: .35em 0; padding-left: 1.35em; }
.md li { margin: .12em 0; }
.md blockquote {
    margin: .4em 0;
    padding: 2px 10px;
    border-left: 3px solid currentColor;
    opacity: .8;
}
.md code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .9em;
    background: rgba(15, 23, 42, .07);
    padding: 1px 5px;
    border-radius: 5px;
}
.msg.mine .bubble .md code { background: rgba(255, 255, 255, .22); }
.md pre {
    margin: .45em 0;
    padding: 10px 12px;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 10px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.55;
    white-space: pre;
}
.md pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
.md img { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; }
.md hr { border: 0; border-top: 1px solid currentColor; opacity: .2; margin: .6em 0; }

/* 待发送 / 失败状态 */
.msg.pending .bubble { opacity: .72; }
.msg.failed .bubble { background: #fdecec; color: #a4262c; box-shadow: inset 0 0 0 1px #f3c2c4; }
.msg.failed .meta::after { content: "发送失败，点击气泡重试"; color: var(--danger); font-size: 11px; }

/* 回到底部 */
.jump {
    position: absolute;
    right: 16px;
    bottom: 16px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--accent);
    border-radius: 999px;
    padding: 7px 13px;
    font-size: 12.5px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 15;
    animation: enter .18s ease-out both;
}

.jump svg { width: 15px; height: 15px; }

/* ---------------------------------------------------------- 输入区 */

.composer {
    position: relative;
    flex-shrink: 0;
    padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    z-index: 20;
}

.quote-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 7px;
    padding: 6px 8px 6px 12px;
    background: var(--accent-soft);
    border-radius: 10px;
    font-size: 12.5px;
    color: #2b4a8f;
}

.quote-bar-label { font-weight: 600; flex-shrink: 0; }
.quote-bar-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: .85;
}

.composer-box {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 5px;
    background: var(--surface-2);
    border: 1.5px solid transparent;
    border-radius: 16px;
    transition: border-color .18s ease, background .18s ease;
}

.composer-box:focus-within {
    background: var(--surface);
    border-color: rgba(47, 109, 246, .45);
    box-shadow: 0 0 0 4px rgba(47, 109, 246, .08);
}

.composer-box textarea {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    resize: none;
    padding: 8px 4px;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    outline: none;
    max-height: 132px;
    min-height: 36px;
}

.composer-box textarea::placeholder { color: #9aa4b2; }

.send {
    position: relative;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #4d8bff, #2f6df6);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity .18s ease, transform .12s ease;
}

.send svg { width: 19px; height: 19px; }
.send:hover { filter: brightness(1.05); }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .45; cursor: default; }

.spin {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.composer-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 5px 4px 0;
    font-size: 11px;
    color: var(--muted);
    user-select: none;
}

.composer-foot .credit { opacity: .8; }

/* 表情面板 */
.emoji-panel {
    position: absolute;
    left: 14px;
    bottom: calc(100% - 4px);
    width: min(280px, calc(100vw - 28px));
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    z-index: 40;
}

.emoji-panel button {
    border: 0;
    background: transparent;
    border-radius: 8px;
    font-size: 19px;
    line-height: 30px;
    height: 30px;
    cursor: pointer;
    padding: 0;
}

.emoji-panel button:hover { background: var(--surface-2); }

/* 上传预览 */
.upload-preview {
    margin-bottom: 8px;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
}

.upload-preview img {
    display: block;
    max-height: 180px;
    max-width: 100%;
    border-radius: 10px;
    margin: 0 auto 8px;
}

.upload-actions { display: flex; justify-content: center; gap: 8px; }

/* ---------------------------------------------------------- 操作面板 */

.sheet {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, .32);
    backdrop-filter: blur(2px);
}

@media (min-width: 640px) {
    .sheet { align-items: center; }
}

.sheet-card {
    width: min(360px, 100%);
    background: var(--surface);
    border-radius: 18px;
    padding: 12px;
    box-shadow: var(--shadow-lg);
    animation: enter .16s ease-out both;
}

.sheet-reactions {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}

.sheet-reactions button {
    border: 0;
    background: transparent;
    border-radius: 10px;
    font-size: 22px;
    line-height: 40px;
    height: 40px;
    cursor: pointer;
    padding: 0;
    transition: background .15s ease, transform .1s ease;
}

.sheet-reactions button:hover { background: var(--surface-2); transform: scale(1.08); }
.sheet-reactions button.on { background: var(--accent-soft); }

.sheet-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding-top: 8px;
}

.sheet-actions button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 0;
    background: transparent;
    border-radius: 10px;
    padding: 8px 0;
    font-family: inherit;
    font-size: 12px;
    color: var(--text-soft);
    cursor: pointer;
}

.sheet-actions button:hover { background: var(--surface-2); }
.sheet-actions svg { width: 18px; height: 18px; }

/* ---------------------------------------------------------- 图片查看器 */

.viewer {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: grid;
    place-items: center;
    background: rgba(8, 12, 20, .94);
    padding: 24px;
}

.viewer img {
    max-width: 94vw;
    max-height: 90vh;
    border-radius: 10px;
    object-fit: contain;
}

.viewer-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .16);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
}

/* ---------------------------------------------------------- 登录弹窗 */

.modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(3px);
}

.modal-card {
    position: relative;
    width: min(400px, 100%);
    background: var(--surface);
    border-radius: 20px;
    padding: 24px;
    box-shadow: var(--shadow-lg);
    animation: enter .18s ease-out both;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
}

.modal-card h2 { margin: 0 0 16px; font-size: 19px; font-weight: 650; }

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.modal-close:hover { background: var(--surface-2); }

.tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--surface-2);
    border-radius: 12px;
    margin-bottom: 16px;
}

.tab {
    flex: 1;
    border: 0;
    background: transparent;
    border-radius: 9px;
    padding: 8px 0;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 550;
    color: var(--text-soft);
    cursor: pointer;
}

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

.form { display: flex; flex-direction: column; gap: 12px; }

.form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12.5px;
    color: var(--text-soft);
    font-weight: 500;
}

.form input {
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 0 12px;
    font-family: inherit;
    font-size: 14.5px;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease;
}

.form input:focus {
    border-color: rgba(47, 109, 246, .55);
    box-shadow: 0 0 0 3px rgba(47, 109, 246, .1);
}

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

.meter { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; border-radius: 4px; transition: width .25s ease, background .25s ease; }

/* ---------------------------------------------------------- Toast */

.toasts {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    z-index: 100;
    pointer-events: none;
    width: max-content;
    max-width: calc(100vw - 24px);
}

.toast {
    background: rgba(15, 23, 42, .94);
    color: #fff;
    padding: 9px 16px;
    border-radius: 11px;
    font-size: 13px;
    box-shadow: var(--shadow-md);
    animation: enter .18s ease-out both;
    max-width: 100%;
}

.toast.error { background: #b42318; }
.toast.success { background: #0f766e; }

/* ---------------------------------------------------------- 响应式 */

@media (max-width: 560px) {
    .topbar { padding: 10px 12px; gap: 8px; }
    .brand-mark { width: 34px; height: 34px; border-radius: 11px; }
    .brand-text strong { font-size: 15px; }
    .user-chip { max-width: 118px; padding-right: 6px; }
    .user-chip span:last-child { font-size: 12.5px; }
    .btn { padding: 7px 11px; font-size: 13px; }
    .chat { padding: 12px 12px 6px; }
    .msg-main { max-width: 84%; }
    .bubble { font-size: 14.5px; }
    .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
    .composer-foot #composerHint { display: none; }
    .composer-box textarea { font-size: 16px; }
}

@media (max-width: 380px) {
    .icon-btn { width: 32px; }
    .composer-box { gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
