/* siderkit webapp — 白色背景主题（浅色为主，无深色反转） */

:root{
  --bg:#ffffff;
  --bg-soft:#f7f8fa;
  --bg-soft2:#f2f4f7;
  --panel:#ffffff;
  --line:#e5e7eb;
  --line-strong:#d1d5db;
  --text:#111827;
  --text-2:#374151;
  --muted:#6b7280;
  --muted-2:#9ca3af;
  --accent:#2563eb;
  --accent-2:#1d4ed8;
  --accent-soft:#eff6ff;
  --ok:#059669;
  --ok-soft:#ecfdf5;
  --warn:#b45309;
  --warn-soft:#fffbeb;
  --danger:#dc2626;
  --danger-soft:#fef2f2;
  --radius:10px;
  --radius-sm:7px;
  --shadow:0 1px 2px rgba(16,24,40,.05),0 1px 3px rgba(16,24,40,.08);
  --mono:"Cascadia Mono","JetBrains Mono",Consolas,"Liberation Mono",Menlo,monospace;
  --sans:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei UI","PingFang SC",
         "Hiragino Sans GB","Noto Sans CJK SC",Roboto,Helvetica,Arial,sans-serif;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--text); font:14.5px/1.62 var(--sans);
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3,h4{margin:0; font-weight:650; line-height:1.3}
a{color:var(--accent); text-decoration:none}
a:hover{text-decoration:underline}
code,kbd,pre{font-family:var(--mono)}
.hidden{display:none !important}
.spacer{flex:1}
.muted-sm{color:var(--muted); font-size:12.5px}
.ta-r{text-align:right}
.grow{flex:1}
.row{display:flex; gap:10px; align-items:flex-end; flex-wrap:wrap}
.row-end{justify-content:flex-end; align-items:center}
.inline{display:flex; align-items:center; gap:6px}
.lbl{color:var(--muted); font-size:12.5px; white-space:nowrap}

/* ============================================================ 顶部 */
.topbar{
  display:flex; align-items:center; gap:14px; padding:0 16px; height:54px;
  background:var(--panel); border-bottom:1px solid var(--line);
  position:sticky; top:0; z-index:30; flex-wrap:nowrap;
}
.brand{display:flex; align-items:center; gap:8px; flex:0 0 auto}
.brand-name{font-weight:700; letter-spacing:.2px}
.brand-sub{color:var(--muted); font-size:12.5px}
.tabs{display:flex; gap:2px; flex:1; min-width:0; overflow-x:auto; scrollbar-width:none}
.tabs::-webkit-scrollbar{display:none}
.tab{
  appearance:none; border:1px solid transparent; background:transparent; color:var(--text-2);
  font:inherit; font-size:13.5px; padding:7px 13px; border-radius:var(--radius-sm);
  cursor:pointer; white-space:nowrap;
}
.tab:hover{background:var(--bg-soft2)}
.tab.is-active{background:var(--accent-soft); border-color:#c7dbfe; color:var(--accent-2);
  font-weight:600}
.topbar-right{display:flex; align-items:center; gap:8px; flex:0 0 auto}
.pill{
  font-size:12px; padding:3px 9px; border-radius:999px; border:1px solid var(--line);
  background:var(--bg-soft); color:var(--muted); white-space:nowrap;
}
.pill-ok{border-color:#bbf7d0; background:var(--ok-soft); color:var(--ok)}
.pill-bad{border-color:#fecaca; background:var(--danger-soft); color:var(--danger)}

/* ============================================================ 通用控件 */
.btn{
  appearance:none; font:inherit; font-size:13.5px; padding:8px 14px; cursor:pointer;
  background:var(--panel); color:var(--text); border:1px solid var(--line-strong);
  border-radius:var(--radius-sm); white-space:nowrap; transition:.12s;
}
.btn:hover{border-color:var(--accent); color:var(--accent-2)}
.btn:disabled{opacity:.5; cursor:not-allowed}
.btn-primary{background:var(--accent); border-color:var(--accent); color:#fff; font-weight:600}
.btn-primary:hover{background:var(--accent-2); border-color:var(--accent-2); color:#fff}
.btn-ghost{background:var(--bg-soft); border-color:var(--line)}
.btn-danger{background:var(--danger-soft); border-color:#fecaca; color:var(--danger)}
.btn-danger:hover{border-color:var(--danger); color:var(--danger)}
.btn-sm{padding:5px 10px; font-size:12.5px}
.btn-block{width:100%}
.icon-btn{padding:8px 10px; font-size:16px; line-height:1}

.input,.select,textarea,select{
  font:inherit; color:var(--text); background:var(--panel);
  border:1px solid var(--line-strong); border-radius:var(--radius-sm); padding:8px 10px;
  width:100%; min-width:0;
}
textarea{resize:vertical; line-height:1.55}
.input:focus,.select:focus,textarea:focus,select:focus{
  outline:none; border-color:var(--accent); box-shadow:0 0 0 3px rgba(37,99,235,.12);
}
.input-sm{padding:5px 8px; font-size:12.5px; width:auto}
select[multiple]{padding:4px}
.chk{display:flex; align-items:center; gap:6px; color:var(--text-2); font-size:13px;
  cursor:pointer; white-space:nowrap}
.chk input{accent-color:var(--accent)}
.field{display:flex; flex-direction:column; gap:5px; margin-bottom:11px}
.field>span{color:var(--muted); font-size:12.5px}
.card{
  background:var(--panel); border:1px solid var(--line); border-radius:var(--radius);
  padding:16px; box-shadow:var(--shadow); margin-bottom:14px;
}
.card-grow{display:flex; flex-direction:column; min-height:0}
.card-title{
  display:flex; align-items:center; gap:8px; font-weight:650; font-size:14.5px;
  margin-bottom:12px; color:var(--text);
}
.grid-2{display:grid; grid-template-columns:repeat(auto-fit,minmax(370px,1fr)); gap:14px;
  align-items:start}
.grid-2>*{margin-bottom:0}
.grid-span-2{grid-column:1/-1}
.kv{display:grid; gap:7px; margin-bottom:11px}
.kv>div{display:flex; gap:10px; align-items:baseline; font-size:13px}
.kv>div>span:first-child{color:var(--muted); min-width:104px; flex:0 0 auto}
.kv code{background:var(--bg-soft); padding:2px 6px; border-radius:5px; font-size:12.5px;
  word-break:break-all}
details summary{cursor:pointer; color:var(--muted); font-size:13px; margin-top:6px}

/* ============================================================ 页面框架 */
.page{display:none; padding:16px; gap:16px; min-height:calc(100vh - 54px)}
.page.is-active{display:flex}
#page-chat{padding:0; gap:0; height:calc(100vh - 54px)}
#page-image{flex-wrap:wrap; align-items:flex-start}
.col-left{flex:1 1 340px; max-width:430px; min-width:300px}
.col-right{flex:2 1 460px; min-width:320px; display:flex; flex-direction:column;
  min-height:0}
#page-files,#page-tools,#page-settings{flex-direction:column}
#page-tools,#page-settings{display:none}
#page-tools.is-active,#page-settings.is-active{display:block}

/* ============================================================ 聊天 */
.sidebar{
  width:236px; flex:0 0 236px; background:var(--bg-soft); border-right:1px solid var(--line);
  display:flex; flex-direction:column; min-height:0;
}
.sidebar-head{padding:10px}
.sidebar-foot{padding:10px; border-top:1px solid var(--line)}
.conv-list{flex:1; overflow-y:auto; padding:0 8px 8px}
.conv-item{
  display:block; width:100%; text-align:left; border:1px solid transparent;
  background:transparent; font:inherit; font-size:13px; padding:8px 10px;
  border-radius:var(--radius-sm); cursor:pointer; color:var(--text-2);
  margin-bottom:2px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.conv-item:hover{background:var(--panel); border-color:var(--line)}
.conv-item.is-active{background:var(--panel); border-color:#c7dbfe; color:var(--accent-2);
  font-weight:600}
.conv-item .del{float:right; color:var(--muted-2); font-size:13px}
.conv-item .del:hover{color:var(--danger)}
.chat-main{flex:1; display:flex; flex-direction:column; min-width:0; min-height:0}
.toolbar{
  display:flex; align-items:center; gap:9px; padding:9px 14px; flex-wrap:wrap;
  border-bottom:1px solid var(--line); background:var(--panel);
}
.toolbar .select{width:auto; min-width:170px; max-width:280px}
.system-box{padding:10px 14px; border-bottom:1px solid var(--line); background:var(--bg-soft)}
.system-box textarea{margin-bottom:8px}
.chat-log{
  flex:1; overflow-y:auto; padding:18px 20px; display:flex; flex-direction:column; gap:16px;
  background:var(--bg);
}
.empty-hint{margin:auto; text-align:center; color:var(--muted); max-width:420px}
.empty-hint h2{font-size:19px; margin-bottom:6px; color:var(--text-2)}
.msg{display:flex; flex-direction:column; gap:5px; max-width:100%}
.msg-head{display:flex; align-items:center; gap:8px; font-size:12px; color:var(--muted)}
.msg-body{
  border:1px solid var(--line); border-radius:var(--radius); padding:11px 14px;
  background:var(--panel); box-shadow:var(--shadow); overflow-wrap:anywhere;
}
.msg.user{align-items:flex-end}
.msg.user .msg-body{background:var(--accent-soft); border-color:#c7dbfe}
.msg.error .msg-body{background:var(--danger-soft); border-color:#fecaca; color:var(--danger)}
.msg-actions{display:flex; gap:6px; opacity:0; transition:.15s}
.msg:hover .msg-actions{opacity:1}
.msg-actions button{
  border:1px solid var(--line); background:var(--panel); color:var(--muted); font-size:11.5px;
  border-radius:5px; padding:2px 7px; cursor:pointer; font-family:var(--sans);
}
.msg-actions button:hover{color:var(--accent-2); border-color:var(--accent)}
.attach-chips{display:flex; gap:6px; flex-wrap:wrap}
.chip{
  display:inline-flex; align-items:center; gap:5px; font-size:12px; padding:3px 8px;
  background:var(--bg-soft2); border:1px solid var(--line); border-radius:999px;
  color:var(--text-2); max-width:280px;
}
.chip .name{overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.chip .x{cursor:pointer; color:var(--muted-2); font-weight:700}
.chip .x:hover{color:var(--danger)}
.refs{font-size:12.5px; color:var(--muted); border-top:1px dashed var(--line);
  margin-top:9px; padding-top:8px}
.refs a{word-break:break-all}
.reasoning{font-size:13px; color:var(--text-2); background:var(--bg-soft);
  border-left:3px solid var(--line-strong); border-radius:0 var(--radius-sm) var(--radius-sm) 0;
  padding:9px 12px; margin-bottom:9px; white-space:pre-wrap; max-height:320px; overflow:auto}
.cursor::after{content:"▊"; animation:blink 1s steps(2) infinite; color:var(--accent)}
@keyframes blink{50%{opacity:0}}
.composer{border-top:1px solid var(--line); background:var(--panel); padding:10px 14px}
.attach-row{display:flex; gap:6px; flex-wrap:wrap; margin-bottom:8px}
.composer-input{display:flex; gap:8px; align-items:flex-end}
.composer-input textarea{max-height:200px; min-height:42px; resize:none}
.composer-input .btn{padding:9px 17px}
.composer-foot{display:flex; justify-content:space-between; gap:10px; margin-top:6px}

/* ============================================================ Markdown */
.md{font-size:14.5px; line-height:1.72; overflow-wrap:anywhere}
.md>*:first-child{margin-top:0}
.md>*:last-child{margin-bottom:0}
.md h1,.md h2,.md h3,.md h4{margin:18px 0 9px; line-height:1.35}
.md h1{font-size:22px; border-bottom:1px solid var(--line); padding-bottom:6px}
.md h2{font-size:19px; border-bottom:1px solid var(--line); padding-bottom:5px}
.md h3{font-size:16.5px}
.md h4{font-size:15px}
.md p{margin:9px 0}
.md ul,.md ol{margin:9px 0; padding-left:24px}
.md li{margin:3px 0}
.md li>ul,.md li>ol{margin:3px 0}
.md blockquote{
  margin:10px 0; padding:8px 14px; border-left:3px solid var(--accent);
  background:var(--bg-soft); color:var(--text-2); border-radius:0 var(--radius-sm) var(--radius-sm) 0;
}
.md blockquote>*:first-child{margin-top:0}
.md blockquote>*:last-child{margin-bottom:0}
.md code{
  background:var(--bg-soft2); border:1px solid var(--line); border-radius:5px;
  padding:1px 5px; font-size:.9em;
}
.md pre{
  position:relative; background:var(--bg-soft); border:1px solid var(--line);
  border-radius:var(--radius-sm); padding:11px 13px; overflow-x:auto; margin:11px 0;
}
.md pre code{background:none; border:none; padding:0; font-size:12.8px; line-height:1.6}
.md pre .code-lang{
  position:absolute; top:0; right:0; font-size:11px; color:var(--muted-2);
  background:var(--bg-soft2); border-left:1px solid var(--line);
  border-bottom:1px solid var(--line); padding:1px 7px;
  border-radius:0 var(--radius-sm) 0 var(--radius-sm); font-family:var(--sans);
}
.md pre .code-copy{
  position:absolute; top:0; right:0; font-size:11px; color:var(--muted);
  background:var(--panel); border:1px solid var(--line); border-radius:0 var(--radius-sm) 0 0;
  padding:2px 8px; cursor:pointer; font-family:var(--sans); opacity:0; transition:.15s;
}
.md pre:hover .code-copy{opacity:1}
.md pre .code-copy:hover{color:var(--accent-2)}
.md pre.has-lang .code-copy{right:0}
.md table{border-collapse:collapse; margin:11px 0; display:block; overflow-x:auto; max-width:100%}
.md th,.md td{border:1px solid var(--line); padding:6px 11px; text-align:left; font-size:13.5px}
.md th{background:var(--bg-soft); font-weight:650}
.md tr:nth-child(even) td{background:#fcfcfd}
.md hr{border:none; border-top:1px solid var(--line); margin:16px 0}
.md img{max-width:100%; border-radius:var(--radius-sm); border:1px solid var(--line)}
.md a{word-break:break-all}
.md input[type=checkbox]{margin-right:5px; accent-color:var(--accent)}
.md .katex-display{overflow-x:auto; overflow-y:hidden; padding:4px 0}
.md .katex{font-size:1.04em}

/* ============================================================ 图像 */
.drop-zone{
  border:1.5px dashed var(--line-strong); border-radius:var(--radius);
  background:var(--bg-soft); padding:16px; text-align:center; color:var(--muted);
  font-size:13px; margin-bottom:11px; transition:.15s;
}
.drop-zone.drop-wide{padding:26px}
.drop-zone.over{border-color:var(--accent); background:var(--accent-soft); color:var(--accent-2)}
.drop-zone>*{margin:4px 0}
.thumb-row{display:flex; gap:8px; flex-wrap:wrap; margin-bottom:11px}
.thumb{position:relative; width:74px; height:74px; border:1px solid var(--line);
  border-radius:var(--radius-sm); overflow:hidden; background:var(--bg-soft)}
.thumb img{width:100%; height:100%; object-fit:cover; display:block}
.thumb .x{
  position:absolute; top:1px; right:1px; width:18px; height:18px; line-height:16px;
  text-align:center; background:rgba(17,24,39,.72); color:#fff; border-radius:4px;
  cursor:pointer; font-size:12px;
}
.engine-meta{margin-bottom:9px; min-height:16px}
.progress{height:5px; background:var(--bg-soft2); border-radius:999px; overflow:hidden;
  margin:9px 0 5px}
.progress-bar{height:100%; width:0; background:var(--accent); transition:width .3s}
.job-status{margin-top:8px}
.gallery{
  display:grid; grid-template-columns:repeat(auto-fill,minmax(158px,1fr)); gap:11px;
  overflow-y:auto; max-height:min(62vh,720px); padding-right:3px;
}
.gal-item{border:1px solid var(--line); border-radius:var(--radius-sm); overflow:hidden;
  background:var(--bg-soft); position:relative}
.gal-item img{width:100%; height:158px; object-fit:cover; display:block; cursor:zoom-in;
  background:#fff}
.gal-meta{padding:6px 8px; font-size:11.5px; color:var(--muted)}
.gal-meta .t{color:var(--text-2); overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.gal-ops{display:flex; gap:5px; padding:0 8px 8px}
.gal-ops button{flex:1; font-size:11.5px; padding:3px 0; border:1px solid var(--line);
  background:var(--panel); border-radius:5px; cursor:pointer; color:var(--text-2);
  font-family:var(--sans)}
.gal-ops button:hover{border-color:var(--accent); color:var(--accent-2)}
.lightbox{
  position:fixed; inset:0; background:rgba(17,24,39,.86); display:flex; align-items:center;
  justify-content:center; z-index:100; padding:24px;
}
.lightbox img{max-width:100%; max-height:100%; border-radius:var(--radius);
  background:#fff; box-shadow:0 20px 50px rgba(0,0,0,.4)}
.lightbox .close{position:absolute; top:16px; right:20px; color:#fff; font-size:28px;
  cursor:pointer; line-height:1}

/* ============================================================ 表格 / 文件 */
.table-wrap{overflow-x:auto; margin-top:12px}
.table{width:100%; border-collapse:collapse; font-size:13.5px}
.table th,.table td{padding:8px 10px; border-bottom:1px solid var(--line); text-align:left;
  white-space:nowrap}
.table th{background:var(--bg-soft); color:var(--muted); font-weight:600; font-size:12.5px;
  position:sticky; top:0}
.table td.name{white-space:normal; word-break:break-all; max-width:340px}
.table tbody tr:hover{background:var(--bg-soft)}
.table .ops{display:flex; gap:6px; justify-content:flex-end}
.table .ops button{font-size:12px; padding:3px 9px; border:1px solid var(--line);
  background:var(--panel); border-radius:5px; cursor:pointer; color:var(--text-2);
  font-family:var(--sans)}
.table .ops button:hover{border-color:var(--accent); color:var(--accent-2)}
.table .ops button.danger:hover{border-color:var(--danger); color:var(--danger)}
.mono-box{font-family:var(--mono); font-size:12.5px; background:var(--bg-soft);
  border:1px solid var(--line); border-radius:5px; padding:2px 6px; word-break:break-all}

/* ============================================================ 工具 */
.out{
  background:var(--bg-soft); border:1px solid var(--line); border-radius:var(--radius-sm);
  padding:11px 13px; margin:11px 0 0; white-space:pre-wrap; word-break:break-word;
  font-size:12.8px; max-height:420px; overflow:auto; min-height:0;
}
.out:empty{display:none}
.out-md{background:var(--bg-soft); border:1px solid var(--line);
  border-radius:var(--radius-sm); padding:12px 15px; margin-top:11px; max-height:520px;
  overflow:auto}
.out-md:empty{display:none}
.compare-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(320px,1fr));
  gap:12px; margin-top:12px}
.compare-card{border:1px solid var(--line); border-radius:var(--radius-sm);
  background:var(--bg-soft); padding:12px 14px}
.compare-card h4{font-size:13px; color:var(--accent-2); margin-bottom:7px}

/* ============================================================ 日志 */
.log{
  background:#fbfbfd; border:1px solid var(--line); border-radius:var(--radius-sm);
  padding:11px 13px; height:290px; overflow:auto; margin:0;
  font-size:12px; line-height:1.55; white-space:pre-wrap; word-break:break-all;
}
.log .err{color:var(--danger)}
.log .ts{color:var(--muted-2)}

/* ============================================================ 登录页 */
.login-body{
  display:flex; align-items:center; justify-content:center; padding:20px;
  background:var(--bg); min-height:100vh;
}
.login-card{
  width:100%; max-width:360px; background:var(--panel); border:1px solid var(--line);
  border-radius:14px; padding:28px 26px; box-shadow:0 4px 20px rgba(16,24,40,.07);
}
.login-brand{display:flex; align-items:center; gap:11px; margin-bottom:22px}
.login-brand h1{font-size:19px}
.login-msg{min-height:20px; font-size:13px; color:var(--danger); margin-top:11px}
.login-msg.ok{color:var(--ok)}
.login-foot{text-align:center; margin:14px 0 0}

/* ============================================================ Toast */
.toast-wrap{position:fixed; right:16px; bottom:16px; display:flex; flex-direction:column;
  gap:8px; z-index:200; max-width:min(92vw,420px)}
.toast{
  background:var(--panel); border:1px solid var(--line); border-left:3px solid var(--accent);
  border-radius:var(--radius-sm); padding:10px 14px; font-size:13.5px;
  box-shadow:0 6px 20px rgba(16,24,40,.12); animation:slide .18s ease-out;
}
.toast.err{border-left-color:var(--danger)}
.toast.ok{border-left-color:var(--ok)}
.toast.warn{border-left-color:var(--warn)}
@keyframes slide{from{opacity:0; transform:translateY(8px)} to{opacity:1; transform:none}}

/* ============================================================ 启动失败提示 */
.boot-error{
  margin:12px 16px 0; padding:12px 15px; border-radius:var(--radius-sm);
  background:var(--danger-soft); border:1px solid #fecaca; color:var(--danger);
  font-size:13.5px; line-height:1.7;
}
.boot-error .btn{margin-top:7px}

/* ============================================================ 响应式 */
@media (max-width:900px){
  .sidebar{display:none}
  .topbar{height:auto; padding:8px 12px; flex-wrap:wrap; gap:8px}
  .tabs{order:3; width:100%; flex:1 1 100%}
  .page{padding:12px}
  #page-chat{height:calc(100vh - 106px)}
  .grid-2{grid-template-columns:1fr}
  .chat-log{padding:14px}
  .msg-body{max-width:100%}
  .toolbar .select{max-width:150px; min-width:120px}
}
