/* ============================================================
   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 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: question text in <summary>. Open: <h3> heading (summary hidden). */
.cw-faq__question,
.cw-faq__question-text {
  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::-webkit-details-marker { display: none; }

.cw-faq__question::after,
.cw-faq__question-text::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 { display: none; }

.cw-faq__item[open] > .cw-faq__question-text {
  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-text::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; }
