:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --line: #e7e5e0;
  --text: #1d1c1a;
  --muted: #8a877f;
  --accent: #1d1c1a;
  --accent-text: #ffffff;
  --soft: #f0efeb;
  --ok: #2f8f5b;
  --warn: #c98a1b;
  --bad: #c64a3c;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #1d1c1a22; border-color: #aaa; }
textarea { resize: vertical; }
small, .muted { color: var(--muted); font-weight: normal; }

.btn { border: 1px solid var(--line); background: #fff; padding: 8px 16px; border-radius: 8px; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { opacity: .88; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--muted); padding: 0; text-decoration: underline; }

/* 登录 */
.login { position: fixed; inset: 0; display: grid; place-items: center; }
.login-card { background: var(--panel); padding: 32px; border-radius: 16px; width: 320px; display: grid; gap: 12px; box-shadow: 0 10px 40px #0001; }
.login-card h1 { font-size: 18px; margin: 0 0 8px; }
.error { color: var(--bad); margin: 0; min-height: 1em; }

/* 布局 */
.app { display: grid; grid-template-columns: 200px 1fr 320px; height: 100vh; }
.app.no-queue { grid-template-columns: 200px 1fr; }
.app.no-queue .queue { display: none; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.brand { font-weight: 700; font-size: 15px; padding: 4px 10px 12px; }
.nav-group { font-size: 12px; color: var(--muted); padding: 14px 10px 4px; }
.nav { text-align: left; background: none; border: 0; padding: 9px 10px; border-radius: 8px; color: var(--text); }
.nav:hover { background: var(--soft); }
.nav.active { background: var(--accent); color: var(--accent-text); }
.sidebar-foot { margin-top: auto; padding: 10px; display: grid; gap: 8px; font-size: 12px; }
.api-status { color: var(--muted); }
.api-status.ok::before { content: '● '; color: var(--ok); }
.api-status.warn::before { content: '● '; color: var(--warn); }

.main { overflow-y: auto; padding: 28px 36px 60px; }
.view { display: none; max-width: 820px; }
.view.active { display: block; }
.view.wide { max-width: none; }
.view-head h2 { margin: 0 0 4px; font-size: 20px; }
.view-head p { margin: 0 0 20px; color: var(--muted); }
.view-head.row { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }

.form { display: grid; gap: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.field { display: grid; gap: 6px; align-content: start; }
.field > label { font-weight: 600; font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.form-actions .count { margin-left: auto; color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: normal; cursor: pointer; padding-top: 6px; }
.switch input { width: auto; }

/* 上传 */
.uploader { display: flex; flex-wrap: wrap; gap: 10px; }
.thumb { position: relative; width: 96px; height: 96px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--soft); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .idx { position: absolute; left: 4px; top: 4px; background: #000a; color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 6px; }
.thumb .rm { position: absolute; right: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: #000a; color: #fff; line-height: 1; }
.thumb.loading::after { content: '上传中…'; position: absolute; inset: 0; display: grid; place-items: center; background: #fffc; font-size: 12px; }
.drop { width: 96px; height: 96px; border: 1.5px dashed #c9c6be; border-radius: 10px; display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 12px; cursor: pointer; background: #fcfcfb; }
.drop:hover, .drop.over { border-color: var(--text); color: var(--text); }


/* 队列 */
.queue { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.queue-head { padding: 18px 16px 10px; display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--line); }
.queue-head h3 { margin: 0; font-size: 15px; }
.queue-list { overflow-y: auto; padding: 12px; display: grid; gap: 10px; align-content: start; }
.q-item { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.q-item:hover { background: var(--soft); }
.q-item .ph { width: 64px; height: 64px; border-radius: 8px; background: var(--soft); overflow: hidden; display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.q-item .ph img { width: 100%; height: 100%; object-fit: cover; }
.q-item .title { font-weight: 600; font-size: 13px; }
.q-item .sub { font-size: 12px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--soft); color: var(--muted); }
.badge.done { background: #e4f3ea; color: var(--ok); }
.badge.failed { background: #f8e4e1; color: var(--bad); }
.badge.running { background: #fbf0dc; color: var(--warn); }
.spin { width: 18px; height: 18px; border: 2px solid #ddd; border-top-color: var(--text); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 资产库 */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters input, .filters select { width: auto; }
.batch-bar { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card .img { aspect-ratio: 3 / 4; background: var(--soft); display: grid; place-items: center; cursor: pointer; overflow: hidden; color: var(--muted); font-size: 12px; text-align: center; padding: 0; }
.card .img img { width: 100%; height: 100%; object-fit: cover; }
.card .info { padding: 10px; display: grid; gap: 6px; font-size: 12px; }
.card .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card .err { color: var(--bad); font-size: 12px; word-break: break-all; }
.fav { border: 0; background: none; font-size: 16px; padding: 0; margin-left: auto; color: #ccc; }
.fav.on { color: #e0a800; }
.center { text-align: center; padding: 20px; }

/* 模板 */
.tpl-list { display: grid; gap: 10px; margin-top: 16px; }
.tpl { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.tpl .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tpl pre { white-space: pre-wrap; margin: 8px 0 0; color: var(--muted); font: inherit; font-size: 12px; max-height: 80px; overflow: hidden; }

/* 弹窗 */
.modal { border: 0; border-radius: 16px; padding: 0; max-width: min(1100px, 94vw); width: 100%; }
.modal::backdrop { background: #0008; }
.modal.small { max-width: 720px; }
.modal-body { display: grid; grid-template-columns: 1.4fr 1fr; min-height: 60vh; max-height: 88vh; position: relative; }
.modal-body.col { display: grid; grid-template-columns: 1fr; gap: 12px; padding: 22px; min-height: 0; overflow-y: auto; }
.modal-body.col h3 { margin: 0; }
.modal-img { background: #111; display: grid; place-items: center; }
.modal-img img { max-width: 100%; max-height: 88vh; object-fit: contain; }
.modal-side { padding: 22px; overflow-y: auto; display: grid; gap: 12px; align-content: start; }
.modal-side pre { white-space: pre-wrap; font: inherit; font-size: 12px; background: var(--soft); padding: 10px; border-radius: 8px; margin: 0; }
.pv-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.close { position: absolute; right: 10px; top: 8px; border: 0; background: #fff; border-radius: 50%; width: 30px; height: 30px; font-size: 18px; }
.pd-item { display: grid; gap: 4px; margin-bottom: 10px; }
.pd-item b { font-size: 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #1d1c1a; color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--bad); }

@media (max-width: 1100px) {
  .app { grid-template-columns: 180px 1fr; }
  .queue { display: none; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .sidebar { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-group, .sidebar-foot { display: none; }
  .main { padding: 16px; }
  .modal-body { grid-template-columns: 1fr; }
}

.small { font-size: 12px; }
.err { color: var(--bad); }

/* ---------- AI 助手 ---------- */
.agent-view.active { display: flex; flex-direction: column; height: calc(100vh - 88px); }
.agent-view .view-head p { margin-bottom: 0; }
.agent-log { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px 16px; }
.agent-empty { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 14px 18px; line-height: 1.7; }
.agent-empty p { margin: 0; }
.agent-empty ul { margin: 4px 0 0; padding-left: 20px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 14px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; display: grid; gap: 8px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.error { border-color: #e7b3ab; color: var(--bad); }
.msg.thinking { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.msg .thumbs img { width: 72px; height: 72px; }
.tool-line { font-size: 12px; display: grid; gap: 6px; white-space: normal; }
.agent-jobs { display: flex; flex-wrap: wrap; gap: 8px; }
.agent-job { width: 96px; height: 128px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); padding: 0; overflow: hidden; display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.agent-job img { width: 100%; height: 100%; object-fit: cover; }
.agent-composer { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 10px; }
.agent-composer .thumb, .agent-composer .drop { width: 64px; height: 64px; }
@media (max-width: 720px) {
  .agent-view.active { height: auto; }
  .agent-log { max-height: 60vh; }
  .msg { max-width: 100%; }
}
