/* ===== Base ===== */
* { box-sizing: border-box; }

/*
  Editor styles are embedded in-site (often inside a modal).
  Keep global styling off the page by scoping the "body" rules to .ejo-editor.
*/
.ejo-editor { height: 100%; }
.ejo-editor {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: #f6f7fb;
  color: #111;

  /* Modal-friendly: let the editor fill its host and manage its own layout */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ===== Top Bar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border:1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border-radius:22px;
  padding:18px;
  position:relative;
  overflow:hidden;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
  box-shadow: 0 14px 44px rgba(0,0,0,.22);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
.brand strong { font-size: 16px; }

/* ===== Dropdown Menu (details/summary) ===== */
details.menu {
  position: relative;
  z-index: 10000;
}

details.menu > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  font-size: 18px;
  line-height: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e6e8f0;
  background: #fff;
}

details.menu > summary::-webkit-details-marker { display: none; }

details.menu[open] > summary {
  background: #f3f6ff;
  border-color: #cdd9ff;
}

details.menu .menuPanel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10001;
  width: min(260px, 80vw);
  background: #fff;
  border: 1px solid #e6e8f0;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  padding: 10px;
  display: grid;
  gap: 8px;
}

/* Prevent menu clipping */
header.topbar,
main.layout,
section.stage,
aside.side {
  overflow: visible !important;
}

.menuPanel button {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e6e8f0;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
}
.menuPanel button:active { transform: translateY(1px); }
.menuPanel button:hover { background: #f6f8ff; }
.menuPanel button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 12px;
  padding: 12px;

  /* Fill the available height inside the modal */
  flex: 1;
  min-height: 0;
}

/* Canvas area */
.stage {
  position: relative;
  background: #ffffff;
  border-radius: 16px;
  overflow: hidden;
  min-height: 0;
}

#svg {
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
  background: #ffffff;
}

/* Floating undo/redo buttons */
.canvasFabs {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 10px;
  z-index: 50;
  pointer-events: auto;

  /* Auto-hide default */
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

/* When JS adds this class, they appear */
.canvasFabs.show {
  opacity: 1;
  transform: translateY(0);
}

/* Optional: allow instant show without animation if needed later */
/* .canvasFabs.instant { transition: none; } */

.fab {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid #e6e8f0;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(0,0,0,0.12);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.fab svg {
  width: 22px;
  height: 22px;
  color: #222;
}

.fab:hover { background: #f6f8ff; }
.fab:active { transform: translateY(1px); }
.fab:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

/* Sidebar */
.side {
  background: #ffffff;
  border: 1px solid #e6e8f0;
  border-radius: 16px;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Tray toggle is mobile-only (enabled in the mobile media query) */
.trayToggle { display: none; }

/* ===== Tabs + Panels ===== */
.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid #eef1f7;
  background: #fbfcff;
}

.tabbar .tab {
  padding: 10px 8px;
  border-radius: 12px;
  border: 1px solid #e6e8f0;
  background: #ffffff;
  cursor: pointer;
  font-size: 13px;
}
.tabbar .tab.active {
  background: #f3f6ff;
  border-color: #cdd9ff;
}

.panelViews {
  padding: 10px;
  overflow: auto;
  flex: 1;
}

.panelView { display: none; }
.panelView.active { display: block; }

/* ===== Tools ===== */
.toolRow {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.tool {
  flex: 1;
  padding: 10px 8px;
  border-radius: 12px;
  border: 1px solid #e6e8f0;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
}
.tool.active {
  background: #f3f6ff;
  border-color: #cdd9ff;
}

/* ===== Icons ===== */
.iconGrid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.iconBtn {
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: 1px solid #e6e8f0;
  background: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.iconBtn svg { width: 70%; height: 70%; }

/* ===== Layers ===== */
.layerBtns {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.layerBtns button {
  padding: 10px 8px;
  border-radius: 12px;
  border: 1px solid #e6e8f0;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}

.layersList {
  display: grid;
  gap: 8px;
}

.layerItem {
  border: 1px solid #e6e8f0;
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}

.layerItem.active {
  background: #f3f6ff;
  border-color: #cdd9ff;
}

.layerTag {
  font-size: 11px;
  color: #666;
  margin-top: 2px;
}

/* ===== Props ===== */
.propsBox {
  display: grid;
  gap: 10px;
}

.propsBox input[type="text"],
.propsBox input[type="number"] {
  width: 100%;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid #e6e8f0;
  font-size: 14px;
}

.propsBox input[type="color"] {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  border: 1px solid #e6e8f0;
  padding: 6px;
  background: #fff;
}

.propsBox button {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #e6e8f0;
  background: #fff;
  cursor: pointer;
}

.rangeWrap label {
  display: block;
  font-size: 12px;
  color: #555;
  margin-bottom: 6px;
}
.rangeWrap input[type="range"] { width: 100%; }

/* =========================================================
   DUPLICATION FIX
   Desktop/tablet: show desktop containers only
   ========================================================= */
#iconGridMobile,
#layersMobile,
#propertiesMobile,
.layerBtns.mobileOnly {
  display: none !important;
}

/* ===== Mobile ===== */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  /* Bottom tools tray on mobile */
  .side {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: min(56vh, 520px);
    min-height: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -14px 40px rgba(0,0,0,0.18);
    transform: translateY(calc(100% - 64px));
    transition: transform 180ms ease;
    z-index: 9998;
  }

  .side.trayOpen {
    transform: translateY(0);
  }

  .trayToggle {
    width: 100%;
    height: 64px;
    border: 0;
    border-bottom: 1px solid #eef1f7;
    background: #fbfcff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
  }

  .trayToggle .grab {
    width: 46px;
    height: 6px;
    border-radius: 999px;
    background: #d7dbe8;
    display: inline-block;
  }

  .trayToggleLabel { font-weight: 600; color: #222; }

  /* Give the canvas room so the tray (peek or open) never traps the bottom */
  .layout { padding-bottom: calc(var(--trayInset, 64px) + 14px); }

  /* On mobile: show mobile containers, hide desktop containers */
  #iconGrid,
  #layers,
  #properties {
    display: none !important;
  }

  #iconGridMobile,
  #layersMobile,
  #propertiesMobile {
    display: grid !important;
  }

  /* Layers buttons: show only mobile buttons on mobile */
  .panelView[data-panel="layers"] .layerBtns:not(.mobileOnly) {
    display: none !important;
  }
  .layerBtns.mobileOnly {
    display: grid !important;
    margin-top: 10px;
  }

  .fab {
    width: 48px;
    height: 48px;
    border-radius: 16px;
  }
  .fab svg {
    width: 24px;
    height: 24px;
  }
}

/* ===== Galleries (thumbnails) ===== */
.bgGallery{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;margin:8px 0;}
.bgGallery button{padding:0;border:1px solid rgba(0,0,0,.12);border-radius:10px;overflow:hidden;background:#fff;cursor:pointer;}
.bgGallery img{display:block;width:100%;height:72px;object-fit:cover;}
.muted{opacity:.7;font-size:12px;}

.layerBtns{flex-wrap:wrap;gap:8px}
.layerBtns button{min-width:72px}
.layerItem .layerRight{display:flex;align-items:center;gap:10px}
.layerEye{cursor:pointer;opacity:.8}
.layerEye.off{opacity:.35}


/* Merge/Flatten preview modal */
.ejoModal{position:fixed;inset:0;background:rgba(0,0,0,.72);display:flex;align-items:center;justify-content:center;z-index:9999;padding:16px}
.ejoModalCard{max-width:920px;width:100%;background:#0f1625;border:1px solid rgba(255,255,255,.12);border-radius:16px;overflow:hidden}
.ejoModalHead{display:flex;align-items:center;justify-content:space-between;padding:12px 14px;border-bottom:1px solid rgba(255,255,255,.1)}
.ejoModalHead h3{margin:0;font-size:14px;font-weight:700}
.ejoModalHead button{padding:8px 10px;border-radius:12px;border:1px solid rgba(255,255,255,.16);background:#0b0f17;color:#e7eefc;cursor:pointer}
.ejoModalBody{padding:14px}
.ejoModalActions{display:flex;gap:10px;flex-wrap:wrap;margin-top:12px}
.ejoModalActions button{padding:10px 12px;border-radius:12px;border:1px solid rgba(255,255,255,.16);background:#0b0f17;color:#e7eefc;cursor:pointer}
.ejoPreviewWrap{background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.10);border-radius:14px;padding:10px;overflow:auto;max-height:60vh}
.ejoPreviewWrap img{width:100%;height:auto;display:block;border-radius:10px}


/* ===== Tray Menu Bar (Draw | Add | Text | Layers) ===== */
.trayToggle{ display:none !important; }

.trayMenuBar{
  display:flex;
  gap:8px;
  padding:10px 10px 6px;
  position:sticky;
  top:0;
  z-index:5;
  background:var(--panelBg, #fff);
  border-bottom:1px solid rgba(0,0,0,.08);
}
.trayBtn{
  flex:1 1 auto;
  padding:10px 8px;
  border-radius:10px;
  border:1px solid rgba(0,0,0,.12);
  background:rgba(0,0,0,.03);
  font-weight:600;
  cursor:pointer;
}
.trayBtn.active{
  background:rgba(0,0,0,.10);
  border-color:rgba(0,0,0,.20);
}


/* Sub tabbar (Objects/Icons/Layers/Props) only shown when Add + Tools is active */
.subTabs.isHidden{display:none !important;}
