:root {
  --bg: #14111c; --card: #1e1a2b; --card2: #272238; --line: #342d49;
  --text: #f1eefa; --muted: #9d94b8; --accent: #b388ff; --accent-ink: #1a1030;
  --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
  --radius: 14px; --nav: 64px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f2fb; --card: #fff; --card2: #f0ebfa; --line: #ddd5ee;
    --text: #1d1730; --muted: #6c6385; --accent: #7c4dff; --accent-ink: #fff;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(var(--nav) + env(safe-area-inset-bottom) + 16px); }

header.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
header.top h1 { font-size: 1.15rem; margin: 0; flex: 1; display: flex; align-items: center; gap: 8px; }
header.top h1 svg { color: var(--accent); }
.pill { font-size: .8rem; padding: 4px 10px; border-radius: 99px; background: var(--card2); display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.online { background: var(--ok); } .dot.connecting { background: var(--warn); } .dot.error { background: var(--bad); }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
h2 { font-size: 1.05rem; margin: 20px 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: .9rem; }
.error-text { color: var(--bad); }

nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs button { flex: 1; height: var(--nav); background: none; border: 0; color: var(--muted); font-size: .75rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
nav.tabs button svg { display: block; }
nav.tabs button.active { color: var(--accent); font-weight: 600; }

button.btn { min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
button.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.btn.danger { color: var(--bad); }
button.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

label.field { display: block; margin: 14px 0 0; }
.field > .lbl { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 5px; }
.help { font-size: .8rem; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px; /* 16px verhindert Zoom auf iOS */ }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* Toggle */
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(22px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.toggle-field .lbl { font-size: .95rem; font-weight: 600; }

/* Tools */
.tool { padding: 0; overflow: clip; }
.tool-head { display: flex; align-items: center; gap: 12px; padding: 14px; cursor: pointer; }
.tool-head .ico { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--card2); color: var(--accent); }
.tool-head .meta { flex: 1; min-width: 0; }
.tool-head .name { font-weight: 700; }
.tool-head .desc { font-size: .82rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tool-head .chev { color: var(--muted); transition: transform .2s; }
.tool.open .chev { transform: rotate(90deg); }
.tool-body { display: none; padding: 0 14px 14px; border-top: 1px solid var(--line); }
.tool.open .tool-body { display: block; }
.tool:not(.on) .tool-head .name::after { content: " · aus"; color: var(--muted); font-weight: 400; font-size: .8rem; }
.tool-actions { position: sticky; bottom: calc(var(--nav) + env(safe-area-inset-bottom) + 8px); margin-top: 16px; }
.tool-actions .btn { width: 100%; box-shadow: 0 4px 16px #0006; }

.item { border: 1px solid var(--line); background: var(--card2); border-radius: 12px; margin-top: 10px; }
.item summary { padding: 12px; cursor: pointer; font-weight: 600; list-style: none; display: flex; gap: 8px; align-items: center; min-height: 46px; }
.item summary::-webkit-details-marker { display: none; }
.item summary .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item summary::after { content: "›"; color: var(--muted); font-size: 1.3rem; transition: transform .2s; }
.item[open] summary::after { transform: rotate(90deg); }
.item .inner { padding: 0 12px 12px; }
.item .btn.danger { width: 100%; margin-top: 14px; }
.add-btn { width: 100%; margin-top: 10px; border-style: dashed; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }

/* Chat */
.log { font-size: .9rem; max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.log div { word-break: break-word; padding: 4px 0; border-bottom: 1px solid var(--line); }
.log time { color: var(--muted); font-size: .75rem; margin-right: 6px; }
.log .u { font-weight: 700; color: var(--accent); }
.log .bot .u { color: var(--ok); }
.log .system { color: var(--muted); font-style: italic; }
.log .error { color: var(--bad); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card2); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.4rem; }
.stat span { font-size: .75rem; color: var(--muted); }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; text-align: center; }
.login .logo { color: var(--accent); display: flex; justify-content: center; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav) + env(safe-area-inset-bottom) + 12px); transform: translate(-50%, 12px);
  background: var(--text); color: var(--bg); padding: 6px 14px; border-radius: 99px; font-size: .8rem; line-height: 1.3; opacity: 0; transition: .25s; z-index: 50; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); color: #fff; }

@media (min-width: 900px) {
  main { padding-top: 28px; }
  nav.tabs { left: 50%; right: auto; width: 520px; transform: translateX(-50%); border-radius: 18px 18px 0 0; border: 1px solid var(--line); }
}
