* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  background: #eef1f4;
  color: #1f2933;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar (fixná výška, nezalamuje sa) ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 52px;
  min-height: 52px;
  background: #ffffff;
  border-bottom: 1px solid #d5dbe1;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
}
#topbar > * { flex: none; }
#logo { display: flex; align-items: center; gap: 8px; font-weight: 800; color: #1257c4; margin-right: 2px; text-decoration: none; letter-spacing: -.3px; }
#logo .mark { width: 26px; height: 26px; border-radius: 7px; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, #1a73e8, #38b6ff); box-shadow: 0 3px 8px rgba(26,115,232,.35); }
#logo .mark svg { width: 17px; height: 17px; }
#logo:hover .txt { text-decoration: underline; }
.home-link { color: #5a6b7e; font-weight: 600; font-size: 13px; text-decoration: none; padding: 5px 10px; border-radius: 8px; }
.home-link:hover { background: #eef3f9; color: #1257c4; }
#topbar .sep { width: 1px; height: 26px; background: #d5dbe1; margin: 0 2px; }
#topbar label.inline { display: flex; align-items: center; gap: 5px; color: #52606d; }
#statusMsg {
  margin-left: auto;
  color: #1e8e3e;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
#statusMsg.err { color: #c5221f; }

button {
  background: #f1f3f5;
  color: #1f2933;
  border: 1px solid #c3cbd3;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
button:hover { background: #e4e9ee; }
button.accent { background: #1a73e8; border-color: #1a73e8; color: #fff; font-weight: 600; }
button.accent:hover { background: #2b7de9; }
button.danger { background: #d93025; border-color: #d93025; color: #fff; }
button.plain { border: none; background: transparent; font-size: 15px; }
button.plain:hover { background: #e4e9ee; }
button.wide { width: 100%; margin-bottom: 8px; }

/* simulačné tlačidlo — pevná šírka, aby lišta neposkakovala */
button.sim {
  background: #fff;
  border: 2px solid #1e8e3e;
  color: #1e8e3e;
  font-weight: 700;
  border-radius: 18px;
  padding: 6px 14px;
  width: 168px;
  text-align: center;
}
button.sim:hover { background: #e6f4ea; }
button.sim.on {
  background: #1e8e3e;
  border-color: #1e8e3e;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(30, 142, 62, .22);
}
button.sim.on:hover { background: #2da04c; }

input[type=number], input[type=text], select {
  background: #fff;
  border: 1px solid #c3cbd3;
  color: #1f2933;
  border-radius: 5px;
  padding: 5px 7px;
  font-size: 13px;
  font-family: inherit;
}
input[type=number]:focus, input[type=text]:focus, select:focus {
  outline: none;
  border-color: #1a73e8;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, .16);
}

/* ---------- layout ---------- */
#main { flex: 1; display: flex; min-height: 0; }

#palette {
  width: 172px;
  background: #ffffff;
  border-right: 1px solid #d5dbe1;
  padding: 10px;
  overflow-y: auto;
}
#palette h3, #props h3 {
  margin: 12px 0 8px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: #7b8794;
}
#palette h3:first-child { margin-top: 2px; }
.palette-item {
  background: #f8f9fa;
  border: 1px solid #d5dbe1;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: grab;
  user-select: none;
}
.palette-item:hover { background: #e8f0fe; border-color: #1a73e8; }
.hint { color: #7b8794; font-size: 11.5px; line-height: 1.6; }

#centerCol { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#canvasWrap {
  flex: 1;
  overflow: auto;
  padding: 20px;
  background: #dde3e9;
}
#canvasScale { transform-origin: top left; width: max-content; }

#canvas {
  position: relative;
  background: #f4f4f4;
  box-shadow: 0 3px 16px rgba(15, 30, 50, .25);
  background-size: cover;
  background-position: center;
  overflow: hidden;
}
#canvas.grid {
  background-image:
    linear-gradient(rgba(0,0,0,.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,.07) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* ---------- prehľad objektov ---------- */
/* výšku nastavuje layoutPanes() podľa voľného miesta pod plátnom */
#overview {
  height: 168px;
  flex: none;
  background: #fff;
  border-top: 1px solid #d5dbe1;
  display: flex;
  flex-direction: column;
}
.ov-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: #7b8794;
  border-bottom: 1px solid #eef1f4;
}
.ov-count {
  background: #eef1f4;
  border-radius: 10px;
  padding: 1px 8px;
  text-transform: none;
  letter-spacing: 0;
}
.ov-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.ov-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid transparent;
}
.ov-row:hover { background: #f1f5f9; }
.ov-row.sel { background: #e8f0fe; border-color: #1a73e8; }
.ov-id {
  font-family: "Consolas", monospace;
  font-weight: 700;
  color: #1565c0;
  background: #eef4fd;
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 12px;
  min-width: 54px;
  text-align: center;
}
.ov-type { color: #52606d; width: 90px; flex: none; }
.ov-desc { color: #1f2933; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ov-bind { color: #7b8794; font-size: 11.5px; white-space: nowrap; }

/* ---------- prvky na plátne ---------- */
.el { position: absolute; cursor: move; user-select: none; white-space: nowrap; }
.el.selected { outline: 2px dashed #1a73e8; outline-offset: 1px; }

.handle {
  position: absolute;
  width: var(--hs, 14px);
  height: var(--hs, 14px);
  background: #1a73e8;
  border: 1px solid #fff;
  border-radius: 3px;
  display: none;
  z-index: 5;
  box-sizing: border-box;
}
.el.selected .handle { display: block; }
.handle.n  { top: calc(var(--hs, 14px) / -2); left: 50%; margin-left: calc(var(--hs, 14px) / -2); cursor: ns-resize; }
.handle.s  { bottom: calc(var(--hs, 14px) / -2); left: 50%; margin-left: calc(var(--hs, 14px) / -2); cursor: ns-resize; }
.handle.e  { right: calc(var(--hs, 14px) / -2); top: 50%; margin-top: calc(var(--hs, 14px) / -2); cursor: ew-resize; }
.handle.w  { left: calc(var(--hs, 14px) / -2); top: 50%; margin-top: calc(var(--hs, 14px) / -2); cursor: ew-resize; }
.handle.ne { top: calc(var(--hs, 14px) / -2); right: calc(var(--hs, 14px) / -2); cursor: nesw-resize; }
.handle.sw { bottom: calc(var(--hs, 14px) / -2); left: calc(var(--hs, 14px) / -2); cursor: nesw-resize; }
.handle.nw { top: calc(var(--hs, 14px) / -2); left: calc(var(--hs, 14px) / -2); cursor: nwse-resize; }
.handle.se { bottom: calc(var(--hs, 14px) / -2); right: calc(var(--hs, 14px) / -2); cursor: nwse-resize; }

.el-input {
  background: #fff;
  border: 1.5px solid #9e9e9e;
  border-radius: 8px;
  color: #1565c0;
  font-weight: 700;
  display: flex;
  align-items: center;
  padding: 0 8px;
  overflow: hidden;
}
.el-input .pencil { margin-left: auto; color: #9e9e9e; font-weight: 400; }
.el-input .in-label {
  position: absolute;
  top: -17px;
  left: 0;
  font-size: 12px;
  font-weight: 400;
  color: #444;
}
.el-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #fff;
  font-weight: 600;
  overflow: hidden;
  text-align: center;
}
.el-button svg { display: block; }
.el-circle { border-radius: 50%; }
.el-shape { display: flex; align-items: center; justify-content: center; overflow: hidden; }
.el-triangle { position: relative; }
.el-triangle .tri-text {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12%;
  text-align: center;
}
.el-image > img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  pointer-events: none;
  user-select: none;
}
.el-image.missing {
  background: repeating-linear-gradient(45deg, #e3e3e3, #e3e3e3 6px, #cfcfcf 6px, #cfcfcf 12px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
}
@keyframes hmiBlink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: .18; } }
.blinking { animation: hmiBlink 1s step-end infinite; }

/* ---------- vlastnosti ---------- */
#props {
  width: 320px;
  background: #ffffff;
  border-left: 1px solid #d5dbe1;
  padding: 10px 12px;
  overflow-y: auto;
}
#props .row { display: flex; align-items: center; gap: 6px; margin-bottom: 7px; }
#props .row > label:first-child { width: 96px; color: #52606d; flex-shrink: 0; }
#props .row input[type=number] { width: 74px; }
#props .row input[type=text] { flex: 1; min-width: 0; }
#props .row select { flex: 1; min-width: 0; }
#props .btnrow { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }

.section {
  border: 1px solid #e0e5ea;
  border-radius: 8px;
  padding: 9px 10px 5px;
  margin-bottom: 10px;
  background: #fbfcfd;
}
.section > .sec-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: #7b8794;
  margin: -2px 0 8px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section .sec-id {
  font-family: "Consolas", monospace;
  background: #eef4fd;
  color: #1565c0;
  border-radius: 4px;
  padding: 0 6px;
  text-transform: none;
}
.section.sim { background: #f6f7f9; border-style: dashed; }
.section.sim .sec-title { color: #9aa5b1; }
.sec-note { font-size: 11px; color: #7b8794; margin: -4px 0 8px; line-height: 1.45; }

.zorder { display: flex; gap: 4px; margin: 2px 0 6px; }
.zorder button { flex: 1; padding: 5px 2px; font-size: 12px; }

/* ---------- moderné ovládacie prvky ---------- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track {
  position: absolute;
  inset: 0;
  background: #cbd2d9;
  border-radius: 12px;
  transition: background .15s;
}
.switch .track::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .15s;
}
.switch input:checked + .track { background: #1a73e8; }
.switch input:checked + .track::before { transform: translateX(18px); }

.segmented {
  display: flex;
  border: 1px solid #c3cbd3;
  border-radius: 6px;
  overflow: hidden;
  flex: 1;
}
.segmented button {
  flex: 1;
  border: none;
  border-radius: 0;
  background: #fff;
  padding: 6px 4px;
  font-size: 12px;
  border-right: 1px solid #dfe4e9;
}
.segmented button:last-child { border-right: none; }
.segmented button.on { background: #1a73e8; color: #fff; font-weight: 600; }

.color-field { display: flex; align-items: center; gap: 4px; flex: 1; flex-wrap: wrap; }
.swatch {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  border: 1px solid rgba(0,0,0,.18);
  cursor: pointer;
  padding: 0;
  background-clip: padding-box;
}
.swatch:hover { transform: scale(1.12); }
.swatch.sel { box-shadow: 0 0 0 2px #1a73e8; }
.color-field input[type=color] {
  width: 28px;
  height: 22px;
  padding: 1px;
  border: 1px solid #c3cbd3;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.rule {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
  background: #eef1f4;
  border-radius: 6px;
  padding: 6px;
  flex-wrap: wrap;
}
.rule select { width: 52px; flex: none; }
.rule input[type=text] { width: 56px; flex: none; }
.rule input[type=color] { width: 26px; height: 22px; padding: 1px; border: 1px solid #c3cbd3; border-radius: 4px; }
.rule .blink-lbl { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: #52606d; }
.rule .del { padding: 3px 8px; margin-left: auto; }

.action-card {
  background: #eef1f4;
  border-radius: 7px;
  padding: 7px 8px 3px;
  margin-bottom: 7px;
}
.action-card .row > label:first-child { width: 74px; font-size: 12px; }
.action-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.action-head .idx { font-weight: 700; color: #52606d; font-size: 12px; }
.action-head .del { margin-left: auto; padding: 2px 8px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 7px; }
.chip {
  border: 1px solid #c3cbd3;
  background: #fff;
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: "Consolas", monospace;
}
.chip.on { background: #1a73e8; border-color: #1a73e8; color: #fff; font-weight: 700; }
.icon-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.icon-pick .preview {
  width: 40px;
  height: 40px;
  border: 1px solid #c3cbd3;
  border-radius: 6px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- modály ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 40, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  width: min(760px, 90vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 14px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head span { font-weight: 600; font-size: 15px; }
.modal-imgwrap {
  flex: 1;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%),
    linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  border: 1px solid #e0e5ea;
  border-radius: 6px;
  overflow: auto;
}
.modal-imgwrap img { max-width: 100%; max-height: 60vh; }
.modal-meta { color: #7b8794; font-size: 12px; margin: 8px 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.gallery-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  overflow-y: auto;
  min-height: 160px;
  max-height: 60vh;
  padding: 2px;
}
.gcard { border: 1px solid #d5dbe1; border-radius: 8px; background: #fff; overflow: hidden; display: flex; flex-direction: column; }
.gcard .gthumb {
  height: 96px;
  cursor: zoom-in;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%),
    linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%);
  background-size: 14px 14px;
  background-position: 0 0, 7px 7px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gcard .gthumb img { max-width: 100%; max-height: 96px; }
.gcard .gname { font-size: 12px; font-weight: 600; padding: 5px 8px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gcard .gmeta { font-size: 11px; color: #7b8794; padding: 0 8px 5px; }
.gcard .gbtns { display: flex; gap: 4px; padding: 0 6px 6px; }
.gcard .gbtns button { flex: 1; padding: 4px 2px; font-size: 11.5px; }
.gallery-empty { color: #7b8794; padding: 30px; text-align: center; grid-column: 1 / -1; }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  overflow-y: auto;
  max-height: 62vh;
  padding: 2px;
}
.icon-card {
  border: 1px solid #d5dbe1;
  border-radius: 8px;
  background: #fff;
  padding: 8px 4px 6px;
  text-align: center;
  cursor: pointer;
}
.icon-card:hover { border-color: #1a73e8; background: #f5f9ff; }
.icon-card.sel { border-color: #1a73e8; box-shadow: 0 0 0 2px rgba(26,115,232,.25); }
.icon-card .lbl { font-size: 11px; color: #52606d; margin-top: 4px; }
