:root {
  --bg: #0e0e12;
  --panel: #17171d;
  --panel-2: #1f1f27;
  --border: #2b2b35;
  --text: #e9e9f0;
  --text-dim: #9a9aa8;
  --accent: #9146ff;
  --accent-hover: #a366ff;
  --danger: #ff5470;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
}

.brand-icon { font-size: 1.3rem; }

.add-form {
  display: flex;
  gap: 8px;
  flex: 1 1 320px;
  min-width: 240px;
}

.add-form input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
}

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

.add-form button,
.topbar-actions button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 9px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.add-form button:hover { background: var(--accent-hover); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ghost-btn {
  background: var(--panel-2) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  font-weight: 500 !important;
}

.ghost-btn:hover { border-color: var(--accent) !important; }

.ghost-btn.danger:hover { border-color: var(--danger) !important; color: var(--danger) !important; }

.ghost-btn.active {
  border-color: var(--danger) !important;
  color: var(--danger) !important;
}

.layout-select {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.layout-select select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar button {
  padding: 7px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}

.toolbar-sep {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 0 2px;
}

.site-footer {
  text-align: center;
  padding: 18px 20px 24px;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* Grille en flexbox avec retour à la ligne : l'ordre visuel suit toujours
   l'ordre du DOM (gauche à droite, comme du texte), ce qui rend le
   glisser-déposer prévisible. align-items:flex-start empêche une tuile plus
   haute (ex: chat ouvert) d'étirer ses voisines de la même ligne. */
.grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
}

/* flex-grow: 0 => toutes les tuiles ont la même taille par défaut, elles ne
   s'étirent plus pour combler l'espace restant d'une ligne. */
.tile { flex: 0 1 360px; max-width: 100%; }

.grid[data-columns="1"] .tile { flex-basis: 100%; }
.grid[data-columns="2"] .tile { flex-basis: calc((100% - 12px) / 2); }
.grid[data-columns="3"] .tile { flex-basis: calc((100% - 24px) / 3); }
.grid[data-columns="4"] .tile { flex-basis: calc((100% - 36px) / 4); }
.grid[data-columns="5"] .tile { flex-basis: calc((100% - 48px) / 5); }


.empty-state {
  flex: 1 1 100%;
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
  font-size: 0.95rem;
}

.tile {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tile.dragging { opacity: 0.4; }

.tile-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: var(--panel-2);
  cursor: grab;
  user-select: none;
}

.tile-header:active { cursor: grabbing; }

.tile-name {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 3px 6px;
  border-radius: 5px;
  line-height: 1;
}

.tile-btn:hover {
  background: var(--border);
  color: var(--text);
}

.tile-btn.muted { color: var(--danger); }
.tile-btn.remove:hover { color: var(--danger); }
.tile-btn.active { color: var(--accent); }

.tile-video {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.tile-video iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.embed-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 16px;
  text-align: center;
  color: #f0c674;
  font-size: 0.82rem;
  line-height: 1.5;
}

.tile-chat {
  height: 500px;
  border-top: 1px solid var(--border);
}

.tile-chat iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.chat-frame { background: #18181b; }

.parent-warning {
  margin: 0 16px 16px;
  background: #2a1f10;
  border: 1px solid #5a4315;
  color: #f0c674;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.5;
}

.parent-warning code {
  background: rgba(0,0,0,0.3);
  padding: 1px 6px;
  border-radius: 4px;
}

.hidden { display: none !important; }

/* Focus overlay */
.focus-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.focus-panel {
  width: 100%;
  height: 100%;
  max-width: 1500px;
  display: flex;
  gap: 12px;
}

.focus-video {
  flex: 1;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.focus-video iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.focus-chat {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.focus-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--panel-2);
  font-weight: 600;
  font-size: 0.9rem;
}

.focus-chat .chat-frame {
  flex: 1;
  width: 100%;
  border: none;
}

@media (max-width: 800px) {
  .focus-panel { flex-direction: column; }
  .focus-chat { width: 100%; height: 260px; }
  .topbar { gap: 10px; }
}
