/* =========================================================================
   COMPONENTS  —  aimatin.com
   A small, self-hosted (no-CDN) component layer shared by every article.
   Loaded AFTER prompt.css + persian-bootstrap-shell.css so it can refine
   and override. Reuses the existing design tokens (--primary-blue, --radius-*,
   Vazirmatn, #066ac9 accent) so the look stays "Persian Bootstrap Modern".

   Behaviour for these components lives in components.js (copy buttons +
   table->card labelling). The CSS degrades gracefully if JS is disabled.

   Sections:
     1. Component tokens
     2. Prompt / code card        (.code-box-wrapper / .code-content / .copy-btn)
     3. Responsive tables -> cards (.cmp-rtable)
     4. Mobile rhythm + overflow hardening (edge-stick / spill fixes)
   ========================================================================= */

:root {
    /* code card surface (refined from the legacy Dracula #282a36) */
    --code-bg: #1f2330;
    --code-bg-2: #272c3b;
    --code-header: rgba(255, 255, 255, 0.04);
    --code-border: rgba(255, 255, 255, 0.10);
    --code-text: #f3f4f8;
    --code-lang: #8ab4ff;
    --ok: #2ecc71;
    /* one comfortable gutter token — generous so Persian text breathes */
    --cmp-gutter: clamp(20px, 5.2vw, 28px);
}

/* =========================================================================
   2. PROMPT / CODE CARD
   Generated by components.js from bare <pre> blocks, and also styles the
   legacy hand-built .code-box-wrapper markup (e.g. instagram-audit-ai).
   ========================================================================= */
.code-box-wrapper {
    background: linear-gradient(180deg, var(--code-bg) 0%, var(--code-bg-2) 100%);
    border: 1px solid var(--code-border);
    border-radius: var(--radius-sm, 14px);
    margin: 26px 0;
    overflow: hidden;
    box-shadow: 0 14px 34px -18px rgba(15, 23, 42, 0.55);
    max-width: 100%;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 14px 9px 16px;
    background: var(--code-header);
    border-bottom: 1px solid var(--code-border);
}

.code-lang {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--code-lang);
    font-size: 0.82rem;
    font-weight: 700;
    font-family: var(--font, 'Vazirmatn'), sans-serif;
    letter-spacing: 0.01em;
}
.code-lang::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--code-lang);
    box-shadow: 0 0 0 3px rgba(138, 180, 255, 0.18);
    flex-shrink: 0;
}

/* copy button — pill with a clear copied state */
.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 6px 13px;
    border-radius: 999px;
    cursor: pointer;
    font-family: var(--font, 'Vazirmatn'), sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    transition: background .2s ease, color .2s ease, border-color .2s ease, transform .12s ease;
}
.copy-btn:hover { background: rgba(255, 255, 255, 0.2); transform: translateY(-1px); }
.copy-btn:active { transform: translateY(0); }
.copy-btn i { font-size: 0.85rem; }
.copy-btn.is-copied {
    background: var(--ok);
    border-color: var(--ok);
    color: #04210f;
}
.copy-btn.is-copied i { color: #04210f; }

.code-content {
    margin: 0;
    padding: 18px 18px 20px;
    color: var(--code-text);
    font-family: 'Vazirmatn', 'Consolas', 'Monaco', monospace;
    font-size: 0.98rem;
    line-height: 1.85;
    /* Mixed Persian/English prompts: let each line pick its own direction
       from its first strong character instead of forcing LTR. */
    unicode-bidi: plaintext;
    text-align: start;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.code-content::selection { background: rgba(138, 180, 255, 0.35); }

/* When JS generated the card, the original <pre>/<code> chrome is dropped.
   Guard against double monospace/box styling from prompt.css on the inner code. */
.code-content code {
    background: none !important;
    padding: 0 !important;
    color: inherit !important;
    font-family: inherit !important;
    font-size: inherit !important;
    white-space: inherit !important;
}

/* =========================================================================
   3. RESPONSIVE TABLES  ->  STACKED CARDS ON MOBILE
   JS adds .cmp-rtable to article tables and data-label="<header>" to each
   <td>. Desktop stays a normal table; phones become one card per row with
   no horizontal scroll (multi-word Persian names no longer shatter).
   ========================================================================= */
.cmp-rtable { width: 100%; border-collapse: collapse; }

@media (max-width: 768px) {
    /* the wrapper stops scrolling — cards fit the viewport */
    .glass-table-wrapper {
        overflow: visible;
        background: none;
        border: none;
        box-shadow: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        padding: 0;
    }

    .cmp-rtable,
    .cmp-rtable tbody { display: block; width: 100%; min-width: 0 !important; }

    /* headers are conveyed per-cell via data-label, so hide the header row */
    .cmp-rtable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

    .cmp-rtable tr {
        display: block;
        background: #fff;
        border: 1px solid var(--line, #ebedf0);
        border-radius: var(--radius-sm, 14px);
        margin: 0 0 14px;
        padding: 4px 14px;
        box-shadow: 0 6px 20px -14px rgba(15, 23, 42, 0.35);
        min-width: 0 !important;
    }

    /* Stacked label-above-value (block, not flex). Flex turned inline <a>/<strong>
       inside a cell into separate flex items that overflowed the card on phones;
       block keeps the whole value as one wrapping unit at full width. */
    .cmp-rtable td {
        display: block;
        padding: 11px 0;
        border: none;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        text-align: start;
        word-break: normal;
        overflow-wrap: anywhere;
        min-width: 0 !important;
    }
    .cmp-rtable tr td:last-child { border-bottom: none; }

    /* the column header, shown as a bold label stacked above the value */
    .cmp-rtable td::before {
        content: attr(data-label);
        display: block;
        font-weight: 800;
        color: var(--text-secondary, #565a60);
        margin-bottom: 3px;
        text-align: start;
    }
    /* rows without a usable header label just show the value full-width */
    .cmp-rtable td[data-label=""]::before,
    .cmp-rtable td:not([data-label])::before { content: none; }
}

/* =========================================================================
   4. MOBILE RHYTHM + OVERFLOW HARDENING
   Root cause of the "متن چسبیده به لبه / زده بیرون" feeling: blocks that
   ignore the gutter or force width. Cap everything to the viewport and give
   a single consistent, comfortable gutter. Authoritative (loads last).
   ========================================================================= */
/* ❗ THE REAL GUTTER FIX
   On these articles the body (.article-content) is a DIRECT CHILD OF <body>,
   NOT inside a padded .container. With no horizontal padding of its own it
   spans edge-to-edge on phones, so every paragraph / info-box / list / card /
   table sits flush against the screen edge (the "چسبیده به لبه" complaint).
   Pad the wrapper itself, at every width. Children inherit the gutter. */
.article-content { padding-inline: var(--cmp-gutter); }
.breadcrumb { margin-inline: var(--cmp-gutter); }

@media (max-width: 768px) {
    .container { padding-inline: var(--cmp-gutter); }
    .article-header { padding-inline: var(--cmp-gutter); }

    /* nothing inside an article may exceed the viewport */
    .article-content,
    .article-content > * { max-width: 100%; min-width: 0; }
    .article-content img { height: auto; }

    /* code on phones: slightly smaller + tighter so long lines stay readable */
    .code-content { font-size: 0.9rem; padding: 16px 14px 18px; }
    .code-header { padding: 8px 10px 8px 12px; }
    .copy-btn { padding: 6px 11px; font-size: 0.76rem; }
}

/* =========================================================================
   5. CTA READABILITY
   .cta-box sets color:#fff, but `.article-content h2/p` (dark) win on
   specificity, so the heading + text rendered dark-on-gradient (unreadable).
   Force white for text elements inside the CTA — but NOT the .btn (keeps its
   own white-bg / blue-text styling).
   ========================================================================= */
.cta-box,
.cta-box h1, .cta-box h2, .cta-box h3, .cta-box h4,
.cta-box p, .cta-box li, .cta-box .lead, .cta-box span:not(.btn span) {
    color: #fff !important;
}
.cta-box h2::after { background: rgba(255, 255, 255, 0.5); }
.cta-box a:not(.btn) { color: #fff; text-decoration: underline; }
/* the action button keeps its solid readable look */
.cta-box .btn:not(.btn-soft) { background: #fff; color: var(--primary-blue, #066ac9) !important; }
