:root {
  --bg: #f4f6f9; --panel: #fff; --text: #16181d; --muted: #5f6673; --line: #e4e7ec;
  --accent: #4f46e5; --accent-text: #fff; --ok: #047857; --warn: #b45309; --bad: #b91c1c;
  --chip: #eef0f4; --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05); --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1014; --panel: #161922; --text: #e7e9ee; --muted: #98a0ad; --line: #272c37;
    --accent: #818cf8; --accent-text: #0e1014; --ok: #34d399; --warn: #fbbf24; --bad: #f87171;
    --chip: #20242e; --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5); color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
code { font: 12px ui-monospace, Consolas, monospace; }
.muted { color: var(--muted); }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ── brand ─────────────────────────────────────────────────────────────────── */
.brand { display: flex; gap: 10px; align-items: center; padding: 16px; }
.brand b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.brand span:not(.logo) { display: block; font-size: 12px; color: var(--muted); }
.logo { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 17px; flex: none; }

/* ── sidebar ───────────────────────────────────────────────────────────────── */
#side { position: fixed; inset: 0 auto 0 0; width: 250px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 50; transition: transform .2s ease; }
#side-head { display: flex; align-items: center; justify-content: space-between; padding-right: 10px; }
#tabs { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; }
#tabs button { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 10px 12px; border: 0; border-radius: 8px; background: none; color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; text-align: left; transition: background .15s, color .15s; }
#tabs button svg { width: 18px; height: 18px; flex: none; }
#tabs button:hover { background: var(--chip); color: var(--text); }
#tabs button.on { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.side-foot .who { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ── topbar & content ──────────────────────────────────────────────────────── */
.shell { margin-left: 250px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: color-mix(in srgb, var(--bg) 82%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
#gsearch { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; max-width: 360px; margin-left: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; }
#gsearch svg { width: 15px; height: 15px; color: var(--muted); flex: none; }
#gsearch input { flex: 1; min-width: 0; border: 0; background: none; padding: 7px 0; }
#gsearch input:focus { outline: none; box-shadow: none; }
#gsearch:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
@media (max-width: 640px) { .topbar { flex-wrap: wrap; } #gsearch { order: 3; flex: 1 1 100%; max-width: none; } }

/* Live search results drop down under the topbar field as you type. */
#gsearch { position: relative; }
#gsresults { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); max-height: min(60vh, 480px); overflow: auto; z-index: 45; padding: 6px; }
.gsr-head { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px 4px; }
.gsr { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.gsr:hover { background: var(--chip); }
.gsr > span:first-child { min-width: 0; overflow: hidden; }
.gsr > span:first-child > b, .gsr > span:first-child > code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gsr-sub { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gsr-empty { padding: 10px; color: var(--muted); font-size: 13px; }
#gsresults .chip { flex: none; white-space: nowrap; }

/* Back navigation above detail pages */
.backlink { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 500; }
.backlink svg { width: 16px; height: 16px; }

/* Empty values ("nothing yet") read as placeholders, not as data */
.none { font-style: italic; opacity: .65; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
#view { width: 100%; max-width: 1200px; margin: 0 auto; padding: 20px 16px 56px; }
@media (min-width: 768px) { #view { padding: 24px 28px 64px; } }
#backdrop { position: fixed; inset: 0; background: rgba(10, 12, 18, .45); z-index: 40; }
#menu, #close-side { display: none; }
@media (max-width: 1023px) {
  #side { transform: translateX(-100%); }
  #side.open { transform: none; box-shadow: var(--shadow-lg); }
  .shell { margin-left: 0; }
  #menu, #close-side { display: inline-flex; align-items: center; justify-content: center; }
}
@media (min-width: 1024px) { #backdrop { display: none !important; } }

/* ── cards, grids ──────────────────────────────────────────────────────────── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow-sm); }
.card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.split { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.split > * { min-width: 0; }
.legacy-controls { grid-column: 1 / -1; border-block: 1px solid var(--line); padding-block: 12px; }
.legacy-controls summary, details.card > summary { cursor: pointer; font-weight: 600; }
.billing-record { padding-block: 10px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.billing-record p { margin: 0 0 6px; }
input[readonly] { color: var(--muted); background: var(--chip); }
@media (max-width: 860px) { .split { grid-template-columns: minmax(0, 1fr); } }
.scroll { overflow-x: auto; max-width: 100%; }
.stat { padding: 16px; position: relative; }
.stat b { display: block; font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; }
.stat .muted { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
a.card.stat { display: block; color: var(--text); text-decoration: none; transition: border-color .15s; }
a.card.stat:hover { border-color: var(--accent); }
.stat-ic { position: absolute; top: 14px; right: 14px; color: var(--muted); }
.stat-ic svg { width: 18px; height: 18px; }

/* Attention list rows on Overview */
.att { padding: 10px 0; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.att:last-child { border-bottom: 0; }

/* Loading skeleton while a view fetches */
.sk { height: 96px; border-radius: 12px; background: linear-gradient(90deg, var(--panel) 25%, var(--chip) 50%, var(--panel) 75%); background-size: 200% 100%; animation: sk-sweep 1.2s linear infinite, sk-show 0s .12s forwards; opacity: 0; }
.sk.tall { height: 220px; margin-top: 14px; }
@keyframes sk-sweep { to { background-position: -200% 0; } }
@keyframes sk-show { to { opacity: 1; } }

/* Bottom tab bar: primary navigation within thumb reach on phones */
#btabs { display: none; }
@media (max-width: 860px) {
  #btabs { display: flex; position: fixed; inset: auto 0 0 0; z-index: 35; background: var(--panel); border-top: 1px solid var(--line); padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); }
  #btabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-family: inherit; font-size: 10.5px; font-weight: 600; line-height: 1.2; cursor: pointer; }
  #btabs button svg { width: 20px; height: 20px; }
  #btabs button.on { color: var(--accent); }
  .shell { padding-bottom: 76px; }
  #toast { bottom: 84px; }
}

/* ── tables ────────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
td.wrap { white-space: normal; }
th { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: color-mix(in srgb, var(--chip) 60%, transparent); }

/* Below 680px a wide table becomes a stack of labeled cards instead of sideways scrolling. */
@media (max-width: 860px) {
  table.rtable, table.rtable tbody, table.rtable tr, table.rtable td { display: block; width: 100%; }
  table.rtable thead { display: none; }
  table.rtable tr { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; background: var(--panel); box-shadow: var(--shadow-sm); }
  table.rtable tr:hover td { background: transparent; }
  table.rtable td { border: 0; padding: 5px 0; white-space: normal; }
  table.rtable td::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  table.rtable td[data-label=""]::before { content: none; }
}

/* History: a compact "what · who · when" list on phones, full table on desktop. */
.evlist { display: none; }
@media (max-width: 860px) {
  .evlist { display: block; }
  .ev { padding: 9px 0; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
  .ev:last-child { border-bottom: 0; }
  .ev-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13.5px; }
  .ev-top .muted { flex: none; font-size: 12px; }
  .ev-sub { font-size: 12px; overflow-wrap: anywhere; }
}

/* Mobile action cards: minimal identity always visible, details expand on demand, and the
   licence actions are one tap away without opening anything. */
.mcards { display: none; }
@media (max-width: 860px) {
  .hide-mobile { display: none !important; }
  .mcards { display: grid; gap: 10px; margin-bottom: 14px; }
  .mcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-sm); }
  .mcard summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; cursor: pointer; list-style: none; }
  .mcard summary::-webkit-details-marker { display: none; }
  .mcard summary .chev { width: 16px; height: 16px; color: var(--muted); flex: none; transition: transform .15s; }
  .mcard details[open] summary .chev { transform: rotate(180deg); }
  .mcard summary .m-id { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; overflow-wrap: anywhere; }
  .mcard-body { padding: 0 14px 12px; display: grid; gap: 7px; font-size: 13.5px; }
  .mcard-body .kv { display: grid; gap: 1px; }
  .mcard-body .kv > span:first-child { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .mcard-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--line); }
  .mcard-actions .btn.small { min-height: 40px; padding: 6px 14px; font-size: 13px; }
}

/* ── forms ─────────────────────────────────────────────────────────────────── */
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
textarea { width: 100%; min-height: 64px; }
label { display: grid; gap: 4px; font-size: 12px; font-weight: 500; color: var(--muted); }
label > input, label > select { color: var(--text); }
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
@media (max-width: 640px) { input, select, textarea { font-size: 16px; } }

/* Sectioned forms (the code editor): sub-cards in a 2-column grid, fields stacking inside,
   paired fields side by side, hints below inputs. */
.fsecs { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
@media (max-width: 900px) { .fsecs { grid-template-columns: minmax(0, 1fr); } }
.fsec { display: flex; flex-direction: column; gap: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.fsec h4 { margin: 0; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.fpair { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
@media (max-width: 480px) { .fpair { grid-template-columns: minmax(0, 1fr); } }
.fsec label input, .fsec label select { width: 100%; }
.hint { font-size: 11px; font-weight: 400; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ── buttons & chips ───────────────────────────────────────────────────────── */
.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 7px 14px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; transition: background .15s, border-color .15s, filter .15s; }
.btn svg { width: 16px; height: 16px; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small.icon { padding: 8px; }

.chip { display: inline-block; padding: 1px 9px; border-radius: 99px; background: var(--chip); font-size: 12px; font-weight: 500; }
.chip.publisher { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.chip.creator { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.chip.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.chip.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }

#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; max-width: calc(100% - 32px); z-index: 60; font-weight: 500; box-shadow: var(--shadow-lg); }
#toast.error { background: var(--bad); color: #fff; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
