/* FuckChatControl — feuille de style unique, aucune ressource externe. */

:root {
  --bg: #0d1117;
  --bg-2: #131a24;
  --bg-3: #1a2330;
  --line: #23303f;
  --text: #e6edf3;
  --dim: #8b98a5;
  --accent: #2ea6ff;
  --accent-2: #1b7fd4;
  --mine: #1f4d75;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* Les conteneurs ci-dessous declarent display:flex/grid, ce qui l'emporterait
   sur l'attribut [hidden]. On tranche une bonne fois pour toutes. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  overflow: hidden;
  overscroll-behavior: none;      /* pas de "tirer pour rafraichir" en pleine conversation */
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* Sur mobile, 100vh deborde sous la barre d'URL : dvh suit la hauteur reelle. */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

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

button {
  cursor: pointer;
  border: none;
  background: var(--bg-3);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  transition: background .15s;
}
button:hover { background: #22303f; }
button.primary { background: var(--accent); color: #04121e; font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.icon { background: none; padding: 6px 8px; color: var(--dim); font-size: 16px; }
button.icon:hover { background: var(--bg-3); color: var(--text); }
button.danger { background: #3a1c1c; color: #ff9b95; }
button.danger:hover { background: #4d2222; }

input, textarea, select {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

/* ---------- authentification ---------- */

.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
  overflow-y: auto;
}
.auth-card {
  width: min(440px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
}
.brand { margin: 0 0 6px; font-size: 26px; letter-spacing: -.5px; }
.brand span { color: var(--accent); }
.tagline { margin: 0 0 20px; color: var(--dim); font-size: 14px; line-height: 1.5; }

.bio-unlock {
  width: 100%; padding: 14px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.bio-unlock::before { content: '☝'; font-size: 18px; }
.bio-note { text-align: center; margin: 0 0 16px; }

.tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.tab { flex: 1; background: transparent; border: 1px solid var(--line); }
.tab.active { background: var(--bg-3); border-color: var(--accent); color: var(--accent); }

#auth-form label { display: block; margin-bottom: 14px; }
#auth-form label span { display: block; margin-bottom: 6px; font-size: 13px; color: var(--dim); }
#auth-submit { width: 100%; padding: 12px; }

.warn {
  background: #2a2210;
  border: 1px solid #4a3c14;
  color: #e3c56b;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 14px;
}
.error {
  color: #ffb3ae;
  background: #3a1c1c;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 14px 0 0;
}

.credit {
  text-align: center; font-size: 11px; color: var(--dim);
  opacity: .45; margin: 18px 0 0; letter-spacing: .3px;
}

.readonly-note {
  padding: 14px 16px; border-top: 1px solid var(--line); background: var(--bg-2);
  color: var(--dim); font-size: 13px; text-align: center;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

.how { margin-top: 20px; font-size: 13px; color: var(--dim); }
.how summary { cursor: pointer; }
.how ul { margin: 10px 0 0; padding-left: 18px; line-height: 1.7; }

/* ---------- structure application ---------- */

.app { display: flex; height: 100%; }

.sidebar {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
}

.me { display: flex; align-items: center; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.me-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.me-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; color: var(--dim); }
.status.online { color: var(--ok); }
.status.offline { color: var(--bad); }

.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7a3fd4);
  display: grid; place-items: center;
  font-weight: 700; color: #04121e; flex-shrink: 0;
  text-transform: uppercase;
}
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }

.actions { display: flex; gap: 8px; padding: 12px 14px 8px; }
.actions button { flex: 1; font-size: 13px; }

#search { margin: 0 14px 10px; width: calc(100% - 28px); }

.conversations { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; }
.conversations li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 10px; cursor: pointer;
}
.conversations li:hover { background: var(--bg-3); }
.conversations li.active { background: var(--bg-3); box-shadow: inset 2px 0 0 var(--accent); }
.conv-text { flex: 1; min-width: 0; }
.conv-title { display: flex; align-items: center; gap: 6px; }
.conv-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.conv-last { font-size: 12.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 10px; padding: 1px 6px; border-radius: 20px; border: 1px solid var(--line); color: var(--dim); }
.pill.ok { color: var(--ok); border-color: #1f4d2c; }
.pill.bad { color: var(--bad); border-color: #4d2222; }
.unread { background: var(--accent); color: #04121e; font-size: 11px; font-weight: 700;
          border-radius: 20px; padding: 1px 7px; }

/* ---------- conversation ---------- */

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-inner { display: flex; flex-direction: column; height: 100%; }
.empty { flex: 1; display: grid; place-content: center; text-align: center; color: var(--dim); gap: 4px; }
.dim { color: var(--dim); font-size: 13px; }

.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.chat-header > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-header .sub { font-size: 12px; color: var(--dim); }
/* le titre et le sous-titre tiennent sur une ligne, quelle que soit la largeur */
.chat-header strong, .chat-header .sub {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.back { display: none; }

.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: #12331f; color: var(--ok); border: 1px solid #1f4d2c;
}

.messages { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 6px; }

.msg { max-width: min(620px, 78%); padding: 8px 12px; border-radius: var(--radius); background: var(--bg-3); align-self: flex-start; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg .who { font-size: 12px; color: var(--accent); margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.msg .meta { font-size: 11px; color: var(--dim); margin-top: 3px; text-align: right; }
.msg.failed { outline: 1px solid var(--bad); }
.msg .file { display: flex; align-items: center; gap: 10px; }
.msg .file a { color: var(--accent); }
.msg progress { width: 100%; height: 4px; }

.day { align-self: center; font-size: 11px; color: var(--dim); background: var(--bg-2);
       padding: 3px 10px; border-radius: 20px; margin: 8px 0; }

.banner {
  margin: 0 16px 8px; padding: 10px 12px; border-radius: 8px; font-size: 13px;
  background: #2a2210; border: 1px solid #4a3c14; color: #e3c56b;
}
.banner.bad { background: #3a1c1c; border-color: #5a2626; color: #ffb3ae; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--bg-2); }
.composer textarea { resize: none; max-height: 160px; }
.send { background: var(--accent); color: #04121e; width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; }
.send:hover { background: var(--accent-2); }

/* ---------- enregistrement vocal ---------- */

.recorder {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-top: 1px solid var(--line); background: var(--bg-2);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.recorder #rec-time { font-variant-numeric: tabular-nums; font-size: 16px; min-width: 48px; }
.rec-hint { color: var(--dim); font-size: 13px; flex: 1; }
.rec-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--bad);
  animation: blink 1s steps(2, start) infinite; flex-shrink: 0;
}
@keyframes blink { 50% { opacity: .25; } }

.msg.missed-call { background: #3a1c1c; }
.msg .missed { display: flex; align-items: center; gap: 8px; color: #ffb3ae; }

.msg .voice { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.msg .voice audio { width: 100%; height: 36px; }
.msg .voice-time { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }

@media (max-width: 780px) {
  .rec-hint { display: none; }
}

/* ---------- panneau lateral ---------- */

.panel { width: 320px; flex-shrink: 0; border-left: 1px solid var(--line); background: var(--bg-2); overflow-y: auto; }
.panel header, .modal-card header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.panel #panel-body { padding: 16px; }

.field { margin-bottom: 16px; }
.field-label { font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.safety {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px; line-height: 1.9; letter-spacing: 1px;
  background: var(--bg-3); padding: 12px; border-radius: 8px; word-spacing: 8px;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row button { flex: 1; min-width: 120px; }
.member { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.member span { flex: 1; }

/* ---------- modale ---------- */

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 20px; z-index: 40; }
.modal-card { width: min(460px, 100%); background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; max-height: 86vh; overflow: auto; }
.modal-card #modal-body { padding: 16px; }
.check { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.check input { width: auto; }

/* ---------- appel audio / video ---------- */

.call {
  position: fixed; inset: 0; z-index: 60; background: #05080c;
  display: flex; align-items: center; justify-content: center;
}
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #05080c; }
.call-local {
  position: absolute; right: 16px; border-radius: 12px; object-fit: cover;
  width: 132px; height: 186px; background: #000; border: 1px solid var(--line);
  top: calc(16px + env(safe-area-inset-top));
  transform: scaleX(-1); /* effet miroir, comme une glace */
}

.call-overlay {
  position: relative; z-index: 1; width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(40px + env(safe-area-inset-top)) 20px calc(36px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(5,8,12,.75) 0%, transparent 32%, transparent 58%, rgba(5,8,12,.85) 100%);
  pointer-events: none;
}
.call-overlay > * { pointer-events: auto; }

.call-who { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.call-who strong { font-size: 22px; }
.call-who span { color: var(--dim); font-size: 14px; }
.call-secure { color: var(--ok) !important; font-size: 12.5px !important; }
.avatar.big { width: 96px; height: 96px; font-size: 34px; margin-bottom: 8px; }

.call-controls { display: flex; gap: 16px; align-items: center; }
.round {
  width: 62px; height: 62px; border-radius: 50%; font-size: 24px;
  background: rgba(255,255,255,.14); display: grid; place-items: center;
  backdrop-filter: blur(8px);
}
.round:hover { background: rgba(255,255,255,.24); }
.round.off { background: #fff; color: #05080c; }
.round.hangup { background: var(--bad); }
.round.hangup:hover { background: #ff6b62; }
.round.accept { background: var(--ok); animation: pulse 1.4s ease-in-out infinite; }
/* repondre a un appel video sans allumer sa camera */
.round.accept-audio { background: #1f6f3c; }
.round.accept-audio::after {
  content: ''; position: absolute; width: 2px; height: 34px;
  background: #fff; transform: rotate(45deg); opacity: .85;
}
.round.accept-audio { position: relative; overflow: hidden; }
@keyframes pulse { 50% { transform: scale(1.09); } }

/* ---------- ecran de confidentialite ---------- */

.privacy-screen {
  position: fixed; inset: 0; z-index: 90;
  background: var(--bg);
  display: grid; place-items: center;
}
.privacy-mark { font-size: 48px; opacity: .35; }

/* ---------- bandeau de mise a jour ---------- */

.update-bar {
  position: fixed; z-index: 70;
  left: 12px; right: 12px; top: calc(12px + env(safe-area-inset-top));
  margin: 0 auto; max-width: 460px;
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-3); border: 1px solid var(--accent);
  border-radius: 10px; padding: 10px 12px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.update-bar span { flex: 1; }
.update-bar button { padding: 6px 12px; }

/* ---------- toasts ---------- */

.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--bg-3); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; font-size: 13px; max-width: 340px;
  animation: slide .2s ease;
}
.toast.bad { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } }

/* ---------- mobile ---------- */

@media (max-width: 780px) {
  .sidebar { width: 100%; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .chat { display: none; }
  .panel { position: fixed; inset: 0; width: 100%; z-index: 30; }
  .back { display: block; }
  .msg { max-width: 88%; }

  /* encoche et barre d'accueil : on ne passe pas dessous */
  .me { padding-top: calc(14px + env(safe-area-inset-top)); }
  .chat-header { padding-top: calc(12px + env(safe-area-inset-top)); }
  .composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .conversations { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .panel header { padding-top: calc(14px + env(safe-area-inset-top)); }

  /* les notifications ne doivent pas recouvrir la zone de saisie */
  .toasts { left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  /* cibles tactiles confortables */
  button.icon { padding: 10px 12px; font-size: 18px; }
  .conversations li { padding: 12px 10px; }
  .call-local { width: 104px; height: 148px; }
  .round { width: 58px; height: 58px; }
  .call-controls { gap: 12px; }
}

/* iOS zoome sur les champs dont la police est inferieure a 16 px */
@media (max-width: 780px) and (hover: none) {
  input, textarea, select { font-size: 16px; }
}
