/* editor.css */
@import url('./consent.css');
:root{
  --bg:#ffffff;
  --panel:#ffffff;
  --stroke:#0090f6;
  --strokeSoft: rgba(0,144,246,.22);
  --text:#0b1220;
  --muted: rgba(11,18,32,.72);
  --accent:#0090f6;
  --warn:#d97706;
  --bad:#dc2626;
  --ok:#16a34a;
  --shadow: 0 10px 26px rgba(0,0,0,.08);
  --radius:14px;
  --gap:14px;
  --dock-w: 88px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

*{box-sizing:border-box}
html,body{min-height:100%;width:100%}
body{
  margin:0;
  overflow-x:hidden;
  background: radial-gradient(1200px 800px at 20% 0%, rgba(0,144,246,.08) 0%, #fff 55%);
  color:var(--text);
  font-family:var(--sans);
}
img, svg, video{max-width:100%;height:auto}

.app{
  min-height:100vh;
  display:flex;
  flex-direction:column;
  gap:var(--gap);
  padding:var(--gap);
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:var(--gap);
  background: var(--panel);
  border:1px solid var(--strokeSoft);
  border-radius:var(--radius);
  padding:10px 12px;
  box-shadow:var(--shadow);
  flex-wrap:wrap;
}

.brand{display:flex;align-items:center;gap:10px;min-width:260px}
.dot{
  width:10px;height:10px;border-radius:50%;
  background:var(--accent);
  box-shadow:0 0 0 5px rgba(0,144,246,.12);
}
.brand h1{font-size:14px;margin:0;letter-spacing:.2px}
.brand .meta{font-size:12px;color:var(--muted);overflow-wrap:anywhere}

.pill{
  display:inline-flex;align-items:center;gap:6px;
  padding:6px 10px;border-radius:999px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  font-family:var(--mono);
  font-size:12px;
  color:var(--muted);
  max-width:100%;
  flex-wrap:wrap;
  white-space:normal;
  overflow-wrap:anywhere;
}
.pill .led{width:8px;height:8px;border-radius:50%;background:var(--accent)}

.topActions{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
  justify-content:flex-end;
}
.topActions .btn{width:auto}
#btnBack{display:none}
.app[data-mode="edit"] #btnBack{display:inline-flex}
#btnBack{
  background:var(--accent);
  border-color:var(--accent);
  color:#fff;
  width:112px;
  min-height:54px;
  padding:6px 10px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  line-height:1.15;
  white-space:normal;
}
#btnBack:hover{
  background:#007dd8;
  border-color:#007dd8;
  color:#fff;
}

.sideSwitch{
  display:inline-flex;
  align-items:center;
  flex:0 0 auto;
  gap:4px;
  min-height:54px;
  padding:6px;
  border:1px solid var(--strokeSoft);
  border-radius:12px;
  background:#fff;
  box-sizing:border-box;
}
.sideSwitchBtn{
  min-height:40px;
  padding:0 12px;
  border:1px solid transparent;
  border-radius:8px;
  background:transparent;
  color:var(--muted);
  font-size:11px;
  font-weight:800;
  cursor:pointer;
}
.sideSwitchBtn:hover{
  color:var(--text);
  background:rgba(0,144,246,.06);
}
.sideSwitchBtn.active{
  color:#fff;
  background:var(--accent);
  border-color:var(--accent);
}
.sideSwitchBtn:disabled{
  opacity:.45;
  cursor:not-allowed;
}
.sideSwitchState{
  display:inline-flex;
  align-items:center;
  flex:0 0 auto;
  min-height:54px;
  padding:0 12px;
  border:1px solid var(--strokeSoft);
  border-radius:12px;
  background:#fff;
  color:var(--muted);
  font-size:11px;
  font-weight:700;
  white-space:nowrap;
  box-sizing:border-box;
}

.stageToolbar #btnBack,
.stageToolbar .menuReturnToolbarBtn{
  min-height:54px;
}
.toolbar{
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
  padding:8px 10px;
  background: var(--panel);
  border:1px solid var(--strokeSoft);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
}
.toolbar .btn{
  width:auto;
  padding:6px 10px;
  min-height:32px;
  font-size:11px;
  white-space:nowrap;
}
.toolbar .menuReturnToolbarBtn{
  width:96px;
  min-width:96px;
  min-height:54px;
  padding:6px 10px;
  line-height:1.15;
}
.toolbar .btn .icon{
  width:18px;
  height:18px;
  display:inline-grid;
  place-items:center;
}
.toolbar .btn .icon svg{
  width:18px;
  height:18px;
  stroke:currentColor;
  fill:none;
  stroke-width:2;
  stroke-linecap:round;
  stroke-linejoin:round;
}
.toolbar .btn.iconOnly{
  padding:6px;
  width:36px;
  justify-content:center;
}
.toolbar .btn.iconLabeled{
  width:74px;
  min-height:54px;
  padding:6px 4px;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:4px;
}
.toolbar .btn.iconLabeled .toolbarLabel{
  display:block;
  font-size:10px;
  line-height:1;
  font-weight:700;
  white-space:nowrap;
}
#btnZoomFit .toolbarLabel{
  white-space:normal;
  text-align:center;
  line-height:1.05;
}
.toolbar .btn.iconOnly.active{
  background:rgba(0,144,246,.12);
  border-color:rgba(0,144,246,.55);
}
.toolbar .btn.iconOnly svg{
  width:18px;
  height:18px;
  stroke:currentColor;
  fill:none;
  stroke-width:2;
  stroke-linecap:round;
  stroke-linejoin:round;
}

.layout{
  flex:1;
  display:grid;
  grid-template-columns: minmax(280px, 360px) minmax(0,1fr) minmax(280px, 360px);
  gap:var(--gap);
  align-items:start;
}

.app, .layout, .topbar, .toolbar, .panel, .stage, .canvasWrap{min-width:0}
.layout > *, .topbar > *, .toolbar > *{min-width:0}

.app[data-mode="setup"] .stage,
.app[data-mode="setup"] .exportPanel,
.app[data-mode="setup"] .propsPanel,
.app[data-mode="setup"] .imgPropsPanel,
.app[data-mode="setup"] .layersPanel,
.app[data-mode="setup"] .sideDock,
.app[data-mode="setup"] .sideDrawer{display:none}
.app[data-mode="setup"] .layout{grid-template-columns:1fr}
.app[data-mode="setup"] .setupPanel{max-width:980px;margin:0 auto}

.app[data-mode="edit"] .setupPanel{display:none}
.app[data-mode="edit"] .layout{grid-template-columns:1fr}

.stageBody{
  flex:1;
  display:grid;
  grid-template-columns: var(--dock-w, 88px) minmax(0, 1fr);
  min-height:0;
  position:relative;
}
.sideDock{
  display:flex;
  flex-direction:column;
  gap:8px;
  padding:10px 8px;
  background:var(--panel);
  border-right:1px solid var(--strokeSoft);
}
.dockBtn{
  border-radius:12px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  color:rgba(0,144,246,.95);
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
  padding:8px 6px;
  cursor:pointer;
}
.dockBtn svg{
  width:18px;
  height:18px;
  stroke:currentColor;
  fill:none;
  stroke-width:2;
  stroke-linecap:round;
  stroke-linejoin:round;
}
.dockLabel{
  font-size:10px;
  font-weight:700;
  color:var(--muted);
  letter-spacing:.2px;
}
.dockBtn.active{
  background:rgba(0,144,246,.12);
  border-color:rgba(0,144,246,.55);
}
.sideDock .dockBtn[data-panel="imageAdd"]{
  background:var(--accent);
  border-color:var(--accent);
  color:#fff;
}
.sideDock .dockBtn[data-panel="imageAdd"] svg{
  stroke:#fff;
}
.sideDock .dockBtn[data-panel="imageAdd"] .dockLabel{
  color:#fff;
}
.sideDock .dockBtn[data-panel="imageAdd"].active{
  box-shadow:0 0 0 2px rgba(0,144,246,.25);
}

.sideDrawer{
  position:absolute;
  left:var(--dock-w, 88px);
  top:0;
  z-index:6;
  max-height:100%;
  display:block;
}

.panel{
  background:var(--panel);
  border:1px solid var(--strokeSoft);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

.panel header{
  padding:10px 12px;
  border-bottom:1px solid var(--strokeSoft);
  background:rgba(0,144,246,.05);
}
.panel header h2{
  font-size:12px;
  margin:0;
  color:rgba(0,144,246,.95);
  font-weight:800;
  letter-spacing:.35px;
  text-transform:uppercase;
}
.setupNavRow{
  margin-bottom:10px;
}
.menuReturnLink{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:30px;
  padding:6px 10px;
  border-radius:10px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  color:rgba(0,144,246,.98);
  font-size:11px;
  font-weight:800;
  line-height:1;
  text-decoration:none;
  white-space:nowrap;
}
.menuReturnLink:hover{
  background:rgba(0,144,246,.06);
  border-color:rgba(0,144,246,.35);
}
.menuReturnLinkProminent{
  width:100%;
  min-height:38px;
  justify-content:flex-start;
  padding:8px 12px;
  border-color:rgba(0,144,246,.45);
  background:rgba(0,144,246,.08);
  font-size:12px;
}
.menuReturnToolbarBtn{
  width:96px;
  min-height:54px;
  padding:6px 10px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  line-height:1.15;
  white-space:normal;
}
.menuReturnToolbarBtn:hover{
  background:rgba(0,144,246,.06);
  border-color:rgba(0,144,246,.35);
}
.panel .content{
  padding:10px 12px;
  overflow:visible;   /* kluczowe: nie robimy “wewnętrznych” ścinających scrolli */
}

.panel.panelDrawer{
  display:none;
  width:min(360px, calc(100vw - var(--dock-w, 88px) - 24px));
  max-height:100%;
  overflow:auto;
}
.app[data-panel="textAdd"] .textAddPanel{display:flex}
.app[data-panel="imageAdd"] .imageAddPanel{display:flex}
.app[data-panel="background"] .bgPanel{display:flex}
.app[data-panel="bgGen"] .bgGenPanel{display:flex}
.app[data-panel="text"].has-text-selection .propsPanel{display:flex}
.app[data-panel="image"].has-image-selection .imgPropsPanel{display:flex}
.app[data-panel="layers"] .layersPanel{display:flex}
.app[data-panel="export"] .exportPanel{display:flex}

.stage{
  position:relative;
  display:flex;
  flex-direction:column;
  border-radius:var(--radius);
  border:1px solid var(--strokeSoft);
  background:#fff;
  box-shadow:var(--shadow);

  /* stała, sensowna wysokość sceny */
  height: calc(100vh - 130px);
  min-height:520px;
  max-height:900px;
}
.stageToolbar{
  position:sticky;
  top:0;
  z-index:20;
  width:100%;
  border-radius:var(--radius) var(--radius) 0 0;
  border:0;
  border-bottom:1px solid var(--strokeSoft);
  box-shadow:none;
}
.toolbar .btn.exportPrimary{
  margin-left:auto;
}
.canvasWrap{
  position:relative;
  flex:1;
  min-height:0;
}
.canvasTopHint{
  position:absolute;
  top:8px;
  left:50%;
  transform:translateX(-50%);
  z-index:12;
  pointer-events:none;
  color:#1f2d3d;
  background:#fff7d6;
  border:1px solid #d5c17b;
  border-radius:10px;
  font-size:10px;
  font-weight:700;
  line-height:1.2;
  padding:4px 8px;
  max-width:min(88%, 520px);
  text-align:center;
}
canvas{display:block}

.btn{
  width:100%;
  display:inline-flex;align-items:center;justify-content:center;gap:8px;
  padding:10px 10px;
  border-radius:12px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  color:rgba(0,144,246,.98);
  cursor:pointer;
  font-weight:800;
  transition:transform .05s ease, background .15s ease, border-color .15s ease;
  user-select:none;
}
.btn:hover{background:rgba(0,144,246,.06);border-color:rgba(0,144,246,.35)}
.btn:active{transform:translateY(1px)}
.btn.ok{
  background:rgba(0,144,246,.95);
  color:#fff;
  border-color:rgba(0,144,246,.95);
}
.btn.secondary{background:#fff;color:rgba(0,144,246,.98)}
.btn.danger{
  /* “danger” bez czerwieni — nadal w palecie white + blue */
  background:#fff;
  color:rgba(0,144,246,.98);
  border-color:rgba(0,144,246,.55);
}
.btn:disabled{opacity:.45;cursor:not-allowed}

.grid{display:grid;gap:10px}
.setupStepTitle{
  display:flex;
  align-items:center;
  gap:8px;
  margin-top:4px;
  font-size:12px;
  font-weight:800;
  color:var(--text);
  letter-spacing:.02em;
}
.setupStepNo{
  width:22px;
  height:22px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:999px;
  border:1px solid rgba(0,144,246,.45);
  background:rgba(0,144,246,.08);
  color:var(--accent);
  font-family:var(--mono);
  line-height:1;
}
.propsToolbar{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  align-items:center;
}
.propsDivider{
  width:100%;
  height:0;
  margin:2px 0;
}
.propGrow{flex-grow:1;min-width:220px}
.propGroup{
  display:flex;
  align-items:center;
  gap:6px;
  padding:6px 8px;
  border:1px solid var(--strokeSoft);
  border-radius:12px;
  background:#fff;
}
.propIcon{
  width:28px;
  height:28px;
  display:grid;
  place-items:center;
  border-radius:8px;
  background:rgba(0,144,246,.08);
  color:rgba(0,144,246,.95);
}
.propIcon svg{width:16px;height:16px}
.propGroup select,
.propGroup input[type="number"]{
  height:32px;
  line-height:32px;
  font-size:12px;
  padding:0 8px;
  border-radius:8px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  color:var(--text);
  font-family:var(--mono);
}
.propGroup input[type="range"]{
  height:32px;
  accent-color: var(--accent);
}
.propStroke input[type="range"]{width:120px}
.rangeValue{
  min-width:26px;
  font-size:12px;
  color:var(--muted);
  text-align:right;
  font-family:var(--mono);
}
.miniLabel{
  font-size:11px;
  color:var(--muted);
  font-family:var(--mono);
}
.propGroup input[type="number"]{max-width:78px}
.propFont select{width:100%}
.propShadow input[type="number"]{max-width:64px}
.imagePropsToolbar input[type="number"]{max-width:64px}
.imagePropsToolbar input[type="range"]{
  width:120px;
  accent-color: var(--accent);
}
.propGroup input[type="color"]{
  width:32px;
  height:32px;
  padding:0;
  border-radius:8px;
  border:1px solid var(--strokeSoft);
  background:#fff;
}
.bgPanel #bgColor{
  width:56px;
  height:56px;
  border-radius:12px;
  cursor:pointer;
}
.bgPanel .bgActions,
.bgGenPanel .bgActions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}
.bgPanel .bgActions .btn,
.bgGenPanel .bgActions .btn{
  flex:1;
}
.bgPanel .bgQuality select,
.bgGenPanel .bgQuality select{
  width:100%;
}
.iconBtn{
  width:32px;
  height:32px;
  padding:0;
  display:grid;
  place-items:center;
  border-radius:8px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  color:rgba(0,144,246,.95);
  cursor:pointer;
}
.iconBtn.ok{
  background:rgba(0,144,246,.95);
  color:#fff;
  border-color:rgba(0,144,246,.95);
}
.iconBtn.ok:hover{
  background:rgba(0,144,246,.85);
}
.iconBtn:disabled{
  opacity:.45;
  cursor:not-allowed;
}
.layersToolbar{
  display:flex;
  gap:8px;
  margin-bottom:8px;
}
.layersList{
  list-style:none;
  margin:0;
  padding:0;
  display:grid;
  gap:6px;
}
.layerItem{
  display:grid;
  grid-template-columns: 18px 1fr auto auto;
  gap:8px;
  align-items:center;
  padding:6px 8px;
  border:1px solid var(--strokeSoft);
  border-radius:10px;
  background:#fff;
}
.layerItem.active{
  border-color:rgba(0,144,246,.65);
  box-shadow:0 0 0 2px rgba(0,144,246,.12);
}
.layerItem.is-hidden{opacity:.6}
.layerHandle{
  color:var(--muted);
  cursor:grab;
  user-select:none;
}
.layerName{
  font-size:12px;
  color:var(--text);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.layerBtn{
  width:26px;
  height:26px;
  display:grid;
  place-items:center;
  border-radius:6px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  color:rgba(0,144,246,.95);
  cursor:pointer;
}
.layerBtn svg{
  width:14px;
  height:14px;
  stroke:currentColor;
  fill:none;
  stroke-width:2;
  stroke-linecap:round;
  stroke-linejoin:round;
}
.layerBtn.active{
  background:rgba(0,144,246,.12);
  border-color:rgba(0,144,246,.45);
}
.layerItem.dragging{opacity:.5}
.iconBtn svg{
  width:16px;
  height:16px;
  stroke:currentColor;
  fill:none;
  stroke-width:2;
  stroke-linecap:round;
  stroke-linejoin:round;
}
.iconBtn:hover{background:rgba(0,144,246,.06);border-color:rgba(0,144,246,.35)}
.iconBtn.active{background:rgba(0,144,246,.12);border-color:rgba(0,144,246,.55)}
.field{
  display:grid;
  grid-template-columns: 120px 1fr;
  gap:10px;
  align-items:stretch;
  font-size:12px;
  color:var(--muted);
}
.field label{
  line-height:1.3;
  padding:3px 0;
  display:flex;
  align-items:center;
}
.field input, .field select{
  width:100%;
  height:36px;
  padding:0 10px;
  line-height:36px;
  border-radius:10px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  color:var(--text);
  outline:none;
  font-family:var(--mono);
}
.screenTypeControl,
.bagSizeControl,
.matSizeControl{
  display:grid;
  gap:8px;
}
.screenTypePicker,
.bagSizePicker{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:8px;
}
.matSizePicker{
  display:grid;
  grid-template-columns:repeat(3, minmax(0, 1fr));
  gap:8px;
}
.screenTypeBtn,
.bagSizeBtn,
.matSizeBtn{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:8px;
  min-height:86px;
  padding:10px 8px;
  border-radius:12px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  color:var(--text);
  cursor:pointer;
  transition:background .15s ease, border-color .15s ease, box-shadow .15s ease, color .15s ease;
}
.screenTypeBtn:hover,
.bagSizeBtn:hover,
.matSizeBtn:hover{
  background:rgba(0,144,246,.06);
  border-color:rgba(0,144,246,.35);
}
.screenTypeBtn.active,
.bagSizeBtn.active,
.matSizeBtn.active{
  border-color:var(--accent);
  box-shadow:0 0 0 2px rgba(0,144,246,.18);
}
.screenTypeBtn:disabled,
.bagSizeBtn:disabled,
.matSizeBtn:disabled{
  background:#eef1f4;
  border-color:rgba(11,18,32,.18);
  color:rgba(11,18,32,.52);
  box-shadow:none;
  cursor:not-allowed;
}
.screenTypeIcon,
.bagSizeIcon,
.matSizeIcon{
  display:flex;
  align-items:center;
  justify-content:center;
  width:40px;
  height:32px;
}
.screenTypeIcon svg,
.bagSizeIcon svg,
.matSizeIcon svg{
  width:100%;
  height:100%;
  stroke:currentColor;
  stroke-width:2;
  stroke-linecap:round;
  stroke-linejoin:round;
}
.screenTypeLabel,
.bagSizeLabel,
.matSizeLabel{
  font-size:12px;
  line-height:1.2;
  font-weight:700;
  text-align:center;
}
.shapePicker{
  display:grid;
  grid-template-columns:repeat(3, minmax(0, 1fr));
  gap:8px;
}
.shapeBtn{
  display:flex;
  align-items:center;
  justify-content:center;
  height:36px;
  border-radius:10px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  cursor:pointer;
  transition:background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.shapeBtn:hover{background:rgba(0,144,246,.06);border-color:rgba(0,144,246,.35)}
.shapeBtn.active{
  border-color:var(--accent);
  box-shadow:0 0 0 2px rgba(0,144,246,.18);
}
.shapeIcon{
  display:inline-block;
  width:20px;
  height:20px;
  border:2px solid var(--accent);
  background:rgba(0,144,246,.08);
  border-radius:4px;
}
.shapeIcon.circle{border-radius:50%}
.shapeIcon.square{border-radius:4px}
.shapeIcon.rect{
  width:26px;
  height:16px;
  border-radius:4px;
}
.shapeIcon.trapezoid{
  width:26px;
  height:16px;
  border-radius:0;
  clip-path:polygon(18% 0, 82% 0, 100% 100%, 0 100%);
}
.shapeSelectHidden,
.field select.shapeSelectHidden{
  position:absolute;
  width:1px;
  height:1px;
  padding:0;
  margin:-1px;
  overflow:hidden;
  clip:rect(0,0,0,0);
  white-space:nowrap;
  border:0;
}
.srOnly{
  position:absolute;
  width:1px;
  height:1px;
  padding:0;
  margin:-1px;
  overflow:hidden;
  clip:rect(0,0,0,0);
  white-space:nowrap;
  border:0;
}
.row2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.row2.rect .field{
  grid-template-columns:1fr;
  gap:6px;
}
.row2.trapezoid .field{
  grid-template-columns:1fr;
  gap:6px;
}
.row2.rect .field label{
  padding:0;
}
.row2.trapezoid .field label{
  padding:0;
}
.row2.rect .field input{
  height:34px;
  line-height:34px;
}
.row2.trapezoid .field input{
  height:34px;
  line-height:34px;
}
#rowDims.is-locked .field label{
  color:rgba(11,18,32,.48);
}
#rowDims.is-locked .field input{
  background:#eef1f4;
  border-color:rgba(11,18,32,.18);
  color:rgba(11,18,32,.58);
  cursor:not-allowed;
}
#rowDims.is-locked .field input::placeholder{
  color:rgba(11,18,32,.4);
}
.hintBox{
  font-size:12px;
  line-height:1.35;
  color:var(--muted);
  padding:10px 12px;
  background:rgba(0,144,246,.04);
  border:1px solid var(--strokeSoft);
  border-radius:12px;
  overflow-wrap:anywhere;
}

.sep{height:1px;background:var(--strokeSoft);margin:10px 0}

.previewWrap{
  --setup-preview-height: clamp(180px, 34vh, 320px);
  display:flex;
  align-items:center;
  justify-content:center;
  width:100%;
  min-height:var(--setup-preview-height);
  max-height:var(--setup-preview-height);
  padding:10px;
  background:rgba(0,144,246,.04);
  border:1px solid var(--strokeSoft);
  border-radius:12px;
  overflow:hidden;
}
.previewBox{
  width:150px;height:90px;
  border:2px solid rgba(0,144,246,.8);
  background:rgba(0,144,246,.06);
  box-shadow: inset 0 0 0 2px rgba(0,144,246,.08);
  transition:all .12s ease;
}

.tools{display:grid;gap:10px}
.toolrow{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.toolrow3{display:grid;grid-template-columns:1fr 1fr 1fr;gap:10px}
.small{padding:8px 10px;border-radius:10px;font-size:12px;font-weight:800}

.statusLine{
  font-family:var(--mono);
  font-size:12px;
  color:var(--muted);
  white-space:normal;     /* kluczowe: koniec ucinania */
  overflow-wrap:anywhere; /* kluczowe: długie tokeny/origins nie utną panelu */
}
.qualityStatus{font-weight:700}
.qualityStatus.ok{color:#0a7a43}
.qualityStatus.warn{color:#b36a00}
.qualityStatus.bad{color:#b00020}

.qualityPopup{
  position:fixed;
  right:16px;
  bottom:16px;
  width:min(340px, calc(100vw - 32px));
  background:#fff;
  border:1px solid var(--strokeSoft);
  border-radius:14px;
  box-shadow:var(--shadow);
  padding:10px 12px;
  z-index:1000;
  opacity:0;
  transform:translateY(8px);
  pointer-events:none;
  transition:opacity .18s ease, transform .18s ease;
}
.qualityPopup.show{
  opacity:1;
  transform:translateY(0);
  pointer-events:auto;
}
.qualityPopup.warn{
  border-color:rgba(217,119,6,.45);
  box-shadow:0 10px 26px rgba(217,119,6,.18);
}
.qualityPopup.bad{
  border-color:rgba(220,38,38,.45);
  box-shadow:0 10px 26px rgba(220,38,38,.18);
}
.qualityPopupHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin-bottom:6px;
}
.qualityPopupTitle{
  font-size:12px;
  font-weight:800;
  letter-spacing:.35px;
  text-transform:uppercase;
  color:var(--accent);
}
.qualityPopup.warn .qualityPopupTitle{color:var(--warn)}
.qualityPopup.bad .qualityPopupTitle{color:var(--bad)}
.qualityPopupBody{
  font-size:12px;
  color:var(--text);
  line-height:1.4;
}
.qualityPopupHint{
  margin-top:6px;
  font-size:11px;
  color:var(--muted);
}
.qualityPopupClose{
  width:28px;
  height:28px;
  border-radius:8px;
  border:1px solid var(--strokeSoft);
  background:#fff;
  display:grid;
  place-items:center;
  cursor:pointer;
  color:var(--text);
}
.qualityPopupClose svg{
  width:14px;
  height:14px;
  stroke:currentColor;
  stroke-width:2;
  stroke-linecap:round;
}

.uploadHint{
  margin-top:8px;
}

.pdfImportModal{
  position:fixed;
  inset:0;
  background:rgba(11,18,32,.45);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
  z-index:1120;
  opacity:0;
  pointer-events:none;
  transition:opacity .18s ease;
}
.pdfImportModal.show{
  opacity:1;
  pointer-events:auto;
}
.pdfImportCard{
  width:min(680px, calc(100vw - 32px));
  max-height:calc(100vh - 32px);
  background:#fff;
  border:1px solid var(--strokeSoft);
  border-radius:16px;
  box-shadow:var(--shadow);
  display:grid;
  grid-template-rows:auto auto minmax(220px, 1fr) auto auto auto;
  overflow:hidden;
}
.pdfImportHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 12px;
  border-bottom:1px solid var(--strokeSoft);
  background:rgba(0,144,246,.05);
}
.pdfImportHeader h3{
  margin:0;
  font-size:13px;
  font-weight:800;
  letter-spacing:.2px;
  color:var(--text);
}
.pdfImportMeta{
  margin:0;
  padding:10px 12px 0;
  font-size:12px;
  color:var(--muted);
  overflow-wrap:anywhere;
}
.pdfImportPreview{
  min-height:220px;
  margin:10px 12px 8px;
  border:1px solid var(--strokeSoft);
  border-radius:12px;
  background:
    linear-gradient(45deg, rgba(0,0,0,.04) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.04) 75%, rgba(0,0,0,.04)),
    linear-gradient(45deg, rgba(0,0,0,.04) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.04) 75%, rgba(0,0,0,.04));
  background-size:16px 16px;
  background-position:0 0, 8px 8px;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:auto;
}
.pdfImportCanvas{
  display:block;
  width:auto;
  height:auto;
  max-width:100%;
  max-height:100%;
  border-radius:8px;
  background:#fff;
  box-shadow:0 4px 14px rgba(0,0,0,.16);
}
.pdfImportPreviewStatus{
  padding:0 12px 10px;
  font-size:12px;
  color:var(--muted);
}
.pdfImportControls{
  padding:0 12px 12px;
  display:grid;
  grid-template-columns:1fr auto auto 1fr;
  gap:10px;
  align-items:center;
}
.pdfImportControls .btn{
  width:auto;
}
.pdfImportPageField{
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-size:12px;
  font-weight:700;
  color:var(--text);
}
.pdfImportPageInput{
  width:84px;
  min-height:38px;
  border:1px solid var(--strokeSoft);
  border-radius:10px;
  background:#fff;
  color:var(--text);
  padding:6px 8px;
  font-size:13px;
  font-family:var(--sans);
}
.pdfImportPageInput:focus{
  border-color:rgba(0,144,246,.6);
  box-shadow:0 0 0 3px rgba(0,144,246,.14);
  outline:none;
}
.pdfImportPageCount{
  font-size:12px;
  font-weight:700;
  color:var(--muted);
}
.pdfImportActions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  padding:12px;
  border-top:1px solid var(--strokeSoft);
  background:#fff;
}
.pdfImportActions .btn{
  width:auto;
}

.exportPreviewModal{
  position:fixed;
  inset:0;
  background:rgba(11,18,32,.45);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
  z-index:1100;
  opacity:0;
  pointer-events:none;
  transition:opacity .18s ease;
}
.exportPreviewModal.show{
  opacity:1;
  pointer-events:auto;
}
.exportPreviewCard{
  width:min(940px, calc(100vw - 32px));
  height:calc(100vh - 32px);
  max-height:920px;
  background:#fff;
  border:1px solid var(--strokeSoft);
  border-radius:16px;
  box-shadow:var(--shadow);
  display:grid;
  grid-template-rows:auto minmax(0, 1fr) auto auto auto;
  overflow:hidden;
}
.exportPreviewHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 12px;
  border-bottom:1px solid var(--strokeSoft);
  background:rgba(0,144,246,.05);
}
.exportPreviewHeader h3{
  margin:0;
  font-size:13px;
  font-weight:800;
  letter-spacing:.2px;
  color:var(--text);
}
.exportPreviewBody{
  min-height:0;
  padding:12px;
  overflow:hidden;
  background:
    linear-gradient(45deg, rgba(0,0,0,.04) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.04) 75%, rgba(0,0,0,.04)),
    linear-gradient(45deg, rgba(0,0,0,.04) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.04) 75%, rgba(0,0,0,.04));
  background-size:16px 16px;
  background-position:0 0, 8px 8px;
  display:flex;
  align-items:center;
  justify-content:center;
}
.exportPreviewBody img{
  width:auto;
  height:auto;
  max-width:100%;
  max-height:100%;
  object-fit:contain;
  display:block;
  border-radius:10px;
  background:#fff;
  box-shadow:0 4px 14px rgba(0,0,0,.18);
}
.exportPreviewBody img.is-circle{
  border-radius:50%;
}
.exportMarketplaceFields{
  padding:12px 12px 0;
  background:#fff;
}
.exportMarketplaceGrid{
  display:grid;
  grid-template-columns:minmax(170px, 230px) minmax(0, 1fr);
  gap:10px 12px;
  align-items:start;
}
.exportMarketplaceLabel{
  font-size:13px;
  line-height:1.2;
  color:var(--text);
  font-weight:700;
  padding-top:10px;
}
.exportMarketplaceInput,
.exportMarketplaceTextarea{
  width:100%;
  border:1px solid var(--strokeSoft);
  border-radius:10px;
  background:#fff;
  color:var(--text);
  padding:9px 10px;
  font-size:13px;
  font-family:var(--sans);
}
.exportMarketplaceInput{
  min-height:40px;
}
.exportMarketplaceTextarea{
  resize:vertical;
  min-height:86px;
}
.exportMarketplaceHint{
  margin:0;
  grid-column:2;
  font-size:12px;
  color:var(--muted);
}
.exportMarketplaceInput:focus,
.exportMarketplaceTextarea:focus{
  border-color:rgba(0,144,246,.6);
  box-shadow:0 0 0 3px rgba(0,144,246,.14);
  outline:none;
}
.exportPreviewNote{
  margin:0;
  padding:10px 12px 0;
  background:#fff;
  font-size:12px;
  line-height:1.45;
  color:var(--muted);
}
.exportPreviewAutoCopyInfo{
  margin:0;
  padding:10px 12px 0;
  background:#fff;
  font-size:12px;
  line-height:1.45;
  color:#0a5a24;
  font-weight:700;
}
.exportPreviewActions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  padding:12px;
  border-top:1px solid var(--strokeSoft);
  background:#fff;
}
.exportPreviewActions .btn{
  width:auto;
}

.exportLoadingOverlay{
  position:fixed;
  inset:0;
  background:rgba(11,18,32,.45);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
  z-index:1200;
  opacity:0;
  pointer-events:none;
  transition:opacity .18s ease;
}
.exportLoadingOverlay.show{
  opacity:1;
  pointer-events:auto;
}
.exportLoadingCard{
  width:min(420px, calc(100vw - 32px));
  background:#fff;
  border:1px solid var(--strokeSoft);
  border-radius:16px;
  box-shadow:var(--shadow);
  padding:16px;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:10px;
  text-align:center;
}
.loadingSpinner{
  width:34px;
  height:34px;
  border-radius:50%;
  border:3px solid rgba(0,144,246,.2);
  border-top-color:var(--accent);
  animation:spin 1s linear infinite;
}
.exportLoadingTitle{
  font-size:13px;
  font-weight:800;
  letter-spacing:.2px;
  color:var(--text);
}
.exportLoadingHint{
  font-size:12px;
  color:var(--muted);
}

@keyframes spin{
  to{transform:rotate(360deg)}
}

/* Responsywność: żeby NIC nie ucinać, tylko przejść w pion */
@media (max-width: 1200px){
  :root{--gap:12px}
  .layout{grid-template-columns:1fr}
  .stage{
    height: 60vh;
    min-height:420px;
    max-height:none;
  }
  .topActions{justify-content:flex-start}
  .brand{min-width:0}
}
@media (min-width: 1201px){
  .app[data-mode="edit"] .layout{
    grid-template-columns: minmax(0,1fr) minmax(280px, 360px);
    grid-template-rows: auto auto auto;
    align-items:start;
  }
  .app[data-mode="edit"] .stage{
    grid-column:1;
    grid-row:1 / span 3;
  }
  .app[data-mode="edit"] .propsPanel{
    grid-column:2;
    grid-row:1;
  }
  .app[data-mode="edit"] .imgPropsPanel{
    grid-column:2;
    grid-row:1;
  }
  .app[data-mode="edit"] .layersPanel{
    grid-column:2;
    grid-row:2;
  }
  .app[data-mode="edit"] .exportPanel{
    grid-column:2;
    grid-row:3;
  }
}
@media (max-width: 980px){
  .topbar{flex-direction:column;align-items:stretch}
  .topActions{width:100%}
}
@media (max-width: 700px){
  :root{--gap:10px}
  .app{padding:var(--gap)}
  .app[data-mode="setup"]{padding:8px}
  .app[data-mode="setup"] .setupPanel{
    max-width:100%;
    margin:0;
  }
  .app[data-mode="setup"] .setupPanel .content{padding:14px 14px}
  .app[data-mode="setup"] .setupPanel .grid{gap:12px}
  .app[data-mode="setup"] .setupStepTitle{font-size:13px}
  .app[data-mode="setup"] .setupStepNo{width:24px;height:24px;font-size:12px}
  .app[data-mode="setup"] .field{font-size:13px}
  .app[data-mode="setup"] .field input,
  .app[data-mode="setup"] .field select{
    height:44px;
    line-height:44px;
    font-size:14px;
  }
  .app[data-mode="setup"] .screenTypeBtn,
  .app[data-mode="setup"] .bagSizeBtn,
  .app[data-mode="setup"] .matSizeBtn{
    min-height:92px;
  }
  .app[data-mode="setup"] .screenTypeLabel,
  .app[data-mode="setup"] .bagSizeLabel,
  .app[data-mode="setup"] .matSizeLabel{
    font-size:13px;
  }
  .app[data-mode="setup"] .shapeBtn{height:44px}
  .app[data-mode="setup"] .previewBox{
    width:190px;
    height:120px;
  }
  .canvasWrap{overflow:hidden}
  .app[data-panel="text"].has-text-selection .propsPanel,
  .app[data-panel="image"].has-image-selection .imgPropsPanel{
    position:fixed;
    left:0;
    right:0;
    bottom:calc(var(--dock-h, 72px) + env(safe-area-inset-bottom));
    z-index:12;
    border-radius:16px 16px 0 0;
    box-shadow:0 -8px 20px rgba(0,0,0,.12);
  }
  .app[data-panel="text"].has-text-selection .propsPanel header,
  .app[data-panel="image"].has-image-selection .imgPropsPanel header{display:none}
  .app[data-panel="text"].has-text-selection .propsPanel .content,
  .app[data-panel="image"].has-image-selection .imgPropsPanel .content{
    padding:8px 10px;
  }
  .app[data-panel="text"].has-text-selection .propsPanel .propsToolbar,
  .app[data-panel="image"].has-image-selection .imgPropsPanel .propsToolbar{
    flex-wrap:nowrap;
    gap:8px;
    overflow-x:auto;
    align-items:center;
  }
  .app[data-panel="text"].has-text-selection .propsPanel .propGroup,
  .app[data-panel="image"].has-image-selection .imgPropsPanel .propGroup{
    flex:0 0 auto;
  }
  .app[data-panel="text"].has-text-selection .propsPanel .propsDivider{display:none}
  .app[data-panel="text"].has-text-selection .propsPanel .iconBtn,
  .app[data-panel="image"].has-image-selection .imgPropsPanel .iconBtn{
    width:36px;
    height:36px;
  }
  .toolbar{
    flex-wrap:nowrap;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:thin;
  }
  .toolbar .btn{
    flex:0 0 auto;
  }
  #rowDims{grid-template-columns:1fr !important}
  .field{grid-template-columns:1fr !important}
  .field label{padding:0 0 4px}
  .field input, .field select{
    height:40px;
    line-height:40px;
  }
  .btn{min-height:40px}
  .qualityStatus{display:none}
  .qualityPopup{
    left:12px;
    right:12px;
    bottom:12px;
  }
  .exportPreviewCard{
    width:calc(100vw - 20px);
    height:calc(100vh - 20px);
  }
  .exportPreviewBody{
    min-height:0;
  }
  .exportMarketplaceGrid{
    grid-template-columns:1fr;
    gap:8px;
  }
  .exportMarketplaceLabel{
    padding-top:0;
  }
  .exportMarketplaceHint{
    grid-column:auto;
  }
  .exportPreviewActions{
    flex-wrap:wrap;
  }
  .exportPreviewActions .btn{
    flex:1 1 100%;
  }
  .pdfImportCard{
    width:calc(100vw - 20px);
    max-height:calc(100vh - 20px);
    grid-template-rows:auto auto minmax(180px, 1fr) auto auto auto;
  }
  .pdfImportControls{
    grid-template-columns:1fr 1fr;
  }
  .pdfImportPageField{
    justify-content:flex-end;
  }
  .pdfImportPageCount{
    justify-self:start;
  }
  .pdfImportActions{
    flex-wrap:wrap;
  }
  .pdfImportActions .btn{
    flex:1 1 100%;
  }
}
@media (max-width: 420px){
  .row2{grid-template-columns:1fr}
}

/* Fullscreen editor layout */
.app[data-mode="edit"]{
  padding:0;
  gap:0;
  height:100vh;
  height:100dvh;
  overflow:hidden;
}
.app[data-mode="edit"] .layout{
  display:block;
  height:100vh;
  height:100dvh;
}
.app[data-mode="edit"] .stage{
  height:100vh;
  height:100dvh;
  min-height:0;
  max-height:none;
  border-radius:0;
  border:0;
  box-shadow:none;
}
.app[data-mode="edit"] .stageToolbar{
  border-radius:0;
}

@media (max-width: 700px){
  :root{--dock-w:72px;--dock-h:72px}
  .stageToolbar{padding:12px 12px}
  .toolbar .btn{min-height:40px}
  .toolbar .btn.iconOnly{width:40px}
  .sideSwitch{
    min-height:44px;
    padding:3px;
    border-radius:10px;
  }
  .sideSwitchBtn{
    min-height:34px;
    padding:0 8px;
    font-size:10px;
  }
  .sideSwitchState{
    min-height:44px;
    padding:0 10px;
    font-size:10px;
  }
  .canvasTopHint{
    top:6px;
    font-size:9px;
    padding:4px 6px;
    max-width:92%;
  }
  #btnBack{
    min-height:44px;
    width:96px;
    padding:6px 8px;
    font-size:10px;
    line-height:1.1;
  }
  .menuReturnToolbarBtn{
    min-height:44px;
    width:96px;
    padding:6px 8px;
    font-size:10px;
    line-height:1.1;
  }
  .toolbar .menuReturnToolbarBtn{
    width:96px;
    min-width:96px;
    min-height:44px;
    padding:6px 8px;
    line-height:1.1;
  }
  .toolbar .btn.iconLabeled{
    width:40px;
    min-height:40px;
    padding:6px;
    gap:0;
  }
  .toolbar .btn.iconLabeled .toolbarLabel{display:none}
  .stageBody{
    display:flex !important;
    flex-direction:column !important;
  }
  .sideDock{
    order:2;
    flex-direction:row !important;
    justify-content:flex-start;
    gap:8px;
    padding:8px 8px calc(8px + env(safe-area-inset-bottom));
    border-right:0;
    border-top:1px solid var(--strokeSoft);
    margin-top:auto;
    overflow-x:auto;
    overflow-y:hidden;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:thin;
    scroll-snap-type:x proximity;
  }
  .dockBtn{
    flex:0 0 auto;
    min-width:74px;
    padding:8px 6px;
    scroll-snap-align:start;
  }
  .dockLabel{font-size:9px}
  .sideDock .dockBtn[data-panel="export"]{
    background:var(--ok);
    border-color:var(--ok);
    color:#fff;
  }
  .sideDock .dockBtn[data-panel="export"] svg{
    stroke:#fff;
  }
  .sideDock .dockBtn[data-panel="export"] .dockLabel{
    color:#fff;
  }
  .sideDrawer{
    position:absolute;
    left:0;
    right:0;
    top:auto;
    bottom:calc(var(--dock-h) + env(safe-area-inset-bottom));
    padding:0 8px 8px;
  }
  .panel.panelDrawer{
    width:100%;
    max-height:calc(100% - var(--dock-h) - 8px);
  }
}

@media (max-width: 700px){
  .sideDock{
    position:relative;
    bottom:auto;
    z-index:10;
    background:var(--panel);
  }
}
.btn.ok.exportPrimary{
  background:var(--ok);
  border-color:var(--ok);
  min-width:220px;
}
.btn.ok.exportPrimary:hover{
  background:#128c3f;
  border-color:#128c3f;
}
#btnExportTop{display:none}
@media (min-width: 701px){
  #btnExportTop{display:inline-flex}
  #btnExport{display:none}
  .sideDock .dockBtn[data-panel="export"]{display:none}
  .exportPanel{display:none}
}
@media (max-width: 700px){
  #btnExportTop{display:none}
  #btnExport{display:inline-flex}
}
@media (min-width: 1000px){
  .app[data-mode="setup"] .setupPanel .content{padding:16px 18px}
  .app[data-mode="setup"] .setupPanel .grid{gap:14px}
  .app[data-mode="setup"] .setupPanel .field{
    font-size:14px;
  }
  .app[data-mode="setup"] .setupPanel .field input,
  .app[data-mode="setup"] .setupPanel .field select{
    height:42px;
    line-height:42px;
  }
  .app[data-mode="setup"] .setupPanel .screenTypeBtn,
  .app[data-mode="setup"] .setupPanel .bagSizeBtn,
  .app[data-mode="setup"] .setupPanel .matSizeBtn{
    min-height:90px;
  }
  .app[data-mode="setup"] .setupPanel .shapeBtn{
    height:42px;
  }
  .app[data-mode="setup"] .setupPanel .previewBox{
    width:220px;
    height:132px;
  }
}
