:root {
  --red: #e10613;
  --red-dark: #be0410;
  --ink: #001a34;
  --text: #1d2430;
  --muted: #667085;
  --line: #e6e9ef;
  --bg: #f2f4f7;
  --card: #fff;
  --soft: #fff1f1;
  --green: #087443;
  --amber: #9a6700;
  --shadow: 0 8px 28px rgba(0, 26, 52, 0.08);
  --radius: 16px;
  --font: "Onest", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img { max-width: 100%; }
[x-cloak] { display: none !important; }

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.top-row, .tabs, main, .foot { width: min(1240px, calc(100% - 32px)); margin: 0 auto; }
.top-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--red);
  text-decoration: none;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.04em;
  flex: 0 0 auto;
}
.logo svg { width: 28px; height: 28px; }
.catalog-btn, .btn, .search button {
  border: 0;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  font-weight: 700;
}
.catalog-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 16px;
  flex: 0 0 auto;
}
.catalog-btn svg { width: 14px; height: 14px; }
.catalog-btn:hover, .btn.primary:hover, .search button:hover { background: var(--red-dark); }
.search {
  flex: 1;
  display: flex;
  gap: 8px;
  min-width: 0;
}
.search input {
  flex: 1;
  height: 48px;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0 16px;
  background: #fff;
  outline: none;
}
.search input:focus { border-color: #b9c0cc; }
.search button { width: 56px; height: 48px; display: grid; place-items: center; }
.search button svg { width: 22px; height: 22px; }
.top-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.tool-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  background: var(--bg);
  border-radius: 999px;
  padding: 6px 8px 6px 10px;
  min-height: 40px;
}
.dot { width: 8px; height: 8px; border-radius: 99px; background: var(--muted); display: inline-block; }
.dot.ok { background: #12b76a; box-shadow: 0 0 0 4px rgba(18, 183, 106, .15); }
.dot.wait { background: #f79009; }
.dot.stop { background: #98a2b3; }
.dot.bad { background: var(--red); }
.tool-label { font-size: 13px; font-weight: 600; }
.badge-count {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.userbox { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.userbox button, .btn.ghost, .btn.tiny.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.userbox button { border-radius: 10px; padding: 8px 10px; font-weight: 600; }
.tabs { display: flex; gap: 4px; align-items: center; overflow: auto; padding-bottom: 0; }
.tabs a {
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 13px;
  font-weight: 600;
  color: #5c6778;
  padding: 12px 10px 14px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a.active { color: var(--ink); border-color: var(--ink); }
.portal { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
main { padding: 28px 0 96px; }
.foot { color: var(--muted); font-size: 13px; padding: 8px 0 28px; }
.page-head h1 { margin: 0 0 6px; font-size: 34px; letter-spacing: -.03em; color: var(--ink); }
.lead { margin: 0; color: var(--muted); line-height: 1.45; }
.hero {
  margin-top: 18px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 32px;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(105deg, #8e0410 0%, #e10613 48%, #ff534a 100%);
  min-height: 188px;
}
.eyebrow { margin: 0 0 8px; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 700; opacity: .85; }
.hero h2 { margin: 0 0 8px; font-size: 40px; line-height: 1.02; letter-spacing: -.04em; }
.hero p { margin: 0; max-width: 420px; }
.hero-stats { display: flex; gap: 10px; align-self: center; }
.hero-stats div { background: rgba(255,255,255,.16); border-radius: 16px; min-width: 124px; padding: 14px 16px; }
.hero-stats b { display: block; font-size: 30px; letter-spacing: -.03em; }
.hero-stats span { font-size: 13px; opacity: .9; }
.note, .sync-line {
  margin: 14px 0 0;
  background: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 14px;
}
.sync-line.running { color: var(--red-dark); font-weight: 600; }
.sync-line.bad { color: var(--red-dark); }
.toolbar, .split { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; max-width: 100%; }
.toolbar { margin: 16px 0; }
.toolbar.tight { margin-top: 0; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; }
.field.grow { flex: 1 1 280px; min-width: 220px; max-width: 100%; }
.field input, .field select, .settings-card input, .settings-card select, .settings-card textarea, .sheet input, .sheet textarea, .sheet select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
.field select, .settings-card select { height: 44px; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 14px; min-height: 44px; }
.btn { height: 44px; padding: 0 14px; font-weight: 700; }
.btn.tiny { height: 32px; padding: 0 10px; border-radius: 10px; font-size: 13px; }
.btn.primary { background: var(--red); color: #fff; }
.workspace { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
.tree-card, .settings-card, .prompt-row, .table-wrap, .login-card {
  background: #fff;
  border-radius: 20px;
}
.tree-card {
  padding: 8px;
  position: sticky;
  top: 132px;
  max-height: calc(100vh - 148px);
  overflow: auto;
}
.tree-head, .grid-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; padding: 8px 10px; }
.tree-tools { display: flex; gap: 6px; flex-shrink: 0; }
.tree-tool {
  border: 0;
  background: var(--bg);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.tree-tool:hover { color: var(--ink); }
.tree-row { display: flex; align-items: center; gap: 2px; min-width: 0; }
.tree-toggle {
  flex: 0 0 22px;
  width: 22px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 0;
  line-height: 1;
  cursor: pointer;
  transition: transform .15s ease;
}
.tree-toggle:hover { background: var(--bg); color: var(--ink); }
.tree-toggle.spacer { visibility: hidden; pointer-events: none; }
.node.is-collapsed > .tree-row .tree-toggle { transform: rotate(-90deg); }
.node.is-collapsed > .kids { display: none; }
.tree-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 7px 8px;
  font-weight: 600;
}
.tree-btn .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-btn:hover { background: var(--bg); }
.tree-btn.active { background: var(--soft); color: var(--red-dark); }
.tree-btn.deleted { opacity: .45; }
.tree-btn .ct { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.kids { margin-left: 10px; border-left: 1px solid #e8ecf0; padding-left: 4px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 12px; }
.card {
  position: relative;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid transparent;
  box-shadow: 0 1px 2px rgba(0, 26, 52, .04);
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card.selected { border-color: var(--red); }
.pic { display: block; width: 100%; border: 0; background: #eef1f4; padding: 0; aspect-ratio: 1; position: relative; }
.pic img { width: 100%; height: 100%; object-fit: contain; }
.nophoto { display: grid; place-items: center; height: 100%; color: var(--muted); font-weight: 700; }
.tick { position: absolute; top: 8px; left: 8px; z-index: 2; background: #fff; border-radius: 8px; width: 28px; height: 28px; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.tick input { width: 16px; height: 16px; accent-color: var(--red); }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badges.onpic { position: absolute; left: 8px; right: 8px; bottom: 8px; }
.badge { border-radius: 999px; padding: 3px 8px; font-size: 11px; font-weight: 700; background: #eef1f4; color: var(--ink); }
.badge.new, .badge.queued { background: var(--soft); color: var(--red-dark); }
.badge.ok, .badge.done, .badge.accepted { background: #e7f6ee; color: var(--green); }
.badge.bad, .badge.error, .badge.rejected { background: #ffe4e6; color: var(--red-dark); }
.badge.warn, .badge.processing { background: #fff4d6; color: var(--amber); }
.badge.info, .badge.cancelled, .badge.muted { background: #eef1f4; color: #475467; }
.card-body { padding: 10px 12px 12px; }
.card-body h3, .prompt-row h3, .empty h3 { margin: 0 0 4px; font-size: 14px; letter-spacing: -.01em; }
.card-body p, .dim { margin: 0; color: var(--muted); font-size: 12px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.row-actions a { text-decoration: none; display: inline-flex; align-items: center; }
.empty, .empty-inline, .empty-cell { color: var(--muted); padding: 24px; }
.actionbar {
  position: fixed;
  z-index: 24;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(920px, calc(100% - 24px));
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0, 26, 52, .18);
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px 10px 18px;
  flex-wrap: wrap;
}
.actionbar[hidden] { display: none; }
.statgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 14px; }
.statgrid article, .prompt-row, .version, .settings-card {
  background: #fff;
  border-radius: 16px;
  padding: 14px 16px;
}
.statgrid span { display: block; color: var(--muted); font-size: 13px; }
.statgrid strong { font-size: 22px; color: var(--ink); }
.table-wrap { overflow: auto; border-radius: 20px; }
.grid-table { width: 100%; border-collapse: collapse; background: #fff; }
.grid-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 12px; border-bottom: 1px solid var(--line); }
.grid-table td { padding: 10px 12px; border-bottom: 1px solid #f2f4f7; vertical-align: top; font-size: 14px; }
.thumbcell img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; background: #eef1f4; }
.err { color: var(--red-dark); font-size: 12px; margin-top: 4px; }
.nowrap { white-space: nowrap; }
.prompt-list, .stack, .split-view { display: grid; gap: 10px; }
.prompt-row { display: flex; justify-content: space-between; gap: 16px; text-decoration: none; align-items: center; }
.prompt-row.archived { opacity: .55; }
.prompt-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: 13px; justify-content: flex-end; }
.settings-card h2 { margin: 0 0 12px; font-size: 20px; color: var(--ink); }
.settings-card label, .login-card label { display: grid; gap: 6px; margin-bottom: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.prompt-references { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 14px 0; }
.prompt-references input[type="file"] { max-width: 100%; }
#reference-status { margin: 8px 0 0; }
#reference-error { margin: 8px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.reference-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; padding: 0; margin: 10px 0 0; list-style: none; }
.reference-grid:empty { margin: 0; }
.reference-grid li { display: grid; gap: 4px; min-width: 0; }
.reference-preview { display: grid; place-items: center; aspect-ratio: 1; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.reference-preview img { width: 100%; height: 100%; object-fit: contain; }
.reference-preview span { padding: 6px; text-align: center; font-size: 12px; color: var(--muted); }
#prompt-editor button:disabled, #reference-files:disabled { opacity: .55; cursor: not-allowed; }
.narrow { width: min(860px, 100%); }
.mono, .compile, .check-result { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; white-space: pre-wrap; }
.compile { background: #fff; border-radius: 16px; padding: 16px; min-height: 240px; margin: 0; }
.check-result {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  min-height: 0;
}
.check-result.ok { background: #e7f6ee; color: var(--green); }
.check-result.bad { background: #ffe4e6; color: var(--red-dark); }
.split-view { grid-template-columns: 1fr 1fr; align-items: start; }
.rej-table { display: grid; gap: 8px; }
.rej-item {
  position: relative;
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  background: #fff;
  border-radius: 14px;
  padding: 8px;
  border: 2px solid transparent;
  cursor: pointer;
}
.rej-item.selected { border-color: var(--red); }
.rej-item .tick { position: absolute; top: 8px; left: 8px; z-index: 1; }
.rej-item img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: #eef1f4; }
.rej-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.version { margin-top: 10px; }
.version header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.page { position: relative; }
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0, 26, 52, .46); display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.sheet { background: #fff; border-radius: 24px; padding: 22px; width: min(560px, 100%); max-height: min(88vh, 900px); overflow: auto; }
.sheet.wide { width: min(860px, 100%); }
.sheet h3 { margin: 0 0 8px; font-size: 22px; color: var(--ink); }
.sheet .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 10px; }
.chips button.on { background: var(--soft); border-color: #ffc7ca; color: var(--red-dark); }
.compare { position: relative; width: min(100%, 52vh); aspect-ratio: 1; margin-inline: auto; background: #eef1f4; border-radius: 16px; overflow: hidden; }
.compare img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.compare .before { position: absolute; inset: 0 auto 0 0; overflow: hidden; border-right: 2px solid #fff; }
.compare .before img { width: var(--frame, 100%); max-width: none; height: 100%; }
.lightbox { width: 100%; border-radius: 16px; background: #eef1f4; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: grid; gap: 8px; }
.toast { background: var(--ink); color: #fff; border-radius: 14px; padding: 12px 14px; max-width: 360px; box-shadow: var(--shadow); }
.toast.bad { background: var(--red-dark); }
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(420px, calc(100% - 32px)); padding: 28px; }
.login-card h1 { margin: 14px 0 6px; color: var(--ink); }
.form-error { color: var(--red-dark); font-weight: 600; }
.folder-list { display: grid; gap: 6px; margin-top: 10px; }
.folder-list button { text-align: left; border: 0; background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.export-list { display: grid; gap: 10px; margin-top: 12px; }
.export-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--bg); border-radius: 12px; }
.export-row-stack { display: grid; gap: 10px; align-items: stretch; }
.export-row-top { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.export-row strong { display: block; }
.export-row .dim { margin: 4px 0 0; }
.export-row .btn { flex-shrink: 0; }
.export-row .field { margin: 0; }
.export-row .field input { width: 100%; }
#export-go:disabled { opacity: .45; cursor: not-allowed; }
.mobile-page .table-wrap { display: none; }
.mobile-page .btn { min-height: 56px; height: auto; font-size: 18px; padding: 12px 16px; }
.mobile-page .statgrid { grid-template-columns: 1fr 1fr; }
.more { margin-top: 12px; }
.stage-plan { margin-block: 20px; }
.stage-plan h2 { font-size: 20px; margin: 0 0 10px; }
.stage-cards { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,290px),1fr)); gap: 12px; }
.stage-card { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; align-content: space-between; gap: 10px; }
.stage-card header { display: flex; align-items: center; gap: 8px; }
.stage-card h3 { margin: 0; font-size: 16px; }
.stage-number { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--soft); color: var(--red-dark); font-weight: 700; }
.stage-selection p { margin: 4px 0; color: var(--muted); }
.stage-selection small, .stage-pick small { color: var(--muted); }
.stage-option, .stage-selection, .stage-summary { overflow-wrap: anywhere; }
.stage-card [hidden] { display: none; }
.stage-options { display: grid; gap: 10px; margin-top: 12px; }
.stage-option { border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.stage-pick { border: 0; background: white; width: 100%; padding: 10px; border-radius: 8px; text-align: left; display: grid; gap: 4px; }
.stage-pick:hover, .stage-pick[aria-pressed=true], .pair-tabs .btn[aria-pressed=true] { background: var(--soft); color: var(--red-dark); }
.stage-option details { padding: 4px 10px; font-size: 13px; color: var(--muted); }
.stage-option summary { cursor: pointer; }
.stage-summary { padding-inline-start: 24px; }
.pair-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.stage-preview { display: grid; justify-items: start; font-size: 12px; color: var(--red-dark); }
.redo-reason { margin-top: 14px; }

@media (max-width: 960px) {
  .top-row, .tabs, main, .foot { width: min(100% - 20px, 1240px); }
  .search { order: 5; flex-basis: 100%; }
  .top-row { flex-wrap: wrap; padding: 10px 0; }
  .hero, .workspace, .split-view, .prompt-row, .statgrid { display: grid; grid-template-columns: 1fr; }
  .hero h2 { font-size: 32px; }
  .portal { display: none; }
  .tree { display: none; }
  body.tree-open .tree {
    display: block;
    position: fixed;
    z-index: 30;
    left: 10px;
    right: 10px;
    top: 124px;
    max-height: 70vh;
    overflow: auto;
  }
  .page-head h1 { font-size: 28px; }
  .tabs a { padding: 10px 8px 12px; }
}
