/* styles.css */

/* Global layout */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Geist', sans-serif;
  color: #333;
  background-color: #f4f7f6;
}
#builder-wrapper {
  display: flex;
  flex-direction: row;
  height: 100vh;
  width: 100vw;
  align-items: stretch;
}

/* Sidebar layout improvements */
#sidebar {
  width: 220px;
  height: 100vh;
  background: #fff;
  padding: 7px 7px 0 7px;
  border-right: 1px solid #e0e0e0;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.045);
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  box-sizing: border-box;
  flex-shrink: 0;
}

/* Sidebar section styles */
.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-top: 1px solid #eee;
  padding-top: 6px;
  margin-bottom: 1px;
}
.sidebar-section:first-child {
  border-top: none;
  padding-top: 0;
}
.sidebar-section h4 {
  margin: 0 0 1px 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: #555;
}

.add-elements-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 1px;
}
.add-elements-grid .tool-btn {
  flex: 1 0 28%;
  min-width: 0;
  font-size: 12px;
  padding: 6px 2px;
  margin: 0;
}

.sidebar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  margin-top: 0;
}
.compact-row label {
  min-width: 27px;
  max-width: 37px;
  font-size: 11px;
  margin: 0 2px 0 0;
  white-space: nowrap;
}
.compact-row select,
.compact-row input[type="number"],
.compact-row input[type="color"] {
  min-width: 0;
  padding: 2px 4px;
  font-size: 12px;
  height: 24px;
}
.compact-row input[type="color"] {
  width: 28px;
  padding: 0;
  min-width: 28px;
}
.compact-row .btn {
  height: 25px;
  min-width: 0;
  font-size: 12px;
  padding: 4px 6px;
  margin: 0;
  border-radius: 4px;
}
.sidebar-section label {
  font-size: 11px;
  font-weight: 500;
  margin-bottom: 0;
  color: #444;
  margin-top: 0;
}
.sidebar-row select:disabled,
.sidebar-row input:disabled {
  opacity: 0.4;
  pointer-events: none;
  background: #f3f3f3;
}
#sidebar .sidebar-row:last-child {
  margin-bottom: 2px;
}
#sidebar .btn {
  padding: 5px 8px;
  border: 1px solid #ccc;
  background-color: #f8f8f8;
  color: #333;
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  transition: background-color 0.2s, border-color 0.2s;
  white-space: nowrap;
  text-align: left;
  box-sizing: border-box;
}
#sidebar .btn:hover {
  background-color: #eee;
  border-color: #bbb;
}
#sidebar .btn:active {
  background-color: #ddd;
  border-color: #aaa;
}
#sidebar .breakpoint-btn.active,
#sidebar #toggle-grid-btn.active {
  background-color: #007bff;
  color: #fff;
  border-color: #0056b3;
  font-weight: bold;
}
#breakpoint-switcher {
  display: flex;
  gap: 4px;
}
#breakpoint-switcher .btn {
  flex-grow: 1;
  padding: 5px 3px;
  font-size: 11px;
  min-width: 0;
  border-radius: 4px;
}

/* Compact font size control row */
.font-size-control {
  display: flex;
  align-items: center;
  gap: 4px;
}
.font-size-control .font-size-input {
  width: 34px;
  padding: 4px 2px;
  border: 1px solid #ccc;
  border-radius: 4px;
  text-align: center;
  font-size: 12px;
  box-sizing: border-box;
  min-width: 27px;
  height: 23px;
}
.font-size-control .font-adjust-btn {
  width: 23px;
  height: 23px;
  padding: 0;
  text-align: center;
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1;
  border-radius: 4px;
}

/* Global controls styling small */
#global-settings select,
#global-settings input[type="color"] {
  width: 100%;
  padding: 3px 4px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 12px;
  height: 23px;
  min-width: 0;
}
#global-settings input[type="color"] {
  padding: 0;
}

/* Canvas container */
#canvas-container {
  position: relative;
  flex-grow: 1;
  height: 100vh;
  overflow: auto;
  padding: 15px;
  background-color: #e0e4e8;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

/* Canvas */
#canvas {
  max-width: 100%;
  max-height: 100%;
  position: relative;
  margin: 0;
  min-height: 300px;
  overflow: hidden;
  border: 1px solid #b0b8bf;
  background-color: #fff;
  padding: 20px;
  box-sizing: border-box;
  background-image: none;
  background-size: auto;
  background-position: 0px 0px, 0px 0px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: width 0.3s ease;
  transform-origin: center center;
  flex-shrink: 0;
}

/* Preview sizes */
.preview.SM { width: 375px; }
.preview.MD { width: 768px; }
.preview.LG { width: 1024px; }
.preview.XL { width: 1440px; }

/* Elements */
.element {
  position: relative;    /* <-- Grid item, not absolute! */
  border: 1px dashed transparent;
  box-sizing: border-box;
  cursor: grab;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: transparent;
  line-height: 1;
}
.element:hover {
  border-color: #99c0ff;
}
.element.selected {
  border: 2px solid #007bff;
  background: transparent;
  box-shadow: 0 0 8px rgba(0, 123, 255, 0.3);
  z-index: 10;
}
.delete-btn {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  background-color: #dc3545;
  color: #fff;
  border: 1px solid #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 11;
}
.element.selected .delete-btn {
  opacity: 1;
}
.delete-btn:hover {
  background-color: #c82333;
}
.element h1,
.element h2,
.element h3,
.element h4,
.element p,
.element button {
  margin: 0;
  padding: 0;
  /* REMOVE user-select: none ! */
}

.element img {
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Button styling within elements */
.element button {
  width: 100%;
  height: 100%;
  border: none;
  background-color: #007bff;
  color: #fff;
  cursor: pointer;
  font-size: inherit;
  padding: 5px 10px;
  box-sizing: border-box;
  text-align: center;
}
.element button:hover {
  background-color: #0056b3;
}

/* Snap helper lines */
#snap-line-x, #snap-line-y {
  position: absolute;
  pointer-events: none;
  background: rgba(41,123,255,0.7);
  border-radius: 1px;
  z-index: 99999;
  display: none;
}
#snap-line-x {
  left: 0;
  height: 2px;
  width: 100%;
}
#snap-line-y {
  top: 0;
  width: 2px;
  height: 100%;
}

#canvas-container.pan-enabled {
  cursor: grab;
}
#canvas-container.pan-enabled.panning {
  cursor: grabbing !important;
}
#canvas-container.pan-enabled #canvas {
  cursor: auto;
}

#canvas-zoom-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10010;
  display: flex;
  flex-direction: row;
  align-items: center;
  background: #fff;
  border: 1px solid #e3e3e3;
  box-shadow: 0 4px 16px rgba(0,0,0,0.09);
  border-radius: 22px;
  padding: 5px 10px 5px 10px;
  gap: 5px;
  min-width: 96px;
  max-width: 180px;
}
#canvas-zoom-panel button {
  border: none;
  background: #f6f8fb;
  color: #222;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 15px;
  line-height: 1;
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
  transition: background 0.18s;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#canvas-zoom-panel button:active {
  background: #e8eeff;
}
#canvas-zoom-panel button:disabled {
  background: #eee;
  color: #aaa;
  cursor: not-allowed;
}
#canvas-zoom-panel #canvas-zoom-reset-btn {
  width: 40px;
  min-width: 24px;
  border-radius: 12px;
  font-size: 11px;
  color: #555;
  margin-left: 4px;
  background: #eef6ff;
  font-weight: 500;
  display: none;
}
#canvas-zoom-panel #canvas-zoom-display {
  min-width: 28px;
  text-align: center;
  font-size: 13px;
  color: #222;
  font-weight: 600;
  background: none;
}

/* Resizers (horizontal right, vertical bottom, top, left added) */
.resizer-horiz, .resizer-vert, .resizer-top, .resizer-left {
  position: absolute;
  background: #007bff;
  border: 1.5px solid #fff;
  border-radius: 4px;
  box-shadow: 0 0 5px rgba(0,0,0,0.18);
  opacity: 0;
  transition: opacity 0.19s;
  z-index: 11;
}
.element.selected .resizer-horiz,
.element.selected .resizer-vert,
.element.selected .resizer-top,
.element.selected .resizer-left { opacity: 1; }
.resizer-horiz {
  right: -8px;
  top: 50%;
  width: 13px;
  height: 28px;
  margin-top: -14px;
  cursor: ew-resize;
}
.resizer-vert {
  bottom: -8px;
  left: 50%;
  height: 13px;
  width: 28px;
  margin-left: -14px;
  cursor: ns-resize;
}
/* Top resizer handle (horizontal blue bar above) */
.resizer-top {
  left: 50%;
  top: -8px;
  height: 13px;
  width: 28px;
  margin-left: -14px;
  cursor: ns-resize;
}
/* Left resizer handle (vertical blue bar left) */
.resizer-left {
  left: -8px;
  top: 50%;
  width: 13px;
  height: 28px;
  margin-top: -14px;
  cursor: ew-resize;
}
.resizer { display: none !important; }

/* Exported container styles -- for preview and export, updated for new grid */
/* These are kept in sync for builder preview and export! */
.container {
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: 12px;
  gap: 12px;
  padding: 20px;
  box-sizing: border-box;
  line-height: 1;
}
.container h1, .container h2, .container h3, .container h4, .container p, .container img, .container button { line-height: 1; margin: 0; }
.container img, [data-export-img] { width: 100%; height: 100%; min-height: 0; min-width: 0; object-fit: cover; display: block; }
.container button { padding: 5px 10px; border: none; background-color: #007bff; color: #fff; cursor: pointer; font-size: inherit; box-sizing: border-box; text-align: center; width: 100%; height: 100%; }
@media (min-width: 768px) { .container { grid-template-columns: repeat(24, 1fr); grid-auto-rows: 12px; } }
@media (min-width: 1024px) { .container { grid-template-columns: repeat(24, 1fr); grid-auto-rows: 12px; } }
@media (min-width: 1440px) { .container { grid-template-columns: repeat(24, 1fr); grid-auto-rows: 12px; } }

/* styles.css (only Z-index toolbar and relevant control enhancements) */

/* styles.css (append to existing file for Z-index controls, or update the rules as needed) */

/* --- Z-Index Sidebar Controls --- */
.zindex-adjust-btn {
  width: 23px;
  height: 23px;
  padding: 0;
  text-align: center;
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1;
  border-radius: 4px;
  border: 1px solid #ccc;
  background-color: #f8f8f8;
  color: #333;
  margin-right: 1px;
  margin-left: 1px;
  transition: background-color 0.2s, border-color 0.2s;
}
.zindex-adjust-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #eee;
}
.zindex-adjust-btn:hover:not(:disabled) {
  background-color: #eee;
  border-color: #bbb;
}
.zindex-adjust-btn:active:not(:disabled) {
  background-color: #ddd;
  border-color: #aaa;
}

.zindex-input {
  width: 40px;
  padding: 4px 2px;
  border: 1px solid #ccc;
  border-radius: 4px;
  text-align: center;
  font-size: 12px;
  box-sizing: border-box;
  min-width: 28px;
  height: 23px;
}

#zindex-toolbar-row {
  margin-bottom: 2px;
}
.element[data-type="hr"] {
  min-height: 12px;
  max-height: 64px; /* Allow horizontal resize for width, not for height */
  cursor: row-resize;
  /* Ensure relative position so absolute <hr> is centered */
  position: absolute;
}

/* Always center the HR inside its parent */
.element[data-type="hr"] hr {
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
  height: 2px !important;
  min-height: 2px !important;
  max-height: 2px !important;
  border: none;
  background: #2b3545;
  border-radius: 2px;
  margin: 0;
  display: block;
  opacity: 0.65;
  pointer-events: none;  /* Still allows .element to be interacted with */
}

/* Give the HR element an outline on select, inherit from .element.selected */
.element.selected[data-type="hr"] hr {
  box-shadow: 0 0 0 2px #286ff9;
  opacity: 0.9;
}

/* Inline Image Edit Popover */
.cf-img-edit-popover {
  position: absolute;
  z-index: 10010;
  min-width: 240px;
  /* The rest set from JS for responsiveness */
  font-family: inherit !important;
}
.cf-img-edit-popover label {
  font-size: 13px;
  font-weight: 500;
  color: #394257;
  margin-bottom: 3px;
  display: block;
}
.cf-img-edit-popover input[type="url"], .cf-img-edit-popover input[type="text"] {
  width: 100%;
  padding: 5px 8px;
  margin-top: 2.5px;
  margin-bottom: 6.5px;
  border: 1.2px solid #b2c4f8;
  border-radius: 4px;
  font-size: 14px;
  background: #fcfcff;
  color: #212529;
  box-sizing: border-box;
  transition: border 0.17s;
}
.cf-img-edit-popover input:focus {
  outline: none;
  border-color: #2471fd;
  background: #f3f6ff;
}
.cf-img-edit-row {
  display: flex;
  gap: 11px;
  align-items: center;
  justify-content: flex-end;
}
.cf-img-edit-popover button {
  padding: 4px 17px;
  border: none;
  border-radius: 5px;
  font-size: 14px;
  background: #0077ff;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(74,109,196,0.04);
  transition: background 0.17s;
}
.cf-img-edit-popover button.cf-img-edit-cancel {
  background: #b1b7c8;
  color: #fff;
}
.cf-img-edit-popover button:active {
  background: #1357ae;
}
.cf-img-edit-popover button.cf-img-edit-cancel:active {
  background: #7d879a;
}

.cf-text-edit-popover {
  position: absolute;
  z-index: 10020;
  min-width: 240px;
  font-family: inherit !important;
}

.cf-text-edit-popover label {
  font-size: 14px;
  font-weight: 600;
  color: #eb850c;
  margin-bottom: 3px;
  display: block;
}

.cf-text-edit-popover input[type="text"], .cf-text-edit-popover textarea {
  width: 100%;
  padding: 7px 9px;
  margin-top: 2.5px;
  margin-bottom: 7px;
  border: 1.2px solid #f1be4e;
  border-radius: 5px;
  font-size: 16px;
  background: #fcfcff;
  color: #212529;
  box-sizing: border-box;
  transition: border 0.18s;
  font-family: inherit;
}
.cf-text-edit-popover textarea { min-height: 74px; resize: none; }

.cf-text-edit-popover input:focus, .cf-text-edit-popover textarea:focus {
  outline: none;
  border-color: #ffa600;
  background: #fffbe6;
}
.cf-text-edit-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}
.cf-text-edit-popover button {
  padding: 4px 20px;
  border: none;
  border-radius: 5px;
  font-size: 15px;
  background: #ffa600;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.14s;
}
.cf-text-edit-popover button.cf-text-edit-cancel {
  background: #c7d1dd;
  color: #222;
}
.cf-text-edit-popover button:active {
  background: #e69f14;
}
.cf-text-edit-popover button.cf-text-edit-cancel:active {
  background: #b5b5b5;
}