/* --- AJOUT : Importation de la nouvelle police depuis Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700;800&display=swap');

/* --- MODIFIÉ : Nouvelle palette de couleurs et variables --- */
:root {
  --bg: #101218;
  --panel: #191D24;
  --alt: #232833;
  --border: #2E3440;
  --text: #E5E9F0;
  --muted: #8190A5;
  --brand: #FFD234;
  --accent: #5E81AC;
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
}

*{box-sizing:border-box}

/* --- AMÉLIORATION FINALE : Mise en page Flexbox pour une stabilité maximale sur iOS --- */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  
  /* On transforme le body en conteneur Flexbox vertical */
  display: flex;
  flex-direction: column;
  /* On s'assure qu'il prend au minimum toute la hauteur de l'écran */
  min-height: 100vh;
}


/* =================================== */
/* === HEADER ======================== */
/* =================================== */

.topbar{
  position:sticky;
  top:0;
  z-index:10;
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding: 16px 24px;
  background: rgba(16, 18, 24, 0.6);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand{
  font-weight: 800;
  font-size: 1.1rem;
}
.hint{
  display: none;
}


/* =================================== */
/* === CHAT & MESSAGES =============== */
/* =================================== */

/* --- AMÉLIORATION FINALE : On dit au conteneur de chat de prendre toute la place disponible --- */
#chat{
  padding: 24px; 
  display:grid; 
  gap: 16px; 
  max-width:1100px; 
  margin:0 auto;
  width: 100%; /* S'assure qu'il prend la largeur */
  flex-grow: 1; /* C'est la clé : le chat grandit et pousse le footer vers le bas */
}

.msg{display:flex; gap:12px; align-items:flex-start;}

.msg .bubble{
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 16px;
  max-width: 920px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  transition: all 0.2s ease-in-out;
  position: relative;
}
.msg.you .bubble{background:var(--alt); border-color: #3B4252;}
.meta{font-size:12px; color:var(--muted); margin-bottom:8px;}

/* =================================== */
/* === COMPOSER (ZONE DE SAISIE) ===== */
/* =================================== */

.composer{
  position:sticky;
  bottom:0;
  background: rgba(16, 18, 24, 0.6);
  backdrop-filter: saturate(180%) blur(10px);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  /* On retire le flex-shrink pour s'assurer qu'il ne se compresse pas */
  flex-shrink: 0;
}
#composerForm{max-width:1100px; margin:0 auto; display:grid; grid-template-columns:280px 1fr auto; gap:16px; align-items:start;}
@media (max-width:900px){#composerForm{grid-template-columns:1fr}}

/* --- Style général des boutons --- */
.btn, .btn-ghost, .file-btn, button {
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--alt);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-sans);
  font-weight: 500;
  transition: all 0.2s ease;
}
.btn:hover, .btn-ghost:hover, .file-btn:hover, button:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#sendBtn {
  background: var(--brand);
  color: #111;
  border-color: #D8AE27;
  font-weight: 700;
}
#sendBtn:hover {
  background: #FFDE59;
  border-color: var(--brand);
}

button.danger {
  background: #BF616A20;
  border-color: #BF616A;
  color: #E6848E;
}
button.danger:hover {
  background: #BF616A40;
}
.btn-ghost{background:transparent}

.file{display:flex;align-items:center;gap:8px;margin-bottom:8px}
#imageInput{display:none}

.drop-zone{
  position:relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius:14px;
  padding:4px;
  transition: all 0.2s ease;
}
.drop-zone:focus-within, .drop-zone.drag{
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(255, 210, 52, 0.2);
}
#promptInput{
  width:100%;
  background:transparent;
  color:var(--text);
  border:none;
  outline:none;
  padding:12px;
  min-height:80px;
  resize:vertical;
  font-size: 1rem;
}
.dz-hint{font-size:12px; color:var(--muted); padding:0 12px 10px;}

/* === PRÉSENTATION DES IMAGES ======= */

.selected-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(72px,1fr));gap:8px;margin-top:8px}
.sel-tile{
  position:relative;
  border: 1px solid var(--border);
  border-radius:10px;
  overflow:hidden;
  transition: transform 0.2s ease;
  cursor: pointer;
}
.sel-tile:hover { transform: scale(1.05); }
.sel-tile img{width:100%;height:72px;object-fit:cover;display:block}

.sel-x, .sel-badge {
  background: rgba(16, 18, 24, 0.7);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.sel-x{top:4px; right:4px; color:#fff; border-radius:8px; padding:2px 6px; cursor:pointer; font-size:12px; position: absolute;}
.sel-badge{left:4px; top:4px; color:#fff; padding:1px 6px; border-radius:999px; font-size:11px; position: absolute;}

.main-img{
  border: none;
  border-radius:16px;
  overflow:hidden;
  background:#0b0c0f;
  max-height: 420px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.main-img img{width:100%; max-height:420px; height:auto; object-fit:contain; display:block; cursor:zoom-in}

.actions-row {
    margin-top: 12px;
    position: relative;
    background: var(--alt);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--border);
}
.actions-row .btn.primary {
    background: var(--brand);
    color: #111;
    border-color: #D8AE27;
    font-weight: 700;
}

/* === LIGHTBOX ==== */

body.no-scroll { overflow: hidden; }
.lightbox {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(16, 18, 24, 0.7);
  backdrop-filter: blur(8px);
  display: grid; place-items: center; padding: 24px;
}
.lightbox[hidden] { display: none; }

.lightbox-content {
  position: relative; display: flex; justify-content: center; align-items: center;
  width: auto; max-width: 75vw; height: auto; max-height: 75vh;
  padding: 0; background: transparent; border: none;
  border-radius: 14px;
}

#lbImg {
  width: auto; max-width: 100%; height: auto; max-height: 100%;
  display: block; border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  transform: none !important;
  transition: none !important;
}

.lightbox .close {
  position: absolute;
  z-index: 20;
  top: 16px;
  right: 16px;
  background: rgba(16, 18, 24, 0.7); backdrop-filter: blur(5px);
  color: #fff; border: 1px solid rgba(255,255,255,0.2); border-radius: 10px;
  padding: 8px 12px; cursor: pointer; text-decoration: none; font-size: 14px;
  transition: background-color .2s, border-color .2s, color .2s;
}

.lightbox-actions {
    position: absolute;
    bottom: 16px;
    right: 16px;
    z-index: 20;
    display: flex;
    gap: 10px;
}

.lightbox-actions > button,
.lightbox-actions > a {
    background: rgba(16, 18, 24, 0.7);
    backdrop-filter: blur(5px);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 10px;
    padding: 8px 14px;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    font-family: var(--font-sans);
    transition: background-color .2s, border-color .2s, color .2s;
}

.lightbox .close:hover,
.lightbox-actions > button:hover,
.lightbox-actions > a:hover {
  background: var(--brand);
  color: #111;
  border-color: var(--brand);
  transform: none !important;
}


/* === AUTRES STYLES ===== */

.edit-inline{ margin-top:8px; background:var(--alt); border:1px solid var(--border); border-radius:12px; padding:8px; }
.edit-inline textarea{ width:100%; background:transparent; color:var(--text); border:0; outline:none; resize:vertical; min-height:56px; }
.edit-actions{ margin-top:6px; display:flex; gap:8px; justify-content:flex-end; }
.sel-tile.dragging{ opacity: .6; }
.sel-tile.drag-over{ outline: 2px dashed var(--accent); outline-offset: -3px; }
.thumb-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(160px,1fr));gap:8px}
.thumb{background:#0b0c0f;border:1px solid var(--border);border-radius:10px;overflow:hidden;cursor:pointer}
.thumb img{width:100%;display:block}
.small{font-size:12px;color:var(--muted)}
.mention-box{position:absolute; left:12px; bottom:48px; z-index:5; background:#191D24; border:1px solid var(--border); border-radius:10px; padding:6px; min-width:180px; box-shadow:0 8px 30px rgba(0,0,0,.35);}
.mention-box[hidden]{display:none}
.mention-item{padding:6px 8px;border-radius:8px;cursor:pointer;display:flex;align-items:center;gap:8px}
.mention-item:hover,.mention-item.active{background:#2E3440}
.mention-dot{width:18px;height:18px;display:inline-grid;place-items:center;border-radius:999px;background:#3B4252;font-size:11px;color:#dfe6ff}
.prev-strip{display:flex;gap:8px;margin-top:8px;overflow-x:auto;padding-bottom:2px}
.prev-thumb{flex:0 0 auto;width:84px;height:84px;border:1px solid var(--border);border-radius:10px;overflow:hidden;background:#0b0c0f;cursor:pointer}
.prev-thumb img{width:100%;height:100%;object-fit:cover;display:block}
.bubble.loading .main-img{position:relative;filter:saturate(0.6) brightness(0.9)}
.bubble.loading .main-img::after{content:"";position:absolute;inset:0;background:linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(255,255,255,.08) 50%, rgba(0,0,0,0) 100%);animation:shimmer 1.4s infinite}
@keyframes shimmer{0%{transform:translateX(-100%)}100%{transform:translateX(100%)}}
.progress{height:6px;background:#1c2230;border:1px solid var(--border);border-radius:999px;overflow:hidden;margin-top:8px}
.progress .bar{width:40%;height:100%;background:linear-gradient(90deg,var(--accent),#8aa8ff);animation:indet 1.1s infinite ease-in-out}
@keyframes indet{0%{transform:translateX(-100%)}50%{transform:translateX(20%)}100%{transform:translateX(120%)}}
.main-img img, .prev-thumb img { -webkit-user-drag: none; user-select: none; }
.error-bubble{ background: #BF616A40; border-color: #BF616A; color: #E6848E; }
.error-msg{ font-size: 0.9rem; line-height: 1.4; }
.inpaint-toolbar{ display:flex; gap:12px; align-items:center; justify-content:space-between; margin-bottom:8px; flex-wrap: wrap; }
.inpaint-toolbar .tools{ display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.inpaint-stage{ position:relative; width:100%; max-height:72vh; overflow:auto; background:#0e1014; border:1px solid var(--border); border-radius:12px; }
#inpaintImg, #inpaintMask{ display:block; }
#inpaintImg{ width:100%; height:auto; }
#inpaintMask{ position:absolute; left:0; top:0; image-rendering: pixelated; mix-blend-mode: normal; opacity: 0.6; cursor: crosshair; }
.chk{ display:flex; align-items:center; gap:6px; }
.inpaint-prompt-container {display: flex; gap: 8px; align-items: stretch; margin-bottom: 12px;}
#inpaintPromptInput {flex-grow: 1; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 48px; resize: vertical; outline: none; font-size: 14px; line-height: 1.4;}
#inpaintPromptInput::placeholder { color: var(--muted); }
.inpaint-prompt-container .btn.primary {flex-shrink: 0; padding: 10px 16px; min-width: 100px;}
.crop-stage {position: relative; display: flex; justify-content: center; align-items: center; width: 100%; flex-grow: 1; overflow: hidden; user-select: none; cursor: crosshair;}
#cropImg {max-width: 100%; max-height: 100%; object-fit: contain;}
#cropBox {position: absolute; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6); border: 1px dashed #fff; display: none;}
.btn, .btn-ghost, button, .sel-tile, .prev-thumb, .mention-item, .lightbox .close {-webkit-tap-highlight-color: transparent;}
.topbar, .actions-row, .sel-badge, .handle {user-select: none; -webkit-user-select: none;}

/* --- RESPONSIVE --- */
@media (max-width: 900px){
  #chat{ padding: 12px; gap: 10px; }
  .composer{ padding-bottom: calc(12px + env(safe-area-inset-bottom));}

  #composerForm{
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  #composerForm > .center { order: 1; }
  #composerForm > .right  { order: 2; }
  #composerForm > .left   { order: 3; }

  .file{ margin-bottom: 4px; }
  .file-btn{ padding: 10px 12px; }
  #promptInput{ min-height: 80px; font-size: 16px; line-height: 1.4; }
  .dz-hint{ display:none; }
  .selected-list{ grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
  .sel-tile img{ height: 64px; }

  .actions {
     display: grid;
     grid-template-columns: 1fr 1fr;
     gap: 8px;
  }
  .actions #sendBtn {
     grid-column: 1 / -1;
     padding: 14px;
     font-size: 16px;
     font-weight: 700;
  }

  .main-img{ max-height: 240px; }
  .main-img img{ height: 240px; }
  .prev-thumb{ width:72px; height:72px; }
  .mention-box{ left: 8px; right: 8px; bottom: 56px; min-width: auto; }
  .inpaint-toolbar{ flex-direction:column; align-items:flex-start; gap:8px; }
  .inpaint-stage{ max-height:60vh; }
  .inpaint-prompt-container { flex-direction: column; }
  #inpaintPromptInput { font-size: 16px; }
}

/* === BOUTON DE SUPPRESSION === */
.delete-msg-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: rgba(46, 52, 64, 0.5);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  line-height: 1;
  opacity: 1;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
  z-index: 5;
}

.delete-msg-btn:hover {
  background-color: #BF616A;
  color: #fff;
  transform: scale(1.1);
}