:root {
  --bg: #161320;
  --bg-elevated: #1f1b2e;
  --bubble-mine: #8a5cf6;
  --bubble-theirs: #2a2540;
  --text: #ece8f5;
  --text-dim: #948dab;
  --accent: #ff9f6b;
  --danger: #e85d5d;
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

.screen { height: 100vh; display: flex; flex-direction: column; overflow-x: hidden; }
.hidden { display: none !important; }

/* Connexion */
#login-screen { align-items: center; justify-content: center; }
.login-card {
  background: var(--bg-elevated);
  padding: 36px 28px;
  border-radius: 20px;
  width: min(320px, 86vw);
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.login-card h1 { margin: 0 0 8px; font-size: 1.4rem; font-weight: 600; text-align: center; }
.login-card input {
  background: var(--bg); border: 1px solid #34304a; color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-size: 1rem;
}
.login-card input:focus { outline: 2px solid var(--accent); }
.login-card button {
  background: var(--bubble-mine); color: white; border: none;
  padding: 12px; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.error-text { color: var(--danger); font-size: 0.85rem; text-align: center; min-height: 1em; margin: 0; }

/* Header */
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; background: var(--bg-elevated);
  border-bottom: 1px solid #2a2540;
  flex-shrink: 0;
}
.contact-info { font-weight: 600; font-size: 1rem; flex: 1; }
.header-actions { display: flex; gap: 6px; }
.icon-btn {
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; padding: 6px; border-radius: 10px; color: var(--text);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.06); }
.burger-btn { font-size: 1.4rem; }

/* Messages */
.messages {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  width: 100%;
}
.bubble-row {
  display: flex; flex-direction: column; max-width: 72%;
}
.bubble-row.mine { align-self: flex-end; align-items: flex-end; }
.bubble-row.theirs { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 0.96rem; line-height: 1.4; word-wrap: break-word; word-break: break-word;
  max-width: 100%;
}
.bubble.mine { background: var(--bubble-mine); color: white; border-bottom-right-radius: 4px; }
.bubble.theirs { background: var(--bubble-theirs); border-bottom-left-radius: 4px; }
.bubble img { max-width: 100%; border-radius: 12px; display: block; cursor: pointer; }
.bubble-video { max-width: 100%; max-height: 320px; border-radius: 12px; display: block; }

.upload-progress {
  align-self: center;
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid #34304a;
}

.bubble-meta {
  display: flex; align-items: center; gap: 8px; margin-top: 3px; padding: 0 4px;
}
.bubble-time { font-size: 0.7rem; color: var(--text-dim); }

.like-btn {
  background: none; border: none; cursor: pointer; font-size: 0.95rem;
  padding: 2px 4px; border-radius: 8px; display: flex; align-items: center; gap: 3px;
  color: var(--text-dim);
}
.like-btn:hover { background: rgba(255,255,255,0.07); }
.like-btn.liked { color: #ff5c7a; }
.like-count { font-size: 0.72rem; }

/* Composer */
.composer {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; background: var(--bg-elevated);
  border-top: 1px solid #2a2540; position: relative;
  flex-shrink: 0;
  width: 100%;
}
.composer input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--bg); border: 1px solid #34304a; color: var(--text);
  padding: 11px 14px; border-radius: 20px; font-size: 0.96rem;
}
.send-btn {
  background: var(--bubble-mine); color: white; border: none;
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.1rem; cursor: pointer;
  flex-shrink: 0;
}

/* Emoji picker */
.emoji-picker {
  position: fixed; bottom: 70px; left: 12px;
  background: var(--bg-elevated); border: 1px solid #34304a;
  border-radius: 14px; padding: 8px;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
  max-width: min(280px, calc(100vw - 24px));
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); z-index: 10;
}
.emoji-picker button {
  background: none; border: none; font-size: 1.3rem; cursor: pointer;
  padding: 4px; border-radius: 8px;
}
.emoji-picker button:hover { background: rgba(255,255,255,0.08); }

/* Menu burger (drawer) */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 60;
}
.side-drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: min(260px, 78vw);
  background: var(--bg-elevated);
  box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  z-index: 70;
  display: flex; flex-direction: column;
  padding: 18px 0;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
}
.side-drawer.open { transform: translateX(0); }
.drawer-header {
  font-weight: 700; font-size: 1.05rem;
  padding: 6px 20px 16px; border-bottom: 1px solid #34304a; margin-bottom: 8px;
}
.drawer-item {
  background: none; border: none; color: var(--text);
  text-align: left; padding: 14px 20px; font-size: 0.98rem; cursor: pointer;
}
.drawer-item:hover { background: rgba(255,255,255,0.06); }
.drawer-danger { color: var(--danger); margin-top: auto; }

/* Galerie */
.gallery-container { flex: 1; overflow-y: auto; padding: 16px; }
.gallery-section { margin-bottom: 24px; }
.gallery-section h3 { margin: 0 0 10px; font-size: 0.95rem; color: var(--text-dim); }
.gallery-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.gallery-grid img, .gallery-video-cell {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: pointer;
}
.gallery-video-cell {
  position: relative;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.gallery-video-cell video {
  width: 100%; height: 100%; object-fit: cover;
}
.gallery-play-icon {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; color: white;
  background: rgba(0,0,0,0.25);
  pointer-events: none;
}
.gallery-empty { color: var(--text-dim); font-size: 0.85rem; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 80;
}
.modal-content {
  background: var(--bg-elevated); padding: 24px; border-radius: 18px;
  width: min(340px, 88vw); display: flex; flex-direction: column; gap: 14px;
}
.modal-content h2 { margin: 0; font-size: 1.1rem; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 0.9rem;
}
.field-row { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.field-row input {
  background: var(--bg); border: 1px solid #34304a; color: var(--text);
  padding: 9px 12px; border-radius: 8px;
}
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.btn-primary, .btn-secondary {
  flex: 1; padding: 10px; border-radius: 10px; border: none; cursor: pointer; font-weight: 600;
}
.btn-primary { background: var(--bubble-mine); color: white; }
.btn-secondary { background: #2a2540; color: var(--text); }

/* Lightbox photo */
#lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.88);
  display: flex; align-items: center; justify-content: center; z-index: 100; cursor: zoom-out;
}
#lightbox img, #lightbox video { max-width: 92vw; max-height: 88vh; border-radius: 12px; }
