/* ============================================
   Prism.js - Thème personnalisé Java Facile
   S'adapte automatiquement au mode clair/sombre
   ============================================ */

/* Container du bloc de code */
pre[class*="language-"] {
    position: relative;
    margin: 1.5rem 0;
    padding: 1.25rem;
    border-radius: 0.5rem;
    overflow: auto;
    font-size: 0.875rem;
    line-height: 1.7;
    tab-size: 4;
    -moz-tab-size: 4;
    border: 1px solid var(--border-color);
}

code[class*="language-"],
pre[class*="language-"] {
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
    text-align: left;
    white-space: pre;
    word-spacing: normal;
    word-break: normal;
    word-wrap: normal;
    hyphens: none;
}

/* Inline code */
:not(pre) > code {
    padding: 0.2em 0.4em;
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, Monaco, monospace;
}

/* ============================================
   Thème Clair
   ============================================ */
:root[data-theme="light"] pre[class*="language-"],
:root[data-theme="light"] code[class*="language-"] {
    background: #f6f8fa;
    color: #24292e;
}

:root[data-theme="light"] :not(pre) > code {
    background: #f6f8fa;
    color: #24292e;
}

/* Tokens - Thème Clair */
:root[data-theme="light"] .token.comment,
:root[data-theme="light"] .token.prolog,
:root[data-theme="light"] .token.doctype,
:root[data-theme="light"] .token.cdata {
    color: #6a737d;
    font-style: italic;
}

:root[data-theme="light"] .token.punctuation {
    color: #24292e;
}

:root[data-theme="light"] .token.property,
:root[data-theme="light"] .token.tag,
:root[data-theme="light"] .token.boolean,
:root[data-theme="light"] .token.number,
:root[data-theme="light"] .token.constant,
:root[data-theme="light"] .token.symbol,
:root[data-theme="light"] .token.deleted {
    color: #005cc5;
}

:root[data-theme="light"] .token.selector,
:root[data-theme="light"] .token.attr-name,
:root[data-theme="light"] .token.string,
:root[data-theme="light"] .token.char,
:root[data-theme="light"] .token.builtin,
:root[data-theme="light"] .token.inserted {
    color: #22863a;
}

:root[data-theme="light"] .token.operator,
:root[data-theme="light"] .token.entity,
:root[data-theme="light"] .token.url,
:root[data-theme="light"] .language-css .token.string,
:root[data-theme="light"] .style .token.string {
    color: #d73a49;
}

:root[data-theme="light"] .token.atrule,
:root[data-theme="light"] .token.attr-value,
:root[data-theme="light"] .token.keyword {
    color: #d73a49;
}

:root[data-theme="light"] .token.function,
:root[data-theme="light"] .token.class-name {
    color: #6f42c1;
}

:root[data-theme="light"] .token.regex,
:root[data-theme="light"] .token.important,
:root[data-theme="light"] .token.variable {
    color: #e36209;
}

:root[data-theme="light"] .token.annotation {
    color: #6f42c1;
}

/* ============================================
   Thème Sombre
   ============================================ */
:root[data-theme="dark"] pre[class*="language-"],
:root[data-theme="dark"] code[class*="language-"] {
    background: #161b22;
    color: #c9d1d9;
}

:root[data-theme="dark"] :not(pre) > code {
    background: #161b22;
    color: #c9d1d9;
}

/* Tokens - Thème Sombre */
:root[data-theme="dark"] .token.comment,
:root[data-theme="dark"] .token.prolog,
:root[data-theme="dark"] .token.doctype,
:root[data-theme="dark"] .token.cdata {
    color: #8b949e;
    font-style: italic;
}

:root[data-theme="dark"] .token.punctuation {
    color: #c9d1d9;
}

:root[data-theme="dark"] .token.property,
:root[data-theme="dark"] .token.tag,
:root[data-theme="dark"] .token.boolean,
:root[data-theme="dark"] .token.number,
:root[data-theme="dark"] .token.constant,
:root[data-theme="dark"] .token.symbol,
:root[data-theme="dark"] .token.deleted {
    color: #79c0ff;
}

:root[data-theme="dark"] .token.selector,
:root[data-theme="dark"] .token.attr-name,
:root[data-theme="dark"] .token.string,
:root[data-theme="dark"] .token.char,
:root[data-theme="dark"] .token.builtin,
:root[data-theme="dark"] .token.inserted {
    color: #a5d6ff;
}

:root[data-theme="dark"] .token.operator,
:root[data-theme="dark"] .token.entity,
:root[data-theme="dark"] .token.url,
:root[data-theme="dark"] .language-css .token.string,
:root[data-theme="dark"] .style .token.string {
    color: #ff7b72;
}

:root[data-theme="dark"] .token.atrule,
:root[data-theme="dark"] .token.attr-value,
:root[data-theme="dark"] .token.keyword {
    color: #ff7b72;
}

:root[data-theme="dark"] .token.function,
:root[data-theme="dark"] .token.class-name {
    color: #d2a8ff;
}

:root[data-theme="dark"] .token.regex,
:root[data-theme="dark"] .token.important,
:root[data-theme="dark"] .token.variable {
    color: #ffa657;
}

:root[data-theme="dark"] .token.annotation {
    color: #d2a8ff;
}

/* ============================================
   Bouton Copier
   ============================================ */
.code-block-wrapper {
    position: relative;
}

.copy-button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.4rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.code-block-wrapper:hover .copy-button,
pre[class*="language-"]:hover + .copy-button,
.copy-button:focus {
    opacity: 1;
}

.copy-button:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.copy-button.copied {
    color: #22863a;
    background: rgba(34, 134, 58, 0.1);
    border-color: #22863a;
}

:root[data-theme="dark"] .copy-button.copied {
    color: #7ee787;
    background: rgba(126, 231, 135, 0.1);
    border-color: #7ee787;
}

.copy-button svg {
    width: 14px;
    height: 14px;
}

/* ============================================
   Numéros de lignes (optionnel)
   ============================================ */
pre[class*="language-"].line-numbers {
    padding-left: 3.8em;
    counter-reset: linenumber;
}

pre[class*="language-"].line-numbers > code {
    position: relative;
    white-space: inherit;
}

.line-numbers .line-numbers-rows {
    position: absolute;
    pointer-events: none;
    top: 1.25rem;
    left: 0;
    width: 3em;
    font-size: 100%;
    letter-spacing: -1px;
    border-right: 1px solid var(--border-color);
    user-select: none;
}

.line-numbers-rows > span {
    display: block;
    counter-increment: linenumber;
}

.line-numbers-rows > span:before {
    content: counter(linenumber);
    color: var(--text-tertiary);
    display: block;
    padding-right: 0.8em;
    text-align: right;
}

/* ============================================
   Scrollbar personnalisée pour les blocs de code
   ============================================ */
pre[class*="language-"]::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

pre[class*="language-"]::-webkit-scrollbar-track {
    background: transparent;
}

pre[class*="language-"]::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

pre[class*="language-"]::-webkit-scrollbar-thumb:hover {
    background: var(--border-color-hover);
}

/* ============================================
   Styles supplémentaires pour la lisibilité
   ============================================ */
.token.important,
.token.bold {
    font-weight: bold;
}

.token.italic {
    font-style: italic;
}

.token.entity {
    cursor: help;
}

/* Highlight de lignes */
.line-highlight {
    background: rgba(255, 255, 0, 0.1);
    border-left: 3px solid var(--color-primary);
    margin-left: -1.25rem;
    padding-left: calc(1.25rem - 3px);
}

:root[data-theme="dark"] .line-highlight {
    background: rgba(255, 255, 0, 0.05);
}
