/* =========================================================
   Messenger – Stage 1
   Mobile first, dunkles Farbschema
   ========================================================= */

:root {
  --bg:        #0d0f14;
  --bg-2:      #13161e;
  --panel:     #181c26;
  --panel-2:   #1f2430;
  --line:      #2a3040;
  --text:      #e6e8ee;
  --muted:     #8a92a6;
  --accent:    #7c5cff;
  --accent-2:  #9d85ff;
  --ok:        #3ccf91;
  --warn:      #ffb547;
  --danger:    #ff5c7a;
  --me:        #3a2f7a;
  --them:      #222836;
  --radius:    14px;
  --demo-h:    48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
code { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Buttons & Formulare ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--line); font-weight: 600;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: .9rem; }
.btn.danger { color: var(--danger); }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: .85rem; color: var(--muted); }
input[type=text], input[type=password], input[type=search], input[type=email], input[type=date], input[type=number], textarea, select {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--line); outline: none; color: var(--text);
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

.pill { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.pill.on  { background: rgba(60,207,145,.15); color: var(--ok); }
.pill.off { background: rgba(255,92,122,.15); color: var(--danger); }
.pill.warn{ background: rgba(255,181,71,.15); color: var(--warn); }

/* ---------- Anmeldung / Gast ---------- */
.auth-card {
  width: 100%; max-width: 400px; display: grid; gap: 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px;
}
.brand { text-align: center; display: grid; gap: 6px; justify-items: center; }
.logo { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--accent); color: #fff; }
.logo svg { width: 30px; height: 30px; }
.brand h1 { font-size: 1.5rem; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.guest-actions, .stack { display: grid; gap: 10px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.note { font-size: .85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.keybox {
  display: flex; align-items: center; gap: 8px; padding: 14px; border-radius: 12px;
  background: var(--bg-2); border: 1px dashed var(--accent);
}
.keybox code { flex: 1; word-break: break-all; color: var(--accent-2); font-size: .95rem; letter-spacing: .03em; }
.facts { list-style: none; display: grid; gap: 8px; font-size: .9rem; }
.facts li { padding-left: 14px; position: relative; }
.facts li::before { content: ""; position: absolute; left: 0; top: .6em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* ---------- Messenger ---------- */
.app { flex: 1; display: grid; grid-template-columns: 1fr; height: 100dvh; overflow: hidden; }
.sidebar, .chat { min-height: 0; display: flex; flex-direction: column; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); }
.chat { display: none; background: var(--bg); }
.app.open .sidebar { display: none; }
.app.open .chat { display: flex; }

.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 10px; }
.name { font-weight: 600; }
.sub { font-size: .8rem; color: var(--muted); }
.avatar {
  flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; font-size: .85rem; position: relative;
}
.avatar.is-admin { background: rgba(255,181,71,.15); color: var(--warn); border-color: rgba(255,181,71,.4); }
.avatar.guest { border-style: dashed; color: var(--muted); }
.avatar.online::after {
  content: ""; position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%;
  background: var(--ok); border: 2px solid var(--bg-2);
}

.search { padding: 10px 14px; }
.conv-list { list-style: none; flex: 1; overflow-y: auto; }
.conv {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; border-left: 3px solid transparent;
}
.conv:hover { background: var(--panel); }
.conv.active { background: var(--panel); border-left-color: var(--accent); }
.conv .info { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .top time { font-size: .75rem; color: var(--muted); flex: none; }
.conv .preview { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .badge { flex: none; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: #fff; font-size: .75rem; font-weight: 700; display: grid; place-items: center; }
.new-chat { margin: 12px 14px 16px; }

.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.chat-title { flex: 1; min-width: 0; }
.lock-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px;
  background: rgba(60,207,145,.12); color: var(--ok); font-size: .8rem; font-weight: 600;
}
.lock-badge svg { width: 16px; height: 16px; }

.server-hint { display: none; padding: 8px 14px; font-size: .8rem; background: rgba(255,181,71,.12); color: var(--warn); border-bottom: 1px solid var(--line); }
.chat.raw .server-hint { display: block; }

.messages { flex: 1; overflow-y: auto; padding: 18px 14px; display: flex; flex-direction: column; gap: 8px; }
.day { align-self: center; font-size: .75rem; color: var(--muted); background: var(--panel); padding: 3px 12px; border-radius: 999px; margin: 8px 0; }
.msg { max-width: 80%; padding: 9px 13px 6px; border-radius: 16px; background: var(--them); align-self: flex-start; border-bottom-left-radius: 4px; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--me); border-bottom-left-radius: 16px; border-bottom-right-radius: 4px; }
.msg .meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: .7rem; color: var(--muted); margin-top: 3px; }
.msg .meta svg { width: 14px; height: 14px; }
.msg .meta .read { color: var(--accent-2); }
.chat.raw .msg .txt { font-family: var(--mono); font-size: .75rem; color: var(--warn); word-break: break-all; }
.sys { align-self: center; max-width: 90%; text-align: center; font-size: .78rem; color: var(--muted); padding: 6px 12px; border: 1px dashed var(--line); border-radius: 10px; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg-2); }
.composer textarea { resize: none; max-height: 140px; border-radius: 22px; min-height: 44px; padding: 11px 16px; }
.send { flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; }
.send:hover { background: var(--accent-2); }

/* ---------- Modal & Toast ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
.modal.open { display: flex; }
.modal-card { width: 100%; max-width: 440px; max-height: calc(100dvh - 40px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 24px; display: grid; gap: 16px; }
.layers { list-style: none; display: grid; gap: 12px; }
.layers li { display: flex; gap: 12px; }
.layers .lv { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(124,92,255,.2); color: var(--accent-2); font-weight: 700; }
.layers p { font-size: .85rem; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 200;
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 12px;
  font-size: .9rem; opacity: 0; pointer-events: none; transition: .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Tablet / Desktop ---------- */
@media (min-width: 760px) {
  .app { grid-template-columns: 320px 1fr; }
  .app .sidebar, .app.open .sidebar { display: flex; }
  .chat, .app.open .chat { display: flex; }
  .chat-head .back { display: none; }

}
@media (min-width: 1100px) {
  .app { grid-template-columns: 360px 1fr; }
}

/* ---------- Gast → Konto (0.0.0.2) ---------- */
.hidden { display: none !important; }
.upgrade-banner {
  display: flex; align-items: center; gap: 12px; margin: 10px 14px 0; padding: 12px 14px;
  border-radius: var(--radius); background: rgba(124,92,255,.14); border: 1px solid rgba(124,92,255,.45);
}
.upgrade-banner > div { flex: 1; min-width: 0; }
.upgrade-banner p { font-size: .8rem; color: var(--muted); }
.form label.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: .9rem; cursor: pointer; }
.form label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-error { color: var(--danger); font-size: .85rem; min-height: 1em; }
.form-error:empty { display: none; }
.steps { list-style: none; display: grid; gap: 10px; }
.steps li { display: flex; align-items: center; gap: 12px; font-size: .9rem; color: var(--muted); }
.steps li::before {
  content: ""; flex: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line); box-sizing: border-box;
}
.steps li.run { color: var(--text); }
.steps li.run::before { border-color: var(--accent); border-top-color: transparent; animation: spin .8s linear infinite; }
.steps li.done { color: var(--text); }
.steps li.done::before { border: 0; background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E") center/14px no-repeat; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   Stage 1
   ========================================================= */
.hidden { display: none !important; }
.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; }
.screen.center { align-items: center; justify-content: center; padding: 20px; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs { display: flex; gap: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tabs button { flex: 1; padding: 8px 6px; border-radius: 9px; color: var(--muted); font-size: .88rem; font-weight: 600; }
.tabs button.active { background: var(--panel-2); color: var(--text); }
.tabpane { display: none; }
.tabpane.active { display: grid; }
.auth-msg { padding: 10px 12px; border-radius: 10px; font-size: .9rem; background: var(--panel-2); }
.auth-msg.ok { background: rgba(60,207,145,.12); color: var(--ok); }
.auth-msg.err { background: rgba(255,92,122,.12); color: var(--danger); }
.form-error { color: var(--danger); font-size: .88rem; }
.form-error:empty { display: none; }
.activate-more { display: grid; gap: 14px; }
.check { display: flex; align-items: center; gap: 10px; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.version { text-align: center; font-size: .75rem; color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:disabled:hover { border-color: var(--line); }
input[readonly] { opacity: .7; }

.me-text { min-width: 0; }
.me-text .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-head .me { flex: 1; min-width: 0; }
.offline { padding: 8px 14px; font-size: .8rem; background: rgba(255,181,71,.12); color: var(--warn); }
.conv-empty { padding: 24px 14px; text-align: center; color: var(--muted); font-size: .9rem; }
.tag { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 6px; background: var(--panel-2); color: var(--muted); margin-left: 4px; vertical-align: 1px; }
.chat-empty { flex: 1; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); text-align: center; padding: 20px; }
.chat-empty svg { width: 40px; height: 40px; color: var(--ok); }
.key-warn { padding: 8px 14px; font-size: .8rem; background: rgba(255,92,122,.12); color: var(--danger); border-bottom: 1px solid var(--line); }
.msg .txt { white-space: normal; overflow-wrap: anywhere; }
.msg .tick { display: inline-flex; }
.msg .tick.read { color: var(--accent-2); }
.composer textarea { line-height: 1.4; }
.modal-card .form { gap: 12px; }
.keybox code { user-select: all; }

@media (max-width: 759px) {
  .app .chat { display: none; }
  .app.open .sidebar { display: none; }
  .app.open .chat { display: flex; }
}

/* =========================================================
   Adminbereich
   ========================================================= */
.admin { flex: 1; display: flex; flex-direction: column; height: 100%; }
.admin-nav { display: flex; gap: 4px; padding: 10px; overflow-x: auto; background: var(--bg-2); border-bottom: 1px solid var(--line); flex: none; }
.admin-brand { display: none; }
.admin-nav button { flex: none; padding: 8px 14px; border-radius: 10px; color: var(--muted); white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.admin-nav button.active, .admin-nav button:hover { background: var(--panel-2); color: var(--text); }
.count { background: var(--accent); color: #fff; font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.admin-body { flex: 1; overflow-y: auto; padding: 20px 16px 40px; }
.tab { display: none; max-width: 900px; }
.tab.active { display: grid; gap: 16px; align-content: start; }
.tab h2 { font-size: 1.3rem; }
.tab h3 { font-size: 1rem; margin-top: 8px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 2px; }
.stat .num { font-size: 1.7rem; font-weight: 700; }
.stat .lbl { font-size: .8rem; color: var(--muted); }

.log { list-style: none; display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.log li { background: var(--panel); padding: 10px 14px; font-size: .9rem; display: flex; gap: 12px; }
.log time { color: var(--muted); min-width: 56px; flex: none; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 520px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg-2); }
tbody tr:last-child td { border-bottom: 0; }
td .actions { display: flex; gap: 6px; justify-content: flex-end; }
td.cipher { font-family: var(--mono); font-size: .75rem; color: var(--warn); word-break: break-all; }

.inbox { display: grid; gap: 12px; }
.mail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; }
.mail header { display: flex; justify-content: space-between; gap: 10px; }
.mail time { font-size: .8rem; color: var(--muted); }
.mail .sent { font-size: .85rem; color: var(--ok); }
.reply { display: flex; gap: 8px; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.setting select { width: auto; min-height: 40px; }
.switch { position: relative; width: 50px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: var(--muted); transition: .2s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::before { transform: translateX(22px); background: #fff; }


.admin-page .admin { min-height: 100dvh; }
.admin-nav a { flex: none; padding: 8px 14px; border-radius: 10px; color: var(--muted); white-space: nowrap; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.admin-nav a.active, .admin-nav a:hover { background: var(--panel-2); color: var(--text); }
.admin-nav .back-link { color: var(--accent-2); }
.admin-page .admin { height: auto; }
.admin-page .admin-body { display: block; overflow: visible; max-width: 1000px; }
.admin-page .admin-body > * + * { margin-top: 16px; }
.admin-body h2 { font-size: 1.3rem; }
.admin-body h3 { font-size: 1rem; margin-top: 8px; }
.flash { padding: 12px 14px; border-radius: var(--radius); background: rgba(60,207,145,.12); color: var(--ok); border: 1px solid rgba(60,207,145,.3); display: grid; gap: 8px; }
.flash.err { background: rgba(255,92,122,.12); color: var(--danger); border-color: rgba(255,92,122,.3); }
.code-show { display: grid; gap: 6px; color: var(--text); }
.code-show code { font-size: 1.4rem; letter-spacing: .08em; color: var(--accent-2); background: var(--bg-2); padding: 10px 14px; border-radius: 10px; border: 1px dashed var(--accent); justify-self: start; user-select: all; }
.report, .plain { padding-left: 20px; display: grid; gap: 4px; font-size: .9rem; }
.report { color: var(--text); }
.status-row { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; font-size: .9rem; }
.checks { list-style: none; display: grid; gap: 8px; font-size: .9rem; }
.log li { word-break: break-word; }
.log.mono li { font-family: var(--mono); font-size: .78rem; }
.actions-row td { padding-top: 0; background: var(--bg); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
form.inline { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
form.inline input[type=text] { min-height: 38px; padding: 6px 12px; width: 280px; max-width: 100%; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.form-grid label { display: grid; gap: 6px; font-size: .85rem; color: var(--muted); }
.settings { display: grid; gap: 10px; }
.settings .setting input[type=text], .settings .setting input[type=email], .settings .setting select { width: 260px; max-width: 100%; }
.setting.prepared { opacity: .75; }
.switch input:disabled + span { cursor: not-allowed; opacity: .6; }
pre.code { font-family: var(--mono); font-size: .8rem; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; user-select: all; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
a.btn { text-decoration: none; }
@media (max-width: 759px) {
  .setting { flex-direction: column; align-items: stretch; }
}
@media (min-width: 760px) {
  .admin { flex-direction: row; }
  .admin-nav { flex-direction: column; width: 230px; padding: 16px 10px; border-bottom: 0; border-right: 1px solid var(--line); overflow: visible; position: sticky; top: 0; height: 100dvh; }
  .admin-brand { display: block; font-weight: 700; padding: 4px 14px 14px; color: var(--warn); }
  .admin-nav .back-link { margin-top: auto; }
  .admin-body { padding: 28px 32px 40px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
}
