/* ZPL Designer — editor styles */
:root {
  --bg: #0f1220;
  --bg-2: #161a2c;
  --panel: #1c2138;
  --panel-2: #232944;
  --line: #2c3354;
  --text: #e7eaf3;
  --muted: #9aa3c0;
  --primary: #5b8cff;
  --primary-d: #3f6fe0;
  --success: #2fbf71;
  --danger: #ff5d6c;
  --accent: #7c5cff;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
}

.app { display: flex; flex-direction: column; height: 100vh; }

/* ───────── Header ───────── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap; row-gap: 8px;
  position: relative; z-index: 30; /* keep the template dropdown above the canvas */
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand > i { color: var(--accent); font-size: 20px; }
.brand-logo { width: 24px; height: 24px; display: block; image-rendering: auto; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-tag { color: var(--muted); font-size: 12px; padding-left: 8px; border-left: 1px solid var(--line); }
.header-center { display: flex; align-items: center; gap: 8px; flex: 1 1 260px; min-width: 0; justify-content: center; }

/* Custom template dropdown (native <select> popups can't show a styled,
   guaranteed scrollbar — especially inside an iframe). */
.mfs-dd { position: relative; flex: 1 1 auto; min-width: 170px; max-width: 380px; }
.mfs-dd-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; font-family: inherit;
}
.mfs-dd-btn:hover { border-color: var(--primary); }
.mfs-dd-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mfs-dd-btn i { color: var(--muted); font-size: 11px; flex-shrink: 0; }
.mfs-dd-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1000;
  max-height: 260px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 4px;
}
.mfs-dd-menu button {
  display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text);
  font-family: inherit; font-size: 13px; padding: 8px 10px; border-radius: 6px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mfs-dd-menu button:hover, .mfs-dd-menu button.active { background: var(--primary); color: #fff; }
.mfs-dd-menu .mfs-dd-empty { color: var(--muted); padding: 8px 10px; font-size: 12px; }
.mfs-dd-menu::-webkit-scrollbar { width: 10px; }
.mfs-dd-menu::-webkit-scrollbar-thumb { background: #3a4264; border-radius: 6px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.preview-status { color: var(--muted); font-size: 12px; margin-right: 6px; min-width: 90px; text-align: right; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
  font-family: inherit; transition: background .15s, border-color .15s;
}
.btn:hover { background: #2b3252; }
.btn-primary { background: var(--primary); border-color: var(--primary-d); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost { background: transparent; }
.full-btn { width: 100%; justify-content: center; margin-top: 8px; }

/* ───────── Workspace ───────── */
.workspace { flex: 1; display: grid; grid-template-columns: 256px 1fr 340px; grid-template-rows: minmax(0, 1fr); min-height: 0; }
.rail { background: var(--bg-2); overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.rail-left { border-right: 1px solid var(--line); }
.rail-right { border-left: 1px solid var(--line); }
/* Panels must keep their height and let the RAIL scroll — otherwise a short
   viewport (e.g. inside an iframe) shrinks them to nothing. */
.rail > .panel:not(.panel-grow) { flex-shrink: 0; }
/* The Variables panel holds a scrollable list. It takes its natural height
   (capped to ~10 rows by .var-list) but may shrink on a short viewport so the
   rail itself never needs to scroll. */
.panel-grow { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel h2 {
  margin: 0 0 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); display: flex; align-items: center; gap: 8px; font-weight: 600;
}
.panel h2 i { color: var(--primary); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; line-height: 1.4; }

/* ───────── Palette (in the canvas toolbar) ───────── */
.toolbar-palette { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.palette-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 7px; color: var(--text); cursor: grab; font-size: 12px; font-family: inherit;
  transition: border-color .15s, background .15s; white-space: nowrap;
}
.palette-item:hover { border-color: var(--primary); background: #2b3252; }
.palette-item:active { cursor: grabbing; }
.palette-item i { font-size: 13px; color: var(--primary); }

/* ───────── Variables ───────── */
.var-search { width: 100%; margin-bottom: 8px; }
/* At least 10 rows visible (row 33px + gap 6px → 10×33 + 9×6 = 384px); the list
   scrolls internally so you page through variables without scrolling the whole
   rail. Grows to show more on a tall screen; on a short one the rail scrolls. */
.var-list { flex: 1 1 384px; min-height: 384px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.var-list::-webkit-scrollbar { width: 10px; }
.var-list::-webkit-scrollbar-thumb { background: #3a4264; border-radius: 6px; }
.var-row { background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; flex-shrink: 0; }
.var-row.open { border-color: var(--primary); }
.var-row-head { display: flex; align-items: center; gap: 4px; }
.var-name-btn {
  flex: 1; min-width: 0; text-align: left; background: none; border: none; color: var(--text);
  font-size: 12px; font-family: inherit; padding: 8px 10px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.var-name-btn:hover { color: var(--primary); }
.var-menu-btn {
  width: 28px; align-self: stretch; background: none; border: none; border-left: 1px solid var(--line);
  color: var(--muted); cursor: pointer; font-size: 14px;
}
.var-menu-btn:hover { color: var(--text); background: var(--panel); }
.var-menu { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.var-menu button {
  text-align: left; background: none; border: none; color: var(--text); font-family: inherit;
  font-size: 12px; padding: 8px 12px; cursor: pointer;
}
.var-menu button:hover { background: var(--primary); color: #fff; }
.var-menu button i { width: 16px; color: var(--muted); margin-right: 6px; }
.var-menu button:hover i { color: #fff; }
.var-value { display: flex; gap: 6px; align-items: center; padding: 8px 10px; border-top: 1px solid var(--line); }
.var-value span { font-size: 11px; color: var(--muted); }
.var-value input { flex: 1; padding: 5px 8px; font-size: 12px; }
.var-empty { color: var(--muted); font-size: 12px; padding: 6px 2px; }

/* Insert-variable control inside the properties Data section */
.insert-var { display: flex; gap: 6px; align-items: center; margin: 4px 0 10px; }
.insert-var select { flex: 1; }

/* ───────── Fields ───────── */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type="number"], input[type="text"], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  padding: 8px 10px; border-radius: 7px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; min-height: 56px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin: 8px 0; cursor: pointer; }
input[type="range"] { width: 100%; accent-color: var(--primary); }

/* ───────── Stage / canvas ───────── */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.stage-toolbar {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.tool-btn {
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 7px; cursor: pointer;
}
.tool-btn:hover { background: #2b3252; border-color: var(--primary); }
.tool-btn:disabled { opacity: .35; cursor: default; }
.tool-btn:disabled:hover { background: var(--panel-2); border-color: var(--line); }
.zoom-level { min-width: 48px; text-align: center; color: var(--muted); font-size: 12px; }
.divider { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.readout { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.canvas-scroll { flex: 1; overflow: auto; padding: 40px; display: grid; place-items: center; }
.canvas-pad { position: relative; }

/* Rulers */
.ruler { position: absolute; background: var(--bg-2); color: var(--muted); font-size: 9px; overflow: hidden; }
.ruler-top { top: -22px; left: 0; height: 20px; }
.ruler-left { left: -22px; top: 0; width: 20px; }
.ruler .tick { position: absolute; background: var(--line); }
.ruler-top .tick { bottom: 0; width: 1px; height: 6px; }
.ruler-top .tick.major { height: 12px; }
.ruler-left .tick { right: 0; height: 1px; width: 6px; }
.ruler-left .tick.major { width: 12px; }
.ruler .lbl { position: absolute; font-size: 8px; }
.ruler-top .lbl { top: 1px; transform: translateX(2px); }
.ruler-left .lbl { left: 1px; }

/* Label surface — the background IS the exact Labelary render */
.label {
  position: relative; background: #ffffff; box-shadow: var(--shadow);
  outline: 1px solid #cfd3e0; cursor: default;
}
.canvas-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  /* The raster is supersampled when zoomed in, so smooth downscaling looks
     crisp (anti-aliased) rather than blocky. */
  image-rendering: auto;
  user-select: none; pointer-events: none; display: block;
}
.canvas-spinner {
  position: absolute; top: 8px; right: 8px; color: var(--primary);
  font-size: 18px; background: rgba(255,255,255,.85); border-radius: 50%;
  width: 30px; height: 30px; display: grid; place-items: center; pointer-events: none;
}
.canvas-error {
  position: absolute; left: 8px; right: 8px; bottom: 8px; padding: 8px 10px;
  background: #2a0f14; color: var(--danger); border: 1px solid var(--danger);
  border-radius: 7px; font-size: 11px; pointer-events: none;
}
.grid { position: absolute; inset: 0; pointer-events: none; }
.empty-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px;
  align-items: center; justify-content: center; color: #9aa3c0; pointer-events: none;
}
.empty-hint i { font-size: 28px; }
.empty-hint p { margin: 0; font-size: 13px; }

/* Elements — transparent interaction boxes over the exact raster */
.el {
  position: absolute; box-sizing: border-box; cursor: move;
  user-select: none; -webkit-user-select: none;
  border: 1px solid transparent; transition: border-color .1s, background .1s;
}
.el:hover { border-color: rgba(91,140,255,.55); background: rgba(91,140,255,.06); }
.el.selected { border-color: var(--primary); background: rgba(91,140,255,.10); outline: 1px solid rgba(91,140,255,.35); outline-offset: 1px; }
.el.dragging { background: rgba(124,92,255,.18); border-color: var(--accent); }
/* Inline text editor shown over a text element while editing — sized to match
   the ZPL font so edits appear at the printed size. */
.el-edit {
  position: absolute; z-index: 8; margin: 0; padding: 0; border: 1px dashed var(--accent);
  background: rgba(255,255,255,.97); color: #000; overflow: hidden; box-sizing: content-box;
  resize: none; white-space: pre;
}

/* Resize handles */
.handle {
  position: absolute; width: 9px; height: 9px; background: #fff;
  border: 1.5px solid var(--primary); border-radius: 2px; z-index: 5;
}
.handle.nw { left: -5px; top: -5px; cursor: nwse-resize; }
.handle.n  { top: -5px; left: 50%; margin-left: -5px; cursor: ns-resize; }
.handle.ne { right: -5px; top: -5px; cursor: nesw-resize; }
.handle.e  { right: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }
.handle.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.handle.s  { bottom: -5px; left: 50%; margin-left: -5px; cursor: ns-resize; }
.handle.sw { left: -5px; bottom: -5px; cursor: nesw-resize; }
.handle.w  { left: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }

/* ───────── Properties ───────── */
.prop-group { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.prop-group:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.size-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; }
.lock-btn {
  width: 36px; height: 36px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--muted); border-radius: 7px; cursor: pointer; margin-bottom: 1px;
}
.lock-btn.locked { color: #fff; background: var(--primary); border-color: var(--primary-d); }
.size-buttons { display: flex; gap: 8px; margin-top: 8px; }
.size-buttons button {
  flex: 1; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 7px; padding: 8px; cursor: pointer; font-family: inherit;
}
.size-buttons button:hover { background: #2b3252; border-color: var(--primary); }
.size-buttons .big { font-size: 16px; font-weight: 700; }
.size-buttons .small { font-size: 11px; }

/* ───────── Preview & code ───────── */
.preview-panel .badge {
  margin-left: auto; background: var(--success); color: #04230f; font-size: 10px;
  padding: 2px 7px; border-radius: 20px; letter-spacing: .04em; font-weight: 700;
}
.preview-box {
  position: relative; background: #fff; border-radius: 8px; padding: 10px;
  min-height: 90px; display: grid; place-items: center;
}
.preview-box img { max-width: 100%; image-rendering: -webkit-optimize-contrast; display: block; }
.spinner { position: absolute; inset: 0; display: grid; place-items: center; color: var(--primary); font-size: 22px; background: rgba(255,255,255,.6); }
.preview-error {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: #2a0f14; color: var(--danger); font-size: 12px; padding: 10px; text-align: center;
  border-radius: 8px; border: 1px solid var(--danger);
}
.hidden { display: none !important; }

/* ───────── Tutorial / guided tour ───────── */
.tour { position: fixed; inset: 0; z-index: 5000; }
.tour-ring {
  position: absolute; border: 2px solid var(--primary); border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(7, 9, 15, 0.62); transition: all .2s ease; pointer-events: none;
}
.tour-pop {
  position: absolute; width: 320px; max-width: calc(100vw - 24px); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow);
}
.tour-title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.tour-body { font-size: 13px; color: var(--muted); line-height: 1.5; }
.tour-foot { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.tour-progress { font-size: 12px; color: var(--muted); }
.tour-spacer { flex: 1; }
.tour-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 12px; font-family: inherit;
}
.tour-btn:hover { background: #2b3252; }
.tour-primary { background: var(--primary); border-color: var(--primary-d); color: #fff; }
.tour-primary:hover { background: var(--primary-d); }

.zpl-out-wrap { position: relative; }
.zpl-out {
  display: block; width: 100%; margin: 0; background: #0b0e1a; border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 12px 40px; font-family: "Consolas", monospace; font-size: 12px;
  color: #b9e3ff; white-space: pre; overflow: auto; line-height: 1.5; min-height: 180px;
  resize: vertical;
}
.zpl-out:focus { outline: none; border-color: var(--primary); }
.zpl-error {
  margin-top: 8px; padding: 8px 10px; border-radius: 7px; font-size: 11.5px;
  background: #2a0f14; color: var(--danger); border: 1px solid var(--danger);
}
.badge-soft {
  margin-left: auto; background: var(--panel-2); color: var(--muted); font-size: 10px;
  padding: 2px 7px; border-radius: 20px; letter-spacing: .04em; border: 1px solid var(--line);
}
.copy-code-btn {
  position: absolute; right: 10px; bottom: 10px; width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 7px; cursor: pointer; opacity: .85; transition: background .15s, opacity .15s;
}
.copy-code-btn:hover { background: var(--primary); border-color: var(--primary-d); color: #fff; opacity: 1; }
.copy-code-btn.copied { background: var(--success); border-color: var(--success); color: #04230f; }
.code-panel { flex: 1; }

/* ───────── Modal ───────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5, 7, 15, .68); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  width: 640px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.modal-head, .modal-foot { display: flex; align-items: center; padding: 14px 18px; }
.modal-head { justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.modal-head h3 i { color: var(--primary); }
.modal-x { background: none; border: none; color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1; }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); }
.import-text {
  width: 100%; min-height: 220px; font-family: "Consolas", monospace; font-size: 12.5px;
  line-height: 1.5; white-space: pre; overflow: auto;
}
.import-error {
  margin-top: 10px; padding: 10px 12px; border-radius: 7px; font-size: 12.5px;
  background: #2a0f14; color: var(--danger); border: 1px solid var(--danger);
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c3354; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1200px) {
  .workspace { grid-template-columns: 220px 1fr 300px; }
}
