:root {
  --bg: #f6f4ef; --panel: #fffdf9; --ink: #1d1b18; --muted: #6f6a61; --line: #e4dfd5;
  --accent: #c2410c; --accent-ink: #fff; --accent-soft: #fbe7dc;
  --ok: #15803d; --warn: #b45309; --err: #b91c1c;
  --radius: 14px; --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412; --panel: #1e1c19; --ink: #efebe3; --muted: #9d978c; --line: #312e29;
    --accent: #f97316; --accent-ink: #1b0d03; --accent-soft: #3a2415;
    --ok: #4ade80; --warn: #fbbf24; --err: #f87171; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

header.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
header.top .wrap { display: flex; align-items: center; gap: 12px; height: 56px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .02em; text-decoration: none; }
.brand span { color: var(--accent); }
nav.links { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
nav.links a, nav.links button { text-decoration: none; background: none; border: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); }
nav.links a:hover, nav.links button:hover, nav.links a.on { color: var(--ink); background: var(--line); }
.balance { font-variant-numeric: tabular-nums; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }

main, main.wrap { padding-top: 20px; padding-bottom: 64px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stack > * + * { margin-top: 16px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 120px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 16px; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { width: 100%; padding: 13px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--err); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 14px; cursor: pointer; }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.models { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.models button { text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.models button b { display: block; font-size: 14px; }
.models button small { color: var(--muted); font-size: 12px; }
.models button.on { border-color: var(--accent); background: var(--accent-soft); }

.layout { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.options { display: grid; gap: 14px; }

.refs { display: flex; gap: 8px; flex-wrap: wrap; }
.ref { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.ref img { width: 100%; height: 100%; object-fit: cover; }
.ref button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgb(0 0 0 / .6); color: #fff; cursor: pointer; line-height: 1; }
.ref.add { display: grid; place-items: center; border-style: dashed; color: var(--muted); cursor: pointer; font-size: 26px; background: var(--bg); }
.ref.add.drag { border-color: var(--accent); color: var(--accent); }

.estimate { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; color: var(--muted); }
.estimate b { color: var(--ink); font-variant-numeric: tabular-nums; }

.jobs { display: grid; gap: 14px; }
.job { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.job .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.job .prompt { margin: 0 0 10px; white-space: pre-wrap; word-break: break-word; }
.status { font-weight: 600; }
.status.done { color: var(--ok); } .status.failed { color: var(--err); } .status.running, .status.queued { color: var(--warn); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.grid .cell { position: relative; border-radius: 10px; overflow: hidden; background: var(--line); aspect-ratio: var(--ar, 1); }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.placeholder { display: grid; place-items: center; color: var(--muted); font-size: 13px; aspect-ratio: var(--ar, 1); border-radius: 10px; background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 10px, var(--line) 10px, var(--line) 20px); animation: shimmer 1.2s linear infinite; background-size: 28px 28px; }
@keyframes shimmer { to { background-position: 28px 0; } }
.error { color: var(--err); font-size: 14px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .85); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; gap: 12px; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 110px); border-radius: 8px; object-fit: contain; }
.lightbox .bar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.lightbox .btn { background: #fff; color: #111; border-color: #fff; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 140px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--line); color: var(--muted); }
.tag.off { background: #fee2e2; color: #991b1b; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .panel { width: 100%; max-width: 380px; }
