/* =================================================================
   MSP DM — Interface
   Design : dark glass, gradients aurora, accents purple/cyan
================================================================= */

:root {
  --bg-base: #060814;
  --bg-card: rgba(20, 22, 38, 0.72);
  --bg-card-hover: rgba(28, 32, 52, 0.82);
  --bg-active: rgba(45, 55, 100, 0.65);
  --bg-input: rgba(8, 10, 22, 0.6);
  --line: rgba(255, 255, 255, 0.06);
  --line-strong: rgba(255, 255, 255, 0.12);
  --text: #f1f3fb;
  --text-mute: #8a93a8;
  --text-soft: #b9c0d3;
  --purple: #8b3dff;
  --purple-2: #6d2ad6;
  --cyan: #18d8ff;
  --pink: #ff4d8a;
  --green: #2ee77c;
  --red: #ff476f;
  --gradient: linear-gradient(135deg, var(--purple) 0%, var(--cyan) 100%);
  --gradient-soft: linear-gradient(135deg, rgba(139,61,255,0.20), rgba(24,216,255,0.18));
  --shadow-deep: 0 20px 60px rgba(0,0,0,0.55);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Aurora background */
#bg-aurora {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(circle at 12% 20%, rgba(139,61,255,0.20), transparent 45%),
    radial-gradient(circle at 88% 75%, rgba(24,216,255,0.16), transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(255,77,138,0.06), transparent 65%),
    var(--bg-base);
}

button { cursor: pointer; font-family: inherit; outline: none; border: 0; color: inherit; }
input, textarea { font-family: inherit; outline: none; }
::selection { background: rgba(139,61,255,0.4); }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.16); }

/* =================================================================
   Layout principal
================================================================= */
#app {
  display: grid;
  grid-template-columns: 240px 340px minmax(0, 1fr);
  height: 100vh;
  gap: 0;
  overflow: hidden;
}

aside, section {
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;       /* permet aux enfants flex:1 de shrink */
  overflow: hidden;
}
section:last-child { border-right: 0; }

/* =================================================================
   Headers de colonne
================================================================= */
.col-hdr {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

#convo-list { flex: 1 1 0; min-height: 0; overflow-y: auto; }
#account-list { flex: 1 1 0; min-height: 0; overflow-y: auto; }
.col-hdr-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.col-hdr h2 {
  margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em;
}

#btn-refresh {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: var(--text-soft);
  transition: all 0.18s;
}
#btn-refresh:hover { background: rgba(255,255,255,0.10); color: var(--text); }
#btn-refresh.busy { color: var(--cyan); animation: spin 1.4s linear infinite; }
@keyframes spin { 0%{transform:rotate(0)} 100%{transform:rotate(360deg)} }

.search-wrap {
  position: relative; display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 12px; color: var(--text-mute); pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 13px;
  transition: border-color 0.15s, background 0.15s;
}
#search-input:focus { border-color: var(--purple); background: rgba(8,10,22,0.85); }
#search-input::placeholder { color: var(--text-mute); }

/* =================================================================
   Brand (sidebar comptes)
================================================================= */
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 18px 20px;
  border-bottom: 1px solid var(--line);
}
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--gradient);
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px; color: white;
  box-shadow: 0 6px 20px rgba(139,61,255,0.4);
}
.brand-name { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--text-mute); margin-top: 1px; }

/* =================================================================
   Liste des comptes
================================================================= */
#account-list {
  list-style: none; margin: 0; padding: 8px;
  flex: 1; overflow-y: auto;
}
#account-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.12s;
  position: relative;
}
#account-list li:hover { background: var(--bg-card-hover); }
#account-list li.active {
  background: var(--gradient-soft);
  box-shadow: inset 0 0 0 1px rgba(139,61,255,0.35);
}
#account-list li .avatar { width: 30px; height: 30px; font-size: 13px; }
#account-list li .name {
  flex: 1; font-weight: 600; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#account-list li .del {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 6px;
  background: transparent; color: var(--text-mute);
  opacity: 0; transition: all 0.15s;
  font-size: 16px; line-height: 1;
}
#account-list li:hover .del { opacity: 1; }
#account-list li .del:hover { background: rgba(255,71,111,0.18); color: var(--red); }

.add-btn {
  margin: 8px 12px 14px; padding: 11px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05);
  color: var(--text-soft);
  font-weight: 600; font-size: 13px;
  border: 1px dashed var(--line-strong);
  transition: all 0.18s;
}
.add-btn:hover {
  background: var(--gradient-soft);
  color: var(--text);
  border-color: rgba(139,61,255,0.4);
}
.add-btn .plus {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gradient);
  display: grid; place-items: center;
  font-weight: 700; color: white; font-size: 14px; line-height: 1;
}

/* =================================================================
   Avatars (initiales colorées)
================================================================= */
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: white;
  flex-shrink: 0;
  background: var(--gradient);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.avatar-lg { width: 44px; height: 44px; font-size: 16px; }

/* =================================================================
   Liste des conversations
================================================================= */
#convo-list {
  flex: 1; overflow-y: auto; padding: 6px 8px 10px;
}
#convo-list .empty {
  padding: 60px 24px; text-align: center;
  color: var(--text-mute); font-size: 13px; line-height: 1.5;
}
.convo-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.12s;
  position: relative;
}
.convo-item:hover { background: var(--bg-card-hover); }
.convo-item.active {
  background: var(--gradient-soft);
  box-shadow: inset 0 0 0 1px rgba(139,61,255,0.35);
}
.convo-body { flex: 1; min-width: 0; }
.convo-row1 {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.convo-name {
  font-weight: 600; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.convo-ts {
  font-size: 11px; color: var(--text-mute); flex-shrink: 0;
}
.convo-row2 {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 3px;
}
.convo-preview {
  flex: 1; min-width: 0;
  font-size: 12.5px; color: var(--text-mute);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.convo-badge {
  background: var(--gradient);
  color: white;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(139,61,255,0.4);
  min-width: 20px; text-align: center;
}
.convo-item.unread .convo-name { color: var(--text); font-weight: 700; }
.convo-item.unread .convo-preview { color: var(--text-soft); font-weight: 500; }

/* =================================================================
   Header thread
================================================================= */
.thread-hdr {
  padding: 16px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.thread-info { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.thread-action {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border, rgba(255,255,255,.12));
  background: rgba(255,170,80,.10);
  color: #ffb060;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.thread-action:hover:not(:disabled) { background: rgba(255,170,80,.20); color: #ffd090; }
.thread-action:disabled { opacity: .55; cursor: progress; }
.thread-meta { flex: 1; min-width: 0; }
#thread-title {
  margin: 0; font-size: 16px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-sub {
  font-size: 12px; color: var(--text-mute); margin-top: 2px;
}

/* =================================================================
   Messages (thread)
================================================================= */
#messages {
  flex: 1 1 0;
  min-height: 0;              /* flex shrink fix : empêche que ça pousse le composer hors champ */
  overflow-y: auto;
  padding: 22px;
  display: flex; flex-direction: column; gap: 4px;
}
#messages .empty {
  margin: auto; text-align: center; padding: 40px;
  color: var(--text-mute); font-size: 14px;
}
.day-sep {
  align-self: center;
  font-size: 11px; font-weight: 600;
  color: var(--text-mute);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 10px 14px; margin: 14px 0 6px;
  background: rgba(255,255,255,0.04);
  border-radius: 999px;
}
.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 18px;
  word-wrap: break-word;
  position: relative;
  font-size: 14px;
  line-height: 1.45;
}
.msg.new { animation: pop-in 0.22s ease-out; }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.me {
  align-self: flex-end;
  background: var(--gradient);
  color: white;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 14px rgba(139,61,255,0.35);
}
.msg.them {
  align-self: flex-start;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg .who {
  font-size: 11px; font-weight: 700;
  margin-bottom: 3px;
  color: var(--cyan);
  letter-spacing: 0.02em;
}
.msg .body { white-space: pre-wrap; }
.msg .ts {
  font-size: 10px; opacity: 0.6; margin-top: 4px;
}
.msg.me .ts { color: rgba(255,255,255,0.85); }
.msg.them .ts { color: var(--text-mute); }
.msg.sending { opacity: 0.5; }
.msg.failed {
  background: linear-gradient(135deg, #b03a4a, #6d1c2c) !important;
  color: white;
  box-shadow: 0 4px 14px rgba(255,71,111,0.4) !important;
}
.msg.failed .ts { color: #ffd2dc; }

/* Group consecutive messages from same sender */
.msg.grouped { margin-top: 1px; }
.msg.grouped.me { border-top-right-radius: 8px; border-bottom-right-radius: 6px; }
.msg.grouped.them { border-top-left-radius: 8px; border-bottom-left-radius: 6px; }
.msg.grouped .who { display: none; }

/* =================================================================
   Composer
================================================================= */
#composer {
  flex-shrink: 0;             /* le composer reste toujours visible */
  display: flex; gap: 10px; align-items: flex-end;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: rgba(8,10,22,0.4);
}
#composer-text {
  flex: 1;
  resize: none;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--bg-input);
  color: var(--text);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.4;
  max-height: 140px;
  transition: border-color 0.15s, background 0.15s;
}
#composer-text::placeholder { color: var(--text-mute); }
#composer-text:focus {
  border-color: rgba(139,61,255,0.5);
  background: rgba(8,10,22,0.85);
}
#btn-send {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--gradient);
  color: white;
  display: grid; place-items: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(139,61,255,0.35);
  transition: transform 0.12s, box-shadow 0.12s;
}
#btn-send:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(139,61,255,0.5); }
#btn-send:active { transform: translateY(0); }
#btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* =================================================================
   Modale "Ajouter un compte"
================================================================= */
dialog {
  background: rgba(15,18,32,0.95);
  backdrop-filter: blur(20px);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  padding: 26px 28px;
  min-width: 360px;
  box-shadow: var(--shadow-deep);
}
dialog::backdrop { background: rgba(0,0,0,0.6); backdrop-filter: blur(8px); }
dialog h3 {
  margin: 0 0 4px; font-size: 18px; font-weight: 700; letter-spacing: -0.01em;
}
.dlg-sub { color: var(--text-mute); font-size: 13px; margin: 0 0 18px; }
dialog label {
  display: block; margin-bottom: 12px;
  font-size: 12px; font-weight: 600; color: var(--text-soft);
  letter-spacing: 0.02em;
}
dialog input {
  display: block; width: 100%; margin-top: 6px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px; font-weight: 500;
  transition: border-color 0.15s;
}
dialog input:focus { border-color: var(--purple); }
dialog .row {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px;
}
dialog button {
  padding: 10px 18px; border-radius: 10px; font-weight: 700;
  font-size: 13px; transition: all 0.15s;
}
dialog button.ghost {
  background: rgba(255,255,255,0.06); color: var(--text-soft);
}
dialog button.ghost:hover { background: rgba(255,255,255,0.12); color: var(--text); }
dialog button.primary {
  background: var(--gradient); color: white;
  box-shadow: 0 4px 14px rgba(139,61,255,0.35);
}
dialog button.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(139,61,255,0.5); }

.err {
  color: #ff8a9c; font-size: 13px;
  margin-top: 12px; min-height: 18px;
  padding-left: 4px;
}

/* =================================================================
   Etats vides / loading
================================================================= */
/* =================================================================
   Responsive
================================================================= */
@media (max-width: 900px) {
  #app { grid-template-columns: 60px 280px minmax(0, 1fr); }
  .brand { padding: 18px 8px; justify-content: center; }
  .brand-text { display: none; }
  .add-btn { padding: 11px 6px; }
  .add-btn span:not(.plus) { display: none; }
  #account-list li { justify-content: center; padding: 8px; }
  #account-list li .name { display: none; }
  #account-list li .del { position: absolute; top: -2px; right: -2px; background: var(--bg-card); }
}
@media (max-width: 640px) {
  #app { grid-template-columns: 0 240px minmax(0, 1fr); }
  #accounts { display: none; }
}

.skeleton {
  display: flex; flex-direction: column; gap: 8px; padding: 8px;
}
.skeleton .row {
  height: 56px; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
