/**
 * Atlas V3 — style.css (Frontend)
 * Base : style.css.bak (restauré)
 * Ajustement : Auth uniquement dans le header + rendu discret
 */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #f4f9ff;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* =========================
 * HEADER
 * ========================= */
header {
  background: #4a90e2;
  color: #fff;
  padding: 12px 14px;
  font-size: 1.2rem;
  font-weight: 700;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 100;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;

  /* ✅ zone cliquable (rouge) */
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.header-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* =========================
 * TAYTOO ACTIONS DRAWER (zone jaune)
 * ========================= */
.taytoo-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;

  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(225,232,237,0.9);
  border-radius: 999px;
  padding: 6px 8px;

  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  max-width: 58vw;

  /* animation simple */
  transform-origin: right center;
  transform: scale(1);
  opacity: 1;
  transition: transform 120ms ease, opacity 120ms ease;
}

.taytoo-actions.hidden {
  display: none;
}

.taytoo-action-btn {
  border: none;
  background: rgba(74,144,226,0.12);
  color: #1a1a1a;

  width: 34px;
  height: 34px;
  border-radius: 50%;

  font-size: 18px;
  cursor: pointer;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  -webkit-tap-highlight-color: transparent;
}

.taytoo-action-btn:active {
  transform: scale(0.98);
}

/* Petit indice visuel quand ouvert */
header.taytoo-actions-open .header-left {
  opacity: 0.96;
}

/* =========================
 * AUTH (discret dans le header)
 * ========================= */
.header-auth {
  display: inline-flex;
  align-items: center;
  gap: 8px;

  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(225,232,237,0.9);
  border-radius: 999px;
  padding: 6px 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);

  max-width: 58vw;
}

.atlas-auth-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #bbb;
  flex: 0 0 auto;
}
.atlas-auth-dot.ok { background: #2ecc71; }

.atlas-auth-text {
  color: #1a1a1a;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.atlas-auth-open {
  border: 1px solid rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.15);
  color: #fff;
  border-radius: 12px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85rem;
}

/* =========================
 * MAIN / CHAT
 * ========================= */
main#app {
  flex: 1;
  padding: 76px 12px 86px 12px;
}

#chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: calc(100vh - 76px - 86px);
  padding-right: 4px;
}

.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  max-width: 88%;
  font-size: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.ai {
  background: #fff;
  color: #333;
  border: 1px solid #e1e8ed;
  align-self: flex-start;
}

.bubble.user {
  background: #4a90e2;
  color: #fff;
  align-self: flex-end;
}

/* =========================
 * FOOTER
 * ========================= */
footer {
  background: #fff;
  padding: 10px;
  display: flex;
  gap: 8px;
  border-top: 1px solid #ddd;
  position: fixed;
  bottom: 0;
  width: 100%;
  z-index: 100;
}

#msg {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 20px;
  outline: none;
  font-size: 16px;
}

#btn-send {
  background: #4a90e2;
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}

/* =========================
 * MODAL (auth)
 * ========================= */
.atlas-modal.hidden { display: none; }
.atlas-modal { position: fixed; inset: 0; z-index: 1000; }
.atlas-modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }

.atlas-modal-content {
  position: relative;
  background: white;
  width: min(92vw, 520px);
  margin: 12vh auto;
  padding: 18px 16px;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}

.atlas-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: none;
  background: none;
  font-size: 1.2rem;
  cursor: pointer;
}

.atlas-modal-title {
  margin: 0 0 6px 0;
  font-size: 1.1rem;
}

.atlas-modal-sub {
  margin: 0 0 14px 0;
  color: #555;
  font-size: 0.95rem;
  line-height: 1.3;
}

.atlas-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
}

.atlas-field span {
  font-size: 0.9rem;
  color: #333;
  font-weight: 600;
}

.atlas-field input,
.atlas-field textarea,
.atlas-field select {
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 12px;
  outline: none;
  background: #fff;
}

.atlas-field textarea { resize: none; }

.atlas-field small {
  color: #666;
  font-size: 0.85rem;
}

.atlas-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 6px;
}

.atlas-field-inline {
  flex: 1 1 220px;
  margin: 0;
}

.atlas-btn {
  flex: 0 0 auto;
  background: #4a90e2;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 11px 14px;
  cursor: pointer;
  font-weight: 700;
}

.atlas-auth-status {
  margin-top: 12px;
  font-size: 0.95rem;
  color: #333;
  min-height: 1.2em;
}
.atlas-auth-status[data-kind="ok"] { color: #1f8a4c; }
.atlas-auth-status[data-kind="err"] { color: #c0392b; }

/* =========================
 * Wider screens tweaks
 * ========================= */
@media (min-width: 900px) {
  main#app {
    padding-left: 18px;
    padding-right: 18px;
  }
  .bubble { max-width: 70%; }
  .header-auth { max-width: 520px; }
}

/* =========================
 * IA ICON
 * ========================= */
.ai-icon {
  margin-right: 6px;
  font-size: 1.1em;
}

/* =========================
 * AUTH BUTTON (round)
 * ========================= */
.atlas-auth-open {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#msg {
  flex: 1;
  min-width: 0;
  max-height: 120px;

  padding: 12px 14px;
  border: 1px solid #ccc;
  border-radius: 20px;

  font-size: 16px;
  font-family: inherit;
  line-height: 1.3;

  resize: none;
  overflow-y: hidden;
}

/* =========================
 * TOKEN REQUEST MODAL (taytoo)
 * ========================= */

.atlas-token-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.atlas-token-form h3 {
  margin: 0 0 4px 0;
  font-size: 1.1rem;
}

.atlas-token-hint {
  font-size: 0.9rem;
  color: #555;
  line-height: 1.35;
  margin: 0 0 8px 0;
}

/* Champs */
.atlas-token-form input,
.atlas-token-form textarea {
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 12px;
  outline: none;
  background: #fff;
}

.atlas-token-form textarea {
  resize: none;
}

/* Bouton */
.atlas-token-form button[type="submit"] {
  margin-top: 6px;
  background: #4a90e2;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
  cursor: pointer;
}

.atlas-token-form button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Feedback */
.token-request-feedback {
  min-height: 1.2em;
  font-size: 0.9rem;
}

.token-request-feedback.success {
  color: #1f8a4c;
}

.token-request-feedback.error {
  color: #c0392b;
}

/* =========================
 * AUTH FAB (dans modal token uniquement)
 * ========================= */
.atlas-auth-fab {
  position: absolute;
  right: 16px;
  bottom: 16px;

  width: 44px;
  height: 44px;
  border-radius: 50%;

  border: none;
  background: #4a90e2;
  color: #fff;

  font-size: 20px;
  cursor: pointer;

  box-shadow: 0 6px 18px rgba(0,0,0,.25);
  -webkit-tap-highlight-color: transparent;
}

.atlas-auth-fab:active {
  transform: scale(0.97);
}

.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid #ddd;
}

.preview-item {
  position: relative;
  width: 90px;
  text-align: center;
}

.preview-thumb {
  width: 90px;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #ccc;
}

.preview-label {
  font-size: 12px;
  margin-top: 4px;
  color: #666;
}

.preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ff4d4d;
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  cursor: pointer;
  font-size: 12px;
}

.hidden {
  display: none;
}

/* =========================
 * HISTORY MODAL
 * ========================= */

/* Contenu de la modale */
.atlas-modal-content {
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

/* Bouton nouvelle conversation */
.history-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.history-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: none;
  background: #4a90e2;
  color: white;
  cursor: pointer;
  font-weight: 600;
}

/* 🔥 Zone scrollable */
#history-list {
  overflow-y: auto;
  max-height: 420px; /* ≈ 10 lignes visibles */
  padding-right: 4px;
}

/* Scroll plus discret */
#history-list::-webkit-scrollbar {
  width: 6px;
}

#history-list::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.2);
  border-radius: 3px;
}

/* Ligne conversation */
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background 0.15s ease;
}

.history-item:hover {
  background: #f2f7ff;
}

.history-title {
  flex: 1;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-controls {
  display: flex;
  gap: 6px;
}

.history-controls button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
}