.admin-app {
  --bg: #f3f2ee; --panel: #fafaf8; --raised: #ffffff; --line: #d6d4cc;
  --text: #171717; --muted: #66665f; --accent: #b94f35; --ok: #3f7a3a; --off: #8a5a1f;
  color-scheme: light;
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  .admin-app {
    --bg: #141815; --panel: #1c211d; --raised: #252c26; --line: #374039;
    --text: #f0f2e9; --muted: #abb7aa; --accent: #dbfa82; --ok: #9fd68f; --off: #f0c27a;
    color-scheme: dark;
  }
}
.admin-app *, .admin-app *::before, .admin-app *::after { box-sizing: border-box; }
.admin-app [hidden] { display: none !important; }
.admin-app h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.02em; }
.admin-app h2 { margin: 0 0 .4rem; font-size: 1.15rem; }
.admin-app button { font: inherit; padding: .5rem .85rem; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); color: var(--text); cursor: pointer; }
.admin-app button:hover:not(:disabled) { border-color: var(--muted); }
.admin-app button:disabled { opacity: .55; cursor: default; }
.admin-app .primary { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 650; }
.admin-app :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.admin-app input[type="text"], .admin-app input[type="email"], .admin-app input[type="password"] {
  width: 100%; min-width: 0; font: inherit; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--raised); color: var(--text);
}
.admin-app label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
.admin-app label small, .admin-hint { color: var(--muted); font-weight: 400; font-size: .82rem; }
.admin-eyebrow { margin: 0 0 .3rem; color: var(--accent); letter-spacing: .14em; font: 650 .7rem/1.2 ui-monospace, monospace; }
.admin-status { min-height: 1.4em; color: var(--muted); }

.admin-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.admin-brand { display: inline-flex; align-items: center; gap: .6rem; color: inherit; text-decoration: none; font-weight: 750; white-space: nowrap; }
.admin-brand small { display: block; font: 600 .62rem/1.2 ui-monospace, monospace; color: var(--muted); letter-spacing: .12em; }
.admin-who { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.admin-who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .88rem; }

.admin-signin { width: min(100% - 32px, 420px); margin: 3rem auto; }
.admin-signin form { display: grid; gap: .8rem; margin-top: 1.2rem; }

.admin-console { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: calc(100vh - 58px); }
.admin-nav { display: flex; flex-direction: column; gap: .2rem; padding: 1rem .6rem; border-right: 1px solid var(--line); background: var(--panel); }
.admin-nav a { padding: .55rem .75rem; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 600; }
.admin-nav a:hover { background: var(--bg); }
.admin-nav a[aria-current="page"] { background: var(--raised); box-shadow: 0 1px 4px #0000001a; color: var(--accent); }
.admin-external { color: var(--muted); font-weight: 400; }
/* Scope rail (Pixolada team + shops), scope header, tabs and the Book catalogue's two views. */
.rail-label { margin: .8rem .6rem .2rem; color: var(--muted); font: 650 .66rem/1 ui-monospace, monospace; letter-spacing: .14em; }
.rail-label:first-child { margin-top: 0; }
.admin-nav a.rail-scope { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: .6rem; padding: .45rem .55rem; color: var(--text); }
.rail-text { display: grid; min-width: 0; }
.rail-text strong, .rail-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-text small { color: var(--muted); font: 400 .72rem/1.3 ui-monospace, monospace; }
.rail-state { color: var(--off); font-size: .72rem; font-weight: 650; }
.admin-nav a.rail-external { margin-top: .8rem; }
.scope-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--shop-accent, var(--line)); color: #171717; font-weight: 750; font-size: .85rem; }
.rail-team .scope-mark, .scope-mark[data-team="true"] { background: var(--text); color: var(--bg); }
.scope-head { display: flex; align-items: center; gap: .9rem; }
.scope-head .scope-mark { width: 44px; height: 44px; border-radius: 10px; font-size: 1.05rem; }
.scope-tabs { display: flex; gap: .2rem; margin: 1rem 0 1.2rem; border-bottom: 1px solid var(--line); overflow-x: auto; }
.scope-tabs a { flex: none; padding: .6rem .85rem; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; text-decoration: none; }
.scope-tabs a:hover { color: var(--text); }
.scope-tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.catalogue-views { display: flex; gap: .35rem; flex-wrap: wrap; margin: -.4rem 0 1rem; }
.catalogue-views a { padding: .3rem .75rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .86rem; font-weight: 600; text-decoration: none; }
.catalogue-views a[aria-current="page"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.admin-main { padding: 1.5rem clamp(16px, 4vw, 3rem); min-width: 0; }
.admin-section { max-width: 820px; }
.admin-section-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }

.shop-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.shop-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto auto; align-items: center; gap: .8rem; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--raised); }
.shop-logo { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 9px; overflow: hidden; background: var(--shop-accent, var(--line)); color: #171717; font-weight: 750; }
.shop-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.shop-text { display: grid; min-width: 0; }
.shop-text strong, .shop-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-text small { color: var(--muted); font: .78rem/1.3 ui-monospace, monospace; }
.shop-state { font-size: .8rem; font-weight: 650; color: var(--ok); }
.shop-state[data-enabled="false"] { color: var(--off); }

.admin-dialog { width: min(100% - 32px, 460px); padding: 1.3rem; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); }
.admin-dialog::backdrop { background: #0000005c; }
.admin-dialog form { display: grid; gap: .85rem; }
.admin-dialog p { margin: 0; }
.accent-row { display: flex; align-items: center; gap: .6rem; }
.accent-row input { width: 52px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); }
.accent-row output { font: .85rem ui-monospace, monospace; color: var(--muted); }
.admin-app .admin-check { display: flex; align-items: center; gap: .5rem; }
.logo-field { display: flex; align-items: center; gap: .8rem; }
.logo-field label { flex: 1; min-width: 0; }
.logo-field input[type="file"] { max-width: 100%; font-size: .85rem; }
.admin-dialog { max-height: calc(100vh - 32px); overflow: auto; }
.font-field { display: grid; gap: .35rem; justify-items: start; }
.font-field label { justify-self: stretch; }
.font-field input[type="file"] { max-width: 100%; font-size: .85rem; }
.branding { display: grid; gap: .7rem; margin: 0; padding: .8rem; border: 1px solid var(--line); border-radius: 10px; min-width: 0; }
.branding legend { padding: 0 .3rem; font-weight: 600; }
.branding-theme { display: grid; gap: .35rem; justify-items: start; }
.branding-custom { display: grid; gap: .6rem; }
.branding-preview { display: flex; align-items: center; justify-content: space-between; gap: .6rem; min-height: 58px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bp-bg, #fff); color: var(--bp-fg, #111); }
.bp-brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bp-brand img { height: var(--bp-logo, 30px); width: auto; max-width: 160px; object-fit: contain; }
.bp-brand b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bp-order { padding: 8px 16px; border-radius: 999px; font-weight: 700; background: var(--bp-btn, #111); color: var(--bp-btn-fg, #fff); }
#logo-preview { width: 56px; height: 56px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.admin-actions { display: flex; justify-content: flex-end; gap: .5rem; }

.admin-app select { font: inherit; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); color: var(--text); max-width: 100%; }
.admin-app .admin-inline { display: flex; align-items: center; gap: .5rem; }
.admin-link { color: var(--accent); font-weight: 600; align-self: center; margin-right: auto; }
.offer-form { display: grid; gap: .9rem; }
.tpl-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.tpl-row { padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--raised); }
.tpl-mod { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; align-items: center; gap: .8rem; }
.all-row { grid-template-columns: minmax(0, 1fr) auto auto; }
.tpl-pick { font-weight: 400; }
.tpl-groups { display: grid; gap: 1rem; }
.tpl-group { display: grid; gap: .5rem; }
.tpl-group h3 { margin: 0; font-size: .95rem; }
.admin-inline-group { display: flex; flex-wrap: wrap; gap: .6rem 1rem; }
.item-flags { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .9rem; }
.item-flags small { color: var(--muted); }
.tpl-pick small { color: var(--muted); }
.tpl-state { font-size: .8rem; font-weight: 650; color: var(--muted); }
.tpl-state[data-status="published"] { color: var(--ok); }
.tpl-state[data-status="withdrawn"] { color: var(--off); }
.tpl-dialog { width: min(100% - 32px, 760px); }
.tpl-dialog-body { display: grid; gap: .8rem; }
.tpl-preview { max-height: 60vh; overflow: auto; }
.tpl-page { width: 160px; height: auto; display: block; }
.tpl-wide { width: 288px; }
.tpl-paper { fill: #fff; stroke: #0003; }
.tpl-photo { fill: #0000000f; stroke: #0006; stroke-width: .4; stroke-dasharray: 1.4 1; }
.tpl-spread .tpl-photo { stroke-width: 1.5; stroke-dasharray: 6 4; }
.tpl-text { fill: #1717178c; }
.tpl-thing { fill: #8db3d666; stroke: #2e4d6b88; }
.tpl-theme { display: flex; flex-wrap: wrap; gap: 1rem; align-items: start; }
.tpl-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .25rem .8rem; margin: 0; font-size: .88rem; }
.tpl-facts dt { color: var(--muted); }
.tpl-facts dd { margin: 0; overflow-wrap: anywhere; }
.tpl-spreads { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .6rem; }
.tpl-spread { width: 100%; height: auto; border: 1px solid var(--line); background: #fff; }
.tpl-single { width: 200px; }
.tpl-sticker { width: 160px; height: 160px; }
.tpl-art { display: block; max-width: min(100%, 320px); max-height: 50vh; width: auto; height: auto; }
/* A row's 40 px thumbnail (admin.js `thumbFor`): the preview scaled into the box. */
.item-head { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.item-thumb { flex: none; display: grid; place-items: center; width: 40px; height: 40px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.item-thumb > svg, .item-thumb > img, .item-thumb .tpl-theme > svg, .item-thumb .tpl-spread {
  width: 38px; height: 38px; max-width: none; max-height: none; object-fit: contain; border: 0; }
.item-thumb .tpl-theme, .item-thumb .tpl-spreads { display: block; }
.item-thumb .tpl-facts, .item-thumb .tpl-spread ~ .tpl-spread { display: none; }

@media (max-width: 700px) {
  .tpl-mod, .all-row { grid-template-columns: minmax(0, 1fr) auto; }
  .tpl-mod .tpl-state { grid-column: 1; grid-row: 2; }
  .tpl-mod .item-flags { grid-column: 1 / -1; grid-row: 3; }
  .tpl-mod button { grid-column: 2; grid-row: 1 / span 2; }
  .admin-console { grid-template-columns: 1fr; }
  .admin-nav { flex-direction: row; flex-wrap: nowrap; align-items: center; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: .5rem 16px; }
  .rail-label { display: none; }
  .admin-nav a.rail-scope { flex: none; grid-template-columns: 26px auto auto; border: 1px solid var(--line); }
  .admin-nav a.rail-scope .scope-mark { width: 26px; height: 26px; font-size: .75rem; }
  .rail-text small { display: none; }
  .admin-nav a.rail-external { flex: none; margin-top: 0; }
  .shop-row { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .shop-state { grid-column: 2; grid-row: 2; }
  .shop-row button { grid-column: 3; grid-row: 1 / span 2; }
  .admin-section-head { align-items: start; }
}
.shop-row .admin-link { margin: 0; }
