:root{
  --green:#1f7a34; --green-d:#155d27; --mint:#e7f4e8;
  --bg:#f2f4f3; --card:#ffffff; --ink:#17222a; --muted:#647079; --line:#e2e8e4;
  --out:#dcf5d8; --in:#ffffff;
  --safe-top:env(safe-area-inset-top); --safe-bot:env(safe-area-inset-bottom);
}
@media (prefers-color-scheme: dark){
  :root{ --bg:#12171a; --card:#1b2126; --ink:#e6ebe8; --muted:#93a0a6; --line:#2a3238;
         --mint:#20362a; --out:#264b30; --in:#232a30; }
}
*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html,body{ margin:0; height:100%; }
body{
  font:16px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
  background:var(--bg); color:var(--ink);
  display:flex; flex-direction:column; overflow:hidden;
}
button{ font:inherit; cursor:pointer; border:none; background:none; color:inherit; }

/* Topbar */
#topbar{
  display:flex; align-items:center; gap:8px;
  padding:calc(var(--safe-top) + 8px) 12px 8px;
  background:var(--green); color:#fff; box-shadow:0 1px 4px rgba(0,0,0,.15);
}
#topbar .brand{ display:flex; align-items:center; gap:6px; font-weight:700; }
#topbar .lock{ font-size:15px; }
#topbar .spacer{ flex:1; }
#topbar .icon{ color:#fff; font-size:20px; padding:4px 8px; border-radius:8px; }
#topbar .icon:active{ background:rgba(255,255,255,.2); }
#status{ display:flex; align-items:center; gap:5px; font-size:12px; opacity:.9; }
#status .dot{ width:8px; height:8px; border-radius:50%; background:#c9ffcf; box-shadow:0 0 0 0 rgba(0,0,0,0); }
body[data-online="false"] #status .dot{ background:#ffb3a7; }
#btn-back{ display:none; }
body[data-view="chat"] #btn-back{ display:block; }

main{ flex:1; overflow:hidden; position:relative; display:flex; }
section{ flex:1; overflow:auto; -webkit-overflow-scrolling:touch; }

/* Onboarding */
#view-onboard{ padding:24px 18px calc(var(--safe-bot) + 18px); text-align:center; }
.hero{ margin:22px 0 10px; }
.biglock{ font-size:56px; }
.hero h1{ margin:6px 0 2px; color:var(--green); font-size:30px; }
.hero .sub{ color:var(--muted); margin:0; }
.card{ background:var(--card); border:1px solid var(--line); border-radius:16px;
  padding:16px; margin:16px auto; max-width:520px; text-align:left; }
.card.subtle{ background:transparent; }
.card h2{ margin:0 0 6px; font-size:17px; }
.card p{ margin:0 0 12px; color:var(--muted); font-size:14px; }
.card code{ background:var(--mint); color:var(--green-d); padding:1px 5px; border-radius:5px; }
button.primary{ background:var(--green); color:#fff; padding:12px 16px; border-radius:12px; width:100%; font-weight:600; }
button.primary:active{ background:var(--green-d); }
.card button:not(.primary){ background:var(--mint); color:var(--green-d); padding:12px 16px; border-radius:12px; width:100%; font-weight:600; }
.selftest{ font-size:12px; color:var(--muted); margin-top:20px; }
.selftest.ok{ color:var(--green); } .selftest.bad{ color:#c0392b; }

/* Kontaktliste */
.list{ padding:6px 0 90px; }
.contact{ display:flex; align-items:center; gap:12px; padding:12px 16px; border-bottom:1px solid var(--line); }
.contact:active{ background:var(--mint); }
.contact .ava{ width:42px; height:42px; border-radius:50%; background:var(--green); color:#fff;
  display:flex; align-items:center; justify-content:center; font-weight:700; flex:0 0 auto; }
.contact .meta{ flex:1; min-width:0; }
.contact .name{ font-weight:600; }
.contact .cid{ font-size:12px; color:var(--muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.contact .lk{ font-size:14px; }
.fab{ position:fixed; right:18px; bottom:calc(var(--safe-bot) + 18px);
  width:56px; height:56px; border-radius:50%; background:var(--green); color:#fff; font-size:28px;
  box-shadow:0 4px 14px rgba(0,0,0,.25); }

/* Chat */
#view-chat{ display:flex; flex-direction:column; }
.encbar{ font-size:12px; padding:6px 14px; background:var(--mint); color:var(--green-d);
  display:flex; align-items:center; gap:6px; }
.encbar.warn{ background:#fff3e0; color:#9a6400; }
.messages{ flex:1; overflow:auto; padding:12px; display:flex; flex-direction:column; gap:6px; }
.row{ display:flex; }
.row.me{ justify-content:flex-end; }
.bubble{ max-width:78%; padding:7px 11px; border-radius:14px; background:var(--in);
  border:1px solid var(--line); box-shadow:0 1px 1px rgba(0,0,0,.04); word-wrap:break-word; }
.row.me .bubble{ background:var(--out); border-color:transparent; }
.bubble .foot{ font-size:10px; color:var(--muted); margin-top:2px; text-align:right; }
.bubble a{ color:var(--green-d); }
.daysep{ align-self:center; font-size:11px; color:var(--muted); background:var(--card);
  border:1px solid var(--line); padding:2px 10px; border-radius:10px; margin:6px 0; }
#composer{ display:flex; gap:8px; padding:8px 10px calc(var(--safe-bot) + 8px); background:var(--card); border-top:1px solid var(--line); }
#draft{ flex:1; padding:11px 14px; border-radius:22px; border:1px solid var(--line); background:var(--bg); color:var(--ink); font-size:16px; }
#draft:focus{ outline:none; border-color:var(--green); }
.send{ width:44px; height:44px; border-radius:50%; background:var(--green); color:#fff; font-size:18px; }
.send:disabled{ opacity:.4; }

/* Dialoge / Popup / Toast */
dialog{ border:none; border-radius:16px; padding:18px; width:min(92vw,420px); background:var(--card); color:var(--ink); box-shadow:0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop{ background:rgba(0,0,0,.4); }
dialog h3{ margin:0 0 12px; }
dialog label{ display:block; font-size:13px; color:var(--muted); margin:10px 0; }
dialog input{ width:100%; padding:10px; border:1px solid var(--line); border-radius:10px; background:var(--bg); color:var(--ink); font-size:16px; margin-top:4px; }
dialog menu{ display:flex; justify-content:flex-end; gap:10px; padding:0; margin:16px 0 0; }
dialog menu button{ padding:9px 14px; border-radius:10px; background:var(--mint); color:var(--green-d); font-weight:600; }
dialog menu button.primary{ background:var(--green); color:#fff; }
.mono{ font-family:ui-monospace,Menlo,monospace; font-size:18px; word-break:break-all; background:var(--bg); padding:10px; border-radius:10px; }
.hint{ font-size:12px; color:var(--muted); }
.popup{ position:fixed; top:calc(var(--safe-top) + 52px); right:10px; background:var(--card);
  border:1px solid var(--line); border-radius:12px; box-shadow:0 8px 30px rgba(0,0,0,.25); overflow:hidden; z-index:50; }
.popup button{ display:block; width:100%; text-align:left; padding:12px 16px; border-bottom:1px solid var(--line); }
.popup button:last-child{ border-bottom:none; }
.popup button.danger{ color:#c0392b; }
.toast{ position:fixed; left:50%; bottom:calc(var(--safe-bot) + 20px); transform:translateX(-50%);
  background:#222; color:#fff; padding:10px 16px; border-radius:20px; font-size:14px; z-index:100; max-width:88vw; }

/* View-Umschaltung */
#view-onboard,#view-list,#view-chat{ display:none; }
body[data-view="onboard"] #view-onboard{ display:block; }
body[data-view="list"] #view-list{ display:block; }
body[data-view="chat"] #view-chat{ display:flex; }
body[data-view="chat"] #btn-chatmenu{ display:block; }
body:not([data-view="chat"]) #btn-chatmenu{ display:none; }
