/* Coloration syntaxique ISO : une couleur par catégorie (variables --c-* de tokens.css). */

.tok-motion { color: var(--c-motion); font-weight: 600; }
.tok-cycle { color: var(--c-cycle); font-weight: 600; }
.tok-mode { color: var(--c-mode); font-weight: 600; }
.tok-tool { color: var(--c-tool); font-weight: 600; }
.tok-mcode { color: var(--c-mcode); font-weight: 600; }
.tok-program { color: var(--c-program); font-weight: 600; }
.tok-macroKeyword { color: var(--c-macroKeyword); font-weight: 600; }
.tok-address { color: var(--c-address); }
.tok-value { color: var(--c-value); }
.tok-blockNumber { color: var(--c-blockNumber); }
.tok-comment { color: var(--c-comment); font-style: italic; }

/* Variables de macro : toujours mises en évidence (couleur + fond léger). */
.tok-macro {
  color: var(--c-macro);
  background: var(--c-macro-bg);
  border-radius: 3px;
  font-weight: 600;
}

/* Code absent du profil actif, ou caractère invalide : soulignement ondulé. */
.tok-unknown,
.tok-invalid {
  color: var(--c-unknown);
  text-decoration: underline wavy var(--c-unknown);
  text-decoration-skip-ink: none;
  text-underline-offset: 3px;
}

/* Occurrences de l'élément sous le curseur. */
.cm-iso-occurrence {
  background: var(--occurrence-bg);
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--occurrence-bg);
}

.cm-iso-occurrence-current {
  background: var(--occurrence-current);
  box-shadow: 0 0 0 1px var(--occurrence-current);
}

.cm-iso-occurrence.tok-macro,
.cm-iso-occurrence .tok-macro {
  background: transparent;
}

/* ---- Infobulle de définition ---- */

.def-tip {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(440px, calc(100vw - 16px));
  max-height: min(60vh, 520px);
  font-size: 14px;
  line-height: 1.45;
}

/* Smartphone : au plus 45 % de la hauteur, pour tenir au-dessus ou au-dessous du code touché
   (sinon l'infobulle déborde de l'écran et sa croix de fermeture devient inaccessible). */
@media (max-width: 719px) {
  .def-tip {
    max-height: 45vh;
  }
}

.def-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px 6px 14px;
  border-bottom: 1px solid var(--border);
}

.def-code {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.def-category {
  flex: 1;
  color: var(--text-muted);
  font-size: 12px;
}

.def-close {
  width: 34px;
  height: 34px;
}

.def-body {
  display: grid;
  gap: 8px;
  padding: 10px 14px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.def-name {
  font-size: 15px;
  font-weight: 600;
}

.def-meta {
  margin-top: -6px;
  color: var(--text-muted);
  font-size: 12px;
}

.def-redefined {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 13px;
}

.def-details,
.def-notes {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
}

.def-details li {
  font-weight: 500;
}

.def-notes li {
  color: var(--text-muted);
  font-size: 13px;
}

.def-syntax,
.def-example pre {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: pre-wrap;
}

.def-params {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin: 0;
}

.def-params dt {
  color: var(--c-address);
  font-family: var(--font-mono);
  font-weight: 700;
}

.def-params dt.is-used {
  color: var(--accent);
}

.def-params dd {
  margin: 0;
}

.def-value {
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
}

.def-example span {
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---- Macros : avertissement (non bloquant) ---- */

.cm-macro-warning {
  text-decoration: underline wavy var(--warning);
  text-decoration-skip-ink: none;
  text-underline-offset: 3px;
}

.def-warnings {
  display: grid;
  gap: 6px;
}

/* ---- Liste de suggestions (autocomplétion) ---- */

.cm-tooltip.cm-tooltip-autocomplete > ul {
  font-family: var(--font-mono);
  max-height: 14em;
}

.cm-tooltip.cm-tooltip-autocomplete > ul > li {
  padding: 4px 10px;
}

.cm-tooltip-autocomplete ul li[aria-selected] {
  background: var(--accent);
  color: var(--accent-contrast);
}

.cm-completionDetail {
  margin-left: 10px;
  font-family: var(--font-ui);
  font-style: normal;
  opacity: 0.75;
}

.cm-tooltip.cm-completionInfo {
  max-width: min(320px, 70vw);
  padding: 8px 10px;
  font-size: 13px;
}

/* ---- Repliage ---- */

.cm-foldGutter .cm-gutterElement {
  padding: 0 4px;
  color: var(--text-muted);
  cursor: pointer;
}

.cm-foldPlaceholder {
  margin: 0 4px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
}

/* ---- Panneau de recherche ---- */

.cm-panel.cm-search {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  padding: 6px 8px;
  font-family: var(--font-ui);
  font-size: 13px;
}

.cm-panel.cm-search input[type='text'],
.cm-panel.cm-search .cm-textfield {
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
}

.cm-panel.cm-search button,
.cm-panel.cm-search .cm-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  background-image: none;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
}

.cm-panel.cm-search label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.cm-panel.cm-search button[name='close'] {
  border: 0;
  font-size: 18px;
}

.cm-searchMatch {
  background: var(--occurrence-bg);
  outline: 1px solid var(--occurrence-current);
}

.cm-searchMatch-selected {
  background: var(--occurrence-current);
}

/* Valeurs calculées en bout de ligne (module toolpathPreview) : hors du texte, ni sélectionnées ni copiées. */
.cm-calc-value {
  margin-left: 1.5em;
  padding: 0 0.4em;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.92em;
  user-select: none;
}

.cm-calc-part {
  white-space: nowrap;
}

/* Zéro barré (module slashed-zero) : barre oblique dessinée par un dégradé, couleur du texte. */
.cm-zero {
  background-image: linear-gradient(to bottom right, transparent calc(50% - 0.04em), currentColor calc(50% - 0.04em), currentColor calc(50% + 0.04em), transparent calc(50% + 0.04em));
  background-repeat: no-repeat;
  background-position: 50% 50%;
  background-size: 0.42em 0.62em;
}
