/* Companion UI – dunkel, warm, elegant */
:root {
  --bg: #0b0e14;
  --bg2: #10141d;
  --panel: #141926;
  --panel2: #1a2032;
  --line: #232b40;
  --text: #e8ecf4;
  --muted: #8b93a7;
  --accent: #7c5cff;
  --accent2: #ff6ec7;
  --accent-soft: rgba(124, 92, 255, .14);
  --ok: #4ade80;
  --danger: #f87171;
  --radius: 16px;
  --bubble-user: linear-gradient(135deg, #5b3df5, #7c5cff);
  --bubble-bot: #1a2032;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background:
    radial-gradient(1200px 600px at 85% -10%, rgba(124,92,255,.16), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(255,110,199,.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: rgba(16, 20, 29, .82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.orb {
  width: 42px; height: 42px; border-radius: 50%;
  background: conic-gradient(from 210deg, #7c5cff, #ff6ec7, #ffc46e, #7c5cff);
  filter: saturate(1.1);
  position: relative; flex: none;
  box-shadow: 0 0 22px rgba(124,92,255,.45);
}
.orb::after {
  content: ""; position: absolute; inset: 4px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.55), rgba(255,255,255,0) 45%);
}
.orb.aura::before {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  background: conic-gradient(from 30deg, #7c5cff, #ff6ec7, #ffc46e, #7c5cff);
  filter: blur(14px); opacity: .5; z-index: -1;
  animation: aura 6s linear infinite;
}
@keyframes aura { to { transform: rotate(360deg); } }
.brand-name { font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }
.mood-chip {
  font-size: .78rem; color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); padding: 2px 9px; border-radius: 999px;
  display: inline-flex; gap: 6px; align-items: center; margin-top: 3px;
}
.tabs { display: flex; gap: 6px; background: var(--panel); border: 1px solid var(--line); padding: 4px; border-radius: 12px; }
.tab {
  border: none; background: transparent; color: var(--muted); font: inherit;
  padding: 7px 18px; border-radius: 9px; cursor: pointer; transition: all .18s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 0 0 0 1px rgba(124,92,255,.35); }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.model-badge {
  font-size: .75rem; color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; max-width: 260px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 15px;
  transition: all .18s;
}
.icon-btn:hover { border-color: var(--accent); box-shadow: 0 0 12px rgba(124,92,255,.25); }

/* ---------- Views ---------- */
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; }

/* ---------- Chat ---------- */
.chat-scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.chat-inner { max-width: 860px; margin: 0 auto; padding: 24px 20px 12px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 88%; animation: rise .22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; margin-top: 2px;
  background: conic-gradient(from 210deg, #7c5cff, #ff6ec7, #ffc46e, #7c5cff);
  box-shadow: 0 0 14px rgba(124,92,255,.35);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.msg.user .avatar { background: var(--panel2); border: 1px solid var(--line); box-shadow: none; }
.bubble {
  padding: 11px 15px; border-radius: 18px; line-height: 1.55; white-space: pre-wrap;
  word-break: break-word; position: relative;
}
.msg.bot .bubble { background: var(--bubble-bot); border: 1px solid var(--line); border-top-left-radius: 6px; }
.msg.user .bubble { background: var(--bubble-user); border-top-right-radius: 6px; color: #fff; }
.msg .meta {
  font-size: .68rem; color: var(--muted); margin-top: 5px; text-align: right;
}
.msg.bot .meta { text-align: left; }
.thought {
  font-size: .8rem; color: var(--muted); font-style: italic;
  border-left: 2px solid var(--accent); padding: 2px 0 2px 10px; margin-bottom: 7px;
  opacity: .85; white-space: pre-wrap;
}
.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .4; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; transform: scale(.9);} 40% { opacity: 1; transform: scale(1.1);} }

.composer-wrap { padding: 10px 20px calc(14px + env(safe-area-inset-bottom)); }
.composer {
  max-width: 860px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 10px 12px; transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 18px rgba(124,92,255,.18); }
.composer textarea {
  flex: 1; background: transparent; border: none; outline: none; resize: none;
  color: var(--text); font: inherit; line-height: 1.5; max-height: 180px;
}
.send-btn {
  width: 42px; height: 42px; border-radius: 14px; border: none; cursor: pointer;
  background: linear-gradient(135deg, #5b3df5, #7c5cff); color: #fff; font-size: 17px;
  transition: transform .15s, box-shadow .2s; flex: none;
}
.send-btn:hover { transform: scale(1.06); box-shadow: 0 0 16px rgba(124,92,255,.5); }
.send-btn:disabled { opacity: .4; cursor: default; transform: none; }
.composer-hint {
  max-width: 860px; margin: 6px auto 0; display: flex; align-items: center;
  font-size: .75rem; color: var(--muted);
}
.composer-hint .spacer { flex: 1; }
.conn { display: inline-flex; align-items: center; gap: 5px; }
.conn.ok { color: var(--ok); }
.conn.bad { color: var(--danger); }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: .75rem; }
.link-btn:hover { color: var(--danger); }

/* ---------- Panels (Gedächtnis / Einstellungen) ---------- */
.panel-scroll { flex: 1; overflow-y: auto; }
.panel-inner { max-width: 860px; margin: 0 auto; padding: 22px 20px 60px; display: flex; flex-direction: column; gap: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px;
}
.card h3 { margin: 0 0 6px; font-size: 1.02rem; }
.hint { color: var(--muted); font-size: .82rem; margin: 4px 0 12px; line-height: 1.5; }
.hint-inline { color: var(--muted); font-size: .8rem; font-weight: 400; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.two { grid-template-columns: 2fr 1fr; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; color: var(--muted); }
input[type=text], input[type=number], textarea, select {
  background: var(--bg2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font: inherit; outline: none; width: 100%;
  transition: border-color .2s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.5; }
.check { display: flex; flex-direction: row; align-items: center; gap: 9px; padding: 7px 0; font-size: .92rem; color: var(--text); cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.sliders { display: flex; flex-direction: column; gap: 4px; }
.slider-row { display: grid; grid-template-columns: 210px 1fr 52px; align-items: center; gap: 14px; padding: 6px 0; }
.slider-row.sub { grid-template-columns: 210px 120px; padding-top: 0; }
.slider-row label { font-size: .88rem; color: var(--text); }
.slider-row .val { font-size: .8rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 5px; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2)); outline: none; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: pointer;
  box-shadow: 0 0 10px rgba(124,92,255,.5);
}

.btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  border-radius: 10px; padding: 9px 16px; cursor: pointer; font: inherit; transition: all .18s;
}
.btn:hover { border-color: var(--accent); box-shadow: 0 0 12px rgba(124,92,255,.2); }
.btn.primary { background: linear-gradient(135deg, #5b3df5, #7c5cff); border: none; }
.btn.primary:hover { box-shadow: 0 0 16px rgba(124,92,255,.45); }
.btn.danger { color: var(--danger); border-color: rgba(248,113,113,.4); }
.btn.danger:hover { background: rgba(248,113,113,.12); }
.btn.big { padding: 12px 26px; font-size: 1rem; }
.row-end { display: flex; justify-content: flex-end; margin-top: 12px; }
.save-row { align-items: center; gap: 14px; position: relative; }
.toast { opacity: 0; color: var(--ok); transition: opacity .3s; font-size: .9rem; }
.toast.show { opacity: 1; }

.mem-add, .mem-search { display: flex; gap: 10px; margin-bottom: 10px; }
.mem-list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.mem-item {
  display: flex; align-items: flex-start; gap: 10px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: .88rem;
  line-height: 1.5;
}
.mem-item .txt { flex: 1; }
.mem-item .kind {
  font-size: .68rem; color: var(--accent2); border: 1px solid rgba(255,110,199,.35);
  padding: 1px 8px; border-radius: 999px; flex: none; margin-top: 1px;
}
.mem-item .del { background: none; border: none; color: var(--muted); cursor: pointer; flex: none; }
.mem-item .del:hover { color: var(--danger); }
.mem-item .score { font-size: .7rem; color: var(--muted); flex: none; }
.episodes .mem-item { border-left: 3px solid var(--accent); }
.thoughts .mem-item { border-left: 3px solid var(--accent2); font-style: italic; }
.empty { color: var(--muted); font-size: .85rem; text-align: center; padding: 18px 0; }

.prompt-preview summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.prompt-preview pre {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; font-size: .78rem; line-height: 1.55; white-space: pre-wrap;
  max-height: 420px; overflow-y: auto; color: #b9c2d8;
}

/* ---------- v2: Auth, Nutzer, Denkmodus ---------- */
.hidden { display: none !important; }
.auth-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(7, 9, 14, .82); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
}
.auth-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  padding: 34px 38px; width: min(92vw, 420px); text-align: center;
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
}
.auth-orb { width: 64px; height: 64px; margin: 0 auto 14px; }
.auth-card h2 { margin: 0 0 6px; }
.auth-users { display: flex; flex-direction: column; gap: 9px; margin: 16px 0; }
.auth-user-btn {
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  border-radius: 12px; padding: 12px; font: inherit; cursor: pointer; transition: all .18s;
}
.auth-user-btn:hover { border-color: var(--accent); box-shadow: 0 0 14px rgba(124,92,255,.25); }
.auth-card input { text-align: center; margin-bottom: 10px; }
#authTokenRow { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
body.nonadmin .admin-only { display: none; }
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .85rem; cursor: pointer;
}
.user-chip:hover { border-color: var(--accent); }
.brain-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg2); cursor: pointer; font-size: 17px; flex: none;
  transition: all .18s;
}
.brain-btn.on { border-color: rgba(124,92,255,.5); box-shadow: 0 0 10px rgba(124,92,255,.25); }
.chat-status {
  align-self: center; font-size: .78rem; color: var(--accent2);
  background: rgba(255,110,199,.08); border: 1px solid rgba(255,110,199,.25);
  padding: 4px 14px; border-radius: 999px; animation: rise .2s ease-out;
}
.user-list { display: flex; flex-direction: column; gap: 8px; }
.user-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
.user-item .u-name { font-size: .92rem; }
.admin-badge {
  font-size: .65rem; color: var(--accent); border: 1px solid rgba(124,92,255,.4);
  padding: 1px 7px; border-radius: 999px; margin-left: 6px;
}
.u-actions { display: flex; gap: 6px; }
.btn.mini { padding: 5px 9px; font-size: .8rem; }
.btn.mini.danger { color: var(--danger); border-color: rgba(248,113,113,.4); }
.token-reveal {
  margin-top: 12px; background: rgba(74, 222, 128, .07); border: 1px solid rgba(74,222,128,.35);
  border-radius: 10px; padding: 12px; font-size: .85rem; word-break: break-all;
}
.token-reveal code { display: block; margin-top: 6px; font-size: .95rem; color: var(--ok); }
.lan-info { margin-top: 10px; font-size: .85rem; color: var(--muted); }

/* ---------- Persönlichkeiten (Wizard + Verwaltung) ---------- */
.persona-wizard { max-width: 640px; max-height: 88vh; overflow-y: auto; }
.gender-filter { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 14px; }
.gender-btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--muted);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: .85rem;
}
.gender-btn.on { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tpl-item {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 12px;
  padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 6px;
  transition: border-color .15s, transform .15s;
}
.tpl-item:hover { border-color: var(--accent); transform: translateY(-2px); }
.tpl-item.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tpl-icon { font-size: 1.7rem; line-height: 1; }
.tpl-name { font-weight: 600; font-size: .92rem; }
.tpl-short { font-size: .78rem; color: var(--muted); flex: 1; }
.tpl-gender { font-size: .72rem; color: var(--accent2); }
.tpl-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.active-badge {
  font-size: .68rem; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 2px 8px; margin-left: 4px;
}
.persona-switcher {
  position: fixed; top: 58px; right: 14px; z-index: 90;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); padding: 8px; min-width: 230px;
  opacity: 0; transform: translateY(-6px); pointer-events: none; transition: opacity .15s, transform .15s;
}
.persona-switcher.open { opacity: 1; transform: translateY(0); pointer-events: auto; }
.ps-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 9px; cursor: pointer; font-size: .9rem;
}
.ps-item:hover { background: var(--panel2); }
.ps-item.active { background: var(--accent-soft); }
.ps-icon { font-size: 1.2rem; width: 24px; text-align: center; }
.ps-add { color: var(--accent); border-top: 1px solid var(--line); margin-top: 4px; padding-top: 11px; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand { min-width: 0; flex: 1; }
  .tabs { order: 3; width: 100%; justify-content: space-between; }
  .tab { flex: 1; padding: 7px 8px; text-align: center; }
  .msg { max-width: 94%; }
  .slider-row { grid-template-columns: 1fr 60px; }
  .slider-row input[type=range] { grid-column: 1 / -1; order: 3; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid.two { grid-template-columns: 1fr; }
  .model-badge { display: none; }
  .tpl-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}