* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  height: 100vh;
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-container {
  background: #fff;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  width: 320px;
  text-align: center;
}

.login-container h1 {
  margin-bottom: 1.5rem;
  color: #4a6cf7;
}

.login-container input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 1rem;
  margin-bottom: 1rem;
}

.login-container button {
  width: 100%;
  padding: 0.75rem;
  background: #4a6cf7;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
}

.login-container button:hover {
  background: #3b5de7;
}

.error {
  color: #e53e3e;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

/* Navigation */
nav {
  background: #4a6cf7;
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

nav a {
  color: #fff;
  text-decoration: none;
  font-weight: 500;
  opacity: 0.85;
}

nav a:hover, nav a.active {
  opacity: 1;
}

nav .nav-title {
  font-weight: 700;
  font-size: 1.1rem;
  margin-right: auto;
}

/* Layout principal */
.app-container {
  display: flex;
  height: calc(100vh - 48px);
}

/* Liste conversations */
.conversations-list {
  width: 30%;
  min-width: 280px;
  border-right: 1px solid #e0e0e0;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#conv-list {
  flex: 1;
  overflow-y: auto;
}

.search-bar {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #e0e0e0;
}

.search-bar input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 20px;
  font-size: 0.85rem;
  font-family: inherit;
  background: #f5f5f5;
}

.search-bar input:focus {
  outline: none;
  border-color: #4a6cf7;
  background: #fff;
}

.conv-item {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background 0.15s;
}

.conv-item:hover {
  background: #f8f9ff;
}

.conv-item.active {
  background: #eef1ff;
  border-left: 3px solid #4a6cf7;
}

.conv-item .conv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
}

.conv-item .conv-contact {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
}

.conv-item .conv-date {
  font-size: 0.75rem;
  color: #888;
  white-space: nowrap;
}

.conv-item .conv-subject {
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item .conv-preview {
  font-size: 0.8rem;
  color: #999;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-paid {
  background: #48bb78;
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Panneau conversation */
.conversation-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fafafa;
}

.conversation-panel .empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #aaa;
  font-size: 1.1rem;
}

#conv-view {
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#conv-view.visible {
  display: flex !important;
}

.conv-info-bar {
  background: #fff;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.conv-info-bar .contact-info {
  font-weight: 600;
}

.conv-info-bar .stripe-link {
  font-size: 0.85rem;
  color: #4a6cf7;
  cursor: pointer;
  text-decoration: underline;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-info-bar .stripe-link:hover {
  color: #3b5de7;
}

.copied-toast {
  font-size: 0.75rem;
  color: #48bb78;
  margin-left: 0.5rem;
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message-bubble {
  max-width: 70%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 0.9rem;
  word-wrap: break-word;
}

.message-bubble.inbound {
  align-self: flex-start;
  background: #e8e8e8;
  border-bottom-left-radius: 2px;
}

.message-bubble.outbound {
  align-self: flex-end;
  background: #d4e4ff;
  border-bottom-right-radius: 2px;
}

.message-bubble .msg-time {
  font-size: 0.7rem;
  color: #888;
  margin-top: 0.3rem;
  text-align: right;
}

.event-banner {
  background: #e6ffed;
  border: 1px solid #b7f5c8;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  text-align: center;
  font-size: 0.9rem;
  color: #276749;
  align-self: stretch;
}

/* Zone de rédaction */
.compose-area {
  background: #fff;
  border-top: 1px solid #e0e0e0;
  padding: 0.75rem 1rem;
  position: relative;
}

.textarea-wrapper {
  position: relative;
}

.compose-area textarea {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0.65rem;
  padding-right: 2rem;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  max-height: 200px;
}

.compose-area textarea:focus {
  outline: none;
  border-color: #4a6cf7;
}

.btn-expand {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: #aaa;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}

.btn-expand:hover {
  color: #4a6cf7;
  background: #eef1ff;
}

/* Éditeur plein écran */
.editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.editor-modal {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 900px;
  height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid #e0e0e0;
  font-weight: 600;
}

#editor-fullscreen {
  flex: 1;
  border: none;
  padding: 1.25rem;
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  outline: none;
  border-radius: 0 0 12px 12px;
}

.compose-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
}

.btn-primary {
  background: #4a6cf7;
  color: #fff;
}

.btn-primary:hover {
  background: #3b5de7;
}

.btn-secondary {
  background: #e2e8f0;
  color: #555;
}

.btn-secondary:hover {
  background: #cbd5e0;
}

.btn-danger {
  background: #e53e3e;
  color: #fff;
}

.btn-danger:hover {
  background: #c53030;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Autocomplete réponses préfaites */
.canned-dropdown {
  position: absolute;
  bottom: 100%;
  left: 1rem;
  right: 1rem;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  max-height: 200px;
  overflow-y: auto;
  display: none;
  z-index: 10;
}

.canned-dropdown.visible {
  display: block;
}

.canned-option {
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.85rem;
}

.canned-option:last-child {
  border-bottom: none;
}

.canned-option:hover, .canned-option.selected {
  background: #eef1ff;
}

.canned-option .canned-title {
  font-weight: 600;
  color: #4a6cf7;
}

.canned-option .canned-preview {
  color: #888;
  font-size: 0.8rem;
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sync feedback */
.sync-status {
  font-size: 0.8rem;
  color: #888;
}

.sync-status.syncing {
  color: #4a6cf7;
}

.sync-status.done {
  color: #48bb78;
}

.sync-status.error {
  color: #e53e3e;
}

/* -------- Configuration -------- */
.config-container {
  max-width: 800px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

.config-section {
  background: #fff;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.config-section h2 {
  font-size: 1.15rem;
  margin-bottom: 1rem;
  color: #333;
  border-bottom: 1px solid #eee;
  padding-bottom: 0.5rem;
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
  color: #555;
}

.form-group input, .form-group textarea {
  width: 100%;
  padding: 0.55rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}

.form-group input:focus, .form-group textarea:focus {
  outline: none;
  border-color: #4a6cf7;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group {
  flex: 1;
}

.canned-list {
  margin-bottom: 1rem;
}

.canned-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0;
  border-bottom: 1px solid #f0f0f0;
}

.canned-item .canned-info {
  flex: 1;
}

.canned-item .canned-info .title {
  font-weight: 600;
  font-size: 0.9rem;
}

.canned-item .canned-info .preview {
  font-size: 0.8rem;
  color: #888;
  margin-top: 0.15rem;
}

.canned-item .canned-actions {
  display: flex;
  gap: 0.5rem;
}

.canned-item .canned-actions button {
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
}

.email-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.email-tag {
  background: #eef1ff;
  padding: 0.25rem 0.6rem;
  border-radius: 15px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.email-tag .remove-tag {
  cursor: pointer;
  color: #e53e3e;
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1;
}

.hint {
  font-size: 0.8rem;
  color: #888;
  margin-top: 0.3rem;
  font-style: italic;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #333;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.show {
  opacity: 1;
}

.toast.success {
  background: #48bb78;
}

.toast.error {
  background: #e53e3e;
}

/* --- IA Mode --- */
.ai-buttons {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.btn-ai {
  background: #f0e6ff;
  color: #7c3aed;
  border: 1px solid #ddd6fe;
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
}

.btn-ai:hover {
  background: #e9d5ff;
}

.btn-ai.active {
  background: #7c3aed;
  color: #fff;
  border-color: #7c3aed;
}

.ai-mode-banner {
  background: #f5f3ff;
  border-bottom: 1px solid #ddd6fe;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  color: #7c3aed;
  text-align: center;
}

.messages-container.ai-select-mode .message-bubble {
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
}

.messages-container.ai-select-mode .message-bubble:hover {
  opacity: 0.85;
  box-shadow: 0 0 0 2px #a78bfa;
}

.message-bubble.ai-selected {
  box-shadow: 0 0 0 2px #7c3aed !important;
  opacity: 1 !important;
}

/* --- Model selector (config page) --- */
.model-selector-wrapper {
  position: relative;
}

.model-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
}

.model-dropdown.visible {
  display: block;
}

.model-option {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid #f0f0f0;
}

.model-option:last-child {
  border-bottom: none;
}

.model-option:hover {
  background: #eef1ff;
}

.model-option .model-id {
  font-size: 0.75rem;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50%;
}
