/* --- Markdown Reader Styles --- */

/* Theme Variables */
.md-body {
    --md-bg: #ffffff;
    --md-editor-bg: #FAFAFA;
    --md-preview-bg: #ffffff;
    --md-text-primary: #111827;
    --md-text-secondary: #374151;
    --md-text-muted: #6B7280;
    --md-border: #E5E7EB;
    --md-code-bg: #F3F4F6;
    --md-accent: #007AFF;
    --md-blockquote: #6B7280;
}

.md-body.theme-sepia {
    --md-bg: #FDF6E3;
    --md-editor-bg: #EEE8D5;
    --md-preview-bg: #FDF6E3;
    --md-text-primary: #5F4B32;
    --md-text-secondary: #6B5D4D;
    --md-text-muted: #8B7355;
    --md-border: #D4C4A8;
    --md-code-bg: #EEE8D5;
    --md-accent: #B58900;
    --md-blockquote: #8B7355;
}

.md-body.theme-dark {
    --md-bg: #0D1117;
    --md-editor-bg: #161B22;
    --md-preview-bg: #0D1117;
    --md-text-primary: #E6EDF3;
    --md-text-secondary: #8B949E;
    --md-text-muted: #6E7681;
    --md-border: #30363D;
    --md-code-bg: #21262D;
    --md-accent: #58A6FF;
    --md-blockquote: #8B949E;
}

.md-body {
    background: var(--md-bg);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
    padding: 0;
}

.md-body .tool-nav {
    margin-top: 40px;
}

/* --- Toolbar --- */
.md-toolbar {
    max-width: 1200px;
    margin: 0 auto 16px auto;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 95%;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-toggle {
    background: var(--md-code-bg);
    border-radius: 10px;
    padding: 3px;
    display: flex;
    gap: 2px;
    border: 1px solid var(--md-border);
}

.theme-btn {
    border: none;
    background: transparent;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    color: var(--md-text-muted);
    transition: all 0.25s ease;
}

.theme-btn:hover {
    color: var(--md-text-primary);
}

.theme-btn.active {
    background: var(--md-preview-bg);
    color: var(--md-text-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    font-weight: 600;
}

.md-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    border: 1px solid var(--md-border);
    background: var(--md-preview-bg);
    color: var(--md-text-primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.md-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.md-action-btn.primary {
    background: linear-gradient(135deg, #007AFF 0%, #0055CC 100%);
    color: white;
    border: none;
}

.md-action-btn.primary:hover {
    background: linear-gradient(135deg, #0066DD 0%, #0044AA 100%);
    box-shadow: 0 6px 20px rgba(0, 122, 255, 0.35);
}

/* --- Info Bar --- */
.md-infobar {
    height: 44px;
    border-bottom: 1px solid var(--md-border);
    border-top: 1px solid var(--md-border);
    display: flex;
    flex-shrink: 0;
    background: var(--md-code-bg);
}

.info-left,
.info-right {
    width: 50%;
    padding: 0 24px;
    display: flex;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--md-text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.info-right {
    border-left: 1px solid var(--md-border);
    justify-content: space-between;
}

.info-left .meta {
    margin-left: auto;
    font-weight: 500;
    color: var(--md-text-muted);
    opacity: 0.7;
    text-transform: none;
    letter-spacing: 0;
}

.icon-row {
    display: flex;
    gap: 4px;
}

.icon-btn {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--md-text-muted);
    transition: all 0.2s ease;
    font-size: 16px;
}

.icon-btn:hover {
    background: var(--md-border);
    color: var(--md-text-primary);
}

/* --- Main Container --- */
.md-container {
    flex: 1;
    min-height: 0;
    display: flex;
    width: 100%;
    position: relative;
}

/* --- Editor Pane --- */
.md-editor {
    width: 50%;
    height: 100%;
    background: var(--md-editor-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    transition: background 0.3s ease;
}

#mdEditor {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    padding: 32px;
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Menlo', monospace;
    font-size: 14px;
    line-height: 1.7;
    color: var(--md-text-secondary);
    resize: none;
    outline: none;
    transition: color 0.3s ease;
}

#mdEditor::placeholder {
    color: var(--md-text-muted);
    opacity: 0.6;
}

#mdEditor::selection {
    background: rgba(0, 122, 255, 0.25);
}

/* --- Resizer --- */
.resizer {
    width: 6px;
    background: var(--md-border);
    cursor: col-resize;
    position: relative;
    flex-shrink: 0;
    transition: background 0.2s ease;
}

.resizer:hover,
.resizer.dragging {
    background: var(--md-accent);
}

.resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 40px;
    background: var(--md-text-muted);
    border-radius: 1px;
    opacity: 0.3;
}

/* --- Preview Pane --- */
.md-preview {
    width: calc(50% - 6px);
    height: 100%;
    overflow-y: auto;
    background: var(--md-preview-bg);
    transition: background 0.3s ease;
}

.preview-content {
    padding: 40px 60px;
    max-width: 850px;
    margin: 0 auto;
}

/* --- Markdown Typography --- */
.md-preview h1 {
    font-size: 2.25em;
    font-weight: 800;
    margin-bottom: 16px;
    letter-spacing: -0.5px;
    color: var(--md-text-primary);
    padding-bottom: 12px;
    border-bottom: 2px solid var(--md-border);
}

.md-preview h2 {
    font-size: 1.75em;
    font-weight: 700;
    margin-top: 40px;
    margin-bottom: 16px;
    color: var(--md-text-primary);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--md-border);
}

.md-preview h3 {
    font-size: 1.4em;
    font-weight: 600;
    margin-top: 32px;
    margin-bottom: 12px;
    color: var(--md-text-primary);
}

.md-preview h4 {
    font-size: 1.15em;
    font-weight: 600;
    margin-top: 24px;
    margin-bottom: 8px;
    color: var(--md-text-primary);
}

.md-preview p {
    font-size: 16px;
    line-height: 1.75;
    color: var(--md-text-secondary);
    margin-bottom: 16px;
}

.md-preview ul,
.md-preview ol {
    margin-bottom: 20px;
    padding-left: 24px;
    color: var(--md-text-secondary);
}

.md-preview li {
    margin-bottom: 8px;
    line-height: 1.65;
}

.md-preview li>ul,
.md-preview li>ol {
    margin-top: 8px;
    margin-bottom: 8px;
}

.md-preview blockquote {
    border-left: 4px solid var(--md-accent);
    padding: 12px 20px;
    margin: 24px 0;
    background: var(--md-code-bg);
    border-radius: 0 8px 8px 0;
    color: var(--md-blockquote);
    font-style: italic;
}

.md-preview blockquote p {
    margin: 0;
    color: inherit;
}

.md-preview a {
    color: var(--md-accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}

.md-preview a:hover {
    border-bottom-color: var(--md-accent);
}

.md-preview strong {
    font-weight: 700;
    color: var(--md-text-primary);
}

.md-preview em {
    font-style: italic;
}

.md-preview hr {
    border: none;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--md-border), transparent);
    margin: 40px 0;
}

/* --- Code Styling --- */
.md-preview code {
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
    background: var(--md-code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--md-accent);
}

.md-preview pre {
    background: var(--md-code-bg);
    border-radius: 12px;
    padding: 20px 24px;
    margin: 24px 0;
    overflow-x: auto;
    border: 1px solid var(--md-border);
}

.md-preview pre code {
    background: transparent;
    padding: 0;
    color: var(--md-text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

/* --- Tables --- */
.md-preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 24px 0;
    font-size: 14px;
}

.md-preview th,
.md-preview td {
    border: 1px solid var(--md-border);
    padding: 12px 16px;
    text-align: left;
}

.md-preview th {
    background: var(--md-code-bg);
    font-weight: 600;
    color: var(--md-text-primary);
}

.md-preview tr:hover {
    background: var(--md-code-bg);
}

/* --- Images --- */
.md-preview img {
    max-width: 100%;
    border-radius: 12px;
    margin: 24px 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* --- Task Lists --- */
.md-preview input[type="checkbox"] {
    margin-right: 8px;
    transform: scale(1.1);
}

/* --- Toast / File Info --- */
.md-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--md-preview-bg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 12px 20px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid var(--md-border);
    color: var(--md-text-primary);
    z-index: 100;
    transition: transform 0.3s ease, opacity 0.3s ease, background 0.3s ease;
}

.toast-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    border-left: 1px solid var(--md-border);
    padding-left: 12px;
    margin-left: 4px;
}

.toast-btn {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--md-text-muted);
    transition: all 0.2s ease;
    font-size: 16px;
}

.toast-btn:hover {
    background: var(--md-code-bg);
    color: var(--md-text-primary);
}

.toast-btn.active {
    color: var(--md-accent);
}

.toast-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.toast-divider {
    width: 1px;
    height: 20px;
    background: var(--md-border);
}

/* --- Drag Overlay --- */
.drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 122, 255, 0.08);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.drag-overlay.active {
    opacity: 1;
    visibility: visible;
}

.drag-content {
    background: white;
    border-radius: 24px;
    padding: 60px 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: 0 24px 80px rgba(0, 122, 255, 0.25);
    border: 3px dashed #007AFF;
    animation: pulse 1.5s ease-in-out infinite;
}

.drag-content i {
    font-size: 64px;
    color: #007AFF;
}

.drag-content span {
    font-size: 18px;
    font-weight: 600;
    color: #007AFF;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }
}

/* --- Notification Toast --- */
.notification-toast {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.35);
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10000;
}

.notification-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.notification-toast i {
    font-size: 18px;
}

/* --- Empty State --- */
.empty-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--md-text-muted);
    text-align: center;
    padding: 40px;
}

.empty-preview i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.3;
}

.empty-preview h3 {
    font-size: 20px;
    margin-bottom: 8px;
    font-weight: 600;
}

.empty-preview p {
    font-size: 14px;
    opacity: 0.7;
}

/* --- Print Styles --- */
@media print {

    .tool-nav,
    .md-toolbar,
    .md-infobar,
    .md-editor,
    .resizer,
    .md-toast,
    .notification-toast {
        display: none !important;
    }

    .md-container {
        display: block !important;
    }

    .md-preview {
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }

    .preview-content {
        max-width: 100% !important;
        padding: 0 !important;
    }
}

/* --- Zoom Levels --- */
.md-preview.zoom-in .preview-content {
    font-size: 18px;
}

.md-preview.zoom-in-2 .preview-content {
    font-size: 20px;
}

.md-preview.zoom-out .preview-content {
    font-size: 14px;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .md-container {
        flex-direction: column;
    }

    .md-editor,
    .md-preview {
        width: 100% !important;
        height: 50%;
    }

    .resizer {
        width: 100%;
        height: 6px;
        cursor: row-resize;
    }

    .resizer::after {
        width: 40px;
        height: 2px;
    }

    .info-left,
    .info-right {
        width: 100%;
    }

    .md-infobar {
        flex-direction: column;
        height: auto;
    }

    .info-right {
        border-left: none;
        border-top: 1px solid var(--md-border);
    }

    .md-toolbar {
        flex-direction: column;
        gap: 12px;
    }

    .preview-content {
        padding: 24px;
    }
}

@media (max-width: 600px) {
    .md-body .tool-nav {
        margin-top: 24px;
    }
    .md-toolbar {
        width: 100%;
        padding: 0 12px;
    }
    .toolbar-group {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    .theme-toggle {
        width: 100%;
        justify-content: center;
    }
    .theme-btn {
        flex: 1;
        padding: 8px 10px;
        font-size: 12px;
    }
    .md-action-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    #mdEditor {
        padding: 20px;
        font-size: 13px;
    }
    .preview-content {
        padding: 20px;
    }
    .md-toast {
        width: calc(100% - 24px);
        left: 12px;
        transform: translateX(0);
        bottom: 16px;
        justify-content: space-between;
    }
}

/* scrollbar styling */
.md-preview::-webkit-scrollbar {
    width: 8px;
}

.md-preview::-webkit-scrollbar-track {
    background: transparent;
}

.md-preview::-webkit-scrollbar-thumb {
    background: var(--md-border);
    border-radius: 4px;
}

.md-preview::-webkit-scrollbar-thumb:hover {
    background: var(--md-text-muted);
}

#mdEditor::-webkit-scrollbar {
    width: 8px;
}

#mdEditor::-webkit-scrollbar-track {
    background: transparent;
}

#mdEditor::-webkit-scrollbar-thumb {
    background: var(--md-border);
    border-radius: 4px;
}
