:root {
  --bg: #191d24;
  --surface: #212630;
  --surface-2: #262c37;
  --border: #333b48;
  --text: #e8e6e1;
  --muted: #8b92a0;
  --amber: #e8a33d;
  --green: #6fcf97;
  --red: #e0674f;
  --font-display: "Fraunces", serif;
  --font-body: "Inter", -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
  width: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.55;
  overflow-x: hidden;
  width: 100%;
  overscroll-behavior: none;
  touch-action: pan-y;
  padding-top: 64px; /* hauteur du header, désormais fixe */
}

body.modal-open { overflow: hidden; }

img, video, iframe { max-width: 100%; }

a { color: var(--amber); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  overflow-x: hidden;
}

/* --- Header / signature pulse --- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 700;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand:hover { text-decoration: none; }
.brand-logo { width: 30px; height: 30px; border-radius: 50%; }

.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.pulse-dot.is-up {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(111, 207, 151, 0.6);
  animation: pulse 2.4s infinite;
}
.pulse-dot.is-down { background: var(--red); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(111, 207, 151, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(111, 207, 151, 0); }
  100% { box-shadow: 0 0 0 0 rgba(111, 207, 151, 0); }
}

.mainnav { display: flex; gap: 18px; flex: 1; }
.mainnav a { color: var(--muted); font-weight: 500; font-size: 0.95rem; }
.mainnav a:hover { color: var(--text); text-decoration: none; }
.mainnav a.is-active { color: var(--amber); }

.who {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  font-family: var(--font-mono);
}
.who a { color: var(--muted); }
.who-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }

.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  margin-left: auto;
  padding: 4px 8px;
}

.mobile-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 900;
}
.mobile-menu-backdrop.is-open { opacity: 1; pointer-events: auto; }

.mobile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 78%;
  max-width: 300px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 901;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.mobile-drawer.is-open { transform: translateX(0); }
.mobile-drawer-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--muted);
  padding-bottom: 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.mobile-drawer a {
  color: var(--text);
  font-size: 1.02rem;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.mobile-drawer a.is-active { color: var(--amber); }
.mobile-drawer a:hover { text-decoration: none; background: var(--surface-2); }

/* --- Flash messages --- */
.flashes { max-width: 760px; margin: 16px auto 0; padding: 0 20px; }
.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
}
.flash-success { border-color: var(--green); color: var(--green); }
.flash-error { border-color: var(--red); color: var(--red); }

/* --- Typography --- */
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 2rem; margin: 0 0 6px; }
h2 { font-size: 1.4rem; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* --- Blog entries (log entries) --- */
.entry-list { display: flex; flex-direction: column; gap: 0; }
.entry { padding: 22px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.entry:first-child { padding-top: 0; }
.entry-meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
}
.entry-no { color: var(--amber); }
.entry h2 a { color: var(--text); }
.entry-excerpt { color: var(--muted); margin: 6px 0 0; overflow-wrap: anywhere; }

.entry-body { white-space: pre-wrap; margin-top: 18px; overflow-wrap: anywhere; word-break: break-word; }

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 28px;
  text-align: center;
}

/* --- Blog grid (façon korben.info) --- */
.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-top: 20px;
}
.blog-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  color: var(--text);
}
.blog-card:hover { border-color: var(--amber); text-decoration: none; }
.blog-card .cover {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}
.blog-card .cover-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}
.blog-card .cover-placeholder img { width: 40%; height: 40%; object-fit: contain; opacity: 0.5; }
.blog-card .content { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.blog-card h3 { margin: 0; font-family: var(--font-display); font-size: 1.05rem; line-height: 1.3; }
.blog-card .meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }
.blog-card .excerpt { font-size: 0.85rem; color: var(--muted); margin: 0; overflow-wrap: anywhere; }

/* --- Forms --- */
.form-field { margin-bottom: 16px; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], textarea, select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 0.95rem;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}
textarea { min-height: 260px; resize: vertical; }

button, .btn {
  background: var(--amber);
  color: #1a1206;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.92rem;
}
button:hover, .btn:hover { opacity: 0.9; text-decoration: none; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-danger { background: var(--red); color: #2a0d06; }

.actions { display: flex; gap: 10px; margin-top: 20px; }

/* --- Login --- */
.login-shell {
  max-width: 360px;
  margin: 12vh auto 0;
  padding: 0 20px;
  text-align: center;
}
.login-shell h1 { text-align: center; }
.login-shell form { text-align: left; margin-top: 24px; }
.login-hint { color: var(--muted); font-size: 0.85rem; margin-top: 20px; }

/* --- Polls --- */
.poll-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 16px;
  background: var(--surface);
}
.poll-option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}
.poll-bar-track {
  flex: 1;
  height: 10px;
  background: var(--surface-2);
  border-radius: 5px;
  overflow: hidden;
}
.poll-bar-fill { height: 100%; background: var(--amber); }
.poll-pct { font-family: var(--font-mono); font-size: 0.8rem; color: var(--muted); width: 42px; text-align: right; }
.poll-closed-tag { color: var(--red); font-family: var(--font-mono); font-size: 0.75rem; }

/* --- Chat --- */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: 65vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.chat-shell.chat-compact { height: 420px; }
.chat-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.chat-msg { max-width: 85%; overflow-wrap: anywhere; }
.chat-msg .who { font-family: var(--font-mono); font-size: 0.75rem; color: var(--amber); margin-bottom: 6px; }
.chat-msg .who .time { font-family: var(--font-mono); font-size: 0.68rem; color: var(--muted); margin-left: 6px; }
.chat-msg .bubble-row { display: flex; align-items: flex-end; gap: 8px; }
.chat-msg .body {
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.chat-msg .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.chat-form {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  align-items: center;
  flex-wrap: wrap;
}
.chat-form input[type=text] { flex: 1; min-width: 0; }
.normal-controls { display: flex; align-items: center; gap: 8px; }
.chat-form.is-recording .normal-controls { display: none; }

/* --- Barre d'enregistrement vocal (façon WhatsApp) --- */
.recording-bar {
  display: none;
  align-items: center;
  gap: 12px;
  flex: 1;
}
.chat-form.is-recording .recording-bar { display: flex; }
.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse 1.2s infinite;
  flex-shrink: 0;
}
#rec-timer { font-family: var(--font-mono); font-size: 0.9rem; color: var(--text); min-width: 40px; }

/* --- Modale bottom-sheet (emoji + GIF) : centrée par flexbox, ne peut
   jamais déborder de l'écran, quel que soit l'endroit d'où elle s'ouvre --- */
.picker-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.picker-modal-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 75vh;
  background: #12151b;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
}
.picker-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  flex-shrink: 0;
}
.picker-modal-close {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.picker-modal-body { padding: 14px 16px 20px; overflow-y: auto; flex: 1; }

.gif-search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.95rem;
  margin-bottom: 12px;
}
.gif-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.gif-results img { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; cursor: pointer; }
.gif-status { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; padding: 8px 0; }

/* --- Chat media --- */
.chat-msg .body img.chat-image {
  max-width: 240px;
  max-height: 240px;
  border-radius: 8px;
  display: block;
}
.chat-msg .body audio { width: 220px; max-width: 100%; display: block; }

/* --- Monitoring --- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin: 20px 0;
}
.stat-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
}
.stat-card .label { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); text-transform: uppercase; }
.stat-card .value { font-family: var(--font-mono); font-size: 1.6rem; margin-top: 6px; color: var(--amber); }
.stat-card .sub { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); margin-top: 4px; }

.container-table { width: 100%; border-collapse: collapse; margin-top: 24px; font-family: var(--font-mono); font-size: 0.85rem; }
.container-table th, .container-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.state-running { color: var(--green); }
.state-exited, .state-dead { color: var(--red); }

.monitor-error {
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 8px;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

@media (max-width: 600px) {
  .topbar { padding: 14px 16px; }
  .mainnav, .topbar .who { display: none; }
  .hamburger-btn { display: block; }
  .wrap { padding: 20px 14px 60px; }

  h1 { font-size: 1.5rem; }

  /* Le chat prend moins de place en hauteur sur mobile */
  .chat-shell { height: 70vh; }
  .chat-shell.chat-compact { height: 360px; }
  .chat-msg { max-width: 92%; }
  .chat-msg .body img.chat-image { max-width: 180px; max-height: 180px; }
  .chat-msg .body audio { width: 170px; }
  .chat-form { padding: 10px; gap: 8px; }
  .normal-controls { gap: 6px; }
  .icon-btn { padding: 8px; }

  /* Les formulaires empilent proprement au lieu de déborder */
  .toolbar-field { flex-wrap: wrap; }
  .link-form { flex-direction: column; align-items: stretch; }
  .link-form input[type=text] { min-width: 0; }
  .actions { flex-wrap: wrap; }

  /* Grilles à une colonne */
  .apps-grid { grid-template-columns: repeat(2, 1fr); }
  .blog-grid { grid-template-columns: 1fr; }
  .admin-hub-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  /* Tableaux : défilement horizontal contenu plutôt que débordement de page */
  .simple-table, .container-table { display: block; overflow-x: auto; white-space: nowrap; }

  .picker-modal-sheet { max-height: 85vh; }
  .poll-option-row { flex-wrap: wrap; }
  .poll-bar-track { min-width: 100px; }
}

/* --- Emoji picker (emoji-picker-element), à l'intérieur d'une modale
   bottom-sheet (.picker-modal-sheet) posée par emoji-picker.js --- */
emoji-picker.emoji-popover-el {
  width: 100%;
  height: min(60vh, 420px);
  border: none;
  border-radius: 0;
  box-shadow: none;
  --background: #12151b;
  --border-color: var(--border);
  --indicator-color: var(--amber);
  --input-border-color: var(--border);
  --input-font-color: var(--text);
  --input-placeholder-color: var(--muted);
  --outline-color: var(--amber);
  --category-font-color: var(--muted);
  --num-columns: 8;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.is-recording { border-color: var(--red); color: var(--red); }

.toolbar-field { position: relative; display: flex; gap: 8px; }

/* --- Blog rich content --- */
.entry-body img, .entry-body video {
  max-width: 100%;
  border-radius: 8px;
  margin: 16px 0;
  display: block;
}
.yt-embed {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  margin: 16px 0;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}
.yt-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* --- Apps launcher (façon Homarr) --- */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.app-tile {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  padding: 18px 10px;
  text-align: center;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.app-tile:hover { border-color: var(--amber); text-decoration: none; transform: translateY(-1px); }
.app-tile .icon { font-size: 2rem; }
.app-tile .icon-img { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; }
.app-tile .name { font-weight: 600; font-size: 0.9rem; }
.app-tile .desc { font-size: 0.75rem; color: var(--muted); }

/* --- Liens utiles --- */
.link-list { display: flex; flex-direction: column; gap: 0; margin-top: 12px; }
.link-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.link-row .meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.link-form { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.link-form input[type=text] { flex: 1; min-width: 160px; }

.admin-hub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-top: 20px; }
.admin-hub-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 20px;
  color: var(--text);
}
.admin-hub-card:hover { border-color: var(--amber); text-decoration: none; }
.admin-hub-card .name { font-weight: 600; font-family: var(--font-display); font-size: 1.1rem; }
.admin-hub-card .desc { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }

.simple-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.simple-table th, .simple-table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); }
.simple-table td.actions-cell { display: flex; gap: 8px; }
