:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #1f2329;
  --muted: #646a73;
  --faint: #8f959e;
  --primary: #1677ff;
  --primary-hover: #0f62d9;
  --primary-soft: #eef4ff;
  --primary-line: #c7dcff;
  --emerald: #16a34a;
  --emerald-soft: #eefbf3;
  --amber: #d97706;
  --amber-soft: #fff7e8;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
h1, h2, h3, p { margin: 0; }

/* ---------------------------------------------------------------- shell */

.app-body { height: 100vh; overflow: hidden; }
.shell { display: flex; height: 100vh; }

.sidebar {
  width: 224px;
  flex: 0 0 224px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 20;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--primary);
  position: relative;
  flex: 0 0 24px;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 2px;
  background: #fff;
}

.side-nav { padding: 8px; display: flex; flex-direction: column; gap: 1px; overflow-y: auto; }
.nav-label {
  padding: 12px 8px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}
.side-nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
  transition: background 0.12s ease, color 0.12s ease;
}
.side-nav a svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side-nav a.active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  background: var(--primary);
}

.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); }
.side-user { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex: 0 0 30px;
}
.side-user-meta { display: flex; flex-direction: column; min-width: 0; }
.side-user-meta b { font-size: 12.5px; font-weight: 600; }
.side-user-meta span { font-size: 11px; color: var(--faint); }
.side-logout {
  width: 100%;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.side-logout:hover { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); }

.main { flex: 1; min-width: 0; height: 100vh; display: flex; flex-direction: column; }

.topbar {
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 clamp(16px, 3vw, 28px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}
.topbar-title { font-size: 13px; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-btn {
  display: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}

.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px clamp(16px, 3vw, 28px) 32px;
}

.content.console { display: flex; flex-direction: column; overflow: hidden; padding: 14px clamp(14px, 2.4vw, 24px) 14px; max-width: none; }

/* ---- generate page layout */
.gen-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 348px minmax(0, 1fr);
  gap: 14px;
}
.gen-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.gen-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 2px;
}
.gen-scroll::-webkit-scrollbar { width: 6px; }
.gen-scroll::-webkit-scrollbar-thumb { background: #d9dde3; border-radius: 99px; }

.gen-block {
  padding: 12px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
}
.gen-block-grow { flex: 0 0 auto; }
.gen-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.gen-block-head h2 {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.sub-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
}
.seg-lg button { padding: 7px 8px; font-size: 12.5px; }
.model-mode-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.model-mode-row .seg { min-width: 0; }
.model-mode-row .seg button { padding-left: 4px; padding-right: 4px; }

/* prompt */
#prompt {
  min-height: 72px;
  font-size: 13px;
  line-height: 1.6;
}
.prompt-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.prompt-tools-spacer { flex: 1; }
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.tool-btn:hover { color: var(--primary); border-color: var(--primary-line); background: var(--primary-soft); }
.tool-btn.primary-tool { color: var(--primary); border-color: var(--primary-line); background: var(--primary-soft); }
.tool-btn.primary-tool:hover { background: #e2ecff; }
.tool-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tool-btn svg { display: block; }

/* params */
.param-row { display: flex; gap: 8px; }
.param-cell { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.param-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.slider-row { display: flex; flex-direction: column; gap: 7px; }
.slider-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }

/* submit */
.gen-submit {
  flex: 0 0 auto;
  background: var(--surface);
  box-shadow: 0 -6px 16px rgba(16, 24, 40, 0.04);
}
.gen-submit .primary {
  width: 100%;
  padding: 11px 16px;
  font-size: 13.5px;
  font-weight: 600;
}
.cost-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--faint);
}
.cost-line b { color: var(--text); font-weight: 600; }
.kbd-hint {
  font-size: 10.5px;
  color: var(--faint);
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-2);
  font-family: inherit;
}
.rate-line {
  font-size: 11px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
}

/* ---------------------------------------------------------------- common */

.content-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.content-head h1 { font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.content-head p { margin-top: 3px; color: var(--muted); font-size: 12.5px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel { padding: 18px; margin-bottom: 14px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 13.5px; font-weight: 600; }

.hint { font-size: 11.5px; color: var(--faint); }
.counter { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }

.credits-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
}
.credits-chip b { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- buttons */

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.primary:active { transform: translateY(1px); }
.primary:disabled { cursor: wait; opacity: 0.6; }

.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.ghost:hover { color: var(--primary); border-color: var(--primary-line); background: var(--primary-soft); }
.ghost.danger { color: var(--danger); border-color: #fecaca; }
.ghost.danger:hover { background: var(--danger-soft); }
.ghost.disabled { opacity: 0.4; pointer-events: none; }
.ghost:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-spinner {
  display: none;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.primary.loading .btn-spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- forms */

.field { display: flex; flex-direction: column; gap: 6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.label-row label { font-size: 12px; font-weight: 500; color: var(--muted); }

textarea, select, input[type="number"], input[type="text"], input[type="password"], input[type="email"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
textarea { resize: vertical; min-height: 68px; line-height: 1.5; }
textarea::placeholder, input::placeholder { color: var(--faint); }
textarea:focus, select:focus, input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.12);
}
select { appearance: none; cursor: pointer; }

.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.seg button {
  flex: 1;
  border: 0;
  border-radius: 4px;
  padding: 7px 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--primary); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08); }

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 99px;
  background: #e5e7eb;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--primary);
  cursor: pointer;
}

.seed-row { display: flex; gap: 6px; }
.seed-row input { flex: 1; }
.icon-btn {
  width: 34px;
  flex: 0 0 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.12s ease;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary-line); background: var(--primary-soft); }
.icon-btn svg { display: block; }

.size-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.size-option {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 4px 5px;
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  transition: all 0.12s ease;
}
.size-option b { display: block; font-size: 12px; font-weight: 600; line-height: 1.2; }
.size-option span { display: block; margin-top: 1px; font-size: 10px; color: var(--faint); line-height: 1.2; }
.size-option:hover { border-color: var(--line-strong); background: var(--surface-2); }
.size-option.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.size-option.active span { color: var(--primary); opacity: 0.75; }

/* ---------------------------------------------------------------- console */

.stage { padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.stage-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; }
.stage-title { display: flex; align-items: baseline; gap: 10px; }
.stage-title h2 { font-size: 13px; font-weight: 600; }
.stage-actions { display: flex; gap: 6px; }
.stage-actions .ghost svg { display: block; }

.canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(45deg, #f4f5f7 25%, transparent 25%, transparent 75%, #f4f5f7 75%),
    linear-gradient(45deg, #f4f5f7 25%, #fbfbfc 25%, #fbfbfc 75%, #f4f5f7 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#previewImg { width: 100%; height: 100%; object-fit: contain; display: block; background: var(--surface-2); }

.empty { text-align: center; color: var(--faint); padding: 24px; }
.empty-icon { color: #c0c6cf; margin-bottom: 12px; display: flex; justify-content: center; }
.empty p { color: var(--muted); font-size: 13px; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.88);
}
.loading-ring {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #e5e7eb;
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
.loading-text {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.loading-bar { width: min(220px, 60%); height: 2px; border-radius: 99px; background: #e5e7eb; overflow: hidden; }
.loading-bar i {
  display: block;
  width: 40%;
  height: 100%;
  background: var(--primary);
  animation: sweep 1.2s ease-in-out infinite;
}
@keyframes sweep { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }

.meta { display: flex; flex-wrap: wrap; gap: 6px; min-height: 22px; flex: 0 0 auto; }
.meta span {
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- grid / works */

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 0 10px; }
.section-head h2 { font-size: 13.5px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(154px, 1fr)); gap: 10px; }
.history-empty { color: var(--faint); font-size: 12.5px; }
.history-card {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s ease;
}
.history-card:hover { border-color: var(--primary); }
.history-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.history-card .cap {
  position: absolute;
  inset: auto 0 0 0;
  padding: 18px 7px 6px;
  background: linear-gradient(transparent, rgba(16, 24, 40, 0.72));
  color: #fff;
  font-size: 10.5px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.green { background: var(--emerald-soft); border-color: #bbf7d0; color: #15803d; }
.badge.blue { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary); }
.badge.amber { background: var(--amber-soft); border-color: #fde68a; color: #b45309; }
.badge.red { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }

/* ---------------------------------------------------------------- stats */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat .k { font-size: 11.5px; color: var(--muted); }
.stat .v { margin-top: 4px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 11.5px; font-weight: 400; color: var(--faint); }

/* ---------------------------------------------------------------- forms / modal */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 148px; }
.toolbar .spacer { flex: 1; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--muted); }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(16, 24, 40, 0.36);
}
.modal {
  width: min(440px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 16px; font-weight: 600; }
.modal > p { margin: 4px 0 14px; color: var(--muted); font-size: 12.5px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 40;
  max-width: min(520px, 90vw);
  padding: 9px 14px;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--danger);
  font-size: 12.5px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: #bbf7d0; color: #15803d; }

/* ---------------------------------------------------------------- login */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  width: min(380px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 22px; font-weight: 700; }
.login-brand .brand-mark { width: 26px; height: 26px; }
.login-card h1 { font-size: 18px; font-weight: 600; }
.login-card .sub { margin: 5px 0 20px; color: var(--muted); font-size: 12.5px; }
.login-card .field { margin-bottom: 12px; }
.login-card .primary { width: 100%; margin-top: 4px; }
.login-foot { margin-top: 16px; text-align: center; font-size: 11px; color: var(--faint); }

/* ---------------------------------------------------------------- responsive */

.layout { display: grid; grid-template-columns: 336px minmax(0, 1fr); gap: 14px; }
.layout.side { grid-template-columns: minmax(0, 1fr) 320px; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 15; background: rgba(16, 24, 40, 0.32); }

@media (max-width: 1000px) {
  .layout, .layout.side { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app-body { height: auto; overflow: auto; }
  .shell { height: auto; min-height: 100vh; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .main { height: auto; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .content { overflow: visible; padding: 16px 12px 32px; }
  .content.console { overflow: visible; height: auto; }
  .gen-wrap { display: block; }
  .gen-scroll { overflow: visible; }
  .stage { margin-top: 12px; min-height: 54vh; }
  .canvas { min-height: 320px; }
  .two-col { grid-template-columns: 1fr; }
  .content-head h1 { font-size: 18px; }
}

@media (max-width: 480px) {
  .size-grid { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .prompt-tools-spacer { display: none; }
  .prompt-tools { justify-content: flex-start; }
}

/* ---------------------------------------------------------------- captcha */

.cap-row {
  display: flex;
  justify-content: center;
  margin: 2px 0 4px;
}
cap-widget {
  --cap-background: #ffffff;
  --cap-border-color: var(--line);
  --cap-border-radius: 6px;
  --cap-color: var(--text);
  --cap-widget-width: 230px;
  --cap-font: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.code-block {
  margin: 0;
  padding: 12px;
  border: 1px solid #1e293b;
  border-radius: 6px;
  background: #0f172a;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.65;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------------------------------------------------------------- implicit captcha */

.cap-hidden {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
}
.cap-hidden cap-widget {
  display: block;
  width: 0;
  height: 0;
  opacity: 0;
  visibility: hidden;
}
.cap-modal { text-align: center; }
.cap-modal .loading-ring { margin: 0 auto 14px; }
.cap-modal p { margin-bottom: 0; }

.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }
.code-row .ghost { flex: 0 0 auto; white-space: nowrap; }

/* ---------------------------------------------------------------- prompt optimizer */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.switch input {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
  cursor: pointer;
}
.advanced-panel {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface-2);
}
.advanced-panel .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.advanced-panel .field { gap: 5px; }
.advanced-panel .sub-label { font-size: 11px; }
.advanced-panel .hint { margin-top: 8px; }
.advanced-panel .hint b { color: var(--primary); }
#optResult { min-height: 120px; }

/* ---------------------------------------------------------------- progressive preview */

.progressive-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  padding: 10px;
  overflow: auto;
  background: var(--surface-2);
}
.progressive-grid[hidden] { display: none !important; }
.progressive-item {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.progressive-item img { width: 100%; height: 100%; object-fit: contain; display: block; }
.progressive-item span {
  position: absolute;
  left: 6px;
  top: 6px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 11px;
}
.progressive-item:hover { border-color: var(--primary); }

.progressive-grid { grid-auto-rows: minmax(150px, 1fr); }
.progressive-placeholder {
  height: 100%;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  background: var(--surface-2);
}
.progressive-placeholder b { font-size: 13px; color: var(--text); }
.progressive-item.failed { border-color: #fecaca; background: var(--danger-soft); }

/* ---------------------------------------------------------------- status page */

.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid #bbf7d0;
  border-radius: 99px;
  background: var(--emerald-soft);
  color: #15803d;
  font-size: 11.5px;
  font-weight: 500;
}
.live-dot i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.4); }
  50% { box-shadow: 0 0 0 5px rgba(22, 163, 74, 0); }
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat-card {
  position: relative;
  padding: 13px 14px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--accent, var(--primary));
  opacity: 0.85;
}
.accent-blue { --accent: #1677ff; --accent-soft: #eef4ff; }
.accent-green { --accent: #16a34a; --accent-soft: #eefbf3; }
.accent-red { --accent: #dc2626; --accent-soft: #fef2f2; }
.accent-amber { --accent: #d97706; --accent-soft: #fff7e8; }
.accent-violet { --accent: #7c3aed; --accent-soft: #f5f3ff; }

.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label { font-size: 11.5px; color: var(--muted); }
.stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}
.stat-value {
  margin-top: 7px;
  font-size: 23px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.stat-value small { margin-left: 2px; font-size: 11.5px; font-weight: 400; color: var(--faint); }
.stat-foot { margin-top: 4px; font-size: 10.5px; color: var(--faint); }
.stat-foot b { color: var(--muted); font-weight: 600; }
.stat-spark { display: block; width: 100%; height: 26px; margin-top: 5px; }
.stat-meter {
  height: 4px;
  margin-top: 8px;
  border-radius: 99px;
  background: #eef1f5;
  overflow: hidden;
}
.stat-meter i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #34d399, #16a34a);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.chart-card { padding: 15px 16px 10px; }
.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.chart-head h2 { font-size: 13px; font-weight: 600; }
.chart-head p { margin-top: 2px; }
.chart-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
  padding-top: 2px;
}
.chart-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}
.chart-box { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }

.chart-tip {
  position: absolute;
  z-index: 5;
  width: 132px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.12);
  font-size: 11px;
  pointer-events: none;
}
.chart-tip .tip-label {
  padding-bottom: 5px;
  margin-bottom: 5px;
  border-bottom: 1px solid var(--line);
  color: var(--faint);
  font-size: 10.5px;
}
.chart-tip span {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  line-height: 1.7;
}
.chart-tip span i {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  flex: 0 0 7px;
}
.chart-tip span b {
  margin-left: auto;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.model-list { display: flex; flex-direction: column; }
.model-row {
  display: grid;
  grid-template-columns: minmax(150px, 210px) minmax(80px, 1fr) 64px 150px;
  align-items: center;
  gap: 14px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}
.model-row:last-child { border-bottom: 0; }
.model-name { display: flex; flex-direction: column; min-width: 0; }
.model-name b { font-size: 12.5px; font-weight: 600; }
.model-name span { font-size: 10.5px; color: var(--faint); }
.model-bar { height: 6px; border-radius: 99px; background: #eef1f5; overflow: hidden; }
.model-bar i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #60a5fa, #1677ff);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.model-rate {
  font-size: 12.5px;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.model-rate.good { color: #15803d; }
.model-rate.warn { color: #b45309; }
.model-rate.bad { color: var(--danger); }
.model-detail {
  font-size: 10.5px;
  color: var(--faint);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .model-row { grid-template-columns: minmax(110px, 1fr) 90px; }
  .model-row .model-bar, .model-row .model-detail { display: none; }
}

/* short viewports: keep the whole form on one screen */
@media (max-height: 820px) and (min-width: 901px) {
  .gen-block { padding: 10px 11px 9px; gap: 7px; }
  #prompt { height: 66px; min-height: 66px; }
  .gen-submit .primary { padding: 9px 16px; }
  .gen-side .rate-line { display: none; }
  .size-option { padding: 5px 3px 4px; }
  .size-option b { font-size: 11.5px; }
  .size-option span { font-size: 9.5px; }
  .param-cols { gap: 10px; }
  .slider-row { gap: 5px; }
}
