:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1c1f24; --dim: #6b7280;
  --line: #e3e6ea; --accent: #2563eb; --accent-ink: #fff;
  --danger: #dc2626; --ok: #16a34a; --hover: #f0f3f8;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 6px 20px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --panel: #1b1f26; --ink: #e6e9ee; --dim: #939aa6;
    --line: #2a2f38; --accent: #3b82f6; --hover: #232832;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex; flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.spacer { flex: 1; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40;
}
.brand { font-weight: 650; color: var(--ink); font-size: 16px; }
.brand:hover { text-decoration: none; }
.logo { margin-right: 4px; }
.user {
  font-size: 13px; color: var(--dim); padding: 4px 10px;
  border: 1px solid var(--line); border-radius: 999px;
}
.filename { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.dirty { color: var(--accent); font-style: normal; font-size: 20px; line-height: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-size: 14px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; justify-content: center; padding: 10px; margin-top: 6px; }
.btn:disabled { opacity: .6; cursor: default; }

/* ---------- Layout ---------- */
.wrap { max-width: 1080px; width: 100%; margin: 0 auto; padding: 22px 18px 60px; flex: 1; }
.center { flex: 1; display: grid; place-items: center; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- Login ---------- */
.login { width: 340px; max-width: 100%; padding: 30px 28px; text-align: center; }
.login-logo { font-size: 40px; }
.login h1 { margin: 6px 0 2px; font-size: 21px; }
.login p { margin: 0 0 18px; font-size: 13px; }
.login label { display: block; text-align: left; font-size: 13px; color: var(--dim); margin-bottom: 12px; }
.login input {
  width: 100%; margin-top: 4px; padding: 10px; font: inherit;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.alert { background: #fee2e2; color: #991b1b; border-radius: 8px; padding: 9px; font-size: 13px; margin-bottom: 14px; }
@media (prefers-color-scheme: dark) { .alert { background: #3f1d1d; color: #fca5a5; } }

/* ---------- Breadcrumbs & Toolbar ---------- */
.crumbs { margin-bottom: 14px; font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.crumbs .sep { color: var(--dim); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.sel-actions { display: inline-flex; align-items: center; gap: 8px; }
[hidden] { display: none !important; }

.menu { position: relative; }
.menu-list {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); min-width: 190px; overflow: hidden; padding: 4px;
}
.menu.open .menu-list { display: block; }
.menu-list a { display: block; padding: 8px 12px; color: var(--ink); border-radius: 6px; font-size: 14px; }
.menu-list a:hover { background: var(--hover); text-decoration: none; }

/* ---------- Dateiliste ---------- */
.droparea { position: relative; overflow: hidden; }
.files { width: 100%; border-collapse: collapse; font-size: 14px; }
.files th {
  text-align: left; font-weight: 600; font-size: 12px; letter-spacing: .03em;
  text-transform: uppercase; color: var(--dim);
  padding: 11px 12px; border-bottom: 1px solid var(--line);
}
.files td { padding: 9px 12px; border-bottom: 1px solid var(--line); }
.files tr:last-child td { border-bottom: 0; }
.files tbody tr:hover { background: var(--hover); }
.files .cb { width: 34px; }
.files .num { width: 90px; text-align: right; }
.files .date { width: 140px; white-space: nowrap; }
.files .act { width: 130px; text-align: right; white-space: nowrap; }
.files .act a { display: inline-block; padding: 3px 5px; border-radius: 6px; text-decoration: none; opacity: .65; }
.files .act a:hover { opacity: 1; background: var(--bg); }
.files .name { display: flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 500; }
.files .name:hover { color: var(--accent); text-decoration: none; }
.files .ic { font-size: 16px; width: 20px; text-align: center; color: var(--dim); }
.files .ic .fa-folder { color: #eab308; }
.files .ic .md { color: #0ea5e9; }
.files .ic .html { color: #f97316; }
.files .ic .img { color: #22c55e; }
.files .ic .pdf { color: #ef4444; }
.files .up a { color: var(--dim); font-size: 13px; }
.empty { padding: 56px 20px; text-align: center; color: var(--ink); }

.dropzone-hint {
  display: none; position: absolute; inset: 0; z-index: 20;
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
  border: 2px dashed var(--accent); border-radius: var(--radius);
  align-items: center; justify-content: center; font-weight: 600; color: var(--accent);
}
.droparea.dragging .dropzone-hint { display: flex; }

/* ---------- Upload-Fortschritt ---------- */
.progress {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 12px 16px; width: min(420px, 92vw); z-index: 60;
}
.progress .bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 7px; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.progress span { font-size: 13px; color: var(--dim); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 9px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 90;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- Editor ---------- */
.editor-main { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0; }
.editbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.modes { display: inline-flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: 9px; }
.modes .mode { padding: 5px 12px; border-radius: 7px; font-size: 14px; color: var(--dim); }
.modes .mode:hover { text-decoration: none; color: var(--ink); }
.modes .mode.on { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.editor-shell { flex: 1; min-height: 0; padding: 14px 16px 16px; display: flex; }
.editor-shell > * { flex: 1; min-height: 0; }

/* CodeMirror */
.CodeMirror { height: 100%; border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; }
.CodeMirror-scroll { min-height: 100%; }

/* EasyMDE */
.EasyMDEContainer { display: flex; flex-direction: column; background: var(--panel); border-radius: var(--radius); min-height: 0; }
.EasyMDEContainer .CodeMirror {
  border: 0; border-radius: 0; flex: 1 1 0; min-height: 0; height: auto;
  background: var(--panel); color: var(--ink);
}
.EasyMDEContainer .CodeMirror-scroll { min-height: 0 !important; }
.EasyMDEContainer .editor-preview-side { height: auto; }
.editor-toolbar { border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; background: var(--panel); }
.editor-toolbar button { color: var(--ink) !important; }
.editor-toolbar button:hover, .editor-toolbar button.active { background: var(--hover); border-color: var(--line); }
.EasyMDEContainer .CodeMirror { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.editor-statusbar { border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); background: var(--panel); color: var(--dim); }
.editor-preview, .editor-preview-side { background: var(--panel); color: var(--ink); padding: 16px 20px; }
.CodeMirror-cursor { border-left-color: var(--ink); }
.cm-s-easymde .CodeMirror-selected, .CodeMirror-selected { background: color-mix(in srgb, var(--accent) 22%, transparent) !important; }

/* Trumbowyg */
/* Trumbowyg verwaltet die Sichtbarkeit von Editor und Textarea (Code-Ansicht)
   selbst über .trumbowyg-editor-visible/-hidden - deren flex-Werte NICHT anfassen,
   sonst teilt sich die unsichtbare Textarea den Platz mit dem Editor. */
.trumbowyg-box {
  height: 100%; min-height: 0; margin: 0; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--panel);
}
.trumbowyg-editor-box { flex: 1 1 auto; min-height: 0; overflow: auto; background: #fff; }
.trumbowyg-editor { min-height: 100%; box-sizing: border-box; }
.trumbowyg-button-pane { background: var(--panel); border-bottom: 1px solid var(--line); }
.trumbowyg-button-pane::after { display: none; }
@media (prefers-color-scheme: dark) {
  .trumbowyg-button-pane { background: var(--panel); }
  /* Manche Symbole zeichnen mit stroke="currentColor", daher auch color setzen */
  .trumbowyg-button-pane button svg { fill: var(--ink); color: var(--ink); }
  .trumbowyg-button-pane .trumbowyg-open-dropdown::after { border-top-color: var(--ink); }
  .trumbowyg-button-pane button:not(.trumbowyg-disable):hover,
  .trumbowyg-button-pane button.trumbowyg-active { background: var(--hover); }
  .trumbowyg-button-pane .trumbowyg-button-group + .trumbowyg-button-group::before { background: var(--line); }
  .trumbowyg-dropdown, .trumbowyg-modal-box { background: var(--panel); color: var(--ink); border-color: var(--line); }
  .trumbowyg-dropdown button { background: var(--panel); color: var(--ink); }
  .trumbowyg-dropdown button svg { fill: var(--ink); }
  .trumbowyg-modal-box label input { background: var(--bg); color: var(--ink); }
  .trumbowyg-modal-box .trumbowyg-modal-title { background: var(--bg); color: var(--ink); }
}
/* Schreibfläche des HTML-Editors bewusst hell: sie zeigt das Dokument, wie es später aussieht */
.trumbowyg-editor { background: #fff; color: #111; }

@media (max-width: 640px) {
  .files .date, .files .num { display: none; }
  .topbar { padding: 9px 12px; gap: 8px; }
  .brand .dim { display: none; }
  .wrap { padding: 16px 10px 50px; }
  .editor-shell { padding: 8px; }
}

/* ---------- Markdown-Vorschau ---------- */
.editor-preview, .editor-preview-side { font-size: 15px; line-height: 1.65; }
.editor-preview > *:first-child, .editor-preview-side > *:first-child { margin-top: 0; }
.editor-preview h1, .editor-preview-side h1 { font-size: 1.7em; margin: 1.2em 0 .5em; padding-bottom: .25em; border-bottom: 1px solid var(--line); }
.editor-preview h2, .editor-preview-side h2 { font-size: 1.35em; margin: 1.2em 0 .5em; padding-bottom: .2em; border-bottom: 1px solid var(--line); }
.editor-preview h3, .editor-preview-side h3 { font-size: 1.15em; margin: 1.1em 0 .4em; }
.editor-preview table, .editor-preview-side table { border-collapse: collapse; margin: 1em 0; display: block; overflow-x: auto; max-width: 100%; }
.editor-preview th, .editor-preview td,
.editor-preview-side th, .editor-preview-side td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; }
.editor-preview th, .editor-preview-side th { background: var(--bg); font-weight: 600; }
.editor-preview pre, .editor-preview-side pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow-x: auto; }
.editor-preview code, .editor-preview-side code { background: var(--bg); border-radius: 4px; padding: 1px 5px; font-size: .9em; }
.editor-preview pre code, .editor-preview-side pre code { background: none; padding: 0; }
.editor-preview blockquote, .editor-preview-side blockquote { margin: 1em 0; padding: .2em 1em; border-left: 3px solid var(--line); color: var(--dim); }
.editor-preview img, .editor-preview-side img { max-width: 100%; height: auto; border-radius: 6px; }
.editor-preview hr, .editor-preview-side hr { border: 0; border-top: 1px solid var(--line); margin: 1.5em 0; }
