/* ============================================================================
 * TraPay — legacy-content shim
 *
 * The CMS imported ~1500 legacy posts + landings whose body HTML was authored
 * against Bootstrap 3 and the old TraPay theme. The new theme doesn't ship
 * Bootstrap, so those classes were rendering bare. This file makes the legacy
 * markup look right without polluting the new theme.
 *
 * SCOPE: everything below is intentionally scoped to `.prose` so it only fires
 *        inside CMS-rendered body content (page/post/landing body), never the
 *        new-theme chrome. Keep new selectors under `.prose` too.
 *
 * Sections:
 *   1. Bootstrap 3 grid (.row / .col-*) — fluid 12-col flexbox, mobile first
 *   2. Bootstrap 3 utilities (img-responsive / pull-* / center-block / text-*)
 *   3. Bootstrap 3 buttons (.btn / .btn-warning / .btn-link)
 *   4. Bootstrap 3 panels + accordion (.panel-group / .collapse — FAQ blocks)
 *   5. Bootstrap 3 tables (.table / .table-bordered / .table-striped / .table-responsive)
 *   6. Bootstrap 3 alerts/wells
 *   7. Legacy custom (.ibox / .ibox2 / .sign / .well)
 *   8. Image alignment (img.pull-left / img.pull-right) — RTL aware
 *
 * RTL: body is rtl, so float:left/right are visual-LEFT/visual-RIGHT (per
 *       CSS spec — `float` is physical, not logical). This matches the
 *       legacy author intent which was also rtl.
 * ============================================================================ */

/* 1. Grid =================================================================== */
.tp-legacy-body .row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -0.75rem;
    margin-left: -0.75rem;
}
.tp-legacy-body .row > [class*="col-"] {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
    width: 100%;
    min-width: 0;
}

/* mobile-first: all cols full width by default, widen at md (768px+) */
@media (min-width: 768px) {
    .tp-legacy-body .col-md-1  { width: 8.3333%; }
    .tp-legacy-body .col-md-2  { width: 16.6667%; }
    .tp-legacy-body .col-md-3  { width: 25%; }
    .tp-legacy-body .col-md-4  { width: 33.3333%; }
    .tp-legacy-body .col-md-5  { width: 41.6667%; }
    .tp-legacy-body .col-md-6  { width: 50%; }
    .tp-legacy-body .col-md-7  { width: 58.3333%; }
    .tp-legacy-body .col-md-8  { width: 66.6667%; }
    .tp-legacy-body .col-md-9  { width: 75%; }
    .tp-legacy-body .col-md-10 { width: 83.3333%; }
    .tp-legacy-body .col-md-11 { width: 91.6667%; }
    .tp-legacy-body .col-md-12 { width: 100%; }
}
@media (min-width: 576px) {
    .tp-legacy-body .col-sm-6  { width: 50%; }
    .tp-legacy-body .col-sm-12 { width: 100%; }
}
.tp-legacy-body .col-xs-6  { width: 50%; }
.tp-legacy-body .col-xs-12 { width: 100%; }
.tp-legacy-body .mr-auto   { margin-inline-start: auto; }
.tp-legacy-body .ml-auto   { margin-inline-end: auto; }

/* 2. Utilities ============================================================== */
.tp-legacy-body .img-responsive {
    display: block;
    max-width: 100%;
    height: auto;
}
.tp-legacy-body .center-block {
    display: block;
    margin-right: auto;
    margin-left: auto;
}
.tp-legacy-body .pull-left  { float: left; }
.tp-legacy-body .pull-right { float: right; }
.tp-legacy-body .clearfix::after { content: ""; display: table; clear: both; }
.tp-legacy-body .text-center { text-align: center; }
.tp-legacy-body .text-right  { text-align: right; }
.tp-legacy-body .text-left   { text-align: left; }
.tp-legacy-body .text-muted  { color: var(--colors-neutral-500, #6b7280); }

/* legacy floated images: give them room to breathe in body copy */
.tp-legacy-body img.pull-left  { margin: 0 1rem 1rem 0; max-width: 50%; }
.tp-legacy-body img.pull-right { margin: 0 0 1rem 1rem; max-width: 50%; }
@media (max-width: 640px) {
    .tp-legacy-body img.pull-left,
    .tp-legacy-body img.pull-right {
        float: none;
        display: block;
        margin: 0.75rem auto;
        max-width: 100%;
    }
}

/* 3. Buttons ================================================================ */
.tp-legacy-body .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: 0.625rem;
    font-weight: 600;
    font-size: 0.9375rem;
    line-height: 1.4;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none !important;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
}
.tp-legacy-body .btn:hover { transform: translateY(-1px); }
.tp-legacy-body .btn-warning {
    background: var(--colors-semantic-warning-base, #f59e0b);
    color: #fff;
    border-color: transparent;
}
.tp-legacy-body .btn-warning:hover {
    background: var(--colors-semantic-warning-strong, #d97706);
    color: #fff;
}
.tp-legacy-body .btn-link {
    background: transparent;
    color: var(--tp-brand, var(--color-primary, #0d3e7e));
    border: none;
    padding: 0;
    text-decoration: underline !important;
}
.tp-legacy-body .btn-link:hover {
    color: var(--colors-primary-700, #1e40af);
    transform: none;
}
.tp-legacy-body .btn-primary {
    background: var(--tp-brand, var(--color-primary, #0d3e7e));
    color: #fff;
}
.tp-legacy-body .btn-default {
    background: #fff;
    color: var(--colors-surface-foreground, #0f1b2d);
    border-color: var(--colors-neutral-200, #e5e7eb);
}

/* 4. Panels + cards + collapse (FAQ accordion) ============================== */
/* Handles BOTH Bootstrap 3 markup (.panel-group / .panel / .panel-heading /
 * .panel-body) AND Bootstrap 4 markup (.panel-group / .card / .card-header /
 * .card-body) — imported posts use either depending on when they were written. */
.tp-legacy-body .panel-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1.5rem 0;
}
.tp-legacy-body .panel,
.tp-legacy-body .panel-default,
.tp-legacy-body .panel-group > .card {
    border: 1px solid var(--colors-neutral-200, #e5e7eb);
    border-radius: 0.75rem;
    background: #fff;
    overflow: hidden;
}
.tp-legacy-body .panel-heading,
.tp-legacy-body .panel-group > .card > .card-header {
    background: var(--colors-neutral-50, #f9fafb);
    border-bottom: 1px solid var(--colors-neutral-200, #e5e7eb);
    padding: 1rem 1.25rem;
}
.dark .tp-legacy-body .panel-group > .card > .card-header {
    background: var(--colors-neutral-800, #1f2937);
    border-bottom-color: var(--colors-neutral-700, #374151);
}
.dark .tp-legacy-body .panel-group > .card > .card-header .btn-link { color: var(--colors-neutral-100, #f3f4f6); }
.tp-legacy-body .panel-heading h4,
.tp-legacy-body .panel-group > .card > .card-header h4 { margin: 0; font-size: 1rem; }
.tp-legacy-body .panel-heading .btn-link,
.tp-legacy-body .panel-group > .card > .card-header .btn-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    color: var(--colors-surface-foreground, #0f1b2d);
    font-weight: 600;
    text-decoration: none !important;
    padding: 0;
    background: transparent;
    text-align: start;
}
.tp-legacy-body .panel-heading .btn-link::after,
.tp-legacy-body .panel-group > .card > .card-header .btn-link::after {
    content: "▾";
    display: inline-block;
    font-size: 0.85rem;
    color: var(--colors-neutral-500, #6b7280);
    transition: transform .2s ease;
    flex-shrink: 0;
    margin-inline-start: 0.75rem;
}
.tp-legacy-body .panel-heading .btn-link[aria-expanded="true"]::after,
.tp-legacy-body .panel-group > .card > .card-header .btn-link[aria-expanded="true"]::after {
    transform: rotate(180deg);
    color: var(--tp-brand, var(--color-primary, #0d3e7e));
}
.tp-legacy-body .panel-heading .btn-link.collapsed::after,
.tp-legacy-body .panel-group > .card > .card-header .btn-link.collapsed::after { transform: none; }
.tp-legacy-body .panel-body,
.tp-legacy-body .panel-group > .card > .collapse > .card-body,
.tp-legacy-body .panel-group > .card > .card-body {
    padding: 1rem 1.25rem;
    color: var(--colors-neutral-700, #374151);
}
.dark .tp-legacy-body .panel-group > .card > .collapse > .card-body,
.dark .tp-legacy-body .panel-group > .card > .card-body {
    color: var(--colors-neutral-200, #e5e7eb);
}
.tp-legacy-body .panel-collapse { background: #fff; }
.dark .tp-legacy-body .panel-collapse { background: var(--colors-surface-dark, #1f2937); }

/* collapse mechanics — JS toggles .in / .show / .open. Inline height:0 from
 * legacy markup is overridden when .in/.show/.open is set.
 * NOTE: Tailwind ships a `.collapse` utility = `visibility:collapse`, which
 * clashes with Bootstrap's `.collapse` accordion class and hides the answer
 * text. Force visibility:visible on legacy collapse panels. */
.tp-legacy-body .collapse { visibility: visible; }
.tp-legacy-body .collapse:not(.in):not(.show):not(.open) { display: none; }
.tp-legacy-body .collapse.in,
.tp-legacy-body .collapse.show,
.tp-legacy-body .collapse.open {
    display: block;
    height: auto !important;
    visibility: visible;
}
.tp-legacy-body .collapsing {
    overflow: hidden;
    transition: max-height .25s ease;
}

/* 5. Tables ================================================================= */
.tp-legacy-body .table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    margin: 1.25rem 0;
    border-radius: 0.5rem;
}
.tp-legacy-body .table {
    width: 100%;
    margin: 1.25rem 0;
    border-collapse: collapse;
    background: #fff;
    font-size: 0.9375rem;
}
.tp-legacy-body .table th,
.tp-legacy-body .table td {
    padding: 0.75rem 1rem;
    text-align: inherit;
    vertical-align: middle;
}
.tp-legacy-body .table-bordered,
.tp-legacy-body .table-bordered th,
.tp-legacy-body .table-bordered td {
    border: 1px solid var(--colors-neutral-200, #e5e7eb);
}
.tp-legacy-body .table-striped tbody tr:nth-of-type(odd) {
    background: var(--colors-neutral-50, #f9fafb);
}
.tp-legacy-body .table-hover tbody tr:hover {
    background: var(--colors-primary-50, #eff6ff);
}
.tp-legacy-body .table thead th {
    background: var(--colors-neutral-100, #f3f4f6);
    font-weight: 700;
    color: var(--colors-surface-foreground, #0f1b2d);
}

/* 6. Alerts + wells ========================================================= */
.tp-legacy-body .alert {
    padding: 1rem 1.25rem;
    margin: 1.25rem 0;
    border-radius: 0.625rem;
    border-left: 4px solid;
    background: var(--colors-neutral-50, #f9fafb);
    color: var(--colors-neutral-800, #1f2937);
}
.tp-legacy-body .alert-info    { border-color: #3b82f6; background: #eff6ff; }
.tp-legacy-body .alert-success { border-color: #10b981; background: #ecfdf5; }
.tp-legacy-body .alert-warning { border-color: #f59e0b; background: #fffbeb; }
.tp-legacy-body .alert-danger  { border-color: #ef4444; background: #fef2f2; }
.tp-legacy-body .well {
    background: var(--colors-neutral-50, #f9fafb);
    border: 1px solid var(--colors-neutral-200, #e5e7eb);
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
    margin: 1.25rem 0;
}

/* 7. Legacy custom containers (ibox / ibox2 / sign) ========================== */
.tp-legacy-body .ibox,
.tp-legacy-body .ibox2 {
    background: #fff;
    border: 1px solid var(--colors-neutral-200, #e5e7eb);
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
}
.tp-legacy-body .ibox2 { background: var(--colors-neutral-50, #f9fafb); }
.tp-legacy-body .sign {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    background: var(--colors-primary-50, #eff6ff);
    color: var(--tp-brand, var(--color-primary, #0d3e7e));
    font-size: 0.8125rem;
    font-weight: 600;
}

/* 8. Dark mode tweaks ======================================================= */
.dark .tp-legacy-body .panel,
.dark .tp-legacy-body .panel-default,
.dark .tp-legacy-body .panel-collapse,
.dark .tp-legacy-body .card,
.dark .tp-legacy-body .card-body,
.dark .tp-legacy-body .table,
.dark .tp-legacy-body .ibox,
.dark .tp-legacy-body .ibox2,
.dark .tp-legacy-body .well {
    background: var(--colors-surface-dark, #1f2937);
    border-color: var(--colors-neutral-700, #374151);
    color: var(--colors-neutral-200, #e5e7eb);
}
.dark .tp-legacy-body .panel-heading,
.dark .tp-legacy-body .card-header {
    background: var(--colors-neutral-800, #1f2937);
    border-color: var(--colors-neutral-700, #374151);
}
.dark .tp-legacy-body .panel-heading .btn-link,
.dark .tp-legacy-body .card-header .btn-link { color: var(--colors-neutral-100, #f3f4f6); }
.dark .tp-legacy-body .table thead th { background: var(--colors-neutral-800, #1f2937); color: #f3f4f6; }
.dark .tp-legacy-body .table-striped tbody tr:nth-of-type(odd) { background: rgba(255,255,255,0.02); }
.dark .tp-legacy-body .table-hover tbody tr:hover { background: rgba(59,130,246,0.08); }

/* ============================================================================
 * TraPay — modernized-body base spacing (optimize-post / fix-landing output)
 *
 * WHY: improved post/landing bodies live in the DB and use Tailwind utility
 * classes (my-6, mt-4, p-8, space-y-*). Tailwind PURGES unused classes by
 * scanning source files — it never sees DB body HTML — so those utilities
 * silently produce NO CSS and every element collapses to margin:0 (cramped,
 * no rhythm). `.tp-modernized-body` also intentionally drops `.prose`, so
 * there is no fallback typographic spacing either.
 *
 * FIX: give the scope real, compiled base spacing here. Element selectors only
 * (no Tailwind class names) so it works regardless of which utilities the body
 * HTML carries. Mirrors the 8pt rhythm in DESIGN-SYSTEM.md.
 * ==========================================================================*/

.tp-modernized-body { line-height: 1.9; }

/* vertical rhythm between top-level blocks */
.tp-modernized-body > * + * { margin-top: 1.25rem; }        /* 20px default gap */

.tp-modernized-body p { margin: 0 0 1.25rem; line-height: 1.95; }
.tp-modernized-body ul,
.tp-modernized-body ol { margin: 0 0 1.25rem; padding-inline-start: 1.5rem; }
.tp-modernized-body li { margin-bottom: .5rem; line-height: 1.9; }
.tp-modernized-body li::marker { color: color-mix(in srgb, var(--brand) 55%, transparent); }

/* headings get more space above than below (section anchors) */
.tp-modernized-body h2 { margin: 3rem 0 1rem; line-height: 1.4; }
.tp-modernized-body h3 { margin: 2rem 0 .75rem; line-height: 1.5; }
.tp-modernized-body h2:first-child,
.tp-modernized-body h3:first-child { margin-top: 0; }

/* images: centered, capped, breathing room (inline max-width still wins) */
.tp-modernized-body img { display: block; margin: 1.5rem auto; max-width: 100%; height: auto; border-radius: 1rem; }

/* horizontal rules = section dividers */
.tp-modernized-body hr { margin: 2.5rem 0; border: 0; border-top: 1px solid var(--colors-neutral-200, #e5e7eb); }
.dark .tp-modernized-body hr { border-top-color: #1f2937; }

/* the wrapper panels I emit (hero / callout / CTA / FAQ) already carry inline
 * padding+radius+bg via style="", but Tailwind gap/margin utilities on them do
 * NOT compile — give them outer spacing here. .not-prose is the marker class. */
.tp-modernized-body .not-prose { margin-top: 1.75rem; margin-bottom: 1.75rem; }

/* FAQ <details> rhythm (they use my-3 which won't compile) */
.tp-modernized-body details { margin: .75rem 0; padding: 1.25rem; }
.tp-modernized-body details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.tp-modernized-body details > summary::-webkit-details-marker { display: none; }
.tp-modernized-body details p { margin: .75rem 0 0; }

/* blockquote ("بیشتر بدانید" boxes) */
.tp-modernized-body blockquote { margin: 1.75rem 0; }

/* legacy &nbsp;-only spacer paragraphs → don't let them add phantom gaps */
.tp-modernized-body p:empty { display: none; }
.tp-modernized-body p:blank { margin: 0; }
