/**
 * Flex Layout Variables
 * Adjust these to change the look globally.
 */
:root {
  --flex-gap: 24px;
  --flex-editor-accent: #00a3ff;
  --flex-editor-danger: #ff4d4d;
  --flex-editor-bg: #1e1e1e;
  --flex-editor-border: #d1d9e0;
}

/* --- Frontend Layout --- */
.cl-flex-row {
  display: flex;
  flex-wrap: wrap;
  row-gap: var(--flex-gap);
  max-width: 100%;
  padding: 0 5px;
}

.cl-flex-col {
  position: relative;
  flex: 1 0 0%;
  box-sizing: border-box;
  min-width: 0;
}

/* 4-Breakpoint Responsive Grid Logic */

/* XS (Mobile Defaults) */
@media (max-width: 575px) {
  .cl-flex-row[data-xs="1"] > .cl-flex-col {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .cl-flex-row[data-xs="2"] > .cl-flex-col {
    flex: 0 0 50%;
    max-width: 50%;
  }
}

/* SM (Tablets) */
@media (min-width: 576px) and (max-width: 767px) {
  .cl-flex-row[data-sm="1"] > .cl-flex-col {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .cl-flex-row[data-sm="2"] > .cl-flex-col {
    flex: 0 0 50%;
    max-width: 50%;
  }
}

/* MD (Laptops) */
@media (min-width: 768px) and (max-width: 1199px) {
  .cl-flex-row[data-md="1"] > .cl-flex-col {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .cl-flex-row[data-md="2"] > .cl-flex-col {
    flex: 0 0 50%;
    max-width: 50%;
  }
  .cl-flex-row[data-md="3"] > .cl-flex-col {
    flex: 0 0 33.3333%;
    max-width: 33.3333%;
  }
  .cl-flex-row[data-md="4"] > .cl-flex-col {
    flex: 0 0 25%;
    max-width: 25%;
  }
}

/* LG (Desktops) */
@media (min-width: 1200px) {
  .cl-flex-row[data-lg="1"] > .cl-flex-col {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .cl-flex-row[data-lg="2"] > .cl-flex-col {
    flex: 0 0 50%;
    max-width: 50%;
  }
  .cl-flex-row[data-lg="3"] > .cl-flex-col {
    flex: 0 0 33.3333%;
    max-width: 33.3333%;
  }
  .cl-flex-row[data-lg="4"] > .cl-flex-col {
    flex: 0 0 25%;
    max-width: 25%;
  }
  .cl-flex-row[data-lg="5"] > .cl-flex-col {
    flex: 0 0 20%;
    max-width: 20%;
  }
  .cl-flex-row[data-lg="6"] > .cl-flex-col {
    flex: 0 0 16.6666%;
    max-width: 16.6666%;
  }
}

/* --- Editor UI (CKEditor 5 Specific) --- */
.ck-content .cl-flex-row {
  margin: 30px 0;
  margin-right: calc(var(--flex-gap) * -0.5);
  margin-left: calc(var(--flex-gap) * -0.5);
  padding: 40px 0 0 15px;
  border: 2px solid var(--flex-editor-border);
  border-radius: 8px;
  background: #fdfdfd;
}

.ck-content .cl-flex-col {
  padding: 20px !important;
  transition: border-color 0.2s ease;
  border: 1px dashed #cbd5e0 !important;
  background: #fff;
}

.ck-content .cl-flex-col:hover {
  border-color: var(--flex-editor-accent) !important;
}

/* Modern Control Bar */
.cl-flex-row-controls {
  position: absolute;
  z-index: 10;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  height: 32px;
  margin: 10px 0;
  padding: 0 12px;
  letter-spacing: 0.5px;
  color: #fff;
  border-radius: 6px 6px 0 0;
  background: var(--flex-editor-bg);
  font-family: sans-serif;
  font-size: 11px;
  gap: 15px;
}

.cl-flex-btn-edit {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: #fff;
  gap: 5px;
}
.cl-flex-btn-edit:hover {
  color: var(--flex-editor-accent);
}

.cl-flex-btn-delete {
  margin-left: auto;
  cursor: pointer;
  color: #ffa4a4;
  font-weight: bold;
}
.cl-flex-btn-delete:hover {
  color: var(--flex-editor-danger);
}

/* Add Column Button (Modern Style) */
.cl-flex-add-col-wrapper {
  flex: 0 0 100%;
  order: 999;
  padding: 10px 0;
}

.cl-flex-add-column-btn {
  width: 100%;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  color: #718096;
  border: 2px dashed var(--flex-editor-border);
  border-radius: 6px;
  background: #f8fafc;
  font-weight: 600;
}

.cl-flex-add-column-btn:hover {
  color: var(--flex-editor-accent);
  border-color: var(--flex-editor-accent);
  background: #edf2f7;
}

/* Circular Item Delete Icon */
.cl-flex-item-del {
  position: absolute;
  z-index: 15;
  top: -8px;
  right: -8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    opacity 0.2s ease;
  opacity: 0;
  color: white;
  border-radius: 50%;
  background: var(--flex-editor-danger);
  box-shadow: 0 2px 4px rgb(0, 0, 0, 0.2);
  font-size: 14px;
}

.cl-flex-col:hover .cl-flex-item-del {
  opacity: 1;
}

.cl-flex-item-del:hover {
  transform: scale(1.1);
  background: #c00;
}

/* Frontend safety: Hide Editor UI on live site */
.cl-flex-row-controls,
.cl-flex-add-col-wrapper,
.cl-flex-item-del {
  display: none;
}
.ck-content .cl-flex-row-controls,
.ck-content .cl-flex-add-col-wrapper,
.ck-content .cl-flex-item-del {
  display: flex;
}

/* 1. Target the Drupal Dialog Wrapper */
body .ui-dialog.ui-widget.ui-widget-content {
  z-index: 999999 !important;
}

/* 2. Target the Modal Backdrop */
body .ui-widget-overlay {
  z-index: 999998 !important;
}

/* 3. If CKEditor is in full screen, it often uses these classes */
.ck-body-wrapper {
  z-index: 999997 !important;
}

.ck5-column-layout-modal-top {
  z-index: 10001 !important;
}
