:root { --bg:#0b0b0c; --panel:#121214; --muted:#888; --accent:#d5ad39; }
*{box-sizing:border-box} html,body{height:100%} body{margin:0;background:var(--bg);color:#eee;font:14px/1.4 system-ui,Segoe UI,Roboto,Arial}
.hidden{display:none!important}
.muted{color:var(--muted)}

.topbar{position:sticky;top:0;z-index:10;display:flex;align-items:center;gap:.75rem;padding:.5rem .75rem;background:linear-gradient(#191919,#0f0f10);border-bottom:1px solid #222}
.topbar .brand{display:flex;align-items:center;gap:.5rem;font-weight:600}
.ghost{background:#1b1b1e;border:1px solid #2b2b2e;color:#eee;border-radius:.6rem;padding:.4rem .7rem;cursor:pointer}
.ghost:hover{filter:brightness(1.1)}

.panel.centered{max-width:460px;margin:5vh auto;background:var(--panel);padding:1.25rem;border-radius:12px}
.formrow{display:grid;grid-template-columns:1fr 1fr auto;gap:.5rem}
.formrow input, .composer input{background:#1a1a1e;border:1px solid #2a2a2e;color:#eee;border-radius:.6rem;padding:.6rem .75rem;width:100%}
.formrow button, .composer button{background:var(--accent);color:#111;border:none;border-radius:.6rem;padding:.6rem .9rem;font-weight:600;cursor:pointer}

.app{display:grid;grid-template-columns:300px 1fr;height:calc(100vh - 56px)}
.sidebar{border-right:1px solid #222;background:#121214;overflow:auto}
.search{width:100%;margin:.6rem;padding:.55rem .7rem;border-radius:.6rem;background:#1a1a1e;border:1px solid #2a2a2e;color:#eee}
.contacts{padding:.25rem .25rem .75rem}
.contact{display:flex;gap:.6rem;align-items:center;padding:.55rem .6rem;border-radius:.6rem;cursor:pointer}
.contact:hover{background:#1b1b1f}
.contact .avatar{width:28px;height:28px;border-radius:50%;background:#2b2b30;display:flex;align-items:center;justify-content:center;font-weight:700}
.contact .name{font-weight:600}
.contact .sub{font-size:12px;color:#9aa}

.chatpane{display:grid;grid-template-rows:auto 1fr auto;height:100%}
.chatheader{padding:.6rem .9rem;border-bottom:1px solid #222;background:#121214}
.messages{overflow:auto;padding:1rem;display:flex;flex-direction:column;gap:.5rem;background:#0c0c0f}
.msgrow{max-width:70%}
.msgrow.me{align-self:flex-end}
.bubble{background:#1b1b22;color:#eee;padding:.6rem .75rem;border-radius:12px}
.msgrow.me .bubble{background:#17321c}
.meta{font-size:11px;color:#999;margin:.2rem 0}
.composer{position:sticky;bottom:0;display:flex;gap:.5rem;padding:.6rem;border-top:1px solid #222;background:#111}
.messages{padding-bottom:4.5rem}

/* Mobile: Sidebar ausblenden wenn ein Chat offen ist */
@media (max-width: 900px){
  .app{grid-template-columns:1fr}
  body.has-chat .sidebar{display:none}
  body.has-chat .chatpane{grid-column:1/2}
}
button[disabled]{opacity:.6;pointer-events:none}

/* ==== MOBILE FIXES: Fixe Topbar + Composer, sichere Viewport-Höhen ==== */
:root{
  --topbar-h: 52px;
}

html, body { height: 100%; }
body { min-height: 100dvh; background: #0b0b0c; }

.topbar{
  position: fixed;
  left: 0; right: 0;
  top: 0;
  height: var(--topbar-h);
  padding-top: env(safe-area-inset-top, 0px);
  z-index: 10000;
  background: rgba(11,11,12,.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.app{
  /* Platz für fixe Topbar + Safe-Area */
  padding-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  height: calc(100dvh - env(safe-area-inset-bottom, 0px));
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Gesamte Chat-Ansicht füllt den Raum unter der Topbar */
#chatView.chat{
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 280px 1fr;
}

/* Mobil: Sidebar aus dem Flow, wenn Chat offen (Body hat Klasse .has-chat) */
@media (max-width: 900px){
  #chatView.chat{
    grid-template-columns: 1fr;
  }
  body.has-chat #sidebar{ display: none; }
}

/* Chatpane mit sticky Header oben und Composer unten */
.chatpane{
  position: relative;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
}

.chatheader{
  position: sticky;
  top: 0; /* sitzt unter der Topbar */
  z-index: 5;
  background: #0b0b0c;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

/* Nachrichten-Viewport */
#messages{
  overflow: auto;
  min-height: 0;
}

/* Eingabeleiste „ankleben“ + Bottom Safe-Area */
.composer{
  position: sticky;
  bottom: 0;
  z-index: 6;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: #0b0b0c;
  border-top: 1px solid rgba(255,255,255,.06);
}

/* Buttons sind verlässlich tappbar */
#btnBack, #btnLogout, #btnEnablePush{
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}


/* --- primary/ghost Buttons fallback --- */
.primary{ background:var(--accent); color:#000; border:0; border-radius:12px; padding:.7rem 1rem; font-weight:700; cursor:pointer; }
.ghost{ background:transparent; color:var(--text); border:1px solid var(--line); border-radius:12px; padding:.55rem .9rem; cursor:pointer; }
.hidden{ display:none !important; }
#diag, .diag, #diagLog { display:none !important; }

/* --- Fix: Composer unten fest, Messages füllen den Rest --- */
.chat { display:flex; flex-direction:row; height:100dvh; }
.sidebar { width:320px; overflow:auto; }
.chatpane { flex:1; display:flex; flex-direction:column; min-width:0; }
.messages { flex:1; overflow:auto; padding:1rem; }
.composer { position:sticky; bottom:0; background:var(--panel,#131316); border-top:1px solid var(--line,#232326); padding:0.75rem; display:flex; gap:0.5rem; }
.composer input { flex:1; }

/* Login/Chat Umschalten */
.hidden { display:none !important; }

/* Klickflächen */
.contact { cursor:pointer; }

/* Optional: Debug-Elemente ausblenden, falls vorhanden */
#diag, .diag, #diagLog { display:none !important; }
