/* =============================================================================
   travel-web — UI minimale façon claude.ai (light par défaut, dark optionnel)
   Palette beaucoup plus sobre : pas d'accents envahissants, bulles user en
   gris doux, assistant sans bulle (texte sur fond direct).
   ============================================================================= */

/* ------------------------------ Light theme ----------------------------- */
:root {
  --bg:           #faf9f5;     /* fond principal warm cream */
  --bg-side:      #f4f2eb;     /* sidebar, légèrement plus dense */
  --bg-elev:      #ffffff;     /* composer, cards */
  --bg-hover:     #ecebe3;     /* hover row sidebar */
  --bg-active:    #e6e3d8;     /* session active */
  --bg-user:      #ecebe3;     /* bulle utilisateur */
  --border:       #e7e3d6;
  --border-strong:#d6cfbc;
  --text:         #1f1d1a;
  --text-soft:    #4a463f;
  --muted:        #8e8779;
  --accent:       #c96442;     /* utilisé avec parcimonie : liens + send */
  --shadow:       0 1px 2px rgba(0,0,0,0.04);
  --code-bg:      #efece2;
  --code-text:    #3b3934;
  --error:        #c0392b;
  --focus-ring:   rgba(201,100,66,0.25);
}

/* ------------------------------ Dark theme ------------------------------ */
:root[data-theme="dark"] {
  --bg:           #1f1e1c;
  --bg-side:      #181715;
  --bg-elev:      #2a2825;
  --bg-hover:     #2a2825;
  --bg-active:    #34322e;
  --bg-user:      #2f2d29;
  --border:       #34322e;
  --border-strong:#44423d;
  --text:         #ecebe4;
  --text-soft:    #c4c0b5;
  --muted:        #807a6f;
  --accent:       #d97757;
  --shadow:       0 1px 2px rgba(0,0,0,0.3);
  --code-bg:      #2a2825;
  --code-text:    #ecebe4;
  --error:        #e74c3c;
  --focus-ring:   rgba(217,119,87,0.32);
}

/* ------------------------------ Base ----------------------------------- */
* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Inter",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.muted { color: var(--muted); }
.error { color: var(--error); margin: 0; font-size: 0.85rem; }
.hidden { display: none !important; }
.ml-auto { margin-left: auto; }

/* Garde-fou : l'attribut HTML `hidden` doit toujours gagner sur les
   display:flex / display:grid posés par `.screen-center` / `.app`,
   sinon le login reste visible au-dessus de l'app après auth. */
[hidden] { display: none !important; }

button, input, textarea {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; background: transparent; border: none; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

input, textarea {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ------------------------------ Login ---------------------------------- */
.screen-center {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 26px;
  width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
}
.card .logo { font-size: 1.8rem; }
.card h1 { margin: 2px 0 0; font-size: 1.2rem; font-weight: 600; }
.card p { margin: 0 0 4px; font-size: 0.88rem; }
.card button[type="submit"] {
  background: var(--text); color: var(--bg);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 500;
  font-size: 0.92rem;
  transition: opacity 0.12s;
}
.card button[type="submit"]:hover { opacity: 0.85; }

/* ============================== App layout ==============================
   Layout en position:absolute (pas de CSS Grid). Plus prévisible : la sidebar
   est à gauche avec une largeur fixe via --sidebar-w, le chat occupe tout
   ce qui reste. Quand la sidebar est fermée, elle glisse à gauche
   (translateX -100%) et le chat passe en left: 0. */
.app {
  position: relative;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ------------------------------ Sidebar -------------------------------- */
.sidebar {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: var(--sidebar-w, 260px);
  min-width: 260px;            /* assez large pour "Nouvelle conversation" */
  background: var(--bg-side);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  z-index: 5;
  transition: transform 0.18s ease-out;
}
.app.sidebar-closed .sidebar {
  transform: translateX(-100%);
}
.sidebar-top {
  padding: 12px 10px 6px;
}
/* Gros bouton "Nouvelle conversation" labellé, comme dans Claude */
.btn-new-chat {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
}
.btn-new-chat:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.sidebar-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 14px 14px 6px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.icon-btn-mini {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 5px;
  background: transparent;
  border: none;
  color: var(--muted);
}
.icon-btn-mini:hover { background: var(--bg-hover); color: var(--text); }
.sessions {
  list-style: none; margin: 0; padding: 0 6px;
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.sessions li {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.88rem;
  min-width: 0;
  transition: background 0.1s;
}
.sessions li:hover { background: var(--bg-hover); }
.sessions li.active {
  background: var(--bg-active);
  font-weight: 500;
}
.sessions li .session-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.sessions li .session-del {
  opacity: 0;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
  background: transparent;
  border: none;
}
.sessions li:hover .session-del { opacity: 0.7; }
.sessions li .session-del:hover { color: var(--error); opacity: 1; background: var(--bg); }
.sessions-empty {
  padding: 12px 14px;
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
}
.sidebar-foot {
  display: flex; gap: 2px;
  padding: 8px;
  border-top: 1px solid var(--border);
}

/* Toggle sidebar dans le chat-head : toujours visible, plus gros */
.toggle-sidebar-btn {
  width: 34px; height: 34px;
  flex-shrink: 0;
}

/* Icon buttons (sobres) */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 7px;
  color: var(--text-soft);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* Poignée de redimensionnement (4px sur le bord droit) */
.resize-handle {
  position: absolute; top: 0; right: -2px; bottom: 0;
  width: 4px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.12s;
  z-index: 5;
}
.resize-handle:hover, body.resizing .resize-handle {
  background: var(--border-strong);
}
body.resizing { cursor: col-resize; user-select: none; }
body.resizing * { user-select: none !important; }
body.resizing .app { transition: none; }

/* ============================== Chat ==================================== */
.chat {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  left: var(--sidebar-w, 260px);
  display: flex; flex-direction: column;
  background: var(--bg);
  transition: left 0.18s ease-out;
  min-width: 0;
}
.app.sidebar-closed .chat { left: 0; }
.chat-head {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  min-height: 44px;
  border-bottom: 1px solid transparent;
}
.chat-title {
  font-size: 0.92rem;
  color: var(--text-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Zone messages : largeur lisible, centrée */
.messages {
  flex: 1; overflow-y: auto;
  padding: 14px 18px 8px;
  display: flex; flex-direction: column;
  gap: 18px;
}
.messages > * {
  max-width: 720px; width: 100%;
  margin-left: auto; margin-right: auto;
}

/* État vide : titre + composer GROUPÉS et centrés verticalement.
   Les auto-margins sandwichent le bloc (empty-title + composer) au centre :
   - empty-title { margin-top: auto } pousse tout depuis le haut
   - composer    { margin-bottom: auto } pousse depuis le bas */
.app.is-empty .messages { display: none; }
.app.is-empty .empty-title { margin-top: auto; }
.app.is-empty .composer  { margin-bottom: auto; padding-top: 0; }
.app.is-empty .empty-title {
  display: block;
  text-align: center;
  font-size: 1.55rem;
  color: var(--text-soft);
  font-weight: 500;
  margin-bottom: 22px;
}
.empty-title { display: none; }

/* ----- Messages bubbles ----- */
.msg { display: flex; flex-direction: column; }

/* User : .msg.user est la rangée pleine largeur (720px max) qui aligne sa
   bulle interne à droite. La bulle .user-bubble s'ajuste au contenu (jusqu'à
   75% de la rangée) — donc plus de bandeau full-width disgracieux pour un
   message court. */
.msg.user {
  flex-direction: row;
  justify-content: flex-end;
}
.user-bubble {
  background: var(--bg-user);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 18px;       /* uniformément arrondi, plus de "tail" en bas */
  max-width: 75%;
  width: fit-content;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 0.94rem;
  white-space: pre-wrap;
}

.msg.assistant {
  align-self: stretch; width: 100%;
  padding: 4px 0 2px;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.stream-status {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 6px;
}
.stream-status:empty { display: none; }
.tools { font-size: 0.72rem; color: var(--muted); margin-top: 10px; }

/* Bannière affichée quand la réponse a été tronquée (timeout proxy / coupure).
   Permet de relancer la même question d'un clic. */
.stream-banner {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg-side);
  font-size: 0.85rem;
  color: var(--text-soft);
}
.stream-banner .banner-retry {
  margin-left: auto;
  padding: 5px 12px;
  border-radius: 7px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.82rem;
  border: none;
}
.stream-banner .banner-retry:hover { opacity: 0.85; }

/* ----- Markdown rendu ----- */
.stream-text > :first-child { margin-top: 0; }
.stream-text > :last-child { margin-bottom: 0; }

.stream-text h1, .stream-text h2, .stream-text h3, .stream-text h4 {
  font-weight: 600;
  line-height: 1.3;
  margin: 16px 0 6px;
  color: var(--text);
}
.stream-text h1 { font-size: 1.25rem; }
.stream-text h2 { font-size: 1.1rem; }
.stream-text h3 { font-size: 1rem; }
.stream-text h4 { font-size: 0.92rem; color: var(--text-soft); }

.stream-text p { margin: 7px 0; }

.stream-text ul, .stream-text ol { margin: 7px 0; padding-left: 22px; }
.stream-text li { margin: 3px 0; }
.stream-text li > p { margin: 2px 0; }

.stream-text strong { font-weight: 600; }
.stream-text em { font-style: italic; }

.stream-text a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}
.stream-text a:hover { filter: brightness(0.9); }

.stream-text code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.86em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.stream-text pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 11px 13px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.85rem;
  margin: 10px 0;
}
.stream-text pre code { background: transparent; padding: 0; }

.stream-text blockquote {
  border-left: 3px solid var(--border-strong);
  margin: 10px 0;
  padding: 2px 12px;
  color: var(--text-soft);
}
.stream-text hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* Tableaux scrollables sur ligne */
.stream-text .table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.stream-text table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
  min-width: 380px;
}
.stream-text th, .stream-text td {
  border-bottom: 1px solid var(--border);
  padding: 7px 11px;
  text-align: left;
  vertical-align: top;
}
.stream-text thead th {
  background: var(--bg-side);
  font-weight: 600;
}
.stream-text tr:last-child td { border-bottom: none; }

/* ============================== Composer ================================ */
.composer {
  padding: 8px 18px 18px;
  background: var(--bg);
}
.composer-inner {
  display: flex; align-items: flex-end; gap: 6px;
  max-width: 720px; margin: 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 8px 6px 8px 14px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.composer-inner textarea {
  flex: 1;
  border: none; background: transparent;
  padding: 7px 0;
  max-height: 220px; min-height: 24px;
  font-size: 0.95rem;
  resize: none;
  outline: none;
}
.composer-inner textarea:focus { box-shadow: none; border: none; }

.send-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  flex-shrink: 0;
  transition: opacity 0.12s, background 0.12s;
}
.send-btn:hover { opacity: 0.85; }
.send-btn:disabled { background: var(--border-strong); }

/* ============================== Mobile ================================== */
@media (max-width: 720px) {
  .app { grid-template-columns: 0 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: min(280px, 80vw);
    z-index: 10;
    transform: translateX(-100%);
  }
  .app:not(.sidebar-closed) .sidebar { transform: translateX(0); }
  .messages { padding: 12px 14px; }
  .composer { padding: 8px 12px 14px; }
  .resize-handle { display: none; }
}
