/* Assistant Dutiko — feuille de style */

:root {
  --ink:        #10201c;
  --ink-2:      #4a5b55;
  --ink-3:      #7f8e88;
  --green:      #0f6e56;
  --green-deep: #0a4e3d;
  --green-text: #0a4e3d;   /* texte vert sur fond pâle */
  --green-hover: #0a4e3d;  /* survol d'un bouton plein */
  --green-wash: #e7f0ec;
  --canvas:     #f5f6f7;
  --surface:    #ffffff;
  --panel:      #fbfcfc;   /* rail, barre du haut, zone de saisie */
  --line:       #dfe3e5;
  --line-soft:  #eceff0;
  --amber:      #9a5f0f;
  --amber-wash: #fbf1e2;
  --red:        #a4342b;
  --red-wash:   #fbeceb;
  --term:       #10241f;
  --term-line:  #1d3b33;
  --term-text:  #cfe3db;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 6px;
  --rail: 286px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--green); }

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

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

/* ---------- Connexion ---------- */

.login-page {
  min-height: 100%;
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 15% -10%, #e2ece7 0%, transparent 60%),
    var(--canvas);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 34px 32px 30px;
  box-shadow: 0 1px 2px rgba(16, 32, 28, .05);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-card .sub {
  margin: 0 0 26px;
  color: var(--ink-2);
  font-size: 14px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  transition: border-color .12s ease, box-shadow .12s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 110, 86, .12);
  outline: none;
}

.field textarea { min-height: 120px; resize: vertical; font-family: var(--mono); font-size: 13px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s ease;
}
.btn:hover { background: var(--green-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-wide { width: 100%; justify-content: center; }

.btn-quiet {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--line);
}
.btn-quiet:hover { background: var(--green-wash); color: var(--green-text); }

.btn-danger { background: var(--red); }
.btn-danger:hover { background: #862a22; }

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 18px;
  background: var(--red-wash);
  color: var(--red);
  border: 1px solid #f0cdc9;
}
.alert-ok {
  background: var(--green-wash);
  color: var(--green-text);
  border-color: #c6ddd4;
}

/* ---------- Ossature application ---------- */

.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  grid-template-rows: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Voile du tiroir mobile : toujours hors flux, sinon il occupe une colonne
   de la grille et renvoie la colonne principale à la ligne. */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(16, 32, 28, .38);
  z-index: 30;
  display: none;
}
.scrim.is-open { display: block; }

/* Rail gauche */

.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rail-head {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -.02em;
}

.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--ink-3); }

.rail-search {
  width: 100%;
  padding: 8px 11px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13.5px;
}
.rail-search:focus { outline: none; border-color: var(--green); }

.seg {
  display: flex;
  gap: 2px;
  margin-top: 12px;
  padding: 2px;
  background: var(--canvas);
  border-radius: 9px;
}
.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.seg-btn.is-on { background: var(--surface); color: var(--green-text); font-weight: 550; box-shadow: 0 1px 2px rgba(16,32,28,.06); }

.conv-author {
  display: inline-block;
  font-size: 11px;
  color: var(--green-text);
  background: var(--green-wash);
  border-radius: 4px;
  padding: 0 5px;
  margin-right: 5px;
  vertical-align: 1px;
}

.conv-lock { color: var(--ink-3); margin-right: 4px; }

.vis-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
}
.vis-btn svg { width: 13px; height: 13px; }
.vis-btn:hover { border-color: var(--green); color: var(--green-text); }
.vis-btn.is-private { background: var(--amber-wash); color: var(--amber); border-color: #eeddc0; }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px 16px;
  min-height: 0;
}

.conv-group {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-3);
  padding: 14px 8px 6px;
  letter-spacing: .01em;
}

.conv {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  position: relative;
}
.conv:hover { background: var(--canvas); }
.conv.is-active { background: var(--green-wash); box-shadow: inset 2px 0 0 var(--green); }
.conv.is-active .conv-title { color: var(--green-text); font-weight: 550; }

.conv-title {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 22px;
}

.conv-meta {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: -.01em;
  color: var(--ink-3);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-menu {
  position: absolute;
  top: 7px; right: 4px;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0;
  line-height: 1;
}
.conv:hover .conv-menu, .conv.is-active .conv-menu { opacity: 1; }
.conv-menu:hover { background: #fff; color: var(--ink); }

.rail-foot {
  border-top: 1px solid var(--line-soft);
  padding: 8px 10px;
}

/* Toute la ligne est le bouton : grande cible, nom complet lisible */
.who-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 7px 8px;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
}
.who-btn:hover { background: var(--canvas); }
.who-btn .who { flex: 1; min-width: 0; }
.who-btn .chev { color: var(--ink-3); flex: 0 0 auto; transition: transform .15s ease; }
.who-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.who-btn[aria-expanded="true"] { background: var(--canvas); }

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--green-wash);
  color: var(--green-text);
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 600;
  flex: 0 0 auto;
}

.who { min-width: 0; flex: 1; }
.who-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-role { font-size: 11.5px; color: var(--ink-3); }

.icon-link {
  color: var(--ink-3);
  text-decoration: none;
  padding: 5px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
}
.icon-link:hover { background: var(--canvas); color: var(--ink); }

/* Colonne principale */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  row-gap: 8px;
  padding: 12px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-height: 58px;
}

.topbar select { max-width: 190px; flex: 0 1 auto; min-width: 0; text-overflow: ellipsis; }

.topbar h1 {
  font-size: 15.5px;
  font-weight: 550;
  margin: 0;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.tag {
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 5px;
  background: var(--green-wash);
  color: var(--green-text);
  white-space: nowrap;
}
.tag-quiet { background: var(--canvas); color: var(--ink-2); border: 1px solid var(--line); }

.thread {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 28px 22px 12px;
  min-height: 0;
  scroll-behavior: smooth;
}

.thread-inner { max-width: 800px; margin: 0 auto; min-width: 0; }

/* Messages */

.msg {
  margin-bottom: 22px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line-soft);
}
.msg:last-child { border-bottom: 0; padding-bottom: 4px; }

.msg-who {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: .01em;
  color: var(--ink-3);
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.msg-user .bubble {
  background: transparent;
  border: 0;
  border-left: 2px solid var(--green);
  border-radius: 0;
  padding: 2px 0 2px 14px;
}

.msg-assistant .bubble { padding: 0 2px; }

.bubble p { margin: 0 0 12px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 12px; padding-left: 22px; }
.bubble li { margin-bottom: 4px; }
.bubble h3 { font-size: 15px; margin: 18px 0 8px; font-weight: 600; }
.bubble h2 { font-size: 16px; margin: 20px 0 8px; font-weight: 600; }
.bubble code {
  font-family: var(--mono);
  font-size: 12.8px;
  background: var(--green-wash);
  color: var(--green-text);
  padding: 1px 5px;
  border-radius: 4px;
}
.bubble pre {
  background: var(--term);
  color: var(--term-text);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 14px;
  position: relative;
}
.bubble pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: 12.8px;
  line-height: 1.6;
}
.bubble table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 14px;
  font-size: 14px;
}
.bubble th, .bubble td {
  border-bottom: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
}
.bubble th { color: var(--ink-2); font-weight: 600; }

.copy-code {
  position: absolute;
  top: 8px; right: 8px;
  border: 1px solid var(--term-line);
  background: rgba(255,255,255,.06);
  color: var(--term-text);
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease;
}
.bubble pre:hover .copy-code, .copy-code:focus { opacity: 1; }

.msg-foot {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.msg-error {
  border: 1px solid #f0cdc9;
  background: var(--red-wash);
  color: var(--red);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 14px;
}

/* Pièces jointes */

.att {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
  background: var(--surface);
}

.att-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  background: var(--canvas);
  border-bottom: 1px solid transparent;
}
.att[open] .att-head { border-bottom-color: var(--line); }

.att-name { font-family: var(--mono); font-size: 12.5px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-info { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }

.att-body {
  max-height: 340px;
  overflow: auto;
  background: var(--term);
  color: var(--term-text);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  padding: 12px 14px;
  white-space: pre;
  margin: 0;
}

.badge-condensed {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--amber-wash);
  color: var(--amber);
  white-space: nowrap;
}

/* Zone d'écriture */

.composer-wrap {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 22px 14px;
}

.composer {
  max-width: 800px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 4px 6px 6px 6px;
  background: var(--surface);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.composer:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 110, 86, .1);
}

.composer textarea {
  display: block;
  width: 100%;
  border: 0;
  resize: none;
  outline: none;
  max-height: 260px;
  min-height: 24px;
  padding: 8px 8px 4px;
  font-size: 15px;
  line-height: 1.5;
  background: transparent;
}
.composer textarea::placeholder { color: var(--ink-3); }

/* Barre d'outils : tout sur une seule ligne fine, sous le texte */
.composer-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 13px;
  padding: 6px 9px;
  border-radius: 8px;
  cursor: pointer;
}
.attach-btn:hover { background: var(--canvas); color: var(--ink); }
.attach-btn svg { width: 15px; height: 15px; }

.composer-hint {
  flex: 1;
  font-size: 12px;
  color: var(--ink-3);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-tag {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-3);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--canvas);
  white-space: nowrap;
}

.send-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 0;
  background: var(--green);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background .12s ease;
}
.send-btn:hover { background: var(--green-hover); }
.send-btn:disabled { background: #b9c7c1; cursor: not-allowed; }
.send-btn.is-stop { background: var(--ink); }
.send-btn.is-stop:hover { background: #000; }

/* Pièces jointes en attente, au-dessus du texte */
.pending-files {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 4px 0;
}
.pending-files:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: var(--green-wash);
  color: var(--green-text);
  border-radius: 8px;
  padding: 5px 6px 5px 10px;
  max-width: 260px;
}
.chip .chip-name {
  font-family: var(--mono);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip .chip-info { color: #4d7d6d; font-size: 11px; white-space: nowrap; }
.chip button {
  border: 0; background: transparent; cursor: pointer;
  color: inherit; line-height: 1; padding: 2px 4px; border-radius: 50%;
  font-size: 14px;
}
.chip button:hover { background: rgba(10, 78, 61, .12); }

.composer-note {
  max-width: 800px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-3);
}

/* Écran vide */

.empty {
  max-width: 660px;
  margin: 6vh auto 0;
  text-align: left;
}
.empty h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -.02em;
  margin: 0 0 8px;
}
.empty p { color: var(--ink-2); margin: 0 0 26px; }

.starters { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }

.starter {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 13px 15px;
  cursor: pointer;
}
.starter:hover { border-color: var(--green); background: var(--green-wash); }
.starter b { display: block; font-weight: 550; font-size: 14px; margin-bottom: 2px; }
.starter span { font-size: 13px; color: var(--ink-2); }

/* Indicateur de réflexion */

.thinking { display: inline-flex; gap: 4px; align-items: center; height: 20px; }
.thinking i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-3);
  animation: pulse 1.2s infinite ease-in-out;
}
.thinking i:nth-child(2) { animation-delay: .18s; }
.thinking i:nth-child(3) { animation-delay: .36s; }
@keyframes pulse { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .thinking i { animation: none; opacity: .6; }
  .thread { scroll-behavior: auto; }
  * { transition: none !important; }
}

/* ---------- Pages d'administration ---------- */

.page {
  max-width: 940px;
  margin: 0 auto;
  padding: 26px 26px 70px;
}

.page h1 { font-size: 21px; font-weight: 600; letter-spacing: -.015em; margin: 0 0 4px; }
.page .lead { color: var(--ink-2); margin: 0 0 26px; max-width: 70ch; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 20px;
}
.panel h2 { font-size: 16px; font-weight: 600; margin: 0 0 16px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-3);
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--line);
}
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-family: var(--mono); font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.rail-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 16px;
  min-height: 0;
}

.rnav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 1px;
}
.rnav svg { width: 17px; height: 17px; flex: 0 0 auto; }
.rnav span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rnav:hover { background: var(--canvas); color: var(--ink); }
.rnav.is-on { background: var(--green-wash); color: var(--green-text); font-weight: 550; }

.rail-sep {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-3);
  padding: 18px 11px 7px;
}

.page-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
}
.stat b { display: block; font-size: 24px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--ink-2); }

.bar-track { background: var(--canvas); border-radius: 4px; height: 8px; overflow: hidden; }
.bar-fill { background: var(--green); height: 100%; }


/* ---------- Thème sombre ----------
   Appliqué par l'attribut data-theme sur <html> : « sombre » en permanence,
   « auto » selon le réglage du système. Le script en tête de page le pose
   avant le premier rendu, pour éviter le flash blanc. */

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --ink:        #e4ebe8;
    --ink-2:      #a3b5af;
    --ink-3:      #7e918b;
    --green:      #16a37e;
    --green-text: #7fe3bf;
    --green-hover:#1cbb91;
    --green-wash: #163229;
    --canvas:     #0c1412;
    --surface:    #131d1a;
    --panel:      #101917;
    --line:       #24322e;
    --line-soft:  #1b2724;
    --amber:      #dda45c;
    --amber-wash: #2a2216;
    --red:        #ef8175;
    --red-wash:   #2d1a18;
    --term:       #08110f;
    --term-line:  #1f3630;
    --term-text:  #cfe3db;
  }
}

html[data-theme="sombre"] {
  --ink:        #e4ebe8;
  --ink-2:      #a3b5af;
  --ink-3:      #7e918b;
  --green:      #16a37e;
  --green-text: #7fe3bf;
  --green-hover:#1cbb91;
  --green-wash: #163229;
  --canvas:     #0c1412;
  --surface:    #131d1a;
  --panel:      #101917;
  --line:       #24322e;
  --line-soft:  #1b2724;
  --amber:      #dda45c;
  --amber-wash: #2a2216;
  --red:        #ef8175;
  --red-wash:   #2d1a18;
  --term:       #08110f;
  --term-line:  #1f3630;
  --term-text:  #cfe3db;
}

/* Ajustements propres au sombre : les ombres claires n'y servent à rien,
   et quelques fonds doivent être repris à la main. */
html[data-theme="sombre"] .seg-btn.is-on,
html[data-theme="auto"] .seg-btn.is-on {
  box-shadow: none;
}
html[data-theme="sombre"] .login-page,
html[data-theme="auto"] .login-page {
  background: var(--canvas);
}
html[data-theme="sombre"] .login-card,
html[data-theme="sombre"] .modal,
html[data-theme="sombre"] .menu {
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
}
html[data-theme="sombre"] .toast { background: #24322e; }
html[data-theme="sombre"] .chip-info { color: #6fbfa1; }
html[data-theme="sombre"] .copy-code { background: rgba(255, 255, 255, .08); }
html[data-theme="sombre"] .send-btn:disabled { background: #2b3a35; }
html[data-theme="sombre"] .bar-track { background: #1b2724; }
html[data-theme="sombre"] img,
html[data-theme="sombre"] .brand-mark { }

/* Le bouton de thème */
.theme-btn { cursor: pointer; border: 0; background: transparent; }

/* ---------- Menus, boîtes de dialogue, infobulles ---------- */

.menu {
  position: fixed;
  z-index: 60;
  min-width: 186px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: 0 12px 34px rgba(16, 32, 28, .16);
  padding: 5px;
}

.menu a,
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13.5px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.menu a { text-decoration: none; }
.menu a svg,
.menu button svg { width: 15px; height: 15px; flex: 0 0 auto; color: var(--ink-3); }
.menu a:hover,
.menu button:hover { background: var(--canvas); }
.menu button.danger { color: var(--red); }
.menu button.danger svg { color: var(--red); }
.menu button.danger:hover { background: var(--red-wash); }
.menu-sep { height: 1px; background: var(--line-soft); margin: 4px 2px; }

.menu-label {
  font-size: 11.5px;
  color: var(--ink-3);
  padding: 8px 10px 5px;
}
.menu .seg { margin: 0 6px 6px; }
.menu .seg-btn { font-size: 12.5px; padding: 5px 6px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 32, 28, .42);
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border-radius: 14px;
  padding: 24px 24px 20px;
  box-shadow: 0 24px 60px rgba(16, 32, 28, .3);
}
.modal h3 { margin: 0 0 8px; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.modal p  { margin: 0 0 18px; color: var(--ink-2); font-size: 14px; line-height: 1.55; }
.modal input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 20px;
}
.modal input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(15,110,86,.12); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Infobulle : au-dessus par défaut, en dessous avec .tip-below */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  transform: translateX(-50%) translateY(3px);
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  white-space: nowrap;
  padding: 5px 9px;
  border-radius: 7px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
  z-index: 65;
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after { opacity: 1; transform: translateX(-50%); }
[data-tip].tip-below::after { bottom: auto; top: calc(100% + 7px); transform: translateX(-50%) translateY(-3px); }
[data-tip].tip-below:hover::after { transform: translateX(-50%); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  padding: 11px 18px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16, 32, 28, .28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 80;
}
.toast.is-on { opacity: 1; transform: translateX(-50%); }

.toast.has-action {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(560px, calc(100vw - 32px));
  text-align: left;
  line-height: 1.45;
}
.toast-action {
  flex: 0 0 auto;
  color: #8ee3c4;
  font-weight: 600;
  text-decoration: none;
  border-left: 1px solid rgba(255, 255, 255, .22);
  padding-left: 14px;
}
.toast-action:hover { text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  [data-tip]::after, .toast { transition: none; }
}

/* ---------- Adaptation aux petits écrans ---------- */

.rail-toggle { display: none; }

/* Portables et petits écrans : rail plus étroit */
@media (max-width: 1180px) {
  :root { --rail: 250px; }
  .thread { padding: 24px 18px 12px; }
  .composer-wrap { padding: 12px 18px 16px; }
  .topbar select { max-width: 150px; }
}

/* Tablette et mobile : le rail devient un tiroir */
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }

  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    width: 86%;
    max-width: 320px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(16, 32, 28, .18);
  }
  .rail.is-open { transform: none; }
  .rail-toggle { display: grid; }

  .topbar { padding: 10px 14px; gap: 8px; }
  .topbar h1 { flex: 1 1 140px; font-size: 15px; }
  .topbar select { flex: 1 1 calc(50% - 6px); max-width: none; }
  #conv-tokens { display: none; }

  .thread { padding: 18px 14px 8px; }
  .composer-wrap { padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); }
  .composer { border-radius: 12px; }
  .composer-note { display: none; }
  .model-tag { display: none; }

  .starters { grid-template-columns: 1fr; }
  .empty { margin-top: 2vh; }
  .empty h2 { font-size: 21px; }

  .stat-row { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .page { padding: 20px 16px 50px; }

  /* Tableaux d'administration : défilement propre plutôt que débordement */
  .panel { padding: 16px; overflow-x: auto; }
  .tbl { min-width: 520px; }
}

/* Téléphone */
@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .topbar h1 { flex: 1 1 100%; order: -1; }
  .topbar select { flex: 1 1 calc(50% - 20px); font-size: 12px; }
  .att-info { display: none; }
  .att-body { max-height: 240px; font-size: 11.5px; }
  .bubble pre { padding: 12px; }
  .copy-code { opacity: 1; }
  .msg { margin-bottom: 20px; }
  .stat-row { grid-template-columns: 1fr; }
  .conv-menu { opacity: 1; }
}

/* Écran très large : on garde une mesure de lecture confortable */
@media (min-width: 1600px) {
  .thread-inner, .composer { max-width: 820px; }
}
