/* Code Viewer Styles */
.code-viewer-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    background: var(--code-bg, #1e1e1e);
    position: relative;
}

.cv-wrapper {
    min-height: 100%;
}

.cv-wrapper pre {
    margin: 0;
    padding: 0;
}

.cv-wrapper code {
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    display: block;
    padding: 15px;
    overflow-x: auto;
    background: transparent; /* Let container handle bg */
}

/* Scrollbar styling for code view */
.code-viewer-container::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.code-viewer-container::-webkit-scrollbar-thumb {
    background: #424242;
    border-radius: 5px;
}

.code-viewer-container::-webkit-scrollbar-corner {
    background: transparent;
}

/* States */
.cv-loading, .cv-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary, #888);
    font-size: 13px;
}

.cv-error {
    padding: 20px;
    color: var(--ios-red, #ff3b30);
    font-family: monospace;
}

/* Markdown Styles */
.cv-markdown {
    background: var(--ios-bg, #0d1117);
    padding: 20px;
    min-height: 100%;
}

.markdown-body {
    color: var(--text-primary, #c9d1d9);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    max-width: 980px;
    word-wrap: break-word;
}

/* Headers */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary, #c9d1d9);
}

.markdown-body h1 {
    font-size: 2em;
    border-bottom: 1px solid var(--border-color, #30363d);
    padding-bottom: 0.3em;
}

.markdown-body h2 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border-color, #30363d);
    padding-bottom: 0.3em;
}

.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }
.markdown-body h5 { font-size: 0.875em; }
.markdown-body h6 { font-size: 0.85em; color: var(--text-secondary, #8b949e); }

/* Paragraphs */
.markdown-body p {
    margin-top: 0;
    margin-bottom: 16px;
}

/* Lists */
.markdown-body ul,
.markdown-body ol {
    margin-top: 0;
    margin-bottom: 16px;
    padding-left: 2em;
}

.markdown-body li {
    margin-top: 0.25em;
}

.markdown-body li > p {
    margin-top: 16px;
}

.markdown-body li + li {
    margin-top: 0.25em;
}

/* Code */
.markdown-body code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(110, 118, 129, 0.4);
    border-radius: 6px;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
}

.markdown-body pre {
    margin-top: 0;
    margin-bottom: 16px;
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: var(--code-block-bg, #161b22);
    border-radius: 6px;
}

.markdown-body pre code {
    display: block;
    padding: 0;
    margin: 0;
    font-size: 100%;
    word-break: normal;
    white-space: pre;
    background: transparent;
    border: 0;
}

/* Links */
.markdown-body a {
    color: var(--link-color, #58a6ff);
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

/* Blockquotes */
.markdown-body blockquote {
    margin: 0 0 16px 0;
    padding: 0 1em;
    color: var(--text-secondary, #8b949e);
    border-left: 0.25em solid var(--border-color, #30363d);
}

.markdown-body blockquote > :first-child {
    margin-top: 0;
}

.markdown-body blockquote > :last-child {
    margin-bottom: 0;
}

/* Tables */
.markdown-body table {
    border-spacing: 0;
    border-collapse: collapse;
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body table th,
.markdown-body table td {
    padding: 6px 13px;
    border: 1px solid var(--border-color, #30363d);
}

.markdown-body table th {
    font-weight: 600;
    background-color: var(--table-header-bg, #161b22);
}

.markdown-body table tr {
    background-color: var(--table-row-bg, #0d1117);
    border-top: 1px solid var(--border-color, #30363d);
}

.markdown-body table tr:nth-child(2n) {
    background-color: var(--table-row-alt-bg, #161b22);
}

/* Horizontal Rule */
.markdown-body hr {
    height: 0.25em;
    padding: 0;
    margin: 24px 0;
    background-color: var(--border-color, #30363d);
    border: 0;
}

/* Images */
.markdown-body img {
    max-width: 100%;
    box-sizing: content-box;
    background-color: var(--ios-bg, #0d1117);
}

/* Strong/Bold */
.markdown-body strong {
    font-weight: 600;
}

/* Emphasis/Italic */
.markdown-body em {
    font-style: italic;
}

/* Mermaid Diagrams */
.markdown-body .mermaid-diagram {
    margin: 16px 0;
    background-color: var(--code-block-bg, #161b22);
    border-radius: 6px;
    overflow: hidden;
    min-height: 100px;
    position: relative;
}

.mermaid-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mermaid-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    color: #a1a1aa;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s ease;
}

.mermaid-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ededed;
}

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

.mermaid-diagram-content {
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: auto;
}

.mermaid-diagram-content svg {
    max-width: 100%;
    height: auto;
}

/* Mermaid Toast Notification */
.mermaid-toast {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    z-index: 100;
    animation: mermaid-toast-fade 2s ease-out forwards;
}

.mermaid-toast.success {
    background: rgba(74, 222, 128, 0.9);
    color: #000;
}

.mermaid-toast.error {
    background: rgba(239, 68, 68, 0.9);
    color: #fff;
}

@keyframes mermaid-toast-fade {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    85% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* Mermaid Fullscreen Modal */
.mermaid-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.mermaid-modal.open {
    opacity: 1;
}

.mermaid-modal.closing {
    opacity: 0;
}

.mermaid-modal-content {
    background: #1a1a1a;
    border-radius: 12px;
    max-width: 95vw;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.mermaid-modal.open .mermaid-modal-content {
    transform: scale(1);
}

.mermaid-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: #252525;
    border-bottom: 1px solid #333;
    color: #ededed;
    font-weight: 600;
    font-size: 14px;
}

.mermaid-modal-actions {
    display: flex;
    gap: 8px;
}

.mermaid-modal-actions .mermaid-btn {
    padding: 6px 12px;
}

.mermaid-close {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.mermaid-close:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #f87171;
}

.mermaid-modal-body {
    padding: 40px;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #161b22;
}

.mermaid-modal-body svg {
    max-width: 100%;
    height: auto;
}

/* Mermaid error state */
.markdown-body .mermaid-error {
    margin: 16px 0;
    padding: 16px;
    background-color: rgba(255, 59, 48, 0.1);
    border: 1px solid var(--ios-red, #ff3b30);
    border-radius: 6px;
    color: var(--ios-red, #ff3b30);
    font-family: monospace;
    font-size: 12px;
}
