/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary:    #313338;
  --bg-secondary:  #2b2d31;
  --bg-tertiary:   #1e1f22;
  --bg-hover:      #35373c;
  --bg-active:     #404249;
  --accent:        #5865f2;
  --accent-hover:  #4752c4;
  --accent-light:  rgba(88, 101, 242, 0.15);
  --danger:        #da3633;
  --danger-hover:  #b91c1c;
  --success:       #23a55a;
  --text-primary:  #f2f3f5;
  --text-secondary:#b5bac1;
  --text-muted:    #80848e;
  --border:        rgba(255,255,255,0.06);
  --radius:        8px;
  --radius-sm:     4px;
  --shadow:        0 4px 16px rgba(0,0,0,0.4);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.4;
}

/* ── Layout ── */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 24px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.guilds-section {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  padding: 8px 16px 4px;
}

.guild-list { display: flex; flex-direction: column; gap: 1px; padding: 0 8px; }

.guild-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.guild-item:hover { background: var(--bg-hover); }
.guild-item.active { background: var(--accent-light); }
.guild-item.active .guild-name { color: var(--text-primary); }

.guild-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-active);
  flex-shrink: 0;
}

.guild-icon-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.guild-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main ── */
.main {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  overflow: hidden;
}

/* ── Clone Banner ── */
.clone-banner {
  background: linear-gradient(135deg, #23a55a22, #23a55a11);
  border-bottom: 1px solid #23a55a44;
  padding: 12px 20px;
  transition: all 0.3s;
}

.clone-banner.hidden { display: none; }

.clone-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.banner-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 6px;
}

.banner-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--success);
  letter-spacing: 0.8px;
}

/* ── Active personas chips ── */
.active-personas-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.active-persona-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-tertiary);
  border: 1px solid #23a55a44;
  border-radius: 20px;
  padding: 3px 8px 3px 4px;
}

.persona-chip-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--success);
}

.persona-chip-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.persona-chip-count {
  font-size: 11px;
  color: var(--text-secondary);
}

.persona-chip-stop {
  font-size: 10px;
  padding: 1px 4px;
  opacity: 0.6;
  line-height: 1;
}

.persona-chip-stop:hover {
  opacity: 1;
}

.persona-chip-history {
  font-size: 10px;
  padding: 1px 4px;
  opacity: 0.6;
  line-height: 1;
}

.persona-chip-history:hover {
  opacity: 1;
}

/* ── Historique modal ── */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px 0;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.history-item-user {
  background: var(--bg-tertiary);
}

.history-item-assistant {
  background: #23a55a18;
  border-left: 3px solid var(--success);
}

.history-role {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-content {
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Button active state (persona toggle) ── */
.btn-active {
  background: #23a55a22 !important;
  color: var(--success) !important;
  border: 1px solid #23a55a55 !important;
}

/* ── Feed speaker (persona mode) ── */
.feed-speaker-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-right: 4px;
}

.send-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.send-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 6px 8px;
  font-size: 13px;
  min-width: 140px;
}

.send-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}

.send-input:focus {
  border-color: var(--accent);
}

/* ── Progress Bar ── */
.progress-bar {
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
}

.progress-bar.hidden { display: none; }

.progress-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.progress-channel {
  color: var(--text-muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-count {
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.progress-track {
  height: 4px;
  background: var(--bg-active);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  animation: pulse-progress 1.5s ease-in-out infinite;
  transition: width 0.3s;
}

@keyframes pulse-progress {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ── Content ── */
.content {
  display: grid;
  grid-template-columns: 1fr 340px;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ── Panels ── */
.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

.members-panel {
  overflow: hidden;
}

.feed-panel { border-right: none; }

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

.panel-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.member-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-active);
  padding: 2px 8px;
  border-radius: 10px;
}

/* ── List sections (bots custom / membres Discord) ── */
.list-section {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
}

.list-section:last-child {
  flex: 1;
  overflow: hidden;
  border-bottom: none;
}

.list-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 6px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.list-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  flex: 1;
}

/* ── Member List ── */
.member-list {
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-section:last-child .member-list {
  flex: 1;
}

.custom-bot-list {
  max-height: 220px;
}

.empty-state-sm {
  padding: 12px 20px;
  font-size: 12px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: default;
  transition: background 0.1s;
}

.member-item:hover { background: var(--bg-hover); }

.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.member-info {
  flex: 1;
  min-width: 0;
}

.member-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-username {
  font-size: 11px;
  color: var(--text-muted);
}

.member-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s;
}

.member-item:hover .member-actions { opacity: 1; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s, opacity 0.1s;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 4px 8px; font-size: 12px; }

/* ── Feed ── */
.feed-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.feed-item {
  background: var(--bg-primary);
  border-radius: var(--radius);
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  animation: slide-in 0.2s ease;
}

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

.feed-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.feed-channel {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

.feed-time {
  font-size: 11px;
  color: var(--text-muted);
}

.feed-content {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
  word-break: break-word;
}

.feed-trigger {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── States ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 48px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-icon { font-size: 32px; }

.loading-state {
  padding: 16px;
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
}

/* ── Modal ── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(2px);
}

.modal-box {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(680px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.modal-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-active);
  padding: 2px 8px;
  border-radius: 10px;
}

.prompt-textarea {
  flex: 1;
  min-height: 280px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 12px;
  resize: vertical;
  outline: none;
}

.prompt-textarea:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Shuffle Banner ── */
.shuffle-banner {
  background: linear-gradient(135deg, #5865f222, #5865f211);
  border-bottom: 1px solid #5865f244;
  padding: 12px 20px;
  transition: all 0.3s;
}

.shuffle-banner.hidden { display: none; }

.shuffle-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.shuffle-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.shuffle-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.8px;
}

.shuffle-personas-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.shuffle-persona-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-active);
  border-radius: 12px;
  padding: 2px 8px 2px 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.shuffle-persona-chip img {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
}

/* ── Shuffle Modal ── */
.shuffle-modal-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: -4px;
}

.shuffle-config {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.shuffle-config-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shuffle-config-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.shuffle-member-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  background: var(--bg-tertiary);
}

.shuffle-member-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.shuffle-member-option:hover { background: var(--bg-hover); }

.shuffle-member-option input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
}

.shuffle-member-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.shuffle-member-option span:nth-child(3) {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.shuffle-member-username {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Shuffle section headers (dans modal) ── */
.shuffle-section-header {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  padding: 6px 8px 2px;
  margin-top: 4px;
}

/* ── Feed shuffle ── */
.feed-item-shuffle {
  border-left-color: var(--accent);
}

.feed-speaker {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}

.feed-speaker-avatar {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 2px;
}

/* ── Discord Emojis ── */
.discord-emoji {
  width: 20px;
  height: 20px;
  vertical-align: middle;
  display: inline;
  margin: 0 1px;
}

/* ── Bots Custom ── */
.custom-badge {
  display: inline-block;
  background: rgba(88, 101, 242, 0.25);
  color: var(--accent);
  border: 1px solid rgba(88, 101, 242, 0.4);
  border-radius: 3px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  vertical-align: middle;
  margin-left: 5px;
}

.member-item-custom {
  border-left: 2px solid rgba(88, 101, 242, 0.4);
}

.member-avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-active);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

/* Modal bot manuel */
.custom-bot-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 0 8px;
}

.custom-bot-avatar-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.custom-bot-avatar-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
  overflow: hidden;
}

.custom-bot-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.custom-bot-avatar-upload {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
