:root {
  /* Bleu-nuit tinté plutôt qu'un gris neutre — un seul family de gris,
     teinté froid du fond jusqu'aux bordures, pour une identité propre au
     panel plutôt qu'un thème sombre générique. */
  --bg: #0c0e13;
  --bg-elevated: #12151d;
  --bg-card: #171b25;
  --bg-hover: #1f2430;
  --border: #232838;
  --border-light: #2c3244;
  --text: #eaecf2;
  --text-dim: #9aa1b5;
  --text-faint: #656d82;
  /* Ambre — délibérément distinct du bleu-violet "Discord" utilisé à
     l'intérieur de la fenêtre de chat (elle, reste fidèle à Discord) : le
     chrome du panel a sa propre identité, façon voyant de contrôle. */
  --accent: #e0993d;
  --accent-hover: #c9822a;
  --accent-soft: rgba(224, 153, 61, 0.14);
  /* Un ambre clair reste trop lumineux pour du texte blanc lisible dessus —
     un texte sombre passe nettement mieux, comme sur n'importe quel badge
     ambre/jaune conventionnel. */
  --text-on-accent: #241505;
  --success: #3ecf8e;
  --success-soft: rgba(62, 207, 142, 0.14);
  --danger: #f0555c;
  --danger-soft: rgba(240, 85, 92, 0.14);
  --warning: #e8c547;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 28px rgba(3, 4, 8, 0.55);
  --font:
    "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 14px;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

/* ---------- Login ---------- */

.login-screen {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #1a1f2e 0%, var(--bg) 55%);
}

.login-card {
  width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card .logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #f4b860);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 26px;
}

.login-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
}

.login-card p {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 24px;
}

.login-card input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text);
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}
.login-card input:focus {
  border-color: var(--accent);
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13px;
  transition:
    background 0.15s,
    opacity 0.15s,
    transform 0.1s;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  width: 100%;
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover {
  background: var(--border-light);
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger);
  color: white;
}
.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
}
.btn-icon {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}
.btn-icon:active {
  transform: scale(0.94);
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.error-msg {
  color: var(--danger);
  font-size: 12.5px;
  margin-top: -4px;
  margin-bottom: 12px;
  min-height: 16px;
}

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100dvh;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-header .logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #f4b860);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.sidebar-header h1 {
  font-size: 15px;
  margin: 0;
}
.sidebar-header .sub {
  font-size: 11px;
  color: var(--text-faint);
}

.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
}
.sidebar-search input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.sidebar-search .btn-icon {
  width: 34px;
  height: auto;
  flex-shrink: 0;
}
.sidebar-search input:focus {
  border-color: var(--accent);
}

.bot-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.bot-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.12s;
}
.bot-item:hover {
  background: var(--bg-hover);
}
.bot-item.active {
  background: var(--accent-soft);
  color: #f6d9a8;
}
.bot-item .name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bot-item .chevron {
  color: var(--text-faint);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.pin-star {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
  padding: 2px;
  flex-shrink: 0;
  transition: color 0.12s;
}
.pin-star:hover {
  color: var(--warning);
}
.pin-star.pinned {
  color: var(--warning);
}
.bot-list-heading {
  color: var(--text-faint);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  padding: 10px 12px 4px;
}
.bot-list-heading:first-child {
  padding-top: 4px;
}
.bot-item.expanded .chevron {
  transform: rotate(90deg);
}

.guild-list {
  padding-left: 8px;
  margin: 2px 0 6px;
}
.guild-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-dim);
}
.guild-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.guild-item.active {
  background: var(--accent);
  color: var(--text-on-accent);
}
.guild-item img {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  flex-shrink: 0;
  background: var(--border);
}
.guild-item .placeholder-icon {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--border-light);
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.sidebar-footer .btn {
  width: 100%;
}

/* ---------- Main ---------- */

.main {
  overflow-y: auto;
  padding: 28px 36px 60px;
}

.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 260;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 16px;
  align-items: center;
  justify-content: center;
}
.sidebar-scrim {
  display: none;
}

/* ---------- Mobile : sidebar en tiroir plutôt qu'en colonne fixe ---------- */
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    max-width: 82vw;
    z-index: 280;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .mobile-menu-btn {
    display: flex;
  }
  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(3, 4, 8, 0.55);
    z-index: 270;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  .sidebar-scrim.open {
    opacity: 1;
    pointer-events: auto;
  }
  .main {
    padding: calc(env(safe-area-inset-top) + 68px) 16px 40px;
  }
  .modal,
  .modal.modal-wide {
    width: calc(100vw - 32px);
  }
  /* Empêche Safari iOS de zoomer automatiquement la page quand on touche un
     champ de saisie dont la taille de police est < 16px — sinon chaque tap
     sur un champ (recherche, composer de chat, mot de passe...) dézoome
     brutalement la vue une fois le clavier refermé. */
  input,
  select,
  textarea {
    font-size: 16px;
  }
  .panel-toolbar {
    flex-wrap: wrap;
  }
  .panel-toolbar input[type="text"] {
    width: auto;
    flex: 1;
    min-width: 0;
  }
}

/* Respecte l'encoche / la Dynamic Island et la barre d'accueil quand le
   panel est installé en PWA plein écran sur iPhone (voir viewport-fit=cover
   + apple-mobile-web-app-status-bar-style=black-translucent). */
@media (max-width: 860px) {
  .mobile-menu-btn {
    top: calc(env(safe-area-inset-top) + 14px);
  }
  .sidebar {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
  }
  .sidebar-footer {
    padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
  }
}

/* ---------- Mobile : modales plein écran façon app native ---------- */
@media (max-width: 600px) {
  .modal,
  .modal.modal-wide {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
    padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 14px);
  }
  .modal-overlay {
    padding: 0;
  }
  .modal h3 {
    flex-shrink: 0;
  }
  .chat-modal {
    overflow-y: hidden;
  }
  .chat-modal .chat-toolbar {
    flex-shrink: 0;
  }
  .chat-messages {
    flex: 1;
    min-height: 0;
    max-height: none;
  }
  .chat-composer {
    flex-shrink: 0;
  }
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  text-align: center;
  gap: 8px;
}
.empty-state .icon {
  font-size: 40px;
  opacity: 0.5;
  margin-bottom: 8px;
}

.guild-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.guild-header img,
.guild-header .placeholder-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--bg-card);
  flex-shrink: 0;
}
.guild-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
}
.guild-header .meta {
  color: var(--text-dim);
  font-size: 12.5px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition:
    border-color 0.15s,
    transform 0.15s;
}
.stat-card:hover {
  border-color: var(--border-light);
  transform: translateY(-1px);
}
.stat-card .value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 24px;
  font-weight: 500;
}
.stat-card .label {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 2px;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar {
  display: none;
}
.tab {
  padding: 10px 16px;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition:
    color 0.15s,
    border-color 0.15s;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.panel-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
}
.panel-toolbar input[type="text"] {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text);
  outline: none;
  width: 240px;
}
.panel-toolbar input[type="text"]:focus {
  border-color: var(--accent);
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.15s;
}
.row:hover {
  border-color: var(--border-light);
}

.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.role-name {
  font-weight: 600;
  font-size: 13.5px;
}
.role-meta {
  font-size: 11.5px;
  color: var(--text-faint);
}
.row .spacer {
  flex: 1;
}

.badge {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--bg-hover);
  color: var(--text-dim);
  font-weight: 600;
  white-space: nowrap;
}
.badge.admin {
  background: var(--danger-soft);
  color: var(--danger);
}

.channel-icon {
  width: 20px;
  text-align: center;
  color: var(--text-faint);
  flex-shrink: 0;
}
.channel-category {
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 18px 0 6px;
  font-weight: 700;
}

.voice-occupants {
  padding-top: 6px;
  padding-bottom: 6px;
  flex-wrap: wrap;
  row-gap: 6px;
}
.voice-occupant {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 3px;
  border-radius: 14px;
  background: var(--bg-elevated);
  font-size: 12px;
  cursor: pointer;
}
.voice-occupant:hover {
  background: var(--bg-hover);
}
.voice-occupant img {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--border);
}
.channel-category:first-child {
  margin-top: 0;
}

.channel-name-edit {
  font-family: inherit;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 13.5px;
  padding: 4px 8px;
  border-radius: 6px;
  width: 220px;
}
.channel-name-edit:hover {
  border-color: var(--border-light);
}
.channel-name-edit:focus {
  border-color: var(--accent);
  background: var(--bg);
  outline: none;
}

.member-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--border);
}
.member-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  line-height: 0;
}
.status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
}
.member-name {
  font-weight: 600;
  font-size: 13.5px;
}
.member-username {
  font-size: 11.5px;
  color: var(--text-faint);
}
.role-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 280px;
}
.role-pill {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
}

.loading,
.empty-row {
  color: var(--text-faint);
  padding: 24px;
  text-align: center;
  font-size: 13px;
}
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.loading::before {
  content: "";
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#tab-content.tab-fade-in {
  animation: tabFadeIn 0.18s ease-out;
}
@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 10, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.12s ease-out;
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal {
  width: 480px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
}
.modal.modal-wide {
  width: 760px;
}
.modal h3 {
  margin: 0 0 18px;
  font-size: 16px;
}

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input[type="text"],
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text);
  outline: none;
}
.field input[type="text"]:focus,
.field textarea:focus {
  border-color: var(--accent);
}
.field-row {
  display: flex;
  gap: 12px;
}
.field-row .field {
  flex: 1;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.color-row input[type="color"] {
  width: 40px;
  height: 36px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: none;
  padding: 2px;
  cursor: pointer;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
}
.switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .track {
  position: absolute;
  inset: 0;
  background: var(--border-light);
  border-radius: 20px;
  transition: background 0.15s;
  cursor: pointer;
}
.switch .track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch input:checked + .track {
  background: var(--success);
}
.switch input:checked + .track::before {
  transform: translateX(16px);
}

.perm-group {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.perm-group summary {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 700;
  background: var(--bg-elevated);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.perm-group summary::-webkit-details-marker {
  display: none;
}
.perm-group summary .count {
  color: var(--text-faint);
  font-weight: 500;
}
.perm-list {
  padding: 6px 12px 10px;
}
.perm-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 12.5px;
}
.perm-check input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.modal-actions .right {
  display: flex;
  gap: 8px;
}

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  min-width: 240px;
  animation: slideIn 0.15s ease-out;
}
.toast.success {
  border-left-color: var(--success);
}
.toast.error {
  border-left-color: var(--danger);
}
@keyframes slideIn {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.hidden {
  display: none !important;
}

/* ---------- Ajouts : verrous, réordonnancement, sélection en masse ---------- */

.lock-icon {
  font-size: 11px;
  opacity: 0.85;
}

.reorder-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.reorder-btns .btn-icon {
  padding: 0 4px;
  height: 15px;
  font-size: 9px;
  line-height: 1;
}

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 12.5px;
}
.bulk-bar select {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text);
}
.bulk-bar .spacer {
  flex: 1;
}

.member-check {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.perm-check.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- Permissions par salon : contrôle à 3 états ---------- */

.tri-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tri-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 12.5px;
}
.tri {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.tri-btn {
  width: 26px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tri-btn:hover {
  border-color: var(--text-dim);
}
.tri-btn.neutral.active {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-light);
}
.tri-btn.allow.active {
  background: var(--success-soft);
  color: var(--success);
  border-color: var(--success);
}
.tri-btn.deny.active {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}

/* ---------- Sélecteurs génériques (nouveau salon, invitations, etc.) ---------- */

.field select,
.panel-toolbar select {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text);
  outline: none;
}
.field select:focus,
.panel-toolbar select:focus {
  border-color: var(--accent);
}

/* ---------- Chat d'un salon ---------- */

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.chat-toolbar input[type="text"] {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text);
  outline: none;
}
.chat-toolbar input[type="text"]:focus {
  border-color: var(--accent);
}
.chat-messages {
  max-height: 58vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 12px;
  padding-right: 4px;
}
.chat-message {
  display: flex;
  gap: 10px;
  padding: 3px 8px;
  margin: 0 -8px;
  border-radius: var(--radius-sm);
}
.chat-message:hover {
  background: var(--bg-hover);
}
.chat-msg-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  flex-shrink: 0;
}
.chat-message:hover .chat-msg-actions {
  opacity: 1;
}
.chat-msg-actions .btn-icon {
  font-size: 12px;
}
.chat-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 12px;
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.6;
}
.reaction-pill img {
  width: 14px;
  height: 14px;
}
.reaction-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.reaction-pill.reaction-add {
  opacity: 0.6;
}
.reaction-pill.reaction-add:hover {
  opacity: 1;
}
.chat-message img.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bg-elevated);
  cursor: pointer;
}
.chat-message .chat-body {
  flex: 1;
  min-width: 0;
}
.chat-message .chat-meta {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 2px;
  display: flex;
  gap: 7px;
  align-items: baseline;
}
.chat-message .chat-author {
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.chat-message .chat-author:hover {
  text-decoration: underline;
}
.chat-message .chat-content {
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}
.mention {
  background: rgba(88, 101, 242, 0.3);
  color: #c9cdfb;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 500;
  cursor: default;
}

/* Regroupement des messages consécutifs d'un même auteur (comme Discord) —
   avatar/nom affichés une fois, les suivants n'ont qu'une heure au survol.
   Le fond au survol (ci-dessus) est un simple changement de `background`
   sans toucher au padding/margin — un changement de dimensions au survol
   fait sauter le texte, donc l'espace de survol est réservé dès le départ
   (constant), jamais ajouté après coup. */
.chat-message.grouped {
  padding-left: 50px;
  position: relative;
}
.chat-grouped-time {
  position: absolute;
  left: 8px;
  top: 5px;
  width: 40px;
  text-align: center;
  font-size: 10px;
  color: var(--text-faint);
  opacity: 0;
}
.chat-message.grouped:hover .chat-grouped-time {
  opacity: 1;
}

/* Sur un écran tactile il n'existe pas de survol : les actions par message
   (supprimer/épingler/réagir) et l'heure des messages groupés resteraient
   invisibles et donc inutilisables. On les affiche en permanence dès qu'on
   détecte l'absence de pointeur à survol, et on agrandit les cibles pour
   rester confortable au doigt (44px recommandé). */
@media (hover: none) {
  .chat-msg-actions {
    opacity: 1;
  }
  .chat-msg-actions .btn-icon {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }
  .chat-message.grouped .chat-grouped-time {
    opacity: 1;
  }
  .btn-icon {
    width: 36px;
    height: 36px;
  }
  .pin-star {
    padding: 8px;
  }
  .copy-id-btn {
    padding: 6px;
  }
}
.chat-attachment img {
  max-width: 220px;
  max-height: 160px;
  border-radius: 6px;
  margin-top: 6px;
  display: block;
}
.chat-attachment a {
  color: var(--accent);
  font-size: 12px;
}
.chat-embed {
  border-left: 3px solid var(--accent);
  background: var(--bg-elevated);
  border-radius: 4px;
  padding: 8px 10px;
  margin-top: 6px;
  font-size: 12.5px;
}
.chat-embed .title {
  font-weight: 700;
  margin-bottom: 2px;
}

.chat-composer {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.chat-composer input[type="text"] {
  flex: 1;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text);
  outline: none;
}
.chat-composer input[type="text"]:focus {
  border-color: var(--accent);
}
.chat-composer input[type="text"]:disabled {
  opacity: 0.6;
}

/* ---------- Palette façon Discord, limitée à la fenêtre de chat ---------- */
/* Le reste du panel garde son propre thème — seule la zone de
   conversation emprunte les couleurs réelles de Discord (#313338 etc.)
   pour ressembler à s'y méprendre à l'app native. */
.chat-modal {
  background: #313338;
  border-color: #1e1f22;
}
.chat-modal h3 {
  color: #f2f3f5;
}
.chat-modal .chat-toolbar {
  background: #2b2d31;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #1e1f22;
}
.chat-modal .role-meta {
  color: #949ba4;
}
.chat-modal .chat-content {
  color: #dbdee1;
}
.chat-modal .chat-author {
  color: #f2f3f5;
}
.chat-modal .chat-meta span {
  color: #949ba4;
}
.chat-modal .chat-composer input[type="text"] {
  background: #383a40;
  border-color: #1e1f22;
  color: #f2f3f5;
}
.chat-modal .empty-row {
  color: #6d6f78;
}

.author-popover {
  position: fixed;
  z-index: 250;
  width: 260px;
  max-height: min(420px, calc(100vh - 24px));
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  animation: fadeIn 0.12s ease-out;
}

/* Fiche "pop-out" façon profil Discord : bannière + avatar qui déborde,
   comme le vrai popup de profil quand on clique un pseudo dans Discord. */
.discord-profile-popover {
  width: 300px;
  padding: 0;
  overflow: hidden;
  background: #232428;
  border-color: #1e1f22;
  /* La bannière garde ses coins carrés à l'intérieur (elle est en haut) —
     seul le corps scrolle si un membre a beaucoup de rôles, la bannière
     reste fixe en haut plutôt que de défiler avec le reste. */
  display: flex;
  flex-direction: column;
}
.discord-profile-banner {
  height: 60px;
  flex-shrink: 0;
  background-position: center;
  background-size: cover;
}
.discord-profile-body {
  padding: 0 14px 14px;
  overflow-y: auto;
}
.discord-profile-avatar-wrap {
  position: relative;
  width: 66px;
  margin-top: -33px;
}
.discord-profile-avatar {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 4px solid #232428;
  background: #232428;
  display: block;
}
.discord-profile-avatar-wrap .status-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  border-color: #232428 !important;
}
.discord-profile-name {
  color: #f2f3f5;
  font-weight: 700;
  font-size: 16px;
  margin-top: 8px;
}
.discord-profile-username {
  color: #949ba4;
  font-size: 12.5px;
}
.discord-profile-dates {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #2b2d31;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  color: #dbdee1;
}
.discord-profile-dates .role-meta {
  color: #949ba4;
}

/* ---------- Autocomplétion @mention ---------- */

.chat-input-wrap {
  position: relative;
  flex: 1;
}
.mention-suggestions {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 60;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
}
.mention-item:hover {
  background: var(--bg-hover);
}
.mention-item img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---------- Sélecteur d'émojis (toute la flotte) ---------- */

.emoji-picker {
  position: fixed;
  z-index: 250;
  width: 300px;
  max-height: 360px;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
  animation: fadeIn 0.12s ease-out;
}
.emoji-picker input[type="text"] {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text);
  outline: none;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.emoji-picker input[type="text"]:focus {
  border-color: var(--accent);
}
#emoji-picker-grid {
  overflow-y: auto;
}
.emoji-group-label {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 700;
  margin: 8px 0 4px;
}
.emoji-group-label:first-child {
  margin-top: 0;
}
.emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.emoji-item {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  padding: 2px;
}
.emoji-item:hover {
  background: var(--bg-hover);
}

/* ---------- Copier un ID ---------- */

.copy-id-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 11px;
  padding: 0 2px;
  vertical-align: middle;
  transition: color 0.12s;
}
.copy-id-btn:hover {
  color: var(--accent);
}

/* ---------- Mode compact ---------- */

body.compact .row {
  padding: 6px 10px;
}
body.compact .card-list {
  gap: 3px;
}
body.compact .chat-message {
  padding: 1px 8px;
}
body.compact .stat-card {
  padding: 10px 12px;
}
body.compact .main {
  padding-top: 18px;
}
body.compact .guild-header {
  margin-bottom: 14px;
}
body.compact .tabs {
  margin-bottom: 12px;
}
#compact-toggle-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}
