:root{
  --bg:#0b0c10;
  --panel: rgba(255,255,255,0.06);
  --panel2: rgba(255,255,255,0.09);
  --text: rgba(255,255,255,0.92);
  --muted: rgba(255,255,255,0.65);
  --border: rgba(255,255,255,0.12);
  --shadow: 0 10px 30px rgba(0,0,0,0.45);

  --primary:#22c55e;
  --danger:#ef4444;

  --radius:18px;
  --sans: system-ui, -apple-system, Segoe UI, Roboto, Arial;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* ✅ fallback JS iOS */
  --vh: 1vh;
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  font-family:var(--sans);
  background: var(--bg);
  color:var(--text);
}

/* ===== Header ===== */
.topbar{
  position: sticky;
  top: 0;
  z-index: 50;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;

  background: rgba(12,13,18,0.92);
  border-bottom: 1px solid var(--border);
}

.brand{
  display:flex;
  align-items:center;
  gap: 10px;
  min-width: 0;
}

.logo{
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display:grid;
  place-items:center;
  background: var(--primary);
  color: #041408;
  font-weight: 900;
  flex: 0 0 auto;
}

.brand-text{min-width:0;}
.brand-text h1{
  margin:0;
  font-size: 18px;
  line-height: 1;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}
.brand-text p{
  margin:2px 0 0 0;
  font-size:12px;
  color: var(--muted);
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

/* ===== Menu button (☰ -> ✕) ===== */
.icon-btn{
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.06);
  display:grid;
  place-items:center;
  cursor:pointer;
}

.burger{
  width: 18px;
  height: 14px;
  position: relative;
  display:block;
  *

}
.burger, .burger::before, .burger::after{
  content:"";
  position:absolute;
  left:0; right:0;
  height:2px;
  background: rgba(255,255,255,0.78);
  border-radius: 999px;
  transition: transform .18s ease, top .18s ease, opacity .18s ease;
}
.burger{ top:6px; }
.burger::before{ top:-6px; }
.burger::after{ top:6px; }

.icon-btn.open .burger{ opacity:0; }
.icon-btn.open .burger::before{
  top:0;
  transform: rotate(45deg);
  opacity:1;
}
.icon-btn.open .burger::after{
  top:0;
  transform: rotate(-45deg);
  opacity:1;
}

/* ===== Drawer ===== */
.overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 60;
}

.drawer{
  position: fixed;
  top:0;
  right:0;
  height:100%;
  width: min(360px, 88vw);
  background: rgba(12,13,18,0.97);
  border-left: 1px solid var(--border);
  z-index: 70;

  transform: translateX(100%);
  transition: transform .18s ease;
  display:flex;
  flex-direction: column;
  padding: 12px;
}

.drawer.open{ transform: translateX(0); }

.drawer-head{
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.drawer-title{
  font-weight: 900;
  letter-spacing: .2px;
}

.drawer-body{
  padding-top: 12px;
  display:grid;
  gap: 12px;
}

.control{
  display:grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.control select{
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  outline: none;
}

.row{
  display:flex;
  gap: 10px;
}
.row .btn{ flex: 1; }

.help{
  color: var(--muted);
  font-size: 13px;
  border: 1px dashed rgba(255,255,255,0.18);
  border-radius: var(--radius);
  padding: 10px 12px;
}

/* ===== Buttons ===== */
.btn{
  border:1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 14px;
  cursor:pointer;
  user-select:none;
}

.btn-primary{
  background: var(--primary);
  color:#041408;
  font-weight: 900;
  border-color: rgba(34,197,94,0.35);
}

.btn-ghost{ color: var(--muted); }

.btn-danger{
  border-color: rgba(239,68,68,0.35);
  background: rgba(239,68,68,0.14);
}

/* ===== Main layout (✅ iOS fix) ===== */
.main{
  /* fallback JS: --vh * 100 = vraie hauteur visible */
  height: calc((var(--vh) * 100) - 66px);
  display:grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
}

@supports (height: 100dvh){
  .main{ height: calc(100dvh - 66px); }
}
@supports (height: 100svh){
  .main{ height: calc(100svh - 66px); }
}

/* ===== Chat area ===== */
.chat{
  overflow:auto;
  overflow-x: hidden; /* IMPORTANT : pas de scroll horizontal global */
  padding: 12px;
  min-height: 0;
}

/* ===== Messages ===== */
.msg{ display:grid; gap: 6px; margin: 10px 0; }
.msg.you{ justify-items: end; }
.meta{
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  display:flex;
  align-items:center;
  gap: 8px;
}

.badge{
  padding: 4px 10px;
  border-radius: 999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.05);
}

.bubble{
  max-width: 92%;
  border-radius: var(--radius);
  padding: 12px 14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.06);
  line-height: 1.35;
  word-break: break-word;
}

.msg.you .bubble{ background: rgba(59,130,246,0.12); border-color: rgba(59,130,246,0.22); }
.msg.ai .bubble{ background: rgba(34,197,94,0.10); border-color: rgba(34,197,94,0.22); }
.msg.err .bubble{ background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.22); }

/* ===== Composer (✅ toujours visible) ===== */
.composer{
  position: sticky;
  bottom: 0;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: rgba(12,13,18,0.92);
  z-index: 10;
}

.composer-inner{
  display:grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items:end;
}

textarea{
  width:100%;
  resize:none;
  border-radius: var(--radius);
  border:1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  padding: 12px 12px;

  font-size: 16px; /* IMPORTANT iOS : évite zoom */
  line-height: 1.3;

  max-height: 140px;
  overflow:auto;
  outline:none;
}

.statusline{
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* ===== Markdown ===== */
.md p{ margin: .45em 0; }
.md ul, .md ol{ margin: .45em 0 .45em 1.15em; }
.md li{ margin: .2em 0; }
.md a{ color:#93c5fd; text-decoration: none; }
.md a:hover{ text-decoration: underline; }

.md code{
  font-family: var(--mono);
  font-size: 13px;
  background: rgba(0,0,0,0.25);
  border:1px solid rgba(255,255,255,0.12);
  padding: 2px 6px;
  border-radius: 10px;
}

/* ✅ code blocks: ne déplacent plus la page */
.md pre{
  max-width: 100%;
  overflow-x: auto;                 /* scroll uniquement dans le bloc */
  -webkit-overflow-scrolling: touch;
  margin: .6em 0;
  padding: 12px;
  border-radius: 14px;
  background: rgba(0,0,0,0.35);
  border:1px solid rgba(255,255,255,0.12);
}
.md pre code{
  white-space: pre;
  display:block;
  background: transparent;
  border: none;
  padding: 0;
}