:root {
  --brand: #0f4c81;
  --brand-dark: #0a3a65;
  --brand-soft: #e6eef6;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --line: #dde3ea;
  --text: #17212b;
  --muted: #6b7885;
  --mine: #d7e8f9;
  --theirs: #ffffff;
  --online: #2bb673;
  --danger: #c0392b;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg); overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Anmeldung */
.screen { height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border-radius: 18px; padding: 28px;
  box-shadow: 0 10px 40px rgba(15, 76, 129, .15); display: grid; gap: 14px; text-align: center;
}
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: -8px 0 4px; }
.login-card label { text-align: left; font-size: 14px; color: var(--muted); display: grid; gap: 6px; }
.login-logo { width: 64px; height: 64px; margin: 0 auto; }
input, textarea, select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.error { color: var(--danger); font-size: 14px; min-height: 18px; }
button.primary {
  background: var(--brand); color: #fff; border: 0; border-radius: 10px; padding: 12px 16px; font-weight: 600;
}
button.primary:hover { background: var(--brand-dark); }
button.small { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 14px; }
button.small.primary { border: 0; background: var(--brand); color: #fff; }
button.small.danger { color: var(--danger); border-color: #efc2bd; }

/* Layout */
#app { display: grid; grid-template-columns: 340px 1fr; height: 100dvh; }
#side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.side-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--brand); color: #fff;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.side-title { flex: 1; font-weight: 700; font-size: 18px; }
.icon-btn {
  border: 0; background: transparent; font-size: 20px; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: inherit;
}
.icon-btn:hover { background: rgba(0, 0, 0, .08); }
.side-head .icon-btn:hover { background: rgba(255, 255, 255, .15); }
.search { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.search input { background: var(--bg); border-radius: 20px; padding: 8px 14px; }
.notif-bar {
  display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: #fff7e0; font-size: 13px;
  border-bottom: 1px solid #f0e2b0;
}

/* Avatare */
.avatar, .avatar-btn {
  width: 44px; height: 44px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; flex: none; position: relative; overflow: visible;
  background-size: cover; background-position: center; border: 0;
}
.avatar-btn { width: 40px; height: 40px; background-color: #fff; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.lg { width: 96px; height: 96px; font-size: 32px; }
.avatar.group { background-color: #e7eef2; color: #3b5a6c; }
.dot {
  position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%;
  background: var(--online); border: 2px solid #fff;
}

/* Chatliste */
.chat-list { flex: 1; overflow-y: auto; }
.group-label {
  padding: 12px 14px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.group-label .grow { flex: 1; }
.group-label button { border: 0; background: none; color: var(--brand); font-size: 12px; text-transform: none; letter-spacing: 0; }
.chat-item {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px; border: 0; width: 100%; background: transparent;
  text-align: left; border-bottom: 1px solid #f0f3f6;
}
.chat-item:hover { background: #f6f9fc; }
.chat-item.active { background: var(--brand-soft); }
.chat-item .meta { flex: 1; min-width: 0; }
.chat-item .row { display: flex; gap: 8px; align-items: baseline; }
.chat-item .name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { font-size: 12px; color: var(--muted); }
.chat-item .preview { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.badge {
  background: var(--brand); color: #fff; border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px;
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
}
.list-empty { padding: 24px 16px; color: var(--muted); text-align: center; }

/* Chat-Ansicht */
.empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 20px; }
.empty-logo { width: 72px; opacity: .85; }
#chatView { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); padding-top: calc(8px + env(safe-area-inset-top));
}
.chat-head .back { display: none; }
.chat-title { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 2px 0; display: grid; }
.chat-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title small.online { color: var(--online); }
.messages { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: #e3e9ef; color: #4a5a68; font-size: 12px; padding: 3px 12px; border-radius: 12px; margin: 10px 0 6px; }
.msg { display: flex; gap: 8px; max-width: 100%; }
.msg.mine { justify-content: flex-end; }
.bubble {
  max-width: min(78%, 560px); background: var(--theirs); border-radius: var(--radius); padding: 7px 11px 5px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .06); overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--mine); }
.bubble .who { font-size: 13px; font-weight: 700; color: var(--brand); margin-bottom: 1px; }
.bubble .text { white-space: pre-wrap; }
.bubble .time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.bubble img.photo { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; cursor: zoom-in; margin-bottom: 4px; }
.bubble audio { width: 240px; max-width: 100%; height: 40px; }
.file-card {
  display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: rgba(15, 76, 129, .07);
  border-radius: 10px; color: inherit; text-decoration: none; margin-bottom: 3px;
}
.file-card .ico { font-size: 24px; }
.file-card .fn { font-weight: 600; word-break: break-all; }
.msg .avatar.sm { align-self: flex-end; }
.typing { height: 20px; padding: 0 16px; font-size: 13px; color: var(--muted); }
.readonly { text-align: center; padding: 14px; background: #eef1f4; color: var(--muted); border-top: 1px solid var(--line); }

/* Eingabe */
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.composer-row { display: flex; align-items: flex-end; gap: 2px; }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 140px; border-radius: 20px; padding: 10px 14px; line-height: 1.3; }
.composer .icon-btn { width: 40px; height: 40px; flex: none; font-size: 19px; }
.composer .icon-btn.active { background: #fde3e0; }
.composer .send {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 18px; margin-left: 4px;
}
.rec-bar { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #e03a2b; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* Dialoge */
.modal { position: fixed; inset: 0; background: rgba(10, 25, 40, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card {
  background: #fff; border-radius: 16px; width: min(460px, 100%); max-height: 90dvh; overflow-y: auto; padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3); display: grid; gap: 12px;
}
.modal-card h3 { margin: 0; }
.modal-card label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.pick-list { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.pick-list label {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; color: var(--text); font-size: 16px; border-bottom: 1px solid #f0f3f6;
}
.pick-list input { width: auto; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid #f0f3f6; flex-wrap: wrap; }
.member-row .grow { flex: 1; min-width: 120px; }
.role-tag { font-size: 11px; background: var(--brand-soft); color: var(--brand); border-radius: 8px; padding: 1px 7px; margin-left: 6px; }
.role-tag.ro { background: #fdeceb; color: var(--danger); }
.profile-head { display: grid; justify-items: center; gap: 8px; }
.tabs { display: flex; gap: 6px; }
.tabs button { flex: 1; padding: 8px; border: 1px solid var(--line); background: #fff; border-radius: 8px; }
.tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d2a36; color: #fff; padding: 10px 16px;
  border-radius: 10px; z-index: 60; max-width: 90vw; box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
}
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .88); display: grid; place-items: center; z-index: 70; padding: 12px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* Handy / schmales Fenster: immer nur eine Spalte */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #main { display: none; }
  body.chat-open #side { display: none; }
  body.chat-open #main { display: flex; }
  .chat-head .back { display: grid; }
  .bubble { max-width: 86%; }
  .composer .icon-btn { width: 34px; font-size: 18px; }
  .composer .send { width: 40px; height: 40px; margin-left: 2px; }
  .composer { padding-left: 4px; padding-right: 4px; }
}
