/* ─────────────────────────────────────────────────────────
   style.css – Aussehen des Messengers
   Farben stehen oben als Variablen – dort kannst du alles anpassen.
   ───────────────────────────────────────────────────────── */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #15181d;
  --muted: #6b7280;
  --border: #e3e5e9;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --bubble-in: #ffffff;
  --bubble-out: #2f6fed;
  --bubble-out-text: #ffffff;
  --online: #1faa59;
  --danger: #d33b3b;
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #1a1e24;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --border: #2a3038;
    --accent: #4d86ff;
    --bubble-in: #232830;
    --bubble-out: #3b74f0;
    --online: #34c26f;
    --danger: #ff6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

.btn-primary {
  background: var(--accent); color: var(--accent-text);
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600;
}
.btn-ghost {
  background: none; border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 10px; font-size: 14px; color: var(--muted);
}
.btn-link { background: none; border: 0; color: var(--accent); padding: 4px 0; font-size: 14px; }

/* ── Login ───────────────────────────────────────────── */
.login {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px;
  padding: 28px 24px; display: flex; flex-direction: column; gap: 14px;
}
.login-logo { align-self: center; border-radius: 16px; }
.login-card h1 { margin: 0 0 6px; text-align: center; font-size: 24px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.login-card input {
  padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); font-size: 16px; /* 16px verhindert Zoom auf dem iPhone */
}
.login-error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
.login-intro { margin: -4px 0 4px; text-align: center; color: var(--muted); font-size: 15px; }
.login-card small { font-size: 12px; }

/* ── App-Layout ──────────────────────────────────────── */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
  padding-top: env(safe-area-inset-top);
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
}
.sidebar-header h1 { margin: 0; font-size: 22px; }

.conn-banner {
  margin: 0 12px 8px; padding: 8px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger); font-size: 14px;
}

.chat-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border-radius: 12px; cursor: pointer;
}
.chat-item:hover { background: var(--bg); }
.chat-item.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }

.avatar {
  position: relative; flex: none;
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: 17px;
}
.avatar .dot {
  position: absolute; right: 0; bottom: 0;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--online); border: 2px solid var(--panel);
}
.chat-item-name { flex: 1; min-width: 0; font-weight: 600; }
.chat-item-preview {
  display: block; font-weight: 400; font-size: 14px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--accent); color: var(--accent-text);
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
}

.sidebar-footer {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  font-size: 14px; color: var(--muted);
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
}

/* ── Chat ────────────────────────────────────────────── */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.chat-header h2 { margin: 0; font-size: 17px; }
.chat-subtitle { margin: 0; font-size: 13px; color: var(--muted); min-height: 1.2em; }
.btn-back {
  display: none; background: none; border: 0;
  font-size: 34px; line-height: 1; padding: 0 8px 4px 0; color: var(--accent);
}

.messages {
  flex: 1; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 4px;
  overscroll-behavior: contain;
}
.day-separator {
  align-self: center; margin: 12px 0 6px;
  font-size: 12px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 10px;
}
.msg {
  max-width: min(78%, 560px);
  padding: 8px 12px 6px; border-radius: var(--radius);
  background: var(--bubble-in); border: 1px solid var(--border);
  align-self: flex-start;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.out {
  align-self: flex-end;
  background: var(--bubble-out); color: var(--bubble-out-text); border-color: transparent;
}
.msg.grouped { margin-top: -1px; }
.msg-sender { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.msg-time { font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.msg a { color: inherit; }
.empty { margin: auto; color: var(--muted); text-align: center; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px;
  padding: 10px 14px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--bg);
  font-size: 16px; /* verhindert Zoom auf dem iPhone */
}
.btn-send {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); border: 0;
  display: grid; place-items: center;
}
.btn-send:disabled { opacity: .45; }
.btn-attach {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  background: none; border: 0; color: var(--muted);
  display: grid; place-items: center;
}
.btn-attach:hover { color: var(--accent); }
.btn-attach:disabled { opacity: .45; }

/* ── Bilder ──────────────────────────────────────────── */
.msg.image { padding: 4px 4px 6px; }
.msg-img {
  display: block;
  width: min(280px, 60vw); height: auto;
  max-height: 360px; object-fit: cover;
  border-radius: calc(var(--radius) - 4px);
  background: var(--border);
  cursor: zoom-in;
}
.msg.image .msg-sender,
.msg.image .msg-caption,
.msg.image .msg-time { padding: 0 8px; }
.msg-caption { margin-top: 6px; }

.upload-status {
  align-self: flex-end; font-size: 13px; color: var(--muted);
  padding: 4px 8px;
}
.upload-status.error { color: var(--danger); }

.lightbox {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, .9);
  display: grid; place-items: center;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: calc(100dvh - 24px); object-fit: contain; }

.drop-hint {
  outline: 3px dashed var(--accent); outline-offset: -12px;
}

/* ── Handy: immer nur eine Ansicht (Liste ODER Chat) ─── */
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; }
  .app:not(.chat-open) .chat { display: none; }
  .app.chat-open .sidebar { display: none; }
  .btn-back { display: block; }
}

/* ── Gruppen ─────────────────────────────────────────── */
.sidebar-actions { display: flex; gap: 6px; }
.avatar-group { border-radius: 13px; }
.avatar-small { width: 32px; height: 32px; font-size: 14px; }
.chat-head { min-width: 0; }
.chat-head.clickable { cursor: pointer; }
.chat-head h2, .chat-subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.system-msg {
  align-self: center; text-align: center; max-width: 85%;
  margin: 6px 0; padding: 4px 12px; border-radius: 10px;
  font-size: 13px; color: var(--muted);
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}

.dialog {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--panel); color: var(--text);
  padding: 20px;
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog h2 { margin: 0 0 12px; font-size: 20px; }
.dialog-field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.dialog-field input {
  padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); font-size: 16px;
}
.dialog-hint { color: var(--muted); font-size: 14px; margin: 14px 0 6px; }
.picker { max-height: 45dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.picker-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 10px; cursor: pointer;
}
.picker-item:hover { background: var(--bg); }
.picker-item input { width: 18px; height: 18px; accent-color: var(--accent); }
.picker-empty { color: var(--muted); font-size: 14px; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog-buttons.vertical { flex-direction: column; align-items: stretch; }
.dialog-buttons.vertical button { padding: 10px; font-size: 15px; }
.member-list { list-style: none; margin: 0; padding: 0; max-height: 40dvh; overflow-y: auto; }
.member-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.btn-danger {
  background: none; border: 1px solid var(--danger); color: var(--danger);
  border-radius: 10px; padding: 6px 10px;
}

/* ── Nachrichten-Menü & gelöschte Nachrichten ────────── */
.msg { position: relative; }
.msg.deleted { font-style: italic; opacity: .7; }
.msg-more {
  position: absolute; top: 2px; right: 4px;
  width: 26px; height: 22px; border-radius: 8px;
  border: 0; background: color-mix(in srgb, var(--panel) 85%, transparent);
  color: var(--muted); font-size: 16px; line-height: 1;
  display: none;
}
.msg.out .msg-more { color: #fff; background: rgba(0, 0, 0, .18); }
@media (hover: hover) and (pointer: fine) {
  .msg:hover .msg-more { display: block; }
}
@media (pointer: coarse) {
  /* Kein Text-Markieren beim langen Drücken auf dem Handy */
  .msg { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
.msg-menu {
  position: fixed; z-index: 20; min-width: 190px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .22);
  padding: 4px; display: flex; flex-direction: column;
}
.msg-menu button {
  background: none; border: 0; text-align: left;
  padding: 10px 12px; border-radius: 8px; font-size: 15px;
}
.msg-menu button:hover { background: var(--bg); }
.msg-menu .danger { color: var(--danger); }

/* ── Suche ───────────────────────────────────────────── */
.search-box { padding: 0 12px 10px; }
.search-box input, .picker-search {
  width: 100%; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg);
  font-size: 16px; /* verhindert Zoom auf dem iPhone */
}
.picker-search { margin-bottom: 8px; }
.list-heading {
  padding: 14px 10px 6px; font-size: 13px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}
.list-empty { padding: 16px 10px; color: var(--muted); font-size: 14px; }

/* ── @benutzername ───────────────────────────────────── */
.handle {
  display: block; font-weight: 400; font-size: 13px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#me-name .handle { display: inline; margin-left: 6px; }
.person-name { min-width: 0; }

/* ── Profilbilder ────────────────────────────────────── */
.avatar { overflow: visible; }
.avatar img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block;
}
.chat-avatar:empty { display: none; }
.chat-avatar .avatar { width: 38px; height: 38px; }
.btn-icon { padding: 6px 9px; line-height: 1; }

.me-card {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; padding: 4px; border-radius: 12px; text-align: left;
}
.me-card:hover { background: var(--bg); }
.me-card .person-name { font-weight: 600; color: var(--text); }

.settings-profile { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.settings-avatar .avatar { width: 84px; height: 84px; font-size: 34px; }
.settings-avatar-buttons { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.settings-row { display: flex; gap: 8px; }
.settings-row input { flex: 1; min-width: 0; }
.settings-name small { color: var(--muted); }
.settings-status { min-height: 1.2em; font-size: 14px; color: var(--muted); margin: 10px 0 0; }

/* ── Gelesen-Häkchen ─────────────────────────────────── */
.ticks { margin-left: 4px; letter-spacing: -3px; font-weight: 700; }
.ticks.read { color: #7fe3ff; opacity: 1; }
.msg:not(.out) .ticks.read { color: var(--accent); }

/* ── Antworten ───────────────────────────────────────── */
.reply-quote {
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--text) 7%, transparent);
  border-radius: 8px; padding: 4px 8px; margin: 2px 0 6px;
  font-size: 13px; cursor: pointer; max-width: 100%;
}
.msg.out .reply-quote { border-left-color: #fff; background: rgba(255, 255, 255, .16); }
.msg.image .reply-quote { margin: 4px 4px 6px; }
.reply-who { font-weight: 700; }
.msg.out .reply-who { color: #fff !important; }
.reply-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }
.reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--border);
}
.reply-bar-text {
  flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; font-size: 14px;
}
.reply-bar .reply-who { color: var(--accent); }
.msg.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: none; } }

/* ── Kamera & Video ──────────────────────────────────── */
.btn-camera { display: none; }
@media (pointer: coarse) { .btn-camera { display: grid; } }
.msg-video { cursor: default; max-height: 420px; background: #000; }
.msg.out .msg-time { opacity: .85; }
.msg.out .ticks { color: rgba(255, 255, 255, .9); }
.msg.out .ticks.read { color: #a5f3ff; }
