/* ============================================================================
   Universal Dashboard Customizer
   ----------------------------------------------------------------------------
   One engine that puts "Customize Dashboard" on every page which extends the
   shared site shell. The per-page hand-written customizers this replaces all
   repeated the same four ideas (toggle button, control bar, per-section
   controls, save/load/reset). Keeping them here means a fix lands everywhere.

   Sections:
     1. Launcher + control bar
     2. Per-item control strip
     3. Item states (hidden / disabled)
     4. Inline text editing affordances
     5. Item list side panel
     6. Table column chips
     7. Responsive
   ========================================================================== */

/* --- 1. Launcher + control bar ------------------------------------------- */

#cdz-launcher-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100040;
  font-family: "Segoe UI", system-ui, sans-serif;
}

#cdz-launcher-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #4338ca, #6d28d9);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(67, 56, 202, 0.38);
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}

#cdz-launcher-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(67, 56, 202, 0.48);
  filter: brightness(1.06);
}

#cdz-launcher-btn:focus-visible {
  outline: 3px solid rgba(67, 56, 202, 0.45);
  outline-offset: 3px;
}

#cdz-launcher-btn.cdz-on {
  background: linear-gradient(135deg, #be123c, #e11d48);
  box-shadow: 0 10px 26px rgba(225, 29, 72, 0.42);
}

/* The control bar docks to the top so it never covers page content. It must sit
   above the fixed site navbar (z-index 100000), otherwise it appears glued to
   the back of the nav when Customize mode is active. */
#cdz-control-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100010;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: linear-gradient(135deg, #e0e7ff, #ede9fe);
  border-bottom: 3px solid #4338ca;
  box-shadow: 0 8px 26px rgba(30, 27, 75, 0.22);
  font-family: "Segoe UI", system-ui, sans-serif;
}

#cdz-control-bar.cdz-open {
  display: flex;
}

#cdz-bar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #3730a3;
  font-size: 0.9rem;
}

#cdz-bar-title b {
  display: block;
  font-size: 0.95rem;
  font-weight: 800;
}

#cdz-bar-title span {
  font-size: 0.76rem;
  color: #4338ca;
}

#cdz-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

#cdz-bar-actions button,
#cdz-bar-actions label {
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  background: #fff;
  color: #3730a3;
  border-color: #c7d2fe;
  white-space: nowrap;
}

#cdz-bar-actions button:hover,
#cdz-bar-actions label:hover {
  background: #f5f3ff;
}

#cdz-bar-actions .cdz-primary {
  background: #4338ca;
  border-color: #3730a3;
  color: #fff;
}

#cdz-bar-actions .cdz-primary:hover {
  background: #3730a3;
}

#cdz-bar-actions .cdz-danger {
  color: #be123c;
  border-color: #fecdd3;
}

#cdz-bar-actions .cdz-danger:hover {
  background: #fff1f2;
}

/* The strip-based editing model pushes the real content down instead of using a
   fixed bar, so nothing here needs to reserve space for the chrome. The body
   hooks exist for page authors who want to react to the mode. */
body.cdz-active [contenteditable="true"] {
  cursor: text;
}

/* --- 2. Per-item control strip ------------------------------------------- */

.cdz-item-strip {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 6px 0;
  padding: 5px 10px;
  background: #eef2ff;
  border: 1.5px dashed #6366f1;
  border-radius: 8px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.72rem;
  color: #3730a3;
}

.cdz-active .cdz-item-strip {
  display: flex;
}

.cdz-item-strip .cdz-strip-label {
  font-weight: 800;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: #4338ca;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cdz-item-strip .cdz-strip-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.cdz-item-strip button {
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid #c7d2fe;
  background: #fff;
  color: #3730a3;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
}

.cdz-item-strip button:hover {
  background: #e0e7ff;
}

.cdz-item-strip button.cdz-off {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}

.cdz-item-strip button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Outline every managed item so the admin can see the hit area. */
.cdz-managed {
  outline: 1.5px dashed rgba(99, 102, 241, 0.45) !important;
  outline-offset: 3px;
}

/* --- 3. Item states ------------------------------------------------------ */

.cdz-hidden-item {
  display: none !important;
}

.cdz-disabled-item {
  opacity: 0.45 !important;
  filter: grayscale(0.6) !important;
  position: relative;
}

/* Lock interaction without breaking layout: the dimming above is the visual
   cue, these rules stop clicks/keys reaching the frozen controls. */
.cdz-disabled-item a,
.cdz-disabled-item button,
.cdz-disabled-item select,
.cdz-disabled-item textarea,
.cdz-disabled-item summary,
.cdz-disabled-item [role="button"] {
  pointer-events: none !important;
  cursor: not-allowed !important;
  user-select: none;
}

.cdz-disabled-badge {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 5;
  padding: 2px 8px;
  border-radius: 999px;
  background: #991b1b;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  pointer-events: none;
}

.cdz-active .cdz-disabled-item > .cdz-disabled-badge {
  display: block;
}

/* --- 4. Inline text editing (active ONLY when customizer is open) -------- */

.cdz-text-editable {
  outline: none;
}

.cdz-active .cdz-text-editable {
  outline: 2px dashed rgba(245, 158, 11, 0.7) !important;
  outline-offset: 2px;
  border-radius: 4px;
  cursor: text;
}

.cdz-active .cdz-text-editable:hover {
  background: rgba(253, 230, 138, 0.35);
}

.cdz-active .cdz-text-editable:focus {
  outline: 2px solid #f59e0b !important;
  background: rgba(253, 230, 138, 0.5);
}

.cdz-active .cdz-text-edited {
  position: relative;
}

.cdz-active .cdz-text-edited::after {
  content: "✎";
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 0.6rem;
  background: #f59e0b;
  color: #fff;
  border-radius: 999px;
  width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  pointer-events: none;
}

/* --- 5. Item list side panel --------------------------------------------- */

#cdz-panel {
  position: fixed;
  top: 62px;
  right: 18px;
  bottom: 18px;
  width: min(390px, calc(100vw - 36px));
  z-index: 100020;
  display: none;
  flex-direction: column;
  background: #fff;
  border: 1px solid #c7d2fe;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.78rem;
}

#cdz-panel.cdz-open {
  display: flex;
}

#cdz-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
  border-bottom: 1px solid #c7d2fe;
  border-radius: 14px 14px 0 0;
}

#cdz-panel-head strong {
  color: #3730a3;
  font-size: 0.85rem;
}

#cdz-panel-head button {
  border: none;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  color: #4338ca;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 6px;
}

#cdz-panel-head button:hover {
  background: rgba(67, 56, 202, 0.12);
}

#cdz-panel-tools {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid #eef2f7;
  flex-wrap: wrap;
  align-items: center;
}

#cdz-panel-tools input[type="search"] {
  flex: 1 1 140px;
  padding: 6px 9px;
  border: 1px solid #c7d2fe;
  border-radius: 7px;
  font-size: 0.75rem;
}

#cdz-panel-tools button {
  padding: 6px 10px;
  border: 1px solid #c7d2fe;
  border-radius: 7px;
  background: #fff;
  color: #3730a3;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

#cdz-panel-tools button:hover {
  background: #eef2ff;
}

#cdz-panel-stats {
  padding: 7px 12px;
  font-size: 0.7rem;
  color: #64748b;
  background: #f8fafc;
  border-bottom: 1px solid #eef2f7;
}

#cdz-item-list {
  flex: 1 1 auto;
  overflow: auto;
  margin: 0;
  padding: 6px 8px 12px;
  list-style: none;
}

#cdz-item-list li {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 6px 7px;
  border-radius: 8px;
  border: 1px solid transparent;
}

#cdz-item-list li:hover {
  background: #f8fafc;
  border-color: #e2e8f0;
}

#cdz-item-list li.cdz-group-head {
  margin-top: 8px;
  padding: 8px 7px 4px 7px;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #6366f1;
  border: none;
}

#cdz-item-list li.cdz-is-hidden {
  opacity: 0.5;
}

#cdz-item-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
  cursor: pointer;
}

#cdz-item-list .cdz-row-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #334155;
}

#cdz-item-list .cdz-row-vis,
#cdz-item-list .cdz-row-en {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.62rem;
  color: #64748b;
  white-space: nowrap;
}

#cdz-item-list .cdz-row-actions {
  display: flex;
  gap: 3px;
  flex: 0 0 auto;
}

#cdz-item-list .cdz-row-actions button {
  border: 1px solid #c7d2fe;
  background: #fff;
  color: #4338ca;
  border-radius: 5px;
  font-size: 0.66rem;
  padding: 2px 5px;
  cursor: pointer;
  line-height: 1.3;
}

#cdz-item-list .cdz-row-actions button:hover {
  background: #eef2ff;
}

#cdz-empty {
  padding: 18px 12px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.75rem;
}

/* --- 6. Table column chips ----------------------------------------------- */

.cdz-col-strip {
  display: none;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  margin: 0 0 6px 0;
  padding: 5px 10px;
  background: #ecfdf5;
  border: 1.5px dashed #10b981;
  border-radius: 8px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.7rem;
  color: #065f46;
}

.cdz-active .cdz-col-strip {
  display: flex;
}

.cdz-col-strip > b {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.cdz-col-strip label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #a7f3d0;
  cursor: pointer;
  max-width: 190px;
}

.cdz-col-strip label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Column visibility is applied per-cell by the engine (inline display), so that
   hiding column 3 of a 7 column table leaves the other six intact. */

/* --- 7. Responsive ------------------------------------------------------- */

@media (max-width: 820px) {
  #cdz-control-bar {
    padding: 8px 10px;
  }

  #cdz-bar-title span {
    display: none;
  }

  #cdz-panel {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-height: 62vh;
  }

  #cdz-launcher-btn span {
    display: none;
  }
}
