:root {
  --bg: #0e0e10;
  --bg-alt: #18181b;
  --card: #1f1f23;
  --border: #2d2d33;
  --text: #efeff1;
  --text-dim: #adadb8;
  --purple: #9147ff;
  --purple-dark: #772ce8;
  --green: #00c78c;
  --red: #eb4a4a;
  --yellow: #f0b90b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at top, #17171b, var(--bg) 60%);
  color: var(--text);
  font-family: "Inter", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(24, 24, 27, 0.8);
  position: sticky;
  top: 0;
  backdrop-filter: blur(6px);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 600; }
.dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--purple);
  box-shadow: 0 0 10px var(--purple);
}

.status-pill {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.status-pill.online { color: var(--green); border-color: var(--green); }
.status-pill.offline { color: var(--red); border-color: var(--red); }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-badge { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.user-badge .role-tag {
  font-weight: 700; padding: 2px 8px; border-radius: 6px;
  background: rgba(145, 71, 255, 0.15); color: var(--purple);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.card h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 14px 0;
}

.current-card { grid-column: span 2; min-height: 120px; }
@media (max-width: 700px) { .current-card { grid-column: span 1; } }

.empty { color: var(--text-dim); font-size: 14px; padding: 10px 0; }
.hidden { display: none !important; }

.current-box {
  background: var(--bg-alt);
  border-radius: 10px;
  padding: 14px 16px;
  border-left: 4px solid var(--purple);
}
.user-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.username { font-weight: 700; color: var(--purple); }
.time { font-size: 12px; color: var(--text-dim); }
.message { margin: 0; font-size: 16px; line-height: 1.4; }
.voice-tag {
  display: inline-block; margin-top: 8px; font-size: 11px;
  background: rgba(145, 71, 255, 0.15); color: var(--purple);
  padding: 2px 8px; border-radius: 6px;
}

.controls-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.btn {
  border: none; border-radius: 8px; padding: 10px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s ease;
  color: var(--text);
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--purple); }
.btn-secondary { background: var(--bg-alt); border: 1px solid var(--border); }
.btn-danger { background: var(--red); }
.btn-toggle { background: var(--green); color: #06231a; }
.btn-toggle.off { background: var(--red); color: white; }

.volume-row { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
input[type="range"] { width: 100%; accent-color: var(--purple); }

.queue-card { grid-column: span 2; }
@media (max-width: 700px) { .queue-card { grid-column: span 1; } }

.queue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.queue-list li {
  background: var(--bg-alt); border-radius: 8px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
  border: 1px solid var(--border);
}
.queue-list .qi-top { display: flex; justify-content: space-between; font-size: 13px; }
.queue-list .qi-user { font-weight: 600; color: var(--purple); }
.queue-list .qi-time { color: var(--text-dim); font-size: 11px; }
.queue-list .qi-msg { font-size: 14px; color: var(--text); }
.queue-list .qi-pos {
  font-size: 11px; color: var(--text-dim);
}

.manage-row { display: flex; gap: 8px; margin-bottom: 12px; }
.manage-row input {
  flex: 1; background: var(--bg-alt); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 14px;
}

.tag-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; max-height: 200px; overflow-y: auto; }
.tag-list li {
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 12px;
  display: flex; align-items: center; gap: 6px;
}
.tag-list button {
  background: none; border: none; color: var(--red); cursor: pointer; font-size: 13px;
}

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.login-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; width: 280px; text-align: center;
}
.login-box input {
  width: 100%; margin: 12px 0; padding: 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-alt); color: var(--text);
}
.login-box button {
  width: 100%; padding: 10px; border-radius: 8px; border: none;
  background: var(--purple); color: white; font-weight: 600; cursor: pointer;
}
.error { color: var(--red); font-size: 12px; }

.btn-twitch {
  display: block; text-align: center; text-decoration: none;
  background: var(--purple); color: white; padding: 12px; border-radius: 8px;
  font-weight: 700; margin: 14px 0 6px; font-size: 15px;
}
.btn-twitch:hover { background: var(--purple-dark); }
/* Hoehere Spezifitaet als ".login-box button" fuer Faelle, in denen ein
   unauffaelliger Text-Knopf (z.B. Abmelden, Berechtigung zuruecksetzen)
   neben einem grossen, auffaelligen Button steht. */
.login-box button.link-btn-plain,
button.link-btn-plain {
  width: auto; background: none; border: none; color: var(--text-dim);
  font-size: 12px; font-weight: 400; text-decoration: underline;
  cursor: pointer; padding: 4px; margin-top: 8px;
}
.link-btn-plain:hover { color: var(--text); }
#backup-box { margin-top: 8px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 8px; padding: 12px 24px 0;
  max-width: 1200px; margin: 0 auto;
}
.tab-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 14px; font-weight: 600; padding: 10px 16px;
  cursor: pointer; border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--purple); border-bottom-color: var(--purple); }
.tab-panel.hidden { display: none !important; }

/* ---------- Banner ---------- */
.banner {
  max-width: 1200px; margin: 16px auto 0; padding: 12px 20px;
  background: rgba(240, 185, 11, 0.12); border: 1px solid var(--yellow);
  border-radius: 10px; color: var(--yellow); font-size: 14px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.link-btn {
  background: none; border: 1px solid var(--yellow); color: var(--yellow);
  border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 13px; font-weight: 600;
}

/* ---------- Settings forms ---------- */
.grid-settings { align-items: start; }
.span-2 { grid-column: span 2; }
@media (max-width: 700px) { .span-2 { grid-column: span 1; } }

.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.card-head h2 { margin: 0; }

.device-code-box {
  background: var(--bg-alt); border: 1px solid var(--purple);
  border-radius: 10px; padding: 16px 18px; margin: 4px 0 14px;
}
.device-code-box p { margin: 0 0 8px; font-size: 13px; color: var(--text-dim); }
.device-code-link {
  display: inline-block; color: var(--purple); font-weight: 600;
  font-size: 15px; margin-bottom: 12px; word-break: break-all;
}
.device-code-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.device-code-value {
  font-family: "SFMono-Regular", Consolas, monospace; font-size: 24px; font-weight: 700;
  letter-spacing: 0.08em; color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 16px;
}
.redirect-uri-value {
  font-size: 13px; font-weight: 400; letter-spacing: normal;
  word-break: break-all; flex: 1; min-width: 0;
}

.inline-warning {
  background: rgba(240, 185, 11, 0.12); border: 1px solid var(--yellow);
  border-radius: 8px; padding: 10px 14px; color: var(--yellow);
  font-size: 12px; line-height: 1.6; margin: 0 0 14px;
}
.inline-warning a, .inline-warning button.link-btn-plain {
  color: var(--yellow); text-decoration: underline; font-weight: 600;
}

.obs-help {
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; margin-top: 10px;
  font-size: 12px; color: var(--text-dim); line-height: 1.6;
}
.obs-help summary {
  cursor: pointer; font-weight: 600; color: var(--text);
  list-style: none;
}
.obs-help summary::-webkit-details-marker { display: none; }
.obs-help summary::before { content: "▸ "; color: var(--purple); }
.obs-help[open] summary::before { content: "▾ "; }
.obs-help ol { margin: 10px 0 0; padding-left: 20px; }
.obs-help li { margin-bottom: 6px; }
.obs-help li:last-child { margin-bottom: 0; }
.obs-help b { color: var(--text); }

.hint { color: var(--text-dim); font-size: 12px; line-height: 1.5; margin: 6px 0 14px; }
.hint code {
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px;
}

.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px; margin-bottom: 14px;
}
.form-grid label, .block-label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--text-dim); font-weight: 600;
}
.form-grid input[type="text"],
.form-grid input[type="password"],
.form-grid input[type="number"],
.form-grid select {
  background: var(--bg-alt); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 14px; font-weight: 400;
  font-family: inherit;
}
.form-grid input:read-only { opacity: 0.6; cursor: not-allowed; }
.tag-auto {
  font-size: 10px; text-transform: none; font-weight: 600;
  color: var(--green); background: rgba(0, 199, 140, 0.12);
  padding: 1px 6px; border-radius: 5px; margin-left: 6px;
}
.tag-restart {
  font-size: 10px; text-transform: none; font-weight: 600;
  color: var(--yellow); background: rgba(240, 185, 11, 0.12);
  padding: 1px 6px; border-radius: 5px; margin-left: 6px;
}

.divider { height: 1px; background: var(--border); margin: 18px 0; }
.card h3 { font-size: 13px; color: var(--text-dim); margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.04em; }

.toggle-row { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 16px; }
.switch-label {
  display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer;
}
.switch-label input { accent-color: var(--purple); width: 16px; height: 16px; }

.checkbox-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px; margin-bottom: 14px;
}
.checkbox-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }

#permissions-target {
  background: var(--bg-alt); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 14px; font-weight: 400;
  font-family: inherit; margin-top: 4px; max-width: 100%;
}

.permissions-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.permission-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-size: 13px; gap: 12px;
}
.permission-item input { accent-color: var(--purple); width: 18px; height: 18px; flex-shrink: 0; }
.permission-item span:first-child { flex: 1; }
.permission-item button.link-btn-plain { margin-top: 0; white-space: nowrap; }

.permission-group-head {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  margin: 12px 0 -2px; padding: 0 2px; font-size: 12px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em;
}
.permission-group-head button.link-btn-plain { margin-top: 0; white-space: nowrap; }

.tag-override {
  font-size: 10px; text-transform: none; font-weight: 600;
  color: var(--yellow); background: rgba(240, 185, 11, 0.12);
  padding: 1px 6px; border-radius: 5px; white-space: nowrap;
}
.checkbox-item input { accent-color: var(--purple); }
#voice-pool-wrap.hidden { display: none; }

.conn-badge {
  font-size: 12px; padding: 5px 12px; border-radius: 999px;
  background: var(--bg-alt); border: 1px solid var(--border); color: var(--text-dim);
  white-space: nowrap;
}
.conn-badge.online { color: var(--green); border-color: var(--green); background: rgba(0,199,140,0.1); }
.conn-badge.offline { color: var(--red); border-color: var(--red); background: rgba(235,74,74,0.1); }
.conn-badge.connecting { color: var(--yellow); border-color: var(--yellow); background: rgba(240,185,11,0.1); }

#advanced-wrap { margin-top: 14px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 10px; font-size: 13px; max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
