/*!
 * CS TOC — iOS-style table of contents.
 *
 * Colours are never hard-coded for a mode: everything is mixed from the theme's own
 * text colour (currentColor) and page background (--cstoc-bg, detected by JS), so the
 * TOC follows the theme in light AND dark mode, however the theme switches.
 */

:root {
    --cstoc-bg: Canvas;               /* replaced at runtime with the real page background */
    --cstoc-accent: #007aff;          /* replaced at runtime with the theme link colour     */
    --cstoc-icon: #007aff;            /* header icon: always iOS system blue                 */
    --cstoc-fill: 5%;                 /* grouped background strength                         */
    --cstoc-radius: 14px;
    --cstoc-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --cstoc-ease: cubic-bezier(.32, .72, 0, 1);
}
:root[data-cstoc-scheme="dark"] {
    --cstoc-fill: 9%;
    --cstoc-icon: #0a84ff;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-cstoc-scheme]) { --cstoc-accent: #0a84ff; --cstoc-icon: #0a84ff; --cstoc-fill: 9%; }
}

/* ------------------------------------------------------------------ */
/* Inline TOC (inset grouped list)                                     */
/* ------------------------------------------------------------------ */

.cstoc {
    --cstoc-sep: color-mix(in srgb, currentColor 14%, transparent);
    --cstoc-2nd: color-mix(in srgb, currentColor 60%, transparent);
    box-sizing: border-box;
    margin: 1.75em 0;
    padding: 0;
    border-radius: var(--cstoc-radius);
    background: color-mix(in srgb, currentColor var(--cstoc-fill), transparent);
    font-family: var(--cstoc-font);
    font-size: 16px;
    line-height: 1.35;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    clear: both;
}
.cstoc--inherit-font,
.cstoc--inherit-font .cstoc__head { font-family: inherit; }
.cstoc *, .cstoc *::before, .cstoc *::after { box-sizing: border-box; }

.cstoc__head {
    all: unset;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 52px;
    padding: 12px 16px;
    cursor: pointer;
    color: inherit;
    font: inherit;
    -webkit-tap-highlight-color: transparent;
}
.cstoc__head:hover { background: color-mix(in srgb, currentColor 4%, transparent); }
.cstoc__head:focus-visible { outline: 2px solid var(--cstoc-accent); outline-offset: -2px; border-radius: var(--cstoc-radius); }
.cstoc__icon {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 29px; height: 29px; border-radius: 7px;
    background: var(--cstoc-icon); color: #fff;
}
.cstoc__title { font-size: 17px; font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cstoc__chevron {
    margin-left: auto;
    flex: none;
    color: color-mix(in srgb, currentColor 35%, transparent);
    transform: rotate(90deg);
    transition: transform .25s var(--cstoc-ease);
}
.cstoc__head[aria-expanded="false"] .cstoc__chevron { transform: rotate(0deg); }

.cstoc__body { border-top: .5px solid var(--cstoc-sep); padding: 4px 0 6px; }
.cstoc__body[hidden] { display: none; }

.cstoc__list { list-style: none; margin: 0; padding: 0; counter-reset: cstoc; }
.cstoc .cstoc__list .cstoc__list { padding-left: 16px; }
.cstoc__item { margin: 0; padding: 0; counter-increment: cstoc; }
.cstoc__item::marker { content: none; }

.cstoc__link {
    position: relative;
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-height: 44px;
    padding: 11px 16px;
    color: inherit !important;
    text-decoration: none !important;
    border: 0 !important;
    box-shadow: none !important;
    -webkit-tap-highlight-color: transparent;
    transition: background-color .2s, color .2s;
}
/* inset separator, iOS style */
.cstoc__item + .cstoc__item > .cstoc__link::before,
.cstoc__list .cstoc__list > .cstoc__item:first-child > .cstoc__link::before {
    content: "";
    position: absolute;
    top: 0; left: 16px; right: 0;
    border-top: .5px solid var(--cstoc-sep);
}
.cstoc__link:hover { background: color-mix(in srgb, currentColor 4%, transparent); }
.cstoc__link:focus-visible { outline: 2px solid var(--cstoc-accent); outline-offset: -2px; }
.cstoc__list--l2 .cstoc__link, .cstoc__list--l3 .cstoc__link, .cstoc__list--l4 .cstoc__link { font-size: 15px; }
.cstoc__list--l2 .cstoc__text, .cstoc__list--l3 .cstoc__text, .cstoc__list--l4 .cstoc__text { color: color-mix(in srgb, currentColor 82%, transparent); }

.cstoc--numbered .cstoc__link > .cstoc__text::before {
    content: counters(cstoc, ".") ".";
    display: inline-block;
    min-width: 1.6em;
    margin-right: 6px;
    color: var(--cstoc-2nd);
    font-variant-numeric: tabular-nums;
}
.cstoc--numbered .cstoc__list .cstoc__list .cstoc__link > .cstoc__text::before { content: counters(cstoc, "."); min-width: 2.2em; }

.cstoc--marker .cstoc__link { align-items: center; }
.cstoc--marker .cstoc__link > .cstoc__text { display: inline-flex; align-items: center; gap: 10px; }
.cstoc--marker .cstoc__link > .cstoc__text::before {
    content: "";
    flex: none;
    display: inline-block;
    color: var(--cstoc-marker, color-mix(in srgb, currentColor 45%, transparent));
}
.cstoc--marker-dot .cstoc__link > .cstoc__text::before    { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.cstoc--marker-circle .cstoc__link > .cstoc__text::before { width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; }
.cstoc--marker-square .cstoc__link > .cstoc__text::before { width: 6px; height: 6px; border-radius: 1.5px; background: currentColor; }
.cstoc--marker-dash .cstoc__link > .cstoc__text::before   { width: 9px; height: 2px; border-radius: 1px; background: currentColor; }
.cstoc--marker-chevron .cstoc__link > .cstoc__text::before { content: "\203A"; font-weight: 600; font-size: 1.25em; line-height: 1; width: .5em; }
.cstoc--marker-arrow .cstoc__link > .cstoc__text::before   { content: "\2192"; font-size: 1em; line-height: 1; width: 1em; }
/* sub levels: lighter, slightly smaller marker */
.cstoc--marker .cstoc__list .cstoc__list .cstoc__link > .cstoc__text::before { opacity: .7; transform: scale(.85); }
.cstoc--marker .cstoc__link.is-active > .cstoc__text::before { color: var(--cstoc-accent); opacity: 1; }

/* current section (scroll-spy) */
.cstoc__link.is-active { color: var(--cstoc-accent) !important; font-weight: 600; }
.cstoc__link.is-active > .cstoc__text,
.cstoc__link.is-active > .cstoc__text::before { color: var(--cstoc-accent); }
.cstoc__link.is-active::after {
    content: "";
    position: absolute;
    left: 4px; top: 12px; bottom: 12px;
    width: 3px; border-radius: 3px;
    background: var(--cstoc-accent);
}

/* ------------------------------------------------------------------ */
/* Compact (default): no row lines, tight rows, smaller header          */
/* ------------------------------------------------------------------ */
.cstoc--compact { margin: 1.25em 0; font-size: 15px; }
.cstoc--compact .cstoc__head { min-height: 0; padding: 8px 12px; gap: 8px; }
.cstoc--compact .cstoc__icon { width: 24px; height: 24px; border-radius: 6px; }
.cstoc--compact .cstoc__icon svg { width: 15px; height: 15px; }
.cstoc--compact .cstoc__title { font-size: 15px; }
.cstoc--compact .cstoc__body { border-top: 0; padding: 0 0 8px; }
.cstoc--compact .cstoc__link { min-height: 0; padding: 4px 12px 4px 14px; border-radius: 6px; }
.cstoc.cstoc--compact .cstoc__item .cstoc__link::before { display: none; }
.cstoc--compact .cstoc__list .cstoc__list { padding-left: 18px; }
.cstoc--compact .cstoc__list--l2 .cstoc__link,
.cstoc--compact .cstoc__list--l3 .cstoc__link,
.cstoc--compact .cstoc__list--l4 .cstoc__link { font-size: 14px; }
.cstoc--compact.cstoc--marker .cstoc__link > .cstoc__text { gap: 8px; }
.cstoc--compact .cstoc__link.is-active::after { left: 3px; top: 6px; bottom: 6px; }
/* the mobile bottom sheet keeps finger-size rows */
.cstoc-sheet .cstoc--compact .cstoc__link { padding: 10px 16px; }

/* target heading flash */
.cstoc-target { animation: cstoc-flash 1.4s var(--cstoc-ease); border-radius: 6px; }
@keyframes cstoc-flash {
    0%, 40% { background: color-mix(in srgb, var(--cstoc-accent) 16%, transparent); }
    100% { background: transparent; }
}

/* ------------------------------------------------------------------ */
/* Floating pill + bottom sheet                                        */
/* ------------------------------------------------------------------ */

.cstoc-fab {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 99990;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: min(70vw, 340px);
    height: 44px;
    padding: 0 16px 0 12px;
    border: .5px solid color-mix(in srgb, currentColor 12%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--cstoc-bg) 78%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .16), 0 1px 3px rgba(0, 0, 0, .1);
    color: inherit;
    font: 600 15px/1 var(--cstoc-font);
    cursor: pointer;
    opacity: 0;
    transform: translateY(16px) scale(.96);
    pointer-events: none;
    transition: opacity .3s var(--cstoc-ease), transform .3s var(--cstoc-ease);
    -webkit-tap-highlight-color: transparent;
}
.cstoc-fab.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.cstoc-fab:focus-visible { outline: 2px solid var(--cstoc-accent); outline-offset: 2px; }
.cstoc-fab svg { flex: none; color: var(--cstoc-accent); }
.cstoc-fab__label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cstoc-fab__progress { flex: none; }
.cstoc-fab__progress circle:last-child { transition: stroke-dashoffset .2s linear; }

.cstoc-backdrop {
    position: fixed; inset: 0; z-index: 99998;
    background: rgba(0, 0, 0, .32);
    opacity: 0;
    transition: opacity .3s var(--cstoc-ease);
}
.cstoc-backdrop.is-open { opacity: 1; }

.cstoc-sheet {
    position: fixed;
    left: 50%; bottom: 0; z-index: 99999;
    width: min(100%, 560px);
    max-height: 78vh;
    display: flex; flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
    border-radius: 14px 14px 0 0;
    background: color-mix(in srgb, currentColor 4%, var(--cstoc-bg));
    box-shadow: 0 -10px 40px rgba(0, 0, 0, .2);
    color: inherit;
    font-family: var(--cstoc-font);
    transform: translate(-50%, 100%);
    transition: transform .4s var(--cstoc-ease);
    outline: none;
}
.cstoc-sheet.is-open { transform: translate(-50%, 0); }
.cstoc-sheet.is-dragging { transition: none; }
.cstoc-sheet__grabber { padding: 6px 0 2px; display: flex; justify-content: center; cursor: grab; touch-action: none; }
.cstoc-sheet__grabber span { width: 36px; height: 5px; border-radius: 3px; background: color-mix(in srgb, currentColor 25%, transparent); }
.cstoc-sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px 10px; touch-action: none; }
.cstoc-sheet__title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.02em; color: inherit; }
.cstoc-sheet__close {
    all: unset;
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 50%;
    background: color-mix(in srgb, currentColor 10%, transparent);
    color: color-mix(in srgb, currentColor 60%, transparent);
    cursor: pointer;
}
.cstoc-sheet__close:focus-visible { outline: 2px solid var(--cstoc-accent); }
.cstoc-sheet__body { overflow-y: auto; overscroll-behavior: contain; padding: 0 16px 16px; -webkit-overflow-scrolling: touch; }
.cstoc-sheet .cstoc { margin: 0; }
.cstoc-sheet .cstoc__head { display: none; }
.cstoc-sheet .cstoc__body { border-top: 0; }

.cstoc-sheet[hidden], .cstoc-backdrop[hidden] { display: none !important; }
html.cstoc-lock, html.cstoc-lock body { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
    .cstoc__chevron, .cstoc-fab, .cstoc-backdrop, .cstoc-sheet, .cstoc__link { transition: none; }
    .cstoc-target { animation: none; }
}
@media print {
    .cstoc-fab, .cstoc-sheet, .cstoc-backdrop { display: none !important; }
}

/* Older browsers without color-mix(): neutral translucent fallbacks. */
@supports not (background: color-mix(in srgb, red 50%, transparent)) {
    .cstoc { background: rgba(127, 127, 127, .1); }
    .cstoc__body, .cstoc__item + .cstoc__item > .cstoc__link::before { border-color: rgba(127, 127, 127, .25); }
    .cstoc--numbered .cstoc__link > .cstoc__text::before { opacity: .6; }
    .cstoc-fab { background: rgba(127, 127, 127, .25); }
    .cstoc-sheet { background: var(--cstoc-bg); }
}

/* Elementor widget wrapper + editor hint */
.cstoc-slot:empty{display:none}
.cstoc-editor-hint{padding:12px 14px;border-radius:12px;border:1px dashed color-mix(in srgb,currentColor 35%,transparent);font:13px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;opacity:.8}


/* ------------------------------------------------------------------ */
/* 1.4 — Màu chuẩn iOS + chống CSS chung của theme                     */
/* (vd. Additional CSS "span { color: #0d6efd; display: block }")       */
/* ------------------------------------------------------------------ */

/* Chữ luôn theo mục lục, không theo rule span / a của theme. */
.cstoc .cstoc__link,
.cstoc .cstoc__text,
.cstoc .cstoc__title,
.cstoc-fab .cstoc-fab__label,
.cstoc-sheet .cstoc-sheet__title { color: inherit !important; text-decoration: none !important; }
.cstoc .cstoc__text { display: inline; background: none; }
.cstoc .cstoc__title, .cstoc-fab .cstoc-fab__label { display: block; }
.cstoc .cstoc__list--l2 .cstoc__text,
.cstoc .cstoc__list--l3 .cstoc__text,
.cstoc .cstoc__list--l4 .cstoc__text { color: var(--cstoc-label-2, color-mix(in srgb, currentColor 82%, transparent)) !important; }
.cstoc .cstoc__link.is-active,
.cstoc .cstoc__link.is-active .cstoc__text,
.cstoc .cstoc__list .cstoc__link.is-active .cstoc__text { color: var(--cstoc-accent) !important; }
.cstoc .cstoc__link:visited { color: inherit !important; }

/* Dark mode: bảng màu hệ thống iOS (label / secondaryLabel / separator / grouped background). */
:root[data-cstoc-scheme="dark"] .cstoc,
:root[data-cstoc-scheme="dark"] .cstoc-sheet,
:root[data-cstoc-scheme="dark"] .cstoc-fab {
    --cstoc-label-2: rgba(235, 235, 245, .82);
    --cstoc-2nd: rgba(235, 235, 245, .6);                  /* secondaryLabel */
    --cstoc-marker: rgba(235, 235, 245, .5);
    --cstoc-sep: rgba(84, 84, 88, .65);                    /* separator */
    color: #f5f5f7 !important;                             /* label */
}
:root[data-cstoc-scheme="dark"] .cstoc {
    /* secondarySystemGroupedBackground: bề mặt nổi trên nền trang (iOS: #1C1C1E trên #000). */
    background: color-mix(in srgb, #fff 10%, var(--cstoc-bg));
    box-shadow: inset 0 0 0 .5px rgba(255, 255, 255, .08);
}
:root[data-cstoc-scheme="dark"] .cstoc__head:hover,
:root[data-cstoc-scheme="dark"] .cstoc__link:hover { background: rgba(255, 255, 255, .06); }
:root[data-cstoc-scheme="dark"] .cstoc__link:active { background: rgba(255, 255, 255, .1); }
:root[data-cstoc-scheme="dark"] .cstoc__chevron { color: rgba(235, 235, 245, .3); }
:root[data-cstoc-scheme="dark"] .cstoc--compact .cstoc__link.is-active { background: color-mix(in srgb, var(--cstoc-accent) 16%, transparent); }
:root[data-cstoc-scheme="dark"] .cstoc-sheet { background: color-mix(in srgb, #fff 10%, var(--cstoc-bg)); }
:root[data-cstoc-scheme="dark"] .cstoc-sheet .cstoc { background: color-mix(in srgb, #fff 6%, transparent); box-shadow: none; }
:root[data-cstoc-scheme="dark"] .cstoc-sheet__grabber span { background: rgba(235, 235, 245, .3); }
:root[data-cstoc-scheme="dark"] .cstoc-sheet__close { background: rgba(118, 118, 128, .24); color: rgba(235, 235, 245, .6); }
:root[data-cstoc-scheme="dark"] .cstoc-fab {
    border-color: rgba(255, 255, 255, .12);
    background: color-mix(in srgb, color-mix(in srgb, #fff 12%, var(--cstoc-bg)) 82%, transparent);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .3);
}
/* Light mode: hàng đang đọc có nền nhấn nhẹ như iOS */
:root:not([data-cstoc-scheme="dark"]) .cstoc--compact .cstoc__link.is-active { background: color-mix(in srgb, var(--cstoc-accent) 10%, transparent); }
@supports not (background: color-mix(in srgb, red 50%, transparent)) {
    :root[data-cstoc-scheme="dark"] .cstoc, :root[data-cstoc-scheme="dark"] .cstoc-sheet { background: #1c1c1e; }
}
