/* =================================================================
   MARKDOWN SECTIONS
   Scoped styles for markdown-rendered content: TOC sidebar, alert
   boxes, and article-body tables. Loaded globally via core.php.
   ================================================================= */


/* =================================================================
   TOC SIDEBAR — neutral palette (theme-independent)
   ================================================================= */
#toc-container {
    top: 24px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}
.toc-sidebar {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 1.5rem 1.25rem;
}
.toc-sidebar__title {
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 600;
    color: #868e96;
    margin: 0 0 1rem;
    padding: 0 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.toc-toggle { display: none; } /* hidden on desktop */


/* =================================================================
   TOC LIST
   ================================================================= */
.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
}
.toc-list--nested {
    padding-left: 0.75rem;
    margin-top: 2px;
    border-left: 2px solid #dee2e6;
}
.toc-item { margin-bottom: 3px; }
.toc-link {
    display: block;
    padding: 0.4rem 0.625rem;
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.45;
    color: #495057;
    text-decoration: none;
    border-radius: 5px;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.toc-link:hover           { background: #e9ecef; color: #212529; }
.toc-link--nested         { font-size: 0.8rem; color: #868e96; }
.toc-link--active,
.toc-link--active:hover   { background: #495057; color: #fff; }


/* =================================================================
   TOC PLACEHOLDER / SPINNER
   ================================================================= */
.toc-placeholder {
    padding: 1rem;
    text-align: center;
    font-size: 0.85rem;
    color: #adb5bd;
}
.toc-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid #dee2e6;
    border-top-color: #868e96;
    border-radius: 50%;
    animation: toc-spin 0.6s linear infinite;
}
@keyframes toc-spin { to { transform: rotate(360deg); } }


/* =================================================================
   MOBILE TOC — collapsible, appears before content
   ================================================================= */
@media (max-width: 991.98px) {
    #toc-container {
        position: relative !important;
        top: auto !important;
        max-height: none;
        overflow: visible;
        margin-bottom: 1.25rem;
    }

    .toc-sidebar {
        padding: 0;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        overflow: hidden;
        background: #f8f9fa;
    }

    .toc-sidebar__title { display: none; }

    .toc-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 0.7rem 1rem;
        margin: 0;
        border: none;
        background: #f8f9fa;
        cursor: pointer;
        -webkit-appearance: none;
        appearance: none;
    }
    .toc-toggle__label {
        display: flex;
        align-items: center;
        gap: 0.45rem;
        font-family: var(--font-body);
        font-size: 0.85rem;
        font-weight: 600;
        color: #495057;
        letter-spacing: 0.3px;
    }
    .toc-toggle__list-icon { color: #868e96; flex-shrink: 0; }
    .toc-toggle__chevron   {
        color: #868e96;
        transition: transform 0.25s ease;
        flex-shrink: 0;
    }
    .toc-toggle[aria-expanded="true"] .toc-toggle__chevron {
        transform: rotate(180deg);
    }

    .toc-body {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease, padding 0.3s ease;
        padding: 0 1rem;
    }
    .toc-body--open {
        max-height: 60vh;
        overflow-y: auto;
        border-top: 1px solid #e9ecef;
        padding: 0.75rem 1rem 1rem;
    }
}

@media (min-width: 992px) {
    .toc-body { display: block; }
}


/* =================================================================
   .section--bold overrides (dark backgrounds)
   ================================================================= */
.section--bold .toc-sidebar           { background: rgba(255,255,255,0.07); border-color: rgba(255,255,255,0.1); }
.section--bold .toc-sidebar__title    { color: rgba(255,255,255,0.5); }
.section--bold .toc-toggle            { background: rgba(255,255,255,0.05); }
.section--bold .toc-toggle__label     { color: rgba(255,255,255,0.7); }
.section--bold .toc-toggle__list-icon,
.section--bold .toc-toggle__chevron   { color: rgba(255,255,255,0.45); }
.section--bold .toc-link              { color: rgba(255,255,255,0.6); }
.section--bold .toc-link:hover        { background: rgba(255,255,255,0.1); color: #fff; }
.section--bold .toc-link--active,
.section--bold .toc-link--active:hover{ background: rgba(255,255,255,0.15); color: #fff; }
.section--bold .toc-list--nested      { border-left-color: rgba(255,255,255,0.12); }
.section--bold .toc-body--open        { border-top-color: rgba(255,255,255,0.1); }


/* =================================================================
   ALERT BOXES
   ================================================================= */
.alert-info,
.alert-tip,
.alert-important,
.alert-warning {
    border-left: 4px solid var(--color-primary);
    border-radius: var(--border-radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    background-color: var(--color-primary-light);
}
.alert-tip,
.alert-warning {
    border-left-color: var(--color-accent);
    background-color: color-mix(in oklch, var(--color-accent) 10%, var(--color-bg));
}
.alert-important {
    border-left-color: var(--color-primary-dark);
    background-color: var(--color-primary-light);
}
.alert-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}
.alert-icon                    { flex-shrink: 0; color: inherit; }
.alert-tip .alert-header       { color: var(--color-accent-hover); }
.alert-tip .alert-icon         { color: var(--color-accent); }
.alert-warning .alert-header   { color: var(--color-accent-hover); }
.alert-warning .alert-icon     { color: var(--color-accent); }
.alert-info .alert-header      { color: var(--color-primary); }
.alert-info .alert-icon        { color: var(--color-primary); }
.alert-important .alert-header { color: var(--color-primary-dark); }
.alert-important .alert-icon   { color: var(--color-primary-dark); }


/* =================================================================
   CONTENT TABLES — mobile-scrollable wrapper
   Wrapper is emitted by format_content() around every <table>.
   ================================================================= */
.table-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1.5rem;
    /* Subtle right-edge shadow as a scroll affordance on mobile */
    background:
        linear-gradient(to right, var(--color-bg) 30%, transparent),
        linear-gradient(to right, transparent, var(--color-bg) 70%) 100% 0,
        radial-gradient(farthest-side at 0 50%, rgba(0,0,0,0.12), transparent),
        radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,0.12), transparent) 100% 0;
    background-repeat: no-repeat;
    background-size: 20px 100%, 20px 100%, 10px 100%, 10px 100%;
    background-attachment: local, local, scroll, scroll;
}
.content-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
    font-size: 1rem;
    line-height: 1.65;
}
.content-table th,
.content-table td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border);
    color: var(--color-text-body);
    vertical-align: top;
}
.content-table thead th {
    background-color: var(--color-bg-alt);
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
}
.content-table tbody tr:nth-child(even) {
    background-color: color-mix(in oklch, var(--color-bg-alt) 50%, transparent);
}

/* Bold-section inversion */
.section--bold .content-table th,
.section--bold .content-table td         { border-color: color-mix(in oklch, var(--color-bg) 20%, transparent); color: var(--color-bg-inverted-muted); }
.section--bold .content-table thead th    { background-color: color-mix(in oklch, var(--color-bg) 12%, transparent); color: var(--color-bg); }
.section--bold .content-table tbody tr:nth-child(even) { background-color: color-mix(in oklch, var(--color-bg) 6%, transparent); }

/* Tighter cells on phones so more columns fit before scroll kicks in */
@media (max-width: 576px) {
    .content-table {
        font-size: 0.9rem;
    }
    .content-table th,
    .content-table td {
        padding: 0.5rem 0.75rem;
    }
}


/* =================================================================
   SUMMARY BLOCK — ::: summary ... :::
   Travel-magazine TLDR card: warm cream tint, gradient top rail
   (primary → accent, like a "journey"), checkmark bullets.
   ================================================================= */
.summary {
    --summary-tint: color-mix(in oklch, var(--color-accent) 10%, var(--color-bg));
    --summary-edge: color-mix(in oklch, var(--color-accent) 22%, transparent);

    position: relative;
    background: var(--summary-tint);
    border: 1px solid var(--summary-edge);
    border-radius: 14px;
    padding: 1.75rem 2rem 1.5rem;
    margin: 0 0 2rem;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04),
        0 14px 36px -14px color-mix(in oklch, var(--color-primary) 22%, transparent);
    overflow: hidden;
}

/* 4px gradient rail along the top: primary → accent ("the journey") */
.summary::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg,
        var(--color-primary) 0%,
        var(--color-accent) 100%);
}

.summary > :first-child { margin-top: 0; }
.summary > :last-child  { margin-bottom: 0; }

/* Heading — bigger, confident, accent checkmark, no form-like underline */
.summary h2,
.summary h3 {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.01em;
    color: var(--color-primary);
    margin: 0 0 1.25rem;
    padding: 0;
    border: none;
}

.summary h2::before,
.summary h3::before {
    content: "";
    width: 1.5rem;
    height: 1.5rem;
    flex-shrink: 0;
    background-color: var(--color-accent);
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM6.97 11.03a.75.75 0 0 0 1.07-.02l3.99-4.99a.75.75 0 1 0-1.17-.94L7.4 9.42 5.56 7.59a.75.75 0 0 0-1.06 1.06l2.47 2.38z'/></svg>") center/contain no-repeat;
    mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM6.97 11.03a.75.75 0 0 0 1.07-.02l3.99-4.99a.75.75 0 1 0-1.17-.94L7.4 9.42 5.56 7.59a.75.75 0 0 0-1.06 1.06l2.47 2.38z'/></svg>") center/contain no-repeat;
}

/* List: strip inherited padding/margin, checkmark bullets for <ul> */
.summary ul,
.summary ol {
    padding-left: 0 !important;
    margin: 0 !important;
    list-style: none;
}
.summary ul li,
.summary ol li {
    position: relative;
    padding: 0 0 0 1.9rem;
    margin-bottom: 0.7rem !important;
    line-height: 1.55 !important;
}
.summary ul li:last-child,
.summary ol li:last-child { margin-bottom: 0 !important; }

/* Primary-colored checkmark — reinforces the "summary / checked off" idea */
.summary ul li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.35em;
    width: 1.1rem;
    height: 1.1rem;
    background-color: var(--color-primary);
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z'/></svg>") center/contain no-repeat;
    mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z'/></svg>") center/contain no-repeat;
}

/* Numbered lists get pill badges */
.summary ol { counter-reset: summary-counter; }
.summary ol li { counter-increment: summary-counter; }
.summary ol li::before {
    content: counter(summary-counter);
    position: absolute;
    left: 0;
    top: 0.15em;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-bg);
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.35rem;
}

/* .section--bold inversion (dark backgrounds) */
.section--bold .summary {
    --summary-tint: rgba(255, 255, 255, 0.07);
    --summary-edge: rgba(255, 255, 255, 0.15);
    box-shadow: none;
}
.section--bold .summary::before {
    background: linear-gradient(90deg, var(--color-bg), var(--color-accent));
}
.section--bold .summary h2,
.section--bold .summary h3            { color: var(--color-bg); }
.section--bold .summary ul li::before { background-color: var(--color-bg); }
.section--bold .summary ol li::before { background: var(--color-bg); color: var(--color-primary); }

@media (max-width: 576px) {
    .summary {
        padding: 1.5rem 1.25rem 1.25rem;
        border-radius: 12px;
        margin-bottom: 1.5rem;
    }
    .summary h2,
    .summary h3 { font-size: 1.15rem; }
}


/* =================================================================
   REDUCED MOTION
   ================================================================= */
@media (prefers-reduced-motion: reduce) {
    .toc-link            { transition: none; }
    .toc-spinner         { animation: none; }
    .toc-body            { transition: none; }
    .toc-toggle__chevron { transition: none; }
    .content-table *     { transition: none !important; }
}
