/* Admin-Konsole — neutrales Plattform-Design. CSP-strikt: keine Inline-Styles,
   alles ueber Klassen; dynamische Werte via CSSOM im JS. Light + Dark. */

:root, :root[data-theme="light"] {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef1f6;
  --fill: rgba(20,28,46,.05); --fill-2: rgba(20,28,46,.09);
  --border: rgba(20,28,46,.12); --border-strong: rgba(20,28,46,.22);
  --text: #131a2b; --muted: #5a6478;
  --accent: #3651d4; --accent-hover: #2c44bd; --accent-text: #fff; --accent-soft: rgba(54,81,212,.10);
  --ok: #1f8f5f; --ok-soft: rgba(31,143,95,.12);
  --warn: #9a6a10; --warn-soft: rgba(154,106,16,.12);
  --danger: #c0392b; --danger-soft: rgba(192,57,43,.10);
  --radius: 14px; --radius-s: 9px; --pill: 999px;
  --shadow-s: 0 1px 2px rgba(20,28,46,.05), 0 4px 12px -8px rgba(20,28,46,.18);
  --shadow: 0 10px 30px -18px rgba(20,28,46,.28);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg:#0c1018; --surface:#141a26; --surface-2:#1b2331;
  --fill:rgba(255,255,255,.06); --fill-2:rgba(255,255,255,.11);
  --border:rgba(255,255,255,.13); --border-strong:rgba(255,255,255,.24);
  --text:#e7ecf4; --muted:#9aa6bd;
  --accent:#7d90f0; --accent-hover:#93a3f4; --accent-text:#0b1020; --accent-soft:rgba(125,144,240,.16);
  --ok:#5cc294; --ok-soft:rgba(92,194,148,.16); --warn:#d8ab5c; --warn-soft:rgba(216,171,92,.16);
  --danger:#e07a6c; --danger-soft:rgba(224,122,108,.16);
  --shadow-s:0 1px 2px rgba(0,0,0,.5),0 4px 12px -8px rgba(0,0,0,.6); --shadow:0 14px 34px -18px rgba(0,0,0,.7);
}}
:root[data-theme="dark"] {
  --bg:#0c1018; --surface:#141a26; --surface-2:#1b2331;
  --fill:rgba(255,255,255,.06); --fill-2:rgba(255,255,255,.11);
  --border:rgba(255,255,255,.13); --border-strong:rgba(255,255,255,.24);
  --text:#e7ecf4; --muted:#9aa6bd;
  --accent:#7d90f0; --accent-hover:#93a3f4; --accent-text:#0b1020; --accent-soft:rgba(125,144,240,.16);
  --ok:#5cc294; --ok-soft:rgba(92,194,148,.16); --warn:#d8ab5c; --warn-soft:rgba(216,171,92,.16);
  --danger:#e07a6c; --danger-soft:rgba(224,122,108,.16);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.55; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1,h2,h3,p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-s); }
:focus:not(:focus-visible) { outline: none; }
.hidden { display: none !important; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 12px 22px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand .dot { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: var(--accent-text); font-size: 13px; }
.spacer { flex: 1; }
.tabs { display: flex; gap: 4px; }
.tab { background: none; border: 0; padding: 7px 13px; border-radius: var(--pill); color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer; }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.tab:hover:not(.active) { background: var(--fill); color: var(--text); }
.main { max-width: 960px; margin: 0 auto; padding: 24px 22px 80px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.page-sub { color: var(--muted); font-size: 14px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 16px; min-height: 40px; border: 1px solid transparent; border-radius: var(--pill); background: var(--fill); font-size: 14px; font-weight: 600; cursor: pointer; transition: background .16s, border-color .16s, opacity .16s; text-decoration: none; color: inherit; }
.btn:hover:not(:disabled) { background: var(--fill-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--fill); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn .ico { display: inline-flex; }
.btn .ico svg { width: 16px; height: 16px; display: block; }

/* Fields */
.field { margin-bottom: 14px; }
.label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.input { width: 100%; padding: 10px 13px; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: var(--surface); transition: border-color .16s, box-shadow .16s; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row-inline { display: flex; gap: 8px; align-items: center; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-s); }
.card.pad { padding: 20px; }
.stack > * + * { margin-top: 12px; }

/* Instanz-Liste */
.inst-list { display: grid; gap: 12px; }
.inst { display: flex; align-items: center; gap: 14px; padding: 16px 18px; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: border-color .16s, background .16s; color: inherit; }
.inst:hover { border-color: var(--border-strong); background: var(--surface-2); }
.inst-mark { width: 42px; height: 42px; flex: none; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; }
.inst-main { flex: 1; min-width: 0; }
.inst-name { font-weight: 700; font-size: 15.5px; }
.inst-meta { color: var(--muted); font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inst-side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex: none; }

/* Badges / Status */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: var(--pill); font-size: 12px; font-weight: 700; background: var(--fill); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge .d { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* Feature-Switches */
.feat-grid { display: grid; grid-template-columns: 1fr; gap: 2px; }
.feat { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.feat:last-child { border-bottom: 0; }
.feat-main { flex: 1; min-width: 0; }
.feat-label { font-weight: 600; font-size: 14.5px; }
.feat-desc { color: var(--muted); font-size: 12.5px; }
.switch { flex: none; width: 46px; height: 27px; border-radius: var(--pill); border: 0; background: var(--fill-2); position: relative; cursor: pointer; transition: background .16s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .16s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(19px); }

/* Detail-Bloecke */
.block { border-top: 1px solid var(--border); padding-top: 18px; margin-top: 18px; }
.block-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 12px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 14px; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; }
.mono { font-family: var(--mono); font-size: 13px; word-break: break-all; }

/* Secret (Token einmalig) */
.secret { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-s); padding: 11px 13px; }
.secret .v { flex: 1; min-width: 0; }

/* Tabelle (Protokoll) */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table-wrap { overflow-x: auto; }

/* Empty / Loading */
.state { padding: 48px 20px; text-align: center; color: var(--muted); }
.state-title { font-weight: 700; color: var(--text); margin-bottom: 5px; }
.spinner { width: 22px; height: 22px; margin: 0 auto 12px; border: 2.5px solid var(--fill-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth .card { width: 100%; max-width: 400px; }
.auth-head { text-align: center; margin-bottom: 18px; }
.auth-title { font-size: 19px; font-weight: 700; }
.auth-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.alert { padding: 10px 13px; border-radius: var(--radius-s); font-size: 14px; margin-bottom: 12px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }

/* Dialog */
.dialog { border: 0; padding: 0; border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow); width: min(440px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(8,12,22,.5); }
.dialog .pad { padding: 22px; }
.dialog-title { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.dialog-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 18px; }

/* Toast */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 22px; z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 17px; border-radius: var(--pill); font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 560px) { .main { padding: 18px 16px 80px; } .inst-meta { max-width: 46vw; } }
