/* md-viewer.css */

:root {
    --header: #1f5f8b;
    --header-dark: #17496b;
    --accent: #2c7db1;
    --bg: #eef2f5;
    --panel: #ffffff;
    --border: #ccd5dc;
    --text: #222;
    --muted: #68747d;
    --code: #f5f7f9;
    --shadow: 0 2px 8px rgba(0,0,0,.12);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* HEADER */
header {
    background: var(--header);
    color: white;
    padding: 13px 18px;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: 1500px;
    margin: auto;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.logo {
    font-size: 21px;
    font-weight: bold;
    margin-right: auto;
}

.file-name {
    font-size: 14px;
    opacity: .9;
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* TOOLBAR */
.toolbar {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 9px;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 5px rgba(0,0,0,.08);
}

.toolbar-inner {
    max-width: 1500px;
    margin: auto;
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    align-items: center;
}

button,
.file-label,
select {
    border: 1px solid #aeb9c1;
    border-radius: 5px;
    background: white;
    color: #222;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
}

button:hover,
.file-label:hover,
select:hover {
    background: #edf4f8;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--header-dark);
    color: white;
}

input[type="file"] {
    display: none;
}

.separator {
    width: 1px;
    height: 30px;
    background: var(--border);
    margin: 0 3px;
}

.status {
    margin-left: auto;
    color: var(--muted);
    font-size: 13px;
}

/* MAIN */
main {
    max-width: 1500px;
    margin: 18px auto;
    padding: 0 15px;
}

.workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    min-height: calc(100vh - 185px);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 7px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-title {
    background: #f4f6f8;
    border-bottom: 1px solid var(--border);
    padding: 9px 12px;
    font-size: 14px;
    font-weight: bold;
}

textarea {
    width: 100%;
    flex: 1;
    min-height: 600px;
    border: 0;
    outline: none;
    resize: none;
    padding: 18px;
    font-family: "Courier New", monospace;
    font-size: 14px;
    line-height: 1.55;
}

.preview-wrap {
    flex: 1;
    overflow: auto;
    background: white;
}

#preview {
    padding: 35px 45px;
    max-width: 1000px;
    margin: auto;
}

/* MARKDOWN */
#preview h1,
#preview h2,
#preview h3,
#preview h4,
#preview h5,
#preview h6 {
    line-height: 1.25;
    margin-top: 1.5em;
    margin-bottom: .6em;
    color: #183c55;
}

#preview h1 {
    font-size: 2.15em;
}

#preview h2 {
    font-size: 1.7em;
}

#preview h3 { font-size: 1.4em; }
#preview h4 { font-size: 1.2em; }
#preview h5 { font-size: 1.05em; }
#preview h6 { font-size: 1em; color: #5b6973; }

#preview p {
    line-height: 1.65;
    margin: .8em 0;
}

#preview a {
    color: #126a9e;
    text-decoration: underline;
}

#preview img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

#preview blockquote {
    margin: 1em 0;
    padding: .7em 1em;
    border-left: 5px solid var(--accent);
    background: #f2f6f9;
    color: #4a555d;
}

#preview ul,
#preview ol {
    padding-left: 2em;
    line-height: 1.65;
}

#preview li {
    margin: .2em 0;
}

#preview hr {
    border: 0;
    border-top: 1px solid #ccd5dc;
    margin: 2em 0;
}

/* ---------------------------------------------------------
   MARKDOWN TABELLEN
--------------------------------------------------------- */

#preview table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    margin: 1.2em 0;
    table-layout: auto;
    font-size: inherit;
}

#preview th,
#preview td {
    border: 1px solid #cbd4da;
    padding: 8px 10px;
    vertical-align: top;
    line-height: 1.45;
    word-break: normal;
    overflow-wrap: anywhere;
}

#preview th {
    background: #eaf0f4;
    font-weight: bold;
}

#preview td p,
#preview th p {
    margin: 0;
}

#preview tbody tr:nth-child(even) td {
    background: #fafbfc;
}

#preview table a {
    overflow-wrap: anywhere;
}

/* Tabellen auf kleinen Bildschirmen */
@media (max-width: 700px) {

    #preview table {
        display: block;
        width: 100%;
        overflow-x: auto;
    }

    #preview th,
    #preview td {
        min-width: 100px;
    }
}

#preview code {
    background: #eef1f3;
    border-radius: 3px;
    padding: .15em .35em;
    font-family: "Courier New", monospace;
    font-size: .92em;
}

#preview pre {
    background: var(--code);
    border: 1px solid #d9dfe3;
    border-radius: 5px;
    padding: 15px;
    overflow-x: auto;
    line-height: 1.5;
}

#preview pre code {
    padding: 0;
    background: transparent;
}

/* MERMAID / FLUSSDIAGRAMME */
#preview .mermaid-diagram {
    margin: 1.4em 0;
    padding: 16px;
    overflow-x: auto;
    text-align: center;
    background: #fff;
    border: 1px solid #d9dfe3;
    border-radius: 6px;
}
#preview .mermaid-diagram svg {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}
#preview .mermaid-error {
    color: #9b1c1c;
    text-align: left;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: "Courier New", monospace;
    font-size: 13px;
}
@media print {
    #preview .mermaid-diagram {
        overflow: visible;
        border: 0;
        padding: 8px 0;
        break-inside: avoid;
    }
    #preview .mermaid-diagram svg {
        max-width: 100%;
        max-height: 240mm;
    }
}

#preview input[type="checkbox"] {
    margin-right: .45em;
    transform: translateY(1px);
}

.task-list-item {
    list-style: none;
}

.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px 0;
}

.math-block {
    margin: 1.2em 0;
    text-align: center;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px 0;
}

.math-block .katex-display {
    margin: 0;
}

/* ---------------------------------------------------------
   FUSSNOTEN
--------------------------------------------------------- */

#preview .footnote-ref {
    font-size: .8em;
    vertical-align: super;
    line-height: 0;
    margin-left: 2px;
}

#preview .footnote-ref a {
    text-decoration: none;
    color: var(--accent);
    font-weight: bold;
}

#preview .footnotes {
    margin-top: 1em;
    padding-top: 0;
}

#preview .footnotes ol {
    padding-left: 2em;
}

#preview .footnotes li {
    margin: .5em 0;
    padding-left: .3em;
}

#preview .footnote-back {
    margin-left: .5em;
    text-decoration: none;
    color: var(--accent);
}

/* DRAG & DROP */
.drop-active {
    outline: 3px dashed var(--accent);
    outline-offset: -5px;
}

.drop-zone {
    border: 2px dashed #b7c2ca;
    border-radius: 7px;
    padding: 25px;
    text-align: center;
    color: #66747d;
    margin: 15px;
    cursor: pointer;
}

.drop-zone:hover {
    background: #f5f8fa;
}

/* EMPTY */
.empty {
    text-align: center;
    padding: 80px 20px;
    color: #7a858c;
}

.empty strong {
    display: block;
    font-size: 22px;
    color: #53616a;
    margin-bottom: 10px;
}

/* FOOTER */
footer {
    background: var(--header);
    color: white;
    text-align: center;
    padding: 7px;
    font-size: 13px;
    margin-top: 20px;
}

footer a {
    color: white;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* FULLSCREEN PREVIEW */
body.preview-only .workspace {
    grid-template-columns: 1fr;
}

body.preview-only .source-panel {
    display: none;
}

body.preview-only #preview {
    max-width: 1100px;
}

/* PRINT */
@media print {
    @page {
        size: A4;
        margin: 18mm 15mm;
    }

    body {
        background: white !important;
    }

    header,
    .toolbar,
    .source-panel,
    footer,
    .panel-title {
        display: none !important;
    }

    main {
        margin: 0;
        padding: 0;
        max-width: none;
    }

    .workspace {
        display: block;
        min-height: 0;
    }

    .panel {
        display: block;
        border: 0;
        box-shadow: none;
        overflow: visible;
    }

    .preview-wrap {
        overflow: visible;
    }

    #preview {
        max-width: none;
        padding: 0;
        margin: 0;
    }

    #preview a {
        color: black;
        text-decoration: none;
    }

    #preview img {
        max-width: 100%;
    }

    #preview pre {
        white-space: pre-wrap;
        overflow-wrap: break-word;
    }

    #preview table {
        break-inside: auto;
    }
    
    #preview tr {
        break-inside: avoid;
    }

    tr,
    img,
    pre,
    blockquote {
        break-inside: avoid;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        break-after: avoid;
    }
    
    /* Erstes Element auf Seite 1 ohne zusätzlichen Abstand */
    #preview > *:first-child {
        margin-top: 0 !important;
    }
}

@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    textarea {
        min-height: 350px;
    }

    #preview {
        padding: 25px 20px;
    }

    .status {
        width: 100%;
        margin-left: 0;
    }
}
