:root {
  --bg: #1e1e1e;
  --bg-side: #181818;
  --bg-bar: #1f1f1f;
  --bg-card: #252526;
  --bg-hover: #2a2d2e;
  --bg-active: #37373d;
  --bg-input: #2b2b2b;
  --border: #2f2f2f;
  --border-strong: #3c3c3c;
  --text: #cccccc;
  --text-strong: #ffffff;
  --muted: #8b8b8b;
  --accent: #0078d4;
  --accent-hover: #1a8ae6;
  --ok: #4ec9b0;
  --warn: #e5c07b;
  --err: #f14c4c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: var(--accent-hover); }
h1, h2, h3 { color: var(--text-strong); font-weight: 600; }
.muted { color: var(--muted); }
.center { text-align: center; }
.spacer { flex: 1; }

/* ---------- Boutons / champs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 6px;
  background: #333; color: var(--text-strong);
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:hover { background: #3d3d3d; }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: #5a1d1d; color: #ffb3b3; }
.btn.danger:hover { background: #742525; }
.btn.ghost { background: transparent; border-color: var(--border-strong); }
.btn.ghost:hover { background: var(--bg-hover); }
.btn.block { width: 100%; justify-content: center; padding: 9px; margin-top: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 28px; height: 28px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px;
}
.icon-btn:hover { background: #3a3a3a; color: var(--text-strong); }

.input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text-strong);
  font: inherit;
  outline: none;
}
.input:focus { border-color: var(--accent); }
.select { width: auto; cursor: pointer; }
.select.small { padding: 4px 6px; font-size: 12px; }
.label { display: block; margin: 12px 0 5px; color: var(--text); font-size: 12px; }
.hint { color: var(--muted); font-size: 11px; margin-top: 4px; }
.form-error { color: #ff8f8f; min-height: 18px; margin-top: 10px; font-size: 12px; }

.avatar {
  width: 24px; height: 24px; flex: none;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #111;
}
.avatar.small { width: 20px; height: 20px; font-size: 10px; }
.avatars { display: flex; }
.avatars .avatar { border: 2px solid var(--bg-card); margin-left: -6px; }
.avatars .avatar:first-child { margin-left: 0; }
.avatars.online .avatar { border-color: var(--bg-bar); }

.badge {
  font-size: 10px; font-weight: 600; letter-spacing: .3px;
  padding: 2px 7px; border-radius: 10px;
  background: #333; color: var(--text);
  white-space: nowrap;
}
.badge.owner { background: #0e3a5c; color: #8fc9ff; }
.badge.editor { background: #1f4a35; color: #8fe3b8; }
.badge.viewer { background: #4a3d1a; color: #f0d58a; }

/* ---------- Barre du haut ---------- */
#topbar {
  height: 44px; flex: none;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: var(--bg-bar);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text-strong); text-decoration: none; white-space: nowrap; }
.logo { color: var(--accent); font-weight: 700; }
#crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; }
.crumb-link { color: var(--muted); text-decoration: none; white-space: nowrap; }
.crumb-link:hover { color: var(--text-strong); }
.crumb-sep { color: #555; }
.crumb-name { color: var(--text-strong); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top-actions { display: flex; align-items: center; gap: 8px; }
#top-actions .avatars { margin-right: 6px; }
.user-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 10px; border-radius: 6px; background: #2a2a2a;
}
.user-btn:hover { background: #333; }
.caret { color: var(--muted); font-size: 10px; }
body[data-view="auth"] #topbar { display: none; }

.dropdown {
  position: fixed; z-index: 200;
  min-width: 200px; padding: 4px;
  background: #252526; border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.dropdown-item { display: block; width: 100%; text-align: left; padding: 7px 10px; border-radius: 5px; }
.dropdown-item:hover { background: var(--accent); color: #fff; }
.dropdown-item.danger { color: #ff9b9b; }
.dropdown-item.danger:hover { background: #742525; color: #fff; }
.dropdown-sep { height: 1px; background: var(--border-strong); margin: 4px 2px; }

/* ---------- Vues ---------- */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view.scroll { overflow-y: auto; }

/* ---------- Connexion ---------- */
#view-auth { overflow-y: auto; background: radial-gradient(ellipse at top, #13293d 0%, var(--bg) 60%); }
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 30px 16px; }
.auth-card {
  width: 100%; max-width: 360px;
  background: var(--bg-card); border: 1px solid var(--border-strong); border-radius: 12px;
  padding: 28px 28px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.auth-card h1 { text-align: center; margin: 4px 0 4px; font-size: 22px; }
.auth-card > p { margin: 0 0 8px; }
.auth-logo { text-align: center; font-size: 34px; font-weight: 700; color: var(--accent); }
.auth-switch { text-align: center; margin: 16px 0 0; color: var(--muted); }

/* ---------- Tableau de bord ---------- */
.dash { max-width: 1100px; width: 100%; margin: 0 auto; padding: 28px 24px 60px; }
.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dash-head h1 { margin: 0 0 2px; font-size: 22px; }
.dash-head p { margin: 0; }
.section-title { font-size: 15px; margin: 34px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card {
  background: var(--bg-card); border: 1px solid var(--border-strong); border-radius: 10px;
  padding: 14px; cursor: pointer;
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color .15s, transform .15s;
  outline: none;
}
.card:hover, .card:focus-visible { border-color: var(--accent); transform: translateY(-1px); }
.card-top { display: flex; align-items: center; gap: 8px; }
.card-icon { font-size: 20px; }
.card-name { font-size: 14px; font-weight: 600; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.card-foot { display: flex; align-items: center; justify-content: space-between; min-height: 28px; }
.card-actions { display: flex; gap: 2px; opacity: .55; transition: opacity .15s; }
.card:hover .card-actions { opacity: 1; }
.empty-card {
  border: 1px dashed var(--border-strong); border-radius: 10px;
  padding: 30px; text-align: center; color: var(--muted); cursor: pointer;
}
.empty-card:hover { border-color: var(--accent); color: var(--text); }
.empty-card .big { font-size: 30px; margin-bottom: 6px; }

/* ---------- Fenêtres modales ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 16px 16px;
  animation: fade .12s ease-out;
}
.modal {
  width: 100%; max-width: 420px;
  background: var(--bg-card); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 24px 60px rgba(0,0,0,.55);
  max-height: 76vh; display: flex; flex-direction: column;
}
.modal.wide { max-width: 540px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 4px 20px; }
.modal-head h2 { margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 4px 20px 16px; overflow-y: auto; }
.modal-body .label:first-child { margin-top: 6px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.confirm-text { margin: 8px 0; line-height: 1.6; }
@keyframes fade { from { opacity: 0; } }

.share-add { display: flex; gap: 8px; margin: 10px 0 4px; }
.share-add .input:first-child { flex: 1; }
.share h3 { font-size: 13px; margin: 18px 0 8px; }
.member-list { display: flex; flex-direction: column; gap: 2px; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 6px; }
.member:hover { background: #2c2c2c; }
.member-name { flex: 1; }
.member-right { display: flex; align-items: center; gap: 4px; }
.share-leave { margin-top: 18px; display: flex; justify-content: flex-end; }

/* ---------- Vue répertoire ---------- */
#layout { flex: 1; display: flex; min-height: 0; }

#sidebar {
  width: 280px; min-width: 200px; max-width: 50vw;
  resize: horizontal; overflow: auto;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: relative;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  padding: 6px 6px 4px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--muted); letter-spacing: .6px;
}
.side-actions { display: flex; gap: 1px; width: 100%; }
#side-write { display: flex; gap: 1px; flex: 1; }
.side-actions button { font-size: 12px; padding: 4px 7px; border-radius: 4px; color: var(--muted); white-space: nowrap; }
.side-actions button:hover { background: var(--bg-hover); color: var(--text); }

#tree { flex: 1; overflow-y: auto; padding-bottom: 20px; user-select: none; }
.tree-empty { padding: 12px 16px; color: var(--muted); line-height: 1.6; }
.tree-row { display: flex; align-items: center; gap: 4px; height: 24px; padding-right: 6px; cursor: pointer; white-space: nowrap; }
.tree-row:hover { background: var(--bg-hover); }
.tree-row.active { background: var(--bg-active); }
.tree-row.selected { box-shadow: inset 2px 0 0 var(--accent); }
.twisty { width: 12px; color: var(--muted); font-size: 10px; flex: none; text-align: center; }
.ficon { font-size: 9px; font-weight: 700; width: 20px; text-align: center; flex: none; }
.ficon.folder { font-size: 13px; }
.tree-name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.pdots { display: flex; gap: 2px; }
.pdot { width: 8px; height: 8px; border-radius: 50%; }
.row-actions { display: none; gap: 1px; }
.tree-row:hover .row-actions { display: flex; }
.row-actions button { padding: 0 4px; border-radius: 3px; color: var(--muted); font-size: 12px; }
.row-actions button:hover { background: #3c3c3c; color: var(--text); }

.drop-hint {
  display: none;
  position: absolute; inset: 36px 6px 6px;
  border: 2px dashed var(--accent); border-radius: 8px;
  background: rgba(0,120,212,.12);
  align-items: center; justify-content: center;
  color: var(--text-strong); font-weight: 600;
  pointer-events: none;
}
#sidebar.drop .drop-hint { display: flex; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#tabs { display: flex; height: 35px; flex: none; background: var(--bg-bar); overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px 0 12px;
  border-right: 1px solid var(--border);
  color: var(--muted); cursor: pointer; white-space: nowrap;
  border-top: 1px solid transparent;
}
.tab:hover { background: #262626; }
.tab.active { background: var(--bg); color: #fff; border-top-color: var(--accent); }
.tab-status { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }
.tab-status.connected { background: var(--ok); }
.tab-close { width: 20px; height: 20px; border-radius: 4px; font-size: 16px; line-height: 1; opacity: .6; }
.tab-close:hover { background: #3c3c3c; opacity: 1; }

#editor-wrap { flex: 1; position: relative; min-height: 0; }
#editor { position: absolute; inset: 0; }
#welcome, #loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--muted);
}
.welcome-box { max-width: 440px; padding: 20px; }
.welcome-box h1 { color: var(--text); font-weight: 500; margin: 4px 0 8px; }
.welcome-box ul { padding-left: 18px; line-height: 1.9; }
.logo.big { font-size: 42px; }

/* Curseurs des autres */
.rcaret { position: absolute; height: 100%; border-left: 2px solid; margin-left: -1px; box-sizing: border-box; z-index: 5; }
.rcaret::after {
  position: absolute; top: -15px; left: -2px;
  padding: 0 4px; border-radius: 3px 3px 3px 0;
  font: 600 10px/14px system-ui, sans-serif; color: #111;
  white-space: nowrap; pointer-events: none; opacity: .9;
}

#statusbar {
  height: 24px; flex: none;
  display: flex; align-items: center; gap: 16px;
  padding: 0 12px;
  background: var(--accent); color: #fff; font-size: 12px;
}
#st-conn.on { color: #d6ffe9; }
#st-conn.wait { color: #fff2c4; }
#st-conn.off { color: #ffd0d0; font-weight: 600; }

/* ---------- Notifications ---------- */
#toasts { position: fixed; right: 16px; bottom: 36px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast {
  background: #252526; border: 1px solid #3c3c3c; border-left: 3px solid var(--accent);
  padding: 8px 14px; border-radius: 4px; max-width: 380px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  transition: opacity .3s, transform .3s;
}
.toast.error { border-left-color: var(--err); }
.toast.out { opacity: 0; transform: translateY(6px); }

@media (max-width: 760px) {
  #top-actions .btn.ghost, .brand + #crumbs .crumb-link, .crumb-sep { display: none; }
  #sidebar { width: 200px; }
}
