:root {
  --bg: #f4f4f1;
  --dot: #c9c9c4;
  --panel: #ffffff;
  --panel-border: #e3e3df;
  --text: #1f1f1d;
  --muted: #74746f;
  --accent: #4262ff;
  --accent-soft: #e6eaff;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  --s: 1; /* inverse du zoom, pour garder poignées et curseurs à taille constante */
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  border-radius: 6px;
}

/* ---------- Surface infinie ---------- */
#board {
  position: fixed;
  inset: 0;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.2px);
  touch-action: none;
  cursor: default;
}
#board.tool-hand, #board.panning { cursor: grab; }
#board.panning:active { cursor: grabbing; }
#board.tool-pen, #board.tool-arrow, #board.tool-rect,
#board.tool-ellipse, #board.tool-sticky, #board.tool-text { cursor: crosshair; }

#world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

#objects { position: relative; }

/* ---------- Objets ---------- */
.obj {
  position: absolute;
  user-select: none;
}

.obj .text {
  width: 100%;
  height: 100%;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
  line-height: 1.25;
}
.obj .text[contenteditable] { cursor: text; user-select: text; }

.sticky {
  box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 6px 14px rgba(0,0,0,.10);
  padding: 16px;
}
.sticky .text {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.rect, .ellipse {
  display: flex;
  border: 2px solid rgba(0, 0, 0, 0.55);
  padding: 10px;
}
.ellipse { border-radius: 50%; padding: 14% 12%; }
.rect .text, .ellipse .text {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 18px; /* remplacée par o.fs pour les formes importées */
}

.textobj .text { font-size: 24px; }
.textobj.empty .text::before { content: "Texte"; color: var(--muted); }

.obj svg { position: absolute; overflow: visible; pointer-events: none; }
.obj svg .hit { stroke: transparent; fill: none; pointer-events: stroke; }
.obj svg .ink { fill: none; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.path, .arrow { pointer-events: none; }

/* Sélection locale */
.obj.selected { outline: calc(2px * var(--s)) solid var(--accent); outline-offset: calc(2px * var(--s)); }
.path.selected, .arrow.selected { outline: none; }
.path.selected .ink, .arrow.selected .ink { filter: drop-shadow(0 0 calc(3px * var(--s)) var(--accent)); }

/* Sélection d'un autre participant */
.obj.remote-sel { outline: calc(2px * var(--s)) dashed var(--rc); outline-offset: calc(4px * var(--s)); }

.handle {
  position: absolute;
  width: calc(12px * var(--s));
  height: calc(12px * var(--s));
  background: #fff;
  border: calc(2px * var(--s)) solid var(--accent);
  border-radius: 50%;
  pointer-events: auto;
  z-index: 2;
}
.handle.resize { right: calc(-8px * var(--s)); bottom: calc(-8px * var(--s)); cursor: nwse-resize; }
.handle.end { cursor: move; transform: translate(-50%, -50%); }

/* Votes */
.votes {
  position: absolute;
  right: 6px;
  bottom: 6px;
  font-size: 13px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.sticky:hover .votes, .votes.has { opacity: 1; }
.votes.mine { background: var(--accent); color: #fff; }

#marquee {
  position: absolute;
  border: calc(1px * var(--s)) solid var(--accent);
  background: rgba(66, 98, 255, 0.08);
  pointer-events: none;
}

/* Curseurs des autres participants */
.cursor {
  position: absolute;
  pointer-events: none;
  transform: scale(var(--s));
  transform-origin: 0 0;
  transition: left .08s linear, top .08s linear;
  z-index: 1000000;
}
.cursor svg { width: 18px; height: 18px; display: block; }
.cursor span {
  display: inline-block;
  margin: 2px 0 0 12px;
  padding: 2px 8px;
  border-radius: 8px;
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
}

/* ---------- Panneaux ---------- */
.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 10;
}

#topbar {
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
}
#topbar .logo { color: var(--accent); }
#board-name { color: var(--muted); font-size: 13px; }
#topbar button { padding: 4px 8px; background: var(--accent-soft); color: var(--accent); }
.status { font-size: 12px; }
.status.online { color: #2f9e44; }
.status.offline { color: #f03e3e; }

#presence {
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
}
#avatars { display: flex; }
.avatar {
  width: 28px;
  height: 28px;
  margin-left: -6px;
  border-radius: 50%;
  border: 2px solid #fff;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
}
#me { display: flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px; }
#me:hover { background: var(--bg); }

#timer {
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
#timer.done { background: #ffe3e3; color: #c92a2a; animation: pulse 1s infinite alternate; }
#timer button { font-size: 14px; color: var(--muted); padding: 2px 6px; }
@keyframes pulse { to { transform: translateX(-50%) scale(1.06); } }

#toolbar {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
}
#toolbar button { width: 40px; height: 40px; display: grid; place-items: center; }
#toolbar button:hover { background: var(--bg); }
#toolbar button.active { background: var(--accent-soft); color: var(--accent); }
#toolbar svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#toolbar hr { width: 70%; border: 0; border-top: 1px solid var(--panel-border); margin: 4px auto; }

#contextbar {
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
}
#contextbar button { min-width: 32px; height: 32px; font-size: 16px; }
#contextbar button:hover { background: var(--bg); }
#palette { display: flex; gap: 4px; }
.swatch {
  width: 24px !important;
  min-width: 0 !important;
  height: 24px !important;
  border-radius: 50% !important;
  border: 1px solid rgba(0,0,0,.15) !important;
}
.swatch.current { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.sep { width: 1px; height: 22px; background: var(--panel-border); margin: 0 4px; }

#zoombar {
  right: 12px;
  bottom: 16px;
  display: flex;
  align-items: center;
  padding: 4px;
}
#zoombar button { min-width: 32px; height: 32px; font-size: 16px; }
#zoombar button:hover { background: var(--bg); }
#zoom-value { font-size: 13px !important; min-width: 52px !important; }

#toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 20;
}

@media (max-width: 600px) {
  #board-name, #me .label { display: none; }
  #toolbar { top: auto; bottom: 70px; transform: none; }
}

/* ---------- Cadres ---------- */
.frame {
  border: 1px solid rgba(0, 0, 0, 0.18);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.frame .text {
  position: absolute;
  left: 0;
  top: calc(-24px * var(--s));
  height: auto;
  font-size: calc(14px * var(--s));
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ---------- Fenêtre d'import ---------- */
#miro-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  padding: 20px 22px;
  color: var(--text);
}
#miro-dialog::backdrop { background: rgba(0, 0, 0, 0.3); }
#miro-dialog h2 { margin: 0 0 6px; font-size: 18px; }
#miro-dialog .hint, #miro-dialog details { color: var(--muted); font-size: 13px; }
#miro-dialog label { display: block; margin: 14px 0 0; font-size: 14px; font-weight: 600; }
#miro-dialog input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  font: inherit;
  font-weight: 400;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
}
#miro-dialog input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#miro-dialog details { margin-top: 14px; }
#miro-dialog summary { cursor: pointer; color: var(--accent); }
#miro-dialog ol { padding-left: 20px; }
#miro-dialog code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }
#miro-status { min-height: 1.2em; font-size: 14px; margin: 12px 0 0; }
#miro-status.error { color: #c92a2a; }
#miro-dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
#miro-dialog .actions button { padding: 8px 14px; }
#miro-dialog .actions button:hover { background: var(--bg); }
#miro-dialog .primary { background: var(--accent); color: #fff; }
#miro-dialog .primary:hover { background: #2f4fe0 !important; }
#miro-dialog .primary:disabled { opacity: 0.6; cursor: wait; }

/* ---------- Images et documents ---------- */
.image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: #fff;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  cursor: pointer;
}
.file .icon { font-size: 26px; }
.file .name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Droits ---------- */
body.readonly .edit-only { display: none !important; }
body.readonly .votes { pointer-events: none; }
#role-badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: #fff3bf; color: #8a6d00; }
#menu-btn { padding: 4px 10px !important; font-weight: 700; }

/* ---------- Participants ---------- */
#avatars { cursor: pointer; }
#people {
  top: 62px;
  right: 12px;
  width: 260px;
  max-height: 60vh;
  overflow: auto;
  padding: 10px 12px;
}
.people-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.people-head button { color: var(--muted); padding: 2px 6px; }
#people-list { list-style: none; margin: 0; padding: 0; }
#people-list li { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 14px; }
#people-list .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#people-list .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#people-list .prole { font-size: 12px; color: var(--muted); }

/* ---------- Menu contextuel ---------- */
#ctxmenu {
  z-index: 30;
  min-width: 220px;
  padding: 5px;
  display: flex;
  flex-direction: column;
}
#ctxmenu button {
  text-align: left;
  padding: 7px 10px;
  font-size: 14px;
}
#ctxmenu button:hover { background: var(--bg); }
#ctxmenu button.danger { color: #c92a2a; }
#ctxmenu hr { width: 100%; border: 0; border-top: 1px solid var(--panel-border); margin: 4px 0; }
.menu-palette { display: grid; grid-template-columns: repeat(6, 24px); gap: 6px; padding: 6px 8px; }
.menu-palette .swatch { padding: 0 !important; }

/* ---------- Accès refusé ---------- */
#denied {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(244, 244, 241, 0.96);
  display: grid;
  place-items: center;
  padding: 16px;
}
.denied-box { max-width: 420px; text-align: center; font-size: 17px; }
.denied-icon { font-size: 44px; }

/* ---------- Fenêtres ---------- */
.dlg {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  padding: 20px 22px;
  color: var(--text);
}
.dlg.wide { width: min(560px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0, 0, 0, 0.3); }
.dlg h2 { margin: 0 0 6px; font-size: 18px; }
.dlg h3 { margin: 18px 0 4px; font-size: 15px; }
.dlg .hint { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
.dlg input, .dlg select {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #fff;
}
.dlg input:focus, .dlg select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.dlg button { padding: 8px 14px; }
.dlg button:hover { background: var(--bg); }
.dlg .primary { background: var(--accent); color: #fff; }
.dlg .primary:hover { background: #2f4fe0 !important; }
.dlg .danger { color: #c92a2a; }
.dlg .error { color: #c92a2a; font-size: 14px; min-height: 1.2em; margin: 8px 0 0; }
.dlg .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
#share-links { list-style: none; padding: 0; margin: 0 0 10px; }
#share-links li { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--panel-border); font-size: 14px; }
#share-links li.empty { color: var(--muted); border: 0; }
#share-links .link-info { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#share-links button { padding: 4px 8px; font-size: 13px; }
#share-create { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#share-create input[name=label] { grid-column: 1 / -1; }
#share-create button { grid-column: 1 / -1; }

/* ---------- Aide ---------- */
#help-btn { font-weight: 700; color: var(--accent); }
.dlg.help {
  width: min(860px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 48px));
  padding: 0;
}
.dlg.help[open] { display: flex; flex-direction: column; }
.help-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--panel-border);
}
.help-head h2 { margin: 0; }
.help-head button { color: var(--muted); font-size: 16px; padding: 4px 8px; }
.help-body { display: grid; grid-template-columns: 200px 1fr; flex: 1; min-height: 0; }
#help-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  border-right: 1px solid var(--panel-border);
  overflow-y: auto;
}
#help-nav button { text-align: left; padding: 8px 10px; font-size: 14px; }
#help-nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#help-content { overflow-y: auto; padding: 6px 24px 20px; font-size: 15px; line-height: 1.55; }
#help-content h3 { font-size: 18px; margin: 14px 0 8px; }
#help-content li { margin: 6px 0; }
#help-content .note { background: var(--bg); padding: 8px 12px; border-radius: 8px; font-size: 14px; }
#help-content table { border-collapse: collapse; width: 100%; font-size: 14px; }
#help-content td { padding: 7px 6px; border-bottom: 1px solid var(--panel-border); vertical-align: top; }
#help-content td:first-child { white-space: nowrap; width: 1%; padding-right: 16px; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  font: 600 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
  background: #fff;
  border: 1px solid var(--panel-border);
  border-bottom-width: 2px;
  border-radius: 5px;
}

@media (max-width: 640px) {
  .help-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #help-nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--panel-border); }
  #help-nav button { white-space: nowrap; }
  #help-content { padding: 6px 16px 16px; }
  #help-content td:first-child { white-space: normal; width: 42%; padding-right: 8px; }
}
