:root {
  color-scheme: light;
  --paper: #f5f2ee;
  --surface: #fff;
  --subtle: #faf7f3;
  --ink: #2e2826;
  --muted: #655a55;
  --line: #e6dfd8;
  --control-line: #97877e;
  --chrome: #272321;
  --chrome-hover: #3c332e;
  --chrome-ink: #f9f5ef;
  --accent: #a4472b;
  --accent-dark: #81341f;
  --highlight: #faeee6;
  --warm-light: #ffbf9b;
  --danger: #962e3b;
  --radius: 12px;
  --content-gutter: clamp(16px, 3vw, 42px);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button, select, summary { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
a { color: var(--accent-dark); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.65rem, 3vw, 2.3rem); font-weight: 720; line-height: 1.22; }
h2 { font-size: 1.2rem; line-height: 1.35; }
h3 { font-size: 1.04rem; }
small, .muted { color: var(--muted); }
small { font-size: .875rem; }
.skip-link {
  position: fixed;
  z-index: 20;
  top: 8px;
  left: 8px;
  background: var(--surface);
  padding: 12px;
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.shell { min-height: 100dvh; }
.topbar {
  display: grid;
  grid-template-areas: "brand navigation account";
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  min-height: 66px;
  gap: 12px 32px;
  padding: 0 var(--content-gutter);
  background: var(--chrome);
  color: var(--chrome-ink);
}
.brand-link { grid-area: brand; color: inherit; text-decoration: none; justify-self: start; }
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  position: relative;
  width: 33px;
  height: 33px;
  flex: none;
  border-radius: 8px;
  background: var(--warm-light);
  color: var(--chrome);
}
.brand-mark::before, .brand-mark::after {
  content: "";
  position: absolute;
  top: 9px;
  width: 4px;
  height: 15px;
  border-radius: 1px;
  background: currentColor;
  transform: skew(-25deg);
}
.brand-mark::before { left: 11px; }
.brand-mark::after { left: 18px; }
.brand-name { display: grid; gap: 2px; font-size: .875rem; line-height: 1.15; white-space: nowrap; }
.brand-name strong { font-size: 1.1rem; letter-spacing: .06em; }
.top-nav { grid-area: navigation; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; min-width: 0; }
.top-links { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.tool-links { position: relative; padding-inline-start: 12px; }
.tool-links::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 50%;
  width: 1px;
  height: 18px;
  transform: translateY(-50%);
  background: #f9f5ef38;
}
.top-link, .top-menu summary, .top-nav-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-weight: 600;
  text-decoration: none;
}
.top-link:hover, .top-menu summary:hover, .top-menu[open] summary, .top-nav-toggle:hover {
  background: var(--chrome-hover);
}
.top-link[aria-current="page"], .top-menu summary.is-active {
  background: #50392f;
  color: #ffceb1;
}
.topbar :focus-visible, .login-brand :focus-visible { outline-color: var(--warm-light); }
.top-account { grid-area: account; }
.top-menu { position: relative; }
.top-menu summary { list-style: none; }
.top-menu summary::-webkit-details-marker { display: none; }
.top-menu summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin: -3px 2px 0;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
  flex: none;
}
.account-name { max-width: clamp(3rem, 11vw, 11rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-menu-items {
  position: absolute;
  z-index: 3;
  inset: calc(100% + 8px) 0 auto auto;
  min-width: 150px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 24px #2e282624;
}
.top-menu-items :focus-visible { outline-color: var(--accent); outline-offset: -2px; }
.menu-link {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
}
.menu-link:hover, .menu-link[aria-current="page"] { background: var(--highlight); color: var(--accent-dark); }
.top-nav-toggle { grid-area: toggle; display: none; }

.content { max-width: 1680px; margin: 0 auto; padding: 28px var(--content-gutter) 48px; }
.content:focus { outline: none; }
.heading, .section-title, .toolbar, .dialog-head, .dialog-foot, .upload-foot, .row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.heading { margin-bottom: 22px; }
.heading p { margin-top: 6px; color: var(--muted); }
.workspace.has-sidebar { display: grid; grid-template-columns: 220px minmax(0, 1fr); align-items: start; gap: 20px; }
.workspace-main { min-width: 0; }
.side-panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--subtle); }
.side-title { padding: 16px 14px 12px; font-size: .95rem; color: var(--muted); }
.side-group { display: grid; gap: 2px; padding: 0 8px 8px; }
.side-group + .side-group { padding-top: 8px; border-top: 1px solid var(--line); }
.side-link {
  display: flex;
  position: relative;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 8px;
  border-radius: 7px;
  color: var(--ink);
  font-weight: 570;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.side-link:hover { background: #f1e9e0; }
.side-link[aria-current="page"] { background: var(--highlight); color: var(--accent-dark); font-weight: 700; }
.side-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset: 10px auto 10px 0;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.stage-index, .side-count, .result-count { font-variant-numeric: tabular-nums; }
.stage-index {
  display: grid;
  flex: none;
  place-items: center;
  min-width: 27px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: .875rem;
}
.side-link[aria-current="page"] .stage-index { border-color: #e1bba9; color: var(--accent-dark); }
.side-caption { flex: 1; }
.side-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 23px;
  padding: 1px 5px;
  border-radius: 5px;
  background: #eee8e1;
  color: var(--muted);
  font-size: .875rem;
}
.side-link[aria-current="page"] .side-count { background: #f3dacb; color: var(--accent-dark); }

.primary, .secondary, .text-button, .danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}
.primary { background: var(--accent); color: #fff; }
.primary:hover:not(:disabled) { background: var(--accent-dark); }
.secondary { border-color: var(--control-line); background: var(--surface); color: var(--ink); }
.secondary:hover:not(:disabled) { background: var(--subtle); }
.text-button { padding-inline: 8px; background: transparent; color: var(--accent-dark); }
.text-button:hover:not(:disabled) { background: var(--highlight); }
.danger { border-color: #e1b7bd; background: var(--surface); color: var(--danger); }
.danger:hover:not(:disabled) { background: #fbecef; }
.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.section-title { flex-wrap: wrap; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.toolbar { flex-wrap: wrap; justify-content: flex-start; padding: 12px 18px; }
.toolbar input { width: min(265px, 100%); }
.toolbar .refresh { margin-left: auto; }
input:not([type=checkbox]):not([type=radio]), textarea, select {
  min-width: 0;
  min-height: 40px;
  padding: 7px 10px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 400;
}
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
textarea { display: block; width: 100%; resize: vertical; }
textarea[readonly] { background: var(--subtle); }
input[type=file] { max-width: 100%; width: 100%; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: .93rem; }
th { border-top: 1px solid var(--line); background: var(--subtle); color: var(--muted); font-weight: 660; white-space: nowrap; }
tbody tr:hover, tbody tr:focus { background: #fdf8f3; }
tbody tr:focus { outline-offset: -2px; }
td:first-child { min-width: 150px; overflow-wrap: anywhere; }
td strong { display: block; }
.progress { display: flex; gap: 4px; margin-bottom: 4px; }
.progress i { width: 18px; height: 4px; border-radius: 4px; background: #e9e0d7; }
.progress i.done { background: #3a7964; }
.progress i.current { background: var(--accent); }
.status {
  display: inline-flex;
  padding: 2px 7px;
  border-radius: 5px;
  background: #eee8e3;
  color: #554842;
  font-size: .875rem;
  white-space: nowrap;
}
.status.review, .status.needs_input { background: #f9ecd5; color: #79460c; }
.status.failed { background: #f8e6e8; color: var(--danger); }
.status.running, .status.queued { background: #e5edf8; color: #31527a; }
.status.ready { background: #e1efe8; color: #285b4b; }
ul.actions { display: flex; flex-wrap: wrap; gap: 2px; margin: 0; padding: 0; list-style: none; }
.actions button { min-height: 36px; font-size: .9rem; }
.queue > .error { margin: 0 18px 12px; }
.empty { display: grid; justify-items: center; gap: 8px; padding: 54px 16px; text-align: center; }
.empty p { max-width: 48ch; }
.empty .primary, .empty .secondary { margin-top: 5px; }
.empty-glyph {
  position: relative;
  width: 40px;
  height: 32px;
  margin-bottom: 6px;
  border: 1.5px solid #ba907c;
  border-radius: 5px;
  background: var(--highlight);
}
.empty-glyph::before {
  content: "";
  position: absolute;
  inset: 7px 7px auto;
  height: 6px;
  border: 1.5px solid #ba907c;
  border-radius: 2px;
}

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(420px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 16px 40px #34261516;
}
.login-brand { padding: 22px 28px; background: var(--chrome); color: var(--chrome-ink); }
.login-main { padding: 25px 28px 30px; }
.login-main h1 { margin-bottom: 21px; font-size: 1.7rem; }
.login form { display: grid; gap: 16px; }
.login form .primary { margin-top: 4px; min-height: 44px; }

dialog {
  width: min(880px, calc(100vw - 28px));
  max-height: calc(100dvh - 36px);
  padding: 0;
  border: 1px solid var(--control-line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 18px 55px #2117114d;
}
dialog::backdrop { background: #211a16a6; }
.dialog-head, .dialog-foot { position: sticky; z-index: 1; padding: 13px 20px; background: var(--surface); }
.dialog-head { top: 0; border-bottom: 1px solid var(--line); }
.dialog-foot { bottom: 0; }
.upload-foot { padding: 13px 20px; background: var(--subtle); }
.dialog-foot, .upload-foot { flex-wrap: wrap; border-top: 1px solid var(--line); }
.dialog-foot .controls, .upload-foot .controls { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.dialog-body, .upload-body { display: grid; gap: 16px; padding: 18px 20px; }
.upload-body { overflow-wrap: anywhere; }
.dialog-head .secondary { min-width: 44px; padding: 6px; font-size: 1.2rem; }
.queue-result { background: var(--subtle); }
.image-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr)); gap: 12px; }
.image-results figure { margin: 0; min-width: 0; }
.image-results img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--surface); }
.image-results figcaption { display: grid; gap: 5px; padding-block: 7px; }
.panel > .info[role="alert"] { margin: 12px; }
.upload-foot > .info[role="alert"] { width: 100%; }
.result-meta {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow-wrap: anywhere;
}
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}
.tab:hover { background: var(--highlight); }
.tab[aria-selected="true"] { border-color: #dfbba9; background: var(--highlight); color: var(--accent-dark); }
.group { min-width: 0; margin: 0; padding: 12px 0 0; border: 0; border-top: 1px solid var(--line); }
.group legend { padding: 0 9px 0 0; font-weight: 700; }
.queue-result .group {
  padding: 8px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.queue-result .group legend { padding: 0 5px; }
.field { display: grid; gap: 5px; min-width: 0; font-weight: 620; }
.field small { font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stack { display: grid; gap: 12px; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; overflow-wrap: anywhere; }
.previews { display: flex; flex-wrap: wrap; gap: 8px; }
.preview { display: grid; gap: 5px; width: 115px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--subtle); }
.preview img { width: 100%; height: 80px; object-fit: contain; }
.preview small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview button { min-height: 34px; }
.variant { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.variant .row-between { margin-bottom: 7px; }
.error, .info { padding: 9px 11px; border-radius: 8px; overflow-wrap: anywhere; }
.error { background: #fae9ec; color: var(--danger); }
.info { border: 1px solid var(--line); background: var(--subtle); color: var(--muted); }
.readout { overflow-wrap: anywhere; }
.readout ul { margin: 5px 0 0; padding-left: 22px; }
.notice {
  position: fixed;
  z-index: 5;
  right: 20px;
  bottom: 20px;
  max-width: calc(100vw - 40px);
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--chrome);
  color: var(--chrome-ink);
  box-shadow: 0 6px 22px #211a162b;
}

@media (max-width: 1040px) {
  .topbar {
    grid-template-areas: "brand account" "navigation navigation";
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 12px;
    padding-block: 8px;
  }
  .workspace.has-sidebar { grid-template-columns: 195px minmax(0, 1fr); gap: 14px; }
  .toolbar .refresh { margin-left: 0; }
  th, td { padding-inline: 9px; }
}
@media (max-width: 760px) {
  .top-nav { display: grid; }
  .tool-links { padding: 6px 0 0; }
  .tool-links::before { top: 0; width: 24px; height: 1px; transform: none; }
  .content { padding-top: 21px; }
  .workspace.has-sidebar { grid-template-columns: minmax(0, 1fr); }
  .side-group { display: flex; flex-wrap: wrap; }
  .side-title { padding-top: 10px; }
  .side-link { padding-inline: 9px; }
}
@media (max-width: 560px) {
  .topbar {
    grid-template-areas: "brand toggle account" "navigation navigation navigation";
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 0 3px;
  }
  .top-nav-toggle { display: flex; }
  .top-nav { display: none; }
  .top-nav.is-open { display: grid; margin-top: 8px; }
  .top-link, .top-menu summary, .top-nav-toggle { padding-inline: 8px; }
  .brand { gap: 6px; }
  .brand-mark { width: 30px; height: 30px; }
  .brand-mark::before, .brand-mark::after { top: 8px; }
  .brand-mark::before { left: 10px; }
  .brand-mark::after { left: 17px; }
  .brand-name { font-size: .75rem; }
  .heading { align-items: flex-start; flex-direction: column; margin-bottom: 16px; }
  .side-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-link { gap: 6px; padding-inline: 7px; }
  .primary, .secondary, .text-button, .danger, input:not([type=checkbox]):not([type=radio]), textarea, select, .actions button {
    min-height: 44px;
  }
  .section-title, .toolbar, .dialog-body, .dialog-head, .dialog-foot, .upload-body, .upload-foot { padding-inline: 12px; }
  .toolbar { gap: 8px; }
  .toolbar input { width: 100%; }
  .jobs-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .jobs-table, .jobs-table tbody, .jobs-table tr, .jobs-table td { display: block; }
  .jobs-table tr { padding: 8px 12px; border-top: 1px solid var(--line); }
  .jobs-table td { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border: 0; }
  .jobs-table td[data-label]::before { content: attr(data-label); flex: none; color: var(--muted); }
  .jobs-table td:last-child { justify-content: flex-start; }
  .grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 355px) {
  .topbar { --content-gutter: 10px; }
  .brand-name { font-size: .72rem; }
  .top-menu summary { gap: 4px; }
}
