/* Widget builder layout - dashboard. */

.widget-builder {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 300px;
  gap: 16px;
  margin-top: 16px;
  align-items: stretch;
}

@media (max-width: 1200px) {
  .widget-builder { grid-template-columns: 200px 1fr; }
  .widget-builder__inspector { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .widget-builder { grid-template-columns: 1fr; }
}

/* ---------- top bar (name + save + tabs) ---------------------------- */

.wb-topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 2px solid #2b2118;
  background: #faf8f4;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.08);
  margin-top: 12px;
}

.wb-topbar input[type="text"] {
  font-weight: 700;
  font-size: 0.95rem;
  padding: 6px 10px;
  border: 2px solid #2b2118;
  background: #fff;
  min-width: 200px;
}

.wb-topbar .wb-spacer { flex: 1; }

.wb-topbar label.small {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #4a3a2a;
}

#wb-msg {
  min-width: 160px;
  font-weight: 600;
  font-size: 0.85rem;
}
#wb-msg[data-kind="error"] { color: #b91c1c; }
#wb-msg[data-kind="success"] { color: #16a34a; }
#wb-msg[data-kind="info"] { color: #4a3a2a; }

/* ---------- left palette -------------------------------------------- */

.wb-palette {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 2px solid #2b2118;
  background: #fff;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.08);
  max-height: 78vh;
  overflow: auto;
}

.wb-palette__group {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b5c4a;
  margin-top: 8px;
  margin-bottom: 2px;
  font-weight: 700;
}
.wb-palette__group:first-child { margin-top: 0; }

.wb-palette__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 2px solid #2b2118;
  background: #fff;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: grab;
  user-select: none;
  transition: transform 80ms, background 80ms;
}
.wb-palette__item:hover { background: #f4f0e6; transform: translate(-1px, -1px); box-shadow: 2px 2px 0 #2b2118; }
.wb-palette__item:active { cursor: grabbing; }

/* ---------- canvas area --------------------------------------------- */

.wb-canvas-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.wb-canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 2px solid #2b2118;
  background: #fff;
}

.wb-canvas-toolbar label.small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: #4a3a2a;
}

.wb-canvas-toolbar input[type="number"] { width: 72px; }
.wb-canvas-toolbar input[type="color"] {
  width: 32px; height: 28px; padding: 0; border: 2px solid #2b2118; background: transparent;
}
.wb-canvas-toolbar select { font-family: inherit; padding: 4px 6px; }

.wb-zoom {
  display: inline-flex; align-items: center; gap: 4px;
}
.wb-zoom button {
  padding: 3px 8px; font-size: 0.85rem;
}
#wb-zoom-label { font-size: 0.78rem; min-width: 40px; text-align: center; }

.wb-canvas-wrap {
  position: relative;
  overflow: auto;
  min-height: 360px;
  max-height: 70vh;
  padding: 24px;
  background:
    linear-gradient(45deg, #ede6d7 25%, transparent 25%),
    linear-gradient(-45deg, #ede6d7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ede6d7 75%),
    linear-gradient(-45deg, transparent 75%, #ede6d7 75%) #f4f0e6;
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  border: 2px solid #2b2118;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.08);
}

.wb-canvas {
  position: relative;
  transform-origin: top left;
  margin: 0;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  outline: 1px dashed rgba(43, 33, 24, 0.25);
}

.wb-editor-root {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
}
.wb-editor-root.is-transparent {
  background:
    linear-gradient(45deg, #d5d0c4 25%, transparent 25%),
    linear-gradient(-45deg, #d5d0c4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d5d0c4 75%),
    linear-gradient(-45deg, transparent 75%, #d5d0c4 75%) #e8e2d3 !important;
  background-size: 12px 12px !important;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0 !important;
}

/* ---------- block shells (preview in builder) ----------------------- */

.wb-block {
  position: absolute;
  cursor: move;
  user-select: none;
  transition: outline-color 80ms;
  outline: 1px dashed transparent;
  outline-offset: 2px;
}
.wb-block:hover { outline-color: rgba(196, 92, 0, 0.5); }
.wb-block.is-selected { outline: 2px solid #c45c00; outline-offset: 2px; }
.wb-block__inner {
  position: relative;
  pointer-events: none;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: inherit;
  justify-content: inherit;
  align-items: inherit;
  gap: inherit;
}

.wb-divider-line { width: 100%; height: 2px; background: var(--lb-border, #2b2118); opacity: 0.7; }

/* selected: 8 tiny handles - n s e w + corners */
.wb-handle {
  position: absolute;
  background: #fff;
  border: 2px solid #c45c00;
  box-sizing: border-box;
  z-index: 5;
}
.wb-handle--n, .wb-handle--s { left: 50%; width: 10px; height: 10px; transform: translateX(-50%); }
.wb-handle--e, .wb-handle--w { top: 50%; width: 10px; height: 10px; transform: translateY(-50%); }
.wb-handle--n { top: -6px; cursor: n-resize; }
.wb-handle--s { bottom: -6px; cursor: s-resize; }
.wb-handle--e { right: -6px; cursor: e-resize; }
.wb-handle--w { left: -6px; cursor: w-resize; }
.wb-handle--ne { top: -6px; right: -6px; width: 10px; height: 10px; cursor: ne-resize; }
.wb-handle--nw { top: -6px; left: -6px; width: 10px; height: 10px; cursor: nw-resize; }
.wb-handle--se { bottom: -6px; right: -6px; width: 10px; height: 10px; cursor: se-resize; }
.wb-handle--sw { bottom: -6px; left: -6px; width: 10px; height: 10px; cursor: sw-resize; }

body.wb-grabbing, body.wb-grabbing * { cursor: grabbing !important; }
body.wb-resizing * { cursor: inherit; }
body.wb-panning, body.wb-panning * { cursor: grabbing !important; user-select: none; }

.wb-canvas-wrap.is-pannable { cursor: grab; }
.wb-canvas-wrap.is-pannable .wb-block { cursor: grab; }

.wb-pan-tip {
  margin-left: auto;
  font-size: 0.72rem;
  color: #6b5c4a;
  font-style: italic;
}

/* ---------- inspector ----------------------------------------------- */

.widget-builder__inspector {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.wb-card {
  padding: 12px;
  border: 2px solid #2b2118;
  background: #fff;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.06);
}

.wb-card__title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6b5c4a;
  margin-bottom: 8px;
  font-weight: 700;
}

.wb-widget-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
}
.wb-widget-list__item {
  display: flex;
  gap: 4px;
  align-items: stretch;
}
.wb-widget-list__btn {
  flex: 1;
  text-align: left;
  padding: 6px 8px;
  font-size: 0.82rem;
  background: #faf8f4;
  border: 2px solid #2b2118;
  cursor: pointer;
}
.wb-widget-list__item.is-active .wb-widget-list__btn {
  background: #c45c00; color: #fff;
}
.wb-widget-list__del {
  padding: 4px 8px;
  font-weight: 700;
  background: #fff;
  border: 2px solid #2b2118;
  color: #b91c1c;
  cursor: pointer;
}
.wb-widget-list__empty {
  font-size: 0.8rem; color: #6b5c4a; padding: 6px 0;
}

.wb-inspector { display: flex; flex-direction: column; gap: 8px; }
.wb-hint { font-size: 0.84rem; color: #6b5c4a; margin: 0; }

.wb-inspector__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.wb-inspector__name { font-weight: 700; font-size: 0.95rem; }
.wb-icon-btn {
  width: 28px; height: 28px; border: 2px solid #b91c1c; background: #fff;
  color: #b91c1c; font-weight: 700; font-size: 1rem; cursor: pointer; line-height: 1;
}
.wb-icon-btn:hover { background: #b91c1c; color: #fff; }

.wb-row {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.78rem; color: #4a3a2a;
}
.wb-row input[type="text"],
.wb-row input[type="number"],
.wb-row input[type="range"],
.wb-row select {
  width: 100%; font-family: inherit; box-sizing: border-box;
}
.wb-row input[type="color"] { width: 100%; height: 28px; padding: 0; border: 2px solid #2b2118; }
.wb-row__val { float: right; color: #2b2118; font-weight: 600; }
.wb-row--grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.wb-row--grid2 label {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 0.72rem; min-width: 0;
}
.wb-row--inline {
  flex-direction: row; align-items: center; gap: 8px;
  white-space: nowrap;
  font-size: 0.82rem;
}
.wb-row--inline input[type="checkbox"] {
  width: 16px; height: 16px; margin: 0; flex-shrink: 0;
}
.wb-row--actions {
  flex-direction: row; flex-wrap: wrap; gap: 6px; margin-top: 6px;
}
.wb-row--actions button {
  font-size: 0.78rem; padding: 4px 8px; flex: 1 1 auto;
  white-space: nowrap;
}

/* ---------- export panel -------------------------------------------- */

.wb-export {
  margin-top: 12px;
  padding: 12px 14px;
  border: 2px solid #2b2118;
  background: #faf8f4;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.08);
}
.wb-export__title { font-weight: 700; margin-bottom: 4px; }
.wb-export__hint { font-size: 0.85rem; color: #4a3a2a; margin: 0 0 10px; }
.wb-export__buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.wb-export__buttons button:disabled { opacity: 0.45; cursor: not-allowed; }
.wb-export__codes { display: grid; grid-template-columns: 1fr; gap: 8px; }
.wb-export__codes label { font-size: 0.78rem; color: #6b5c4a; font-weight: 600; }
.wb-export__codes pre {
  margin: 4px 0 0;
  padding: 8px 10px;
  font-size: 0.74rem;
  background: #fff;
  border: 2px solid #2b2118;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 100px;
  overflow: auto;
}
