/* ============================================================
   operatori-mappe.css
   Design system + shell layout per l'editor di mappe operatori.
   Prefisso: .mp-* (evita collisioni con hd-*, sv-*, adm-*, ecc.)

   Decisione font mono: Opzione B (zero nuovi file).
   Oswald (già self-hosted) per etichette UPPERCASE.
   System mono stack per eventuali snippet/code.
   ============================================================ */

/* ── Token specifici mappe ── */
:root {
  /* Mappati ai token del sito — i fallback garantiscono autonomia */
  --mp-paper: var(--color-bg, #f8f6f1);
  --mp-paper-2: #ece7da;
  --mp-node-bg: var(--color-bg-card, #fbfaf5);
  --mp-ink: var(--color-text, #1a1714);
  --mp-ink-soft: #3a352e;
  --mp-muted: #7a7064;
  --mp-accent: var(--color-primary, #c04428);
  --mp-accent-deep: #93311d;
  --mp-accent-soft: #e9c8b8;
  --mp-line: var(--color-text, #1a1714);
  --mp-ok: #3f6b4e;
  --mp-warn: #c9892b;

  /* Nodi morbidi (canvas mappe) — pill chiare + bordo tenue */
  --mp-leaf-bg: #ffffff;
  --mp-leaf-border: #e4ded0;

  /* Struttura visiva */
  --mp-border: 2px;
  --mp-radius: 3px;
  --mp-shadow: 4px 4px 0 var(--mp-ink);
  --mp-shadow-sm: 2px 2px 0 var(--mp-ink);

  /* Tipografia */
  --mp-font-display: var(--font-accent, 'Fraunces'), Georgia, serif;
  --mp-font-ui: var(--font-body, 'Plus Jakarta Sans'), 'Inter', system-ui, sans-serif;
  --mp-font-label: var(--font-display, 'Oswald'), 'Inter', system-ui, sans-serif;
  --mp-font-mono: ui-monospace, 'SFMono-Regular', 'Consolas', monospace;

  /* Griglia a puntini */
  --mp-grid-dot: #d9d3c4;

  /* Palette swatch inspector (Fase 5) */
  --mp-swatch-paper: var(--mp-node-bg);
  --mp-swatch-terra: var(--mp-accent);
  --mp-swatch-senape: #c9892b;
  --mp-swatch-petrolio: #2e5e63;
  --mp-swatch-oliva: #6b6b3a;
  --mp-swatch-prugna: #6e3b5c;
  --mp-swatch-verde: #3f6b4e;
  --mp-swatch-ink: var(--mp-ink);

  /* Dimensioni shell */
  --mp-toolbar-h: 52px;
  --mp-toolbar-h-mobile: 48px;
  --mp-status-h: 32px;
}

/* ── Dark mode ── */
[data-theme='dark'] {
  --mp-paper: #1c1917;
  --mp-paper-2: #2a2520;
  --mp-node-bg: #252220;
  --mp-ink: #f0ece4;
  --mp-ink-soft: #c8c0b4;
  --mp-muted: #7a7264;
  --mp-accent: #e05a38;
  --mp-accent-deep: #c04428;
  --mp-accent-soft: #4a2418;
  --mp-line: #f0ece4;
  --mp-grid-dot: #38322c;
  --mp-ok: #5a9b6e;
  --mp-warn: #e0a040;
  --mp-leaf-bg: #2a2622;
  --mp-leaf-border: #3a342c;
}

/* ============================================================
   Shell layout — full viewport, no scroll
   ============================================================ */

/* Override body per pagine con data-app-page="mappe" */
body[data-app-page='mappe'] {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--mp-paper);
  color: var(--mp-ink);
  font-family: var(--mp-font-ui);
}

/* Radice: griglia — toolbar a tutta larghezza in alto (riga 1), poi canvas
   (1fr) e inspector (colonna `auto`) affiancati nella riga 2.
   Il vecchio flex-row-wrap collassava il canvas a width:0: un item flex con
   flex-basis:0 sta sempre sulla stessa riga dell'header width:100%, quindi non
   andava mai a capo e riceveva 0px (canvas invisibile, nodi fuori vista,
   non cliccabili). Con grid la colonna `auto` dell'inspector vale 0 quando è
   [hidden] (display:none) → il canvas occupa tutta la larghezza. Le panel e le
   modali sono position:absolute/fixed: restano fuori dal flusso della griglia
   e non ne alterano le tracce. L'outline è absolute (overlay sinistro). */
.mp-root {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    'toolbar toolbar'
    'canvas inspector'
    'status status';
  width: 100dvw;
  height: 100dvh;
  background: var(--mp-paper);
  color: var(--mp-ink);
  overflow: hidden;
}

.mp-toolbar {
  grid-area: toolbar;
}

.mp-canvas-wrap {
  grid-area: canvas;
}

.mp-statusbar {
  grid-area: status;
}

.mp-inspector {
  grid-area: inspector;
}

/* ============================================================
   Toolbar — chrome chiaro/glassy (look v2)
   ============================================================ */

.mp-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%; /* FIX 4: occupa tutta la riga nel flex-wrap */
  height: var(--mp-toolbar-h);
  min-height: var(--mp-toolbar-h);
  padding: 0 12px;
  background: color-mix(in srgb, var(--mp-paper) 86%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--mp-leaf-border);
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none; /* Firefox */
  box-sizing: border-box;
}

.mp-toolbar::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* Wordmark: "sulla soglia mappe" */
.mp-wordmark {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-right: 12px;
  flex-shrink: 0;
  user-select: none;
}

.mp-wordmark-name {
  font-family: var(--mp-font-ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mp-ink);
  line-height: 1;
}

.mp-wordmark-tag {
  font-family: var(--mp-font-display);
  font-style: italic;
  font-size: 15px;
  font-weight: 400;
  color: var(--mp-accent);
  line-height: 1;
}

/* Separatore visivo tra gruppi */
.mp-toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--mp-leaf-border);
  margin: 0 4px;
  flex-shrink: 0;
}

.mp-toolbar-spacer {
  flex: 1;
}

/* Gruppo di pulsanti correlati */
.mp-toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* ============================================================
   Pulsanti brutalisti .mp-btn
   ============================================================ */

.mp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  min-width: 36px;
  padding: 0 12px;
  background: transparent;
  color: var(--mp-muted);
  border: 0;
  border-radius: 9px;
  font-family: var(--mp-font-ui);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background 0.14s,
    color 0.14s,
    transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

/* Hover: pastiglia calda (look v2) */
.mp-btn:hover {
  background: var(--mp-paper-2);
  color: var(--mp-ink);
}

.mp-btn:active {
  transform: translateY(0.5px);
}

/* Focus visibile per accessibilità */
.mp-btn:focus-visible {
  outline: 2px solid var(--mp-accent);
  outline-offset: 2px;
}

/* Stato attivo (es. layout corrente / tool selezionato): ink pieno */
.mp-btn[aria-pressed='true'],
.mp-btn.mp-btn-active {
  background: var(--mp-ink);
  color: var(--mp-paper);
}

.mp-btn[aria-pressed='true']:hover,
.mp-btn.mp-btn-active:hover {
  background: var(--mp-ink);
  color: var(--mp-paper);
}

/* Variante accento (es. tool Collega attivo) */
.mp-btn.mp-btn-accent {
  background: var(--mp-accent);
  color: #fff;
}

.mp-btn.mp-btn-accent:hover {
  background: var(--mp-accent-deep);
  color: #fff;
}

/* Variante ghost: identica al default ora (compat) */
.mp-btn-ghost {
  border: 0;
}

.mp-btn-ghost:hover {
  background: var(--mp-paper-2);
  color: var(--mp-ink);
}

/* Pulsante solo icona (quadrato) */
.mp-btn-icon {
  width: 36px;
  padding: 0;
  font-size: 16px;
}

/* Mobile: touch target 44px */
@media (pointer: coarse) {
  .mp-btn {
    height: 40px;
    min-width: 40px;
  }

  .mp-btn-icon {
    width: 40px;
  }
}

/* ============================================================
   Mode switch (mentale / concettuale) — pill segmentata
   ============================================================ */

.mp-modeswitch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--mp-leaf-border);
  background: var(--mp-leaf-bg);
  flex-shrink: 0;
}

.mp-mode-btn {
  height: 28px;
  padding: 0 13px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--mp-muted);
  font-family: var(--mp-font-ui);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.16s,
    color 0.16s;
}

.mp-mode-btn:hover {
  color: var(--mp-ink);
}

.mp-mode-btn[aria-pressed='true'] {
  background: var(--mp-ink);
  color: var(--mp-paper);
}

.mp-mode-btn:focus-visible {
  outline: 2px solid var(--mp-accent);
  outline-offset: 2px;
}

/* ============================================================
   Status bar (footer) — meta mono
   ============================================================ */

.mp-statusbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--mp-status-h);
  min-height: var(--mp-status-h);
  padding: 0 14px;
  background: var(--mp-leaf-bg);
  border-top: 1px solid var(--mp-leaf-border);
  font-family: var(--mp-font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mp-muted);
  overflow: hidden;
  white-space: nowrap;
}

.mp-statusbar .mp-sb-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mp-statusbar .mp-sb-item b {
  color: var(--mp-ink);
  font-weight: 600;
}

.mp-statusbar .mp-sb-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mp-ok);
}

.mp-statusbar .mp-sb-sep {
  width: 1px;
  height: 14px;
  background: var(--mp-leaf-border);
  flex-shrink: 0;
}

.mp-statusbar .mp-sb-right {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

@media (max-width: 640px) {
  .mp-statusbar .mp-sb-hide-sm {
    display: none;
  }
}

/* ============================================================
   Mini-toolbar sul nodo selezionato (overlay HTML, look v2)
   ============================================================ */

.mp-node-mini {
  position: absolute;
  z-index: 30;
  transform: translate(-50%, calc(-100% - 9px));
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 3px;
  background: var(--mp-ink);
  border-radius: 999px;
  box-shadow: 0 8px 22px -8px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  pointer-events: auto;
}

.mp-node-mini[hidden] {
  display: none;
}

.mp-node-mini-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: color-mix(in srgb, var(--mp-paper) 80%, transparent);
  cursor: pointer;
  transition:
    background 0.14s,
    color 0.14s;
}

.mp-node-mini-btn svg {
  width: 15px;
  height: 15px;
}

.mp-node-mini-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.mp-node-mini-btn--del:hover {
  background: var(--mp-accent);
  color: #fff;
}

.mp-node-mini-sep {
  width: 1px;
  height: 16px;
  background: rgba(255, 255, 255, 0.16);
  margin: 0 2px;
}

/* ============================================================
   Canvas wrap — area principale
   ============================================================ */

.mp-canvas-wrap {
  flex: 1 1 0;
  /* FIX 4: altezza calcolata sottraendo toolbar + status bar */
  height: calc(100dvh - var(--mp-toolbar-h) - var(--mp-status-h));
  min-width: 0; /* evita overflow nel flex-row */
  position: relative;
  overflow: hidden;
  background: var(--mp-paper);
  /* Impedisce scroll/pinch nativi del browser sull'area canvas */
  touch-action: none;
}

/* ============================================================
   Canvas SVG
   ============================================================ */

.mp-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

/* Cursore durante pan */
.mp-canvas.mp-is-panning,
.mp-canvas:active {
  cursor: grabbing;
}

/* Sfondo carta a puntini (gestito via pattern SVG nel markup) */
.mp-canvas-bg {
  pointer-events: all; /* riceve i pointer events per il pan */
}

/* ============================================================
   World group — pan/zoom applicati qui
   ============================================================ */

.mp-world {
  /* Il transform viene applicato via JS: translate(x,y) scale(s) */
}

/* Layer separati per z-order (archi → link → nodi) */
#mp-layer-arcs {
  pointer-events: none; /* archi strutturali: non interattivi */
}

/* FIX 3: #mp-layer-links deve ricevere click per selezionare i link */
#mp-layer-links {
  pointer-events: all;
}

#mp-layer-nodes {
  pointer-events: all;
}

/* ============================================================
   Status bar
   ============================================================ */

.mp-status {
  position: absolute;
  bottom: 12px;
  left: 12px;
  padding: 3px 8px;
  background: var(--mp-paper);
  border: 1px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  font-family: var(--mp-font-label);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mp-muted);
  opacity: 0.85;
  pointer-events: none;
  /* Nascosta su mobile per non occupare spazio */
}

@media (max-width: 480px) {
  .mp-status {
    display: none;
  }
}

/* ============================================================
   Responsive — toolbar su 375px
   ============================================================ */

@media (max-width: 480px) {
  /* FIX 4: su mobile canvas-wrap torna a tutta larghezza */
  .mp-canvas-wrap {
    width: 100%;
    height: calc(100dvh - var(--mp-toolbar-h-mobile) - var(--mp-status-h));
  }

  .mp-toolbar {
    height: var(--mp-toolbar-h-mobile);
    min-height: var(--mp-toolbar-h-mobile);
    padding: 0 8px;
    gap: 2px;
  }

  .mp-wordmark {
    margin-right: 6px;
  }

  .mp-wordmark-name {
    font-size: 11px;
  }

  .mp-wordmark-tag {
    font-size: 13px;
  }

  .mp-btn {
    height: 36px;
    min-width: 36px;
    padding: 0 8px;
    font-size: 12px;
  }

  .mp-btn-icon {
    width: 36px;
    padding: 0;
  }
}

/* ============================================================
   Animazione ingresso (Fase 0: solo toolbar)
   Rispetta prefers-reduced-motion
   ============================================================ */

@media (prefers-reduced-motion: no-preference) {
  .mp-toolbar {
    animation: mp-toolbar-in 0.2s ease both;
  }

  @keyframes mp-toolbar-in {
    from {
      opacity: 0;
      transform: translateY(-4px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* ============================================================
   Futuri pannelli (Inspector, Outline) — reserved tokens
   Definiti qui come no-op per Fase 0, attivati nelle fasi successive
   ============================================================ */

.mp-panel {
  /* Fase 5: width 260px, border-left, background mp-paper */
  display: none;
}

.mp-panel-label {
  font-family: var(--mp-font-label);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mp-muted);
}

/* ============================================================
   Nodi SVG — .mp-node (Fase 1)
   ============================================================ */

/* Gruppo nodo: cursore pointer, transizione selezione */
.mp-node {
  cursor: pointer;
}

/* Rect sfondo — fill/stroke/filter impostati via JS (look morbido).
   Qui solo la transizione del bordo per la selezione. */
.mp-node-bg {
  transition:
    stroke 0.12s,
    stroke-width 0.12s;
}

/* Nodo in dragging */
.mp-node--dragging {
  opacity: 0.7;
  cursor: grabbing;
}

/* Nodo drop target (reparent) — bordo verde tratteggiato (vince sull'attributo JS) */
.mp-node--drop-target .mp-node-bg {
  stroke: var(--mp-ok);
  stroke-width: 2.5;
  stroke-dasharray: 4 2;
}

/* Testo del nodo */
.mp-node-text {
  font-family: var(--mp-font-ui);
  font-size: 13px;
  font-weight: 500;
  fill: var(--mp-ink);
  pointer-events: none;
  user-select: none;
}

/* Radice / categorie: testo bianco semibold (pill piena colorata) */
.mp-node--root .mp-node-text {
  font-weight: 600;
  font-size: 16px;
}

/* Barra accento sinistra (foglie) — fill colore categoria via JS */
.mp-node-accent {
  pointer-events: none;
}

/* Badge circolare (root/cat) — chip bianco con glifo categoria (Fraunces corsivo) */
.mp-node-badge-text {
  font-family: var(--mp-font-display);
  font-style: italic;
  font-weight: 600;
  pointer-events: none;
  user-select: none;
}

.mp-node-badge-bg {
  /* fill chiaro impostata via JS */
}

/* Toggle collapse +/− */
.mp-node-toggle {
  cursor: pointer;
}

.mp-node-toggle-bg {
  fill: var(--mp-paper);
  stroke: var(--mp-ink);
  stroke-width: 1;
}

.mp-node-toggle-icon {
  fill: var(--mp-ink);
  font-family: var(--mp-font-mono);
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  user-select: none;
  text-anchor: middle;
  dominant-baseline: middle;
}

/* Icona nodo */
.mp-node-icon {
  pointer-events: none;
  user-select: none;
}

/* Badge priorità */
.mp-node-priority-bg {
  /* fill impostata via JS in base al livello priorità */
}

.mp-node-priority-text {
  fill: var(--mp-paper);
  font-family: var(--mp-font-label);
  font-size: 9px;
  font-weight: 700;
  pointer-events: none;
  user-select: none;
}

/* Focus visibile (navigazione tastiera) */
.mp-node:focus-visible {
  outline: 2px solid var(--mp-accent);
  outline-offset: 3px;
}

/* ============================================================
   Archi SVG — .mp-arc (Fase 1)
   ============================================================ */

/* Connettori (look v2): tratto sottile curvo, stroke colore categoria via JS */
.mp-arc {
  fill: none;
  pointer-events: none;
}

/* ============================================================
   Edit in-place — .mp-edit-input (Fase 1)
   ============================================================ */

.mp-edit-input {
  position: absolute;
  z-index: 100;
  box-sizing: border-box;
  padding: 6px 10px;
  background: var(--mp-node-bg);
  color: var(--mp-ink);
  border: 2px solid var(--mp-accent);
  border-radius: var(--mp-radius);
  font-family: var(--mp-font-ui);
  font-size: 13px;
  line-height: 1.4;
  resize: none;
  overflow: hidden;
  box-shadow: 4px 4px 0 var(--mp-ink);
  /* Posizionamento via JS */
}

.mp-edit-input:focus {
  outline: none;
  border-color: var(--mp-accent-deep);
}

/* ============================================================
   Toast leggero — #mp-toast (Fase 1)
   ============================================================ */

.mp-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  padding: 8px 18px;
  background: var(--mp-ink);
  color: var(--mp-paper);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  font-family: var(--mp-font-ui);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 3px 3px 0 var(--mp-accent);
}

.mp-toast--error {
  background: var(--mp-accent);
  border-color: var(--mp-accent-deep);
  box-shadow: 3px 3px 0 var(--mp-ink);
}

@media (prefers-reduced-motion: no-preference) {
  .mp-toast {
    animation: mp-toast-in 0.15s ease both;
  }

  @keyframes mp-toast-in {
    from {
      opacity: 0;
      transform: translateX(-50%) translateY(8px);
    }

    to {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }
  }
}

/* ============================================================
   Pulsanti toolbar editing — stati disabled
   ============================================================ */

.mp-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Assicura che pointer-events sia disabilitato su layer-arcs */
/* (già definito sopra — mantenuto per compatibilità commento) */

/* Dark mode nodi — fill/stroke/filter gestiti via JS (token --mp-leaf-*).
   Nessun override CSS qui per non sovrascrivere gli attributi del renderer. */

[data-theme='dark'] .mp-edit-input {
  border-color: var(--mp-accent);
  box-shadow: 4px 4px 0 rgba(240, 236, 228, 0.2);
}

/* ============================================================
   Selettore layout — Fase 2
   Bottoni .mp-layout-btn iniettati da mappe-main.js nel gruppo
   [data-toolbar-group="layout"]
   ============================================================ */

/* Stato attivo: sfondo accento, testo carta */
.mp-layout-btn[aria-pressed='true'] {
  background: var(--mp-accent);
  color: var(--mp-paper);
  border-color: var(--mp-accent);
}

.mp-layout-btn[aria-pressed='true']:hover {
  background: var(--mp-accent-deep);
  border-color: var(--mp-accent-deep);
}

/* Tooltip esteso su desktop per leggibilità */
@media (hover: hover) {
  .mp-layout-btn {
    position: relative;
  }
}

/* Dark mode: stato attivo layout */
[data-theme='dark'] .mp-layout-btn[aria-pressed='true'] {
  background: var(--mp-accent);
  border-color: var(--mp-accent-deep);
}

/* ============================================================
   Canvas libero (free layout) — Fase 4
   Cursore crosshair per indicare che il doppio click crea un nodo.
   Attivato via data-layout="free" sul body o via classe JS.
   ============================================================ */

/* Il canvas in modalità free mostra cursore crosshair */
body[data-layout='free'] .mp-canvas,
.mp-canvas--free-mode {
  cursor: crosshair;
}

/* Hint visivo: etichetta "doppio clic per creare un nodo" */
.mp-free-hint {
  position: absolute;
  bottom: calc(var(--mp-toolbar-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--mp-ink);
  color: var(--mp-paper);
  font-family: var(--mp-font-ui);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  padding: 4px 10px;
  border-radius: var(--mp-radius);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  white-space: nowrap;
  z-index: 10;
}

/* Mostra l'hint quando il layout free è attivo */
body[data-layout='free'] .mp-free-hint {
  opacity: 1;
}

/* Nodi floating in free mode: bordo tratteggiato accento per distinguerli */
.mp-node--floating .mp-node-bg {
  stroke-dasharray: 4 2;
  stroke: var(--mp-accent);
}

/* Drag del nodo in free mode: feedback visivo */
.mp-node--dragging {
  opacity: 0.75;
}

/* Dark mode: hint */
[data-theme='dark'] .mp-free-hint {
  background: var(--mp-ink);
  color: var(--mp-paper);
}

/* ============================================================
   Inspector — pannello laterale destro (Fase 5)
   Richiudibile: toggled via [hidden] attribute da mappe-main.js
   ============================================================ */

/* Override del placeholder .mp-panel (era display:none) */
.mp-inspector {
  display: flex;
  flex-direction: column;
  width: 268px;
  min-width: 268px;
  max-width: 268px;
  /* FIX 4: altezza calcolata come canvas-wrap */
  height: calc(100dvh - var(--mp-toolbar-h) - var(--mp-status-h));
  background: var(--mp-paper);
  border-left: 1px solid var(--mp-leaf-border);
  overflow: hidden;
  flex-shrink: 0;
  z-index: 10;
}

.mp-inspector[hidden] {
  display: none;
}

/* Header: titolo + bottone chiudi */
.mp-insp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 14px;
  border-bottom: 1.5px solid var(--mp-ink);
  flex-shrink: 0;
  background: var(--mp-paper-2);
}

.mp-insp-title {
  font-family: var(--mp-font-label);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mp-ink);
  flex: 1;
}

.mp-insp-close {
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  border-color: transparent;
  color: var(--mp-muted);
}

.mp-insp-close:hover {
  background: var(--mp-ink);
  color: var(--mp-paper);
  border-color: var(--mp-ink);
}

/* Body scrollabile */
.mp-insp-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--mp-ink) transparent;
}

/* Sezione */
.mp-insp-section {
  padding: 10px 14px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  padding-bottom: 12px;
}

[data-theme='dark'] .mp-insp-section {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.mp-insp-section-title {
  font-family: var(--mp-font-label);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mp-muted);
  margin-bottom: 8px;
}

/* Label testo */
.mp-insp-label {
  font-family: var(--mp-font-ui);
  font-size: 11px;
  color: var(--mp-muted);
  display: block;
  margin-bottom: 4px;
}

/* Textarea generica */
.mp-insp-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  background: var(--mp-node-bg);
  color: var(--mp-ink);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  font-family: var(--mp-font-ui);
  font-size: 12px;
  line-height: 1.4;
  resize: vertical;
  min-height: 52px;
}

.mp-insp-textarea:focus {
  outline: none;
  border-color: var(--mp-accent);
  box-shadow: 0 0 0 2px var(--mp-accent-soft);
}

.mp-insp-textarea--note {
  min-height: 72px;
  font-family: var(--mp-font-mono);
  font-size: 11px;
}

/* Input testo singola riga */
.mp-insp-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  background: var(--mp-node-bg);
  color: var(--mp-ink);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  font-family: var(--mp-font-ui);
  font-size: 12px;
  height: 32px;
}

.mp-insp-input:focus {
  outline: none;
  border-color: var(--mp-accent);
  box-shadow: 0 0 0 2px var(--mp-accent-soft);
}

/* ── Swatch colore ── */
.mp-insp-swatch-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.mp-insp-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 2px;
  border: 1.5px solid var(--mp-ink);
  background: var(--swatch-bg, var(--mp-node-bg));
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.1s;
}

.mp-insp-swatch--paper {
  background: var(--mp-node-bg);
  /* pattern diagonale per indicare "nessun colore / default" */
  background-image: repeating-linear-gradient(
    45deg,
    var(--mp-paper-2) 0px,
    var(--mp-paper-2) 2px,
    transparent 2px,
    transparent 6px
  );
}

.mp-insp-swatch:hover {
  transform: scale(1.15);
  z-index: 1;
}

.mp-insp-swatch--active {
  border-color: var(--mp-accent);
  border-width: 2px;
  transform: scale(1.1);
}

.mp-insp-swatch--active::after {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: 1px;
  box-shadow: inset 0 0 0 1.5px var(--mp-accent);
}

/* ── Selettore forma ── */
.mp-insp-shape-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.mp-insp-shape-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  background: var(--mp-node-bg);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  cursor: pointer;
  color: var(--mp-ink);
  transition: background 0.1s;
  min-height: 36px;
}

.mp-insp-shape-btn:hover {
  background: var(--mp-paper-2);
}

.mp-insp-shape-btn--active,
.mp-insp-shape-btn[aria-pressed='true'] {
  background: var(--mp-accent);
  border-color: var(--mp-accent);
  color: var(--mp-paper);
}

/* ── Griglia icone ── */
.mp-insp-icon-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
}

.mp-insp-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  font-size: 16px;
  background: var(--mp-node-bg);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  min-height: 36px;
  transition: background 0.1s;
}

.mp-insp-icon-btn:hover {
  background: var(--mp-paper-2);
}

.mp-insp-icon-btn--active,
.mp-insp-icon-btn[aria-pressed='true'] {
  background: var(--mp-accent-soft);
  border-color: var(--mp-accent);
}

/* ── Priorità ── */
.mp-insp-prio-row {
  display: flex;
  gap: 3px;
}

.mp-insp-prio-btn {
  flex: 1;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mp-font-label);
  font-size: 11px;
  font-weight: 700;
  background: var(--mp-node-bg);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  cursor: pointer;
  color: var(--mp-ink);
  transition: background 0.1s;
}

.mp-insp-prio-btn[data-prio='0'] {
  color: var(--mp-muted);
  font-weight: 400;
}

.mp-insp-prio-btn[data-prio='1']:hover,
.mp-insp-prio-btn[data-prio='1'].mp-insp-prio-btn--active {
  background: #3f6b4e;
  border-color: #3f6b4e;
  color: var(--mp-paper);
}

.mp-insp-prio-btn[data-prio='2']:hover,
.mp-insp-prio-btn[data-prio='2'].mp-insp-prio-btn--active {
  background: #6b6b3a;
  border-color: #6b6b3a;
  color: var(--mp-paper);
}

.mp-insp-prio-btn[data-prio='3']:hover,
.mp-insp-prio-btn[data-prio='3'].mp-insp-prio-btn--active {
  background: #c9892b;
  border-color: #c9892b;
  color: var(--mp-paper);
}

.mp-insp-prio-btn[data-prio='4']:hover,
.mp-insp-prio-btn[data-prio='4'].mp-insp-prio-btn--active {
  background: #c04428;
  border-color: #c04428;
  color: var(--mp-paper);
}

.mp-insp-prio-btn[data-prio='5']:hover,
.mp-insp-prio-btn[data-prio='5'].mp-insp-prio-btn--active {
  background: #93311d;
  border-color: #93311d;
  color: var(--mp-paper);
}

/* ── Stile linea ── */
.mp-insp-style-row {
  display: flex;
  gap: 3px;
}

.mp-insp-style-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  background: var(--mp-node-bg);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  cursor: pointer;
  color: var(--mp-ink);
  min-height: 36px;
  transition: background 0.1s;
}

.mp-insp-style-btn:hover {
  background: var(--mp-paper-2);
}

.mp-insp-style-btn--active,
.mp-insp-style-btn[aria-pressed='true'] {
  background: var(--mp-accent);
  border-color: var(--mp-accent);
  color: var(--mp-paper);
}

/* ── Freccia ── */
.mp-insp-arrow-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mp-insp-arrow-btn {
  width: 100%;
  padding: 6px 10px;
  text-align: left;
  background: var(--mp-node-bg);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  cursor: pointer;
  font-family: var(--mp-font-ui);
  font-size: 12px;
  color: var(--mp-ink);
  min-height: 34px;
  transition: background 0.1s;
}

.mp-insp-arrow-btn:hover {
  background: var(--mp-paper-2);
}

.mp-insp-arrow-btn--active,
.mp-insp-arrow-btn[aria-pressed='true'] {
  background: var(--mp-accent);
  border-color: var(--mp-accent);
  color: var(--mp-paper);
}

/* ── Azioni ── */
.mp-insp-actions-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mp-insp-action-btn {
  width: 100%;
  justify-content: flex-start;
  font-size: 12px;
  height: 32px;
  padding: 0 10px;
}

.mp-insp-action-btn--danger {
  color: var(--mp-accent);
  border-color: var(--mp-accent);
}

.mp-insp-action-btn--danger:hover {
  background: var(--mp-accent);
  color: var(--mp-paper);
  border-color: var(--mp-accent-deep);
}

/* ── Bottone toggle inspector nella toolbar ── */
.mp-inspector-toggle[aria-pressed='true'] {
  background: var(--mp-ink);
  color: var(--mp-paper);
  border-color: var(--mp-ink);
}

/* ── Mobile (375px): inspector bottom-sheet ── */
@media (max-width: 640px) {
  /* La radice passa a una sola colonna: toolbar / canvas / inspector impilati.
     Senza questo override l'inspector resterebbe nella colonna `auto` della
     griglia desktop (a destra) invece di diventare un bottom-sheet. */
  .mp-root {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      'toolbar'
      'canvas'
      'inspector';
  }

  /* Su mobile: inspector diventa bottom-sheet */
  .mp-inspector {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: auto; /* FIX 4: su mobile non fissiamo altezza calcolata */
    max-height: 55vh;
    border-left: none;
    border-top: var(--mp-border) solid var(--mp-ink);
  }

  .mp-insp-body {
    /* scrollabile orizzontalmente su mobile per le griglia swatch */
    overflow-x: auto;
  }

  .mp-insp-swatch-grid {
    grid-template-columns: repeat(8, 28px);
  }

  .mp-insp-icon-grid {
    grid-template-columns: repeat(9, 32px);
  }
}

/* ── Dark mode inspector ── */
[data-theme='dark'] .mp-insp-header {
  background: var(--mp-paper-2);
  border-bottom-color: var(--mp-ink);
}

[data-theme='dark'] .mp-insp-textarea,
[data-theme='dark'] .mp-insp-input,
[data-theme='dark'] .mp-insp-shape-btn,
[data-theme='dark'] .mp-insp-icon-btn,
[data-theme='dark'] .mp-insp-prio-btn,
[data-theme='dark'] .mp-insp-style-btn,
[data-theme='dark'] .mp-insp-arrow-btn,
[data-theme='dark'] .mp-insp-swatch {
  background: var(--mp-paper-2);
  border-color: var(--mp-ink);
  color: var(--mp-ink);
}

[data-theme='dark'] .mp-insp-textarea:focus,
[data-theme='dark'] .mp-insp-input:focus {
  border-color: var(--mp-accent);
  box-shadow: 0 0 0 2px var(--mp-accent-soft);
}

/* ============================================================
   Fase 6 — Menu Template
   .mp-template-panel  : dropdown pannello sotto il bottone toolbar
   .mp-template-item   : voce singola del menu
   .mp-modal-backdrop  : sfondo modale semitrasparente
   .mp-modal           : contenitore modale centrato
   ============================================================ */

/* ── Bottone toolbar Template ── */
.mp-btn-template-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mp-font-label);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ── Pannello dropdown template ── */
.mp-template-panel {
  position: absolute;
  top: calc(var(--mp-toolbar-h) + 4px);
  /* Allineato al lato sinistro del bottone (js può aggiustare) */
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  width: 340px;
  max-width: calc(100vw - 24px);
  background: var(--mp-paper);
  border: var(--mp-border) solid var(--mp-ink);
  box-shadow: var(--mp-shadow);
  border-radius: var(--mp-radius);
  overflow: hidden;
}

.mp-template-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--mp-paper-2);
  background: var(--mp-paper-2);
}

.mp-template-panel-title {
  font-family: var(--mp-font-label);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mp-muted);
}

.mp-template-close {
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Lista template ── */
.mp-template-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  max-height: 420px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ── Voce singola ── */
.mp-template-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--mp-paper-2);
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
  min-height: 44px; /* touch target */
}

.mp-template-item:last-child {
  border-bottom: none;
}

.mp-template-item:hover,
.mp-template-item:focus-visible {
  background: var(--mp-accent-soft);
  outline: none;
}

.mp-template-item:focus-visible {
  outline: 2px solid var(--mp-accent);
  outline-offset: -2px;
}

.mp-template-icon {
  font-size: 20px;
  line-height: 1.2;
  flex-shrink: 0;
  margin-top: 1px;
}

.mp-template-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mp-template-label {
  font-family: var(--mp-font-ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--mp-ink);
  line-height: 1.3;
}

.mp-template-desc {
  font-family: var(--mp-font-ui);
  font-size: 11px;
  color: var(--mp-muted);
  line-height: 1.4;
}

/* ── Modale conferma sovrascrittura ── */
.mp-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(26, 23, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.mp-modal-backdrop[hidden] {
  display: none;
}

.mp-modal {
  background: var(--mp-paper);
  border: var(--mp-border) solid var(--mp-ink);
  box-shadow: var(--mp-shadow);
  border-radius: var(--mp-radius);
  padding: 28px 28px 24px;
  max-width: 400px;
  width: 100%;
}

.mp-modal-title {
  font-family: var(--mp-font-display);
  font-size: 20px;
  font-weight: 700;
  font-style: italic;
  color: var(--mp-ink);
  margin: 0 0 12px;
  line-height: 1.2;
}

.mp-modal-desc {
  font-family: var(--mp-font-ui);
  font-size: 14px;
  color: var(--mp-ink-soft);
  margin: 0 0 20px;
  line-height: 1.5;
}

.mp-modal-desc kbd {
  font-family: var(--mp-font-mono);
  font-size: 12px;
  background: var(--mp-paper-2);
  border: 1px solid var(--mp-ink);
  border-radius: 2px;
  padding: 1px 4px;
}

.mp-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Bottone primario generico (usato nella modale) */
.mp-btn-primary {
  background: var(--mp-accent);
  color: var(--mp-paper);
  border-color: var(--mp-accent);
  font-weight: 600;
}

.mp-btn-primary:hover {
  background: var(--mp-accent-deep);
  border-color: var(--mp-accent-deep);
}

/* ── Dark mode template panel + modale ── */
[data-theme='dark'] .mp-template-panel {
  background: var(--mp-paper);
  border-color: var(--mp-paper-2);
  box-shadow: 4px 4px 0 rgba(255, 255, 255, 0.08);
}

[data-theme='dark'] .mp-template-panel-header {
  background: var(--mp-paper-2);
  border-bottom-color: var(--mp-ink);
}

[data-theme='dark'] .mp-template-item {
  border-bottom-color: var(--mp-ink);
}

[data-theme='dark'] .mp-template-item:hover,
[data-theme='dark'] .mp-template-item:focus-visible {
  background: rgba(192, 68, 40, 0.18);
}

[data-theme='dark'] .mp-modal {
  background: var(--mp-paper);
  border-color: var(--mp-paper-2);
}

/* ── Mobile 375px ── */
@media (max-width: 480px) {
  .mp-template-panel {
    position: fixed;
    top: var(--mp-toolbar-h-mobile);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    transform: none;
    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  .mp-template-list {
    max-height: 55vh;
  }

  .mp-modal {
    padding: 20px 16px 16px;
  }

  .mp-modal-actions {
    flex-direction: column-reverse;
  }

  .mp-modal-actions .mp-btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }
}

/* ============================================================
   Fase 8 — Export / Import / Lista mappe
   ============================================================ */

/* ── Variante bottone pericolo ── */
.mp-btn-danger {
  background: var(--mp-paper);
  color: #b91c1c;
  border-color: #b91c1c;
}

.mp-btn-danger:hover {
  background: #b91c1c;
  color: var(--mp-paper);
  border-color: #b91c1c;
}

/* ── Variante bottone extra-piccolo (icone lista mappe) ── */
.mp-btn-xs {
  height: 26px;
  min-width: 26px;
  padding: 0 6px;
  font-size: 12px;
}

/* ── Dropdown panel — base condivisa ── */
.mp-dropdown-panel {
  position: absolute;
  top: calc(var(--mp-toolbar-h) + 2px);
  left: 12px;
  z-index: 300;
  min-width: 220px;
  max-width: 320px;
  background: var(--mp-paper);
  border: var(--mp-border) solid var(--mp-ink);
  border-radius: var(--mp-radius);
  box-shadow: var(--mp-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Stato chiuso: l'attributo [hidden] DEVE vincere su display:flex.
   Senza questo override la regola di classe (specificità 0,1,0) batte la
   regola user-agent [hidden]{display:none} (stessa specificità ma origine
   precedente) e i dropdown (menu mappe + esporta) restano sempre visibili,
   sovrapposti e non chiudibili dalla X. */
.mp-dropdown-panel[hidden] {
  display: none;
}

/* Pannello export posizionato a destra del pannello mappe */
.mp-export-panel {
  left: auto;
  right: 12px;
}

/* ── Header dropdown ── */
.mp-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--mp-paper-2);
  flex-shrink: 0;
}

.mp-dropdown-title {
  font-family: var(--mp-font-label);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mp-muted);
}

/* ── Etichette sezione ── */
.mp-dropdown-section-label {
  padding: 6px 12px 2px;
  font-family: var(--mp-font-label);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mp-muted);
}

/* ── Sezione items ── */
.mp-dropdown-section {
  padding: 4px 6px;
}

/* ── Divisore ── */
.mp-dropdown-divider {
  height: 1px;
  background: var(--mp-paper-2);
  margin: 4px 0;
}

/* ── Voce dropdown ── */
.mp-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  background: transparent;
  border: none;
  border-radius: 2px;
  font-family: var(--mp-font-ui);
  font-size: 13px;
  color: var(--mp-ink);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: background 0.08s;
}

.mp-dropdown-item:hover {
  background: var(--mp-paper-2);
}

.mp-dropdown-item:focus-visible {
  outline: 2px solid var(--mp-accent);
  outline-offset: -1px;
}

/* Hint descrittivo inline nella voce */
.mp-dropdown-hint {
  font-size: 11px;
  color: var(--mp-muted);
  margin-left: 2px;
}

/* ── Lista mappe salvate ── */
.mp-map-list {
  list-style: none;
  margin: 0;
  padding: 4px 6px;
  max-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
}

.mp-map-list-empty {
  padding: 10px 8px;
  font-size: 12px;
  color: var(--mp-muted);
  font-style: italic;
}

.mp-map-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border-radius: 2px;
  transition: background 0.08s;
}

.mp-map-list-item:hover {
  background: var(--mp-paper-2);
}

.mp-map-list-title {
  flex: 1;
  font-size: 13px;
  color: var(--mp-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.mp-map-list-date {
  font-size: 11px;
  color: var(--mp-muted);
  flex-shrink: 0;
}

.mp-map-list-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s;
}

.mp-map-list-item:hover .mp-map-list-actions,
.mp-map-list-item:focus-within .mp-map-list-actions {
  opacity: 1;
}

/* ── Modal: input testo (per rinomina) ── */
.mp-modal-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.mp-modal-label {
  font-family: var(--mp-font-label);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mp-muted);
}

.mp-modal-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--mp-paper);
  border: var(--mp-border) solid var(--mp-ink);
  border-radius: var(--mp-radius);
  font-family: var(--mp-font-ui);
  font-size: 14px;
  color: var(--mp-ink);
  box-sizing: border-box;
}

.mp-modal-input:focus {
  outline: 2px solid var(--mp-accent);
  outline-offset: 1px;
}

/* ── Dark mode per nuovi componenti ── */
[data-theme='dark'] .mp-btn-danger {
  color: #f87171;
  border-color: #f87171;
}

[data-theme='dark'] .mp-btn-danger:hover {
  background: #7f1d1d;
  color: var(--mp-paper);
  border-color: #7f1d1d;
}

[data-theme='dark'] .mp-modal-input {
  background: var(--mp-node-bg);
}

/* ── Mobile 375px — dropdown panel ── */
@media (max-width: 480px) {
  .mp-dropdown-panel,
  .mp-export-panel {
    position: fixed;
    top: var(--mp-toolbar-h-mobile);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    border-left: none;
    border-right: none;
    border-radius: 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    max-height: 60vh;
    overflow-y: auto;
  }

  .mp-map-list {
    max-height: 40vh;
  }

  .mp-map-list-actions {
    opacity: 1;
  }
}

/* ============================================================
   Fase 9 — Accessibilità WCAG 2.2 AA, i18n, animazioni, RTL
   ============================================================ */

/* ── Focus visibile su tutti gli elementi interattivi ── */
/* Copertura universale: bottoni, link, input, select, textarea */
.mp-root *:focus-visible {
  outline: 2px solid var(--mp-accent);
  outline-offset: 2px;
}

/* Rimuove outline di default solo quando focus-visible è supportato
   (progressive enhancement) */
.mp-root *:focus:not(:focus-visible) {
  outline: none;
}

/* Focus visibile su nodi SVG (non-standard, gestito via tabindex sul <g>) */
.mp-node:focus-visible {
  outline: 2px solid var(--mp-accent);
  outline-offset: 3px;
}

/* Focus su input interno dell'outline */
.mp-outline-search:focus-visible,
.mp-search-input:focus-visible {
  outline: 2px solid var(--mp-accent);
  outline-offset: 2px;
  border-color: var(--mp-accent);
}

/* Focus sul selettore lingua */
.mp-lang-select:focus-visible {
  outline: 2px solid var(--mp-accent);
  outline-offset: 2px;
}

/* ── Selettore lingua ── */
.mp-lang-select {
  height: 30px;
  padding: 0 6px;
  background: var(--mp-paper);
  color: var(--mp-ink);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  font-family: var(--mp-font-label);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  min-width: 44px;
  text-align: center;
}

.mp-lang-select:hover {
  background: var(--mp-paper-2);
}

@media (pointer: coarse) {
  .mp-lang-select {
    height: 40px;
    min-width: 48px;
  }
}

/* Screen-reader only (per label lingua) */
.mp-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Input nascosto (es. selettore file import) — niente style inline */
.mp-hidden-input {
  display: none;
}

/* ── Modale aiuto ── */
.mp-help-modal-backdrop {
  z-index: 600; /* sopra le modali template (500) */
}

.mp-help-modal {
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.mp-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1.5px solid var(--mp-ink);
  flex-shrink: 0;
}

.mp-help-title {
  margin: 0;
  font-size: 18px;
}

.mp-help-close {
  flex-shrink: 0;
}

.mp-help-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--mp-ink) transparent;
}

.mp-help-section {
  /* nessuno stile specifico — la struttura basta */
}

.mp-help-section-title {
  font-family: var(--mp-font-label);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mp-muted);
  margin: 0 0 8px;
}

.mp-help-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mp-help-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.mp-help-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  padding: 2px 6px;
  background: var(--mp-paper-2);
  border: 1px solid var(--mp-ink);
  border-radius: 3px;
  font-family: var(--mp-font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--mp-ink);
  white-space: nowrap;
  flex-shrink: 0;
  text-align: center;
}

.mp-help-desc {
  font-family: var(--mp-font-ui);
  font-size: 13px;
  color: var(--mp-ink-soft);
  line-height: 1.4;
}

@media (max-width: 480px) {
  .mp-help-modal {
    max-height: 90vh;
  }

  .mp-modal-header {
    padding: 16px 16px 12px;
  }

  .mp-help-body {
    padding: 12px 16px 20px;
  }

  .mp-help-row {
    flex-direction: column;
    gap: 2px;
  }

  .mp-help-kbd {
    min-width: 0;
  }
}

/* Dark mode modale aiuto */
[data-theme='dark'] .mp-help-kbd {
  background: var(--mp-paper-2);
  border-color: var(--mp-ink);
}

/* ── Animazione ingresso canvas (sobria, un solo elemento) ── */
@media (prefers-reduced-motion: no-preference) {
  .mp-canvas-wrap {
    animation: mp-canvas-in 0.25s ease both;
    animation-delay: 0.05s;
  }

  @keyframes mp-canvas-in {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }
}

/* ── prefers-reduced-motion: azzera TUTTE le animazioni ── */
@media (prefers-reduced-motion: reduce) {
  /* Annulla toolbar-in */
  .mp-toolbar {
    animation: none;
  }

  /* Annulla canvas-in */
  .mp-canvas-wrap {
    animation: none;
  }

  /* Annulla toast */
  .mp-toast {
    animation: none;
  }

  /* Annulla transizioni UI */
  .mp-btn,
  .mp-node-bg,
  .mp-insp-swatch,
  .mp-insp-shape-btn,
  .mp-insp-icon-btn,
  .mp-insp-prio-btn,
  .mp-insp-style-btn,
  .mp-insp-arrow-btn,
  .mp-template-item,
  .mp-free-hint {
    transition: none;
  }
}

/* ── RTL per lingua AR ── */
[dir='rtl'] .mp-toolbar {
  flex-direction: row-reverse;
}

[dir='rtl'] .mp-wordmark {
  margin-right: 0;
  margin-left: 12px;
  flex-direction: row-reverse;
}

[dir='rtl'] .mp-toolbar-group {
  flex-direction: row-reverse;
}

/* RTL: l'inspector va a sinistra. `.mp-root` è una griglia, quindi `order` su
   un grid-item non basta a riposizionarlo nelle aree: ridefiniamo direttamente
   il template della griglia invertendo l'ordine delle aree e delle colonne. */
[dir='rtl'] .mp-root {
  grid-template-columns: auto 1fr;
  grid-template-areas:
    'toolbar toolbar'
    'inspector canvas';
}

[dir='rtl'] .mp-inspector {
  /* Inspector a sinistra: il bordo separatore va sul lato destro (verso il
     canvas, che in RTL è alla sua destra). */
  border-left: none;
  border-right: var(--mp-border) solid var(--mp-ink);
}

[dir='rtl'] .mp-modal-actions {
  flex-direction: row-reverse;
}

[dir='rtl'] .mp-help-row {
  flex-direction: row-reverse;
}

[dir='rtl'] .mp-insp-actions-row {
  text-align: right;
}

/* ── Contrasto AA — assicura testo su sfondo ── */
/* Il colore muted (#7A7064 su #F8F6F1) raggiunge 4.53:1 (AA) */
/* Il colore ink (#1A1714 su #F8F6F1) raggiunge 16.4:1 (AAA) */
/* Il colore accent (#C04428 su #F8F6F1) raggiunge 4.51:1 (AA) */
/* Nessun override necessario per la palette corrente. */
/* Nota: .mp-muted su .mp-paper-2 (#ECE7DA) → 3.8:1, borderline.
   Usiamo --mp-ink-soft (#3A352E) per testi critici su paper-2. */
.mp-insp-section-title,
.mp-panel-label,
.mp-template-panel-title {
  /* Già --mp-muted, accettabile per testo decorativo/label (non corpo). */
  color: var(--mp-ink-soft);
}

/* ============================================================
   Fase 7 — Outline & Ricerca
   ============================================================ */

/* ── Pannello outline ── */
.mp-outline {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  background: var(--mp-paper);
  border-right: var(--mp-border) solid var(--mp-ink);
  display: flex;
  flex-direction: column;
  z-index: 30;
  overflow: hidden;
}

/* Stato chiuso: [hidden] deve vincere su display:flex (stesso problema di
   .mp-dropdown-panel). Senza questo l'outline resta sempre visibile a
   sinistra, copre il canvas e la X non lo chiude. */
.mp-outline[hidden] {
  display: none;
}

/* Header outline */
.mp-outline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  /* Il bordo morbido è gestito dalla regola successiva (rgba). NIENTE
     opacity: 0.15 qui — si applicava all'intero header rendendo titolo
     "Struttura" e pulsante di chiusura quasi invisibili. */
  border-bottom: 1px solid var(--mp-ink);
  flex-shrink: 0;
}

.mp-outline-header {
  border-bottom: 1px solid rgba(26, 23, 20, 0.15);
}

.mp-outline-title {
  font-family: var(--mp-font-label);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mp-ink-soft);
}

.mp-outline-close {
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--mp-muted);
}

.mp-outline-close:hover {
  color: var(--mp-ink);
  background: var(--mp-paper-2);
}

/* Contenitore campo ricerca */
.mp-search-container {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(26, 23, 20, 0.1);
  flex-shrink: 0;
}

/* Campo ricerca (box wrapper) */
.mp-search-box {
  display: flex;
  align-items: center;
  gap: 2px;
}

.mp-search-input {
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 8px;
  font-family: var(--mp-font-ui);
  font-size: 12px;
  background: var(--mp-node-bg);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  color: var(--mp-ink);
  outline: none;
}

.mp-search-input::placeholder {
  color: var(--mp-muted);
}

.mp-search-input:focus {
  border-color: var(--mp-accent);
  box-shadow: 0 0 0 2px var(--mp-accent-soft);
}

/* Rimuove decorazione browser su input[type=search] */
.mp-search-input::-webkit-search-cancel-button {
  display: none;
}

.mp-search-counter {
  font-family: var(--mp-font-label);
  font-size: 10px;
  color: var(--mp-muted);
  min-width: 32px;
  text-align: center;
  user-select: none;
}

.mp-search-nav {
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
}

.mp-search-dim-toggle {
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  color: var(--mp-muted);
}

.mp-search-dim-toggle--active {
  background: var(--mp-accent);
  color: var(--mp-paper);
  border-color: var(--mp-accent);
}

.mp-search-dim-toggle--active:hover {
  background: var(--mp-accent-deep);
}

/* Corpo outline: area scrollabile */
.mp-outline-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--mp-paper-2) transparent;
}

.mp-outline-body::-webkit-scrollbar {
  width: 4px;
}

.mp-outline-body::-webkit-scrollbar-thumb {
  background: var(--mp-paper-2);
  border-radius: 2px;
}

/* Messaggio vuoto */
.mp-outline-empty {
  padding: 12px 16px;
  font-size: 12px;
  color: var(--mp-muted);
  font-style: italic;
  margin: 0;
}

/* Albero outline: ul/li */
.mp-outline-body ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mp-outline-body li {
  margin: 0;
  padding: 0;
}

/* Indentazione visiva: depth via CSS custom property */
.mp-outline-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 30px;
  padding: 3px 10px 3px calc(10px + var(--mp-outline-depth, 0) * 14px);
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  user-select: none;
}

.mp-outline-row:hover {
  background: var(--mp-paper-2);
}

.mp-outline-row:focus {
  outline: 2px solid var(--mp-accent);
  outline-offset: -2px;
}

.mp-outline-row--root {
  font-weight: 600;
}

/* Chevron espansione */
.mp-outline-chevron {
  flex-shrink: 0;
  width: 12px;
  font-size: 10px;
  color: var(--mp-muted);
  line-height: 1;
  text-align: center;
}

/* Chevron cliccabile (nodo con figli): ripiega/espande il sottoalbero */
.mp-outline-chevron--toggle {
  cursor: pointer;
}

.mp-outline-chevron--toggle:hover {
  color: var(--mp-ink);
}

/* Label voce outline */
.mp-outline-label {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--mp-ink);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 2px;
  padding: 1px 2px;
}

/* Editing inline del label */
.mp-outline-label[contenteditable='true']:focus {
  outline: none;
  background: var(--mp-node-bg);
  border: 1px solid var(--mp-accent);
  border-radius: 2px;
  white-space: pre-wrap;
  overflow: visible;
  text-overflow: clip;
}

/* ── Nodi highlight/dim (Fase 7 — ricerca) ── */

/* Nodo che corrisponde alla ricerca */
.mp-node--match .mp-node-bg {
  stroke: var(--mp-accent) !important;
  stroke-width: 2.5 !important;
  filter: drop-shadow(0 0 3px var(--mp-accent-soft));
}

/* Nodo attenuato (non corrispondente quando dim è attivo) */
.mp-node--dim {
  opacity: 0.28;
}

/* ── Dark mode outline ── */
[data-theme='dark'] .mp-outline {
  border-right-color: var(--mp-ink);
}

[data-theme='dark'] .mp-search-input {
  background: var(--mp-node-bg);
  border-color: var(--mp-ink-soft);
  color: var(--mp-ink);
}

[data-theme='dark'] .mp-search-input:focus {
  border-color: var(--mp-accent);
}

/* ── Mobile 375px ── */
@media (max-width: 600px) {
  .mp-outline {
    width: 100%;
    max-width: 100%;
    border-right: none;
    border-bottom: var(--mp-border) solid var(--mp-ink);
    top: 0;
    bottom: auto;
    max-height: 50dvh;
  }

  .mp-outline-row {
    min-height: 44px; /* touch target */
  }
}

/* Nota: l'outline è un overlay absolute sopra il canvas (vedi .mp-outline) e
   .mp-root è una griglia. Non serve più spostare/restringere .mp-canvas-wrap
   quando l'outline è aperto: l'overlay si sovrappone senza alterare il layout.
   La vecchia regola `body[data-outline-open] .mp-canvas-wrap { margin-left }`
   è stata rimossa perché restringeva inutilmente il canvas. */

/* ============================================================
   FIX 6 — Icone toolbar con margine destro
   ============================================================ */

.mp-btn-icon-gap {
  margin-right: 4px;
}

/* ============================================================
   Fase 3 — collegamenti (CSS mancanti) FIX 2
   ============================================================ */

/* Overlay input frase legame: appare sopra il canvas */
.mp-link-overlay {
  position: absolute;
  /* Centrato nel canvas-wrap: senza top/left/transform restava incollato in
     alto a sinistra. */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 200;
  background: var(--mp-node-bg);
  border: 2px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  padding: 10px 12px;
  box-shadow: var(--mp-shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 220px;
  max-width: 320px;
}

/* Label piccola maiuscoletto nell'overlay */
.mp-link-overlay-label {
  font-family: var(--mp-font-label);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mp-muted);
}

/* Input testo etichetta legame */
.mp-link-overlay-input {
  width: 100%;
  box-sizing: border-box;
  height: 32px;
  padding: 0 8px;
  background: var(--mp-paper);
  color: var(--mp-ink);
  border: 1.5px solid var(--mp-ink);
  border-radius: var(--mp-radius);
  font-family: var(--mp-font-ui);
  font-size: 13px;
}

.mp-link-overlay-input:focus {
  outline: none;
  border-color: var(--mp-accent);
  box-shadow: 0 0 0 2px var(--mp-accent-soft);
}

/* Flex container per i bottoni confirm/cancel dell'overlay */
.mp-link-overlay-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* Cursore crosshair sul canvas in modalità collega */
.mp-canvas--link-mode {
  cursor: crosshair;
}

/* Nodo sorgente evidenziato durante link mode */
.mp-node--link-source .mp-node-bg {
  stroke: var(--mp-accent) !important;
  stroke-width: 3 !important;
  filter: drop-shadow(0 0 4px var(--mp-accent));
}

/* Gruppo link: deve ricevere click */
.mp-link {
  pointer-events: all;
  cursor: pointer;
}

/* Linea del collegamento */
.mp-link-path {
  stroke: var(--mp-ink);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
}

/* Variante doppia linea */
.mp-link-path-double {
  stroke: var(--mp-ink);
  fill: none;
  stroke-width: 1.5;
  stroke-dasharray: none;
}

/* Hit area trasparente per facilitare il click sul collegamento */
.mp-link-hit {
  stroke: transparent;
  stroke-width: 12;
  fill: none;
  cursor: pointer;
  pointer-events: stroke;
}

/* Collegamento selezionato */
.mp-link--selected .mp-link-path,
.mp-link--selected .mp-link-path-double {
  stroke: var(--mp-accent);
  stroke-width: 2.5;
}

/* Gruppo etichetta collegamento */
.mp-link-label-g {
  pointer-events: none;
}

/* Sfondo rect dietro l'etichetta */
.mp-link-label-bg {
  fill: var(--mp-node-bg);
  rx: 2;
}

/* Testo etichetta collegamento */
.mp-link-label {
  font-family: var(--mp-font-ui);
  font-size: 11px;
  fill: var(--mp-ink);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

/* Path freccia.
   context-stroke: la freccia eredita lo stroke del path che usa il marker, così
   segue il colore custom/selezione del link invece di restare fissa su --mp-ink.
   Fallback var(--mp-ink) per i (rari) motori che non supportano context-stroke. */
.mp-link-arrow-path {
  fill: var(--mp-ink);
  fill: context-stroke;
  stroke: none;
}

/* Classe helper i18n: nessuno stile speciale necessario */
.mp-i18n-text {
  vertical-align: baseline;
}

/* Dark mode — solo le proprietà che non usano già var() */
[data-theme='dark'] .mp-link-overlay {
  box-shadow: 4px 4px 0 rgba(240, 236, 228, 0.15);
}

[data-theme='dark'] .mp-link-overlay-input {
  background: var(--mp-paper-2);
}

[data-theme='dark'] .mp-link--selected .mp-link-path,
[data-theme='dark'] .mp-link--selected .mp-link-path-double {
  filter: drop-shadow(0 0 2px var(--mp-accent));
}
