/* Code Enhancement Styles for PMCP Book */

/* Rust syntax highlighting enhancements */
.language-rust {
    position: relative;
}

.language-rust::before {
    content: "🦀 Rust";
    position: absolute;
    top: 8px;
    right: 8px;
    background: #CE422B;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

/* TOML syntax highlighting */
.language-toml::before {
    content: "📝 TOML";
    position: absolute;
    top: 8px;
    right: 8px;
    background: #1976D2;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

/* Bash/Shell syntax highlighting */
.language-bash::before,
.language-sh::before {
    content: "🐚 Shell";
    position: absolute;
    top: 8px;
    right: 8px;
    background: #4CAF50;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

/* JSON syntax highlighting */
.language-json::before {
    content: "📋 JSON";
    position: absolute;
    top: 8px;
    right: 8px;
    background: #FF9800;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

/* Output/console highlighting */
.language-console::before,
.language-output::before {
    content: "💻 Output";
    position: absolute;
    top: 8px;
    right: 8px;
    background: #424242;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

/* Code block enhancements */
.code-block-wrapper {
    position: relative;
    margin: 16px 0;
}

.code-block-title {
    background-color: var(--pmcp-primary);
    color: white;
    padding: 8px 16px;
    font-size: 0.9em;
    font-weight: 500;
    border-radius: 4px 4px 0 0;
    margin-bottom: 0;
}

.code-block-content {
    margin-top: 0 !important;
    border-radius: 0 0 4px 4px;
}

/* Inline code styling */
code {
    background-color: var(--pmcp-bg-code);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 0.9em;
}

/* Copy button styling */
.copy-button {
    position: absolute;
    top: 8px;
    right: 40px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.8em;
    opacity: 0;
    transition: opacity 0.2s;
}

pre:hover .copy-button {
    opacity: 1;
}

.copy-button:hover {
    background: white;
}

/* Line number styling */
.hljs-ln {
    border-collapse: collapse;
}

.hljs-ln-line {
    white-space: pre;
}

.hljs-ln-numbers {
    text-align: right;
    color: var(--pmcp-text-muted);
    padding-right: 16px;
    user-select: none;
    border-right: 1px solid var(--theme-hover);
}

.hljs-ln-code {
    padding-left: 16px;
}

/* Highlighted lines */
.code-line-highlighted {
    background-color: rgba(30, 136, 229, 0.1);
    margin: 0 -16px;
    padding: 0 16px;
}

.code-line-added {
    background-color: rgba(76, 175, 80, 0.1);
    margin: 0 -16px;
    padding: 0 16px;
}

.code-line-removed {
    background-color: rgba(244, 67, 54, 0.1);
    margin: 0 -16px;
    padding: 0 16px;
}

/* Error highlighting in code */
.code-error {
    background-color: rgba(244, 67, 54, 0.2);
    text-decoration: underline wavy red;
}

.code-warning {
    background-color: rgba(255, 152, 0, 0.2);
    text-decoration: underline wavy orange;
}

/* Code annotation tooltips */
.code-annotation {
    position: relative;
    border-bottom: 2px dotted var(--pmcp-primary);
    cursor: help;
}

.code-annotation:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 1000;
    font-size: 0.8em;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Expandable code sections */
.code-expandable {
    max-height: 300px;
    overflow: hidden;
    position: relative;
}

.code-expandable.expanded {
    max-height: none;
}

.code-expand-button {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, var(--bg));
    text-align: center;
    padding: 20px 0 10px;
    cursor: pointer;
    color: var(--pmcp-primary);
    font-weight: 500;
}

.code-expand-button:hover {
    text-decoration: underline;
}

/* Playground integration styling */
.playground-button {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--pmcp-success);
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8em;
    opacity: 0;
    transition: opacity 0.2s;
}

pre:hover .playground-button {
    opacity: 1;
}

.playground-button:hover {
    background: #388E3C;
}

/* Dark theme adjustments */
.ayu .copy-button {
    background: rgba(0, 0, 0, 0.8);
    border-color: #555;
    color: white;
}

.ayu .copy-button:hover {
    background: black;
}

.ayu .hljs-ln-numbers {
    border-right-color: #555;
}

.ayu code {
    background-color: var(--pmcp-bg-code-dark);
}