:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #667085;
  --line: #d9dee5;
  --accent: #1d4e6b;
  --accent-ink: #ffffff;
  --rec: #c8372d;
  --ok: #2f8f5b;
  --paper: #ffffff;
  --preview: #8b93a1;
  --chip: #e6ebf1;
  --warn-bg: #fff4d6;
  --warn-line: #e5c35c;
  --warn-ink: #5c4300;
  --hot: #c8372d;
  --warm: #b86e00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --panel: #1b2129; --ink: #e6eaf0; --muted: #98a2b3; --line: #2c3541;
    --accent: #5aa6cf; --accent-ink: #0c1218; --paper: #20262f; --preview: #7d8696; --chip: #2a323d;
    --warn-bg: #3a3014; --warn-line: #7a6320; --warn-ink: #f0dc9c;
    --hot: #ff7b70; --warm: #f0a53c;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

/* ------------------------------------------------------------ Kopfzeile */
header {
  display: flex; align-items: center; gap: 18px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
header h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
nav { display: flex; gap: 4px; }
nav a {
  padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--ink);
}
nav a:hover { background: var(--chip); }
nav a.on { background: var(--accent); color: var(--accent-ink); }
.pill {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px;
  background: var(--hot); color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--rec); }
.dot.on { background: var(--ok); }
.spacer { flex: 1; }
#userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
#userbox b { color: var(--ink); font-weight: 600; }

main { padding: 16px 20px 28px; max-width: 1400px; margin: 0 auto; }
.editorgrid, .detailgrid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; }
@media (max-width: 960px) { .editorgrid, .detailgrid { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------- Bedienelemente */
button, .btn {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--hot); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
label { display: block; font-size: 12.5px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--ink); font-size: 15px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 14px;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 0 0 10px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 2px 0; }
.err { color: var(--rec); font-size: 13px; margin-top: 8px; min-height: 1em; }
.notice {
  background: var(--chip); border-radius: 8px; padding: 9px 12px; margin-bottom: 12px;
}
.notice.warn, .callout { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); }
.callout { border-radius: 8px; padding: 9px 12px; margin-bottom: 12px; }
.callout p { margin: 4px 0 0; white-space: pre-wrap; }

/* --------------------------------------------------------- Editor */
.metagrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; }
.metagrid .wide { grid-column: 1 / -1; }
@media (max-width: 700px) { .metagrid { grid-template-columns: 1fr; } }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
#mic { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; padding: 9px 18px; min-width: 150px; }
#mic.rec { background: var(--rec); border-color: var(--rec); color: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(200,55,45,.45); } 50% { box-shadow: 0 0 0 8px rgba(200,55,45,0); } }
.meter { width: 90px; height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .08s linear; }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 2px; }
.chips { display: flex; gap: 6px; }
.chip { min-width: 32px; padding: 6px 9px; text-align: center; background: var(--chip); border-radius: 7px; font-size: 13px; border: 1px solid transparent; color: var(--muted); }
.chip.on { background: var(--accent); color: var(--accent-ink); }

.paper {
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  min-height: 52vh; padding: 36px 44px; position: relative;
  font: 17px/1.65 Georgia, "Times New Roman", serif;
}
.paper.readonly { min-height: 40vh; }
#editor { outline: none; min-height: 45vh; white-space: pre-wrap; word-wrap: break-word; caret-color: var(--accent); }
#editor p, #dText p { margin: 0 0 .9em; }
#dText { white-space: pre-wrap; word-wrap: break-word; }
/* Einfügemarke: Mit Fokus zeigt der Browser seinen eigenen Cursor. Ohne Fokus (z. B. nach einem Klick
   auf einen Knopf) blinkt hier eine Marke am Textende, denn dort landet der diktierte Text. */
@keyframes blink { 50% { opacity: 0; } }
#editor:not(:focus) p:last-child::after {
  content: ""; display: inline-block; width: 2px; height: 1.15em; margin-left: 2px;
  vertical-align: text-bottom; background: var(--accent); animation: blink 1.1s steps(1) infinite;
}
#editor.is-empty:not(:focus) p:first-child::before {
  content: ""; display: inline-block; width: 2px; height: 1.15em; margin-right: 2px;
  vertical-align: text-bottom; background: var(--accent); animation: blink 1.1s steps(1) infinite;
}
#editor.is-empty p:first-child::after {
  content: "Mikrofon starten und diktieren. Zeichen, Absätze und Formatierung per Sprache, z. B. „Komma“, „neuer Absatz“, „letzten Satz löschen“.";
  display: inline; width: auto; height: auto; margin: 0; background: none; animation: none;
  vertical-align: baseline; color: var(--preview); font-style: italic; pointer-events: none;
}
.pv { color: var(--preview); }
.actionbar {
  display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.savestate { color: var(--muted); font-size: 13px; }
.savestate.bad { color: var(--rec); }

aside h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 0 0 10px; }
label.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; font-size: 15px; color: var(--ink); }
label.row input[type=checkbox] { width: auto; }
label.row select { width: auto; max-width: 58%; min-width: 0; }
input[type=range] { width: 130px; padding: 0; }
.cmds { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.cmds td { padding: 5px 0; vertical-align: top; border-top: 1px solid var(--line); }
.cmds tr:first-child td { border-top: 0; }
.cmds td:first-child { padding-right: 10px; font-weight: 600; white-space: nowrap; }
.cmds td:last-child { color: var(--muted); }
details summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }

/* ------------------------------------------------------------- Listen */
.listhead { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.listhead h2 { margin: 0; font-size: 20px; }
.tabs { display: flex; gap: 4px; }
.tabs button { border-color: transparent; background: var(--chip); }
.tabs button.on { background: var(--accent); color: var(--accent-ink); }
table.docs { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.docs th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); }
table.docs td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
table.docs tbody tr { cursor: pointer; }
table.docs tbody tr:hover { background: var(--chip); }
table.docs tr.prio-sehr_eilig td:first-child { box-shadow: inset 4px 0 0 var(--hot); }
table.docs tr.prio-eilig td:first-child { box-shadow: inset 4px 0 0 var(--warm); }
table.docs.anwalt .col-owner { display: none; }
td .sub { color: var(--muted); font-size: 13px; }
td a.title { font-weight: 600; text-decoration: none; color: var(--ink); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.badge.sehr_eilig { background: var(--hot); color: #fff; }
.badge.eilig { background: var(--warm); color: #fff; }
.badge.q { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }
.overdue { color: var(--hot); font-weight: 600; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* ------------------------------------------------------------ Detail */
.backrow { margin-bottom: 10px; }
dl.meta { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; font-size: 14px; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; word-break: break-word; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions button { text-align: left; }
ul.events { list-style: none; margin: 0; padding: 0; font-size: 13px; }
ul.events li { padding: 4px 0; border-top: 1px solid var(--line); color: var(--muted); }
ul.events li:first-child { border-top: 0; }
ul.events b { color: var(--ink); font-weight: 600; }
#dReturnBox { margin-top: 10px; display: grid; gap: 8px; }

/* ------------------------------------------------------------ Anmeldung */
#overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
form.login { width: min(380px, 92vw); display: grid; gap: 12px; padding: 22px; }
form.login h2 { margin: 0 0 2px; font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--ink); }

.formbtns { display: flex; gap: 8px; justify-content: flex-end; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg, #fff);
  padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); z-index: 50; }
.cmdnote { min-height: 1.5em; margin: 2px 4px 6px; font-size: 13px; color: var(--muted); }
.cm { display: inline-block; width: 2px; height: 1.15em; margin: 0 -1px; vertical-align: text-bottom;
  background: var(--accent); animation: blink 1.1s steps(1) infinite; }
#editor.has-cm p:last-child::after { content: none; }

/* Das Textfeld hat eine feste Höhe und scrollt in sich. So bleibt die Seite mit Einstellungen und Knöpfen
   beim Diktieren an ihrem Platz. */
.paper.scroll { height: clamp(280px, calc(100vh - 480px), 900px); min-height: 0; overflow-y: auto; padding: 24px 36px; overscroll-behavior: contain; }
.paper.scroll #editor { min-height: 100%; }
