/* ============ AI 绘图工坊 · 自包含样式（无 CDN） ============ */
:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f8f9fc;
  --line: #e6e8f0;
  --text: #1f2333;
  --text-2: #6b7280;
  --text-3: #9aa1b1;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eef0ff;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(24, 28, 50, .06);
  --shadow-lg: 0 10px 40px rgba(24, 28, 50, .14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
input, textarea, select, button { font-family: inherit; font-size: 14px; }

/* ------------ 通用控件 ------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: var(--radius-sm); cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #cfd4e6; background: var(--panel-2); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent; color: #fff; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.btn-danger { color: var(--err); border-color: #f8cccc; }
.btn-danger:hover { background: #fef2f2; border-color: #f0aaaa; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); outline: none; transition: .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .1); }
.textarea { resize: vertical; min-height: 76px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-body { padding: 18px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

table.tb { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tb th, table.tb td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.tb th { background: var(--panel-2); color: var(--text-2); font-weight: 600; white-space: nowrap; }
table.tb tr:hover td { background: #fafbff; }
table.tb td.nowrap { white-space: nowrap; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; line-height: 18px; }
.tag-ok { background: #e7f8f1; color: #067a55; }
.tag-off { background: #f2f3f7; color: #8a90a2; }
.tag-err { background: #fdeaea; color: #b91c1c; }
.tag-info { background: var(--brand-soft); color: #4338ca; }
.tag-warn { background: #fef4e2; color: #a16207; }
.muted { color: var(--text-3); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.pager { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 16px 0 4px; }
.pager a, .pager span { padding: 5px 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text-2); font-size: 13px; }
.pager .cur { background: var(--brand); border-color: var(--brand); color: #fff; }

.flash { padding: 11px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13px; border: 1px solid transparent; }
.flash-ok { background: #eafaf3; border-color: #b6e9d5; color: #06694a; }
.flash-err { background: #fef3f3; border-color: #f7cccc; color: #a51c1c; }

/* ------------ 登录页 ------------ */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #e8e6ff 0%, transparent 60%),
              radial-gradient(1000px 500px at 110% 110%, #e2f3ff 0%, transparent 55%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px; }
.auth-logo { width: 46px; height: 46px; border-radius: 13px; background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 22px; margin-bottom: 18px; }
.auth-card h1 { font-size: 21px; margin: 0 0 6px; }
.auth-card p.sub { color: var(--text-2); font-size: 13px; margin: 0 0 22px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-2); }

/* ------------ 应用壳 ------------ */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 260px; flex: 0 0 260px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--line); }
.brand .dot { width: 28px; height: 28px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.side-actions { padding: 12px; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.conv-item { padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; gap: 8px; color: var(--text); }
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--brand-soft); color: #3730a3; font-weight: 600; }
.conv-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv-item .del { opacity: 0; color: var(--text-3); font-size: 15px; padding: 0 2px; }
.conv-item:hover .del { opacity: 1; }
.side-foot { border-top: 1px solid var(--line); padding: 12px; font-size: 13px; }
.side-foot .quota { display: flex; justify-content: space-between; margin-bottom: 10px; color: var(--text-2); }
.side-foot .quota b { color: var(--brand); font-size: 15px; }
.side-foot a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--text-2); }
.side-foot a:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.topbar { height: 56px; flex: 0 0 56px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; padding: 0 16px; gap: 12px; }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-left .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn { display: none; border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 34px; height: 34px; cursor: pointer; }

.messages { flex: 1; overflow-y: auto; padding: 22px 16px 8px; }
.msg-wrap { max-width: 860px; margin: 0 auto; }
.msg { display: flex; gap: 10px; margin-bottom: 20px; }
.avatar { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff; background: var(--text-3); }
.msg.user .avatar { background: #94a3b8; }
.msg.assistant .avatar { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.bubble { min-width: 0; max-width: 100%; }
.bubble .who { font-size: 12px; color: var(--text-3); margin-bottom: 4px; }
.bubble .text { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; white-space: pre-wrap;
  word-break: break-word; box-shadow: var(--shadow); }
.msg.user .bubble .text { background: var(--brand-soft); border-color: #dfe2ff; }
.msg-images { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.msg-images img { max-width: 320px; max-height: 320px; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; background: #fff; box-shadow: var(--shadow); }
.reason-box { margin-top: 6px; font-size: 12px; color: var(--text-3); background: #fbfbfd; border: 1px dashed var(--line);
  border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; max-height: 160px; overflow: auto; }
.typing::after { content: '▍'; animation: blink 1s steps(2) infinite; color: var(--brand); }
@keyframes blink { 0%, 50% { opacity: 1 } 50.01%, 100% { opacity: 0 } }
.spinner { width: 15px; height: 15px; border: 2px solid #d9dce9; border-top-color: var(--brand); border-radius: 50%;
  display: inline-block; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg) } }

/* 生图过程动画占位 */
.gen-ph { margin-top: 8px; }
.gen-shimmer { position: relative; width: 260px; height: 260px; max-width: 100%; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); background: linear-gradient(160deg, #eef0ff 0%, #f6f5ff 55%, #eaf4ff 100%); }
.gen-shimmer::after { content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 25%, rgba(255, 255, 255, .8) 50%, transparent 75%);
  transform: translateX(-100%); animation: shimmer 1.8s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.gen-orb { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; border: 3px solid rgba(79, 70, 229, .18); border-top-color: var(--brand);
  animation: spin .9s linear infinite; }
.gen-pct { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); margin-top: -46px;
  font-size: 15px; color: var(--brand); animation: floaty 2.2s ease-in-out infinite; }
@keyframes floaty { 0%, 100% { transform: translate(-50%, 0); opacity: .55 } 50% { transform: translate(-50%, -8px); opacity: 1 } }
.gen-status { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--text-2); }
.gen-time { margin-left: auto; font-size: 12px; color: var(--text-3); font-family: ui-monospace, Menlo, Consolas, monospace; }
.empty { text-align: center; color: var(--text-3); padding: 60px 20px; }
.empty h2 { color: var(--text); font-size: 19px; margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.chip { padding: 8px 14px; background: #fff; border: 1px solid var(--line); border-radius: 20px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.chip:hover { border-color: var(--brand); color: var(--brand); }

.composer { border-top: 1px solid var(--line); background: #fff; padding: 10px 16px 14px; }
.composer-inner { max-width: 860px; margin: 0 auto; }
.composer-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-size: 13px; }
.seg button.active { background: #fff; color: var(--brand); font-weight: 600; box-shadow: var(--shadow); }
.composer-tools select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--text-2); }
.composer-input { display: flex; gap: 10px; align-items: flex-end; border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 8px 8px 14px; background: #fff; transition: .15s; }
.composer-input:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .1); }
.composer-input textarea { flex: 1; border: 0; outline: none; resize: none; max-height: 180px; min-height: 26px; line-height: 1.6;
  font-size: 14px; padding: 4px 0; background: transparent; }
.composer-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* 灯箱 */
.lightbox { position: fixed; inset: 0; background: rgba(15, 18, 34, .8); display: none; align-items: center; justify-content: center;
  z-index: 99; padding: 30px; flex-direction: column; gap: 14px; }
.lightbox.on { display: flex; }
.lightbox img { max-width: 92vw; max-height: 80vh; border-radius: 10px; box-shadow: var(--shadow-lg); background: #fff; }
.lightbox .bar { display: flex; gap: 10px; }

.toast-box { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--brand); border-radius: 8px;
  padding: 10px 16px; box-shadow: var(--shadow-lg); font-size: 13px; max-width: 360px; animation: slidein .2s ease; }
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0 } }

/* ------------ 后台 ------------ */
.admin-shell { display: flex; min-height: 100vh; }
.admin-nav { width: 218px; flex: 0 0 218px; background: #fff; border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.admin-nav .brand { border: 0; padding: 6px 8px 18px; }
.admin-nav a.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text-2); margin-bottom: 3px; font-size: 13.5px; }
.admin-nav a.nav-item:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
.admin-nav a.nav-item.active { background: var(--brand-soft); color: #3730a3; font-weight: 600; }
.admin-main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.admin-head h1 { font-size: 20px; margin: 0; }
.admin-head .sub { color: var(--text-3); font-size: 13px; margin-top: 2px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .k { font-size: 12.5px; color: var(--text-3); }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.5px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--text-3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tbl-scroll { overflow-x: auto; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

@media (max-width: 1000px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form-2col { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; transform: translateX(-100%); transition: .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .icon-btn { display: block; }
  .admin-nav { display: none; }
  .admin-main { padding: 16px; }
  .msg-images img { max-width: 100%; }
}
