:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #d7dfeb;
  --line-strong: #b7c4d8;
  --text: #142033;
  --muted: #66758d;
  --blue: #2563eb;
  --blue-soft: #e7efff;
  --green: #087443;
  --red: #b42318;
  --shadow: 0 14px 34px rgba(20, 32, 51, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; }
button, textarea, input, select { font: inherit; }
button {
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .1s ease, filter .12s ease, opacity .12s ease;
}
button:not(:disabled):active { transform: translateY(1px) scale(.985); filter: brightness(.97); }
button.is-busy { cursor: progress; opacity: .72; }
button.is-busy::after {
  width: .82em; height: .82em; margin-left: 2px;
  display: inline-block; flex: 0 0 auto;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  content: ""; animation: button-busy-spin .65s linear infinite;
}
@keyframes button-busy-spin { to { transform: rotate(360deg); } }
[hidden] { display: none !important; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  min-height: 58px; padding: 10px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: rgba(255, 255, 255, .96); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 900; letter-spacing: 0; white-space: nowrap; }
.brand span, .session { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session { max-width: 45vw; text-align: right; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; min-width: 0; }
.page {
  width: min(1460px, calc(100vw - 28px));
  margin: 0 auto; padding: 14px 0 24px;
  display: grid; grid-template-columns: 430px minmax(0, 1fr); gap: 14px;
}
.sidebar { display: grid; gap: 14px; align-self: start; position: sticky; top: 72px; }
.panel {
  min-width: 0; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel-head {
  min-height: 50px; padding: 12px 14px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 900; }
.panel-head-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.panel-body { padding: 14px; display: grid; gap: 12px; }
.field { display: grid; gap: 7px; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 900; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-label-row output { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; font-weight: 700; }
.field-help { color: var(--muted); font-size: 12px; line-height: 1.55; }
.input, .textarea, .select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; outline: none;
  background: #fff; color: var(--text);
}
.input, .select { min-height: 38px; padding: 0 11px; }
.textarea { min-height: 230px; padding: 12px 13px; line-height: 1.62; resize: vertical; }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn {
  min-height: 36px; padding: 0 13px; border: 1px solid var(--line); border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: #fff; color: var(--text); font-weight: 800; text-decoration: none;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.btn:hover:not(:disabled) { border-color: var(--line-strong); box-shadow: 0 8px 18px rgba(20, 32, 51, .08); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover:not(:disabled) { box-shadow: 0 10px 24px rgba(37, 99, 235, .24); }
.btn.compact { min-height: 30px; padding: 0 10px; font-size: 12px; }
.generate { width: 100%; min-height: 44px; font-size: 15px; }
.pill {
  min-height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-soft); color: var(--muted); font-size: 12px; font-weight: 900;
  display: inline-flex; align-items: center; white-space: nowrap;
}
.pill.blue { background: var(--blue-soft); color: var(--blue); border-color: #bfd2ff; }
.pill.green { background: #ecfdf3; color: var(--green); border-color: #abefc6; }
.status { min-height: 20px; color: var(--muted); line-height: 1.5; }
.status.error { color: var(--red); }
.status.ok { color: var(--green); }
.login { width: min(460px, calc(100vw - 28px)); margin: 42px auto; }
.auth-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.ref-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.ref-drop {
  min-height: 62px; padding: 12px 14px; border: 1px dashed var(--line-strong); border-radius: 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(180deg, #fff, #f8fbff); cursor: pointer;
}
.ref-drop:hover, .ref-drop:focus-visible, .ref-drop.is-dragging {
  border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); outline: none;
}
.ref-drop.is-dragging { background: var(--blue-soft); }
.ref-drop.is-processing { cursor: progress; opacity: .72; }
.ref-title { display: grid; gap: 2px; min-width: 0; }
.ref-title strong { font-size: 16px; }
.ref-title span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-count { color: var(--blue); font-weight: 900; white-space: nowrap; }
.reference-processing {
  padding: 9px 11px; border: 1px solid #bfd2ff; border-radius: 8px;
  background: var(--blue-soft); color: var(--blue); font-size: 12px; font-weight: 800;
  overflow-wrap: anywhere;
}
.thumbs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.thumb {
  position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-soft);
}
.thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.thumb button {
  position: absolute; right: 5px; top: 5px; width: 24px; height: 24px;
  border: 1px solid rgba(20, 32, 51, .18); border-radius: 999px;
  background: rgba(255,255,255,.94); font-weight: 900;
}
.cost-total {
  padding: 13px; border: 1px solid var(--line); border-radius: 8px;
  background: linear-gradient(135deg, #f0fdf4, #f8fffb); border-color: #abefc6;
  box-shadow: inset 0 0 0 1px rgba(8, 116, 67, .04);
}
.stat-k { color: var(--muted); font-size: 12px; font-weight: 900; }
.stat-v { margin-top: 4px; font-size: 16px; font-weight: 900; }
.cost-total .stat-v { color: var(--green); font-size: 28px; }
.cost-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.stat-card { padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.results { min-height: calc(100vh - 96px); display: grid; grid-template-rows: auto 1fr; }
.results-body { padding: 14px; min-height: 0; display: grid; gap: 12px; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.result-alert {
  max-height: 180px; overflow: auto;
  padding: 12px 14px; border: 1px solid #fecdca; border-radius: 8px;
  background: linear-gradient(135deg, #fff5f5, #fffafa); color: var(--red);
  box-shadow: 0 12px 24px rgba(180, 35, 24, .1);
}
.result-alert strong { display: block; margin-bottom: 5px; font-size: 15px; font-weight: 900; }
.result-alert div { line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.progress { display: grid; gap: 8px; }
.bar { height: 8px; border-radius: 999px; overflow: hidden; background: #e8edf5; }
.bar i { display: block; width: 0; height: 100%; background: var(--blue); transition: width .2s ease; }
.gallery-grid {
  min-height: 0; overflow: auto; align-content: start;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 14px; padding-right: 2px;
}
.empty {
  min-height: 360px; border: 1px dashed var(--line); border-radius: 8px;
  display: grid; place-items: center; text-align: center; padding: 24px;
  background: linear-gradient(135deg, #fff, #f8fafc); color: var(--muted);
}
.card {
  position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; box-shadow: 0 12px 24px rgba(20, 32, 51, .08); cursor: zoom-in;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-1px); border-color: var(--line-strong); box-shadow: 0 18px 34px rgba(20, 32, 51, .13); }
.card img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; background: #fff; }
.card.landscape img { aspect-ratio: 1.5; }
.card.portrait img { aspect-ratio: .67; }
.card.wide img { aspect-ratio: 16 / 9; }
.card.tall img { aspect-ratio: 9 / 16; }
.card.pending {
  min-height: 245px; cursor: default;
  display: grid; place-items: center; padding: 18px;
  background:
    radial-gradient(circle at 20% 20%, rgba(37, 99, 235, .13), transparent 34%),
    linear-gradient(135deg, #ffffff, #f4f8ff);
}
.card.pending:hover { transform: none; }
.card.pending.failed { border-color: #fecdca; background: linear-gradient(135deg, #fffafa, #fff5f5); }
.pending-box { min-width: 0; max-width: 100%; display: grid; justify-items: center; gap: 12px; text-align: center; color: var(--muted); }
.pending-box > div { max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
.pending-error { max-height: 72px; overflow: auto; color: var(--red); line-height: 1.45; }
.pending-ring {
  width: 58px; height: 58px; border-radius: 999px;
  border: 5px solid #dbe7ff; border-top-color: var(--blue);
  animation: image2-spin .86s linear infinite;
  box-shadow: 0 12px 28px rgba(37, 99, 235, .16);
}
.pending-ring.stopped { animation: none; border-color: #ffd6d2; border-top-color: var(--red); }
.pending-title { color: var(--text); font-weight: 900; font-size: 16px; }
.pending-time { min-width: 88px; padding: 5px 10px; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-weight: 900; }
@keyframes image2-spin { to { transform: rotate(360deg); } }
.card-meta {
  position: absolute; left: 8px; right: 8px; bottom: 8px; padding: 8px;
  display: grid; gap: 3px; border-radius: 8px;
  background: rgba(255,255,255,.92); box-shadow: 0 8px 20px rgba(20, 32, 51, .12);
  opacity: 0; transform: translateY(4px); pointer-events: none; transition: opacity .15s ease, transform .15s ease;
}
.card:hover .card-meta { opacity: 1; transform: translateY(0); }
.card-meta strong, .card-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta span { color: var(--muted); font-size: 12px; }
.ref-btn {
  position: absolute; right: 8px; top: 8px; min-height: 30px; padding: 0 10px;
  border: 1px solid rgba(37, 99, 235, .25); border-radius: 8px;
  background: rgba(255,255,255,.96); color: var(--blue); font-weight: 900;
}
.ref-btn:hover { background: var(--blue); color: #fff; border-color: var(--blue); }
.del-btn {
  position: absolute; left: 8px; top: 8px; min-height: 30px; padding: 0 10px;
  border: 1px solid rgba(180, 35, 24, .25); border-radius: 8px;
  background: rgba(255,255,255,.96); color: var(--red); font-weight: 900;
}
.del-btn:hover { background: var(--red); color: #fff; border-color: var(--red); }
.del-btn:disabled { cursor: progress; opacity: .82; }
.modal {
  position: fixed; inset: 0; z-index: 30; padding: 16px;
  display: grid; grid-template-rows: auto 1fr; gap: 12px;
  background: rgba(15, 23, 42, .84);
}
.modal-head { display: flex; justify-content: flex-end; }
.modal-body { min-height: 0; display: grid; place-items: center; }
.modal img {
  max-width: 100%; max-height: calc(100vh - 88px); object-fit: contain;
  border-radius: 8px; background: #fff; box-shadow: 0 24px 70px rgba(0,0,0,.35);
}
@media (max-width: 980px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .session { max-width: 100%; text-align: left; }
  .page { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .results { min-height: 520px; }
}
@media (max-width: 560px) {
  .grid2, .cost-grid { grid-template-columns: 1fr; }
  .thumbs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .panel-head-actions { gap: 5px; }
  .ref-drop { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
