/* Qwen 聊天 PWA — 设计令牌 & 布局（DSH 风格：干净、克制、留白） */
:root{
  --bg:#f8f9fb;
  --panel:#ffffff;
  --panel2:#f1f3f7;
  --border:#e5e7eb;
  --text:#1f2937;
  --muted:#6b7280;
  --accent:#4f46e5;
  --accent-2:#7c3aed;
  --user:#4f46e5;
  --user-text:#ffffff;
  --radius:16px;
  --shadow:0 1px 2px rgba(16,24,40,.04),0 1px 3px rgba(16,24,40,.06);
  --safe-b:env(safe-area-inset-bottom,0px);
  --safe-t:env(safe-area-inset-top,0px);
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;background:var(--bg);color:var(--text);-webkit-font-smoothing:antialiased}
button{font-family:inherit;cursor:pointer;border:none;background:none;color:inherit}
textarea{font-family:inherit}

.app{display:flex;height:100%;max-width:1100px;margin:0 auto;background:var(--bg)}

/* ===== 侧栏 ===== */
.sidebar{width:260px;flex:0 0 260px;background:var(--panel);border-right:1px solid var(--border);display:flex;flex-direction:column;padding:14px;gap:12px}
@media (min-width:721px){
  .app.sidebar-collapsed .sidebar{display:none}
}
.sidebar-head{display:flex;align-items:center;justify-content:space-between}
.brand{font-weight:600;font-size:15px}
.collapse-side{display:inline-flex;width:28px;height:28px;border-radius:8px;background:var(--panel2);color:var(--muted);font-size:16px;line-height:1;align-items:center;justify-content:center}
.new-btn{background:var(--accent);color:#fff;border-radius:10px;padding:11px 14px;font-size:14px;font-weight:500;transition:filter .15s}
.new-btn:hover{filter:brightness(1.08)}
.session-list{flex:1;overflow-y:auto;display:flex;flex-direction:column;gap:4px}
.session-item{display:flex;align-items:center;gap:8px;padding:9px 10px;border-radius:10px;font-size:13px;color:var(--text);text-align:left;transition:background .12s}
.session-item:hover{background:var(--panel2)}
.session-item.active{background:#eef2ff;color:var(--accent)}
.session-item .t{flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.session-item .del{color:var(--muted);font-size:14px;line-height:1;padding:2px 4px;border-radius:6px;visibility:hidden}
.session-item:hover .del{visibility:visible}
.session-item .del:hover{color:#ef4444;background:#fee2e2}

/* ===== 主区 ===== */
.main{flex:1;display:flex;flex-direction:column;min-width:0}
.topbar{display:flex;align-items:center;gap:10px;padding:calc(10px + var(--safe-t)) 16px 10px;border-bottom:1px solid var(--border);background:var(--panel)}
.topbar-title{flex:1;min-width:0}
.session-title{font-weight:600;font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.meta{font-size:11px;color:var(--muted);margin-top:2px}
.version{font-size:11px;color:var(--muted);background:var(--panel2);padding:2px 8px;border-radius:999px}

.chat{flex:1;overflow-y:auto;padding:18px 16px;display:flex;flex-direction:column;gap:14px}
.row{display:flex;gap:10px;width:100%}
.row.user{justify-content:flex-end}
.bubble{max-width:82%;padding:10px 14px;border-radius:14px;line-height:1.65;font-size:14px;white-space:pre-wrap;word-break:break-word}
.row.user .bubble{background:var(--user);color:var(--user-text);border-bottom-right-radius:4px}
.row.ai .bubble{background:var(--panel);border:1px solid var(--border);border-bottom-left-radius:4px;box-shadow:var(--shadow)}

details.think{background:var(--panel2);border:1px solid var(--border);border-radius:10px;padding:6px 10px;margin-top:8px;font-size:12px;color:var(--muted)}
details.think summary{cursor:pointer;user-select:none;outline:none}
details.think pre{margin:6px 0 0;white-space:pre-wrap;word-break:break-word;color:#4b5563}
.thinking{font-size:12px;color:var(--muted);opacity:.8}
.cursor{display:inline-block;width:8px;height:1em;background:var(--accent);vertical-align:-2px;animation:blink 1s steps(2) infinite}
@keyframes blink{50%{opacity:0}}

/* ===== 输入区 ===== */
.composer-wrap{background:var(--panel);border-top:1px solid var(--border);padding:12px 16px calc(12px + var(--safe-b))}
.composer{display:flex;align-items:flex-end;gap:8px;max-width:820px;margin:0 auto;background:var(--panel);border:1px solid var(--border);border-radius:16px;padding:8px 8px 8px 14px;box-shadow:var(--shadow)}
.composer:focus-within{border-color:var(--accent)}
#inp{flex:1;border:none;outline:none;resize:none;font-size:14px;line-height:1.5;max-height:180px;background:transparent;color:var(--text);padding:4px 0}
#inp::placeholder{color:#9ca3af}
.send,.stop{width:38px;height:38px;flex:0 0 38px;border-radius:10px;font-size:18px;display:flex;align-items:center;justify-content:center}
.send{background:var(--accent);color:#fff}
.send:hover{filter:brightness(1.08)}
.send:disabled{opacity:.4;cursor:not-allowed}
.stop{background:#ef4444;color:#fff}
[hidden]{display:none!important}
.bar{max-width:820px;margin:8px auto 0;font-size:11px;color:var(--muted);min-height:14px;display:flex;justify-content:space-between;align-items:center;gap:12px}
.err{color:#ef4444}
.ctx{display:inline-flex;align-items:center;gap:7px;white-space:nowrap}
.ctx-bar{display:inline-block;width:54px;height:6px;border-radius:3px;background:var(--border);overflow:hidden}
.ctx-fill{display:block;height:100%;width:0;background:var(--accent);transition:width .3s ease}
.ctx.warn .ctx-fill{background:#f59e0b}
.ctx.danger .ctx-fill{background:#ef4444}

.scrim{display:none;position:fixed;inset:0;background:rgba(0,0,0,.35);z-index:9}

/* ===== Pod 控制条（紧凑） ===== */
.pod-bar{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:4px 12px;background:var(--panel2);border-bottom:1px solid var(--border);font-size:11px;color:var(--muted)}
.pod-status{font-weight:600}
.pod-status.ok{color:#16a34a}
.pod-status.off{color:#6b7280}
.pod-status.warn{color:#d97706}
.pod-status.err{color:#ef4444}
.pod-cost{color:var(--muted);font-size:11px;white-space:nowrap}
.pod-actions{display:flex;gap:5px}
.pod-btn{padding:3px 9px;border-radius:7px;font-size:11px;line-height:1.4;border:1px solid var(--border);background:var(--panel)}
.pod-btn:hover{filter:brightness(1.05)}
.pod-btn.start{background:var(--accent);color:#fff;border-color:var(--accent)}
.pod-btn.stop{background:#fff;color:#ef4444;border-color:#fecaca}
.pod-btn:disabled{opacity:.4;cursor:not-allowed}

/* ===== 图片附件 ===== */
.web-toggle{width:38px;height:38px;flex:0 0 38px;border-radius:10px;font-size:16px;display:flex;align-items:center;justify-content:center;color:var(--muted);background:var(--panel2)}
.web-toggle:hover{background:var(--border)}
.web-toggle.on{background:var(--accent);color:#fff}
.web-tag{display:inline-block;margin-left:6px;font-size:11px;color:var(--accent);background:var(--panel2);border-radius:6px;padding:1px 6px;white-space:nowrap}
.attach{width:38px;height:38px;flex:0 0 38px;border-radius:10px;font-size:17px;display:flex;align-items:center;justify-content:center;color:var(--muted);background:var(--panel2)}
.attach:hover{background:var(--border)}
.attach-list{display:flex;flex-wrap:wrap;gap:8px;max-width:820px;margin:0 auto 8px}
.attach-thumb{position:relative;width:64px;height:64px;border-radius:10px;overflow:hidden;border:1px solid var(--border)}
.attach-thumb img{width:100%;height:100%;object-fit:cover;display:block}
.attach-thumb .x{position:absolute;top:2px;right:2px;width:18px;height:18px;border-radius:50%;background:rgba(0,0,0,.55);color:#fff;font-size:12px;line-height:1;display:flex;align-items:center;justify-content:center;cursor:pointer}
.bubble img.bubble-img{max-width:100%;max-height:220px;border-radius:8px;display:block;margin-bottom:6px}
.row.user .bubble img.bubble-img{border:1px solid rgba(255,255,255,.3)}

/* ===== Markdown 渲染 ===== */
.bubble .md{white-space:normal;line-height:1.7;font-size:14px}
.bubble .md>*:first-child{margin-top:0}
.bubble .md>*:last-child{margin-bottom:0}
.md h1,.md h2,.md h3,.md h4{margin:.6em 0 .35em;line-height:1.3;font-weight:600}
.md h1{font-size:1.25em}.md h2{font-size:1.15em}.md h3{font-size:1.05em}
.md p{margin:.4em 0}
.md ul,.md ol{margin:.4em 0;padding-left:1.4em}
.md li{margin:.15em 0}
.md a{color:var(--accent)}
.md code{background:var(--panel2);border:1px solid var(--border);border-radius:4px;padding:.1em .3em;font-size:.9em}
.md pre{background:#0b1220;color:#e5e7eb;border-radius:8px;padding:10px 12px;overflow-x:auto;margin:.5em 0}
.md pre code{background:none;border:none;padding:0;color:inherit}
.md blockquote{border-left:3px solid var(--accent);margin:.4em 0;padding:.1em .8em;color:var(--muted);background:var(--panel2);border-radius:0 8px 8px 0}
.md hr{border:none;border-top:1px solid var(--border);margin:.7em 0}
.md table{border-collapse:collapse;margin:.5em 0;width:100%;font-size:13px}
.md th,.md td{border:1px solid var(--border);padding:5px 8px;text-align:left}
.md th{background:var(--panel2)}

/* ===== 手机 ===== */
@media (max-width:720px){
  .sidebar{position:fixed;left:0;top:0;bottom:0;z-index:10;transform:translateX(-100%);transition:transform .2s ease;box-shadow:var(--shadow)}
  .app:not(.sidebar-collapsed) .sidebar{transform:translateX(0)}
  .app:not(.sidebar-collapsed) .scrim{display:block}
  .pod-bar{flex-wrap:wrap}
  .bubble{max-width:88%}
}
