/* BlazorMarkdownEditor.css */

:root {
    --bme-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --bme-mono: 'Fira Code', 'Cascadia Code', Consolas, monospace;
    --bme-border: #d1d5db;
    --bme-bg: #ffffff;
    --bme-bg-toolbar: #f9fafb;
    --bme-bg-statusbar: #f3f4f6;
    --bme-text: #111827;
    --bme-text-muted: #6b7280;
    --bme-accent: #2563eb;
    --bme-accent-hover: #1d4ed8;
    --bme-radius: 8px;
    --bme-btn-hover: #e5e7eb;
    --bme-btn-active: #dbeafe;
    --bme-separator: #e5e7eb;
    --bme-preview-h: #1e293b;
    --bme-code-bg: #f3f4f6;
    --bme-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
}

/* Dark theme */
.bme-dark {
    --bme-border: #374151;
    --bme-bg: #1f2937;
    --bme-bg-toolbar: #111827;
    --bme-bg-statusbar: #111827;
    --bme-text: #f9fafb;
    --bme-text-muted: #9ca3af;
    --bme-btn-hover: #374151;
    --bme-btn-active: #1e3a5f;
    --bme-separator: #374151;
    --bme-preview-h: #e2e8f0;
    --bme-code-bg: #374151;
}

/* ---- Wrapper ---- */
.bme-editor, .bme-editor * {
    box-sizing: border-box;
}

.bme-editor {
    font-family: var(--bme-font);
    border: 1px solid var(--bme-border);
    border-radius: var(--bme-radius);
    background: var(--bme-bg);
    color: var(--bme-text);
    box-shadow: var(--bme-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1; /* Allow growing to fill available parent space */
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

/* ---- Toolbar ---- */
.bme-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px 10px;
    background: var(--bme-bg-toolbar);
    border-bottom: 1px solid var(--bme-border);
    user-select: none;
}

.bme-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--bme-text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.12s, color 0.12s;
    position: relative;
}

.bme-toolbar-btn:hover {
    background: var(--bme-btn-hover);
}

.bme-toolbar-btn.active {
    background: var(--bme-btn-active);
    color: var(--bme-accent);
}

.bme-toolbar-group {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.bme-toolbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.bme-toolbar-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.bme-toolbar-spacer {
    flex: 1;
}

.bme-separator {
    width: 1px;
    height: 22px;
    background: var(--bme-separator);
    margin: 0 4px;
}

/* Tooltip */
.bme-toolbar-btn::after, .bme-toolbar-group::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 6px); /* Show below the button */
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: #f9fafb;
    font-size: 11px;
    font-weight: 400;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
}

.bme-toolbar-btn:hover::after, .bme-toolbar-group:hover::after {
    opacity: 1;
}

/* Heading dropdown */
.bme-heading-select {
    appearance: none;
    -webkit-appearance: none;
    height: 32px;
    border: 1px solid var(--bme-border);
    border-radius: 6px;
    background-color: var(--bme-bg);
    color: var(--bme-text);
    font-size: 13px;
    font-weight: 500;
    padding: 0 30px 0 12px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
}

.bme-dark .bme-heading-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%239ca3af' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

.bme-heading-select:hover {
    border-color: var(--bme-accent);
    background-color: var(--bme-bg-toolbar);
}

.bme-heading-select:focus {
    border-color: var(--bme-accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Filename Editor */
.bme-filename-wrapper {
    display: flex;
    align-items: center;
    background: var(--bme-bg);
    border: 1px solid var(--bme-border);
    border-radius: 6px;
    padding: 0 8px;
    margin: 0 8px;
    height: 32px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.bme-filename-wrapper:focus-within {
    border-color: var(--bme-accent);
}

.bme-filename-input {
    border: none;
    background: transparent;
    color: var(--bme-text);
    font-size: 13px;
    font-weight: 500;
    outline: none;
    width: 120px;
    padding: 0;
}

.bme-filename-ext {
    color: var(--bme-text-muted);
    font-size: 12px;
    user-select: none;
}

/* ---- Body ---- */
.bme-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative; /* For absolute source overlay in visual mode */
}

/* ---- Raw / Split textarea ---- */
.bme-source {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    padding: 16px 20px;
    font-family: var(--bme-mono);
    font-size: 14px;
    line-height: 1.7;
    background: var(--bme-bg);
    color: var(--bme-text);
    tab-size: 4;
    overflow-y: auto;
}

.bme-source::placeholder {
    color: var(--bme-text-muted);
}

/* ---- Preview ---- */
.bme-preview {
    flex: 1;
    padding: 20px 28px;
    overflow-y: auto;
    font-size: 15px;
    line-height: 1.75;
    color: var(--bme-text);
}

.bme-preview-only {
    background: #f0f2f5; /* Light gray background to make the "page" stand out */
}

.bme-dark.bme-preview-only {
    background: #111827;
}

.bme-preview-only .bme-body {
    padding: 40px 0;
    overflow-y: auto;
    display: block; /* Allow vertical stacking and centering */
}

.bme-preview-only .bme-preview {
    background: var(--bme-bg);
    max-width: 816px; /* Approx A4 width (8.5in * 96dpi) */
    margin: 0 auto;
    min-height: 1056px; /* Approx A4 height (11in * 96dpi) */
    padding: 60px 80px; /* Standard print margins */
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    border-radius: 4px;
    flex: none; /* Don't grow to fill, keep fixed width */
}

.bme-wysiwyg {
    outline: none;
}

.bme-wysiwyg:focus {
    background: var(--bme-bg);
}
.bme-preview h1, .bme-preview h2, .bme-preview h3,
.bme-preview h4, .bme-preview h5, .bme-preview h6 {
    color: var(--bme-preview-h);
    margin-top: 1.5em;
    margin-bottom: .5em;
    font-weight: 700;
    line-height: 1.3;
}
.bme-preview h1 { font-size: 2em; border-bottom: 2px solid var(--bme-border); padding-bottom: .3em; }
.bme-preview h2 { font-size: 1.5em; border-bottom: 1px solid var(--bme-border); padding-bottom: .2em; }
.bme-preview h3 { font-size: 1.25em; }
.bme-preview p { margin: .75em 0; }
.bme-preview strong { font-weight: 700; }
.bme-preview em { font-style: italic; }
.bme-preview del { text-decoration: line-through; }

.bme-preview ul, .bme-preview ol {
    padding-left: 1.75em;
    margin: .5em 0;
}

.bme-preview li { 
    margin: .25em 0; 
}

.bme-preview ul li {
    list-style-type: disc;
}

.bme-preview ol li {
    list-style-type: decimal;
}

.bme-preview table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
    font-size: .9em;
}

.bme-preview th, .bme-preview td {
    border: 1px solid var(--bme-border);
    padding: .5em .75em;
    text-align: left;
}

.bme-preview th {
    background: var(--bme-bg-toolbar);
    font-weight: 600;
}

.bme-preview tr:nth-child(even) td {
    background: var(--bme-code-bg);
}

.bme-preview hr {
    border: none;
    border-top: 2px solid var(--bme-border);
    margin: 2em 0;
}

/* ---- Status bar ---- */
.bme-statusbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 4px 14px;
    background: var(--bme-bg-statusbar);
    border-top: 1px solid var(--bme-border);
    font-size: 11px;
    color: var(--bme-text-muted);
    user-select: none;
}

.bme-statusbar-spacer { flex: 1; }

.bme-mode-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 8px;
    border-radius: 99px;
    background: var(--bme-btn-active);
    color: var(--bme-accent);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .05em;
}

/* ---- Dialogs ---- */
.bme-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.bme-dialog {
    background: var(--bme-bg);
    border: 1px solid var(--bme-border);
    border-radius: 12px;
    padding: 24px;
    min-width: 360px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    color: var(--bme-text);
}

.bme-dialog h3 {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
}

.bme-dialog label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--bme-text-muted);
}

.bme-dialog input, .bme-dialog select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--bme-border);
    border-radius: 6px;
    background: var(--bme-bg);
    color: var(--bme-text);
    font-size: 14px;
    margin-bottom: 12px;
    outline: none;
    box-sizing: border-box;
}

.bme-dialog input:focus {
    border-color: var(--bme-accent);
}

.bme-dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 8px;
}

.bme-btn {
    padding: 7px 18px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background .12s;
}

.bme-btn-primary {
    background: var(--bme-accent);
    color: #fff;
}

.bme-btn-primary:hover { background: var(--bme-accent-hover); }

.bme-btn-secondary {
    background: var(--bme-btn-hover);
    color: var(--bme-text);
}

.bme-btn-secondary:hover { background: var(--bme-separator); }

.bme-preview img, .bme-wysiwyg img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    display: block;
    margin: 1rem 0;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    /* Toolbar: Make it horizontally scrollable instead of wrapping */
    .bme-toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 4px 6px;
        scrollbar-width: none; /* Hide scrollbar for Firefox */
        -ms-overflow-style: none; /* Hide scrollbar for IE/Edge */
    }
    
    .bme-toolbar::-webkit-scrollbar {
        display: none; /* Hide scrollbar for Chrome/Safari */
    }

    .bme-toolbar-btn {
        flex-shrink: 0;
        width: 36px; /* Slightly larger touch target */
        height: 36px;
    }

    /* Filename: Make it more flexible and compact */
    .bme-filename-wrapper {
        margin: 0 4px;
        height: 30px;
        min-width: 80px;
        flex-shrink: 1; /* Allow to shrink on very small screens */
    }

    .bme-filename-input {
        width: 80px;
        font-size: 12px;
    }

    .bme-filename-ext {
        display: none; /* Hide .md on mobile to save space */
    }

    /* Editor Body: Reduce padding */
    .bme-source, .bme-preview {
        padding: 12px 16px;
    }

    /* Preview-only Mode (Visual "Page" Mode) */
    .bme-preview-only .bme-body {
        padding: 0;
        background: var(--bme-bg); /* Match editor background on mobile */
    }

    .bme-preview-only .bme-preview {
        max-width: 100%;
        margin: 0;
        min-height: 100%;
        padding: 20px 16px;
        box-shadow: none;
        border-radius: 0;
    }

    /* Hide tooltips on mobile */
    .bme-toolbar-btn::after, .bme-toolbar-group::after {
        display: none !important;
    }

    /* Status bar: Hide extra info to avoid overlap */
    .bme-statusbar {
        gap: 8px;
        overflow-x: auto;
    }
    .bme-statusbar span:nth-child(2), /* Hide chars */
    .bme-statusbar span:nth-child(4)  /* Hide reading time */ {
        display: none;
    }

    /* Dialogs: Full width on mobile */
    .bme-dialog {
        min-width: 90%;
        padding: 16px;
        margin: 10px;
    }

    .bme-dialog-actions {
        flex-direction: column;
    }

    .bme-btn {
        width: 100%;
        padding: 12px;
    }
}
