/* ============================================================
   style.css - Chatteru Design System 💜
   Farbpalette: beruhigend, modern, augenfreundlich (Lavender).
   Helles Theme als Standard; Dark Mode automatisch, wenn das
   Betriebssystem des Nutzers dunkel eingestellt ist.
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

/* ---------- Helles Theme (Standard) ---------- */
:root {
  --bg:            #F8F9FC;  /* Soft Gray: App-Hintergrund */
  --bg-chat:       #F4F1FF;  /* Lavender Mist: Chat-Hintergrund */
  --panel:         #FFFFFF;  /* Pure White: Karten, Sidebar */
  --hover:         #F4F1FF;  /* Hover-Flächen */
  --selected:      #CFC3F4;  /* Lavender Light: ausgewählte Chats */
  --border:        #E6E4F2;
  --text:          #2D3142;  /* Text Dark */
  --text-dim:      #6B7280;  /* Text Secondary */
  --accent:        #7E78B8;  /* Chatteru Lavender */
  --accent-hover:  #6A64A8;
  --on-accent:     #FFFFFF;
  --bubble-mine:       #E9E2FF;  /* eigene Nachrichten */
  --bubble-mine-text:  #2D3142;
  --bubble-theirs:     #FFFFFF;  /* empfangene Nachrichten */
  --bubble-theirs-text:#2D3142;
  --online:        #7BC67B;  /* sanftes Grün */
  --offline:       #C9CCD8;
  --read:          #7DA7D9;  /* Pastellblau: gelesen */
  --danger:        #D97878;  /* sanftes Rot */
}

/* ---------- Dark Mode (automatisch) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #161924;
    --bg-chat:       #161924;
    --panel:         #25273A;
    --hover:         #2E3048;
    --selected:      #3A3560;
    --border:        #33364D;
    --text:          #F5F5F7;
    --text-dim:      #9CA1B3;
    --accent:        #9188D8;  /* Chatteru Lavender Dark */
    --accent-hover:  #7E78B8;
    --on-accent:     #FFFFFF;
    --bubble-mine:       #9188D8;
    --bubble-mine-text:  #FFFFFF;
    --bubble-theirs:     #25273A;
    --bubble-theirs-text:#F5F5F7;
    --offline:       #555B6E;
  }
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;   /* dvh = echte sichtbare Höhe am Handy (Adressleiste!) */
  overflow: hidden;
}

.view { height: 100vh; height: 100dvh; }
.hidden { display: none !important; }

/* Zurück-Knopf: nur am Handy sichtbar (siehe Media Query unten) */
#btn-back { display: none; }

/* Senden-Knopf: Text am Desktop, Pfeil am Handy */
.send-icon { display: none; }

/* ---------- Login-Ansicht ---------- */
#auth-view { display: flex; align-items: center; justify-content: center; }

.auth-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 6px 24px rgba(126, 120, 184, 0.10);
}
.auth-box h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 26px;
  color: var(--accent);
}

input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-dim); }

button {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  color: var(--on-accent);
  font-size: 15px;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button.secondary {
  background: var(--hover);
  border: 1px solid var(--border);
  color: var(--text);
}
button.secondary:hover { background: var(--selected); }
button.small {
  padding: 4px 10px;
  font-size: 13px;
  background: var(--hover);
  color: var(--text);
  border: 1px solid var(--border);
}
button.small:hover { background: var(--selected); }

.auth-buttons { display: flex; gap: 8px; }
.auth-buttons button { flex: 1; }
.error { color: var(--danger); font-size: 14px; text-align: center; min-height: 18px; }

/* Impressum/Datenschutz-Links unter dem Login */
.legal-links { text-align: center; font-size: 13px; }
.legal-links a { color: var(--text-dim); text-decoration: none; }
.legal-links a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Messenger-Ansicht ---------- */
#chat-view { display: flex; }

#sidebar {
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
#sidebar header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--accent);
}

.add-contact { display: flex; gap: 6px; padding: 10px; }
.add-contact input { flex: 1; min-width: 0; }
.add-contact button { padding: 8px 14px; }

/* Scrollbarer Bereich mit beiden Listen (Gruppen + Kontakte) */
.lists { overflow-y: auto; flex: 1; }

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px 4px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

#contact-list, #group-list { list-style: none; }
#contact-list li, #group-list li {
  padding: 12px 16px;
  padding-right: 56px;      /* Platz für das Ungelesen-Badge rechts */
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  position: relative;
}

/* ---------- Profilbilder (Avatare) ---------- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;         /* Foto füllt den Kreis, ohne zu verzerren */
  flex-shrink: 0;
}
.avatar.fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}

/* Listeneintrag mit Avatar: Bild links, Text rechts daneben */
li.with-avatar {
  display: flex;
  align-items: center;
  gap: 11px;
}
.li-text { min-width: 0; flex: 1; }

/* Eigenes Profil oben: Avatar (klein) + Name, klickbar */
#me-box {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  min-width: 0;
}
#me-box .avatar { width: 32px; height: 32px; font-size: 14px; }
#me-box:hover #my-name { text-decoration: underline; }
#my-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Ungelesen-Badge: lila Zahl, vertikal mittig am rechten Rand */
.badge {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  min-width: 24px;
  text-align: center;
}
#contact-list li:hover, #group-list li:hover { background: var(--hover); }
#contact-list li.active, #group-list li.active {
  background: var(--hover);
  border-left: 3px solid var(--accent);
}
.contact-name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.contact-last {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* Online-Status-Punkt */
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot.online  { background: var(--online); }
.dot.offline { background: var(--offline); }

#chat-area { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-chat); }
#chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
#chat-title {
  flex: 1;                 /* füllt die Mitte -> steht links neben ← */
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Nachrichtenblasen */
.msg {
  max-width: 65%;
  padding: 9px 14px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.35;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(45, 49, 66, 0.06);
}
.msg.mine {
  align-self: flex-end;
  background: var(--bubble-mine);
  color: var(--bubble-mine-text);
  border-bottom-right-radius: 4px;
}
.msg.theirs {
  align-self: flex-start;
  background: var(--bubble-theirs);
  color: var(--bubble-theirs-text);
  border-bottom-left-radius: 4px;
}
.msg .time { display: block; font-size: 11px; opacity: 0.6; margin-top: 3px; text-align: right; }

/* Absendername über fremden Nachrichten in Gruppen */
.msg .sender {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}

/* Haken: ✓ = gesendet, ✓✓ = gelesen */
.checks { margin-left: 5px; }
.checks.read { color: var(--read); opacity: 1; }

/* Platzhalter, während verschlüsselte Medien geladen werden */
.media-loading { font-size: 13px; opacity: 0.7; padding: 6px 0; }

/* Bilder und Videos in Nachrichten */
.msg img, .msg video {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  margin-bottom: 4px;
}
.msg img { cursor: pointer; }   /* Klick = in voller Größe öffnen */
.msg video { min-width: 220px; }

/* Sprachnachrichten: kompakter Audio-Player */
.msg audio { display: block; width: 250px; max-width: 100%; margin-bottom: 4px; }

/* Mikrofon-Button während der Aufnahme: sanftes Rot, pulsierend */
#btn-mic.recording {
  background: var(--danger);
  color: #fff;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.6; }
}
#btn-mic, #btn-cancel-rec, #btn-attach { padding: 10px 12px; }

#send-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
/* min-width: 0 ist entscheidend: ohne das hat ein Textfeld eine
   eingebaute Mindestbreite (~200px) und sprengt am Handy die Zeile -
   die ganze Seite wird dann breiter als der Bildschirm! */
#send-form input { flex: 1; min-width: 0; }
#send-form button { flex-shrink: 0; }

/* ============================================================
   Responsive Ansichten
   - Desktop  (> 1024px): Sidebar 280px + Chat (Standard oben)
   - Tablet   (701-1024px): schmalere Sidebar + Chat
   - Handy    (<= 700px): ENTWEDER Liste ODER Chat (WhatsApp-Stil),
     Wechsel über die Klasse .chat-open + Zurück-Knopf
   ============================================================ */

/* ---------- Tablet ---------- */
@media (min-width: 701px) and (max-width: 1024px) {
  #sidebar { width: 230px; }
}

/* ---------- Handy ---------- */
@media (max-width: 700px) {
  /* Eine Spalte: Liste füllt den ganzen Bildschirm ... */
  #sidebar { width: 100%; border-right: none; }
  #chat-area { display: none; }

  /* ... bis ein Chat geöffnet wird - dann umgekehrt */
  #chat-view.chat-open #sidebar { display: none; }
  #chat-view.chat-open #chat-area { display: flex; }

  /* Zurück-Knopf einblenden */
  #btn-back { display: inline-block; flex-shrink: 0; }

  /* Senden-Knopf: nur Pfeil statt Text (spart Platz) */
  .send-label { display: none; }
  .send-icon { display: inline; }

  /* Deutlich einrücken: Nachrichten mit viel Luft zum Rand */
  #messages { padding: 22px 28px; }
  .msg { max-width: 84%; padding: 10px 15px; }
  #chat-header { padding: 14px 22px; }

  /* Eingabezeile: eingerückt, Senden-Pfeil weit weg von der Kante,
     und Platz für den iPhone-Home-Balken (safe-area).
     Kompakte Knöpfe, damit die Zeile sicher in jede Bildschirmbreite passt. */
  #send-form {
    padding: 14px 22px calc(14px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  #btn-attach, #btn-mic, #btn-cancel-rec, #send-btn { padding: 10px 11px; }

  /* Sicherheitsnetz: nichts darf die Seite horizontal aufdrücken */
  body { overflow-x: hidden; }

  /* Listen und Kopfzeile: gleiche Einrückung */
  #sidebar header { padding: 16px 22px; }
  .add-contact { padding: 12px 22px; }
  .section-title { padding: 12px 22px 4px; }
  #contact-list li, #group-list li { padding: 14px 22px; }

  input { font-size: 16px; }   /* verhindert Auto-Zoom beim iPhone */
}
