/* Weboberflaeche des WebdynEasy-Dienstes.
   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; }

/* --- Konfiguration ---------------------------------------------------- */

.cfg-section { border-top: 1px solid var(--line); margin-top: 1rem; }
.cfg-section > p.muted { font-size: .875rem; margin: 0 0 .5rem; }
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0 1rem; align-items: end; }

/* Was bereitgelegt wird, traegt links einen Strich. */
.cfg-field { border-left: 3px solid transparent; padding-left: .5rem; margin-bottom: .5rem; }
.cfg-field.changed { border-left-color: var(--accent); }
.cfg-field.invalid { border-left-color: var(--bad); }
.cfg-field.wide { grid-column: 1 / -1; }
.cfg-field label { margin-bottom: 0; }
.cfg-field select, .cfg-field input[type="text"], .cfg-field input[type="number"], .cfg-field input[type="password"] { width: 100%; }
.cfg-title { display: block; color: var(--muted); font-size: .875rem; margin-bottom: .2rem; }
.cfg-secret { display: flex; gap: .5rem; align-items: center; }
.cfg-secret input { flex: 1; min-width: 0; }

label.check { display: flex; align-items: center; gap: .45rem; padding: .4rem 0; }
label.check > span { color: var(--text); font-size: inherit; margin-bottom: 0; }

.cfg-codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 0 1rem; }
.cfg-codes label.check { padding: .15rem 0; }

.cfg-schedule td.center, .cfg-schedule th { text-align: center; }
.cfg-schedule th:first-child { text-align: left; }
.cfg-schedule input.cron { width: 12rem; }
.cfg-schedule input.seconds { width: 8rem; }

details > summary { cursor: pointer; color: var(--muted); margin: .25rem 0 .5rem; }

/* --- 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; }
}
