:root {
  --bg: #05020b;
  --bg2: #0c0518;
  --panel: rgba(22, 9, 44, 0.72);
  --panel2: rgba(34, 14, 66, 0.55);
  --line: rgba(168, 85, 247, 0.3);
  --text: #f3edff;
  --muted: #a99ccb;
  --p1: #6d28d9;
  --p2: #a855f7;
  --p3: #d946ef;
  --ok: #34d399;
  --bad: #fb7185;
  --warn: #fbbf24;
  --glow: 0 0 22px rgba(168, 85, 247, 0.45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--p2); text-decoration: none; }
a:hover { color: #d8b4fe; }
[hidden] { display: none !important; }

/* ---------- Hintergrund mit Leuchteffekten ---------- */
.bgfx { position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: radial-gradient(1100px 650px at 85% -10%, rgba(109, 40, 217, .3), transparent 60%),
              radial-gradient(900px 600px at -10% 105%, rgba(192, 38, 211, .2), transparent 60%),
              linear-gradient(160deg, #05020b, #12062a 55%, #05020b); }
.bgfx::after { content: ""; position: absolute; inset: 0;
  background-image: linear-gradient(rgba(168, 85, 247, .07) 1px, transparent 1px), linear-gradient(90deg, rgba(168, 85, 247, .07) 1px, transparent 1px);
  background-size: 48px 48px; mask-image: radial-gradient(ellipse at center, #000 10%, transparent 72%); }
.bgfx i { position: absolute; border-radius: 50%; filter: blur(100px); opacity: .45; animation: drift 20s ease-in-out infinite; }
.bgfx i:nth-child(1) { width: 440px; height: 440px; background: #6d28d9; top: 6%; left: 8%; }
.bgfx i:nth-child(2) { width: 380px; height: 380px; background: #c026d3; top: 52%; right: 6%; animation-delay: -7s; }
.bgfx i:nth-child(3) { width: 320px; height: 320px; background: #4c1d95; bottom: -8%; left: 42%; animation-delay: -13s; }
@keyframes drift { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(40px, -34px); } }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 20px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(109, 40, 217, .16); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
  transition: transform .15s, box-shadow .2s, background .2s, opacity .2s; }
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--glow); color: #fff; }
.btn.primary { background: linear-gradient(135deg, var(--p1), var(--p3)); border-color: transparent; box-shadow: 0 0 24px rgba(168, 85, 247, .4); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(251, 113, 133, .5); color: #fecdd3; background: rgba(251, 113, 133, .1); }
.btn.danger:hover:not(:disabled) { box-shadow: 0 0 20px rgba(251, 113, 133, .45); }
.btn.small { padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; text-decoration: underline; padding: 6px; }
.link:hover { color: #fff; }

/* ---------- Login / Setup / Verify ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-card { width: min(420px, 100%); text-align: center; padding: 38px 32px 30px; border-radius: 22px;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(16px);
  box-shadow: 0 0 0 1px rgba(168, 85, 247, .08), 0 0 60px rgba(124, 58, 237, .28), 0 30px 80px rgba(0, 0, 0, .55);
  animation: cardglow 6s ease-in-out infinite; }
.auth-card.wide { width: min(560px, 100%); }
@keyframes cardglow { 50% { box-shadow: 0 0 0 1px rgba(217, 70, 239, .18), 0 0 84px rgba(168, 85, 247, .4), 0 30px 80px rgba(0, 0, 0, .55); } }
.logo { font-size: 2rem; font-weight: 900; letter-spacing: .16em; color: #fff; text-shadow: 0 0 24px rgba(168, 85, 247, .9), 0 0 56px rgba(124, 58, 237, .6); }
.logo span { color: var(--p2); }
.sub { margin: 6px 0 22px; color: var(--p2); letter-spacing: .24em; text-transform: uppercase; font-size: .78rem; font-weight: 600; }
.hint { color: var(--muted); font-size: .9rem; margin: 18px 0; }
.hint.left { text-align: left; margin-top: 0; }
.hint.small { font-size: .8rem; margin: 14px 0 6px; }
.back { display: inline-block; margin-top: 4px; color: var(--muted); font-size: .9rem; }
.btn.discord { width: 100%; padding: 14px 20px; font-size: 1.02rem; background: linear-gradient(135deg, #5865f2, #8b5cf6 60%, #c026d3); border-color: transparent; box-shadow: 0 0 30px rgba(139, 92, 246, .55); }
.alert { margin: 0 0 18px; padding: 11px 14px; border-radius: 12px; font-size: .9rem; text-align: left; color: #fecdd3; background: rgba(251, 113, 133, .12); border: 1px solid rgba(251, 113, 133, .4); }

.setup-steps { text-align: left; color: var(--muted); padding-left: 22px; margin: 0 0 20px; }
.setup-steps li { margin: 4px 0; }
.setup-steps b { color: #fff; }
.qr-wrap { display: flex; gap: 20px; align-items: center; justify-content: center; flex-wrap: wrap; margin-bottom: 22px; }
.qr { width: 240px; height: 240px; display: grid; place-items: center; background: #fff; border-radius: 16px; padding: 10px; box-shadow: 0 0 40px rgba(168, 85, 247, .55); }
.qr img { display: block; width: 100%; height: 100%; }
.qr .loading { color: #4c1d95; font-size: .85rem; }
.secret { text-align: left; max-width: 220px; }
.secret small { display: block; color: var(--muted); font-size: .75rem; }
.secret code { display: block; margin: 6px 0 10px; padding: 8px 10px; border-radius: 10px; background: rgba(0, 0, 0, .5); border: 1px solid var(--line);
  color: #e9d5ff; font: 600 .95rem ui-monospace, Menlo, Consolas, monospace; word-break: break-all; letter-spacing: .04em; }
#codeForm { display: grid; gap: 14px; }
.code-input { width: 100%; text-align: center; font: 700 2rem/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .3em; padding: 14px;
  border-radius: 14px; border: 1px solid var(--line); background: rgba(0, 0, 0, .5); color: #fff; }
.code-input::placeholder { color: rgba(169, 156, 203, .35); }
.code-input:focus, .field input:focus, .field textarea:focus, .inline-input:focus { outline: none; border-color: var(--p2); box-shadow: 0 0 0 3px rgba(168, 85, 247, .25), 0 0 24px rgba(168, 85, 247, .35); }

/* ---------- Panel-Layout ---------- */
body.panel { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 16px; gap: 20px;
  background: linear-gradient(180deg, rgba(20, 8, 40, .88), rgba(9, 3, 20, .92)); border-right: 1px solid var(--line); backdrop-filter: blur(14px);
  box-shadow: 6px 0 40px rgba(109, 40, 217, .15); }
.brand { font-size: 1.35rem; font-weight: 900; letter-spacing: .16em; color: #fff; text-shadow: 0 0 20px rgba(168, 85, 247, .9); padding: 4px 10px; }
.brand span { color: var(--p2); }
.brand small { display: block; margin-top: 2px; font-size: .62rem; letter-spacing: .3em; font-weight: 600; text-transform: uppercase; color: var(--muted); text-shadow: none; }
#nav { display: grid; gap: 6px; flex: 1; align-content: start; }
#nav button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid transparent; background: transparent;
  color: var(--muted); font: inherit; font-weight: 600; text-align: left; cursor: pointer; transition: .2s; }
#nav button .ic { width: 22px; text-align: center; color: var(--p2); }
#nav button:hover { color: #fff; background: rgba(109, 40, 217, .16); }
#nav button.active { color: #fff; border-color: var(--line); background: linear-gradient(90deg, rgba(109, 40, 217, .4), rgba(192, 38, 211, .12));
  box-shadow: inset 3px 0 0 var(--p2), 0 0 24px rgba(168, 85, 247, .25); text-shadow: 0 0 14px rgba(216, 180, 254, .8); }
.me { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 14px; background: var(--panel2); border: 1px solid var(--line); }
.me img { width: 38px; height: 38px; border-radius: 50%; box-shadow: 0 0 14px rgba(168, 85, 247, .7); }
.me .who { flex: 1; min-width: 0; line-height: 1.25; }
.me .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .who small { color: var(--p2); text-transform: uppercase; letter-spacing: .12em; font-size: .68rem; }
.me button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 6px; border-radius: 8px; }
.me button:hover { color: #fff; background: rgba(251, 113, 133, .2); }

.main { padding: 26px clamp(16px, 3vw, 40px) 80px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px; margin-bottom: 26px; }
.top h1 { margin: 0; font-size: 1.8rem; font-weight: 800; text-shadow: 0 0 26px rgba(168, 85, 247, .6); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
#save.dirty { animation: savepulse 1.6s ease-in-out infinite; }
@keyframes savepulse { 50% { box-shadow: 0 0 36px rgba(217, 70, 239, .8); } }

/* ---------- Karten, Felder ---------- */
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.card { min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px; backdrop-filter: blur(10px);
  box-shadow: 0 0 0 1px rgba(168, 85, 247, .05), 0 10px 40px rgba(0, 0, 0, .35); transition: border-color .25s, box-shadow .25s; }
.card:hover { border-color: rgba(192, 132, 252, .5); box-shadow: 0 0 30px rgba(168, 85, 247, .18), 0 10px 40px rgba(0, 0, 0, .35); }
.card > h2 { margin: 0 0 4px; font-size: 1.1rem; text-shadow: 0 0 16px rgba(168, 85, 247, .55); }
.card > .desc { margin: 0 0 16px; color: var(--muted); font-size: .9rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field .lbl { font-size: .8rem; font-weight: 600; color: #d8c8ff; letter-spacing: .04em; }
.field input, .field textarea, .inline-input { width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .42);
  color: var(--text); font: inherit; transition: .2s; }
.field textarea { resize: vertical; min-height: 70px; }
.field .hint { color: var(--muted); font-size: .78rem; }
.with-btn { display: flex; gap: 8px; align-items: stretch; }
.with-btn input { flex: 1; }

.list { display: grid; gap: 12px; }
.row { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: start; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel2); }
.row .num { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; color: #e9d5ff;
  border: 1px solid var(--line); background: rgba(109, 40, 217, .25); box-shadow: inset 0 0 14px rgba(168, 85, 247, .3); }
.row .fields { display: grid; gap: 10px; min-width: 0; }
.row .fields.two { grid-template-columns: 1fr 1fr; }
.row-actions { display: flex; flex-direction: column; gap: 6px; }
.icon { width: 32px; height: 32px; border-radius: 10px; border: 1px solid var(--line); background: rgba(109, 40, 217, .18); color: #fff; cursor: pointer; font: inherit; transition: .2s; }
.icon:hover:not(:disabled) { box-shadow: var(--glow); }
.icon:disabled { opacity: .3; cursor: not-allowed; }
.icon.danger { color: #fecdd3; border-color: rgba(251, 113, 133, .45); background: rgba(251, 113, 133, .1); }
.section-head { display: grid; grid-template-columns: 84px 1fr auto; gap: 12px; align-items: end; margin-bottom: 16px; }
.section-head .row-actions { flex-direction: row; }
.add { margin-top: 14px; }

/* ---------- Übersicht ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.stat { padding: 20px; border-radius: 18px; border: 1px solid var(--line); background: var(--panel); box-shadow: 0 0 30px rgba(124, 58, 237, .14); }
.stat small { color: var(--muted); text-transform: uppercase; letter-spacing: .14em; font-size: .7rem; font-weight: 600; }
.stat b { display: block; margin-top: 6px; font-size: 2rem; line-height: 1.1; color: #fff; text-shadow: 0 0 22px rgba(168, 85, 247, .85); }
.stat span { color: var(--muted); font-size: .8rem; }
.stat.on b { color: var(--ok); text-shadow: 0 0 22px rgba(52, 211, 153, .7); }
.stat.off b { color: var(--bad); text-shadow: 0 0 22px rgba(251, 113, 133, .6); }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; padding: 8px 12px; }
td { padding: 12px; border-top: 1px solid rgba(168, 85, 247, .16); vertical-align: middle; }
tr:hover td { background: rgba(109, 40, 217, .08); }
td code { font: .82rem ui-monospace, Menlo, Consolas, monospace; color: #e9d5ff; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  border: 1px solid var(--line); background: rgba(109, 40, 217, .2); color: #e9d5ff; }
.badge.owner { background: linear-gradient(135deg, rgba(109, 40, 217, .6), rgba(217, 70, 239, .4)); box-shadow: 0 0 14px rgba(217, 70, 239, .4); color: #fff; }
.badge.ok { color: var(--ok); border-color: rgba(52, 211, 153, .4); background: rgba(52, 211, 153, .1); }
.badge.warn { color: var(--warn); border-color: rgba(251, 191, 36, .4); background: rgba(251, 191, 36, .1); }
.cell-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 26px; }

/* ---------- Code / Listen ---------- */
.steps-list { margin: 0 0 16px; padding-left: 22px; color: var(--muted); }
.steps-list li { margin: 6px 0; }
.steps-list code, .card .desc code { font: .85rem ui-monospace, Menlo, Consolas, monospace; color: #e9d5ff; background: rgba(0, 0, 0, .4); padding: 1px 6px; border-radius: 6px; }
pre.code { margin: 0 0 14px; padding: 16px; overflow-x: auto; border-radius: 14px; border: 1px solid var(--line); background: rgba(0, 0, 0, .55);
  box-shadow: inset 0 0 24px rgba(109, 40, 217, .18); color: #e9d5ff; font: .85rem/1.6 ui-monospace, Menlo, Consolas, monospace; }

/* ---------- Owner-Panel: Zugriffsliste ---------- */
.access-row { display: grid; grid-template-columns: minmax(200px, 1.6fr) 130px minmax(160px, 1fr) auto; gap: 14px; align-items: center; padding: 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel2); transition: border-color .2s, box-shadow .2s; }
.access-row:hover { border-color: rgba(192, 132, 252, .5); }
.access-row.is-new { border-color: rgba(251, 191, 36, .55); box-shadow: 0 0 22px rgba(251, 191, 36, .15); }
.access-row .who { display: grid; gap: 6px; min-width: 0; }
.access-row .who input { width: 100%; padding: 8px 11px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, .42); color: var(--text); font: inherit; }
.access-row .who input:focus { outline: none; border-color: var(--p2); box-shadow: 0 0 0 3px rgba(168, 85, 247, .25); }
.access-row code { font: .82rem ui-monospace, Menlo, Consolas, monospace; color: #e9d5ff; word-break: break-all; }
.access-row select, .add-grid select { padding: 9px 11px; }
.block { display: block; margin-top: 4px; }
.add-grid { display: grid; grid-template-columns: 1.6fr 1.1fr 130px auto; gap: 10px; }
details.example summary { cursor: pointer; color: var(--p2); font-weight: 600; margin: 4px 0 12px; }
details.example summary:hover { color: #d8b4fe; }
select.inline-input { appearance: auto; }
select.inline-input:disabled { opacity: .55; }
@media (max-width: 960px) { .access-row, .add-grid { grid-template-columns: 1fr; } }

/* ---------- Toasts ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 50; }
.toast { padding: 12px 18px; border-radius: 14px; background: rgba(20, 8, 40, .95); border: 1px solid var(--line); box-shadow: 0 0 30px rgba(168, 85, 247, .45); animation: pop .25s ease; max-width: 360px; }
.toast.err { border-color: rgba(251, 113, 133, .6); box-shadow: 0 0 30px rgba(251, 113, 133, .4); color: #fecdd3; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Mobil ---------- */
.stat { min-width: 0; overflow-wrap: anywhere; }
.stats { grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); }
.qr { width: min(240px, 100%); height: auto; aspect-ratio: 1; }
.secret { width: 100%; }
.code-input { font-size: clamp(1.4rem, 8vw, 2rem); letter-spacing: .22em; }

@media (max-width: 860px) {
  /* minmax(0,1fr) verhindert, dass die Navigation die Spalte über die Bildschirmbreite aufbläht */
  body.panel { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; min-width: 0; padding: 14px 14px 10px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--line); box-shadow: 0 6px 30px rgba(109, 40, 217, .15); }
  .brand { padding: 0 4px; font-size: 1.15rem; }
  .brand small { display: none; }
  #nav { display: flex; flex: none; overflow-x: auto; gap: 6px; padding-bottom: 6px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
  #nav button { width: auto; flex: none; white-space: nowrap; padding: 10px 14px; }
  .me { padding: 8px 10px; }
  .main { padding: 18px 14px calc(104px + env(safe-area-inset-bottom)); }
  .top { margin-bottom: 18px; }
  .top h1 { font-size: 1.45rem; }

  /* Speichern-Button als feste Leiste unten – immer in Reichweite des Daumens */
  .actions { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 40; }
  .actions .btn.ghost { display: none; }
  #save { width: 100%; padding: 15px; font-size: 1rem; box-shadow: 0 0 30px rgba(168, 85, 247, .55), 0 8px 30px rgba(0, 0, 0, .6); }
  #save:disabled { background: rgba(30, 14, 58, .96); border: 1px solid var(--line); }

  .card { padding: 16px; border-radius: 16px; }
  .row { grid-template-columns: 1fr; }
  .row-actions { flex-direction: row; }
  .row .fields.two, .section-head { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 14px; }
  .stat b { font-size: 1.6rem; }

  /* 16px verhindert das automatische Hineinzoomen von iOS beim Antippen von Feldern */
  input, select, textarea, .field input, .field textarea, .inline-input, .code-input { font-size: 16px; }
  .code-input { font-size: clamp(1.4rem, 8vw, 2rem); }
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; }
  .icon { width: 42px; height: 42px; }
  .cell-actions .btn { flex: 1 1 auto; }

  #toasts { left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  /* schont Akku und Performance auf dem Handy */
  .bgfx i { filter: blur(60px); animation: none; opacity: .4; }
}
@media (max-width: 480px) {
  body.auth { padding: 14px; }
  .auth-card { padding: 28px 20px 22px; border-radius: 18px; }
  .logo { font-size: 1.6rem; }
  .qr-wrap { gap: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
