/* =============================================================
   chat.css — Clone ChatGPT avec sidebar ouverte par défaut
   Responsive mobile-first — Bootstrap 5
   ============================================================= */

:root {
  --font-main: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;

  --color-bg: #f9f9f8;
  --color-surface: #ffffff;
  --color-border: #e5e5e3;
  --color-border-light: #f0f0ee;

  --color-text-primary: #1a1a18;
  --color-text-secondary: #6b6b68;
  --color-text-muted: #9b9b97;

  --color-brand: #19c37d;
  --color-brand-hover: #15a86a;
  --color-brand-subtle: #e6f9f1;

  --color-user-bubble: #ececea;
  --color-sidebar-bg: #ffffff;
  --color-header-bg: #ffffffee;

  --header-height: 56px;
  --sidebar-width: min(85vw, 280px);
  --sidebar-width-desktop: 260px;
  --sidebar-width-collapsed: 56px;
  --input-radius: 16px;
  --bubble-radius: 18px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-input: 0 2px 12px rgba(0,0,0,0.10);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* =============================================================
   LAYOUT PRINCIPAL — Flex row
   ============================================================= */
.chat-app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* =============================================================
   SIDEBAR — Ouverte par défaut
   Mobile: overlay fixe, slide-in | Desktop: colonne fixe
   ============================================================= */
.chat-sidebar {
  --sidebar-w: var(--sidebar-width);
  flex-shrink: 0;
  width: var(--sidebar-w);
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  z-index: 1050;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mobile : sidebar en overlay, ouverte par défaut */
@media (max-width: 767.98px) {
  .chat-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-w);
    transform: translateX(0); /* ouvert par défaut */
    box-shadow: var(--shadow-md);
  }

  .chat-sidebar.sidebar-closed {
    transform: translateX(-100%);
  }
}

/* Desktop : sidebar intégrée au layout */
@media (min-width: 768px) {
  .chat-sidebar {
    --sidebar-w: var(--sidebar-width-desktop);
    width: var(--sidebar-w);
    position: relative;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .chat-sidebar.sidebar-collapsed {
    width: var(--sidebar-width-collapsed) !important;
  }

  .chat-sidebar.sidebar-collapsed .sidebar-text,
  .chat-sidebar.sidebar-collapsed .section-label,
  .chat-sidebar.sidebar-collapsed .conversation-title,
  .chat-sidebar.sidebar-collapsed .user-name {
    opacity: 0;
    width: 0;
    overflow: hidden;
    white-space: nowrap;
    padding: 0;
    margin: 0;
  }

  .chat-sidebar.sidebar-collapsed .sidebar-header {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 12px 8px;
    gap: 8px;
  }

  .chat-sidebar.sidebar-collapsed .sidebar-header-brand {
    margin: 0;
  }

  .chat-sidebar.sidebar-collapsed .sidebar-header-brand .brand-name {
    display: none;
  }

  .chat-sidebar.sidebar-collapsed .btn-sidebar-collapse {
    margin: 0;
  }

  .chat-sidebar.sidebar-collapsed .btn-sidebar-collapse i {
    transform: rotate(180deg);
  }

  .chat-sidebar.sidebar-collapsed .sidebar-new-chat {
    padding: 8px !important;
  }

  .chat-sidebar.sidebar-collapsed .btn-new-chat {
    padding: 10px;
    justify-content: center;
  }

  .chat-sidebar.sidebar-collapsed .btn-new-chat .sidebar-icon-only {
    margin: 0 !important;
  }

  .chat-sidebar.sidebar-collapsed .conversations-section {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  .chat-sidebar.sidebar-collapsed .conversations-section .sidebar-text {
    display: none;
  }

  .chat-sidebar.sidebar-collapsed .conversation-item {
    justify-content: center;
    padding: 10px;
  }

  .chat-sidebar.sidebar-collapsed .conversation-item .sidebar-icon-only {
    margin: 0 !important;
  }

  .chat-sidebar.sidebar-collapsed .sidebar-footer .user-info {
    justify-content: center;
  }

  .chat-sidebar.sidebar-collapsed .sidebar-footer .btn-icon {
    display: none;
  }
}

.sidebar-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  min-height: var(--header-height);
}

.btn-sidebar-close {
  flex-shrink: 0;
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--color-brand);
  color: #fff;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.3px;
}

/* Zone scrollable de la sidebar */
.sidebar-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.sidebar-scroll::-webkit-scrollbar {
  width: 4px;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

.btn-new-chat {
  background: var(--color-brand-subtle);
  color: var(--color-brand);
  border: 1.5px solid rgba(25,195,125,0.25);
  border-radius: 12px;
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  transition: all 0.15s ease;
}

.btn-new-chat:hover {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  padding: 0 2px;
}

.conversations-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-item {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background 0.12s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item:hover {
  background: var(--color-border-light);
  color: var(--color-text-primary);
}

.conversation-item.active {
  background: var(--color-brand-subtle);
  color: var(--color-brand);
  font-weight: 500;
}

.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer {
  flex-shrink: 0;
  background: var(--color-bg);
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: #1a1a18;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Overlay mobile — ferme la sidebar au clic */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 1040;
  opacity: 0;
  transition: opacity 0.25s ease;
}

@media (max-width: 767.98px) {
  .sidebar-overlay.overlay-visible {
    display: block;
    opacity: 1;
  }
}

@media (min-width: 768px) {
  .sidebar-overlay {
    display: none !important;
  }
}

/* =============================================================
   ZONE CHAT PRINCIPALE
   ============================================================= */
.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  flex-shrink: 0;
  height: var(--header-height);
  background: var(--color-header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}

/* Zone de chat scrollable */
.chat-zone {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px 0;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.chat-zone::-webkit-scrollbar {
  width: 4px;
}
.chat-zone::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

/* État vide */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 16px 24px;
  min-height: 60vh;
}

.empty-icon {
  width: 56px;
  height: 56px;
  background: var(--color-brand-subtle);
  color: var(--color-brand);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.empty-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 8px;
}

.empty-subtitle {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 28px;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}

.suggestion-chip {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  font-family: var(--font-main);
  font-weight: 500;
  color: var(--color-text-primary);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.4;
  box-shadow: var(--shadow-sm);
}

.suggestion-chip:hover,
.suggestion-chip:active {
  background: var(--color-brand-subtle);
  border-color: var(--color-brand);
  color: var(--color-brand);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Messages */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 16px;
}

.message-row {
  display: flex;
  width: 100%;
  animation: fadeSlideIn 0.2s ease;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.user .bubble {
  background: var(--color-user-bubble);
  color: var(--color-text-primary);
  border-radius: var(--bubble-radius) var(--bubble-radius) 4px var(--bubble-radius);
  max-width: 82%;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
}

.message-row.assistant {
  justify-content: flex-start;
  align-items: flex-start;
  gap: 10px;
}

.assistant-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  background: var(--color-brand-subtle);
  color: var(--color-brand);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  margin-top: 2px;
}

.message-row.assistant .bubble {
  background: transparent;
  color: var(--color-text-primary);
  border-radius: 0;
  max-width: calc(100% - 40px);
  padding: 4px 0;
  font-size: 15px;
  line-height: 1.65;
  word-break: break-word;
}

.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }

.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  font-size: 16px;
  font-weight: 600;
  margin: 16px 0 8px;
}

.bubble ul, .bubble ol {
  padding-left: 20px;
  margin: 8px 0;
}

.bubble li { margin-bottom: 4px; }

.bubble code {
  font-family: var(--font-mono);
  background: var(--color-border-light);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 13px;
}

.bubble pre {
  background: #f5f5f3;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0;
}

.bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
}

.bubble blockquote {
  border-left: 3px solid var(--color-brand);
  padding-left: 12px;
  color: var(--color-text-secondary);
  margin: 10px 0;
}

.bubble a {
  color: var(--color-brand);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble strong { font-weight: 600; }

.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 8px 0;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--color-text-muted);
  border-radius: 50%;
  animation: typingPulse 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%            { transform: scale(1);   opacity: 1; }
}

/* Footer — Input */
.chat-footer {
  flex-shrink: 0;
  background: var(--color-bg);
  padding: 10px 12px 8px;
  border-top: 1px solid var(--color-border-light);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--input-radius);
  padding: 8px 8px 8px 14px;
  box-shadow: var(--shadow-input);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-wrapper:focus-within {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(25,195,125,0.12);
}

.chat-textarea {
  flex: 1;
  min-height: 52px;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-main);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text-primary);
  resize: none;
  overflow-y: hidden;
  max-height: 140px;
  overflow-y: auto;
  padding: 0;
}

.chat-textarea::placeholder {
  color: var(--color-text-muted);
}

.btn-send {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  background: var(--color-brand);
  color: #fff;
  border: none;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.15s ease;
  cursor: pointer;
  line-height: 1;
}

.btn-send:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.btn-send:not(:disabled):hover {
  background: var(--color-brand-hover);
  transform: scale(1.05);
}

.btn-send:not(:disabled):active {
  transform: scale(0.96);
}

.disclaimer {
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: center;
  margin: 6px 0 0;
  padding: 0 4px;
}

/* Boutons génériques */
.btn-icon {
  background: transparent;
  border: none;
  color: var(--color-text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.btn-icon:hover {
  background: var(--color-border-light);
  color: var(--color-text-primary);
}

.toast-container {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
}

/* =============================================================
   RESPONSIVE — Tablet & Desktop
   ============================================================= */
@media (min-width: 576px) {
  .chat-zone {
    padding: 20px 20px 0;
  }

  .message-row.user .bubble {
    max-width: 70%;
  }

  .empty-title {
    font-size: 22px;
  }
}

@media (min-width: 768px) {
  .chat-zone {
    padding: 24px 0 0;
  }

  .messages-container,
  .empty-state {
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
  }

  .chat-footer {
    padding: 12px 0 10px;
  }

  .input-wrapper {
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
  }

  .disclaimer {
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
  }
}
