:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #9097a6;
  --accent: #4f8cff;
  --accent-2: #3a74e6;
  --danger: #ff5d5d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
[hidden] { display: none !important; }

/* ------------------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; gap: 18px; height: 52px; padding: 0 18px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex: none;
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }
.brand:hover { color: var(--text-strong); }
.logo {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, #4f8cff, #8b5cf6); font-size: 14px;
}
.app-name { font-weight: 600; color: var(--muted); border-left: 1px solid var(--line); padding-left: 18px; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 9px; }
.tab {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 6px 14px; border-radius: 7px; cursor: pointer;
}
.tab.active { background: var(--panel-2); color: var(--text); }
.topbar-note { margin-left: auto; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------ layout */
.workspace { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; min-width: 0; overflow-y: auto; padding: 22px; }
.panel {
  width: 300px; flex: none; overflow-y: auto; background: var(--panel);
  border-left: 1px solid var(--line); padding: 8px 16px 24px;
}
.group { padding: 14px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.group:last-child { border-bottom: 0; }
.group h2 { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 700; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.meta { margin: 0; color: var(--muted); font-size: 12px; }
.meta code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

.make-grid, .batch-grid { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(260px, 340px); gap: 26px; align-items: start; }
.form-col { display: flex; flex-direction: column; gap: 12px; }
.form-col h2 { margin: 0; font-size: 15px; }
.preview-col { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; }

/* ------------------------------------------------------------ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--line-strong); background: var(--hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; font-weight: 500; }
.btn.wide { width: 100%; }
select, .text, .num, textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
select, .text.wide, textarea { width: 100%; }
.num { width: 70px; }
textarea { min-height: 220px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.field.wide { width: 100%; }
.colour { width: 100%; height: 34px; padding: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.colour-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slider { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.slider span { display: flex; justify-content: space-between; color: var(--muted); }
.slider output { color: var(--text); font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ------------------------------------------------------------ make view */
.kinds { display: flex; flex-wrap: wrap; gap: 6px; }
.kind {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit;
  font-size: 12.5px; padding: 7px 11px; border-radius: 999px; cursor: pointer;
}
.kind.active { border-color: var(--accent); background: rgba(79, 140, 255, .18); }
.fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.fields .full { grid-column: 1 / -1; }
.fields .check { flex-direction: row; align-items: center; }
.fields input, .fields select, .fields textarea { width: 100%; }
.fields textarea { min-height: 90px; }
#contentPreview {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; white-space: pre-wrap;
  word-break: break-all; max-height: 120px; overflow: auto;
}
.qr-frame {
  display: grid; place-items: center; background:
    linear-gradient(45deg, var(--panel-3) 25%, transparent 25%, transparent 75%, var(--panel-3) 75%) 0 0/22px 22px,
    linear-gradient(45deg, var(--panel-3) 25%, transparent 25%, transparent 75%, var(--panel-3) 75%) 11px 11px/22px 22px,
    var(--well);
  border: 1px solid var(--line); border-radius: 14px; padding: 18px; min-height: 260px;
}
.qr-frame img { max-width: 100%; display: block; border-radius: 4px; }
.qr-frame img:not([src]) { visibility: hidden; }
.qr-frame.small { min-height: 170px; padding: 12px; }
.shapes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.shape {
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; font-size: 17px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 9px; padding: 7px 2px;
}
.shape span { font-size: 10.5px; font-weight: 600; color: var(--muted); }
.shape.active { border-color: var(--accent); background: rgba(79, 140, 255, .18); }
.shape.active span { color: var(--text); }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.preset {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit;
  font-size: 12px; padding: 6px 10px; border-radius: 999px; cursor: pointer;
}
.preset:hover { border-color: var(--accent); }

.history { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.history-item {
  display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; cursor: pointer; font-size: 12px;
}
.history-item:hover { border-color: var(--accent); }
.history-item img { width: 30px; height: 30px; border-radius: 4px; background: #fff; flex: none; }
.history-item .h-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ scan view */
.scan-wrap { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.dropzone {
  border: 2px dashed var(--line-strong); border-radius: 16px; min-height: 320px;
  display: grid; place-items: center; text-align: center; transition: border-color .15s, background .15s;
}
body.dragging .dropzone { border-color: var(--accent); background: rgba(79, 140, 255, .06); }
.drop-inner { padding: 24px; }
.drop-inner h1 { margin: 10px 0 6px; font-size: 21px; }
.drop-inner p { color: var(--muted); margin: 6px 0 16px; }
.drop-inner .hint { font-size: 12px; margin-top: 14px; }
.drop-icon {
  margin: 0 auto; width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  font-size: 24px; background: var(--panel-2); color: var(--accent);
}
.scan-results { display: flex; flex-direction: column; gap: 10px; }
.result {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.result .value { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; word-break: break-all; }
.result .row { gap: 8px; }
.result .row > * { flex: 0 0 auto; }

/* ------------------------------------------------------------ overlays */
.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 6;
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45); max-width: 80%;
}
.toast.error { border-color: var(--danger); color: var(--danger-text); }
.busy {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: rgba(15, 17, 21, .55); backdrop-filter: blur(2px); z-index: 7;
}
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .15); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .workspace { flex-direction: column; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
  .make-grid, .batch-grid { grid-template-columns: 1fr; }
  .topbar-note { display: none; }
}
