:root {
  --bg: #f4f6fb;
  --bg-stage: #eef1f8;
  --card: #ffffff;
  --ink: #1f2533;
  --ink-soft: #5b6478;
  --muted: #8a92a6;
  --line: #e6e9f2;
  --accent: #5b7cfa;
  --accent-soft: #eaeffd;
  --accent-ink: #2f49b8;
  --free: #2fae73;
  --free-soft: #e6f7ee;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 28, 56, .06), 0 2px 8px rgba(20, 28, 56, .05);
  --shadow-md: 0 10px 30px rgba(20, 28, 56, .10);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, .brand-text strong { font-family: "Poppins", "Inter", sans-serif; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--accent); }
.brand-mark { display: grid; place-items: center; }
.brand-text { display: flex; flex-direction: column; line-height: 1; color: var(--ink); }
.brand-text strong { font-size: 1.25rem; font-weight: 800; letter-spacing: -.02em; }
.brand-text small { color: var(--muted); font-weight: 600; letter-spacing: .14em; text-transform: uppercase; font-size: .62rem; }

.modes { display: flex; gap: 6px; background: var(--bg-stage); padding: 5px; border-radius: 999px; }
.mode-btn {
  border: 0; background: transparent; cursor: pointer;
  font: 600 .86rem "Inter", sans-serif; color: var(--ink-soft);
  padding: 9px 16px; border-radius: 999px; transition: all .18s ease;
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.is-active { background: #fff; color: var(--accent-ink); box-shadow: var(--shadow-sm); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 22px;
  padding: 22px clamp(16px, 4vw, 40px) 40px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

/* ---------- Stage ---------- */
.stage-head h1 { margin: 2px 0 4px; font-size: clamp(1.4rem, 3vw, 1.9rem); letter-spacing: -.02em; }
.stage-hint { margin: 0 0 14px; color: var(--ink-soft); font-size: .92rem; max-width: 60ch; }

.canvas-wrap {
  background: var(--bg-stage);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 10px;
  box-shadow: var(--shadow-sm);
}
.wall-scroll {
  background:
    radial-gradient(circle at 1px 1px, rgba(31,37,51,.05) 1px, transparent 0) 0 0/22px 22px,
    #fbfcff;
  border-radius: 16px;
  overflow: auto;
  min-height: 420px;
  display: grid;
  place-items: center;
  padding: 18px;
}
#wall { width: 100%; height: auto; max-width: 760px; display: block; }

.cell { cursor: pointer; }
.cell .panel-shape { transition: transform .12s ease, filter .12s ease; transform-box: fill-box; transform-origin: center; }
.cell.is-empty .placeholder {
  fill: rgba(91,124,250,.04);
  stroke: rgba(91,124,250,.35);
  stroke-width: 2;
  stroke-dasharray: 6 6;
  transition: fill .15s ease, stroke .15s ease;
}
.cell.is-empty:hover .placeholder { fill: rgba(91,124,250,.12); stroke: var(--accent); }
.cell.is-empty .plus { fill: var(--accent); opacity: 0; font-weight: 700; transition: opacity .15s ease; }
.cell.is-empty:hover .plus { opacity: 1; }
.cell.is-filled:hover .panel-shape { filter: brightness(1.04); }
.cell.is-selected .panel-shape { filter: drop-shadow(0 0 0 var(--accent)); }
.sel-ring { fill: none; stroke: var(--accent); stroke-width: 4; }

.canvas-toolbar { display: flex; gap: 8px; align-items: center; padding: 12px 6px 4px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  font: 600 .8rem "Inter", sans-serif; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  transition: all .15s ease;
}
.chip:hover { color: var(--ink); border-color: var(--accent); }
.chip-info { cursor: default; background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }

/* ---------- Panel / cards ---------- */
.panel { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 88px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 12px; font-size: 1.02rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.muted.small { margin: -6px 0 12px; }

.badge-free {
  font: 600 .68rem "Inter", sans-serif; letter-spacing: .02em;
  background: var(--free-soft); color: var(--free);
  padding: 4px 9px; border-radius: 999px;
}

/* swatches */
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.swatch {
  position: relative; aspect-ratio: 1; border-radius: 10px; cursor: pointer;
  border: 2px solid rgba(31,37,51,.10); padding: 0; transition: transform .12s ease, box-shadow .12s ease;
}
.swatch:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.swatch.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.swatch.is-active::after {
  content: "✓"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: .9rem; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.45); font-weight: 700;
}

/* selected body */
.selected-empty .muted { margin: 0; }
.sel-actions { display: flex; flex-direction: column; gap: 14px; }
.sel-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: .9rem; cursor: pointer; user-select: none; }
.toggle input { width: 0; height: 0; opacity: 0; position: absolute; }
.toggle .track { width: 40px; height: 22px; background: var(--line); border-radius: 999px; position: relative; transition: background .18s ease; flex: none; }
.toggle .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: #fff; border-radius: 50%; box-shadow: var(--shadow-sm); transition: transform .18s ease; }
.toggle input:checked + .track { background: var(--free); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.btn-remove {
  border: 1px solid #f3c2c2; background: #fff5f5; color: #cc4b4b;
  font: 600 .82rem "Inter", sans-serif; padding: 9px 14px; border-radius: 10px; cursor: pointer; width: 100%;
  transition: all .15s ease;
}
.btn-remove:hover { background: #ffe9e9; }

/* forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { min-width: 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
input[type=text], input[type=email], input[type=number], input[type=date], textarea {
  font: 500 .92rem "Inter", sans-serif; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fbfcff;
  transition: border-color .15s ease, box-shadow .15s ease;
  width: 100%; min-width: 0; max-width: 100%;
}
input:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fff; }

/* addons */
.addons { display: flex; flex-direction: column; gap: 10px; }
.addon { display: flex; align-items: center; gap: 12px; }
.addon .addon-info { flex: 1; }
.addon .addon-name { font-weight: 600; font-size: .9rem; }
.addon .addon-price { color: var(--muted); font-size: .78rem; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--bg-stage); border-radius: 10px; padding: 3px; }
.stepper button {
  width: 30px; height: 30px; border: 0; background: #fff; border-radius: 8px; cursor: pointer;
  font-size: 1.1rem; line-height: 1; color: var(--accent-ink); box-shadow: var(--shadow-sm);
}
.stepper button:disabled { opacity: .4; cursor: not-allowed; }
.stepper .qty { min-width: 22px; text-align: center; font-weight: 700; font-size: .9rem; }

/* cost */
.card-cost { position: relative; }
.cost-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cost-list li { display: flex; justify-content: space-between; font-size: .88rem; color: var(--ink-soft); }
.cost-list li.free span:last-child { color: var(--free); font-weight: 700; }
.cost-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: 12px; border-top: 1px dashed var(--line); margin-bottom: 14px; }
.cost-total span { font-weight: 600; color: var(--ink-soft); }
.cost-total strong { font: 800 1.6rem "Poppins", sans-serif; color: var(--ink); letter-spacing: -.02em; }

.btn-primary {
  width: 100%; border: 0; cursor: pointer; color: #fff;
  background: linear-gradient(180deg, #6d8bff, var(--accent));
  font: 700 .98rem "Poppins", sans-serif; padding: 14px; border-radius: 12px;
  box-shadow: 0 6px 18px rgba(91,124,250,.35); transition: transform .12s ease, box-shadow .12s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(91,124,250,.42); }
.btn-primary:active { transform: translateY(0); }
.secondary-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn-ghost {
  flex: 1; border: 1px solid var(--line); background: #fff; color: var(--ink-soft); cursor: pointer;
  font: 600 .82rem "Inter", sans-serif; padding: 10px; border-radius: 10px; transition: all .15s ease;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-ink); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,28,56,.45); backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 20px; padding: 26px; width: min(460px, 100%);
  box-shadow: var(--shadow-md); position: relative; max-height: 92vh; overflow: auto;
}
.modal h2 { margin: 0 0 6px; font-size: 1.3rem; }
.modal-close { position: absolute; top: 14px; right: 16px; border: 0; background: transparent; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-summary {
  background: var(--bg-stage); border-radius: 12px; padding: 14px; margin: 16px 0;
  font-size: .86rem; color: var(--ink-soft); white-space: pre-line; max-height: 180px; overflow: auto;
}
#requestForm { display: flex; flex-direction: column; gap: 14px; }
.check { flex-direction: row; align-items: flex-start; gap: 9px; font-weight: 500; color: var(--ink-soft); }
.check input { margin-top: 2px; flex: none; }
.form-status { margin: 0; font-size: .85rem; min-height: 1.1em; }
.form-status.error { color: #cc4b4b; }
.form-status.ok { color: var(--free); }
#modalSuccess { text-align: center; padding: 16px 0; }
.success-mark { width: 64px; height: 64px; border-radius: 50%; background: var(--free-soft); color: var(--free); font-size: 2rem; display: grid; place-items: center; margin: 0 auto 14px; }

/* admin card */
.card-admin { border: 2px solid var(--accent); background: linear-gradient(180deg, #f6f9ff, #fff); }
.card-admin h2 { justify-content: flex-start; }
.admin-badge { font: 600 .62rem "Inter", sans-serif; letter-spacing: .04em; text-transform: uppercase; background: var(--accent); color: #fff; padding: 3px 8px; border-radius: 999px; }
.card-admin code { background: var(--accent-soft); color: var(--accent-ink); padding: 1px 5px; border-radius: 5px; font-size: .82em; }
.admin-list-head { font-size: .78rem; font-weight: 700; color: var(--ink-soft); margin: 16px 0 8px; }
.admin-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow: auto; }
.admin-row { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.admin-row-name { font-weight: 600; font-size: .84rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-row-meta { font-size: .72rem; color: var(--muted); flex: none; }
.admin-edit { border: 0; background: #f0f8ff; color: #2f6db5; padding: 4px 8px; border-radius: 7px; cursor: pointer; font-size: .75rem; font-weight: 600; flex: none; }
.admin-edit:hover { background: #d4e9ff; }
.admin-del { border: 0; background: #fff5f5; color: #cc4b4b; width: 24px; height: 24px; border-radius: 7px; cursor: pointer; font-size: 1.1rem; line-height: 1; flex: none; }
.admin-del:hover { background: #ffe1e1; }
.admin-actions { display: flex; gap: 8px; margin-top: 12px; }
.admin-actions .btn-ghost { flex: 1; }
/* delete button on template cards (admin) */
.template-card { position: relative; }
.tpl-del { position: absolute; top: 6px; right: 6px; z-index: 2; border: 0; background: rgba(204,75,75,.92); color: #fff; width: 22px; height: 22px; border-radius: 6px; cursor: pointer; font-size: 1rem; line-height: 1; }
.tpl-del:hover { background: #cc4b4b; }

/* nameplate status */
.np-status { margin-bottom: 14px; }
.np-status .np-line { font-size: .82rem; color: var(--ink-soft); margin-bottom: 10px; line-height: 1.45; }
.np-status .np-here { color: var(--ink); font-weight: 700; }
.np-status .np-actions { display: flex; gap: 8px; }
.np-status .np-btn {
  flex: 1; border: 1px solid var(--line); background: #fff; cursor: pointer;
  font: 600 .8rem "Inter", sans-serif; padding: 9px 10px; border-radius: 10px; transition: all .15s ease;
}
.np-status .np-btn.move { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.np-status .np-btn.move:hover { background: #dde7fe; }
.np-status .np-btn.remove { color: #cc4b4b; border-color: #f3c2c2; background: #fff5f5; }
.np-status .np-btn.remove:hover { background: #ffe9e9; }
.np-status .np-btn.cancel:hover { border-color: var(--accent); color: var(--accent-ink); }
.np-status.is-moving { background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: 12px; padding: 12px; }
.np-status.is-moving .np-line { color: var(--accent-ink); margin-bottom: 8px; }
/* highlight clickable panels while moving the nameplate */
#wall.is-moving .cell.is-filled .panel-shape { filter: brightness(1.06); }
#wall.is-moving .cell.is-filled:hover .panel-shape { filter: brightness(1.12) drop-shadow(0 0 6px rgba(91,124,250,.6)); }
#wall.is-moving .cell.is-empty:hover .placeholder { stroke: var(--accent); fill: rgba(91,124,250,.18); }

/* templates */
.templates-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.template-card {
  border: 2px solid var(--line); border-radius: 14px; padding: 12px; cursor: pointer;
  background: #fbfcff; transition: all .15s ease; display: flex; flex-direction: column; gap: 10px;
}
.template-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.template-preview { width: 100%; aspect-ratio: 1; border-radius: 10px; background: var(--bg-stage); display: grid; place-items: center; font-size: .8rem; color: var(--muted); overflow: hidden; }
.template-preview svg { width: 100%; height: 100%; }
.template-info { flex: 1; }
.template-name { font-weight: 700; font-size: .9rem; color: var(--ink); word-break: break-word; }
.template-desc { font-size: .75rem; color: var(--muted); }
.template-btn { border: 0; background: var(--accent); color: #fff; cursor: pointer; border-radius: 8px; padding: 8px; font-weight: 600; font-size: .8rem; transition: all .15s ease; }
.template-btn:hover { filter: brightness(1.08); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; }
  .modes { order: 3; width: 100%; justify-content: center; }
}
@media (max-width: 460px) {
  .swatches { grid-template-columns: repeat(6, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
