:root {
  --bg: #e9f3fa;
  --surface: #ffffff;
  --surface-2: #f4f9fc;
  --primary: #07799e;
  --primary-hover: #066683;
  --primary-soft: #d2e9f0;
  --accent: #d4883f;
  --accent-hover: #bf7733;
  --accent-soft: #f7e6d3;
  --text: #17313b;
  --muted: #5b7380;
  --border: #c7dbe6;
  --danger: #b4443c;
  --ok: #2d7a55;
  --radius: 3px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
code { background: var(--surface-2); padding: 0 .25em; border-radius: var(--radius); }

/* Kopfzeile */
.topbar { background: var(--primary); color: #fff; }
.topbar .inner { max-width: 1100px; margin: 0 auto; padding: 0 .75rem; display: flex; align-items: center; gap: .5rem; min-height: 48px; flex-wrap: wrap; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; margin-right: .5rem; display: flex; align-items: center; gap: .4rem; }
.topbar .brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: .15rem; flex-wrap: wrap; }
.topbar nav a, .topbar nav button { color: #e6f1f5; padding: .4rem .6rem; border-radius: var(--radius); background: none; border: 0; font: inherit; cursor: pointer; }
.topbar nav a:hover, .topbar nav button:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.topbar nav a.active { background: rgba(255,255,255,.18); }
.topbar .spacer { flex: 1; }
.topbar .user { color: #d9eef4; font-size: .9rem; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem .75rem 3rem; }
main.narrow { max-width: 520px; }
main.wide { max-width: none; padding: 0; }

/* Karten / Blöcke */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1rem; }
.card h2 { display: flex; align-items: center; gap: .4rem; justify-content: space-between; }
.card h2 .sub { color: var(--muted); font-weight: 400; font-size: .85rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .75rem; }
.grid .card { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
hr { border: 0; border-top: 1px solid var(--border); margin: .75rem 0; }

/* Formulare */
input[type=text], input[type=password], input[type=number], select, textarea {
  font: inherit; padding: .45rem .55rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; color: var(--text); width: 100%; max-width: 100%;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .5rem 0 .2rem; }
label.inline { display: inline-flex; align-items: center; gap: .35rem; color: var(--text); font-size: .95rem; margin: .3rem 0; }
.field { margin-bottom: .5rem; }
.btn, button.btn {
  display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-size: .92rem; padding: .42rem .75rem; cursor: pointer;
  border: 1px solid var(--primary); background: var(--primary); color: #fff; border-radius: var(--radius); line-height: 1.2; text-decoration: none;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn.accent { background: var(--accent); border-color: var(--accent); }
.btn.accent:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; color: var(--primary); border-color: var(--border); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: #f8e5e3; }
.btn.sm { padding: .25rem .5rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.4rem; letter-spacing: .35em; text-align: center; }
.code-big { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 2.2rem; letter-spacing: .3em; font-weight: 700; color: var(--primary); }

/* Meldungen */
.flash { padding: .6rem .8rem; border-radius: var(--radius); margin-bottom: .75rem; border: 1px solid; }
.flash.ok { background: #e3f2ea; border-color: #b6dcc8; color: var(--ok); }
.flash.err { background: #f8e5e3; border-color: #e5b9b5; color: var(--danger); }
.flash.info { background: var(--accent-soft); border-color: #ebcfae; color: #7a4a14; }

/* Icons */
.ic { width: 20px; height: 20px; flex: none; vertical-align: -5px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ic.folder { color: var(--accent); }
.ic.word { color: #2b5797; } .ic.cell { color: #217346; } .ic.slide { color: #b7472a; } .ic.pdf { color: #b4443c; }
.ic.image { color: #6b4fa0; } .ic.archive, .ic.media, .ic.file { color: var(--muted); }
.ic.sm { width: 16px; height: 16px; }

/* Explorer */
.toolbar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .6rem; }
.crumbs { display: flex; flex-wrap: wrap; gap: .2rem; align-items: center; font-size: .95rem; margin-bottom: .5rem; }
.crumbs .sep { color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.list li { display: flex; align-items: center; gap: .5rem; padding: .45rem .6rem; border-top: 1px solid var(--border); min-height: 42px; }
.list li:first-child { border-top: 0; }
.list li:hover { background: var(--surface-2); }
.list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: .5rem; }
.list .name a { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.list .meta { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.list .meta.size { width: 5.5rem; text-align: right; }
.list .meta.date { width: 8.5rem; }
.list input[type=checkbox] { width: 17px; height: 17px; margin: 0; }
.list .empty { color: var(--muted); justify-content: center; padding: 1.5rem; }
.quick { list-style: none; margin: 0; padding: 0; }
.quick li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; }
.quick li a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.quick .meta { color: var(--muted); font-size: .8rem; white-space: nowrap; }

/* Menüs (ohne JS via details) */
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; padding: .2rem .4rem; border-radius: var(--radius); color: var(--muted); display: inline-flex; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary:hover { background: var(--primary-soft); color: var(--primary); }
details.menu[open] > summary { background: var(--primary-soft); color: var(--primary); }
details.menu .pop {
  position: absolute; right: 0; top: 100%; z-index: 20; min-width: 220px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 2px 8px rgba(23,49,59,.12); padding: .3rem;
}
details.menu .pop a, details.menu .pop button { display: flex; width: 100%; align-items: center; gap: .4rem; padding: .4rem .5rem; background: none; border: 0; font: inherit; color: var(--text); text-align: left; cursor: pointer; border-radius: var(--radius); }
details.menu .pop a:hover, details.menu .pop button:hover { background: var(--surface-2); text-decoration: none; }
details.menu .pop form { margin: 0; }
details.menu .pop .inline-form { padding: .4rem .5rem; display: flex; gap: .3rem; }
details.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: .6rem; }
details.panel > summary { cursor: pointer; padding: .5rem .7rem; font-weight: 600; }
details.panel > .body { padding: .2rem .7rem .7rem; border-top: 1px solid var(--border); }

/* Upload */
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.2rem; text-align: center; color: var(--muted); background: var(--surface); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.progress { height: 8px; background: var(--primary-soft); border-radius: var(--radius); overflow: hidden; margin-top: .5rem; display: none; }
.progress > div { height: 100%; width: 0; background: var(--accent); }
#upl-status { font-size: .85rem; color: var(--muted); margin-top: .3rem; }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: .45rem .5rem; border-top: 1px solid var(--border); vertical-align: middle; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; border-top: 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.meter { height: 6px; background: var(--primary-soft); border-radius: var(--radius); overflow: hidden; }
.meter > div { height: 100%; background: var(--primary); }
.meter.warn > div { background: var(--accent); }
.badge { display: inline-block; font-size: .75rem; padding: .1rem .4rem; border-radius: var(--radius); background: var(--primary-soft); color: var(--primary); }
.badge.accent { background: var(--accent-soft); color: #7a4a14; }

/* Editor */
.editor-bar { display: flex; align-items: center; gap: .6rem; padding: .3rem .6rem; background: var(--primary); color: #fff; min-height: 40px; }
.editor-bar a { color: #fff; }
.editor-bar .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.editor-wrap { position: fixed; inset: 40px 0 0 0; }
#placeholder { width: 100%; height: 100%; }

@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar .inner { padding: 0 .5rem; }
  .topbar nav a, .topbar nav button { padding: .5rem .5rem; }
  .topbar .user { display: none; }
  main { padding: .6rem .5rem 3rem; }
  .list .meta.date { display: none; }
  .list .meta.size { width: auto; }
  .list li { padding: .5rem .5rem; }
  .toolbar .btn { flex: 1 1 auto; justify-content: center; }
  details.menu .pop { min-width: 200px; }
}

/* Inline-Umbenennen */
.list li.renaming .name > a, .list li.renaming .name > .badge { display: none; }
.rename-form { display: none; flex: 1; gap: .3rem; align-items: center; }
.list li.renaming .rename-form { display: flex; }
.rename-form input[type=text] { flex: 1; padding: .3rem .45rem; }
.copy-btn { display: inline-flex; align-items: center; background: none; border: 1px solid var(--border); border-radius: var(--radius); color: var(--primary); cursor: pointer; padding: .2rem .35rem; vertical-align: middle; }
.copy-btn:hover { background: var(--primary-soft); }
.copy-btn.done { color: var(--ok); border-color: var(--ok); }
.meter.lg { height: 10px; }

/* Eigene Dialoge (statt confirm/alert) */
dialog.modal {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text);
  max-width: 26rem; width: calc(100% - 2rem); box-shadow: 0 4px 20px rgba(23,49,59,.18);
}
dialog.modal::backdrop { background: rgba(23,49,59,.45); }
dialog.modal .head { padding: .7rem .9rem .2rem; font-weight: 600; }
dialog.modal .body { padding: 0 .9rem .8rem; color: var(--text); }
dialog.modal .foot { display: flex; gap: .5rem; justify-content: flex-end; padding: .7rem .9rem; border-top: 1px solid var(--border); background: var(--surface-2); }
dialog.modal .foot .btn { min-width: 6rem; justify-content: center; }

/* Eigene Feldmeldungen (statt Browser-Blasen) */
.field-error {
  display: block; margin-top: .25rem; padding: .3rem .5rem; font-size: .85rem;
  color: var(--danger); background: #f8e5e3; border: 1px solid #e5b9b5; border-radius: var(--radius);
}
.invalid { border-color: var(--danger) !important; }

/* Kurzmeldung (Toast) */
.toasts { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: .4rem; align-items: center; }
.toast { background: var(--text); color: #fff; padding: .45rem .8rem; border-radius: var(--radius); font-size: .9rem; max-width: 90vw; }
.toast.err { background: var(--danger); }

/* Markdown-Editor */
.md-bar { display: flex; align-items: center; gap: .5rem; padding: .3rem .6rem; background: var(--primary); color: #fff; min-height: 40px; flex-wrap: wrap; }
.md-bar a, .md-bar button { color: #fff; }
.md-bar .title { flex: 1; min-width: 6rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.md-bar .status { font-size: .82rem; color: #d9eef4; white-space: nowrap; }
.md-bar .seg { display: flex; border: 1px solid rgba(255,255,255,.35); border-radius: var(--radius); overflow: hidden; }
.md-bar .seg button { background: none; border: 0; font: inherit; font-size: .85rem; padding: .25rem .5rem; cursor: pointer; }
.md-bar .seg button.on { background: rgba(255,255,255,.22); }
.md-users { display: flex; gap: .25rem; align-items: center; }
.md-users .who {
  width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: #fff; border: 1px solid rgba(255,255,255,.5);
}

.md-tools { display: flex; gap: .2rem; flex-wrap: wrap; padding: .3rem .5rem; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.md-tools button {
  font: inherit; font-size: .85rem; padding: .2rem .5rem; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.md-tools button:hover { background: var(--primary-soft); }
.md-tools .gap { width: .5rem; }

#md { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.md-form { flex: 1 1 auto; min-height: 0; display: flex; }
.md-wrap { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; overflow: hidden; }
.md-pane { flex: 1 1 50%; min-width: 0; overflow: auto; background: var(--surface); }
.md-pane + .md-pane { border-left: 1px solid var(--border); }
.md-wrap.only-edit .md-pane.preview, .md-wrap.only-view .md-pane.edit { display: none; }

.md-edit-box { position: relative; height: 100%; }
.md-edit-box textarea, .md-carets {
  font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: .8rem; margin: 0; border: 0; width: 100%; height: 100%;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; tab-size: 2;
}
.md-edit-box textarea {
  position: relative; resize: none; outline: none; background: transparent; color: var(--text); display: block;
  overflow-y: scroll; scrollbar-gutter: stable;   /* gleiche Textbreite wie die Marken-Ebene */
}
/* Die Marken-Ebene liegt über dem Textfeld und muss exakt gleich umbrechen: gleiche Innenabstände,
   zuzüglich der Breite der Bildlaufleiste (--sbw wird beim Start gemessen). */
.md-carets { overflow: hidden; padding-right: calc(.8rem + var(--sbw, 0px)); }
.md-edit-box textarea:focus { outline: none; }
.md-carets { position: absolute; inset: 0; overflow: hidden; color: transparent; pointer-events: none; z-index: 1; }
.md-caret { position: relative; display: inline-block; width: 0; border-left: 2px solid var(--rc, var(--primary)); margin: 0 -1px; }
.md-caret b {
  position: absolute; top: -1.05em; left: -2px; font: 600 10px/1.4 system-ui, sans-serif; color: #fff;
  background: var(--rc, var(--primary)); padding: 0 .25em; border-radius: var(--radius); white-space: nowrap;
}
.md-view { padding: .9rem 1.1rem; max-width: 46rem; }
.md-view h1, .md-view h2, .md-view h3, .md-view h4 { margin: 1.1rem 0 .4rem; line-height: 1.25; }
.md-view h1 { font-size: 1.5rem; } .md-view h2 { font-size: 1.25rem; } .md-view h3 { font-size: 1.08rem; }
.md-view > :first-child { margin-top: 0; }
.md-view p, .md-view ul, .md-view ol, .md-view pre, .md-view blockquote, .md-view table { margin: 0 0 .7rem; }
.md-view ul, .md-view ol { padding-left: 1.3rem; }
.md-view li { margin: .15rem 0; }
.md-view code { background: var(--surface-2); border: 1px solid var(--border); padding: 0 .25em; border-radius: var(--radius); font-size: .92em; }
.md-view pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .7rem; overflow-x: auto; }
.md-view pre code { background: none; border: 0; padding: 0; }
.md-view blockquote { border-left: 3px solid var(--primary-soft); padding-left: .7rem; color: var(--muted); }
.md-view hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.md-view img { max-width: 100%; }
.md-view table { border-collapse: collapse; }
.md-view th, .md-view td { border: 1px solid var(--border); padding: .3rem .5rem; }
.md-view input[type=checkbox] { margin-right: .3rem; }
.md-offline { background: var(--accent-soft); color: #7a4a14; padding: .3rem .6rem; font-size: .85rem; border-bottom: 1px solid #ebcfae; }

@media (max-width: 800px) {
  .md-wrap { flex-direction: column; }
  .md-pane + .md-pane { border-left: 0; border-top: 1px solid var(--border); }
  .md-bar .title { flex: 1 0 100%; order: -1; }
}
