/* ============================================================
   Make It Right - frontend stylesheet
   Super-i inspired identity: white canvas, lime accent, black
   pill buttons, sticky top nav. Token-driven; light + dark.
   Sections:
     1. Design tokens (light + dark)
     2. Base elements & typography
     3. Top bar & footer
     4. Page shell & shared panels
     5. Forms & buttons
     6. Auth (login/register)
     7. Home / dashboard
     8. Task table & status
     9. Agents page
    10. Job detail
    11. Product reference lab
    12. Model admin
    13. Responsive breakpoints
    14. Motion preferences
   ============================================================ */

/* ---------- 1. Design tokens ---------- */
:root {
  color-scheme: light;
  font-family: "Segoe UI Variable", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;

  --accent: #b4e45b;
  --accent-soft: #f3f9e8;
  --accent-border: rgba(128, 176, 42, 0.82);
  --accent-border-soft: rgba(128, 176, 42, 0.55);

  --bg: #f5f7f3;
  --surface: #fbfcfa;
  --surface-2: #eef2ec;
  --surface-3: #f8faf7;
  --topbar-bg: rgba(245, 247, 243, 0.92);

  --ink: #0b0d10;
  --text: #1a2230;
  --muted: #5f6b7a;
  --heading-sub: #475569;

  --line: #dfe5dc;
  --line-mid: #ccd5c8;
  --line-dash: #aebba9;

  --field-bg: #fbfcfa;
  --field-border: #bdc9b8;
  --field-border-hover: #94a3b8;

  --btn-bg: #0b0d10;
  --btn-fg: #f8faf7;
  --btn-soft-bg: #e8ede5;
  --btn-soft-fg: #334155;
  --danger: #b42318;

  --link: #42651d;
  --focus: #42651d;
  --eyebrow: #42651d;

  --ok-bg: #dcfce7;
  --ok-fg: #166534;
  --warn-bg: #fef3c7;
  --warn-fg: #854d0e;
  --bad-bg: #fee2e2;
  --bad-fg: #991b1b;
  --neutral-bg: #e2e8f0;
  --neutral-fg: #334155;

  --info-bg: #eff6ff;
  --info-fg: #1e3a8a;
  --info-border: #c7d7fe;
  --info-surface: #f8fbff;
  --info-head: #eef5ff;
  --info-line: #dbe6ff;

  --tint-green-bg: #f0fdf4;
  --tint-green-border: #bbf7d0;
  --tint-blue-bg: #f0f9ff;
  --tint-blue-border: #bae6fd;

  --chip-bg: #eef2f7;
  --chip-fg: #475569;

  --shadow-sm: 0 2px 8px rgba(31, 45, 27, 0.08);
  --shadow-card: 0 12px 30px rgba(31, 45, 27, 0.08);
  --shadow-primary: 0 24px 60px rgba(31, 45, 27, 0.1);
  --topbar-line: rgba(15, 23, 42, 0.08);

  /* Shape rule: panels 16px, fields and actions 10px, status badges pill. */
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

/* AIStarsLab generation */
.aistarslab-page {
  display: grid;
  gap: 20px;
}

.aistarslab-hero {
  align-items: center;
}

.aistarslab-credit {
  min-width: 150px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  display: grid;
  gap: 4px;
  text-align: right;
}

.aistarslab-credit span {
  color: var(--muted);
  font-size: 0.82rem;
}

.aistarslab-credit strong {
  font-size: 1.8rem;
  line-height: 1;
}

.aistarslab-form {
  display: grid;
  gap: 20px;
}

.aistarslab-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.aistarslab-pricing {
  padding: 8px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--link);
  font-weight: 700;
  white-space: nowrap;
}

.aistarslab-capability {
  margin-top: -10px;
}

.aistarslab-materials {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
}

.aistarslab-materials .section-title.compact {
  margin-bottom: 0;
}

.aistarslab-materials .is-muted {
  opacity: 0.55;
}

.aistarslab-submit-note {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 12px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, #f59e0b 12%, transparent);
  color: var(--text);
}

.aistarslab-submit-note span {
  color: var(--muted);
}

.result-video-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.result-video-gallery video {
  width: 100%;
  border-radius: 16px;
  background: #000;
}

@media (max-width: 720px) {
  .aistarslab-grid {
    grid-template-columns: 1fr;
  }

  .aistarslab-credit {
    width: 100%;
    text-align: left;
  }

  .aistarslab-submit-note {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --accent-soft: rgba(180, 228, 91, 0.1);
    --accent-border: rgba(180, 228, 91, 0.62);
    --accent-border-soft: rgba(180, 228, 91, 0.42);

    --bg: #0e1114;
    --surface: #15181d;
    --surface-2: #1b1f26;
    --surface-3: #171b21;
    --topbar-bg: rgba(14, 17, 20, 0.88);

    --ink: #f2f5f8;
    --text: #dde3ea;
    --muted: #9aa5b2;
    --heading-sub: #b5bfca;

    --line: #262c34;
    --line-mid: #333b45;
    --line-dash: #414b57;

    --field-bg: #12151a;
    --field-border: #39424e;
    --field-border-hover: #55606d;

    --btn-bg: #eceff3;
    --btn-fg: #0b0d10;
    --btn-soft-bg: #232932;
    --btn-soft-fg: #cbd4de;
    --danger: #e5484d;

    --link: #c7ed7c;
    --focus: #c7ed7c;
    --eyebrow: #c7ed7c;

    --ok-bg: rgba(34, 197, 94, 0.16);
    --ok-fg: #4ade80;
    --warn-bg: rgba(245, 158, 11, 0.16);
    --warn-fg: #fbbf24;
    --bad-bg: rgba(239, 68, 68, 0.16);
    --bad-fg: #f87171;
    --neutral-bg: rgba(148, 163, 184, 0.18);
    --neutral-fg: #cbd5e1;

    --info-bg: rgba(59, 130, 246, 0.12);
    --info-fg: #93c5fd;
    --info-border: rgba(59, 130, 246, 0.35);
    --info-surface: #141922;
    --info-head: #182030;
    --info-line: rgba(59, 130, 246, 0.25);

    --tint-green-bg: rgba(34, 197, 94, 0.1);
    --tint-green-border: rgba(34, 197, 94, 0.35);
    --tint-blue-bg: rgba(56, 189, 248, 0.1);
    --tint-blue-border: rgba(56, 189, 248, 0.35);

    --chip-bg: #232932;
    --chip-fg: #b5bfca;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.28);
    --shadow-card: 0 14px 34px rgba(0, 0, 0, 0.38);
    --shadow-primary: 0 28px 70px rgba(0, 0, 0, 0.44);
    --topbar-line: rgba(255, 255, 255, 0.08);
  }
}

/* Manual theme choice (theme toggle) must win over the OS preference
   in both directions, so both data-theme blocks restate the full set. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --accent-soft: rgba(180, 228, 91, 0.1);
  --accent-border: rgba(180, 228, 91, 0.62);
  --accent-border-soft: rgba(180, 228, 91, 0.42);

  --bg: #0e1114;
  --surface: #15181d;
  --surface-2: #1b1f26;
  --surface-3: #171b21;
  --topbar-bg: rgba(14, 17, 20, 0.88);

  --ink: #f2f5f8;
  --text: #dde3ea;
  --muted: #9aa5b2;
  --heading-sub: #b5bfca;

  --line: #262c34;
  --line-mid: #333b45;
  --line-dash: #414b57;

  --field-bg: #12151a;
  --field-border: #39424e;
  --field-border-hover: #55606d;

  --btn-bg: #eceff3;
  --btn-fg: #0b0d10;
  --btn-soft-bg: #232932;
  --btn-soft-fg: #cbd4de;
  --danger: #e5484d;

  --link: #c7ed7c;
  --focus: #c7ed7c;
  --eyebrow: #c7ed7c;

  --ok-bg: rgba(34, 197, 94, 0.16);
  --ok-fg: #4ade80;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --warn-fg: #fbbf24;
  --bad-bg: rgba(239, 68, 68, 0.16);
  --bad-fg: #f87171;
  --neutral-bg: rgba(148, 163, 184, 0.18);
  --neutral-fg: #cbd5e1;

  --info-bg: rgba(59, 130, 246, 0.12);
  --info-fg: #93c5fd;
  --info-border: rgba(59, 130, 246, 0.35);
  --info-surface: #141922;
  --info-head: #182030;
  --info-line: rgba(59, 130, 246, 0.25);

  --tint-green-bg: rgba(34, 197, 94, 0.1);
  --tint-green-border: rgba(34, 197, 94, 0.35);
  --tint-blue-bg: rgba(56, 189, 248, 0.1);
  --tint-blue-border: rgba(56, 189, 248, 0.35);

  --chip-bg: #232932;
  --chip-fg: #b5bfca;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.28);
  --shadow-card: 0 14px 34px rgba(0, 0, 0, 0.38);
  --shadow-primary: 0 28px 70px rgba(0, 0, 0, 0.44);
  --topbar-line: rgba(255, 255, 255, 0.08);
}

:root[data-theme="light"] {
  color-scheme: light;

  --accent-soft: #f3f9e8;
  --accent-border: rgba(128, 176, 42, 0.82);
  --accent-border-soft: rgba(128, 176, 42, 0.55);

  --bg: #f5f7f3;
  --surface: #fbfcfa;
  --surface-2: #eef2ec;
  --surface-3: #f8faf7;
  --topbar-bg: rgba(245, 247, 243, 0.92);

  --ink: #0b0d10;
  --text: #1a2230;
  --muted: #5f6b7a;
  --heading-sub: #475569;

  --line: #dfe5dc;
  --line-mid: #ccd5c8;
  --line-dash: #aebba9;

  --field-bg: #fbfcfa;
  --field-border: #bdc9b8;
  --field-border-hover: #94a3b8;

  --btn-bg: #0b0d10;
  --btn-fg: #f8faf7;
  --btn-soft-bg: #e8ede5;
  --btn-soft-fg: #334155;
  --danger: #b42318;

  --link: #42651d;
  --focus: #42651d;
  --eyebrow: #42651d;

  --ok-bg: #dcfce7;
  --ok-fg: #166534;
  --warn-bg: #fef3c7;
  --warn-fg: #854d0e;
  --bad-bg: #fee2e2;
  --bad-fg: #991b1b;
  --neutral-bg: #e2e8f0;
  --neutral-fg: #334155;

  --info-bg: #eff6ff;
  --info-fg: #1e3a8a;
  --info-border: #c7d7fe;
  --info-surface: #f8fbff;
  --info-head: #eef5ff;
  --info-line: #dbe6ff;

  --tint-green-bg: #f0fdf4;
  --tint-green-border: #bbf7d0;
  --tint-blue-bg: #f0f9ff;
  --tint-blue-border: #bae6fd;

  --chip-bg: #eef2f7;
  --chip-fg: #475569;

  --shadow-sm: 0 2px 8px rgba(31, 45, 27, 0.08);
  --shadow-card: 0 12px 30px rgba(31, 45, 27, 0.08);
  --shadow-primary: 0 24px 60px rgba(31, 45, 27, 0.1);
  --topbar-line: rgba(15, 23, 42, 0.08);
}

/* ---------- 2. Base elements & typography ---------- */
* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: rgba(180, 228, 91, 0.24);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  scroll-margin-top: 96px;
}

h1 {
  margin: 0 0 16px;
  font-size: 22px;
  color: var(--ink);
  text-wrap: balance;
}

h2 {
  margin: 22px 0 10px;
  font-size: 16px;
  color: var(--ink);
  text-wrap: balance;
}

.muted {
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--eyebrow);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

::selection {
  background: var(--accent);
  color: #0b0d10;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- 3. Top bar & footer ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  padding: 0 max(28px, env(safe-area-inset-right)) 0 max(28px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--topbar-line);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
}

.brand {
  display: inline-flex;
  min-width: 210px;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  color: #111827;
  background: var(--accent);
  font-size: 14px;
  font-weight: 900;
}

.nav-links {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.nav-links a {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--heading-sub);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.nav-links a:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-canvas-cta {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid #0b0d10;
  border-radius: 999px;
  padding: 7px 17px;
  color: var(--accent);
  background: #0b0d10;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.nav-canvas-cta:hover {
  border-color: var(--accent-border);
  color: #c7f477;
  background: #161a16;
  text-decoration: none;
}

body.canvas-app-page {
  height: 100dvh;
  overflow: hidden;
}

body.canvas-app-page .page {
  width: 100%;
  max-width: none;
  height: calc(100dvh - var(--canvas-top-offset, 72px));
  padding: 0;
  overflow: hidden;
}

body.canvas-app-page .site-footer {
  display: none;
}

.theme-toggle {
  display: inline-grid;
  width: 38px;
  min-height: 38px;
  padding: 0;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--btn-soft-fg);
  background: var(--btn-soft-bg);
  font-size: 16px;
  line-height: 1;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--btn-soft-fg);
  background: var(--btn-soft-bg);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.site-footer {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 24px 24px;
  color: var(--muted);
  font-size: 13px;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--ink);
}

/* ---------- 4. Page shell & shared panels ---------- */
.page {
  max-width: 1360px;
  margin: 0 auto;
  padding: clamp(22px, 3.2vw, 48px) max(clamp(22px, 3.2vw, 48px), env(safe-area-inset-right)) calc(clamp(22px, 3.2vw, 48px) + env(safe-area-inset-bottom)) max(clamp(22px, 3.2vw, 48px), env(safe-area-inset-left));
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
}

.panel:focus-within {
  border-color: var(--line-mid);
}

.wide {
  max-width: 880px;
  margin-left: auto;
  margin-right: auto;
}

.grid {
  display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  gap: 20px;
  align-items: start;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.page-head.compact {
  max-width: 980px;
  margin: 0 auto 18px;
}

.page-head h1 {
  margin-bottom: 8px;
  font-size: 28px;
}

.page-head p {
  margin: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.section-title h2 {
  margin: 0;
  font-size: 18px;
}

.section-title span,
.section-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.back {
  display: inline-block;
  margin-bottom: 18px;
  color: var(--link);
  text-decoration: none;
  font-weight: 700;
}

.back:hover {
  text-decoration: underline;
}

.inline-action {
  width: fit-content;
  margin: -6px 0 12px;
}

.empty {
  padding: 20px;
  color: var(--muted);
}

/* ---------- 5. Forms & buttons ---------- */
label {
  display: grid;
  gap: 7px;
  margin: 14px 0;
  font-size: 14px;
  font-weight: 600;
}

fieldset {
  min-width: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--field-border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--field-bg);
  transition: border-color 0.15s ease;
}

select {
  color-scheme: inherit;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--field-border-hover);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

textarea {
  resize: vertical;
  min-height: 132px;
}

.field-help {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

input[type="file"] {
  padding: 7px;
  color: var(--muted);
  font-size: 14px;
}

input[type="file"]::file-selector-button {
  min-height: 34px;
  margin-right: 10px;
  border: 1px solid var(--line-mid);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  background: var(--surface-2);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font: inherit;
  font-weight: 700;
  color: var(--btn-fg);
  background: var(--btn-bg);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.62;
  cursor: wait;
  transform: none;
}

.secondary,
.ghost {
  color: #0b0d10;
  background: var(--accent);
}

button.compact {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 12px;
}

button.danger {
  background: var(--danger);
  color: #f8faf7;
}

.error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--bad-fg);
  background: var(--bad-bg);
}

.notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--info-fg);
  background: var(--info-bg);
}

.upload-field {
  padding: 12px 14px;
  border: 1px dashed var(--line-dash);
  border-radius: var(--radius-md);
  background: var(--surface-3);
}

.hd-fix-head {
  align-items: center;
}

.hd-fix-form {
  display: grid;
  gap: 18px;
}

.hd-fix-form > label,
.hd-fix-settings label {
  margin: 0;
}

.hd-fix-settings {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.hd-fix-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.hd-fix-preview[hidden] {
  display: none;
}

.hd-fix-preview img {
  width: 88px;
  height: 88px;
  border-radius: 10px;
  object-fit: cover;
}

.hd-fix-preview div {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.hd-fix-preview strong,
.hd-fix-preview span {
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .hd-fix-settings {
    grid-template-columns: 1fr;
  }
}

pre {
  white-space: pre-wrap;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: #0f172a;
  color: #e2e8f0;
  overflow: auto;
}

dt {
  font-weight: 700;
  color: var(--heading-sub);
}

dd {
  margin: 0;
}

/* ---------- 6. Auth (login/register) ---------- */
.auth-shell,
.super-auth {
  min-height: calc(100svh - 154px);
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(620px, 1.1fr);
  gap: clamp(28px, 5vw, 76px);
  align-items: center;
}

.auth-copy,
.auth-stage {
  display: grid;
  gap: 22px;
  align-content: center;
}

.auth-stage h1,
.home-hero h1 {
  display: grid;
  gap: 2px;
  margin: 0 0 18px;
  color: var(--ink);
  font-size: clamp(48px, 6.4vw, 112px);
  font-weight: 800;
  line-height: 0.98;
  letter-spacing: 0;
}

.auth-stage .muted,
.home-hero .muted {
  max-width: 620px;
  color: var(--heading-sub);
  font-size: clamp(16px, 1.4vw, 22px);
  line-height: 1.7;
}

.auth-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.auth-notes span {
  padding: 7px 12px;
  border: 1px solid var(--line-mid);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
}

.auth-grid,
.auth-stack {
  display: grid;
  width: 100%;
  margin: 0;
  grid-template-columns: minmax(280px, 1fr) minmax(260px, 0.86fr);
  gap: 18px;
  align-items: stretch;
}

.auth-panel {
  display: grid;
  align-content: start;
  border-radius: var(--radius-lg);
  padding: clamp(20px, 2vw, 30px);
}

.auth-stack .auth-primary {
  grid-row: span 2;
}

.auth-primary {
  border-color: var(--accent-border-soft);
  box-shadow: var(--shadow-primary);
}

.scan-actions {
  display: grid;
  gap: 12px;
}

.scan-link {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  background: var(--surface-2);
  font-weight: 700;
}

.scan-link span {
  color: var(--bad-fg);
  font-size: 12px;
}

.scan-link.wechat {
  border-color: var(--tint-green-border);
  background: var(--tint-green-bg);
}

.scan-link.qq {
  border-color: var(--tint-blue-border);
  background: var(--tint-blue-bg);
}

.login-shell {
  min-height: calc(100dvh - 112px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(420px, 100%);
}

/* ---------- 7. Home / dashboard ---------- */
.super-home {
  display: grid;
  gap: clamp(18px, 2.2vw, 28px);
}

.home-hero {
  min-height: clamp(144px, 20vh, 220px);
  align-items: center;
  margin-bottom: 0;
  padding: clamp(18px, 2.8vw, 36px) 0;
  border-bottom: 1px solid var(--line);
}

.home-hero h1 {
  display: block;
  max-width: 760px;
  margin-bottom: 12px;
  font-size: clamp(34px, 4vw, 56px);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.home-hero .muted {
  max-width: 620px;
  font-size: clamp(15px, 1.2vw, 18px);
  line-height: 1.65;
}

.home-summary {
  display: grid;
  min-width: 132px;
  justify-items: end;
  align-content: center;
  padding-left: 24px;
  border-left: 1px solid var(--line-mid);
  color: var(--muted);
}

.home-summary strong {
  color: var(--ink);
  font-size: clamp(30px, 3.2vw, 46px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.home-summary span {
  margin-top: 8px;
  font-size: 13px;
}

.entry-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}

.entry-link {
  display: grid;
  gap: 5px;
  min-height: 92px;
  align-content: center;
  padding: clamp(14px, 1.7vw, 22px);
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  background: transparent;
  touch-action: manipulation;
  transition: transform 0.2s ease, border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.entry-link:hover {
  background: var(--surface-3);
}

.entry-link strong {
  font-size: clamp(17px, 1.3vw, 22px);
  color: var(--ink);
}

.entry-link span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.entry-link.active,
.entry-link.accent {
  border-color: var(--line-mid);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.entry-link.active strong,
.entry-link[aria-current="page"] strong {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 4px;
  text-underline-offset: 5px;
}

.dashboard-grid {
  grid-template-columns: minmax(360px, 0.82fr) minmax(520px, 1.18fr);
  gap: clamp(18px, 2vw, 28px);
}

.task-panel,
.task-list-panel {
  min-width: 0;
  border-radius: var(--radius-lg);
}

.task-panel {
  box-shadow: var(--shadow-card);
}

.task-mode-switch,
.image-family-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.task-mode-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  margin: 0;
  cursor: pointer;
}

.task-mode-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
  opacity: 0;
}

.task-mode-option span {
  display: flex;
  width: 100%;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
}

.task-mode-option input:checked + span {
  border-color: var(--line-mid);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.task-mode-option input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.task-mode-fields,
.image-family-fields {
  display: grid;
  gap: 4px;
}

.image-family-switch {
  margin-bottom: 2px;
}

.image-setting-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.task-mode-fields[hidden],
.image-family-fields[hidden] {
  display: none;
}

.submit-row {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

.submit-status {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- 8. Task table & status ---------- */
.table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 90px;
  gap: 12px;
  min-height: 44px;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}

.table-row:last-child {
  border-bottom: 0;
}

a.table-row:hover {
  background: var(--surface-2);
}

.table-head {
  font-weight: 700;
  background: var(--surface-2);
}

.task-table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.task-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

.task-table th,
.task-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.task-table th {
  color: var(--heading-sub);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 750;
}

.task-table th:first-child,
.task-table td:first-child {
  width: 116px;
}

.task-table th:last-child,
.task-table td:last-child {
  width: 92px;
}

.task-table tbody tr:last-child td {
  border-bottom: 0;
}

.task-table tbody tr {
  transition: background-color 0.15s ease;
}

.task-table tbody tr:hover,
.task-table tbody tr:focus-within {
  background: var(--surface-2);
}

.job-title-link {
  display: grid;
  min-width: 0;
  gap: 2px;
  color: var(--ink);
  text-decoration: none;
}

.job-title-link strong,
.job-title-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-title-link span {
  color: var(--muted);
  font-size: 12px;
}

.job-title-link:hover strong {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.task-empty {
  padding: 28px 18px !important;
  color: var(--muted);
  text-align: center !important;
}

.status {
  display: inline-flex;
  justify-content: center;
  min-width: 70px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--neutral-fg);
  background: var(--neutral-bg);
}

.status-done {
  color: var(--ok-fg);
  background: var(--ok-bg);
}

.status-running,
.status-queued {
  color: var(--warn-fg);
  background: var(--warn-bg);
}

.status-failed {
  color: var(--bad-fg);
  background: var(--bad-bg);
}

.status-cancelled {
  color: var(--neutral-fg);
  background: var(--neutral-bg);
}

.job-row-action form {
  margin: 0;
}

/* ---------- 9. Agents page ---------- */
.agent-layout {
  max-width: 1180px;
  margin: 0 auto;
}

.agent-page-head {
  align-items: end;
}

.agent-page-head h1,
.agent-section-title h2 {
  text-wrap: balance;
}

.agent-form {
  display: grid;
  gap: 26px;
  padding-bottom: 68px;
}

.agent-setup,
.agent-selection {
  display: grid;
  gap: 16px;
  padding-top: 18px;
  border-top: 1px solid var(--line-mid);
}

.agent-section-title {
  align-items: end;
  margin: 0;
}

.agent-section-title h2 {
  margin: 0 0 4px;
}

.agent-section-title p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.agent-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}

.agent-toolbar label,
.agent-toolbar fieldset {
  margin: 0;
}

.agent-model-picker {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 8px 12px;
  align-items: end;
}

.agent-model-picker:focus-within {
  border-radius: var(--radius-sm);
}

.agent-model-picker label {
  align-self: end;
}

.agent-model-picker .field-help {
  grid-column: 2;
}

.agent-result-field {
  min-width: 0;
  padding: 0;
  border: 0;
}

.agent-result-field legend {
  margin-bottom: 8px;
  font-weight: 700;
}

.agent-segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.agent-segmented label {
  position: relative;
  cursor: pointer;
}

.agent-segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.agent-segmented span {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.agent-segmented input:checked + span {
  border-color: var(--accent-border);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.agent-segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#agent-size-field[hidden] + .agent-upload-field {
  grid-column: 1 / -1;
}

.agent-file-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 120px));
  gap: 10px;
}

.agent-file-preview:empty {
  display: none;
}

.agent-file-preview figure {
  position: relative;
  min-width: 0;
  margin: 0;
}

.agent-file-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.agent-file-preview figcaption {
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-file-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  width: 28px;
  min-height: 28px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  color: #fff;
  background: rgba(20, 24, 18, 0.74);
  box-shadow: var(--shadow-sm);
  line-height: 1;
}

.agent-file-remove:hover {
  background: rgba(20, 24, 18, 0.92);
}

.agent-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.agent-card {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition: border-color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

.agent-card:focus-within {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.agent-card.is-selected {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  box-shadow: var(--shadow-sm);
}

.agent-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
}

.agent-check input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
}

.agent-check-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.agent-check small {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.5;
}

.agent-card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.agent-card-title small {
  flex: 0 0 auto;
  padding: 3px 6px;
  border-radius: 4px;
  color: var(--ink);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 800;
}

.agent-request {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.agent-request[hidden] {
  display: none;
}

.agent-request textarea {
  min-height: 126px;
  margin-top: 8px;
  background: var(--surface);
}

.agent-submit-bar {
  position: sticky;
  bottom: 14px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  border: 1px solid var(--line-mid);
  border-radius: var(--radius-md);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
}

.agent-submit-bar > div {
  display: grid;
  gap: 3px;
}

.agent-submit-bar button {
  flex: 0 0 auto;
}

/* ---------- 10. Job detail ---------- */
.job-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.job-head h1 {
  margin-bottom: 6px;
}

.job-head p {
  margin: 0;
}

.job-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 12px;
  margin: 14px 0 18px;
}

.job-actions form {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 12px;
  margin: 0;
}

.retry-model {
  width: min(280px, 100%);
  margin: 0;
}

.meta {
  display: grid;
  gap: 8px;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.meta div {
  display: grid;
  grid-template-columns: 90px 1fr;
}

.meta dd {
  overflow-wrap: anywhere;
}

.meta a {
  color: var(--link);
}

.result-panel {
  margin: 22px 0;
  border: 1px solid var(--info-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--info-surface);
}

.result-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--info-line);
  background: var(--info-head);
}

.result-panel-head h2 {
  margin: 0;
}

.result-panel pre {
  min-height: 220px;
  margin: 0;
  border-radius: 0;
}

.result-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  min-height: 52px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.result-gallery.is-empty {
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

.result-gallery a {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line-mid);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.result-gallery img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

/* ---------- 11. Product reference lab ---------- */
.lab-shell {
  display: grid;
  gap: 18px;
}

.lab-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.lab-title h1 {
  margin-bottom: 8px;
}

.lab-grid {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(420px, 1fr) minmax(320px, 380px);
  gap: 18px;
  align-items: start;
}

.lab-inputs,
.lab-analysis,
.lab-output {
  min-width: 0;
}

.lab-block {
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.lab-block h3,
.analysis-head h3 {
  margin: 0;
  font-size: 15px;
  color: var(--ink);
}

.analysis-split {
  display: grid;
  gap: 14px;
}

.analysis-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
}

.analysis-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.analysis-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.product-card .analysis-head {
  background: var(--info-head);
}

.reference-card .analysis-head {
  background: var(--surface-2);
}

.analysis-card textarea {
  min-height: 270px;
  border: 0;
  border-radius: 0;
  font-family: Consolas, "Microsoft YaHei", monospace;
}

.lab-rule {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--info-border);
  border-radius: var(--radius-md);
  color: var(--info-fg);
  background: var(--info-bg);
  font-size: 14px;
  line-height: 1.55;
}

.lab-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.lab-thumbs img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line-mid);
  border-radius: 6px;
  background: var(--surface-2);
}

.lab-job {
  min-height: 44px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line-mid);
  border-radius: var(--radius-md);
  color: var(--heading-sub);
  background: var(--surface-2);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.lab-job a {
  color: var(--link);
  font-weight: 700;
}

.lab-job.error {
  border-color: var(--bad-fg);
  color: var(--bad-fg);
  background: var(--bad-bg);
}

/* ---------- 12. Model admin ---------- */
.model-admin,
.provider-list,
.provider-section {
  display: grid;
  gap: 18px;
}

.model-admin.wide {
  max-width: none;
}

.model-admin-head,
.provider-head,
.provider-meta,
.model-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.model-admin-head h1,
.provider-head h2,
.provider-head p {
  margin: 0;
}

.model-admin-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.model-admin-actions form {
  margin: 0;
}

.model-filter-bar {
  display: grid;
  grid-template-columns: minmax(240px, 1.5fr) minmax(150px, 0.8fr) minmax(150px, 0.8fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.model-filter-bar label {
  margin: 0;
}

.model-filter-actions {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

#model-filter-count {
  min-width: 68px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.provider-count,
.provider-meta span,
.model-status {
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--chip-bg);
  color: var(--chip-fg);
  font-size: 12px;
  font-weight: 700;
}

.model-add-panel {
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.model-add-panel summary {
  cursor: pointer;
  font-weight: 700;
}

.model-add-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.model-add-form button {
  align-self: end;
}

.provider-section {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.provider-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.route-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 14px;
  align-items: start;
}

.route-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
}

.route-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
}

.route-title span {
  color: var(--muted);
  font-size: 13px;
}

.route-title > div:first-child {
  display: grid;
  gap: 4px;
}

.route-table {
  display: grid;
}

.route-row {
  display: grid;
  grid-template-columns: 130px minmax(180px, 1fr) 180px 70px 60px 60px;
  gap: 10px;
  align-items: center;
  min-height: 40px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.model-admin .route-row {
  grid-template-columns: minmax(180px, 1fr) 120px 60px 60px;
}

.route-head {
  font-weight: 700;
  color: var(--heading-sub);
}

.route-off {
  color: var(--bad-fg);
  background: var(--bad-bg);
}

.model-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.model-actions form {
  margin: 0;
}

.model-status.is-enabled {
  background: var(--ok-bg);
  color: var(--ok-fg);
}

.model-status.is-disabled {
  background: var(--chip-bg);
  color: var(--muted);
}

.model-disabled {
  opacity: 0.72;
}

.provider-empty {
  padding: 14px;
  border: 1px dashed var(--line-dash);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
}

.provider-empty,
.model-no-results {
  grid-column: 1 / -1;
}

.model-no-results {
  padding: 28px 18px;
  border: 1px dashed var(--line-dash);
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-align: center;
}

.form-alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.form-alert-error {
  background: var(--bad-bg);
  color: var(--bad-fg);
}

.form-alert-success {
  background: var(--ok-bg);
  color: var(--ok-fg);
}

/* ---------- 13. Responsive breakpoints ---------- */
@media (max-width: 1280px) {
  .lab-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .lab-output {
    grid-column: 1 / -1;
  }
}

@media (max-width: 1100px) {
  .auth-shell,
  .super-auth,
  .dashboard-grid {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .auth-stage h1 {
    max-width: 760px;
  }

  .model-filter-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .topbar {
    height: auto;
    align-items: center;
    padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
    flex-wrap: wrap;
    gap: 10px;
  }

  .brand {
    min-width: 0;
  }

  .nav-links {
    flex: 1 0 100%;
    order: 3;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .nav-links::-webkit-scrollbar {
    display: none;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .page {
    padding: 24px max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .page-head {
    display: grid;
    align-items: start;
  }

  .auth-shell,
  .super-auth {
    min-height: auto;
    gap: 22px;
  }

  .auth-stage h1 {
    font-size: clamp(38px, 13vw, 58px);
  }

  .home-hero h1 {
    max-width: 640px;
    font-size: clamp(32px, 7vw, 44px);
  }

  .auth-grid,
  .auth-stack,
  .entry-strip,
  .dashboard-grid,
  .image-setting-grid,
  .agent-toolbar,
  .agent-options,
  .grid,
  .analysis-split {
    grid-template-columns: 1fr;
  }

  .auth-stack .auth-primary {
    grid-row: auto;
  }

  .home-hero {
    min-height: auto;
  }

  .home-summary {
    min-width: 0;
    justify-items: start;
    padding: 14px 0 0;
    border-top: 1px solid var(--line-mid);
    border-left: 0;
  }

  .entry-link {
    min-height: 82px;
  }

  .table-row {
    grid-template-columns: 88px minmax(0, 1fr) 78px;
    gap: 8px;
  }

  .status {
    min-width: 62px;
  }

  .job-head {
    display: grid;
    gap: 10px;
    justify-items: start;
  }

  .job-actions {
    display: grid;
    justify-content: stretch;
    justify-items: stretch;
  }

  .retry-model {
    width: 100%;
  }

  .meta div {
    grid-template-columns: 82px 1fr;
  }

  .result-gallery {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .lab-title {
    display: grid;
    gap: 10px;
    justify-items: start;
  }

  .lab-grid {
    grid-template-columns: 1fr;
  }

  .model-admin-head,
  .provider-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .model-filter-bar,
  .model-add-form,
  .route-title,
  .route-row,
  .model-admin .route-row {
    grid-template-columns: 1fr;
  }

  .model-filter-actions,
  .model-actions {
    justify-content: flex-start;
  }

  #model-filter-count {
    text-align: left;
  }

  .site-footer {
    display: grid;
    gap: 6px;
    text-align: center;
  }
}

@media (max-width: 680px) {
  .task-table-wrap {
    border: 0;
    overflow: visible;
  }

  .task-table,
  .task-table tbody,
  .task-table tr,
  .task-table td {
    display: block;
    width: 100%;
  }

  .task-table thead {
    display: none;
  }

  .task-table tbody {
    display: grid;
    gap: 10px;
  }

  .task-table tbody tr {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-3);
  }

  .task-table td,
  .task-table td:first-child,
  .task-table td:last-child {
    display: grid;
    width: 100%;
    grid-template-columns: 66px minmax(0, 1fr);
    gap: 10px;
    padding: 5px 0;
    border: 0;
  }

  .task-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .task-table .task-empty {
    display: block;
    padding: 20px 8px !important;
  }

  .task-table .task-empty::before {
    content: none;
  }
}

@media (max-width: 480px) {
  .page {
    padding: 18px max(12px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .panel,
  .auth-panel {
    padding: 16px;
  }

  .auth-stage h1 {
    font-size: clamp(32px, 11.5vw, 44px);
  }

  .home-hero h1 {
    font-size: clamp(30px, 10vw, 38px);
  }

  .table-row {
    grid-template-columns: 74px minmax(0, 1fr) 70px;
    font-size: 13px;
  }

  .status {
    min-width: 56px;
    font-size: 11px;
  }

  form > button[type="submit"],
  .submit-row button,
  .auth-panel button,
  .lab-inputs button,
  .lab-output button {
    width: 100%;
  }

  .top-actions button {
    width: auto;
  }

  .submit-row {
    display: grid;
    align-items: stretch;
  }
}

@media (max-width: 820px) {
  .agent-model-picker,
  .agent-list {
    grid-template-columns: 1fr;
  }

  .agent-model-picker .field-help {
    grid-column: 1;
  }

  .agent-submit-bar {
    bottom: 8px;
  }
}

@media (max-width: 560px) {
  .agent-segmented,
  .agent-submit-bar {
    grid-template-columns: 1fr;
  }

  .agent-submit-bar {
    display: grid;
    align-items: stretch;
  }

  .agent-submit-bar button {
    width: 100%;
  }
}

/* ---------- 14. Motion preferences ---------- */
.job-list-heading {
  align-items: end;
  gap: 20px;
}

.job-list-filters {
  display: flex;
  align-items: end;
  gap: 10px;
}

.job-list-filters label {
  display: grid;
  gap: 5px;
  min-width: 130px;
  color: var(--muted);
  font-size: 12px;
}

.job-list-filters select {
  min-height: 38px;
  padding-block: 7px;
}

.active-job-queue {
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--warning, #d89b35) 42%, transparent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--warning, #d89b35) 8%, var(--panel, #fff));
}

.active-job-queue-head,
.active-job-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.active-job-queue-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

.active-job-queue-head span,
.active-job-item a span {
  color: var(--muted);
  font-size: 0.86rem;
}

.active-job-queue-items {
  display: grid;
  gap: 8px;
}

.active-job-item {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--panel, #fff);
}

.active-job-item > a {
  display: grid;
  min-width: 0;
  margin-right: auto;
  text-decoration: none;
}

.active-job-item > a strong,
.active-job-item > a span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 680px) {
  .active-job-queue-head,
  .active-job-item {
    align-items: stretch;
    flex-direction: column;
  }

  .active-job-item form,
  .active-job-item button {
    width: 100%;
  }
}

.task-list-panel[aria-busy="true"] .task-table-wrap,
.task-list-panel[aria-busy="true"] .job-pagination {
  opacity: 0.5;
  pointer-events: none;
}

.job-pagination,
.job-page-numbers {
  align-items: center;
  gap: 6px;
}

.job-pagination {
  display: grid;
  grid-template-columns: minmax(88px, 1fr) auto minmax(88px, 1fr);
  margin-top: 18px;
}

.job-page-numbers {
  display: flex;
  justify-content: center;
}

.job-pagination > button:first-child {
  justify-self: start;
}

.job-pagination > button:last-child {
  justify-self: end;
}

.job-pagination button {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid var(--line-mid);
  padding: 7px 11px;
  background: var(--btn-soft-bg);
  color: var(--btn-soft-fg);
}

.job-pagination button:disabled {
  cursor: default;
}

.job-pagination button.is-current {
  border-color: var(--accent-border-soft);
  background: var(--accent-soft);
  color: var(--ink);
  opacity: 1;
}

@media (max-width: 640px) {
  .job-list-heading,
  .job-list-filters {
    align-items: stretch;
  }

  .job-list-heading {
    display: grid;
  }

  .job-list-filters label {
    min-width: 0;
    flex: 1;
  }

  .job-pagination {
    grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  * {
    transition: none !important;
    animation: none !important;
  }

  .entry-link:hover {
    transform: none;
  }

  button:active {
    transform: none;
  }
}

/* ---------- 15. Registration controls ---------- */
.registration-state {
  border: 1px solid var(--line-mid);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 0.88rem;
}

.registration-state.is-open,
.registration-badge.is-open {
  border-color: color-mix(in srgb, #22a06b 38%, transparent);
  background: color-mix(in srgb, #22a06b 10%, var(--panel));
  color: #168256;
}

.registration-state.is-closed,
.registration-badge.is-closed {
  border-color: color-mix(in srgb, var(--warning, #d89b35) 42%, transparent);
  background: color-mix(in srgb, var(--warning, #d89b35) 10%, var(--panel));
  color: var(--ink);
}

.auth-panel-disabled input,
.auth-panel-disabled button {
  cursor: not-allowed;
}

.registration-admin {
  max-width: 880px;
  margin-inline: auto;
}

.registration-admin-head,
.registration-summary,
.registration-option {
  display: flex;
}

.registration-admin-head {
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin: 20px 0 24px;
}

.registration-admin-head h1 {
  margin: 4px 0 8px;
}

.registration-badge {
  flex: 0 0 auto;
  border: 1px solid;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.86rem;
  font-weight: 700;
}

.registration-summary {
  gap: 12px;
  margin: 22px 0;
}

.registration-summary > div {
  display: grid;
  flex: 1;
  gap: 6px;
  border: 1px solid var(--line-mid);
  border-radius: 12px;
  padding: 16px;
  background: var(--btn-soft-bg);
}

.registration-summary span,
.registration-settings-form small {
  color: var(--muted);
  font-size: 0.82rem;
}

.registration-settings-form,
.registration-settings-form fieldset {
  display: grid;
  gap: 12px;
}

.registration-settings-form fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

.registration-settings-form legend {
  margin-bottom: 10px;
  font-weight: 700;
}

.registration-option {
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--line-mid);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
}

.registration-option:has(input:checked) {
  border-color: var(--accent-border-soft);
  background: var(--accent-soft);
}

.registration-option input {
  width: auto;
  margin-top: 4px;
}

.registration-option span,
.registration-quota {
  display: grid;
  gap: 4px;
}

.registration-quota {
  margin-top: 8px;
}

.registration-settings-form > button {
  justify-self: start;
  margin-top: 8px;
}

@media (max-width: 640px) {
  .registration-admin-head,
  .registration-summary {
    display: grid;
  }

  .registration-settings-form > button {
    width: 100%;
  }
}
