/**
 * Assistant Sidebar - AIR-ELEC V2
 * Panneau coulissant depuis la droite, redimensionnable, toujours au premier plan
 */

/* ==========================================================================
   Sidebar container
   ========================================================================== */
.assistant-sidebar {
  position: fixed;
  top: 44px;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 70vw;
  min-width: 300px;
  background: var(--white);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.06),
    -8px 0 30px rgba(0, 0, 0, 0.15),
    -4px 0 12px rgba(0, 0, 0, 0.08);
  z-index: 9000;
  transform: translateX(100%);
  transition: transform 0.3s var(--ease-ios);
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.assistant-sidebar.open {
  transform: translateX(0);
  pointer-events: auto;
}

.assistant-sidebar.closing {
  transform: translateX(100%);
}

/* ==========================================================================
   Resize handle (left edge)
   ========================================================================== */
.assistant-sidebar-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 1;
  pointer-events: auto;
}

.assistant-sidebar-handle::before {
  content: '';
  position: absolute;
  left: 1px;
  top: 0;
  bottom: 0;
  width: 3px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 2px;
  transition: background 0.15s ease, width 0.15s ease;
}

.assistant-sidebar-handle:hover::before {
  background: rgba(90, 158, 53, 0.35);
  width: 4px;
  left: 1px;
}

.assistant-sidebar-handle:active::before,
.assistant-sidebar.resizing .assistant-sidebar-handle::before {
  background: rgba(90, 158, 53, 0.5);
  width: 5px;
  left: 0.5px;
}

/* ==========================================================================
   Header
   ========================================================================== */
.assistant-sidebar-header {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 50px;
  border-bottom: 0.5px solid var(--gray-200);
  flex-shrink: 0;
  background: linear-gradient(to bottom, #fafafa 0%, #f5f5f5 100%);
}

.assistant-sidebar-header::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 0.5px;
  background: rgba(255, 255, 255, 0.8);
}

.assistant-sidebar-header-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
}

.assistant-sidebar-header-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, #14b8a6 0%, #2dd4bf 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.assistant-sidebar-header-icon i {
  width: 13px;
  height: 13px;
}

.assistant-sidebar-header-subtitle {
  font-size: 10px;
  font-weight: 400;
  color: var(--gray-500);
  display: block;
  margin-top: -1px;
}

.assistant-sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.assistant-sidebar-btn,
.assistant-sidebar-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.assistant-sidebar-btn:hover,
.assistant-sidebar-close:hover {
  background: var(--gray-200);
  color: var(--gray-700);
}

.assistant-sidebar-btn:active,
.assistant-sidebar-close:active {
  transform: scale(0.92);
}

.assistant-sidebar-btn.active {
  background: var(--green-pale);
  color: var(--green);
}

.assistant-sidebar-btn i,
.assistant-sidebar-close i {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   Sidebar body (wrapper pour chat + panneaux)
   ========================================================================== */
.assistant-sidebar-body {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* ==========================================================================
   Conversations panel (recouvre toute la sidebar)
   ========================================================================== */
.assistant-conv-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--white);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s var(--ease-ios);
  z-index: 100;
}

.assistant-conv-panel.open {
  transform: translateX(0);
}

.assistant-conv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--gray-200);
  flex-shrink: 0;
}

.assistant-conv-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.assistant-conv-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  transition: all 0.15s ease;
}

.assistant-conv-close:hover {
  background: var(--gray-200);
  color: var(--gray-700);
}

.assistant-conv-close:active {
  transform: scale(0.92);
}

.assistant-conv-close i {
  width: 16px;
  height: 16px;
}

.assistant-conv-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
}

.assistant-conv-new {
  padding: 5px 14px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.15s ease;
}

.assistant-conv-new:hover {
  background: var(--green-light);
}

.assistant-conv-new:active {
  transform: scale(0.96);
}

.assistant-conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.assistant-conv-list::-webkit-scrollbar {
  width: 5px;
}

.assistant-conv-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

/* ─── Filtre dans la liste ─── */
.assistant-conv-list-filters {
  display: flex;
  gap: 4px;
  padding: 8px 16px 10px;
  border-bottom: 0.5px solid var(--gray-100);
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 2;
}

.assistant-conv-list-filter {
  padding: 5px 14px;
  background: transparent;
  border: 0.5px solid var(--gray-200);
  border-radius: 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all 0.15s ease;
}

.assistant-conv-list-filter:hover {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-pale);
}

.assistant-conv-list-filter.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

/* ─── Item de conversation ─── */
.assistant-conv-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.12s ease;
}

.assistant-conv-item:hover {
  background: var(--gray-50);
}

.assistant-conv-item.active {
  border-left-color: var(--green);
  background: var(--green-pale);
}

.assistant-conv-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.assistant-conv-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-900);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.assistant-conv-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--gray-400);
}

.assistant-conv-item-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.4;
}

.assistant-conv-item-badge--chantier {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
}

.assistant-conv-item-badge--client {
  background: rgba(139, 92, 246, 0.1);
  color: #8b5cf6;
}

.assistant-conv-item-badge i {
  width: 10px;
  height: 10px;
}

.assistant-conv-item-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

/* ─── Bouton paramètres ─── */
.assistant-conv-item-settings {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-300);
  flex-shrink: 0;
  opacity: 0;
  transition: all 0.15s ease;
  margin-top: -1px;
}

.assistant-conv-item:hover .assistant-conv-item-settings {
  opacity: 1;
  color: var(--gray-400);
}

.assistant-conv-item-settings:hover {
  background: var(--gray-200);
  color: var(--gray-700);
}

.assistant-conv-item-settings i {
  width: 14px;
  height: 14px;
}

/* ─── Empty state ─── */
.assistant-conv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--gray-400);
  gap: 8px;
}

.assistant-conv-empty i {
  width: 32px;
  height: 32px;
  opacity: 0.5;
}

.assistant-conv-empty-text {
  font-size: 13px;
  font-weight: 500;
}

/* ─── Settings panel (slide-in over list) ─── */
.assistant-conv-settings {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--white);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s var(--ease-ios);
  z-index: 10;
}

.assistant-conv-settings.open {
  transform: translateX(0);
}

.assistant-conv-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--gray-200);
  flex-shrink: 0;
}

.assistant-conv-settings-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
}

.assistant-conv-settings-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  transition: all 0.15s ease;
}

.assistant-conv-settings-close:hover {
  background: var(--gray-200);
  color: var(--gray-700);
}

.assistant-conv-settings-close i {
  width: 16px;
  height: 16px;
}

.assistant-conv-settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.assistant-conv-settings-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 4px;
  display: block;
}

.assistant-conv-settings-select {
  width: 100%;
  padding: 9px 12px;
  border: 0.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--gray-800);
  background: var(--gray-50);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.assistant-conv-settings-select:focus {
  border-color: var(--green);
  background-color: var(--white);
}

.assistant-conv-settings-select optgroup {
  font-weight: 600;
  color: var(--gray-600);
}

.assistant-conv-settings-hint {
  font-size: 10px;
  color: var(--gray-400);
  line-height: 1.4;
  margin-top: -6px;
}

.assistant-conv-settings-footer {
  padding: 12px 16px;
  border-top: 0.5px solid var(--gray-200);
  flex-shrink: 0;
}

.assistant-conv-settings-save {
  width: 100%;
  padding: 9px 16px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.15s ease;
}

.assistant-conv-settings-save:hover {
  background: var(--green-light);
}

.assistant-conv-settings-save:active {
  transform: scale(0.98);
}

/* ==========================================================================
   Chat area
   ========================================================================== */
.assistant-sidebar-chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--gray-50);
}

.assistant-sidebar-chat::-webkit-scrollbar {
  width: 6px;
}

.assistant-sidebar-chat::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 3px;
}

.assistant-sidebar-chat::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* Chat bubbles */
.assistant-msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
  animation: msg-fade-in 0.25s var(--ease-ios);
}

@keyframes msg-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.assistant-msg--bot {
  align-self: flex-start;
  background: var(--white);
  border: 0.5px solid var(--gray-200);
  color: var(--gray-900);
  border-bottom-left-radius: 4px;
}

.assistant-msg--user {
  align-self: flex-end;
  background: var(--green);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.assistant-msg strong {
  font-weight: 600;
}

.assistant-msg--bot strong {
  color: var(--gray-900);
}

/* Suggestion chips */
.assistant-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 4px;
  flex-shrink: 0;
}

.assistant-chip {
  padding: 6px 14px;
  background: var(--white);
  border: 0.5px solid var(--gray-200);
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.assistant-chip:hover {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-pale);
}

.assistant-chip:active {
  transform: scale(0.96);
}

/* ==========================================================================
   Input area
   ========================================================================== */
.assistant-sidebar-input {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 0.5px solid var(--gray-200);
  background: var(--white);
  flex-shrink: 0;
}

.assistant-sidebar-input input {
  flex: 1;
  padding: 10px 16px;
  border: 0.5px solid var(--gray-200);
  border-radius: 12px;
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s ease;
  background: var(--gray-50);
}

.assistant-sidebar-input input:focus {
  border-color: var(--green);
  background: var(--white);
}

.assistant-sidebar-input input::placeholder {
  color: var(--gray-400);
}

.assistant-sidebar-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.assistant-sidebar-send:hover {
  background: var(--green-light);
  transform: scale(1.05);
}

.assistant-sidebar-send:active {
  transform: scale(0.93);
}

.assistant-sidebar-send i {
  width: 18px;
  height: 18px;
}

/* ==========================================================================
   Empty state / Loading
   ========================================================================== */
.assistant-sidebar-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  align-self: flex-start;
  background: var(--white);
  border: 0.5px solid var(--gray-200);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.assistant-sidebar-loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray-300);
  animation: dot-pulse 1.2s ease-in-out infinite;
}

.assistant-sidebar-loading-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.assistant-sidebar-loading-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dot-pulse {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ==========================================================================
   Mobile Responsive (< 768px)
   ========================================================================== */
@media (max-width: 767px) {
  .assistant-sidebar {
    top: 43px;
    width: 100% !important;
    max-width: 100%;
    min-width: 100%;
    z-index: 9999;
  }

  .assistant-sidebar-handle {
    display: none;
  }

  .assistant-sidebar-header {
    padding: 0 12px;
    height: 50px;
  }

  .assistant-sidebar-chat {
    padding: 12px;
    -webkit-overflow-scrolling: touch;
  }

  .assistant-conv-header {
    padding: 12px;
  }

  .assistant-conv-item {
    padding: 12px 12px;
  }

  .assistant-conv-item-settings {
    opacity: 1;
    color: var(--gray-400);
  }

  .assistant-conv-list-filters {
    padding: 8px 12px 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .assistant-conv-list-filters::-webkit-scrollbar {
    display: none;
  }

  .assistant-conv-list-filter {
    flex-shrink: 0;
  }

  .assistant-conv-settings-header {
    padding: 12px;
  }

  .assistant-conv-settings-body {
    padding: 12px;
  }

  .assistant-msg {
    max-width: 88%;
    padding: 12px 14px;
    font-size: 14px;
  }

  .assistant-sidebar-input {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .assistant-sidebar-input input {
    padding: 12px 16px;
    font-size: 16px;
  }

  .assistant-sidebar-send {
    width: 44px;
    height: 44px;
  }

  /* Cacher le dock quand la sidebar est ouverte */
  .assistant-sidebar.open ~ .dock {
    display: none;
  }

  .assistant-chips {
    padding: 0 12px 4px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .assistant-chips::-webkit-scrollbar {
    display: none;
  }
}
