/**
 * CloudScale Code Block, Frontend Styles v1.7.5
 *
 * Uses CSS custom properties (--cs-bg, --cs-toolbar-bg, etc.) set by the
 * frontend JS from csCodeConfig, so any highlight.js theme pair works.
 */

/* 1. WRAPPER: full width by default */
.cs-code-wrapper {
    --cs-bg: #282c34;
    --cs-toolbar-bg: #21252b;
    --cs-toolbar-border: rgba(255,255,255,0.08);
    --cs-text-muted: rgba(255,255,255,0.80);
    --cs-text-title: #9da5b4;
    --cs-hover-bg: rgba(255,255,255,0.08);
    --cs-hover-color: #abb2bf;
    --cs-scrollbar-track: var(--cs-bg);
    --cs-scrollbar-thumb: rgba(255,255,255,0.15);
    --cs-line-border: rgba(255,255,255,0.08);
    --cs-line-color: rgba(255,255,255,0.2);
    --cs-active-accent: #61afef;
    --cs-active-accent-bg: rgba(97,175,239,0.12);

    position: relative;
    margin: 1.5em 0;
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Consolas', 'Liberation Mono', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
    background: var(--cs-bg);
}

/* Light mode overrides applied by JS via data-active-theme="light" */
.cs-code-wrapper[data-active-theme="light"] {
    --cs-toolbar-border: rgba(0,0,0,0.1);
    --cs-text-muted: rgba(0,0,0,0.70);
    --cs-text-title: #5c6370;
    --cs-hover-bg: rgba(0,0,0,0.08);
    --cs-hover-color: #383a42;
    --cs-scrollbar-thumb: rgba(0,0,0,0.15);
    --cs-line-border: rgba(0,0,0,0.1);
    --cs-line-color: rgba(0,0,0,0.25);
    --cs-active-accent: #4078f2;
    --cs-active-accent-bg: rgba(64,120,242,0.12);
}

/* 2. TOOLBAR */
.cs-code-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    min-height: 36px;
    user-select: none;
    background: var(--cs-toolbar-bg);
    border-bottom: 1px solid var(--cs-toolbar-border);
}

/* 3. BRAND LINK, use wrapper specificity to override theme a{color} rules */
.cs-code-wrapper .cs-code-brand {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-decoration: none;
    flex-shrink: 0;
    color: #61afef !important;
    opacity: 0.85;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.cs-code-wrapper .cs-code-brand:hover {
    opacity: 1;
    color: #0fb8e0 !important;
}

.cs-code-wrapper[data-active-theme="light"] .cs-code-brand {
    color: var(--wp-admin-theme-color, #2271b1) !important;
}

.cs-code-wrapper[data-active-theme="light"] .cs-code-brand:hover {
    color: #135e96 !important;
}

.cs-brand-bolt {
    font-style: normal;
}

/* 3. TITLE */
.cs-code-title {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50%;
    color: var(--cs-text-title);
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid var(--cs-toolbar-border);
}

/* 4. ACTIONS */
.cs-code-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.cs-code-lang-badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 2px 7px;
    border-radius: 4px;
    line-height: 1.4;
    color: #ffffff;
    background: var(--cs-hover-bg);
}

.cs-code-lang-badge:empty {
    display: none;
}

/* Buttons */
.cs-code-theme-toggle,
.cs-code-lines-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    background: transparent;
    line-height: 1;
    color: #ffffff;
}

.cs-code-theme-toggle:hover,
.cs-code-lines-toggle:hover {
    color: var(--cs-hover-color);
    background: var(--cs-hover-bg);
}

/* GitHub linked button, icon + "Linked" label (mirrors the Copy button) */
.cs-code-gh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    padding: 0 8px 0 6px;
    gap: 4px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    background: transparent;
    line-height: 1;
}
.cs-code-wrapper .cs-code-gh-btn,
.cs-code-wrapper .cs-code-gh-btn:visited,
.cs-code-wrapper .cs-code-gh-btn .cs-gh-label {
    text-decoration: none !important;
}
.cs-gh-label {
    display: inline-block;
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

/* GitHub toolbar icon, use wrapper specificity + !important so theme a{color}
   rules can't darken it (same pattern as .cs-code-brand). */
.cs-code-wrapper .cs-code-gh-btn {
    color: #ffffff !important;
}
.cs-code-wrapper .cs-code-gh-btn:hover,
.cs-code-wrapper .cs-code-gh-btn:focus {
    color: #0fb8e0 !important;
    background: var(--cs-hover-bg);
}
.cs-code-wrapper .cs-code-gh-btn:hover .cs-gh-label,
.cs-code-wrapper .cs-code-gh-btn:focus .cs-gh-label {
    text-decoration: underline !important;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}
.cs-code-wrapper[data-active-theme="light"] .cs-code-gh-btn {
    color: var(--wp-admin-theme-color, #2271b1) !important;
}
.cs-code-wrapper[data-active-theme="light"] .cs-code-gh-btn:hover,
.cs-code-wrapper[data-active-theme="light"] .cs-code-gh-btn:focus {
    color: #0fb8e0 !important;
}

/* Copy button, icon + label */
.cs-code-copy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    padding: 0 8px 0 6px;
    gap: 4px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    background: transparent;
    line-height: 1;
    color: #ffffff;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
}

.cs-code-copy:hover {
    color: var(--cs-hover-color);
    background: var(--cs-hover-bg);
}

.cs-copy-label {
    display: inline-block;
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

/* Copy success */
.cs-code-copy.copied {
    color: #98c379 !important;
}

.cs-code-copy.copied .cs-copy-label {
    display: none;
}

.cs-code-copy .cs-icon-check {
    display: none;
}

.cs-code-copy.copied .cs-icon-copy {
    display: none;
}

.cs-code-copy.copied .cs-icon-check {
    display: inline;
}

/* Theme icon toggles: default to showing sun (dark mode active) */
.cs-icon-moon {
    display: none;
}

.cs-icon-sun {
    display: inline;
}

.cs-code-wrapper[data-active-theme="dark"] .cs-icon-moon {
    display: none;
}

.cs-code-wrapper[data-active-theme="dark"] .cs-icon-sun {
    display: inline;
}

.cs-code-wrapper[data-active-theme="light"] .cs-icon-sun {
    display: none;
}

.cs-code-wrapper[data-active-theme="light"] .cs-icon-moon {
    display: inline;
}

/* Active state for line numbers toggle */
.cs-code-wrapper.cs-lines-active .cs-code-lines-toggle {
    color: var(--cs-active-accent);
    background: var(--cs-active-accent-bg);
}

/* 5. CODE BLOCK: full width, no wrapping, horizontal scroll */
.cs-code-body {
    display: flex;
    position: relative;
}

.cs-code-body pre {
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    border-radius: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    flex: 1;
    min-width: 0;
}

.cs-code-body pre code {
    display: block;
    padding: 16px 18px !important;
    margin: 0 !important;
    overflow-x: auto;
    white-space: pre !important;
    word-wrap: normal !important;
    overflow-wrap: normal !important;
    tab-size: 4;
    border: none !important;
    border-radius: 0 !important;
    width: 100% !important;
    background: var(--cs-bg) !important;
    color: #abb2bf !important;
}

.cs-code-wrapper[data-active-theme="light"] .cs-code-body pre code {
    color: #383a42 !important;
}

/* Scrollbar */
.cs-code-body pre code::-webkit-scrollbar {
    height: 6px;
}

.cs-code-body pre code::-webkit-scrollbar-track {
    background: var(--cs-scrollbar-track);
}

.cs-code-body pre code::-webkit-scrollbar-thumb {
    background: var(--cs-scrollbar-thumb);
    border-radius: 3px;
}

/* 7. LINE NUMBERS GUTTER */
.cs-code-line-numbers {
    display: flex;
    flex-direction: column;
    padding: 16px 0 16px 14px;
    text-align: right;
    user-select: none;
    flex-shrink: 0;
    line-height: 1.6;
    font-size: inherit;
    font-family: inherit;
    min-width: 2.5em;
    box-sizing: border-box;
    color: var(--cs-line-color);
    border-right: 1px solid var(--cs-line-border);
    background: var(--cs-bg);
}

.cs-code-line-numbers span {
    display: block;
    padding-right: 10px;
    line-height: 1.6;
}

/* ── Token colour overrides ──────────────────────────────────────────────────
   WordPress themes often carry high-specificity rules like
   `.entry-content span { color: inherit }` that silently beat the CDN hljs
   stylesheet rules (which carry no !important).  Scoping every token class
   to .cs-code-wrapper gives us two class selectors (0,2,0), beating any
   reasonable theme element+class rule (0,1,1), without touching the CDN CSS.
   Colours match the default atom-one-dark / atom-one-light pair; other pairs
   still load correctly via the JS stylesheet swap.
   ─────────────────────────────────────────────────────────────────────────── */

/* Dark mode tokens (atom-one-dark) */
.cs-code-wrapper .hljs-comment,
.cs-code-wrapper .hljs-quote                                            { color: #a0c690 !important; font-style: italic; }
.cs-code-wrapper .hljs-doctag,
.cs-code-wrapper .hljs-keyword,
.cs-code-wrapper .hljs-formula                                          { color: #c678dd !important; }
.cs-code-wrapper .hljs-section,
.cs-code-wrapper .hljs-name,
.cs-code-wrapper .hljs-selector-tag,
.cs-code-wrapper .hljs-deletion,
.cs-code-wrapper .hljs-subst                                            { color: #e06c75 !important; }
.cs-code-wrapper .hljs-literal                                          { color: #56b6c2 !important; }
.cs-code-wrapper .hljs-string,
.cs-code-wrapper .hljs-regexp,
.cs-code-wrapper .hljs-addition,
.cs-code-wrapper .hljs-attribute                                        { color: #98c379 !important; }
.cs-code-wrapper .hljs-attr,
.cs-code-wrapper .hljs-variable,
.cs-code-wrapper .hljs-template-variable,
.cs-code-wrapper .hljs-type,
.cs-code-wrapper .hljs-selector-class,
.cs-code-wrapper .hljs-selector-attr,
.cs-code-wrapper .hljs-selector-pseudo,
.cs-code-wrapper .hljs-number                                           { color: #d19a66 !important; }
.cs-code-wrapper .hljs-symbol,
.cs-code-wrapper .hljs-bullet,
.cs-code-wrapper .hljs-link,
.cs-code-wrapper .hljs-meta,
.cs-code-wrapper .hljs-selector-id,
.cs-code-wrapper .hljs-title                                            { color: #61aeee !important; }
.cs-code-wrapper .hljs-built_in,
.cs-code-wrapper .hljs-title.class_                                     { color: #e6c07b !important; }
.cs-code-wrapper .hljs-emphasis                                         { font-style: italic; }
.cs-code-wrapper .hljs-strong                                           { font-weight: 700; }
.cs-code-wrapper .hljs-link                                             { text-decoration: underline; }

/* Light mode token overrides (atom-one-light) */
.cs-code-wrapper[data-active-theme="light"] .hljs-comment,
.cs-code-wrapper[data-active-theme="light"] .hljs-quote                 { color: #a0a1a7 !important; font-style: italic; }
.cs-code-wrapper[data-active-theme="light"] .hljs-doctag,
.cs-code-wrapper[data-active-theme="light"] .hljs-keyword,
.cs-code-wrapper[data-active-theme="light"] .hljs-formula               { color: #a626a4 !important; }
.cs-code-wrapper[data-active-theme="light"] .hljs-section,
.cs-code-wrapper[data-active-theme="light"] .hljs-name,
.cs-code-wrapper[data-active-theme="light"] .hljs-selector-tag,
.cs-code-wrapper[data-active-theme="light"] .hljs-deletion,
.cs-code-wrapper[data-active-theme="light"] .hljs-subst                 { color: #e45649 !important; }
.cs-code-wrapper[data-active-theme="light"] .hljs-literal               { color: #0184bb !important; }
.cs-code-wrapper[data-active-theme="light"] .hljs-string,
.cs-code-wrapper[data-active-theme="light"] .hljs-regexp,
.cs-code-wrapper[data-active-theme="light"] .hljs-addition,
.cs-code-wrapper[data-active-theme="light"] .hljs-attribute             { color: #50a14f !important; }
.cs-code-wrapper[data-active-theme="light"] .hljs-attr,
.cs-code-wrapper[data-active-theme="light"] .hljs-variable,
.cs-code-wrapper[data-active-theme="light"] .hljs-template-variable,
.cs-code-wrapper[data-active-theme="light"] .hljs-type,
.cs-code-wrapper[data-active-theme="light"] .hljs-selector-class,
.cs-code-wrapper[data-active-theme="light"] .hljs-selector-attr,
.cs-code-wrapper[data-active-theme="light"] .hljs-selector-pseudo,
.cs-code-wrapper[data-active-theme="light"] .hljs-number                { color: #986801 !important; }
.cs-code-wrapper[data-active-theme="light"] .hljs-symbol,
.cs-code-wrapper[data-active-theme="light"] .hljs-bullet,
.cs-code-wrapper[data-active-theme="light"] .hljs-link,
.cs-code-wrapper[data-active-theme="light"] .hljs-meta,
.cs-code-wrapper[data-active-theme="light"] .hljs-selector-id,
.cs-code-wrapper[data-active-theme="light"] .hljs-title                 { color: #4078f2 !important; }
.cs-code-wrapper[data-active-theme="light"] .hljs-built_in,
.cs-code-wrapper[data-active-theme="light"] .hljs-title.class_          { color: #c18401 !important; }

/* ── View on GitHub footer ──────────────────────────────────────────── */
.cs-code-gh-footer {
    display: flex;
    justify-content: flex-end;
    padding: 6px 12px 8px;
    border-top: 1px solid rgba(127, 127, 127, 0.15);
}
.cs-code-gh-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    text-decoration: none;
    color: inherit;
    opacity: 0.65;
    transition: opacity 120ms ease;
}
.cs-code-gh-link:hover,
.cs-code-gh-link:focus {
    opacity: 1;
    text-decoration: none;
}
.cs-code-gh-link svg {
    flex-shrink: 0;
}
