:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border-color: #334155;
  --border-subtle: #1e293b;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --primary: #f59e0b; /* Sunshine Amber/Gold */
  --primary-hover: #d97706;
  --primary-glow: rgba(245, 158, 11, 0.25);
  
  --accent: #38bdf8;
  --danger: #ef4444;
  --success: #10b981;
  
  --msg-self-bg: #2563eb;
  --msg-other-bg: #1e293b;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --transition: all 0.2s ease-in-out;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  width: 100%;
  position: relative;
}

.screen {
  width: 100%;
  height: 100%;
  display: flex;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   ÉCRAN DE CONNEXION
   ========================================================================== */
#login-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 100%);
  padding: 1.5rem;
}

.login-card {
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 40px var(--primary-glow);
  width: 100%;
  max-width: 440px;
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.brand {
  text-align: center;
}

.logo-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 0 12px rgba(245, 158, 11, 0.6));
}

.brand h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #fff;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.ad-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--accent);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.input-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.input-group input,
.sidebar-search input,
.input-group-row input {
  background-color: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
  transition: var(--transition);
}

.input-group input:focus,
.sidebar-search input:focus,
.input-group-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.error-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  cursor: pointer;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-family: inherit;
  transition: var(--transition);
}

.btn-primary {
  background: var(--primary);
  color: #0f172a;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: #475569;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.btn-icon.danger:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.login-footer {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.4;
}

/* ==========================================================================
   INTERFACE DU TCHAT (SIDEBAR + MAIN)
   ========================================================================== */
#chat-screen {
  flex-direction: row;
}

.sidebar {
  width: 310px;
  min-width: 280px;
  max-width: 340px;
  background-color: #0b1120;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.brand-small {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon-sm {
  font-size: 1.4rem;
}

.brand-small h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.user-profile-badge {
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(30, 41, 59, 0.4);
  border-bottom: 1px solid var(--border-color);
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #ec4899);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.dot-online {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success);
}

.sidebar-search {
  padding: 0.85rem 1.25rem;
  position: relative;
  display: flex;
  align-items: center;
}

.sidebar-search svg {
  position: absolute;
  left: 2rem;
  color: var(--text-dim);
}

.sidebar-search input {
  width: 100%;
  padding-left: 2.3rem;
  font-size: 0.85rem;
  border-radius: 20px;
}

.groups-container {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
}

.groups-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  padding: 0.5rem 0.5rem 0.25rem 0.5rem;
}

.groups-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.group-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-muted);
}

.group-item:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
}

.group-item.active {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--primary);
  font-weight: 600;
  border-left: 3px solid var(--primary);
}

.group-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background-color: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.group-item.active .group-item-icon {
  background-color: var(--primary);
  color: #0f172a;
}

.group-item-content {
  flex: 1;
  min-width: 0;
}

.group-item-name {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-item-preview {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   ZONE CENTRALE : CHAT
   ========================================================================== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  position: relative;
}

.chat-header {
  height: 64px;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(8px);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-hash {
  font-size: 1.5rem;
  color: var(--primary);
  font-weight: 700;
}

.chat-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.group-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.messages-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 420px;
  color: var(--text-dim);
  padding: 2rem;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.empty-state h3 {
  color: var(--text-main);
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Ligne de message */
.message-entry {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #475569;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.message-body {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 75%;
}

.message-meta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.message-sender {
  font-size: 0.85rem;
  font-weight: 600;
  color: #cbd5e1;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.message-bubble {
  background-color: var(--msg-other-bg);
  border: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  border-radius: 0 var(--radius-md) var(--radius-md) var(--radius-md);
  color: var(--text-main);
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: break-word;
}

/* Messages de l'utilisateur connecté */
.message-entry.self {
  flex-direction: row-reverse;
}

.message-entry.self .message-body {
  align-items: flex-end;
}

.message-entry.self .message-meta {
  flex-direction: row-reverse;
}

.message-entry.self .message-bubble {
  background-color: var(--msg-self-bg);
  border-color: #3b82f6;
  border-radius: var(--radius-md) 0 var(--radius-md) var(--radius-md);
}

/* Liens cliquables dans les messages */
.message-bubble a {
  color: #38bdf8;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: var(--transition);
}

.message-entry.self .message-bubble a {
  color: #fef08a;
}

.message-bubble a:hover {
  color: #fff;
}

/* Médias : Images */
.message-image-container {
  margin-top: 0.5rem;
  border-radius: var(--radius-md);
  overflow: hidden;
  max-width: 400px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.message-image {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.message-image:hover {
  transform: scale(1.02);
}

/* Médias : Fichiers attachés (documents, archives, etc.) */
.file-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
  text-decoration: none;
  color: var(--text-main);
  transition: var(--transition);
}

.file-card:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
}

.file-card-icon {
  font-size: 1.5rem;
}

.file-card-info {
  display: flex;
  flex-direction: column;
}

.file-card-name {
  font-size: 0.85rem;
  font-weight: 600;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-card-size {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Indicateur de saisie */
.typing-indicator {
  height: 22px;
  padding: 0 1.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  display: flex;
  align-items: center;
}

/* Zone de composition / Input */
.chat-composer {
  padding: 0.75rem 1.5rem 1.25rem 1.5rem;
  background-color: var(--bg-primary);
}

.composer-form {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.6rem;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: var(--transition);
}

.composer-form:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.composer-form textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  padding: 0.5rem 0.25rem;
  line-height: 1.4;
}

.btn-send {
  background-color: var(--primary);
  border: none;
  color: #0f172a;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.btn-send:hover {
  background-color: var(--primary-hover);
  transform: scale(1.05);
}

/* Aperçu fichier avant envoi */
.attachment-preview {
  margin-bottom: 0.5rem;
}

.preview-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-size: 0.82rem;
}

.preview-filename {
  font-weight: 500;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-filesize {
  color: var(--text-dim);
}

.btn-close-sm {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.1rem;
  margin-left: 0.3rem;
}

.btn-close-sm:hover {
  color: var(--danger);
}

/* ==========================================================================
   MODALES ET LIGHTBOX
   ========================================================================== */
.modal-backdrop,
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.5rem;
}

.modal-box {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.2rem;
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 1.6rem;
  color: var(--text-muted);
  cursor: pointer;
}

.btn-close-modal:hover {
  color: var(--text-main);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.input-group-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.input-group-row input {
  flex: 1;
}

.members-list-container {
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.5);
}

.members-list {
  list-style: none;
}

.member-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.member-item:last-child {
  border-bottom: none;
}

.member-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.member-role-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(245, 158, 11, 0.2);
  color: var(--primary);
  font-weight: 600;
}

.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 85vh;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 2.5rem;
  cursor: pointer;
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive Mobile */
@media (max-width: 768px) {
  .sidebar {
    width: 80px;
    min-width: 80px;
  }
  .brand-small h2,
  .user-info,
  .sidebar-search,
  .groups-title,
  .group-item-content {
    display: none;
  }
  .user-profile-badge {
    justify-content: center;
    padding: 0.75rem;
  }
  .group-item {
    justify-content: center;
  }
  .chat-header {
    padding: 0 1rem;
  }
  .chat-composer {
    padding: 0.75rem 1rem;
  }
}
