/**
 * Mermaid.js 自訂樣式
 * 配合 MrJet Blog 深色主題風格
 *
 * @author MrJet Blog Theme
 * @version 1.0.0
 */

/* ===================================
   Mermaid 容器基本樣式
   =================================== */

.mermaid-container {
    position: relative;
    margin: 2rem 0;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 12px;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    transition: all 0.3s ease;
}

.mermaid-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
}

@keyframes gradient-shift {
    0%, 100% {
        background: linear-gradient(90deg, #00F7DA 0%, #9B95C5 100%);
    }
    50% {
        background: linear-gradient(90deg, #9B95C5 0%, #00F7DA 100%);
    }
}

.mermaid-container:hover {
    transform: translateY(-2px);
    box-shadow: none;
}

/* Mermaid 圖表本身 */
.mermaid {
    text-align: center;
    background: transparent !important;
    padding: 1rem;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

/* 隱藏原始碼（渲染前） */
pre.mermaid {
    display: none;
}

/* 渲染後的 SVG - 使用 Space Grotesk 字體 */
.mermaid svg {
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 auto;
    font-family: 'Space Grotesk', sans-serif;
    display: block;
}

/* 確保所有圖表文字都使用 Space Grotesk */
.mermaid svg text,
.mermaid svg tspan {
    font-family: 'Space Grotesk', sans-serif;
}

/* ===================================
   全螢幕按鈕樣式 - 右上角
   =================================== */

.mermaid-fullscreen-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    padding: 0;
    background: rgba(155, 149, 197, 0.1);
    border: 1px solid rgba(155, 149, 197, 0.3);
    color: #9B95C5;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mermaid-fullscreen-btn:hover {
    background: rgba(155, 149, 197, 0.2);
    border-color: #9B95C5;
    transform: scale(1.05);
}

.mermaid-fullscreen-btn:active {
    transform: scale(0.95);
}

/* ===================================
   全螢幕模式
   =================================== */

.mermaid-container.mermaid-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(20px);
    overflow: auto;
    padding: 2rem;
    padding-bottom: 6rem;
}

.mermaid-fullscreen .mermaid {
    max-height: none;
    overflow: visible;
    padding: 0;
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mermaid-fullscreen .mermaid svg {
    max-height: none;
    width: auto;
    height: auto;
}

.mermaid-fullscreen .mermaid-fullscreen-btn {
    position: fixed;
    top: 2rem;
    right: 2rem;
}

/* ===================================
   錯誤訊息樣式
   =================================== */

.mermaid-error-message {
    padding: 1.5rem;
    background: rgba(255, 0, 0, 0.1);
    border: 1px solid rgba(255, 0, 0, 0.3);
    border-radius: 8px;
    color: #ff6b6b;
    text-align: center;
}

.mermaid-error-message i {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

.mermaid-error-message p {
    margin: 0.5rem 0;
    font-size: 1rem;
}

.mermaid-error-message details {
    margin-top: 1rem;
    text-align: left;
}

.mermaid-error-message summary {
    cursor: pointer;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    transition: background 0.3s;
}

.mermaid-error-message summary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.mermaid-error-message code {
    display: block;
    margin-top: 0.5rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    overflow-x: auto;
}

/* ===================================
   特定圖表類型樣式調整
   =================================== */

/* 流程圖 */
.mermaid .node rect,
.mermaid .node circle,
.mermaid .node ellipse,
.mermaid .node polygon {
    fill: #293038 !important;
    stroke: #00F7DA !important;
    stroke-width: 2px !important;
}

.mermaid .node text {
    fill: #FFFFFF !important;
}

.mermaid .edgeLabel {
    background-color: #1a1f24 !important;
    color: #FFFFFF !important;
}

.mermaid .edgePath .path {
    stroke: #00F7DA !important;
    stroke-width: 2px !important;
}

/* 時序圖 */
.mermaid .actor {
    fill: #293038 !important;
    stroke: #00F7DA !important;
}

.mermaid .actor-line {
    stroke: #9B95C5 !important;
}

.mermaid .messageLine0 {
    stroke: #00F7DA !important;
}

.mermaid .messageLine1 {
    stroke: #9B95C5 !important;
    stroke-dasharray: 2, 2 !important;
}

/* 類圖 */
.mermaid .classGroup rect {
    fill: #293038 !important;
    stroke: #00F7DA !important;
}

.mermaid .classGroup text {
    fill: #FFFFFF !important;
}

/* 甘特圖 */
.mermaid .grid .tick line {
    stroke: rgba(255, 255, 255, 0.1) !important;
}

.mermaid .grid .tick text {
    fill: rgba(255, 255, 255, 0.6) !important;
}

/* 餅圖 */
.mermaid .pieCircle {
    stroke: #00F7DA !important;
    stroke-width: 2px !important;
}

.mermaid .pieTitleText {
    fill: #FFFFFF !important;
    font-size: 1.25rem !important;
    font-weight: bold !important;
}

/* ===================================
   動畫效果
   =================================== */

/* 圖表載入動畫 */
@keyframes mermaid-fade-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mermaid svg {
    animation: mermaid-fade-in 0.5s ease-out;
}

/* 懸停效果 */
.mermaid .node:hover rect,
.mermaid .node:hover circle,
.mermaid .node:hover ellipse,
.mermaid .node:hover polygon {
    fill: rgba(0, 247, 218, 0.1) !important;
    filter: drop-shadow(0 0 10px rgba(0, 247, 218, 0.5));
}

.mermaid .edgePath:hover .path {
    stroke-width: 3px !important;
    filter: drop-shadow(0 0 5px rgba(0, 247, 218, 0.5));
}

/* ===================================
   響應式設計
   =================================== */

@media (max-width: 768px) {
    .mermaid-container {
        padding: 1rem;
        margin: 1.5rem 0;
        border-radius: 12px;
    }

    .mermaid {
        padding: 0.5rem;
        font-size: 0.875rem;
    }

    .mermaid-copy-btn {
        top: 0.5rem;
        right: 0.5rem;
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .mermaid-fullscreen-btn {
        top: 0.5rem;
        right: 0.5rem;
        width: 30px;
        height: 30px;
        font-size: 0.875rem;
    }

    /* 手機版全螢幕調整 */
    .mermaid-fullscreen .mermaid {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .mermaid svg {
        font-size: 0.75rem;
        max-width: 100%;
    }

    /* 小螢幕自動橫向滾動(需要時) */
    .mermaid {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ===================================
   列印樣式
   =================================== */

@media print {
    .mermaid-container {
        border: 1px solid #ccc;
        background: white !important;
        page-break-inside: avoid;
    }

    .mermaid-copy-btn,
    .mermaid-fullscreen-btn {
        display: none !important;
    }

    .mermaid svg {
        max-width: 100% !important;
        height: auto !important;
    }

    /* 列印時改為淺色模式 */
    .mermaid .node rect,
    .mermaid .node circle,
    .mermaid .node ellipse,
    .mermaid .node polygon {
        fill: white !important;
        stroke: black !important;
    }

    .mermaid .node text {
        fill: black !important;
    }

    .mermaid .edgePath .path {
        stroke: black !important;
    }
}

/* ===================================
   無障礙支援
   =================================== */

/* 聚焦樣式 */
.mermaid-copy-btn:focus,
.mermaid-fullscreen-btn:focus {
    outline: 2px solid #00F7DA;
    outline-offset: 2px;
}

/* 鍵盤導航提示 */
.mermaid-container[tabindex="0"]:focus {
    outline: 2px solid #00F7DA;
    outline-offset: 4px;
}

/* 螢幕閱讀器輔助文字 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}