/* INVIV Admin — dark ink cards with thin gold edges, pixel headings. */
@font-face {
  font-family: "INVIV Pixel";
  src: url("/admin/fonts/InvivPixel-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Be Vietnam Pro";
  src: url("/admin/fonts/BeVietnamPro-500.ttf") format("truetype");
  font-weight: 400 500;
  font-display: swap;
}
@font-face {
  font-family: "Be Vietnam Pro";
  src: url("/admin/fonts/BeVietnamPro-600.ttf") format("truetype");
  font-weight: 600 800;
  font-display: swap;
}

:root {
  --bg: #0b1020;
  --ink: #121827;
  --ink-2: #20283a;
  --ink-3: #2a3449;
  --line: #34405a;
  --edge: rgba(243, 184, 63, 0.55);
  --gold: #f3b83f;
  --gold-hi: #ffd86a;
  --text: #eef1f7;
  --muted: #a9b3c7;
  --danger: #ff8080;
  --danger-bg: #4a1d24;
  --ok: #6fdc98;
  --ok-bg: #173a29;
  --warn: #ffd86a;
  --warn-bg: #43361a;
  --android: #1fa2b4;
  --ios: #8f7ff5;
  --other: #c08a20;
  --chart-a: #f3b83f;
  --chart-b: #1fa2b4;
  --radius: 6px;
  --nav-w: 232px;
  --top-h: 56px;
  --tab-h: 64px;
  --pixel: "INVIV Pixel", ui-monospace, monospace;
  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 500 15px/1.5 var(--sans);
}
[hidden] { display: none !important; }
img.px { image-rendering: pixelated; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--ink-2); padding: 1px 5px; border-radius: 4px; }
a { color: var(--gold-hi); }
h1, h2, h3 { margin: 0; font-weight: 400; }
.pixel { font-family: var(--pixel); color: var(--gold-hi); letter-spacing: 0.5px; line-height: 1.05; }
h1.pixel { font-size: 40px; }
h2.pixel { font-size: 32px; }
h3.pixel { font-size: 24px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--gold); color: #121827; padding: 8px 12px; border-radius: 4px; font-weight: 600; }
.skip:focus { top: 8px; }
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.noscript { padding: 24px; text-align: center; }

/* --- cards, buttons, fields ------------------------------------------- */
.card {
  background: var(--ink);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px #070a12, 0 6px 18px rgba(0, 0, 0, 0.25);
  padding: 16px;
  min-width: 0;
}
.card--flat { background: var(--ink-2); border-color: var(--line); box-shadow: none; }
.card__title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.card__title h3 { flex: 1 1 auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  font: 600 14px/1 var(--sans);
  color: var(--text); background: var(--ink-2);
  border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
.btn:hover { background: var(--ink-3); border-color: var(--gold); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--gold); color: #121827; border-color: #b7832a; box-shadow: inset 0 -3px 0 #c98d26; }
.btn--primary:hover { background: var(--gold-hi); border-color: var(--gold-hi); }
.btn--danger { background: var(--danger-bg); color: #ffd6d6; border-color: #a8434f; }
.btn--danger:hover { background: #6a2530; border-color: var(--danger); }
.btn--ghost { background: transparent; }
.btn--sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn--icon { width: 40px; padding: 0; font-size: 16px; }
.btn--block { width: 100%; }
.btn--link {
  background: none; border: 0; padding: 0; min-height: 0; color: var(--text);
  font: 600 14px/1.3 var(--sans); text-align: left; white-space: normal; cursor: pointer;
}
.btn--link:hover { color: var(--gold-hi); text-decoration: underline; background: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field--grow { flex: 1 1 220px; }
.field__label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field__hint { font-size: 12px; color: var(--muted); }
.field__error { margin: 0; font-size: 13px; color: var(--danger); }
.field--invalid input, .field--invalid textarea { border-color: var(--danger); }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  font: 500 15px/1.4 var(--sans); color: var(--text);
  background: #0d1322; border: 1px solid var(--line); border-radius: var(--radius);
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 2px rgba(243, 184, 63, 0.3); }
.field--invalid input:focus, .field--invalid textarea:focus { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(255, 128, 128, 0.35); }
input[type="range"] { padding: 0; min-height: 28px; background: none; border: 0; accent-color: var(--gold); box-shadow: none; }
input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(0.85); }
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--gold) 50%), linear-gradient(135deg, var(--gold) 50%, transparent 50%); background-position: right 16px top 18px, right 11px top 18px; background-size: 5px 5px; background-repeat: no-repeat; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.5;
  background: var(--ink-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.badge--ok { background: var(--ok-bg); color: var(--ok); border-color: #2c6b48; }
.badge--warn { background: var(--warn-bg); color: var(--warn); border-color: #7d6427; }
.badge--danger { background: var(--danger-bg); color: #ffc2c2; border-color: #a8434f; }
.badge--gold { background: rgba(243, 184, 63, 0.12); color: var(--gold-hi); border-color: var(--edge); }
.dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }

/* --- login ---------------------------------------------------------------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(ellipse at top, #1b2440 0%, var(--bg) 60%); }
.login__card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px 24px; text-align: left; }
.login__logo { width: 264px; height: 93px; align-self: center; }
.login__card h1 { text-align: center; }
.login__card p { margin: 0; font-size: 14px; }

/* --- shell ---------------------------------------------------------------- */
.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--top-h); display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: rgba(11, 16, 32, 0.92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--edge);
}
.topbar__brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.topbar__brand img { width: 50px; height: 32px; }
.topbar__brand .pixel { font-size: 26px; }
.topbar__spacer { flex: 1; }

.nav {
  position: fixed; z-index: 15; left: 0; top: var(--top-h); bottom: 0; width: var(--nav-w);
  display: flex; flex-direction: column; gap: 4px; padding: 16px 12px;
  background: var(--ink); border-right: 1px solid var(--edge);
}
.nav__item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius);
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px;
  border: 1px solid transparent;
}
.nav__item svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav__item:hover { color: var(--text); background: var(--ink-2); }
.nav__item[aria-current="page"] { color: var(--gold-hi); background: rgba(243, 184, 63, 0.1); border-color: var(--edge); }
.nav__short { display: none; }

.main { margin-left: var(--nav-w); padding: 24px 32px 48px; max-width: calc(1200px + var(--nav-w)); outline: none; }
.view { display: flex; flex-direction: column; gap: 16px; }
.view__head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.view__head h2 { margin-right: auto; }

/* --- overview --------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; }
.tile__label { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile__value { font-family: var(--pixel); font-size: clamp(28px, 0.9vw + 22px, 38px); line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile__sub { font-size: 12px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: #2a3449; stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font: 500 11px var(--sans); }
.chart .value-label { fill: var(--text); font: 600 12px var(--sans); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:focus { outline: none; }
.chart .col.is-active .bar { filter: brightness(1.25); }
.chart .col.is-active .hit { fill: rgba(255, 255, 255, 0.05); }
.chart-tip {
  position: fixed; z-index: 60; pointer-events: none;
  padding: 6px 10px; border-radius: 4px; font-size: 13px; line-height: 1.35;
  background: #0d1322; color: var(--text); border: 1px solid var(--edge);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); white-space: nowrap;
}
.chart-tip strong { color: var(--gold-hi); }
details.data-table { margin-top: 8px; font-size: 13px; }
details.data-table summary { cursor: pointer; color: var(--muted); }
.split { display: flex; height: 18px; border-radius: 4px; overflow: hidden; gap: 2px; background: var(--ink); }
.split > span { display: block; min-width: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 12px; font-size: 14px; }
.legend > span { display: inline-flex; align-items: center; gap: 8px; }

/* --- tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--edge); border-radius: var(--radius); background: var(--ink); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #222b3e; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; background: #161d2e; position: sticky; top: 0; white-space: nowrap; }
th.sortable button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th.sortable button:focus-visible { outline: 2px solid var(--gold-hi); }
th[aria-sort] { color: var(--gold-hi); }
td.num, th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.row-click { cursor: pointer; }
tbody tr.row-click:hover td { background: #182036; }
.rank { font-family: var(--pixel); font-size: 22px; color: var(--gold-hi); }
.rank--1 { color: #ffd86a; } .rank--2 { color: #d6dbe6; } .rank--3 { color: #e0a36a; }
.sign-text { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

/* --- tabs ----------------------------------------------------------------- */
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--ink); border: 1px solid var(--edge); border-radius: var(--radius); align-self: flex-start; }
.tab { all: unset; cursor: pointer; padding: 8px 14px; border-radius: 4px; font-weight: 600; font-size: 14px; color: var(--muted); }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--gold); color: #121827; }
.tab:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }

/* --- events editor -------------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.event { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.event__head { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.event__head .mono { color: var(--muted); }
.event__head .spacer { flex: 1; }
.event .full { grid-column: 1 / -1; }
.slider { display: flex; align-items: center; gap: 12px; }
.slider output { font-family: var(--pixel); font-size: 24px; color: var(--gold-hi); min-width: 52px; text-align: right; }
.templates { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.save-bar {
  position: sticky; bottom: 12px; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; background: rgba(18, 24, 39, 0.96); border: 1px solid var(--edge); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.save-bar .spacer { flex: 1; }
.alert { padding: 10px 14px; border-radius: var(--radius); border: 1px solid #a8434f; background: var(--danger-bg); color: #ffd6d6; font-size: 14px; }
.alert--info { border-color: var(--line); background: var(--ink-2); color: var(--text); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-family: var(--mono); font-size: 12px; padding: 2px 8px; border-radius: 4px; background: var(--ink-2); border: 1px solid var(--line); }

/* --- billboard ------------------------------------------------------------ */
.sign-preview {
  display: inline-flex; flex-direction: column; gap: 2px; align-items: center;
  padding: 10px 18px; min-width: 220px; max-width: 100%;
  background: #f3dfb5; color: #202334; border: 3px solid #121827; border-radius: 3px;
  box-shadow: 0 0 0 2px #f3b83f, 0 4px 0 2px #8a5a1c;
  font-family: var(--pixel); font-size: 24px; line-height: 1.05; text-align: center; overflow-wrap: anywhere;
}
.sign-preview small { font-size: 16px; color: #6b5a3a; }
.sign-stage { display: flex; justify-content: center; padding: 24px 12px; background: repeating-linear-gradient(0deg, #1b2a24 0 8px, #1f3029 8px 16px); border-radius: var(--radius); border: 1px solid var(--line); }

/* --- system --------------------------------------------------------------- */
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
pre.code {
  margin: 0; padding: 12px; overflow-x: auto; font: 13px/1.5 var(--mono);
  background: #0d1322; border: 1px solid var(--line); border-radius: var(--radius); color: #d7deea;
}
.code-block { position: relative; }
.code-block .btn { position: absolute; top: 6px; right: 6px; }

/* --- drawer + modal --------------------------------------------------------- */
dialog { color: var(--text); padding: 0; border: 0; }
dialog::backdrop { background: rgba(4, 7, 14, 0.7); }
.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(560px, 100vw); max-width: 100vw;
  background: var(--bg); border-left: 1px solid var(--edge); display: none; flex-direction: column;
}
.drawer[open] { display: flex; animation: slide-in 0.18s ease-out; }
.drawer__head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--edge); background: var(--ink); }
.drawer__head h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer__body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.modal {
  width: min(440px, calc(100vw - 32px)); padding: 20px; border-radius: var(--radius);
  background: var(--ink); border: 1px solid var(--edge); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.modal[open] { display: flex; flex-direction: column; gap: 12px; }
.modal p { margin: 0; color: var(--muted); }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.mini-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mini-tiles .tile { padding: 10px 12px; background: var(--ink); border: 1px solid var(--edge); border-radius: var(--radius); }
.mini-tiles .tile__value { font-size: 30px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #222b3e; font-size: 14px; }
.list li:last-child { border-bottom: 0; }

/* --- toasts, skeletons, empty ---------------------------------------------- */
.toasts { position: fixed; z-index: 80; inset: auto 16px 16px auto; margin: 0; padding: 0; border: 0; background: transparent; overflow: visible; color: inherit; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius); font-size: 14px;
  background: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--ok);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45); animation: toast-in 0.18s ease-out;
}
.toast--error { border-left-color: var(--danger); }
.toast--info { border-left-color: var(--gold); }
.toast__icon { font-weight: 700; }
.toast--success .toast__icon { color: var(--ok); }
.toast--error .toast__icon { color: var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.skeleton { position: relative; overflow: hidden; background: var(--ink-2); border-radius: 4px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  transform: translateX(-100%); animation: shimmer 1.2s infinite;
}
.skeleton--tile { height: 92px; }
.skeleton--line { height: 16px; margin: 10px 0; }
.skeleton--block { height: 200px; }
@keyframes shimmer { to { transform: translateX(100%); } }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty .pixel { font-size: 26px; }

/* Inbox + party/boss views */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--gold); }
input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(0.85); }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.hpbar { position: relative; height: 14px; border-radius: 4px; overflow: hidden; background: var(--ink); border: 1px solid var(--line); }
.hpbar > span { display: block; height: 100%; background: var(--danger); transition: width 0.3s ease; }
.hpbar--low > span { background: var(--gold); }
.raid { display: flex; flex-direction: column; gap: 8px; }
.raid__head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.raid__head h4 { margin: 0; flex: 1 1 auto; font-size: 15px; }
.online-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: middle; }
.online-dot--on { background: var(--ok); }
.mail-body { white-space: pre-line; overflow-wrap: anywhere; }

/* --- live content (content.js) ------------------------------------------ */
.view__meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack-xs { display: flex; flex-direction: column; gap: 6px; }
.checker {
  background-color: #1a2133;
  background-image: linear-gradient(45deg, #222b40 25%, transparent 25%, transparent 75%, #222b40 75%), linear-gradient(45deg, #222b40 25%, transparent 25%, transparent 75%, #222b40 75%);
  background-size: 12px 12px; background-position: 0 0, 6px 6px;
}
.thumb-ph { display: grid; place-items: center; width: 100%; height: 100%; font-family: var(--pixel); font-size: 28px; color: var(--muted); }
.tabs--scroll { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs--scroll::-webkit-scrollbar { display: none; }
a.badge { text-decoration: none; }
a.badge:hover { filter: brightness(1.15); }
.tabs--scroll .tab { white-space: nowrap; }
.alert--ok { border-color: #2c6b48; background: var(--ok-bg); color: var(--text); }
.alert--warn { border-color: var(--gold, #f3b83f); background: rgba(243, 184, 63, 0.1); color: var(--text); }
.alert .chips { margin-top: 6px; align-items: center; }
.errlist { margin: 6px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; overflow-wrap: anywhere; }
a.chip { color: var(--gold-hi); text-decoration: none; }
a.chip:hover { border-color: var(--gold); }
.is-busy::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* library grid */
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.cgrid__empty { grid-column: 1 / -1; }
.skeleton--card { height: 210px; }
.ccard {
  all: unset; box-sizing: border-box; cursor: pointer; min-width: 0;
  display: flex; flex-direction: column; gap: 4px; padding: 10px;
  background: var(--ink); border: 1px solid var(--edge); border-radius: var(--radius);
  box-shadow: 0 0 0 1px #070a12; transition: border-color 0.12s, transform 0.06s, background 0.12s;
}
.ccard:hover { border-color: var(--gold-hi); background: #161d2e; }
.ccard:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.ccard:active { transform: translateY(1px); }
.ccard--dim { opacity: 0.6; }
.ccard__thumb { display: grid; place-items: center; height: 96px; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.ccard__thumb img { width: 64px; height: 64px; object-fit: contain; image-rendering: pixelated; }
.ccard__thumb--big img { width: 92px; height: 92px; }
.ccard__name { font-weight: 600; font-size: 14px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ccard__id { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ccard__meta { line-height: 1.35; min-height: 2.7em; font-size: 12px; }
.ccard__chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: auto; }
.detail-thumb { display: grid; place-items: center; height: 200px; border-radius: var(--radius); border: 1px solid var(--edge); }
.detail-thumb img { width: 160px; height: 160px; object-fit: contain; image-rendering: pixelated; }

/* zip drop zone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 20px 16px; border: 2px dashed var(--line); border-radius: var(--radius); cursor: pointer;
  background: #0f1525; transition: border-color 0.12s, background 0.12s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--gold); background: rgba(243, 184, 63, 0.06); }
.dropzone.is-busy { opacity: 0.7; pointer-events: none; }
.dropzone__icon { font-size: 28px; color: var(--gold-hi); line-height: 1; }
.dropzone code { overflow-wrap: anywhere; }

/* editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: 16px; align-items: start; }
.editor__side { position: sticky; top: calc(var(--top-h) + 12px); }
.form-grid__sep { margin: 4px 0 -4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.frames-drop { display: flex; flex-direction: column; gap: 10px; border-radius: var(--radius); }
.frames-drop.is-over { outline: 2px dashed var(--gold); outline-offset: 4px; }
.frames-drop p { margin: 0; }
.frames { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.frames--big { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.fslot { display: flex; flex-direction: column; gap: 4px; padding: 8px; background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.fslot.is-over { border-color: var(--gold); }
.fslot--pending { border-color: #7d6427; }
.fslot--missing { border-style: dashed; }
.fslot__img { display: grid; place-items: center; height: 72px; border-radius: 4px; overflow: hidden; }
.frames--big .fslot__img { height: 96px; }
.fslot__img img { width: 64px; height: 64px; object-fit: contain; image-rendering: pixelated; }
.frames--big .fslot__img img { width: 96px; height: 96px; }
.fslot__none { font-size: 28px; color: var(--line); }
.fslot__name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fslot__state { color: var(--muted); }
.fslot--ok .fslot__state { color: var(--ok); }
.fslot--pending .fslot__state { color: var(--warn); }
.fslot__actions { display: flex; gap: 4px; }
.fslot__actions .btn { flex: 1; padding: 0 8px; }
.fslot__actions .btn--ghost { flex: none; }
.stage-wrap { width: 100%; max-width: 480px; margin: 0 auto; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--edge); background: #4f8a3a; line-height: 0; }
canvas.stage { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.card__title select { width: auto; min-height: 32px; padding: 4px 30px 4px 10px; font-size: 13px; background-position: right 14px top 14px, right 9px top 14px; }

/* AI studio */
.ai textarea { min-height: 72px; }
.ai-compare { display: flex; align-items: center; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ai-compare figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ai-canvas { display: block; max-width: 150px; height: auto; border: 1px solid var(--line); border-radius: 4px; image-rendering: pixelated; }
.ai-arrow { font-size: 22px; color: var(--gold-hi); }
.slider--sm output { font-family: var(--sans); font-size: 13px; min-width: 40px; color: var(--text); }

/* store + bots */
.input-sm { min-height: 34px; padding: 4px 8px; font-size: 14px; }
select.input-sm { padding-right: 28px; background-position: right 14px top 14px, right 9px top 14px; }
.table-edit td input[type="number"] { width: 96px; }
.table-edit td select { width: 112px; }
.table-edit tr.is-changed td { background: rgba(243, 184, 63, 0.06); }
.table-edit tr.is-changed td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
tr.is-focus td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: rgba(243, 184, 63, 0.3); } }
.store-item { display: flex; align-items: center; gap: 10px; min-width: 0; }
.store-item > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.store-item .badge { margin-left: 6px; }
.store-thumb { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.store-thumb img { width: 36px; height: 36px; object-fit: contain; image-rendering: pixelated; }
.store-thumb .thumb-ph { font-size: 18px; }
.bot-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 12px; }
.bot-card { display: flex; flex-direction: column; gap: 12px; }
.bot-card.is-changed { border-color: var(--gold-hi); }
.bot-card.is-focus { animation: flash 1.6s ease-out; }
.bot-card__head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.bot-card__title { display: flex; flex-direction: column; gap: 2px; flex: 1 1 140px; min-width: 0; }
.bot-thumb { flex: none; width: 64px; height: 64px; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); display: grid; place-items: center; }
.bot-thumb img { width: 64px; height: 64px; image-rendering: pixelated; }
.bot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* --- responsive --------------------------------------------------------------- */
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .editor { grid-template-columns: minmax(0, 1fr); }
  .editor__side { position: static; order: -1; }
}
@media (max-width: 860px) {
  :root { --top-h: 52px; }
  .main { margin-left: 0; padding: 16px 16px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); }
  .nav {
    top: auto; right: 0; width: auto; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
    flex-direction: row; gap: 0; padding: 4px 4px env(safe-area-inset-bottom);
    border-right: 0; border-top: 1px solid var(--edge);
  }
  .nav { overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
  .nav::-webkit-scrollbar { display: none; }
  .nav__item { flex: 1 0 64px; min-width: 64px; scroll-snap-align: start; flex-direction: column; gap: 2px; padding: 6px 0; font-size: 10px; letter-spacing: -0.1px; justify-content: center; text-align: center; }
  .nav__item > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav__long { display: none; }
  .nav__short { display: inline; }
  .toasts { inset: auto 16px calc(var(--tab-h) + 12px) 16px; width: auto; }
  .save-bar { bottom: calc(var(--tab-h) + 8px); }
  h2.pixel { font-size: 28px; }
  .event { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  /* Tables become compact two-column cards. */
  .table-wrap.stack-sm { border: 0; background: none; overflow: visible; }
  .stack-sm table, .stack-sm tbody { display: block; width: 100%; }
  .stack-sm thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .stack-sm tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px;
    background: var(--ink); border: 1px solid var(--edge); border-radius: var(--radius);
    margin-bottom: 8px; padding: 12px;
  }
  .stack-sm tbody tr.row-click:hover td { background: none; }
  .stack-sm tbody tr.row-click:hover { border-color: var(--gold); }
  .stack-sm td { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 0; border: 0; text-align: left; min-width: 0; }
  .stack-sm td.num { text-align: left; }
  .stack-sm td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
  .stack-sm td.cell-main { grid-column: 1 / -1; font-size: 15px; }
  .stack-sm td.cell-main::before { content: none; }
  .stack-sm td.cell-wide { grid-column: 1 / -1; }
  .stack-sm td.cell-action { grid-column: 1 / -1; align-items: stretch; }
  .stack-sm td.cell-action::before { content: none; }
  .sign-text { max-width: 100%; }
  .save-bar { padding: 8px 12px; }
  .save-bar .save-bar__hint { display: none; }
}
@media (max-width: 480px) {
  .topbar__brand .pixel { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .mini-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 14px 12px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .modal__actions { flex-direction: column-reverse; }
  .modal__actions .btn { width: 100%; }
  .tabs { align-self: stretch; }
  .tab { flex: 1; text-align: center; }
  .tabs--scroll .tab { flex: none; }
  .cgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .ccard__thumb { height: 84px; }
  .ccard__thumb--big img { width: 80px; height: 80px; }
  .frames { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-edit td input[type="number"], .table-edit td select { width: 100%; }
}
@media (max-width: 640px) {
  .stack-sm .table-edit tr.is-changed { border-color: var(--gold-hi); }
  .stack-sm .table-edit tr.is-changed td { background: none; box-shadow: none; }
  .stack-sm tr.is-focus td { animation: none; }
  .stack-sm tr.is-focus { animation: flash 1.6s ease-out; }
}

input[type="color"] { width: 100%; height: 36px; padding: 2px; border-radius: 8px; border: 1px solid var(--line); background: var(--ink-2); cursor: pointer; }

.pl-meter { width: 100%; height: 10px; accent-color: var(--gold, #f3b83f); }
/* Email: campaign preview (mirrors the mail layout in src/mailTemplates.js) */
.mail-preview { background: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.mail-preview__brand { font-weight: 800; font-size: 20px; line-height: 1; color: var(--gold); margin: 0 4px 10px; }
.mail-preview__brand span { color: var(--text); }
.mail-preview__card { background: var(--ink-2); border: 2px solid var(--gold); border-radius: 14px; padding: 16px; overflow-wrap: anywhere; }
.mail-preview__card h4 { margin: 0 0 10px; color: var(--gold); font-size: 18px; line-height: 1.3; }
.mail-preview__card p { margin: 0 0 10px; line-height: 1.6; }
.mail-preview__card a { color: var(--gold-hi); }
.mail-preview__foot { margin-top: 10px; font-size: 12px; color: var(--muted); text-align: center; }
