/* =========================================================
   DSA Directory - Directory.css (DROP-IN v5.4)
   Updates included:
   - Groups: chevrons + clear open-state visuals
   - TOC active: uses --dsa-primary background
   - Section "Expand/Collapse Groups" buttons: consistent styling
   - Keeps v5.2/v5.3 styles intact otherwise
   ========================================================= */

.dsa-dir {
  --dsa-primary: #117d9a;
  --dsa-active-ink: #d1f37e;

  --dsa-bg: #ffffff;
  --dsa-text: #0f172a;
  --dsa-muted: rgba(15, 23, 42, 0.7);
  --dsa-border: rgba(0, 0, 0, 0.10);

  --dsa-radius: 14px;
  --dsa-shadow: 0 10px 28px rgba(0, 0, 0, 0.10);

  /* NEW tokens for group open styling */
  --dsa-open-bg: rgba(17, 125, 154, 0.08); /* derived from primary */
  --dsa-open-ring: rgba(17, 125, 154, 0.25);

  color: var(--dsa-text);
}

.dsa-dir * { box-sizing: border-box; }

.dsa-dir__flash {
  outline: 3px solid rgba(209, 243, 126, 0.55);
  outline-offset: 6px;
  border-radius: 14px;
}

/* Header */
.dsa-dir__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.dsa-dir__titlewrap { min-width: 0; }

.dsa-dir__title {
  font-size: 1.55rem;
  font-weight: 800;
  margin: 0;
  line-height: 1.15;
}

.dsa-dir__subtitle {
  margin: 6px 0 0;
  color: var(--dsa-muted);
  max-width: 70ch;
}

.dsa-dir__tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dsa-dir__search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dsa-dir__searchInput {
  min-width: 260px;
  border-radius: 999px;
  padding-right: 40px;
}

.dsa-dir__searchClear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 999px;
  width: 30px;
  height: 30px;
  line-height: 1;
  padding: 0;
}

.dsa-dir__adminBadge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--dsa-border);
  border-radius: 999px;
  padding: 7px 10px;
  font-weight: 700;
  background: rgba(0,0,0,0.03);
}

/* Admin bar */
.dsa-dir__adminBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--dsa-border);
  border-radius: var(--dsa-radius);
  background: rgba(0,0,0,0.02);
  margin: 10px 0 14px;
}

.dsa-dir__adminBarLeft,
.dsa-dir__adminBarRight {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* TOC */
.dsa-dir__tocPanel { margin: 12px 0 16px; }

.dsa-dir__tocPanelInner {
  border: 1px solid var(--dsa-border);
  border-radius: var(--dsa-radius);
  padding: 12px;
  background: #fff;
}

.dsa-dir__tocHead {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 10px;
}

.dsa-dir__tocTitle { font-weight: 800; }
.dsa-dir__tocHint { color: var(--dsa-muted); font-size: 0.95rem; }

.dsa-dir__tocGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

.dsa-dir__tocItem {
  display: flex;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--dsa-border);
  border-radius: 12px;
  padding: 10px 12px;
  text-decoration: none;
  color: inherit;
  background: #fff;
  transition: transform .12s ease, border-color .12s ease, background-color .12s ease, box-shadow .12s ease;
}

.dsa-dir__tocItem:hover {
  transform: translateY(-1px);
  border-color: rgba(0,0,0,0.18);
}

/* UPDATED: active uses your primary */
.dsa-dir__tocItem.is-active {
  border-color: rgba(0,0,0,0.0);
  background: var(--dsa-primary);
  color: var(--dsa-active-ink);
  box-shadow: 0 0 0 3px rgba(17, 125, 154, 0.18);
}

.dsa-dir__tocNum {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: rgba(0,0,0,0.05);
}

.dsa-dir__tocText { font-weight: 750; line-height: 1.15; }

/* Make TOC number readable on active */
.dsa-dir__tocItem.is-active .dsa-dir__tocNum {
  background: rgba(255,255,255,0.16);
  color: var(--dsa-active-ink);
}

/* Notices */
.dsa-dir__notice {
  border: 1px solid var(--dsa-border);
  border-radius: var(--dsa-radius);
  padding: 12px 14px;
  background: rgba(0,0,0,0.02);
}

.dsa-dir__notice--err {
  border-color: rgba(220, 53, 69, 0.35);
  background: rgba(220, 53, 69, 0.06);
}

/* Accordion */
.dsa-dir .accordion-item {
  border: 1px solid var(--dsa-border);
  border-radius: var(--dsa-radius);
  overflow: hidden;
  margin-bottom: 10px;
}

.dsa-dir .accordion-button {
  font-weight: 850;
  gap: 10px;
}

.dsa-dir__secNum {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: rgba(0,0,0,0.06);
}

.dsa-dir .accordion-button:not(.collapsed) {
  background: var(--dsa-primary);
  color: var(--dsa-active-ink);
}

.dsa-dir .accordion-button:not(.collapsed) .dsa-dir__secNum {
  background: rgba(255,255,255,0.16);
}

.dsa-dir__secBody { padding-top: 14px; }

.dsa-dir__secTop {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.dsa-dir__secIntro {
  border: 1px solid var(--dsa-border);
  border-radius: var(--dsa-radius);
  padding: 12px 14px;
  background: rgba(0,0,0,0.02);
}

/* Admin buttons row */
.dsa-dir__adminBtns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* NEW: make expand/collapse buttons stand out slightly but stay consistent */
.dsa-dir__adminBtns [data-act="groups-expand"],
.dsa-dir__adminBtns [data-act="groups-collapse"] {
  border-color: rgba(0,0,0,0.18) !important;
  background: rgba(0,0,0,0.03);
}
.dsa-dir__adminBtns [data-act="groups-expand"]:hover,
.dsa-dir__adminBtns [data-act="groups-collapse"]:hover {
  background: rgba(0,0,0,0.06);
}

/* Items stack */
.dsa-dir__itemStack { display: block; }
.dsa-dir__itemBody { margin-top: 8px; }

/* Links grid: multi-column only for link tiles */
.dsa-dir__linksGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin: 10px 0;
}

/* Link tile (no outer card) */
.dsa-dir__link {
  display: flex;
  gap: 10px;
  text-decoration: none;
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 12px;
  padding: 10px 12px;
  transition: transform .12s ease, border-color .12s ease;
  color: inherit;
  background: #fff;
}

.dsa-dir__link:hover {
  transform: translateY(-1px);
  border-color: rgba(0,0,0,0.20);
}

.dsa-dir__linkIcon {
  width: 44px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.06);
  font-weight: 900;
  user-select: none;
}

.dsa-dir__linkText {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.dsa-dir__linkTitle { font-weight: 850; }

.dsa-dir__linkUrl {
  margin-top: 3px;
  font-weight: 600;
  opacity: 0.7;
  font-size: 0.92rem;
  word-break: break-word;
}

/* Minimal wrapper only when needed (admin/buttons/body) */
.dsa-dir__linkWrap {
  display: block;
}

.dsa-dir__itemAdmin {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* Groups */
.dsa-dir__groupCard {
  border: 1px solid var(--dsa-border);
  border-radius: var(--dsa-radius);
  background: #fff;
  margin: 10px 0;
  overflow: hidden;
}

/* NEW: open-state ring/background for the whole group container */
.dsa-dir__groupCard[open] {
  border-color: rgba(17, 125, 154, 0.30);
  box-shadow: 0 0 0 3px var(--dsa-open-ring);
}

/* Summary */
.dsa-dir__groupHead {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}

.dsa-dir__groupHead::-webkit-details-marker { display: none; }

.dsa-dir__groupHeadLeft {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.dsa-dir__groupBadge {
  min-width: 44px;
  height: 32px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.06);
  font-weight: 900;
  user-select: none;
}

.dsa-dir__groupTitle {
  font-weight: 900;
  min-width: 0;
}

/* NEW: right side wrapper for chevron + admin */
.dsa-dir__groupHeadRight {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

/* NEW: Chevron visuals */
.dsa-dir__chev {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.05);
  transition: transform .14s ease, background-color .14s ease;
  flex: 0 0 auto;
}

.dsa-dir__chev i { font-size: 14px; }

/* Rotate chevron when open */
.dsa-dir__groupCard[open] .dsa-dir__chev {
  transform: rotate(90deg);
  background: rgba(17, 125, 154, 0.14);
}

/* NEW: open-state header tint */
.dsa-dir__groupCard[open] > .dsa-dir__groupHead {
  background: var(--dsa-open-bg);
}

/* NEW: open-state badge tint to match */
.dsa-dir__groupCard[open] .dsa-dir__groupBadge {
  background: rgba(17, 125, 154, 0.14);
}

/* Body */
.dsa-dir__groupBody {
  border-top: 1px solid var(--dsa-border);
  padding: 12px 14px 14px;
  background: rgba(0,0,0,0.01);
}

/* Modal */
.dsa-modal[hidden] { display: none !important; }
.dsa-modal { position: fixed; inset: 0; z-index: 99999; }
.dsa-modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }

.dsa-modal__dialog {
  position: relative;
  width: min(860px, calc(100% - 26px));
  margin: 40px auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--dsa-shadow);
  overflow: hidden;
}

.dsa-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--dsa-border);
}

.dsa-modal__title { font-weight: 900; font-size: 1.05rem; }

.dsa-modal__close {
  border: 1px solid var(--dsa-border);
  background: rgba(0,0,0,0.03);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  line-height: 1;
  font-size: 22px;
  cursor: pointer;
}

.dsa-modal__body {
  padding: 14px 16px;
  max-height: calc(85vh - 150px);
  overflow: auto;
}

.dsa-modal__foot {
  padding: 12px 16px;
  border-top: 1px solid var(--dsa-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dsa-modal__msg { color: var(--dsa-muted); font-weight: 600; }
.dsa-modal__msg--err { color: #dc3545; }

.dsa-modal__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Reorder UI */
.dsa-reorder__hint { color: var(--dsa-muted); margin-bottom: 10px; }
.dsa-reorder__list { display: block; margin-top: 10px; }

.dsa-reorder__row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 14px;
  padding: 10px 12px;
  background: #fff;
  margin: 8px 0;
  user-select: none;
}

.dsa-reorder__handle {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.06);
  cursor: grab;
}

.dsa-reorder__handle:active { cursor: grabbing; }

.dsa-reorder__label { flex: 1; min-width: 0; }
.dsa-reorder__title { font-weight: 850; line-height: 1.2; }
.dsa-reorder__meta { opacity: 0.65; font-size: 0.9rem; margin-top: 2px; }
.dsa-reorder__right { display: flex; gap: 8px; align-items: center; }

.dsa-reorder__row.is-over {
  outline: 2px dashed rgba(0,0,0,0.28);
  outline-offset: 2px;
}

.dsa-reorder__row.is-dragging {
  opacity: 0.75;
  border-color: rgba(0,0,0,0.22);
}

/* Reorder breadcrumb */
.dsa-reorder__bc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 4px 0 10px;
}

.dsa-reorder__bcItem {
  border: 1px solid var(--dsa-border);
  border-radius: 999px;
  padding: 6px 10px;
  background: #fff;
  font-size: 0.92rem;
  cursor: pointer;
}

.dsa-reorder__bcItem.is-active {
  background: rgba(0,0,0,0.06);
  border-color: rgba(0,0,0,0.18);
}

.dsa-reorder__bcSep { opacity: 0.55; }

/* Responsive */
@media (max-width: 768px) {
  .dsa-dir__header { flex-direction: column; align-items: stretch; }
  .dsa-dir__tools { justify-content: flex-start; }
  .dsa-dir__searchInput { min-width: 0; width: 100%; }
  .dsa-modal__dialog { margin: 16px auto; }

  /* keep group chevron + admin from wrapping weirdly */
  .dsa-dir__groupHeadRight { gap: 8px; }
}

/* --- DSA modal stacking --- */
.dsa-modal {
  position: fixed;
  inset: 0;
  z-index: 1200; /* your modal layer */
}

.dsa-modal__backdrop {
  position: absolute;
  inset: 0;
  z-index: 1200;
}

.dsa-modal__dialog {
  position: relative;
  z-index: 1210; /* above backdrop */
}

/* Prevent TinyMCE menus/dialogs from being clipped by modal containers */
.dsa-modal__dialog,
.dsa-modal__body {
  overflow: visible !important;
}

/* --- TinyMCE UI must be ABOVE custom modal/backdrop --- */
.tox-tinymce-aux,
.tox .tox-menu,
.tox .tox-dialog,
.tox .tox-pop,
.tox .tox-dropdown,
.tox .tox-swatches,
.tox .tox-tooltip,
.tox .tox-silver-sink {
  z-index: 200000 !important;
}
/* =========================================================
   v5.5 PATCH: keep outline-dark button text readable on hover
   (Bootstrap makes outline-dark go dark bg + white text; we override)
   ========================================================= */

/* Only inside the directory so we don't affect other site buttons */
.dsa-dir .btn-outline-dark {
  color: var(--dsa-text) !important;
  border-color: rgba(0,0,0,0.30) !important;
}

/* Hover/focus: light background + dark text (no white text) */
.dsa-dir .btn-outline-dark:hover,
.dsa-dir .btn-outline-dark:focus,
.dsa-dir .btn-outline-dark:active,
.dsa-dir .btn-outline-dark.active,
.dsa-dir .show > .btn-outline-dark.dropdown-toggle {
  color: var(--dsa-text) !important;
  background: rgba(0,0,0,0.06) !important;
  border-color: rgba(0,0,0,0.35) !important;
  box-shadow: none !important;
}

/* Accessible focus ring */
.dsa-dir .btn-outline-dark:focus-visible {
  outline: 3px solid rgba(17,125,154,0.25);
  outline-offset: 2px;
}
