/* ============================================================
   MARKDOWN EDITOR — GitHub-like
   ============================================================ */

.md-editor {
    display: flex;
    flex-direction: column;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
    background: #161616;
    overflow: hidden;
    transition: border-color 0.2s ease;
}

.md-editor:focus-within {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.12);
}

/* ---------- Header (tabs + toolbar) ---------- */
.md-editor__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    background: #101010;
    border-bottom: 1px solid #1f1f1f;
    flex-wrap: wrap;
}

.md-editor__tabs {
    display: flex;
    gap: 2px;
}

.md-tab {
    padding: 6px 14px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #888;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.md-tab:hover {
    background: #1a1a1a;
    color: #ccc;
}

.md-tab.active {
    background: #1e1e1e;
    color: #fff;
}

/* ---------- Toolbar ---------- */
.md-editor__toolbar {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    align-items: center;
}

.md-tool {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 5px;
    color: #999;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
}

.md-tool:hover {
    background: #1e1e1e;
    color: #fff;
}

.md-tool svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.md-tool--text {
    font-family: ui-monospace, monospace;
    font-size: 0.8rem;
    font-weight: 700;
}

.md-toolbar-divider {
    width: 1px;
    height: 18px;
    background: #2a2a2a;
    margin: 0 4px;
}

/* ---------- Body ---------- */
.md-editor__body {
    position: relative;
    min-height: 260px;
    display: flex;
    flex-direction: column;
}

/* ---------- Editor pane ---------- */
.md-editor__write {
    display: flex;
    flex-direction: column;
    flex: 1;
    position: relative;
}

.md-textarea {
    flex: 1;
    width: 100%;
    min-height: 260px;
    background: #161616;
    border: none;
    outline: none;
    color: #eaeaea;
    padding: 14px 16px;
    font-family: ui-monospace, 'SFMono-Regular', 'Menlo', 'Consolas', monospace;
    font-size: 0.88rem;
    line-height: 1.7;
    resize: vertical;
    direction: ltr;
    text-align: left;
    tab-size: 2;
}

.md-textarea::placeholder {
    color: #555;
}

.md-textarea::selection {
    background: rgba(0, 123, 255, 0.35);
}

/* ---------- Preview pane ---------- */
.md-editor__preview {
    display: none;
    padding: 20px 22px;
    overflow-y: auto;
    max-height: 600px;
    direction: rtl;
    text-align: right;
}

.md-editor__preview.active {
    display: block;
}

.md-editor__write.hidden {
    display: none;
}

/* ---------- Footer ---------- */
.md-editor__footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #101010;
    border-top: 1px solid #1f1f1f;
    color: #666;
    font-size: 0.75rem;
}

.md-editor__footer-right {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ============================================================
   MARKDOWN PREVIEW STYLES (GitHub-like)
   ============================================================ */

.md-preview-content {
    color: #d1d5db;
    font-size: 0.92rem;
    line-height: 1.8;
    word-wrap: break-word;
    direction: rtl;
    text-align: right;
}

.md-preview-content>*:first-child {
    margin-top: 0 !important;
}

.md-preview-content>*:last-child {
    margin-bottom: 0 !important;
}

/* Headings */
.md-preview-content h1,
.md-preview-content h2,
.md-preview-content h3,
.md-preview-content h4,
.md-preview-content h5,
.md-preview-content h6 {
    margin: 22px 0 12px;
    font-weight: 700;
    line-height: 1.3;
    color: #fff;
    text-align: right;
}

.md-preview-content h1 {
    font-size: 1.7rem;
    padding-bottom: 8px;
    border-bottom: 1px solid #2a2a2a;
}

.md-preview-content h2 {
    font-size: 1.35rem;
    padding-bottom: 6px;
    border-bottom: 1px solid #2a2a2a;
}

.md-preview-content h3 {
    font-size: 1.15rem;
}

.md-preview-content h4 {
    font-size: 1rem;
}

.md-preview-content h5 {
    font-size: 0.92rem;
}

.md-preview-content h6 {
    font-size: 0.85rem;
    color: #888;
}

/* Paragraph */
.md-preview-content p {
    margin: 0 0 14px;
}

/* Links */
.md-preview-content a {
    color: #6ebbff;
    text-decoration: none;
    padding-bottom: 0;
}

.md-preview-content a::after {
    display: none;
}

.md-preview-content a:hover {
    text-decoration: underline;
    color: #8ed0ff;
}

/* Strong / Em */
.md-preview-content strong {
    color: #fff;
    font-weight: 700;
}

.md-preview-content em {
    font-style: italic;
    color: #e0e0e0;
}

.md-preview-content del {
    color: #777;
    text-decoration: line-through;
}

/* Lists */
.md-preview-content ul,
.md-preview-content ol {
    margin: 0 0 14px;
    padding-right: 26px;
    padding-left: 0;
}

.md-preview-content li {
    margin: 4px 0;
}

.md-preview-content li>p {
    margin: 0;
}

.md-preview-content ul ul,
.md-preview-content ol ol,
.md-preview-content ul ol,
.md-preview-content ol ul {
    margin: 4px 0;
}

/* Task lists */
.md-preview-content input[type="checkbox"] {
    accent-color: #007bff;
    margin-left: 6px;
    transform: translateY(1px);
}

/* Blockquote */
.md-preview-content blockquote {
    margin: 0 0 14px;
    padding: 10px 16px;
    border-right: 4px solid #007bff;
    background: rgba(0, 123, 255, 0.06);
    border-radius: 4px;
    color: #b0b0b0;
}

.md-preview-content blockquote>*:last-child {
    margin-bottom: 0;
}

/* Inline code */
.md-preview-content code {
    background: #232323;
    color: #ff9d6a;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: ui-monospace, 'SFMono-Regular', 'Menlo', 'Consolas', monospace;
    font-size: 0.85em;
    direction: ltr;
    display: inline-block;
}

/* Code block */
.md-preview-content pre {
    margin: 0 0 14px;
    background: #0d1117;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.md-preview-content pre code {
    display: block;
    padding: 14px 16px;
    background: transparent;
    color: #e6edf3;
    border-radius: 0;
    font-size: 0.82rem;
    line-height: 1.6;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
}

.md-preview-content pre[data-lang]::before {
    content: attr(data-lang);
    position: absolute;
    top: 0;
    left: 0;
    padding: 4px 10px;
    font-size: 0.68rem;
    color: #8b949e;
    background: #161b22;
    border-bottom-right-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: ui-monospace, monospace;
}

/* Horizontal rule */
.md-preview-content hr {
    border: none;
    height: 1px;
    background: #2a2a2a;
    margin: 20px 0;
}

/* Tables */
.md-preview-content table {
    width: 100%;
    margin: 0 0 14px;
    border-collapse: collapse;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    overflow: hidden;
    font-size: 0.88rem;
}

.md-preview-content thead {
    background: #1a1a1a;
}

.md-preview-content th,
.md-preview-content td {
    padding: 9px 12px;
    border: 1px solid #2a2a2a;
    text-align: right;
}

.md-preview-content th {
    color: #fff;
    font-weight: 700;
}

.md-preview-content tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

/* Images */
.md-preview-content img {
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid #2a2a2a;
    margin: 6px 0;
}

/* Details / Summary */
.md-preview-content details {
    margin: 0 0 14px;
    padding: 10px 14px;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
}

.md-preview-content summary {
    cursor: pointer;
    color: #6ebbff;
    font-weight: 600;
}

/* Keyboard key */
.md-preview-content kbd {
    padding: 2px 6px;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-bottom-width: 2px;
    border-radius: 4px;
    font-family: ui-monospace, monospace;
    font-size: 0.78rem;
    color: #e0e0e0;
}

/* Empty state */
.md-editor__preview .md-empty {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-size: 0.85rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .md-editor__toolbar {
        max-width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .md-tab {
        padding: 5px 10px;
        font-size: 0.75rem;
    }

    .md-tool {
        width: 28px;
        height: 28px;
    }
}

/* ---------- Mark (highlight) ---------- */
.md-preview-content mark {
    background: rgba(251, 191, 36, 0.25);
    color: #fbbf24;
    padding: 1px 4px;
    border-radius: 3px;
}

/* ---------- Details / Summary ---------- */
.md-preview-content details {
    margin: 0 0 14px;
    padding: 0;
    background: #161b22;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    overflow: hidden;
}

.md-preview-content summary {
    cursor: pointer;
    padding: 10px 14px;
    color: #6ebbff;
    font-weight: 600;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.md-preview-content summary::-webkit-details-marker {
    display: none;
}

.md-preview-content summary::before {
    content: '▶';
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    display: inline-block;
}

.md-preview-content details[open] summary::before {
    transform: rotate(90deg);
}

.md-preview-content details>*:not(summary) {
    padding: 0 14px;
}

.md-preview-content details>*:last-child {
    padding-bottom: 12px;
}

/* ---------- Figure ---------- */
.md-preview-content figure {
    margin: 0 0 14px;
    text-align: center;
}

.md-preview-content figcaption {
    color: #888;
    font-size: 0.82rem;
    margin-top: 6px;
    text-align: center;
}

/* ---------- abbr / kbd ---------- */
.md-preview-content abbr {
    text-decoration: underline dotted #666;
    cursor: help;
}

.md-preview-content sub,
.md-preview-content sup {
    font-size: 0.75em;
    color: #aaa;
}

/**
 * Copyright (c) 2026 Sobhan Rasoulzadeh Asl (Sobhan-SRZA / Mr. Sinre)
 *
 * Licensed under the BSD 3-Clause License.
 * See the LICENSE file in the project root for license information.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */