/* =====================================================
   admin.css  -  Admin CMS panel
   Split from gpnotesv4.css (original lines 2134-2442)
   ===================================================== */

#adminCMSContainer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background-color: var(--color2);
  /* Uses your dark/light theme background */
  z-index: 9999;
  /* Ensures it sits above the main menu and floating buttons */
  overflow: hidden;
  display: none;
  /* Kept hidden until the .admin-open class is added */
  flex-direction: column;
  /* Header on top, content fills the remaining space */
}

#adminCMSContainer.admin-open {
  display: flex;
}


/* ── Admin header: search bar fills the top, Close pinned to the right ── */
.admin-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  padding: 8px 12px;
  box-sizing: border-box;
  background: var(--headerColor);
  color: white;
  flex-shrink: 0;
  /* don't let the column-flex overlay compress the header */
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.admin-header .admin-close-btn {
  grid-column: 2;
  justify-self: end;
  margin: 0;
  padding: 8px 14px;
  justify-content: center;
  font-size: 13px;
  white-space: nowrap;
}

/* Search bar sits where the title used to be: left side, flexible width */
#nodeSearchBar {
  display: none;
  /* JS flips this to flex when a topic is opened */
  grid-column: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
  width: 100%;
  padding: 4px;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
}

#nodeSearchBar:focus-within {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
}

#nodeSearchInput {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border: none;
  outline: none;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 13px;
}

#nodeSearchInput::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

#searchMatchCount {
  flex-shrink: 0;
  min-width: 40px;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
  white-space: nowrap;
}

.admin-search-nav {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
}

.admin-search-nav:active {
  background: rgba(255, 255, 255, 0.32);
}

@media (min-width: 768px) {
  .admin-header {
    padding: 8px 16px;
  }

  #nodeSearchBar {
    max-width: 480px;
  }
}


#adminTopicSidebar h3 {
  margin-top: 0;
}

#adminTopicSearch {
  width: 100%;
  padding: 10px;
  margin-bottom: 15px;
  margin-top: 15px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #ffffff2a;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--color1);
  box-sizing: border-box;
}

#adminTopicSearch::placeholder {
  color: #c9c9c9;
}

#adminTopicSearch:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.3);
}

.admin-editor-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-wrap: wrap;
  min-height: 36px;
  margin-bottom: 10px;
}

#editingTitle {
  margin: 0;
  line-height: 1.3;
}

.editor-mode-toggle {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid rgba(128, 128, 128, 0.3);
  border-radius: 999px;
  background: var(--color4);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.22);
  user-select: none;
}

.editor-mode-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc((100% - 6px) / 2);
  height: calc(100% - 6px);
  border-radius: 999px;
  background: var(--submitColor);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 180ms ease;
}

.editor-mode-toggle[data-mode="json"] .editor-mode-thumb {
  transform: translateX(100%);
}

.editor-mode-btn {
  position: relative;
  z-index: 1;
  min-width: 64px;
  padding: 7px 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--color3);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color 180ms ease;
}

.editor-mode-btn:hover {
  color: var(--color1);
}

.editor-mode-btn.is-active,
.editor-mode-btn.is-active:hover {
  color: #fff;
}

.editor-mode-btn:focus-visible {
  outline: 2px solid var(--color1);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .editor-mode-thumb,
  .editor-mode-btn {
    transition: none;
  }
}

#jsonEditor {
  display: none;
  width: 100%;
  min-height: 55vh;
  box-sizing: border-box;
  padding: 12px;
  border: 1px solid var(--color3);
  border-radius: 10px;
  background: var(--color4);
  color: var(--color1);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
  tab-size: 2;
  resize: vertical;
  white-space: pre;
  overflow: auto;
}

#jsonEditor:focus {
  outline: none;
  border-color: var(--submitColor);
}

.admin-json-tip {
  display: none;
  margin-top: -6px;
}

.admin-tip {
  font-size: 12px;
  font-style: italic;
  color: var(--color3);
  margin-top: -10px;
  margin-bottom: 20px;
}

.admin-editor-actions {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 0;
  background: var(--color2);
  box-shadow: 0 8px 12px -10px rgba(0, 0, 0, 0.55);
}

.admin-editor-actions .admin-btn {
  flex: 1;
  justify-content: center;
}

#saveChangesBtn {
  display: none;
}

#cmDelete {
  color: #ff6b6b;
  font-weight: bold;
}

.admin-layout {
  flex: 1 1 auto;
  min-height: 0;
  /* Enables internal scrolling instead of page-level clipping */
  display: flex;
  gap: 20px;
  margin-top: 0;
  flex-direction: row;
  padding: 20px;
  color: var(--color1);
}

#adminTopicSidebar {
  flex: 1;
  min-height: 0;
  /* IMPORTANT: lets the flex child shrink so overflow-y:auto works */
  border-right: 1px solid var(--color3);
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 15px;
}

#adminEditorArea {
  flex: 2;
  margin-top: 50px;
  min-height: 0;
  /* IMPORTANT: lets the flex child shrink so overflow-y:auto works */
  padding-left: 10px;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-new-topic-btn {
  width: 100%;
  margin-bottom: 12px;
  text-align: center;
}

#newTopicForm {
  display: none;
  margin: 0 0 15px;
  padding: 12px;
  border: 1px solid var(--color3);
  border-radius: 10px;
  background: var(--color4);
}

#newTopicForm h4 {
  margin: 0 0 10px;
  font-size: 14px;
}

.admin-field {
  display: block;
  margin-bottom: 10px;
}

.admin-field > span {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--color3);
}

.admin-field input,
.admin-field select {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #ffffff2a;
  color: var(--color1);
  font-size: 13px;
}

.admin-field input:focus,
.admin-field select:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.3);
}

.admin-field select option {
  color: #111;
}

.admin-form-error {
  margin: 0 0 10px;
  font-size: 12px;
  color: #ff6b6b;
}

.admin-form-error:empty {
  display: none;
}

.admin-form-actions {
  display: flex;
  gap: 8px;
}

.admin-form-actions .admin-btn {
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
}

.admin-btn-secondary {
  background: var(--color3);
}

.admin-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.topic-list-item {
  cursor: pointer;
  padding: 10px;
  border-bottom: 1px solid var(--color3);
}

.topic-list-item:hover {
  background: var(--color4);
}

.admin-btn {
  background: var(--submitColor);
  color: white;
  padding: 10px 20px;
  border-radius: 5px;
  font-weight: bold;
  border: none;
  cursor: pointer;
  width: auto;
}




#backToTopicsBtn {
  display: none;
  background-color: var(--color3);
}

.context-menu {
  display: none;
  position: fixed;
  background: var(--color2);
  border: 1px solid var(--color3);
  border-radius: 8px;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  padding: 5px;
  flex-direction: column;
  min-width: 160px;
  /* Never taller/wider than the screen: scroll inside instead */
  max-height: calc(100vh - 16px);
  max-height: calc(100dvh - 16px);
  max-width: calc(100vw - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.context-menu button {
  background: none;
  border: none;
  color: var(--color1);
  text-align: left;
  padding: 10px;
  cursor: pointer;
  width: 100%;
  border-radius: 4px;
}

.context-menu button:hover {
  background: var(--color4);
}

.context-menu button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.context-menu button:disabled:hover {
  background: none;
}

#cmCut {
  color: #f0a04b;
}

#cmCopy,
#cmPasteSibling,
#cmPasteChild {
  color: #6fd08c;
}

@media (max-width: 768px) {
  .admin-layout {
    flex-direction: column;
    padding: 10px;
  }

  #adminTopicSidebar {
    height: 100%;
    border-right: none;
  }

  #adminEditorArea {
    display: none;
    padding-left: 0;
    padding-top: 0;
    height: 100%;
  }

  .admin-layout.editing-active #adminTopicSidebar {
    display: none;
  }

  .admin-layout.editing-active #adminEditorArea {
    display: block;
  }

  #backToTopicsBtn {
    display: block;
  }
}

/* ===== Homepage redesign: Explore cards + Category grid ===== */
