/* ===== AI 助手 · 基础 ===== */
#ai-agent{--agent-brand:#2563eb;--agent-brand-2:#4f8bfa;--agent-ink:#172338;--agent-muted:#6b7d99;--agent-line:#e6edf8;--agent-navy:#152b50;font-family:system-ui,-apple-system,"PingFang SC","Microsoft YaHei",sans-serif;font-size:14px;line-height:1.55;color:var(--agent-ink);position:relative;z-index:10050;-webkit-tap-highlight-color:transparent}
#ai-agent *{box-sizing:border-box}
#ai-agent [hidden]{display:none!important}
#ai-agent button,#ai-agent select,#ai-agent textarea,#ai-agent input{font:inherit}
#ai-agent button{cursor:pointer;border:0}
#ai-agent button:focus-visible,#ai-agent select:focus-visible,#ai-agent textarea:focus-visible{outline:2px solid var(--agent-brand);outline-offset:2px}
#ai-agent button:disabled{opacity:.55;cursor:wait}

/* ===== 悬浮启动按钮 ===== */
#agent-launcher{position:fixed;right:24px;bottom:24px;display:inline-flex;align-items:center;gap:9px;padding:13px 20px;border-radius:999px;background:linear-gradient(135deg,#2563eb,#4f8bfa 62%,#3aa5f8);color:#fff;font-weight:600;letter-spacing:.3px;box-shadow:0 16px 34px -14px rgba(37,99,235,.8),0 4px 14px -6px rgba(21,43,80,.3);transition:transform .2s ease,box-shadow .2s ease}
#agent-launcher:hover{transform:translateY(-2px);box-shadow:0 20px 42px -14px rgba(37,99,235,.9),0 8px 22px -8px rgba(21,43,80,.32)}
#agent-launcher:active{transform:translateY(0) scale(.97)}
#agent-launcher::before{content:'';position:absolute;inset:0;border-radius:inherit;pointer-events:none;animation:agent-pulse 3.8s ease-out infinite}
.agent-launcher-icon{display:grid;place-items:center;width:23px;height:23px;font-size:15px;border-radius:8px;background:rgba(255,255,255,.18);transition:transform .3s ease}
#ai-agent.agent-open .agent-launcher-icon{transform:scale(.85) rotate(45deg)}
.agent-launcher-text{white-space:nowrap}

/* ===== 面板 ===== */
#agent-panel{position:fixed;right:24px;bottom:88px;width:min(420px,calc(100vw - 32px));height:min(700px,calc(100vh - 116px));height:min(700px,calc(100dvh - 116px));display:flex;flex-direction:column;overflow:hidden;background:#fff;border:1px solid rgba(230,237,248,.9);border-radius:22px;box-shadow:0 34px 90px -30px rgba(21,43,80,.5),0 12px 30px -18px rgba(21,43,80,.26);opacity:0;transform:translateY(18px) scale(.97);transform-origin:100% 100%;transition:opacity .2s ease,transform .3s cubic-bezier(.2,.9,.25,1.2)}
#ai-agent.agent-open #agent-panel{opacity:1;transform:none}

/* ===== 头部 ===== */
.agent-header{position:relative;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:16px 18px;color:#fff;background:linear-gradient(130deg,#152b50,#1c3f74 55%,#24548f)}
.agent-header::after{content:'';position:absolute;inset:0;pointer-events:none;background:radial-gradient(130% 150% at 100% 0,rgba(96,165,250,.38),transparent 58%)}
.agent-header-title{position:relative;z-index:1;display:flex;align-items:center;gap:11px;min-width:0}
.agent-header-badge{display:grid;place-items:center;width:34px;height:34px;font-size:16px;border-radius:11px;background:rgba(255,255,255,.12);border:1px solid rgba(255,255,255,.18);box-shadow:inset 0 1px 0 rgba(255,255,255,.22)}
.agent-header strong{display:block;font-size:15.5px;letter-spacing:.3px}
.agent-header small{display:block;margin-top:2px;font-size:10.5px;letter-spacing:2.4px;color:#a9c4ea}
#agent-close{position:relative;z-index:1;display:grid;place-items:center;width:30px;height:30px;border-radius:9px;color:#dbe7f8;background:rgba(255,255,255,.08);transition:background .15s,color .15s,transform .15s}
#agent-close:hover{background:rgba(255,255,255,.18);color:#fff}
#agent-close:active{transform:scale(.92)}

/* ===== 工具栏 ===== */
.agent-toolbar{display:flex;align-items:center;gap:6px;padding:9px 12px;border-bottom:1px solid var(--agent-line);background:#fff}
.agent-model-field{display:flex;align-items:center;gap:6px;flex:1;min-width:0;margin:0;font-size:12px;color:var(--agent-muted)}
#agent-model{appearance:none;-webkit-appearance:none;max-width:162px;padding:6px 24px 6px 10px;border:1px solid transparent;border-radius:9px;background-color:#f2f6fc;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0,0,12,12'%3E%3Cpath d='M3,4.6l3,3,3-3' fill='none' stroke='%236b7d99' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 8px center;background-size:12px;color:#2c4a72;font-size:12px;cursor:pointer;transition:background-color .15s,border-color .15s}
#agent-model:hover{background-color:#e9f0fb}
#agent-model:disabled{opacity:.6;cursor:wait}
.agent-toolbar button{display:inline-flex;align-items:center;gap:5px;padding:6px 10px;border-radius:9px;background:transparent;color:#41608c;font-size:12px;transition:background .15s,color .15s}
.agent-toolbar button:hover{background:#f0f5fd;color:var(--agent-brand)}
.agent-toolbar button[aria-expanded="true"]{background:#ecf3ff;color:var(--agent-brand)}
.agent-chevron{color:#8ba1c2;transition:transform .2s ease}
.agent-toolbar button[aria-expanded="true"] .agent-chevron{transform:rotate(180deg);color:var(--agent-brand)}

/* ===== Skills 面板 ===== */
#agent-skills{max-height:260px;overflow:auto;padding:14px 16px 16px;border-bottom:1px solid var(--agent-line);background:linear-gradient(#f9fbff,#f3f8ff);animation:agent-fade .22s ease;scrollbar-width:thin;scrollbar-color:#c9d6ea transparent}
#agent-skills::-webkit-scrollbar{width:9px}
#agent-skills::-webkit-scrollbar-thumb{background:#d5dfee;border:2px solid transparent;border-radius:9px;background-clip:content-box}
.agent-skills-head strong{font-size:12.5px;color:#22385c}
.agent-skills-head p{margin:3px 0 8px;font-size:11px;line-height:1.5;color:#8296b1}
.agent-skill-group{display:grid;gap:8px}
.agent-skill-group:empty{display:none}
.agent-skill-group:not(:empty)::before{content:'已安装';grid-column:1/-1;margin:6px 0 -2px;font-size:10px;letter-spacing:1.6px;color:#93a7c3}
#agent-catalog:not(:empty)::before{content:'可安装'}
.agent-skill-row{display:flex;align-items:flex-start;gap:8px;padding:9px 10px;background:#fff;border:1px solid #e4ecf8;border-radius:11px;transition:border-color .15s,box-shadow .15s}
.agent-skill-row:hover{border-color:#c9dbf8;box-shadow:0 8px 18px -14px rgba(37,99,235,.6)}
.agent-skill-row label{flex:1;min-width:0;margin:0;font-size:12.5px;color:#2c4166}
.agent-skill-row small{display:block;margin-top:2px;font-size:11px;line-height:1.45;color:#7d90ab}
.agent-skill-row input[type="checkbox"]{width:15px;height:15px;margin:1px 6px 0 0;accent-color:var(--agent-brand);vertical-align:-2px;cursor:pointer}
.agent-skill-row button{flex:0 0 auto;padding:5px 10px;border:1px solid #d9e4f5;border-radius:8px;background:#f6f9fe;color:#356094;font-size:11px;transition:background .15s,border-color .15s,color .15s}
.agent-skill-row button:hover:not(:disabled){background:#eaf2ff;border-color:#c3d8f8;color:var(--agent-brand)}

/* ===== SKILL.md 上传 ===== */
.agent-upload{display:flex;align-items:center;gap:10px;margin-top:14px;padding:11px 12px;border:1.5px dashed #bcd0ee;border-radius:12px;background:rgba(255,255,255,.75);cursor:pointer;transition:border-color .15s,background .15s,transform .15s,box-shadow .15s}
.agent-upload:hover{border-color:#8fb4f2;background:#fff}
.agent-upload.is-drag{border-color:var(--agent-brand);background:#ecf4ff;box-shadow:0 10px 22px -16px rgba(37,99,235,.8)}
.agent-upload input{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;border:0;clip:rect(0 0 0 0);clip-path:inset(50%)}
.agent-upload:has(input:focus-visible){outline:2px solid var(--agent-brand);outline-offset:2px;border-color:var(--agent-brand)}
.agent-upload-icon{flex:0 0 auto;display:grid;place-items:center;width:34px;height:34px;border-radius:10px;background:#e8f1ff;color:var(--agent-brand)}
.agent-upload-text{min-width:0}
.agent-upload-text strong{display:block;font-size:12.5px;color:#22385c}
.agent-upload-text small{display:block;margin-top:2px;font-size:10.5px;color:#8296b1}

/* ===== 对话区 ===== */
#agent-messages{flex:1;min-height:90px;overflow-y:auto;padding:18px 16px 14px;overscroll-behavior:contain;background:linear-gradient(#f7faff,#fdfeff 240px);scrollbar-width:thin;scrollbar-color:#c9d6ea transparent}
#agent-messages::-webkit-scrollbar{width:9px}
#agent-messages::-webkit-scrollbar-thumb{background:#d5dfee;border:2px solid transparent;border-radius:9px;background-clip:content-box}
#agent-messages::-webkit-scrollbar-thumb:hover{background:#bdcbe2;border:2px solid transparent;background-clip:content-box}
#agent-messages::-webkit-scrollbar-track{background:transparent}
.agent-welcome{padding:26px 4px 10px;text-align:center;animation:agent-fade .3s ease}
.agent-welcome-badge{display:grid;place-items:center;width:54px;height:54px;margin:0 auto;font-size:24px;color:#fff;border-radius:17px;background:linear-gradient(135deg,#2563eb,#5b9bff 70%,#7cc4ff);box-shadow:0 18px 34px -16px rgba(37,99,235,.8)}
.agent-welcome h3{margin:14px 0 6px;font-size:18px;letter-spacing:.2px;color:#1d3357}
.agent-welcome p{margin:0 0 20px;font-size:12.5px;line-height:1.7;color:#7f91a9}
.agent-prompt{position:relative;display:block;width:100%;margin-top:9px;padding:11px 34px 11px 14px;text-align:left;font-size:12.5px;line-height:1.5;color:#33537d;background:#fff;border:1px solid #e2eaf6;border-radius:12px;box-shadow:0 1px 2px rgba(21,43,80,.03);transition:border-color .16s,box-shadow .16s,transform .16s,color .16s}
.agent-prompt::after{content:'→';position:absolute;right:14px;top:50%;transform:translateY(-50%) translateX(-4px);opacity:0;color:var(--agent-brand);transition:opacity .16s,transform .16s}
.agent-prompt:hover{border-color:#bcd2f5;color:#1f4bb0;box-shadow:0 12px 24px -18px rgba(37,99,235,.8);transform:translateY(-1px)}
.agent-prompt:hover::after{opacity:1;transform:translateY(-50%)}

/* ===== 消息气泡 ===== */
.agent-message{display:flex;gap:10px;margin-bottom:16px;animation:agent-in .26s ease both}
.agent-user{flex-direction:row-reverse}
.agent-message-avatar{flex:0 0 30px;width:30px;height:30px;border-radius:10px;display:grid;place-items:center;font-size:13px;color:var(--agent-brand);background:linear-gradient(135deg,#e9f1ff,#d7e7ff);border:1px solid #dce8fb}
.agent-message-avatar::before{content:'✦'}
.agent-user .agent-message-avatar{background:#eef3f9 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0,0,24,24' fill='none' stroke='%2351678a' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4,21c0-4,3.6-6,8-6s8,2,8,6'/%3E%3C/svg%3E") center/15px no-repeat;border-color:#e1e8f3}
.agent-user .agent-message-avatar::before{content:none}
.agent-message-main{flex:1;min-width:0}
.agent-user .agent-message-main{display:flex;flex-direction:column;align-items:flex-end}
.agent-message-label{margin:0 0 5px 3px;font-size:10.5px;letter-spacing:.4px;color:#8ba0bd}
.agent-user .agent-message-label{margin:0 3px 5px 0}
.agent-message-text{width:fit-content;max-width:100%;padding:11px 13px;border:1px solid #e6edf8;border-radius:4px 14px 14px 14px;background:#fff;box-shadow:0 1px 2px rgba(21,43,80,.035);font-size:13.5px;line-height:1.72;white-space:pre-wrap;overflow-wrap:anywhere}
.agent-user .agent-message-text{border:0;border-radius:14px 4px 14px 14px;background:linear-gradient(135deg,#2f6ef0,#2563eb);color:#fff;box-shadow:0 12px 24px -16px rgba(37,99,235,.9)}

/* ===== Markdown 渲染（AI 气泡） ===== */
.agent-rich{white-space:normal}
.agent-rich>:first-child{margin-top:0}
.agent-rich>:last-child{margin-bottom:0}
.agent-rich p{margin:0 0 .6em}
.agent-rich h1,.agent-rich h2,.agent-rich h3,.agent-rich h4,.agent-rich h5,.agent-rich h6{margin:.95em 0 .45em;font-weight:700;line-height:1.4;color:#16294a}
.agent-rich h1{font-size:16.5px}
.agent-rich h2{font-size:15.5px}
.agent-rich h3{font-size:14.5px}
.agent-rich h4,.agent-rich h5,.agent-rich h6{font-size:13.5px}
.agent-rich ul,.agent-rich ol{margin:.35em 0;padding-left:1.45em}
.agent-rich li{margin:.18em 0}
.agent-rich li::marker{color:#7d94bb}
.agent-rich li.task-list-item{list-style:none}
.agent-rich code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,"Courier New",monospace;font-size:.92em;padding:1px 5px;border:1px solid #e4ecf8;border-radius:5px;background:#f1f5fb}
.agent-rich pre{margin:.55em 0;padding:10px 12px;border:1px solid #e4ecf8;border-radius:10px;background:#f5f8fd;overflow-x:auto}
.agent-rich pre code{padding:0;border:0;border-radius:0;background:none;font-size:12.5px;white-space:pre}
.agent-rich blockquote{margin:.5em 0;padding:2px 0 2px 11px;border-left:3px solid #c9dbf8;color:#5b7599}
.agent-rich blockquote p{margin:.2em 0}
.agent-rich table{display:block;max-width:100%;overflow-x:auto;margin:.55em 0;border-collapse:collapse;font-size:12.5px}
.agent-rich th,.agent-rich td{padding:5px 9px;border:1px solid #e0e9f6;text-align:left}
.agent-rich th{background:#f3f7fd;font-weight:600;color:#2c4166}
.agent-rich tr:nth-child(even) td{background:#fafcff}
.agent-rich hr{margin:.8em 0;border:0;border-top:1px solid #e6edf8}
.agent-rich a{color:var(--agent-brand);text-decoration:none;border-bottom:1px solid rgba(37,99,235,.35);overflow-wrap:anywhere}
.agent-rich a:hover{border-bottom-color:var(--agent-brand)}
.agent-rich img{max-width:100%;border-radius:9px}
.agent-rich input[type="checkbox"]{width:14px;height:14px;margin:0 5px 0 0;accent-color:var(--agent-brand);vertical-align:-2px}
.agent-rich del{color:#94a3b8}
.agent-typing{display:inline-flex;align-items:center;gap:5px;height:18px;padding-left:2px}
.agent-typing i{width:6px;height:6px;border-radius:50%;background:#a6b8d4;animation:agent-dot 1.15s ease-in-out infinite}
.agent-typing i:nth-child(2){animation-delay:.14s}
.agent-typing i:nth-child(3){animation-delay:.28s}
.agent-sources{width:fit-content;max-width:100%;margin-top:8px;font-size:11.5px}
.agent-sources:not(:empty){padding:8px 10px;border:1px dashed #dfe9f8;border-radius:11px;background:rgba(255,255,255,.78)}
.agent-sources a{display:flex;align-items:center;gap:6px;padding:4px 6px;border-radius:7px;color:#4f6d9c;text-decoration:none;transition:background .15s,color .15s}
.agent-sources a::before{content:'';flex:0 0 auto;width:5px;height:5px;border-radius:50%;background:linear-gradient(135deg,#2563eb,#6aa6ff)}
.agent-sources a:hover{background:#f0f6ff;color:var(--agent-brand)}
.agent-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}
.agent-actions button,.agent-actions a{display:inline-flex;align-items:center;gap:6px;padding:7px 12px;border:1px solid #dbe6fb;border-radius:9px;background:#f5f9ff;color:var(--agent-brand);font-size:12px;text-decoration:none;transition:background .15s,border-color .15s,transform .15s,box-shadow .15s}
.agent-actions button:hover:not(:disabled),.agent-actions a:hover{background:#e9f2ff;border-color:#bdd4fa;transform:translateY(-1px);box-shadow:0 10px 18px -14px rgba(37,99,235,.9)}
.agent-actions button:disabled{background:#f1f5fb;color:#7d90ab;border-color:#e4ebf6}
.agent-login{margin:16px 4px;padding:14px;text-align:center;font-size:12.5px;color:var(--agent-muted);background:#fff;border:1px dashed #c9dbf8;border-radius:12px}
.agent-login a{color:var(--agent-brand);font-weight:600;text-decoration:none}
.agent-login a:hover{text-decoration:underline}

/* ===== 底部（状态 + 输入） ===== */
.agent-foot{position:relative;background:#fff}
#agent-to-bottom{position:absolute;left:50%;bottom:calc(100% + 10px);z-index:3;display:inline-flex;align-items:center;gap:5px;padding:6px 12px;font-size:11.5px;color:#3f5b80;background:#fff;border:1px solid #e0e9f6;border-radius:999px;box-shadow:0 14px 30px -16px rgba(21,43,80,.6);opacity:0;visibility:hidden;transform:translateX(-50%) translateY(6px);transition:opacity .18s,transform .18s,visibility .18s}
#agent-to-bottom.is-shown{opacity:1;visibility:visible;transform:translateX(-50%)}
#agent-to-bottom:hover{color:var(--agent-brand);border-color:#c8daf8}
#agent-status{display:flex;align-items:center;gap:7px;min-height:24px;padding:0 18px;font-size:11.5px;color:#5b7599}
#agent-status:not(:empty){padding-top:2px;padding-bottom:8px}
#agent-status:not(:empty)::before{content:'';flex:0 0 auto;width:7px;height:7px;border-radius:50%;background:linear-gradient(135deg,#2563eb,#6aa6ff)}
#ai-agent.agent-busy #agent-status:not(:empty)::before{width:11px;height:11px;background:transparent;border:2px solid #cfdcf0;border-top-color:var(--agent-brand);animation:agent-spin .8s linear infinite}
#agent-form{padding:10px 12px 12px;border-top:1px solid var(--agent-line);background:#fff}
#agent-input{display:block;width:100%;min-height:46px;max-height:132px;padding:10px 12px;border:1px solid #e3ebf7;border-radius:13px;background:#f6f9fd;color:var(--agent-ink);line-height:1.6;resize:none;box-shadow:none;transition:border-color .16s,background .16s,box-shadow .16s}
#agent-input::placeholder{color:#9dabc0}
#agent-input:hover:not(:disabled){border-color:#d3e0f3}
#agent-input:focus{outline:none;border-color:#b9d2fa;background:#fff;box-shadow:0 0 0 3.5px rgba(37,99,235,.13)}
.agent-compose-footer{display:flex;align-items:center;gap:8px;padding-top:9px}
.agent-hint{flex:1;min-width:0;font-size:10.5px;line-height:1.5;color:#9aa8bc}
.agent-count{margin-left:6px;color:#7d90ab;font-variant-numeric:tabular-nums;white-space:nowrap}
#agent-send{display:inline-flex;align-items:center;gap:7px;padding:9px 15px;border-radius:11px;font-size:13px;font-weight:600;color:#fff;background:linear-gradient(135deg,#2563eb,#4f8bfa);box-shadow:0 14px 26px -14px rgba(37,99,235,.95);transition:transform .16s,box-shadow .16s,filter .16s}
#agent-send:hover:not(:disabled){transform:translateY(-1px);box-shadow:0 18px 30px -14px rgba(37,99,235,1)}
#agent-send:active:not(:disabled){transform:translateY(0) scale(.97)}
#agent-send:disabled{filter:saturate(.45);box-shadow:none}
#agent-stop{display:inline-flex;align-items:center;gap:7px;padding:9px 14px;border-radius:11px;font-size:12.5px;font-weight:600;color:#41577a;background:#eef2f9;transition:background .16s,color .16s}
#agent-stop:hover{background:#e3eaf5;color:#2c4166}
.agent-stop-icon{width:10px;height:10px;border-radius:3px;background:currentColor}
.agent-sr-only{position:absolute;left:-10000px}

/* ===== 动画 ===== */
@keyframes agent-in{from{opacity:0;transform:translateY(7px)}to{opacity:1;transform:none}}
@keyframes agent-fade{from{opacity:0}to{opacity:1}}
@keyframes agent-dot{0%,60%,100%{transform:translateY(0);opacity:.5}30%{transform:translateY(-4px);opacity:1}}
@keyframes agent-spin{to{transform:rotate(360deg)}}
@keyframes agent-pulse{0%{box-shadow:0 0 0 0 rgba(79,139,250,.42)}75%,100%{box-shadow:0 0 0 16px rgba(79,139,250,0)}}

/* ===== 响应式与无障碍 ===== */
@media(max-width:520px){
  #agent-launcher{right:16px;bottom:18px;padding:13px 15px}
  .agent-launcher-text{display:none}
  #agent-panel{right:8px;bottom:78px;width:calc(100vw - 16px);height:calc(100vh - 94px);height:calc(100dvh - 94px);border-radius:18px}
  #agent-model{max-width:132px}
  #agent-close{width:32px;height:32px}
}
@media(prefers-reduced-motion:reduce){
  #ai-agent *,#ai-agent *::before,#ai-agent *::after{animation-duration:.001ms!important;animation-iteration-count:1!important;transition-duration:.001ms!important}
}
