/**
 * WP Code Highlighter - 代码高亮样式
 * Version: 1.0.0
 */

/* ========================================
   代码块容器 - 整体框架
   ======================================== */
.wpch-code-wrapper {
    position: relative;
    margin: 1.5em 0;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

.wpch-code-wrapper:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    border-color: #cbd5e1;
}

/* ========================================
   代码块头部 - 语言标签 + 按钮区
   ======================================== */
.wpch-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    user-select: none;
    flex-wrap: nowrap;
    gap: 8px;
}

.wpch-code-lang {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 0.025em;
    text-transform: none;
    white-space: nowrap;
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wpch-code-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* ========================================
   按钮样式
   ======================================== */
.wpch-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.5;
    color: #475569;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.wpch-btn:hover {
    color: #1e293b;
    background: #e2e8f0;
    border-color: #cbd5e1;
}

.wpch-btn:active {
    transform: scale(0.96);
    background: #cbd5e1;
}

.wpch-btn:focus-visible {
    outline: 2px solid #6366f1;
    outline-offset: 1px;
}

.wpch-icon {
    flex-shrink: 0;
    display: block;
}

/* 复制按钮 - 复制成功状态 */
.wpch-btn-copy.copied {
    color: #16a34a;
}

.wpch-btn-copy.copied .wpch-icon {
    stroke: #16a34a;
}

.wpch-btn-copy.copied:hover {
    color: #15803d;
    background: #dcfce7;
    border-color: #bbf7d0;
}

/* 全屏按钮 */
.wpch-btn-fullscreen.active {
    color: #6366f1;
    background: #eef2ff;
    border-color: #c7d2fe;
}

/* ========================================
   代码主体区域 - 可滚动
   ======================================== */
.wpch-code-body {
    position: relative;
    max-height: 500px;
    overflow: auto;
    background: #1e293b;
    scroll-behavior: smooth;
}

/* 代码块内部样式 */
.wpch-code-body pre {
    margin: 0 !important;
    padding: 16px !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    font-size: 14px !important;
    line-height: 1.65 !important;
    font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", "SF Mono", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace !important;
    overflow: visible !important;
    white-space: pre !important;
    word-wrap: normal !important;
    tab-size: 4;
    -moz-tab-size: 4;
    min-width: 100%;
    width: fit-content;
    box-sizing: border-box;
}

.wpch-code-body pre code {
    font-family: inherit !important;
    font-size: inherit !important;
    line-height: inherit !important;
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    color: inherit !important;
    display: block;
}

/* ========================================
   自定义滚动条
   ======================================== */
.wpch-code-body::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.wpch-code-body::-webkit-scrollbar-track {
    background: #334155;
    border-radius: 4px;
}

.wpch-code-body::-webkit-scrollbar-thumb {
    background: #64748b;
    border-radius: 4px;
    border: 2px solid #334155;
}

.wpch-code-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.wpch-code-body::-webkit-scrollbar-corner {
    background: #334155;
}

/* Firefox 滚动条 */
.wpch-code-body {
    scrollbar-width: thin;
    scrollbar-color: #64748b #334155;
}

/* ========================================
   全屏模式
   ======================================== */
.wpch-code-wrapper.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 0;
    z-index: 99999;
    box-shadow: none;
}

.wpch-code-wrapper.fullscreen .wpch-code-body {
    max-height: none !important;
    height: calc(100vh - 41px) !important; /* 减去头部高度 */
}

.wpch-code-wrapper.fullscreen .wpch-code-header {
    border-radius: 0;
}

/* 全屏遮罩背景 */
.wpch-fullscreen-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99998;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.wpch-fullscreen-overlay.active {
    display: block;
}

/* ========================================
   WordPress 主题兼容 - 覆盖主题默认样式
   ======================================== */
/* 覆盖主题可能给 pre/code 加的背景色 */
.wpch-code-body pre {
    background: transparent !important;
    background-color: transparent !important;
    background-image: none !important;
}

/* 确保主题不会破坏代码块内的样式 */
.wpch-code-wrapper *,
.wpch-code-wrapper *::before,
.wpch-code-wrapper *::after {
    box-sizing: border-box;
}

/* ========================================
   移动端适配
   ======================================== */
@media screen and (max-width: 768px) {
    .wpch-code-wrapper {
        margin: 1em 0;
        border-radius: 6px;
    }

    .wpch-code-header {
        padding: 6px 10px;
    }

    .wpch-code-lang {
        font-size: 11px;
    }

    .wpch-btn {
        padding: 4px 8px;
        font-size: 11px;
        gap: 3px;
    }

    .wpch-btn-text {
        display: none; /* 移动端隐藏按钮文字,只显示图标 */
    }

    .wpch-btn {
        padding: 6px;
        min-width: 30px;
    }

    .wpch-code-body {
        max-height: 360px;
    }

    .wpch-code-body pre {
        padding: 12px !important;
        font-size: 13px !important;
        line-height: 1.55 !important;
    }

    .wpch-icon {
        width: 15px;
        height: 15px;
    }
}

@media screen and (max-width: 480px) {
    .wpch-code-wrapper {
        margin: 0.75em 0;
        border-radius: 5px;
    }

    .wpch-code-header {
        padding: 5px 8px;
    }

    .wpch-code-body {
        max-height: 300px;
    }

    .wpch-code-body pre {
        padding: 10px !important;
        font-size: 12px !important;
        line-height: 1.5 !important;
    }

    .wpch-code-body::-webkit-scrollbar {
        width: 5px;
        height: 5px;
    }
}

/* ========================================
   深色主题适配（如果主题使用暗色背景）
   ======================================== */
@media (prefers-color-scheme: dark) {
    .wpch-code-wrapper {
        border-color: #334155;
        background: #0f172a;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    }

    .wpch-code-wrapper:hover {
        border-color: #475569;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .wpch-code-header {
        background: #1e293b;
        border-bottom-color: #334155;
    }

    .wpch-code-lang {
        color: #94a3b8;
    }

    .wpch-btn {
        color: #94a3b8;
    }

    .wpch-btn:hover {
        color: #e2e8f0;
        background: #334155;
        border-color: #475569;
    }

    .wpch-btn:active {
        background: #475569;
    }

    .wpch-code-body {
        background: #020617;
    }

    .wpch-btn-copy.copied {
        color: #4ade80;
    }

    .wpch-btn-copy.copied:hover {
        background: rgba(74, 222, 128, 0.1);
        border-color: rgba(74, 222, 128, 0.2);
    }

    .wpch-btn-fullscreen.active {
        color: #818cf8;
        background: rgba(99, 102, 241, 0.1);
        border-color: rgba(99, 102, 241, 0.2);
    }
}

/* ========================================
   打印样式
   ======================================== */
@media print {
    .wpch-code-wrapper {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
        page-break-inside: avoid;
    }

    .wpch-code-body {
        max-height: none;
        overflow: visible;
    }

    .wpch-code-header {
        background: #f0f0f0;
    }

    .wpch-btn {
        display: none;
    }

    .wpch-fullscreen-overlay {
        display: none !important;
    }
}

/* ========================================
   动画效果
   ======================================== */
@keyframes wpch-copy-flash {
    0%   { background-color: rgba(22, 163, 74, 0.15); }
    50%  { background-color: rgba(22, 163, 74, 0.3); }
    100% { background-color: transparent; }
}

.wpch-btn-copy.flash {
    animation: wpch-copy-flash 0.5s ease;
}

@keyframes wpch-fade-in {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.wpch-code-wrapper.fullscreen {
    animation: wpch-fade-in 0.2s ease-out;
}
