/* ============================================================
   Quay AI 客户端 —— 页面样式（与 HTML / JS 完全分离）
   颜色与圆角等统一取自项目设计变量（base.css / theme.css），
   深色模式由 theme.css 的 [data-theme="dark"] 自动接管。
   ============================================================ */

html, body { height: 100%; }

/* 统一处理 hidden：.btn 等自带 display 的类会覆盖 [hidden] 的默认样式 */
[hidden] { display: none !important; }

body {
    padding: 0;
    background: var(--bg-soft);
    color: var(--text);
    overflow: hidden;
}

/* 固定定位 + viewport 的 interactive-widget=resizes-content：
   移动端软键盘弹出时布局随可视区收缩，输入区始终可见 */
.ai-layout {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
}

/* ---------- 顶栏 ---------- */
.ai-top {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 54px;
    flex: none;
    padding: 0 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 30;
}

.ai-brand {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.01em;
    white-space: nowrap;
}

.ai-top-title {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.ai-model-chip {
    border: 0;
    font-family: var(--font);
    font-size: 11px;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 999px;
    padding: 2px 10px;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.ai-model-chip:hover { filter: brightness(.96); }

.ai-top-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-top-actions .btn { text-decoration: none; }

.ai-menu-btn {
    display: none;
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    flex: none;
    place-items: center;
}

/* 桌面端侧栏折叠按钮（移动端由汉堡菜单接管） */
.ai-collapse-btn {
    display: none;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    flex: none;
    place-items: center;
    transition: border-color .15s, color .15s;
}

.ai-collapse-btn:hover { border-color: var(--accent); color: var(--accent); }

@media (min-width: 861px) {
    .ai-collapse-btn { display: grid; }

    .ai-layout.side-collapsed .ai-side { display: none; }
}

/* ---------- 主体布局 ---------- */
.ai-body {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: stretch;
    gap: 16px;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 16px;
}

/* ---------- 侧栏 ---------- */
.ai-side {
    width: 208px;
    flex: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    min-height: 0;
}

.ai-new-chat { width: 100%; }

.ai-side-block {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ai-side-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    color: var(--text-faint);
    margin-bottom: 8px;
}

.ai-mini-danger {
    border: 0;
    background: transparent;
    font-family: var(--font);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0;
    color: var(--text-faint);
    cursor: pointer;
    padding: 1px 5px;
    border-radius: 5px;
}

.ai-mini-danger:hover { color: var(--danger); background: var(--danger-soft); }

.ai-chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-chat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 9px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    font-family: var(--font);
    font-size: 13px;
    color: var(--text-secondary);
    text-align: left;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.ai-chat-item:hover { background: var(--bg-soft); color: var(--text); }

.ai-chat-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.ai-chat-item .t {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-chat-item .del {
    flex: none;
    border: 0;
    background: transparent;
    color: var(--text-faint);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 5px;
    opacity: 0;
    transition: opacity .15s, color .15s, background .15s;
}

.ai-chat-item:hover .del { opacity: 1; }
.ai-chat-item .del:hover { color: var(--danger); background: var(--danger-soft); }

.ai-chat-empty {
    font-size: 12px;
    color: var(--text-faint);
    text-align: center;
    padding: 18px 0;
}

.ai-side-foot {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.ai-side-usage {
    font-size: 11px;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
    line-height: 1.6;
}

.ai-side-usage b { color: var(--text-secondary); font-weight: 600; }

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

.ai-status-dot.ok { background: var(--success); }

.ai-side-mask { display: none; }

/* ---------- 主区 ---------- */
.ai-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.ai-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
}

/* 空态：欢迎区垂直居中，避免顶部对齐留下大片空白 */
.ai-welcome {
    margin: auto;
    flex: none;
    text-align: center;
    padding: 48px 24px 40px;
}

.ai-welcome h2 {
    font-size: 19px;
    font-weight: 650;
    letter-spacing: -.01em;
    margin-bottom: 6px;
}

.ai-welcome p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 16px;
}

.ai-messages {
    flex: none;
    padding: 20px 20px 8px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* ---------- 消息气泡 ---------- */
.ai-msg { display: flex; gap: 10px; }
.ai-msg-user { justify-content: flex-end; }

.ai-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.ai-bubble {
    max-width: 82%;
    min-width: 0;
    font-size: 14px;
    line-height: 1.7;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    word-break: break-word;
    overflow-wrap: anywhere;
}

.ai-msg-user .ai-bubble {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ---------- Markdown 输出 ---------- */
.ai-bubble h1, .ai-bubble h2, .ai-bubble h3, .ai-bubble h4 {
    margin: 12px 0 6px;
    line-height: 1.4;
    font-weight: 650;
}

.ai-bubble > :first-child { margin-top: 0; }
.ai-bubble h1 { font-size: 19px; }
.ai-bubble h2 { font-size: 17px; }
.ai-bubble h3 { font-size: 15px; }
.ai-bubble h4 { font-size: 14px; }

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

.ai-bubble ul, .ai-bubble ol { margin: 0 0 10px; padding-left: 22px; }
.ai-bubble li { margin-bottom: 4px; }
.ai-bubble li:last-child { margin-bottom: 0; }

.ai-bubble a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; }
.ai-bubble a:hover { border-bottom-color: var(--accent); }
.ai-msg-user .ai-bubble a { color: #fff; border-bottom-color: rgba(255, 255, 255, .6); }

.ai-bubble blockquote {
    margin: 0 0 10px;
    padding: 6px 12px;
    border-left: 3px solid var(--border-strong);
    background: var(--bg);
    color: var(--text-secondary);
    border-radius: 0 8px 8px 0;
}

.ai-bubble hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }

.ai-bubble code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 5px;
}

.ai-msg-user .ai-bubble code { background: rgba(255, 255, 255, .18); border-color: transparent; }

.ai-code {
    margin: 0 0 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg);
}

.ai-bubble > .ai-code:last-child { margin-bottom: 0; }

.ai-code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 10px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-secondary);
}

.ai-code-head span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-code-copy {
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 5px;
    flex: none;
}

.ai-code-copy:hover { color: var(--accent); background: var(--accent-soft); }

.ai-code pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.ai-code pre code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.6; }

.ai-table-wrap { overflow-x: auto; margin: 0 0 10px; }
.ai-bubble table { border-collapse: collapse; font-size: 13px; width: 100%; }
.ai-bubble th, .ai-bubble td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.ai-bubble th { background: var(--bg-soft); font-weight: 600; }

/* 流式输出指示 */
.ai-typing { display: inline-flex; gap: 4px; padding: 5px 2px; }

.ai-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    animation: ai-blink 1.2s infinite;
}

.ai-typing i:nth-child(2) { animation-delay: .2s; }
.ai-typing i:nth-child(3) { animation-delay: .4s; }

@keyframes ai-blink {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
}

.ai-cursor {
    display: inline-block;
    width: 8px;
    height: 15px;
    margin-left: 2px;
    vertical-align: -2px;
    background: var(--accent);
    border-radius: 2px;
    animation: ai-blink 1s infinite;
}

.ai-msg-err {
    margin-top: 8px;
    font-size: 12px;
    color: var(--danger);
    line-height: 1.6;
}

/* ---------- 思考过程（reasoning） ---------- */
.ai-thinking {
    margin: 0 0 10px;
    border: 1px dashed var(--border-strong);
    border-radius: 10px;
    background: var(--bg);
    font-size: 13px;
    color: var(--text-secondary);
}

.ai-thinking > summary {
    list-style: none;
    cursor: pointer;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--text-faint);
    user-select: none;
}

.ai-thinking > summary::-webkit-details-marker { display: none; }
.ai-thinking > summary:hover { color: var(--accent); }

.ai-thinking-body {
    padding: 0 12px 10px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 320px;
    overflow-y: auto;
}

/* ---------- 消息元信息（模型 / 耗时） ---------- */
.ai-msg-meta {
    margin-top: 6px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 10px;
    font-size: 11px;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

.ai-msg-meta .m { color: var(--text-secondary); }

.ai-msg-meta .u {
    border: 0;
    background: transparent;
    font-family: var(--font);
    font-size: 11px;
    color: var(--text-faint);
    cursor: pointer;
    padding: 1px 6px;
    border-radius: 5px;
}

.ai-msg-meta .u:hover { color: var(--accent); background: var(--accent-soft); }

/* ---------- Token 用量明细 ---------- */
.ai-usage {
    margin-top: 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
}

.ai-usage[hidden] { display: none; }

.ai-usage-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text);
}

.ai-usage-head .cache-rate {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    color: var(--success);
}

.ai-usage-bar {
    width: 64px;
    height: 6px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
    flex: none;
}

.ai-usage-bar i {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--success);
}

.ai-usage-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 4px 10px;
}

.ai-usage-row .k { flex: none; width: 34px; color: var(--text-faint); }
.ai-usage-row .v { flex: 1; font-variant-numeric: tabular-nums; }
.ai-usage-row .v b { font-weight: 600; color: var(--text); }
.ai-usage-row .v .sub { color: var(--text-faint); }
.ai-usage-row .v .sub b { font-weight: 500; }

.ai-usage-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 2px;
    margin-right: 4px;
    vertical-align: 0;
}

.ai-usage-dot.hit { background: var(--success); }
.ai-usage-dot.miss { background: #f59e0b; }
.ai-usage-dot.write { background: #8b5cf6; }
.ai-usage-dot.think { background: var(--accent); }

.ai-msg-acts {
    margin-top: 6px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity .15s;
}

.ai-msg:hover .ai-msg-acts, .ai-msg-acts:focus-within { opacity: 1; }

.ai-mini {
    border: 0;
    background: transparent;
    font-family: var(--font);
    font-size: 11px;
    color: var(--text-faint);
    cursor: pointer;
    padding: 2px 7px;
    border-radius: 5px;
}

.ai-mini:hover { color: var(--accent); background: var(--accent-soft); }

/* ---------- 输入区 ---------- */
.ai-composer {
    flex: none;
    border-top: 1px solid var(--border);
    padding: 12px 16px 14px;
    background: var(--bg);
}

.ai-input {
    width: 100%;
    resize: none;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    padding: 10px 12px;
    min-height: 44px;
    max-height: 168px;
    outline: none;
    transition: border-color .15s;
}

.ai-input:focus { border-color: var(--accent); }
.ai-input::placeholder { color: var(--text-faint); }

.ai-composer-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.ai-composer-hint {
    font-size: 11px;
    color: var(--text-faint);
    margin-right: auto;
}

/* ---------- 能力开关（联网 / 思考） ---------- */
.ai-mode-group {
    display: flex;
    gap: 6px;
    margin-right: auto;
}

.ai-chip-toggle {
    height: 26px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .15s, color .15s, background .15s;
}

.ai-chip-toggle:hover { border-color: var(--accent); color: var(--accent); }

.ai-chip-toggle[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* 模型 chip（带下拉指示） */
.ai-chip-model { max-width: 148px; }

.ai-chip-model span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-chip-model .ai-caret {
    font-style: normal;
    font-size: 10px;
    margin-left: 3px;
    opacity: .8;
}

.ai-chip-model.active { border-color: var(--accent); color: var(--accent); }

/* ---------- 快捷配置浮层 ---------- */
.ai-composer { position: relative; }

.ai-pop {
    position: absolute;
    left: 0;
    bottom: calc(100% + 10px);
    z-index: 40;
    width: min(320px, calc(100vw - 32px));
    max-height: min(72vh, 460px);
    overflow-y: auto;
    padding: 6px;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: 0 20px 48px -16px rgba(0, 0, 0, .4);
    animation: ai-pop-in .16s ease-out;
}

@keyframes ai-pop-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

.ai-pop-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    font-family: var(--font);
    font-size: 13px;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: background .14s;
}

.ai-pop-row:hover { background: var(--bg-soft); }
.ai-pop-row.is-static { cursor: default; }
.ai-pop-row.is-static:hover { background: transparent; }

.ai-pop-k { flex: none; color: var(--text); }

.ai-pop-v {
    flex: 1;
    min-width: 0;
    text-align: right;
    color: var(--accent);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-pop-arrow { flex: none; color: var(--text-faint); font-size: 14px; }

/* 模型列表 */
.ai-pop-models {
    margin: 2px 0 4px;
    padding: 4px;
    background: var(--bg-soft);
    border-radius: 10px;
}

.ai-pop-model-list {
    max-height: 210px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.ai-pop-model {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 9px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-family: var(--font);
    font-size: 12.5px;
    color: var(--text-secondary);
    text-align: left;
    cursor: pointer;
    transition: background .14s, color .14s;
}

.ai-pop-model:hover { background: var(--bg); color: var(--text); }

.ai-pop-model.active { color: var(--accent); font-weight: 600; }
.ai-pop-model.active::after { content: "✓"; margin-left: auto; font-size: 12px; }

.ai-pop-empty {
    font-size: 12px;
    color: var(--text-faint);
    padding: 8px 9px;
}

.ai-pop-custom {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.ai-pop-custom .input { flex: 1; min-width: 0; height: 30px; font-size: 12.5px; }
.ai-pop-custom .btn { flex: none; }

/* 推理等级滑块 */
.ai-pop-block { padding: 4px 10px 8px; }

.ai-pop-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 20px;
    background: transparent;
    cursor: pointer;
    --fill: 50%;
}

.ai-pop-range::-webkit-slider-runnable-track {
    height: 8px;
    border-radius: 999px;
    background: linear-gradient(to right, var(--accent) var(--fill), var(--border) var(--fill));
}

.ai-pop-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--accent);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
    margin-top: -5px;
}

.ai-pop-range::-moz-range-track {
    height: 8px;
    border-radius: 999px;
    background: var(--border);
}

.ai-pop-range::-moz-range-progress {
    height: 8px;
    border-radius: 999px;
    background: var(--accent);
}

.ai-pop-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--accent);
}

.ai-pop-ticks {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 2px;
}

.ai-pop-ticks span { flex: 1; text-align: center; }
.ai-pop-ticks span:first-child { text-align: left; }
.ai-pop-ticks span:last-child { text-align: right; }

.ai-pop-more {
    display: block;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 0 0 10px 10px;
    background: transparent;
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    cursor: pointer;
    margin-top: 2px;
}

.ai-pop-more:hover { color: var(--accent); }

.ai-mode-row {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

.ai-mode-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 34px;
}

.ai-mode-name { font-size: 13px; color: var(--text); }
.ai-mode-name i { font-style: normal; font-size: 11px; color: var(--text-faint); margin-left: 4px; }

.ai-select {
    width: 96px;
    height: 30px;
    cursor: pointer;
}

/* 开关（与项目内开关一致） */
.ai-switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
    flex: none;
}

.ai-switch input { opacity: 0; width: 0; height: 0; }

.ai-switch .ai-slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--border-strong);
    cursor: pointer;
    transition: background .18s;
}

.ai-switch .ai-slider:before {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    transition: transform .18s;
}

.ai-switch input:checked + .ai-slider { background: var(--accent); }
.ai-switch input:checked + .ai-slider:before { transform: translateX(18px); }

/* ---------- 设置弹窗 ---------- */
.ai-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.ai-modal[hidden] { display: none; }

.ai-modal-mask {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, .45);
}

.ai-modal-card {
    position: relative;
    width: 100%;
    max-width: 520px;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 24px 60px -24px rgba(0, 0, 0, .55);
    animation: ai-modal-in .15s ease-out;
}

@keyframes ai-modal-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.ai-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: none;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.ai-modal-head h3 { font-size: 15px; font-weight: 600; }

.ai-modal-close {
    border: 0;
    background: transparent;
    font-size: 20px;
    line-height: 1;
    color: var(--text-faint);
    cursor: pointer;
    padding: 2px 7px;
    border-radius: 7px;
}

.ai-modal-close:hover { background: var(--bg-soft); color: var(--text); }

.ai-modal-body { padding: 16px 18px; overflow-y: auto; }

.ai-modal-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
}

.ai-flex-spacer { flex: 1; }

.ai-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin: 12px 0 5px;
}

.ai-label:first-child { margin-top: 0; }

.ai-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 2px;
}

.ai-preset {
    height: 24px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.ai-preset:hover { border-color: var(--accent); color: var(--accent); }

.ai-key-row { display: flex; gap: 8px; }
.ai-key-row .input { flex: 1; min-width: 0; }
.ai-key-row .btn { flex: none; }

.ai-textarea {
    height: auto;
    min-height: 56px;
    padding: 8px 10px;
    resize: vertical;
    line-height: 1.6;
}

.ai-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: end;
}

.ai-grid-2 input[type="range"] { width: 100%; accent-color: var(--accent); }

.ai-tip {
    font-size: 12px;
    color: var(--text-faint);
    line-height: 1.7;
    margin-top: 14px;
}

/* ---------- 轻提示 ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translate(-50%, 12px);
    background: var(--text);
    color: #fff;
    font-size: 13px;
    padding: 9px 16px;
    border-radius: 10px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 200;
    max-width: 86vw;
    text-align: center;
    box-shadow: 0 12px 28px -14px rgba(0, 0, 0, .5);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.toast-success { background: var(--success); }
.toast.toast-error { background: var(--danger); }

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

/* 平板 / 手机：侧栏收为抽屉，控件紧凑化 */
@media (max-width: 860px) {
    .ai-menu-btn { display: grid; }

    .ai-top {
        height: auto;
        min-height: 52px;
        flex-wrap: wrap;
        padding: 7px 12px;
        gap: 6px 10px;
    }

    .ai-top-actions { gap: 5px; }
    .ai-top-actions .btn { height: 28px; padding: 0 10px; font-size: 12px; }
    .ai-brand { font-size: 14px; }

    .ai-body { padding: 12px; gap: 12px; }

    .ai-side {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(248px, 82vw);
        border-radius: 0;
        border: 0;
        border-right: 1px solid var(--border);
        transform: translateX(-100%);
        transition: transform .25s cubic-bezier(.4, 0, .2, 1);
        z-index: 60;
        overflow-y: auto;
        padding: 12px;
    }

    .ai-side.is-open { transform: translateX(0); }

    .ai-side-mask {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(10, 13, 20, .45);
        opacity: 0;
        pointer-events: none;
        transition: opacity .25s;
        z-index: 55;
    }

    .ai-side-mask.is-open { opacity: 1; pointer-events: auto; }

    .ai-messages { padding: 14px 12px 4px; gap: 14px; }
    .ai-bubble { max-width: 92%; }

    /* 输入框 16px：避免 iOS 聚焦时页面自动放大 */
    .ai-input { font-size: 16px; }

    .ai-composer-bar { flex-wrap: wrap; row-gap: 6px; }
}

/* 手机：进一步压缩 */
@media (max-width: 560px) {
    .ai-top-title { display: none; }
    .ai-model-chip { max-width: 108px; }

    .ai-grid-2 { grid-template-columns: 1fr; }

    .ai-composer { padding: 10px 12px 12px; }
    .ai-composer-hint { display: none; }
    .ai-chip-toggle { height: 28px; padding: 0 9px; }

    .ai-msg { gap: 8px; }
    .ai-bubble { max-width: 94%; padding: 9px 12px; font-size: 13.5px; }
    .ai-avatar { width: 24px; height: 24px; font-size: 12px; border-radius: 7px; }

    .ai-welcome { padding: 40px 16px 32px; }
    .ai-welcome h2 { font-size: 18px; }

    .ai-modal { padding: 14px; }
    .ai-modal-card { border-radius: 12px; }
    .ai-modal-head, .ai-modal-body, .ai-modal-foot { padding-left: 14px; padding-right: 14px; }

    .ai-usage-head { flex-wrap: wrap; row-gap: 4px; }
}

/* 小屏手机 */
@media (max-width: 400px) {
    .ai-brand { display: none; }
    .ai-top { gap: 6px; }
    .ai-chip-toggle { padding: 0 8px; font-size: 11.5px; }
    .ai-bubble { max-width: 96%; }
    .ai-msg-meta { font-size: 10.5px; }
}

/* 横屏手机 / 矮窗：压缩纵向占用，保证对话区可见 */
@media (max-height: 520px) {
    .ai-top { min-height: 46px; }
    .ai-welcome { padding: 20px 16px; }
    .ai-welcome h2 { font-size: 17px; margin-bottom: 4px; }
    .ai-welcome p { margin-bottom: 10px; }
    .ai-composer { padding: 8px 12px 10px; }
    .ai-input { min-height: 38px; }
}
