/* Weboberflaeche des Update-Servers.
   Uebernommen aus dem Webdyn-Dienst (Services/Webdyn_Service/wwwroot/style.css),
   damit beide Verwaltungen gleich aussehen. Was nur der Update-Server braucht,
   steht unten im eigenen Abschnitt - Aenderungen am gemeinsamen Teil bitte in
   beiden Dateien nachziehen.
   Ohne Framework: der Dienst liefert diese Dateien selbst aus, und eine
   Werkzeugkette zum Bauen gibt es im Projekt nicht. */

:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --line: #dcdfe4;
  --text: #1f2430;
  --muted: #666d7a;
  --accent: #1a56a8;
  --accent-text: #ffffff;
  --ok: #16794a;
  --warn: #8a5a00;
  --bad: #a52020;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181d;
    --surface: #1d2127;
    --surface-2: #22262d;
    --line: #333a44;
    --text: #e6e8ec;
    --muted: #9aa3b0;
    --accent: #5b9be8;
    --accent-text: #10131a;
    --ok: #5fd39a;
    --warn: #e0b35c;
    --bad: #f0796f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

code, pre, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* --- Startseite ------------------------------------------------------- */

body.start {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 30rem;
  width: 100%;
}

.card h1 { margin: 0 0 .25rem; font-size: 1.4rem; }
.lead { color: var(--muted); margin-top: 0; }
.hint { color: var(--muted); font-size: .875rem; }

/* --- Grundbausteine --------------------------------------------------- */

.button {
  display: inline-block;
  padding: .5rem .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

.button:hover { border-color: var(--accent); }

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.button.danger { color: var(--bad); border-color: var(--bad); }
.button:disabled { opacity: .5; cursor: default; }

button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .4rem .5rem;
  max-width: 100%;
}

textarea { width: 100%; min-height: 14rem; resize: vertical; }

label { display: block; margin-bottom: .75rem; }
label > span { display: block; color: var(--muted); font-size: .875rem; margin-bottom: .2rem; }

p:empty { display: none; }

.error { color: var(--bad); }
.ok { color: var(--ok); }
.muted { color: var(--muted); }

/* --- Gerüst ----------------------------------------------------------- */

header.top {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

header.top h1 { font-size: 1.05rem; margin: 0; }
header.top .who { margin-left: auto; color: var(--muted); font-size: .875rem; }

main { padding: 1rem; }

/* Die Klasse admin setzt init() in app.js, wenn /auth_get is_admin nennt. */
body:not(.admin) .admin-only { display: none; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.panel h2 { font-size: 1rem; margin: 0 0 .75rem; }
.panel h3 { font-size: .9rem; margin: 1rem 0 .5rem; color: var(--muted); }

.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.row > label { margin-bottom: 0; }
.spread { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.spread .right { margin-left: auto; }

/* --- Tabellen --------------------------------------------------------- */

.scroll { overflow-x: auto; }

/* Telegramme und Dateien rollen fuer sich: sonst laege alles darunter bis zu
   2000 Zeilen weiter unten. */
.scroll.tall { max-height: 26rem; overflow-y: auto; }
.scroll.tall th { position: sticky; top: 0; background: var(--surface); }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: .9rem;
}

th, td {
  text-align: left;
  padding: .4rem .6rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th { color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.chosen { background: var(--surface-2); outline: 1px solid var(--accent); }
td.num { text-align: right; font-family: ui-monospace, Consolas, monospace; }
td.wrap { white-space: normal; word-break: break-all; }

/* Sortieren und Filtern im Tabellenkopf. Der Pfeil hat seinen Platz immer,
   sonst springt die Spaltenbreite beim Umschalten. */
th button.sort {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

th button.sort:hover { color: var(--text); }
th button.sort::after { content: ""; display: inline-block; width: 1.1em; text-align: right; font-size: .7em; }
th[aria-sort] { color: var(--text); }
th[aria-sort="ascending"] button.sort::after { content: "\25B2"; }
th[aria-sort="descending"] button.sort::after { content: "\25BC"; }

tr.filters td { padding-top: .3rem; padding-bottom: .5rem; }
tr.filters input, tr.filters select { width: 100%; min-width: 7rem; padding: .2rem .3rem; font-size: .85rem; }

.table-status { margin-bottom: .5rem; }
.table-status label { display: inline-flex; align-items: center; gap: .4rem; margin-bottom: 0; }
.table-status label > span { margin-bottom: 0; }
.table-status input { width: 8rem; }

.pager { justify-content: center; margin-top: .75rem; }
.pager[hidden] { display: none; }

/* --- Kennzahlen ------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: .75rem;
}

.tile {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .6rem .75rem;
}

.tile .k { color: var(--muted); font-size: .8rem; }
.tile .v { font-size: 1.15rem; font-weight: 600; margin-top: .15rem; }
.tile .s { color: var(--muted); font-size: .8rem; }

/* Ladestand: ein Balken sagt mehr als eine Zahl. */
.bar {
  height: .4rem;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin-top: .4rem;
}

.bar > i { display: block; height: 100%; background: var(--ok); }
.bar.low > i { background: var(--warn); }
.bar.empty > i { background: var(--bad); }

pre.json {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .75rem;
  overflow: auto;
  max-height: 32rem;
  font-size: .85rem;
  margin: 0;
}

/* --- Meldungen -------------------------------------------------------- */

#toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 10;
  max-width: min(28rem, calc(100vw - 2rem));
}

.toast {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: .6rem .75rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
  font-size: .9rem;
}

.toast.bad { border-left-color: var(--bad); }
.toast.good { border-left-color: var(--ok); }

@media (max-width: 40rem) {
  header.top .who { margin-left: 0; width: 100%; }
  main { padding: .75rem; }
  .panel { padding: .75rem; }
}

/* ===================================================================== */
/* --- Nur Update-Server ------------------------------------------------ */

/* Bereiche der Verwaltung. Eine Leiste unter dem Kopf statt einer Seitenleiste:
   so bleibt der Kopf derselbe wie im Webdyn-Dashboard. */
nav.tabs {
  display: flex;
  gap: .25rem;
  flex-wrap: wrap;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

nav.tabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: .6rem .75rem;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}

nav.tabs button:hover { color: var(--text); }
nav.tabs button[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* Kopf eines Bereichs: Zurueck, Titel, rechts die Aktion. */
.panel .spread h2 { margin: 0; }
.panel > .spread + * { margin-top: .75rem; }

/* Knoepfe in einer Tabellenzeile. */
td.actions { white-space: nowrap; }
td.actions .button { padding: .2rem .55rem; font-size: .85rem; }
td.actions .button + .button { margin-left: .25rem; }

.button.small { padding: .2rem .55rem; font-size: .85rem; }

/* Ohne Treffer oder waehrend des Ladens. */
td.empty { color: var(--muted); text-align: center; padding: 1.5rem; white-space: normal; }

/* Der Dialog zum Anlegen und Bearbeiten. */
dialog.form {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
}

dialog.form::backdrop { background: rgba(0, 0, 0, .35); }
dialog.form form { display: flex; flex-direction: column; max-height: calc(100vh - 2rem); }
dialog.form h2 { font-size: 1.05rem; margin: 0; padding: 1rem 1rem .5rem; }
dialog.form .fields { padding: .5rem 1rem; overflow-y: auto; }
dialog.form .fields input:not([type="checkbox"]), dialog.form .fields select { width: 100%; }
dialog.form .fields textarea { min-height: 8rem; }
dialog.form .fields input[readonly] { color: var(--muted); }
dialog.form .error { margin: 0; padding: 0 1rem .5rem; }
dialog.form .buttons { display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 1rem 1rem; border-top: 1px solid var(--line); }

label.check { display: flex; align-items: center; gap: .5rem; }
label.check > span { display: inline; margin: 0; color: var(--text); font-size: inherit; }

/* Die INI im Bereich Reports steht zwischen Kopf und Tabelle, ob sichtbar
   oder nicht; der Abstand zur Tabelle bleibt derselbe. */
.panel > pre.report-ini + .scroll { margin-top: .75rem; }

/* Dokumentation eines Programms, nur zum Lesen. Breiter als die Formulare. */
dialog.doc {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(56rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
}

dialog.doc[open] { display: flex; flex-direction: column; }
dialog.doc::backdrop { background: rgba(0, 0, 0, .35); }

.doc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1rem .75rem;
  border-bottom: 1px solid var(--line);
}

.doc-head h2 { font-size: 1.1rem; margin: 0; }
.doc-head .muted { font-size: .85rem; }
.doc-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 1rem; }

/* --- Markdown --------------------------------------------------------- */
/* Dokumentation, Changelog und bekannte Fehler (mdToHtml in markdown.js).
   Wie in CustomerDocs.html, aber mit den Farben dieser Datei. Steht hinter
   ".panel h2/h3", damit Ueberschriften aus dem Markdown wie Fliesstext-
   Ueberschriften aussehen. */

.prose { overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: 0 0 .6rem; }

.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  color: inherit;
  font-weight: 650;
  line-height: 1.3;
  margin: 1.1rem 0 .5rem;
}

.prose h1 { font-size: 1.15rem; }
.prose h2 { font-size: 1.05rem; }
.prose h3 { font-size: .97rem; }
.prose h4, .prose h5, .prose h6 { font-size: .9rem; }

.prose ul, .prose ol { margin: 0 0 .6rem; padding-left: 1.4rem; }
.prose li { margin: .2rem 0; }
.prose li > ul, .prose li > ol { margin: .2rem 0 0; }
.prose ul.tasks { list-style: none; padding-left: .1rem; }
.prose ul.tasks input { margin-right: .4rem; }

.prose blockquote {
  margin: 0 0 .6rem;
  padding: .1rem 0 .1rem .75rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.prose code {
  font-size: .86em;
  padding: .05rem .3rem;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.prose pre {
  margin: 0 0 .6rem;
  padding: .6rem .75rem;
  overflow-x: auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.prose pre code { padding: 0; border: 0; background: none; font-size: .85rem; }
.prose a { color: var(--accent); }
.prose strong { font-weight: 650; }
.prose hr { margin: .9rem 0; border: 0; border-top: 1px solid var(--line); }

/* Breite Tabellen rollen fuer sich. */
.prose .md-table { overflow-x: auto; margin: 0 0 .6rem; }
.prose table { width: auto; font-size: .875rem; }
.prose th, .prose td { border: 1px solid var(--line); padding: .3rem .55rem; white-space: normal; }

/* In Zellen kein Umbruch mitten im Wort ("Stan|dard"): lieber rollt die
   Tabelle in ihrem Kasten (.md-table). */
.prose th, .prose td { overflow-wrap: normal; }
.prose th { color: var(--text); background: var(--surface-2); }
.prose tbody tr:hover { background: none; }

/* --- Versionen eines Programms ---------------------------------------- */
/* Je Programm-Datei ein Block, aufgebaut wie in CustomerDocs.html. */

.version { padding: .9rem 0; border-bottom: 1px solid var(--line); }
.version:first-child { padding-top: 0; }
.version:last-child { border-bottom: 0; padding-bottom: 0; }

.version-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem .65rem;
  margin-bottom: .45rem;
}

.version-head .right { margin-left: auto; display: flex; gap: .25rem; }
.version-nr { font-weight: 650; font-size: 1rem; font-variant-numeric: tabular-nums; }
.version-meta { font-size: .8rem; color: var(--muted); }
.version-file { overflow-wrap: anywhere; }

.version > p.muted { margin: 0; font-size: .875rem; }

.badge {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .05rem .5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge[data-ch="stable"] { background: #e7f6ec; border-color: #b7e0c4; color: #1d6c37; }
.badge[data-ch="beta"]   { background: #eef2ff; border-color: #c3ccf5; color: #35439b; }
.badge[data-ch="test"]   { background: #fff5e5; border-color: #f0d4a3; color: #8a5a12; }
.badge[data-ch="dev"]    { background: #f2eafc; border-color: #d8c4ef; color: #6b31a8; }

@media (prefers-color-scheme: dark) {
  .badge[data-ch="stable"] { background: #16301f; border-color: #2c5a3a; color: #86d3a1; }
  .badge[data-ch="beta"]   { background: #1b2246; border-color: #38427c; color: #a8b5ff; }
  .badge[data-ch="test"]   { background: #33260f; border-color: #5f4a1e; color: #e8bf78; }
  .badge[data-ch="dev"]    { background: #2a1c3d; border-color: #4b3467; color: #cba6f0; }
}

.bugs {
  margin-top: .55rem;
  padding: .55rem .75rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--warn) 8%, var(--surface));
  font-size: .875rem;
}

/* Nur die eigene Ueberschrift des Kastens, nicht fettes Markdown darin. */
.bugs > strong {
  display: block;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--warn);
  margin-bottom: .2rem;
}
