:root {
  --bg: #f3f6fa; --bg2: #e8edf4; --panel: #ffffff; --panel2: #f7f9fc; --line: #d7dee8;
  --text: #0f1b2a; --muted: #5b6b80; --accent: #0a8fb8; --accent2: #5b4fd8;
  --ok: #138a52; --warn: #b7791f; --err: #c53b3b; --glow: rgba(10, 143, 184, .18);
  --radius: 12px; --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #070b12; --bg2: #0b111b; --panel: #0f1724; --panel2: #131d2d; --line: #1e2a3d;
  --text: #dfe9f5; --muted: #7d8ea6; --accent: #38e1ff; --accent2: #8b7dff;
  --ok: #3ddc97; --warn: #f5b84b; --err: #ff6b6b; --glow: rgba(56, 225, 255, .16);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, var(--glow), transparent 60%), var(--bg);
  color: var(--text); font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.shell { display: grid; grid-template-columns: 248px 1fr; height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--bg2), var(--bg)); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 12px; gap: 18px; overflow-y: auto;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px; }
.brand strong { letter-spacing: .32em; font-size: 16px; }
.brand small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .04em; }
.core {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--accent); position: relative;
  box-shadow: 0 0 14px var(--glow), inset 0 0 10px var(--glow);
}
.core::after { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: var(--accent); animation: pulse 3s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.8); } }
@media (prefers-reduced-motion: reduce) { .core::after, .spinner { animation: none !important; } }

nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 9px;
  color: var(--muted); text-decoration: none; border: 1px solid transparent;
}
nav a:hover { color: var(--text); background: var(--panel); }
nav a.active { color: var(--text); background: var(--panel); border-color: var(--line); box-shadow: inset 3px 0 0 var(--accent); }
.ico { width: 18px; text-align: center; color: var(--accent); }

.conn { margin-top: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; background: var(--panel); font-size: 12px; }
.conn-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.conn-val { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(8px); }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: .02em; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.env-badge { font: 600 10px var(--mono); letter-spacing: .12em; color: var(--warn); border: 1px solid currentColor; border-radius: 6px; padding: 3px 7px; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; }
.icon-btn:hover { border-color: var(--accent); }
.menu { display: none; }
#view { flex: 1; overflow-y: auto; padding: 24px; outline: none; }

/* building blocks */
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
#view { overflow-x: hidden; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.stat-val { font: 600 28px/1.1 var(--mono); }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bar { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-top: 10px; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.bar.hot > i { background: linear-gradient(90deg, var(--warn), var(--err)); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 16px; }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121a; font-weight: 600; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.input, select.input, textarea.input { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
label.field { display: block; }
label.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }

.pill { display: inline-block; font: 600 11px var(--mono); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.pill.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 50%, transparent); }
.pill.acc { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }

.notice { border: 1px dashed var(--line); border-radius: var(--radius); padding: 16px; color: var(--muted); background: var(--panel); }
.notice strong { color: var(--text); }
.notice.err { border-color: color-mix(in srgb, var(--err) 50%, transparent); }
.notice code { font-family: var(--mono); color: var(--accent); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* chat */
.chat { display: grid; grid-template-rows: 1fr auto; height: calc(100vh - 63px - 48px); gap: 12px; }
.messages { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px; }
.msg { max-width: min(760px, 88%); padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: color-mix(in srgb, var(--accent) 12%, var(--panel)); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.msg.err { border-color: color-mix(in srgb, var(--err) 55%, transparent); color: var(--err); }
.msg-meta { font: 11px var(--mono); color: var(--muted); margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.composer textarea { resize: none; min-height: 46px; max-height: 180px; }
.counter { font: 11px var(--mono); color: var(--muted); text-align: right; }
.empty-chat { margin: auto; text-align: center; color: var(--muted); max-width: 440px; }
.empty-chat .core { margin: 0 auto 16px; width: 56px; height: 56px; }
.empty-chat .core::after { inset: 16px; }

/* sparkline */
.spark { width: 100%; height: 48px; margin-top: 8px; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.spark path.area { fill: var(--glow); stroke: none; }

.toast-host { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 14px; max-width: 360px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.toast.err { border-left-color: var(--err); }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(560px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .menu { display: inline-block; }
  #view { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .chat { height: calc(100vh - 59px - 32px); height: calc(100dvh - 59px - 32px); }
  .composer { grid-template-columns: 1fr; }
  .composer > div { min-width: 0; }
  .composer textarea { width: 100%; font-size: 16px; } /* 16px: verhindert das automatische Zoomen am iPhone */
  .composer .row { flex-wrap: wrap; }
  .composer .btn, #composer button[type=submit] { min-height: 44px; }
}
