:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --text: #1b1b1b;
  --muted: #6b6b6b;
  --line: #e4e4e0;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --hover: #efefeb;
  --sel: #e6efff;
  --danger: #c62828;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --card: #1f1f1f;
    --text: #ececec;
    --muted: #9a9a9a;
    --line: #2e2e2e;
    --accent: #5b9bff;
    --accent-text: #0b0b0b;
    --hover: #262626;
    --sel: #1d2b44;
    --danger: #ff6b6b;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
input[type=text], input[type=password], input[type=search] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  outline: none;
}
input:focus { border-color: var(--accent); }

/* Login */
#login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 32px 24px;
}
.login-card h1 { margin: 4px 0 8px; font-size: 22px; font-weight: 600; }
.login-card button { width: 100%; padding: 10px; }
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

/* App – feste Aufteilung: Kopf, Suche, Liste (scrollt), Leiste unten */
#app {
  position: fixed; inset: 0;
  display: grid; grid-template-rows: 60px 56px 1fr auto;
  max-width: 900px; margin: 0 auto;
}
.top { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 4px; padding: 0 8px; }
.icon-btn {
  width: 44px; height: 44px; padding: 0; border: none; background: transparent; border-radius: 12px;
  display: grid; place-items: center;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn circle { fill: currentColor; stroke: none; }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn:disabled:hover { background: transparent; }
.titles { min-width: 0; text-align: center; }
.t1 { font-size: 17px; font-weight: 600; height: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t2 {
  height: 20px; font-size: 13px; color: var(--muted);
  white-space: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.t2::-webkit-scrollbar { display: none; }
.t2 button { border: none; background: none; padding: 0 2px; border-radius: 4px; color: inherit; font-size: 13px; }
.t2 span { padding: 0 2px; }
.searchbar { padding: 4px 16px 8px; }
.searchbar input { height: 44px; }

.list {
  overflow-y: auto; overscroll-behavior: contain;
  margin: 0 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  align-self: stretch; min-height: 0;
}
.row {
  display: grid; grid-template-columns: 36px 1fr 44px; align-items: center; gap: 12px;
  height: 60px; padding: 0 4px 0 12px; border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none;
}
.row:hover { background: var(--hover); }
.row.selected { background: var(--sel); }
.row .ic { width: 36px; height: 36px; display: grid; place-items: center; font-size: 22px; }
.row .ic img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }
.row .meta { min-width: 0; }
.row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot { width: 44px; height: 44px; display: grid; place-items: center; }
.slot .more { width: 44px; height: 44px; border: none; background: none; padding: 0; font-size: 20px; color: var(--muted); border-radius: 10px; }
.slot .check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted);
  display: grid; place-items: center; color: var(--accent-text); font-size: 13px; font-weight: 700;
}
.row.selected .slot .check { background: var(--accent); border-color: var(--accent); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.bottombar {
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.bottombar button {
  border: none; background: none; border-radius: 12px; height: 56px; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; color: var(--text);
}
.bottombar button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottombar button.accent { color: var(--accent); }
.bottombar button.danger { color: var(--danger); }
.bottombar button:disabled { opacity: .3; cursor: default; }
.bottombar button:disabled:hover { background: none; }
.menu .info { padding: 8px 12px; font-size: 13px; color: var(--muted); }

/* Kontextmenü */
.menu {
  position: fixed; z-index: 20; min-width: 190px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 6px; display: flex; flex-direction: column;
}
.menu button { border: none; border-radius: 8px; text-align: left; padding: 10px 12px; background: none; }
.menu button:hover { background: var(--hover); }
.menu hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

/* Dialog */
dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 20px;
  background: var(--card); color: var(--text); width: min(92vw, 420px);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin: 0 0 14px; font-size: 18px; font-weight: 600; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.picker { border: 1px solid var(--line); border-radius: 10px; max-height: 46vh; overflow: auto; }
.picker .pk { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.picker .pk:last-child { border-bottom: none; }
.picker .pk:hover { background: var(--hover); }
.picker-path { font-size: 13px; color: var(--muted); margin-bottom: 8px; word-break: break-all; }

/* Uploads */
.uploads {
  position: fixed; right: 16px; bottom: 88px; left: 16px; max-width: 380px; margin-left: auto; z-index: 15;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18); max-height: 40vh; overflow: auto;
}
.up { font-size: 13px; padding: 6px 0; }
.up .bar { height: 4px; background: var(--line); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.up .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.drop {
  position: fixed; inset: 0; z-index: 30; background: rgba(31,111,235,.12);
  border: 3px dashed var(--accent); display: grid; place-items: center; font-size: 20px; pointer-events: none;
}
.drop div { background: var(--card); padding: 14px 22px; border-radius: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  opacity: 0; transition: all .2s; pointer-events: none; z-index: 40; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.foot { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 0; }


/* Vorschau: liegt über Suche + Liste + Leiste, Kopfzeile bleibt */
.viewer {
  position: absolute; left: 0; right: 0; top: 60px; bottom: 0; z-index: 6;
  display: grid; grid-template-rows: 1fr auto; background: var(--bg);
}
.v-body {
  min-height: 0; margin: 4px 16px 0; border-radius: var(--radius); overflow: auto;
  background: var(--card); border: 1px solid var(--line);
  display: grid; place-items: center; touch-action: pan-y;
}
.v-body img, .v-body video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.v-body audio { width: calc(100% - 32px); }
.v-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.v-body pre {
  align-self: start; justify-self: stretch; margin: 0; padding: 16px;
  font: 13px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word;
}
.v-note { text-align: center; color: var(--muted); padding: 24px; }
.v-big { font-size: 56px; margin-bottom: 8px; }
.vrow { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.vrow:last-child { border-bottom: none; }
.vrow .name { font-size: 14px; }
.vrow .sub { font-size: 12px; color: var(--muted); }
.vrow button { padding: 6px 12px; font-size: 13px; }
.menu .info { padding: 6px 12px 2px; }

/* Einstellungen */
.settings { padding: 4px 0 16px; }
.set-sec { padding: 8px 0; border-bottom: 8px solid var(--bg); }
.set-sec:last-child { border-bottom: none; }
.set-sec h3 { margin: 8px 16px 4px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.set-row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  min-height: 60px; padding: 8px 16px; border-bottom: 1px solid var(--line);
}
.set-row:last-child { border-bottom: none; }
.set-row .name { white-space: normal; }
.set-row .sub { white-space: normal; }
.set-sub { margin: 12px 16px 2px; font-size: 13px; color: var(--muted); }
.set-empty { padding: 10px 16px; color: var(--muted); font-size: 14px; }
.set-add { padding: 10px 16px 4px; }
.set-ctl { display: flex; gap: 8px; align-items: center; }
.set-btn { padding: 7px 12px; font-size: 14px; }
.set-btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.set-btn.icon { width: 36px; height: 36px; padding: 0; }
.set-select, .set-input {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; max-width: 46vw;
}
.set-input { width: 46vw; max-width: 260px; border-radius: 10px; }
dialog .set-input { width: 100%; max-width: none; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.set-val { color: var(--muted); font-size: 14px; text-align: right; }
.set-val.warn { color: var(--danger); }
.set-ico { width: 36px; text-align: center; }
.switch {
  width: 50px; height: 30px; padding: 0; border-radius: 999px; border: none;
  background: var(--line); position: relative; flex: none;
}
.switch i { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: left .15s; }
.switch.on { background: var(--accent); }
.switch.on i { left: 23px; }
.switch:hover { background: var(--line); }
.switch.on:hover { background: var(--accent); }
.dlg-text { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.dlg-row { display: flex; justify-content: flex-end; margin-top: 10px; }
#q:disabled { opacity: .5; }
.set-row .sub { color: var(--muted); font-size: 13px; }

.set-row.sub-row { min-height: 44px; padding-top: 0; }
.set-hint { padding: 0 16px 6px; font-size: 13px; color: var(--muted); }
.set-select.wide { width: 100%; max-width: none; }
textarea.set-input { width: 100%; max-width: none; resize: vertical; font: inherit; }
.dlg-label { font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.dlg-label:first-child { margin-top: 0; }
.dlg-files { font-size: 14px; display: grid; gap: 4px; }
a.set-btn.linkbtn { display: inline-flex; align-items: center; text-decoration: none; color: var(--text); border: 1px solid var(--line); border-radius: 999px; margin-right: 8px; }

/* Server-Übersicht */
.status { padding-top: 12px; }
.st-banner { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: center; margin: 0 12px 10px; padding: 12px; border-radius: 14px; background: var(--hover); }
.st-ico { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 18px; color: #fff; }
.st-banner.gruen .st-ico { background: #1e8e3e; }
.st-banner.gelb .st-ico { background: #c77700; }
.st-banner.rot .st-ico { background: var(--danger); }
.st-banner .name { font-weight: 600; font-size: 16px; }
.st-banner .sub { color: var(--muted); font-size: 13px; }
.st-warns { margin: 0 12px 10px; display: grid; gap: 6px; }
.st-warn { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; font-size: 14px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); }
.st-wico { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; background: #c77700; }
.st-warn.rot .st-wico { background: var(--danger); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 12px 8px; }
.tile { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; min-height: 118px; display: grid; grid-template-rows: auto auto 1fr auto; gap: 2px; }
.tile-label { font-size: 12px; color: var(--muted); }
.tile-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile.gelb .tile-value { color: #c77700; }
.tile.rot .tile-value { color: var(--danger); }
.tile-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark { width: 100%; height: 32px; align-self: end; touch-action: none; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark-dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.spark-empty { height: 32px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; align-self: center; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.thin { height: 5px; margin-top: 6px; }
.st-dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; flex: none; }
.st-dot.ok { background: #1e8e3e; }
.st-dot.bad { background: var(--danger); }
.set-row.fold { min-height: 52px; }
.logbox { margin: 0; max-height: 50vh; overflow: auto; font: 11px/1.45 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; background: var(--hover); border-radius: 10px; padding: 10px; }
.logbox.small { max-height: 120px; margin-top: 6px; }
@media (prefers-color-scheme: dark) {
  .st-banner.gruen .st-ico, .st-dot.ok { background: #2ea043; }
  .st-banner.gelb .st-ico, .st-wico { background: #d18616; }
  .tile.gelb .tile-value { color: #e3a33a; }
}
.set-row.fold { grid-template-columns: 1fr 76px; }
.set-row.fold .set-val { text-align: right; }

/* Startseite */
.home { padding: 12px 0 8px; }
.hbanner { width: calc(100% - 24px); border: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.htiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 12px; }
.htile { border: 1px solid var(--line); border-radius: 16px; background: var(--card); padding: 14px 12px; min-height: 108px;
  display: grid; grid-template-rows: auto auto 1fr; gap: 2px; text-align: left; font: inherit; color: var(--text); cursor: pointer; }
.htile:hover { background: var(--hover); }
.htile.dim { opacity: .6; }
.hicon { font-size: 26px; line-height: 1; margin-bottom: 6px; }
.htitle { font-weight: 600; font-size: 15px; }
.hsub { font-size: 12.5px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hfoot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px 0 4px; }
.code-row.off { opacity: .55; }
.code-row .name { font-size: 14px; letter-spacing: .03em; }
.code-big { font: 600 20px/1.4 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; text-align: center; padding: 8px; border: 1px dashed var(--line); border-radius: 10px; margin-bottom: 8px; user-select: all; }

.webframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: var(--radius); }
/* Auf Touch-Geräten keinen „hängenden“ Hover-Zustand anzeigen */
@media (hover: none) {
  button:hover, .row:hover, .htile:hover, .menu button:hover, .picker .pk:hover, .icon-btn:hover { background: inherit; }
  .bottombar button:hover { background: none; }
  button.primary:hover, .set-btn.primary:hover { background: var(--accent); }
  .switch.on:hover { background: var(--accent); }
  .switch:not(.on):hover { background: var(--line); }
}
button:active, .row:active, .htile:active, .pk:active { filter: brightness(.94); }
.v-body:has(.webframe) { place-items: stretch; }

.set-row.stack { grid-template-columns: 1fr; gap: 6px; }
.set-row.stack .set-input { width: 100%; max-width: none; }
.set-row.stack .set-ctl { width: 100%; }
.set-row.stack .set-ctl .set-input { flex: 1; }
