/* =========================================================
   CODE-COPY.CSS — CSE STUDY247
   Astra Child Theme — Code Copy Button

   Table of Contents
   -----------------
   1.  Pre wrapper (positioning context)
   2.  Copy button — base
   3.  Copy button — states (hover / active / focus / copied)
   4.  Responsive — Mobile (≤ 768px)
   5.  Accessibility — Reduced Motion
   =========================================================

   SCOPE NOTES:
   • All rules target .code-copy-pre-wrapper or .code-copy-btn.
   • Never touches .mermaid, blockquote, table, or any
     existing BetterDocs selector.
   • `pre` gets `position: relative` only when our wrapper
     class is present — zero bleed to unrelated <pre> tags.
   ========================================================= */


/* =========================================================
   1. PRE WRAPPER — POSITIONING CONTEXT
   The JS wraps every eligible <pre> in a div that carries
   this class, giving us a clean stacking context for the
   absolutely-positioned button without touching the <pre>
   element's own CSS properties beyond what already exists.
   ========================================================= */

.code-copy-pre-wrapper {
    position: relative;  /* stacking context for the button  */
    display: block;      /* behaves like a block-level element */
}


/* =========================================================
   2. COPY BUTTON — BASE
   ========================================================= */

.code-copy-btn {
    /* Positioning — top-right corner, inside the wrapper */
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;

    /* Sizing & shape */
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    min-width: 58px;
    height: 28px;
    border-radius: 5px;

    /* Typography */
    font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1;
    white-space: nowrap;

    /* Colours — dark button on dark code background */
    color: #c9d1d9;
    background: rgba(48, 54, 61, 0.85);
    border: 1px solid rgba(240, 246, 252, 0.15);

    /* Interaction */
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;

    /* Smooth transitions — only opacity + background */
    transition:
        background  0.15s ease,
        color       0.15s ease,
        border-color 0.15s ease,
        opacity     0.15s ease;

    /* Prevent button text leaking into clipboard reads */
    pointer-events: auto;
}

/* SVG clipboard icon (inline SVG injected by JS) */
.code-copy-btn svg {
    display: inline-block;
    flex-shrink: 0;
    vertical-align: middle;
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}


/* =========================================================
   3. COPY BUTTON — STATES
   ========================================================= */

/* Hover */
.code-copy-btn:hover {
    background: rgba(88, 96, 105, 0.9);
    color: #f0f6fc;
    border-color: rgba(240, 246, 252, 0.3);
}

/* Active / Pressed */
.code-copy-btn:active {
    background: rgba(30, 35, 42, 0.95);
    transform: translateY(1px);
}

/* Keyboard focus — visible ring for accessibility */
.code-copy-btn:focus-visible {
    outline: 2px solid #58a6ff;
    outline-offset: 2px;
}

/* Legacy :focus fallback (browsers that don't support :focus-visible) */
.code-copy-btn:focus:not(:focus-visible) {
    outline: none;
}

/* Copied! state — applied by JS as .code-copy-btn--copied */
.code-copy-btn--copied {
    background: rgba(35, 134, 54, 0.85);
    color: #aff5b4;
    border-color: rgba(63, 185, 80, 0.4);
}

.code-copy-btn--copied:hover {
    background: rgba(46, 160, 67, 0.9);
    color: #aff5b4;
    border-color: rgba(63, 185, 80, 0.55);
}

/* Small icon inside copied state */
.code-copy-btn--copied svg {
    stroke: #aff5b4;
}


/* =========================================================
   4. RESPONSIVE — MOBILE (max-width: 768px)
   Keep the button accessible on smaller screens.
   ========================================================= */

@media (max-width: 768px) {

    .code-copy-btn {
        /* Slightly larger tap target on mobile */
        padding: 5px 10px;
        height: 30px;
        font-size: 11px;
        top: 8px;
        right: 8px;
        /* Slight opacity so it does not fully obscure first line */
        opacity: 0.85;
    }
}


/* =========================================================
   5. ACCESSIBILITY — REDUCED MOTION
   The button's transition is already subtle, but honour
   prefers-reduced-motion by removing the transform on :active.
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    .code-copy-btn,
    .code-copy-btn--copied {
        transition: none;
    }

    .code-copy-btn:active {
        transform: none;
    }
}
