:root {
  --cms-black: #111513;
  --cms-white: #fffdf6;
  --cms-accent: #7cff7c;
  --cms-warn: #ffcf5a;
  --cms-border: rgba(17, 21, 19, .16);
}

.cms-section-toggle {
  position: relative;
  z-index: 20;
  display: block;
  margin: 10px auto 24px;
  padding: 10px 16px;
  border: 1px solid #bdc5d3;
  border-radius: 8px;
  background: #fff;
  color: #343b49;
  font: 700 13px/1.2 system-ui, sans-serif;
  cursor: pointer;
}
.cms-section-disabled { opacity: .48 !important; outline: 3px dashed #dc6b6b !important; outline-offset: -3px; }
.cms-edit-mode .quiz-step { display: block !important; opacity: 1 !important; transform: none !important; margin-bottom: 28px !important; }
.cms-edit-mode .quiz-steps { display: block; }
.cms-edit-mode #projects-legacy { display: none !important; }

.cms-toolbar,
.cms-panel,
.cms-toast {
  font-family: Manrope, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.cms-toolbar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 99999;
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateX(-50%);
  padding: 10px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: rgba(17, 21, 19, .88);
  box-shadow: 0 20px 70px rgba(0,0,0,.28);
  color: var(--cms-white);
  backdrop-filter: blur(18px);
}

.cms-toolbar strong {
  padding: 0 8px;
  font-size: 13px;
  white-space: nowrap;
}

.cms-toolbar button,
.cms-panel button,
.cms-panel input,
.cms-panel textarea {
  font: inherit;
}

.cms-toolbar button,
.cms-panel button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 800;
}

.cms-toolbar button {
  padding: 10px 14px;
  background: rgba(255,255,255,.12);
  color: var(--cms-white);
}

.cms-toolbar button:hover {
  background: rgba(255,255,255,.2);
}

.cms-toolbar .cms-save {
  background: var(--cms-accent);
  color: var(--cms-black);
}

.cms-toolbar .cms-save[disabled] {
  opacity: .55;
  cursor: wait;
}

.cms-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 99999;
  width: min(360px, calc(100vw - 36px));
  padding: 16px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 22px;
  background: rgba(17, 21, 19, .9);
  color: var(--cms-white);
  box-shadow: 0 24px 80px rgba(0,0,0,.32);
  backdrop-filter: blur(18px);
}

.cms-panel[hidden] {
  display: none !important;
}

.cms-panel [hidden] {
  display: none !important;
}

.cms-panel h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.cms-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.cms-panel .cms-panel-close {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  margin: -7px -7px 0 0;
  padding: 0;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(255, 255, 255, .12);
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
}

.cms-panel .cms-panel-close:hover,
.cms-panel .cms-panel-close:focus-visible {
  background: rgba(255, 255, 255, .24);
}

.cms-panel p {
  margin: 0 0 12px;
  color: rgba(255,255,255,.72);
  font-size: 12px;
  line-height: 1.45;
}

.cms-panel label {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: rgba(255,255,255,.72);
  font-size: 12px;
  font-weight: 800;
}

.cms-panel input,
.cms-panel textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  background: rgba(255,255,255,.08);
  color: var(--cms-white);
  outline: none;
  padding: 10px 12px;
}

.cms-panel textarea {
  min-height: 94px;
  resize: vertical;
}

.cms-panel .cms-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.cms-history-fields {
  margin-top: 10px;
}

.cms-history-list {
  display: grid;
  gap: 8px;
  max-height: min(52vh, 460px);
  overflow: auto;
  padding-right: 2px;
}

.cms-history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 16px;
  background: rgba(255,255,255,.07);
}

.cms-history-item strong {
  display: block;
  font-size: 13px;
  color: var(--cms-white);
}

.cms-history-item span,
.cms-history-empty {
  display: block;
  margin: 4px 0 0;
  color: rgba(255,255,255,.62);
  font-size: 11px;
  line-height: 1.35;
}

.cms-history-item button {
  padding: 8px 10px;
  font-size: 12px;
  background: rgba(255,255,255,.14);
  color: var(--cms-white);
}

.cms-history-item:first-child button {
  background: var(--cms-warn);
  color: var(--cms-black);
}

.cms-panel button {
  padding: 10px 12px;
  background: var(--cms-accent);
  color: var(--cms-black);
}

.cms-panel .cms-secondary {
  background: rgba(255,255,255,.12);
  color: var(--cms-white);
}

.cms-toast {
  position: fixed;
  left: 50%;
  top: 18px;
  z-index: 100000;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--cms-black);
  color: var(--cms-white);
  box-shadow: 0 14px 60px rgba(0,0,0,.24);
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.cms-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(4px);
}

body.cms-editing [data-cms-text-key],
body.cms-editing [data-cms-image-key],
body.cms-editing [data-cms-link-key] {
  outline: 1.5px dashed rgba(124, 255, 124, .75);
  outline-offset: 4px;
}

body.cms-editing [data-cms-text-key]:hover,
body.cms-editing [data-cms-image-key]:hover,
body.cms-editing [data-cms-link-key]:hover,
body.cms-editing .cms-selected {
  outline: 3px solid var(--cms-accent) !important;
  outline-offset: 5px;
  cursor: text;
}

body.cms-editing [data-cms-image-key] {
  cursor: copy;
}

body.cms-editing [contenteditable="true"] {
  -webkit-user-modify: read-write-plaintext-only;
}

body.cms-editing [contenteditable="true"]:focus {
  outline: 3px solid var(--cms-warn) !important;
  outline-offset: 5px;
}

body.cms-editing a,
body.cms-editing button,
body.cms-editing .work-open {
  pointer-events: auto;
}

body.cms-editing .work-open {
  display: none;
}

body.cms-saving * {
  cursor: progress !important;
}

@media (max-width: 720px) {
  .cms-toolbar {
    left: 10px;
    right: 10px;
    bottom: 10px;
    transform: none;
    justify-content: space-between;
    border-radius: 20px;
    flex-wrap: wrap;
  }

  .cms-panel {
    top: 10px;
    right: 10px;
    width: calc(100vw - 20px);
  }
}

/* ========== REPEATER UI ========== */

body.cms-editing [data-cms-repeater-item] {
  position: relative;
}

body.cms-editing [data-cms-repeater] > [data-cms-repeater-item]::before {
  content: '';
  position: absolute;
  inset: -8px;
  border: 2px dashed rgba(124, 255, 124, .35);
  border-radius: 12px;
  pointer-events: none;
  z-index: 1;
}

body.cms-editing [data-cms-repeater] > [data-cms-repeater-item]:hover::before {
  border-color: rgba(124, 255, 124, .7);
}

.cms-repeater-controls {
  position: absolute;
  top: -14px;
  right: 8px;
  z-index: 9999;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--cms-black);
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
}

body.cms-editing [data-cms-repeater-item]:hover > .cms-repeater-controls,
body.cms-editing [data-cms-repeater-item]:focus-within > .cms-repeater-controls {
  display: flex;
}

.cms-repeater-controls button {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.14);
  color: var(--cms-white);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.cms-repeater-controls button:hover {
  background: rgba(255,255,255,.28);
}

.cms-repeater-controls .cms-repeater-remove:hover {
  background: #ff5a5a;
  color: #fff;
}

.cms-repeater-add {
  display: block;
  margin: 16px auto 0;
  padding: 12px 24px;
  border: 2px dashed rgba(124, 255, 124, .5);
  border-radius: 16px;
  background: rgba(124, 255, 124, .06);
  color: var(--cms-accent);
  font-family: Manrope, Inter, system-ui, sans-serif;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: all .2s ease;
}

.cms-repeater-add:hover {
  background: rgba(124, 255, 124, .14);
  border-color: var(--cms-accent);
}

.cms-repeater-add span {
  font-size: 18px;
  margin-right: 6px;
}

@media (max-width: 720px) {
  .cms-repeater-controls {
    top: -10px;
    right: 4px;
    padding: 3px 6px;
  }
  .cms-repeater-controls button {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }
}
