/* ============================================================
   RankFlow - WP Connector  |  Frontend styles
   TOC (collapsible table of contents) + FAQ (accordion + schema)

   Theme system
   ─────────────────────────────────────────────────────────────
   Theme styles live in assets/styles/toc/ and assets/styles/faq/.
   Active theme CSS is loaded per component.

   Color overrides are applied via CSS custom-properties injected
   into :root by the plugin's admin settings page (WP Dashboard →
   Settings → RankFlow Styles).
   ============================================================ */


/* ─────────────────────────────────────────────────────────────
   CSS custom-property defaults
   (Overridden per theme below; user colour-picks override both)
   ───────────────────────────────────────────────────────────── */
:root {
  /* ── TOC colors ── */
  --cw-toc-bg:           #f8fafc;
  --cw-toc-border:       #e2e8f0;
  --cw-toc-text:         #64748b;
  --cw-toc-link:         #4f46e5;
  --cw-toc-link-hover:   #3730a3;
  --cw-toc-accent:       #4f46e5;
  --cw-toc-marker:       inherit;

  /* ── TOC typography ── */
  --cw-toc-font-family:  inherit;
  --cw-toc-font-size:    16px;
  --cw-toc-title-size:   14px;
  --cw-toc-title-weight: 700;
  --cw-toc-line-height:  1.5;

  /* ── TOC layout ── */
  --cw-toc-radius:       10px;
  --cw-toc-border-width: 1px;
  --cw-toc-ol-indent:    1.1rem;

  /* ── FAQ colors ── */
  --cw-faq-bg:           #ffffff;
  --cw-faq-border:       #e2e8f0;
  --cw-faq-text:         #475569;
  --cw-faq-accent:       #4f46e5;
  --cw-faq-question:     inherit;
  --cw-faq-open-q:       #4f46e5;
  --cw-faq-open-bg:      inherit;
  --cw-faq-title-color:  inherit;

  /* ── FAQ typography ── */
  --cw-faq-font-family:      inherit;
  --cw-faq-title-size:       14px;
  --cw-faq-title-weight:     700;
  --cw-faq-question-size:    16px;
  --cw-faq-question-weight:  600;
  --cw-faq-answer-size:      16px;
  --cw-faq-line-height:      1.7;

  /* ── FAQ layout ── */
  --cw-faq-radius:       8px;
  --cw-faq-border-width: 1px;
  --cw-faq-item-gap:     0.5rem;
}


/* ═══════════════════════════════════════════════════════════════
   TABLE OF CONTENTS
   ═══════════════════════════════════════════════════════════════ */

/* ── Base structural rules (all themes) ── */
.cw-toc {
  margin: 0 0 2rem 0;
  overflow: hidden;
  padding: 0;
  font-family: var(--cw-toc-font-family, inherit);
}

.cw-toc details { padding: 0; }

/* Force correct open/closed state regardless of theme CSS overrides.
   Some WP themes reset <details> in ways that break native disclosure. */
.cw-toc details > .cw-toc__body    { display: none; }
.cw-toc details[open] > .cw-toc__body { display: block; }

.cw-toc summary.cw-toc__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  -webkit-user-select: none;
  font-size: var(--cw-toc-title-size, 11px);
  font-weight: var(--cw-toc-title-weight, 700);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  gap: 0.5rem;
}

/* Hide ALL browser-native disclosure markers (Chrome, Firefox, Safari) */
.cw-toc summary.cw-toc__toggle { list-style: none; }
.cw-toc summary.cw-toc__toggle::-webkit-details-marker { display: none; }
.cw-toc summary.cw-toc__toggle::marker { display: none; }

/* Single chevron via ::after - rotates when open */
.cw-toc summary.cw-toc__toggle::after {
  content: "▾";
  font-size: 14px;
  line-height: 1;
  transition: transform 0.2s ease;
  flex-shrink: 0;
  margin-left: auto;
}

.cw-toc details[open] summary.cw-toc__toggle::after { transform: rotate(180deg); }

/* Any leftover <span> chevron inside summary (old content) - hide it */
.cw-toc summary.cw-toc__toggle > span { display: none; }

.cw-toc__body { padding: 0.75rem 1.25rem 1rem 1.25rem; }

.cw-toc__list {
  margin: 0;
  padding-left: var(--cw-toc-ol-indent, 1.1rem);
  list-style-type: decimal;
  line-height: 1;
}

.cw-toc__list--nested,
.cw-toc__list .cw-toc__list {
  margin: 0.25rem 0 0.25rem 0;
  padding-left: var(--cw-toc-ol-indent, 1.1rem);
  list-style-type: decimal;
}

.cw-toc__list li {
  margin: 0 0 0.35rem 0;
  color: var(--cw-toc-marker, inherit);
  font-size: var(--cw-toc-font-size, 0.875rem);
  line-height: var(--cw-toc-line-height, 1.5);
}

.cw-toc__list li::marker {
  color: var(--cw-toc-marker, inherit);
}

.cw-toc__list a {
  text-decoration: none;
  line-height: 1.5;
  transition: color 0.15s;
}

.cw-toc__list a:hover { text-decoration: underline; }


/* ═══════════════════════════════════════════════════════════════
   FAQ ACCORDION
   ═══════════════════════════════════════════════════════════════ */

/* ── Base structural rules (all themes) ── */
.cw-faq {
  margin: 2.5rem 0;
  font-family: var(--cw-faq-font-family, inherit);
}

.cw-faq__title {
  font-size:   var(--cw-faq-title-size, 1.25rem);
  font-weight: var(--cw-faq-title-weight, 700);
  margin:      0 0 1rem 0;
  color:       var(--cw-faq-title-color, inherit);
}

.cw-faq__item {
  margin-bottom: var(--cw-faq-item-gap, 0.5rem);
  overflow:      hidden;
  transition:    box-shadow 0.15s;
}

/* Closed + open: <summary> toggles the accordion. H3 stays for schema only. */
.cw-faq__question {
  display:           flex;
  align-items:       center;
  justify-content:   space-between;
  margin:            0;
  padding:           0.85rem 2.75rem 0.85rem 1.1rem;
  cursor:            pointer;
  font-weight:       var(--cw-faq-question-weight, 600);
  font-size:         var(--cw-faq-question-size, 0.95rem);
  line-height:       1.4;
  color:             var(--cw-faq-question, inherit);
  list-style:        none;
  user-select:       none;
  -webkit-user-select: none;
  position:          relative;
  gap:               0.75rem;
}

.cw-faq__question-text {
  position:          absolute;
  width:             1px;
  height:            1px;
  padding:           0;
  margin:            -1px;
  overflow:          hidden;
  clip:              rect(0, 0, 0, 0);
  white-space:       nowrap;
  border:            0;
}

.cw-faq__question::-webkit-details-marker { display: none; }

.cw-faq__question::after {
  content:     "+";
  position:    absolute;
  right:       1.1rem;
  top:         50%;
  transform:   translateY(-50%);
  font-size:   1.25rem;
  font-weight: 400;
  line-height: 1;
  color:       var(--cw-faq-accent, inherit);
  transition:  transform 0.2s ease;
  pointer-events: none;
}

.cw-faq__item[open] > .cw-faq__question {
  color:         var(--cw-faq-open-q, inherit);
  border-bottom: 1px solid var(--cw-faq-border, rgba(0,0,0,0.1));
}

.cw-faq__item[open] > .cw-faq__question::after {
  transform: translateY(-50%) rotate(45deg);
}

.cw-faq__answer {
  padding:     0.75rem 1.1rem 1rem 1.1rem;
  font-size:   var(--cw-faq-answer-size, 0.9rem);
  line-height: var(--cw-faq-line-height, 1.7);
  color:       var(--cw-faq-text, inherit);
}

.cw-faq__answer p:last-child { margin-bottom: 0; }

/* Force correct open/closed state regardless of theme CSS overrides.
   Some WP themes interfere with native <details> disclosure behavior. */
.cw-faq__item > .cw-faq__answer       { display: none; }
.cw-faq__item[open] > .cw-faq__answer { display: block; }


/* ═══════════════════════════════════════════════════════════════
   PRODUCT ROW (Block Engine embeds)
   ═══════════════════════════════════════════════════════════════ */

.cw-product-row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 16px !important;
  width: 100% !important;
  box-sizing: border-box !important;
  align-items: stretch !important;
  overflow-x: auto !important;
}

.entry-content .cw-product-row,
.post-content .cw-product-row,
article .cw-product-row,
.cw-block-style .cw-product-row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  width: 100% !important;
  clear: none !important;
  float: none !important;
}

.cw-product-row__item {
  flex: 1 1 0 !important;
  min-width: 0 !important;
  width: auto !important;
  max-width: none !important;
  box-sizing: border-box !important;
  float: none !important;
  clear: none !important;
}

.entry-content .cw-product-row > .cw-product-row__item,
.post-content .cw-product-row > .cw-product-row__item,
.entry-content .cw-product-row > div:not(.cw-product-row__item),
.post-content .cw-product-row > div:not(.cw-product-row__item) {
  width: auto !important;
  max-width: none !important;
  float: none !important;
  clear: none !important;
}

.cw-product-row__item img {
  max-width: 100% !important;
  height: auto;
  display: block;
}

/* Mobile: stack products vertically */
@media (max-width: 767px) {
  .cw-product-row {
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    overflow-x: visible !important;
  }

  .cw-product-row__item,
  .entry-content .cw-product-row > .cw-product-row__item,
  .post-content .cw-product-row > .cw-product-row__item,
  .entry-content .cw-product-row > div:not(.cw-product-row__item),
  .post-content .cw-product-row > div:not(.cw-product-row__item) {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  [data-blockgroup-type="products"] > [data-block-type^="product."]:not(:has(.cw-product-row)) {
    flex-direction: column !important;
    overflow-x: visible !important;
  }

  [data-blockgroup-type="products"] > [data-block-type^="product."]:not(:has(.cw-product-row)) > div {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* Legacy embeds without cw-product-row (old cached HTML) */
[data-blockgroup-type="products"] > [data-block-type^="product."]:not(:has(.cw-product-row)) {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 16px !important;
  width: 100% !important;
  box-sizing: border-box !important;
  align-items: stretch !important;
  overflow-x: auto !important;
  clear: both !important;
}

.entry-content [data-blockgroup-type="products"] > [data-block-type^="product."]:not(:has(.cw-product-row)),
.post-content [data-blockgroup-type="products"] > [data-block-type^="product."]:not(:has(.cw-product-row)) {
  display: flex !important;
  width: 100% !important;
  float: none !important;
}

[data-blockgroup-type="products"] > [data-block-type^="product."]:not(:has(.cw-product-row)) > div {
  flex: 1 1 0 !important;
  min-width: 0 !important;
  width: auto !important;
  max-width: none !important;
  box-sizing: border-box !important;
  float: none !important;
  clear: none !important;
}

/* Block Style tab overrides (background, padding, radius, shadow) */
.cw-block-style {
  display: block !important;
  box-sizing: border-box !important;
  width: 100% !important;
  clear: both !important;
}

.entry-content .cw-block-style,
.post-content .cw-block-style,
article .cw-block-style {
  display: block !important;
  width: 100% !important;
  float: none !important;
  clear: both !important;
}

/* Block Engine buttons (Style tab: bg / hover / text) */
.cw-block-btn {
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease !important;
}

.cw-block-btn--solid:hover,
.cw-block-btn--product:hover {
  background: var(--cw-btn-hover-bg, #4f46e5) !important;
  color: var(--cw-btn-color, #fff) !important;
}

.cw-block-btn--outline:hover {
  background: var(--cw-btn-hover-bg, #4f46e5) !important;
  color: var(--cw-btn-color, #fff) !important;
  border-color: var(--cw-btn-hover-bg, #4f46e5) !important;
}

.cw-block-btn--ghost:hover {
  background: color-mix(in srgb, var(--cw-btn-hover-bg, #4f46e5) 14%, transparent) !important;
  color: var(--cw-btn-hover-bg, #4f46e5) !important;
}
