:root {
  --bg: #f6f5f2;
  --card: #fff;
  --ink: #1c1c1e;
  --muted: #6e6e73;
  --line: #e2e0db;
  --accent: #1f5eff;
  --ok: #1d7a3a;
  --ok-bg: #e8f5ec;
  --err: #b42318;
  --err-bg: #fdecea;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, textarea[spellcheck="false"] { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
h1 { font-size: 26px; margin: 8px 0 18px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
h2 { font-size: 18px; margin: 28px 0 10px; }
h3 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

header.top {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px;
  background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 10;
}
header.top .brand { color: #fff; font-weight: 700; }
header.top nav { display: flex; gap: 4px; flex: 1; }
header.top nav a { color: #c7c7cc; padding: 6px 12px; border-radius: 6px; }
header.top nav a.on, header.top nav a:hover { color: #fff; background: #3a3a3c; text-decoration: none; }
header.top button.link { color: #c7c7cc; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 24px 60px; }
main.wide { max-width: none; }
main.narrow { max-width: 380px; padding-top: 12vh; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 16px; }
.card.inline, form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: 14px; }

input, select, textarea, button {
  font: inherit; color: inherit; border: 1px solid #cfccc5; border-radius: 7px; padding: 6px 9px; background: #fff;
}
textarea { width: 100%; resize: vertical; }
button { cursor: pointer; background: #f0eee9; }
button:hover { background: #e6e3dc; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #164bd1; }
button.link { background: none; border: 0; padding: 0 4px; color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--ink); font-size: 15px; }
label.check { flex-direction: row; align-items: center; gap: 6px; }

.login { display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0; }

.alert { padding: 10px 14px; border-radius: 8px; background: #eeeae2; margin: 0 0 14px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.err { background: var(--err-bg); color: var(--err); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.err-text { color: var(--err); margin: 4px 0 0; }
.warn-text { color: var(--warn); margin: 4px 0 0; }

.badge { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 99px; background: #eeeae2; color: #48484a; vertical-align: middle; }
.badge.warn, .badge.s-draft { background: var(--warn-bg); color: var(--warn); }
.badge.s-active { background: var(--ok-bg); color: var(--ok); }
.badge.s-archive { background: #e5e5ea; color: #8e8e93; }

table.grid { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.grid th, table.grid td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid th { font-size: 12px; font-weight: 600; color: var(--muted); background: #faf9f7; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr.off td { color: var(--muted); }
table.grid tr.bad td:first-child { color: var(--err); }
table.grid tr.ok td:first-child { color: var(--ok); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { font-size: 13px; color: var(--muted); }
.tile .value { font-size: 28px; font-weight: 650; margin: 4px 0; }
.tile.bad { border-color: var(--err); }
.tile.bad .value { color: var(--err); }
ul.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
ul.chips li { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 4px 0 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.asset-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: inherit; display: flex; flex-direction: column; }
.asset-card:hover { border-color: var(--accent); text-decoration: none; }
.asset-card.status-archive { opacity: .55; }
.asset-card .thumb { aspect-ratio: 1; background: #efede8; display: grid; place-items: center; }
.asset-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.asset-card .meta { padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.asset-card .meta b { font-size: 14px; word-break: break-all; }
.asset-card .meta .badge { align-self: flex-start; }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 12px; margin: 12px 0 14px; }
.fields .wide { grid-column: 1 / -1; }
.fields:not([data-subject="item"]) .only-item:not(.only-scene),
.fields:not([data-subject="common"]) .only-common,
.fields:not([data-subject="scene"]) .only-scene:not(.only-item),
.fields[data-subject="common"] .only-item.only-scene { display: none; }
.drop { border: 2px dashed #cfccc5; border-radius: var(--radius); padding: 18px; align-items: flex-start; }

.crumbs { margin: 0; font-size: 13px; color: var(--muted); }
.split { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .split, .editor-split { grid-template-columns: 1fr !important; } }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 7px 0 0 7px; }
.seg button:last-child { border-radius: 0 7px 7px 0; border-left: 0; }
.seg button.on, .tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.focus-editor {
  position: relative; display: inline-block; max-width: 100%; user-select: none; touch-action: none;
  background: repeating-conic-gradient(#e9e7e2 0 25%, #fff 0 50%) 0 0 / 16px 16px; border-radius: 6px; overflow: hidden;
}
.focus-editor[data-mode="focus"] { cursor: crosshair; }
.focus-editor[data-mode="zone"] { cursor: cell; }
.focus-editor img { display: block; max-width: 100%; max-height: 70vh; }
.focus-editor .zone { position: absolute; border: 2px solid #ff3b30; background: rgba(255, 59, 48, .12); pointer-events: none; }
.focus-editor .dot {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  border: 3px solid #fff; background: var(--accent); box-shadow: 0 0 0 1px rgba(0,0,0,.4); pointer-events: none;
}
.crops { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.crop { margin: 0; min-width: 0; }
.crop .frame { width: 100%; background: #ddd; border-radius: 4px; overflow: hidden; }
.crop .frame img { width: 100%; height: 100%; display: block; }
.crop.bad .frame { outline: 2px solid var(--err); }
.crop figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }

.editor-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 520px); gap: 20px; align-items: start; }
.editor { display: flex; flex-direction: column; gap: 10px; }
.editor textarea { min-height: 60vh; }
.cm-host { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.cm-host .cm-scroller { min-height: 60vh; max-height: 75vh; }
.tabs { display: flex; gap: 4px; }
.tabs button { border-radius: 7px 7px 0 0; }
.actions { display: flex; gap: 8px; }
.help pre { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; }
.preview-pane { position: sticky; top: 64px; }
.preview-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 10px; }
.preview-form details { flex-basis: 100%; }
.preview .slide-img, .slide-img { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.slides { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.slide { margin: 0; }
.slide figcaption { font-size: 12px; margin-top: 4px; }
.slide.bad { border: 2px solid var(--err); border-radius: 8px; padding: 6px; }
ul.versions { list-style: none; padding: 0; margin: 0; font-size: 13px; }
ul.versions a.on { font-weight: 700; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

.statusbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 0 0 16px; }
.statusbar a { padding: 6px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--ink); }
.statusbar a.on { border-color: var(--ink); background: var(--ink); color: #fff; }
.statusbar .push { margin-left: auto; }
.badge.st-ready { background: var(--ok-bg); color: var(--ok); }
.badge.st-missing_assets, .badge.st-error { background: var(--err-bg); color: var(--err); }
.badge.st-queued, .badge.st-rendering { background: #e6eeff; color: #1f4fbf; }
pre.card { overflow-x: auto; font-size: 13px; }
.badge.st-pending_approval { background: var(--warn-bg); color: var(--warn); }
.toolbar.sticky { position: sticky; top: 52px; z-index: 5; background: var(--bg); padding: 10px 0; flex-wrap: wrap; }
.toolbar .push { flex: 1; }
.change-row { padding: 12px 14px; }
.pairs { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; }
.pair { margin: 0; }
.pair-imgs { display: flex; gap: 6px; }
.pair-imgs > div { width: 210px; display: flex; flex-direction: column; gap: 4px; }
.pair-imgs .shot { aspect-ratio: 3 / 4; background: #efede8; border-radius: 6px; overflow: hidden; display: grid; place-items: center; }
.pair-imgs img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pair .tag { align-self: flex-start; font-size: 11px; background: #48484a; color: #fff; padding: 1px 8px; border-radius: 4px; }
.pair .tag.new { background: var(--accent); }
.pair figcaption { font-size: 12px; margin-top: 4px; }
