:root {
  color-scheme: dark;
  --bg: #0e0f12;
  --panel: #16181d;
  --line: #23272f;
  --text: #e8e9ed;
  --muted: #868c98;
  --ok: #3ecf8e;
  --warn: #e5b567;
  --bad: #e06c75;
  --info: #7aa2f7;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    14px / 1.5 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}

header.top {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
header.top .brand {
  font-weight: 700;
  letter-spacing: -0.01em;
}
header.top nav {
  display: flex;
  gap: 0.25rem;
}
header.top nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
}
header.top nav a:hover {
  color: var(--text);
  background: #1b1e24;
}
header.top nav a.active {
  color: var(--text);
  background: #1b1e24;
}
header.top .spacer {
  flex: 1;
}
header.top .meta {
  color: var(--muted);
  font-size: 0.8rem;
}

main {
  padding: 1.25rem 1.5rem 3rem;
  max-width: 1400px;
  margin: 0 auto;
}
h1 {
  font-size: 1.25rem;
  margin: 0 0 0.25rem;
  letter-spacing: -0.01em;
}
h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.8rem;
  font-weight: 600;
}
p.sub {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.1rem 1.2rem;
  margin-bottom: 1rem;
}

.row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}
.row.end {
  justify-content: flex-end;
}
.grow {
  flex: 1;
}
.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(12, 1fr);
}
.span-4 {
  grid-column: span 4;
}
.span-6 {
  grid-column: span 6;
}
.span-8 {
  grid-column: span 8;
}
.span-12 {
  grid-column: span 12;
}
@media (max-width: 1000px) {
  .span-4,
  .span-6,
  .span-8 {
    grid-column: span 12;
  }
}

label {
  color: var(--muted);
  font-size: 0.78rem;
  display: block;
  margin-bottom: 0.2rem;
}
input,
select,
textarea,
button {
  font: inherit;
  color: var(--text);
  background: #1c1f25;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}
textarea {
  min-height: 70px;
  resize: vertical;
}
input[type="color"] {
  padding: 0.15rem;
  width: 44px;
  height: 32px;
}
button {
  cursor: pointer;
}
button:hover {
  border-color: #3a404b;
}
button.primary {
  background: var(--ok);
  color: #0e0f12;
  border-color: transparent;
  font-weight: 600;
}
button.ghost {
  background: transparent;
}
button.danger {
  background: transparent;
  color: var(--bad);
  border-color: #5a2a30;
}
button.small {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  text-align: left;
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid var(--line);
}
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tr:last-child td {
  border-bottom: 0;
}

.muted {
  color: var(--muted);
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
}
.tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: #232833;
  color: var(--info);
}
.tag.warn {
  background: #3a2f1a;
  color: var(--warn);
}
.tag.ok {
  background: #16332a;
  color: var(--ok);
}
.tag.bad {
  background: #3a1d21;
  color: var(--bad);
}
.msg {
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.2em;
}
.msg.bad {
  color: var(--bad);
}

.issue {
  display: flex;
  gap: 0.6rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--line);
}
.issue:last-child {
  border-bottom: 0;
}
.sev {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  height: fit-content;
}
.sev.error {
  background: #3a1d21;
  color: var(--bad);
}
.sev.warning {
  background: #3a2f1a;
  color: var(--warn);
}

/* designer */
.designer {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 1000px) {
  .designer {
    grid-template-columns: 1fr;
  }
}
.stage-wrap {
  background: #0b0c0e;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  display: grid;
  place-items: center;
  min-height: 520px;
  overflow: auto;
}
.stage {
  position: relative;
  transform-origin: top left;
  box-shadow: 0 20px 60px #000a;
  overflow: hidden;
}
.stage .el {
  position: absolute;
  user-select: none;
}
.stage .el.selected {
  outline: 2px dashed var(--info);
  outline-offset: 2px;
}
.stage .el[data-type="text"] {
  display: flex;
  white-space: pre-wrap;
}
.stage .el[data-type="button"] {
  display: grid;
  place-items: center;
  font-weight: 700;
  cursor: default;
}
.stage .el[data-type="image"] {
  object-fit: cover;
}
.stage .el[data-type="qr"],
.stage .el[data-type="result"] {
  display: grid;
  place-items: center;
  border: 1px dashed #3a404b;
  color: var(--muted);
  font-size: 12px;
  background: #ffffff0a;
}
.panel .field {
  margin-bottom: 0.7rem;
}
.panel .field input[type="number"] {
  width: 100%;
}
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.element-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.8rem;
}
.element-list button {
  text-align: left;
  background: #1a1d23;
  border: 1px solid var(--line);
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  border-radius: 6px;
}
.element-list button.active {
  border-color: var(--info);
  color: var(--info);
}

/* role-based visibility (server still enforces every action) */
.role-client .internal-only {
  display: none;
}
.role-client a[data-page="templates"],
.role-client a[data-page="users"] {
  display: none;
}
.summary-line {
  margin: 0 0 0.4rem;
}
