:root {
  --bg: #0b0c10;
  --bg-sidebar: #08090d;
  --bg-header: #0d0f16;
  --bg-elevated: #14161f;
  --hover: #1a1d27;
  --selected: #20232f;
  --border: #22252f;
  --text: #eef0f7;
  --text-muted: #9096ac;
  --text-faint: #5b6076;
  --neon-cyan: #00f0ff;
  --neon-pink: #ff2ec4;
  --neon-purple: #9d4dff;
  --danger: #ff3860;
  --online: #23a55a;
  --accent: var(--neon-cyan);
  --glow-sm: 0 0 6px rgba(0, 240, 255, 0.55);
  --glow-lg: 0 0 6px rgba(0, 240, 255, 0.55), 0 0 20px rgba(0, 240, 255, 0.25);
  --glow-pink: 0 0 6px rgba(255, 46, 196, 0.6), 0 0 16px rgba(255, 46, 196, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh; /* évite que la barre d'adresse mobile ne rogne le bas de l'écran */
  overflow: hidden;
}

::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
}

.hidden {
  display: none !important;
}

.screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Écran d'authentification */

#auth-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #12141d 0%, #08090d 70%);
}

.auth-card {
  background: var(--bg-header);
  padding: 32px;
  border-radius: 10px;
  width: 90%;
  max-width: 360px;
  border: 1px solid rgba(0, 240, 255, 0.35);
  box-shadow: var(--glow-lg);
}

.auth-card h1 {
  margin: 0 0 20px;
  font-size: 20px;
  text-align: center;
  color: var(--text);
  text-shadow: var(--glow-sm);
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-card label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.auth-card input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 16px; /* évite le zoom automatique au focus sur iOS Safari (< 16px) */
  background: var(--bg-elevated);
  color: var(--text);
}

.auth-card input:focus {
  outline: none;
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-sm);
}

.auth-card button {
  margin-top: 6px;
  padding: 10px;
  border: 1px solid var(--neon-cyan);
  border-radius: 4px;
  background: var(--neon-cyan);
  color: #05060a;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: box-shadow 0.15s ease;
}

.auth-card button:hover {
  box-shadow: var(--glow-lg);
}

#pin-back {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 400;
}

#pin-back:hover {
  background: transparent;
  color: var(--text);
  box-shadow: none;
  text-decoration: underline;
}

#pin-message {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 10px 0 0;
  text-align: center;
  text-shadow: 0 0 8px rgba(255, 56, 96, 0.5);
}

/* Écran de chat */

.app-layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-toggle-btn {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.6);
  z-index: 940;
}

.sidebar-header {
  padding: 16px;
  font-weight: 700;
  color: var(--text);
  text-shadow: var(--glow-sm);
  border-bottom: 1px solid var(--border);
}

.sidebar-header .bi {
  color: var(--neon-cyan);
}

.channel-list {
  padding: 12px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-left: 3px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}

.channel-item .hash {
  color: var(--text-faint);
  font-weight: 600;
}

.channel-item:hover {
  background: var(--hover);
  color: var(--text);
}

.channel-item.active {
  background: var(--selected);
  color: var(--text);
  border-left-color: var(--neon-cyan);
  box-shadow: inset 0 0 12px rgba(0, 240, 255, 0.08);
}

.channel-item.unread {
  color: var(--text);
  font-weight: 700;
}

.channel-item .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--neon-pink);
  box-shadow: var(--glow-pink);
  flex-shrink: 0;
  visibility: hidden;
}

.channel-item.unread .unread-dot {
  visibility: visible;
}

.online-section {
  padding: 8px 16px 12px;
  border-top: 1px solid var(--border);
}

.online-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.online-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
}

.online-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online);
  box-shadow: 0 0 5px rgba(35, 165, 96, 0.7);
  flex-shrink: 0;
}

.online-pseudo {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-spacer {
  flex: 1;
}

.sidebar-footer {
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.me {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
}

#me-pseudo {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  background: var(--neon-pink);
  box-shadow: var(--glow-pink);
  color: #1a0212;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 8px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-footer-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 15px;
  width: 30px;
  height: 30px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--hover);
  color: var(--neon-cyan);
  box-shadow: var(--glow-sm);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-header);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}

.chat-header .hash {
  color: var(--neon-cyan);
  text-shadow: var(--glow-sm);
}

.admin-panel {
  background: #201322;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 46, 196, 0.4);
  flex-shrink: 0;
  max-height: 260px;
  overflow-y: auto;
}

.admin-panel-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.admin-panel input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 16px;
  background: var(--bg-elevated);
  color: var(--text);
}

.admin-panel-row button {
  padding: 6px 12px;
  border: 1px solid var(--danger);
  border-radius: 4px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: box-shadow 0.15s ease;
}

.admin-panel-row button:hover {
  box-shadow: 0 0 10px rgba(255, 56, 96, 0.4);
}

#admin-panel-msg {
  font-size: 12px;
  color: var(--text-muted);
}

.banned-list-section {
  border-top: 1px solid rgba(255, 46, 196, 0.25);
  padding-top: 8px;
}

.banned-list-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  margin-bottom: 6px;
}

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

.banned-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

.banned-item-empty {
  color: var(--text-faint);
  font-style: italic;
}

.unban-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: box-shadow 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.unban-btn:hover {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-sm);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
}

.history-loading {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  margin: 6px 0 0;
  flex-shrink: 0;
}

.message-row {
  padding: 6px 16px;
  position: relative;
}

.message-row:hover {
  background: var(--hover);
}

.message-row:hover .message-actions {
  display: flex;
}

.message-body {
  min-width: 0;
}

.message-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.message-head .pseudo {
  font-weight: 700;
  color: var(--text);
  font-size: 14px;
}

.message-head .time {
  font-size: 11px;
  color: var(--text-faint);
}

.edited-tag {
  font-size: 10px;
  color: var(--text-faint);
  font-style: italic;
}

.reply-quote {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 12px;
  color: var(--text-faint);
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
}

.reply-quote:hover {
  color: var(--text-muted);
}

.reply-quote .bi {
  flex-shrink: 0;
}

.reply-quote-pseudo {
  color: var(--neon-purple);
  font-weight: 600;
  flex-shrink: 0;
}

.reply-quote-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-text {
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.edit-box {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.edit-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--neon-cyan);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
}

.edit-input:focus {
  outline: none;
}

.edit-save-btn,
.edit-cancel-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 32px;
  color: var(--text-muted);
  cursor: pointer;
}

.edit-save-btn:hover {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
}

.edit-cancel-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.reactions:empty {
  display: none;
  margin-top: 0;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}

.reaction-pill:hover {
  border-color: var(--neon-cyan);
}

.reaction-pill.active {
  border-color: var(--neon-cyan);
  background: rgba(0, 240, 255, 0.12);
  color: var(--text);
}

.reaction-picker {
  position: absolute;
  top: -6px;
  right: 16px;
  transform: translateY(-100%);
  display: flex;
  gap: 2px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: var(--glow-sm);
  z-index: 10;
}

.reaction-picker button {
  background: transparent;
  border: none;
  font-size: 18px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.reaction-picker button:hover {
  background: var(--hover);
}

.chat-link {
  color: var(--neon-cyan);
  text-decoration: none;
  word-break: break-all;
}

.chat-link:hover {
  text-decoration: underline;
  text-shadow: var(--glow-sm);
}

.mention {
  color: var(--neon-purple);
  background: rgba(157, 77, 255, 0.12);
  border-radius: 4px;
  padding: 0 4px;
  font-weight: 600;
}

.mention-self {
  color: #05060a;
  background: var(--neon-pink);
  box-shadow: var(--glow-pink);
}

.inline-code {
  font-family: 'Courier New', Consolas, monospace;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.9em;
}

.message-text strong {
  font-weight: 700;
}

.message-text em {
  font-style: italic;
}

.flash-highlight {
  animation: flash-highlight 1.5s ease;
}

@keyframes flash-highlight {
  0% {
    background: rgba(0, 240, 255, 0.18);
  }
  100% {
    background: transparent;
  }
}

.embed-card {
  display: block;
  max-width: 420px;
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--neon-purple);
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.embed-card:hover {
  border-color: var(--neon-purple);
  box-shadow: 0 0 6px rgba(157, 77, 255, 0.55), 0 0 18px rgba(157, 77, 255, 0.22);
}

.embed-site {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  margin-bottom: 2px;
}

.embed-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--neon-cyan);
  margin-bottom: 4px;
}

.embed-description {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.embed-image {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 4px;
  margin-top: 8px;
}

.message-image {
  display: block;
  max-width: 320px;
  max-height: 320px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-top: 6px;
  cursor: pointer;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.message-image:hover {
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-sm);
}

.message-actions {
  display: none;
  position: absolute;
  top: 4px;
  right: 16px;
  gap: 2px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px;
}

.action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 4px;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  transition: box-shadow 0.15s ease, color 0.15s ease;
}

.action-btn:hover {
  color: var(--neon-cyan);
  background: var(--hover);
  box-shadow: var(--glow-sm);
}

.action-btn-danger:hover {
  color: var(--danger);
  box-shadow: 0 0 10px rgba(255, 56, 96, 0.4);
}

.message-form {
  display: flex;
  align-items: center;
  padding: 12px 16px 20px;
  gap: 8px;
  flex-shrink: 0;
}

.message-form input[type='text'] {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px; /* évite le zoom automatique au focus sur iOS Safari (< 16px) */
  background: var(--bg-elevated);
  color: var(--text);
}

.message-form input[type='text']::placeholder {
  color: var(--text-faint);
}

.message-form input[type='text']:focus {
  outline: none;
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-sm);
}

.message-form button[type='submit'] {
  padding: 10px 14px;
  border: 1px solid var(--neon-cyan);
  border-radius: 6px;
  background: var(--neon-cyan);
  color: #05060a;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: box-shadow 0.15s ease;
}

.message-form button[type='submit']:hover {
  box-shadow: var(--glow-lg);
}

#chat-error {
  text-align: center;
  margin: 4px 0;
  flex-shrink: 0;
}

.typing-indicator {
  font-size: 12px;
  font-style: italic;
  color: var(--text-faint);
  margin: 0;
  padding: 0 16px;
  flex-shrink: 0;
}

.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 16px 0;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--neon-purple);
  border-radius: 6px;
  flex-shrink: 0;
}

.reply-preview-content {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  font-size: 12px;
}

.reply-preview-label {
  color: var(--text-faint);
  flex-shrink: 0;
}

.reply-preview-label strong {
  color: var(--neon-purple);
}

.reply-preview-text {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#reply-preview-cancel {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

/* Popup d'affichage d'image en grand */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  z-index: 1000;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: var(--glow-lg);
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.lightbox-close:hover {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-sm);
}

/* Pages d'erreur (404 / 500) */

.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #12141d 0%, #08090d 70%);
  padding: 20px;
}

.error-card {
  text-align: center;
  background: var(--bg-header);
  border: 1px solid rgba(0, 240, 255, 0.35);
  box-shadow: var(--glow-lg);
  border-radius: 10px;
  padding: 40px 32px;
  width: 90%;
  max-width: 360px;
}

.error-icon {
  font-size: 40px;
  color: var(--neon-cyan);
  text-shadow: var(--glow-sm);
}

.error-card h1 {
  font-size: 48px;
  margin: 12px 0 4px;
  color: var(--text);
}

.error-card p {
  color: var(--text-muted);
  margin: 0 0 20px;
}

.error-link {
  display: inline-block;
  padding: 10px 20px;
  border: 1px solid var(--neon-cyan);
  border-radius: 4px;
  background: var(--neon-cyan);
  color: #05060a;
  font-weight: 700;
  text-decoration: none;
  transition: box-shadow 0.15s ease;
}

.error-link:hover {
  box-shadow: var(--glow-lg);
}

/* Mobile : la sidebar devient un tiroir escamotable au lieu de prendre une
   largeur fixe qui écraserait la zone de chat sur un petit écran. */

@media (max-width: 768px) {
  .sidebar-toggle-btn {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 80%;
    max-width: 280px;
    z-index: 950;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    z-index: 940;
  }

  /* cibles tactiles un peu plus grandes qu'au clavier/souris */
  .icon-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .action-btn {
    width: 32px;
    height: 32px;
  }

  .lightbox-close {
    width: 44px;
    height: 44px;
  }

  .admin-panel-row {
    flex-wrap: wrap;
  }

  .admin-panel input {
    flex: 1;
    min-width: 0;
  }

  .message-image {
    max-width: 240px;
  }
}
