/* Word — stile dell'interfaccia */

/* ---------- Colori e misure ---------- */
:root {
  color-scheme: light;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --chrome: #f5f6fa;
  --chrome-2: #eef0f5;
  --card: #ffffff;
  --desk: #e7eaf0;
  --desk-2: #dfe3ea;
  --ink: #141a26;
  --ink-2: #4b5468;
  --ink-3: #8790a3;
  --line: #e3e6ed;
  --line-2: #d4d9e3;
  --hover: rgba(20, 30, 60, .055);
  --press: rgba(20, 30, 60, .1);
  --accent: #2457d6;
  --accent-2: #1c46b3;
  --accent-ink: #ffffff;
  --accent-soft: #e6edfd;
  --accent-line: rgba(36, 87, 214, .35);
  --danger: #c4281c;
  --ok: #1f9d55;
  --warn: #d08a00;
  --pop: rgba(255, 255, 255, .92);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --shadow-lg: 0 2px 6px rgba(16, 24, 40, .06), 0 18px 48px -8px rgba(16, 24, 40, .22);
  --page-shadow: 0 0 0 1px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .08), 0 14px 40px -10px rgba(16, 24, 40, .22);
  --r: 8px;
  --r-lg: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --chrome: #15181e; --chrome-2: #1b1f27; --card: #1e222b; --desk: #0f1115; --desk-2: #0b0d10;
    --ink: #e9ecf3; --ink-2: #a9b1c2; --ink-3: #6f7889;
    --line: #2a2f3a; --line-2: #363c48;
    --hover: rgba(255, 255, 255, .06); --press: rgba(255, 255, 255, .1);
    --accent: #7ea4ff; --accent-2: #9db9ff; --accent-ink: #0d1530; --accent-soft: rgba(126, 164, 255, .15); --accent-line: rgba(126, 164, 255, .45);
    --danger: #ff8579; --ok: #4fd18b; --warn: #f0b44c;
    --pop: rgba(32, 36, 45, .94);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 16px rgba(0, 0, 0, .3);
    --shadow-lg: 0 2px 8px rgba(0, 0, 0, .4), 0 24px 56px -8px rgba(0, 0, 0, .6);
    --page-shadow: 0 0 0 1px rgba(255, 255, 255, .04), 0 18px 50px -12px rgba(0, 0, 0, .75);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --chrome: #15181e; --chrome-2: #1b1f27; --card: #1e222b; --desk: #0f1115; --desk-2: #0b0d10;
  --ink: #e9ecf3; --ink-2: #a9b1c2; --ink-3: #6f7889;
  --line: #2a2f3a; --line-2: #363c48;
  --hover: rgba(255, 255, 255, .06); --press: rgba(255, 255, 255, .1);
  --accent: #7ea4ff; --accent-2: #9db9ff; --accent-ink: #0d1530; --accent-soft: rgba(126, 164, 255, .15); --accent-line: rgba(126, 164, 255, .45);
  --danger: #ff8579; --ok: #4fd18b; --warn: #f0b44c;
  --pop: rgba(32, 36, 45, .94);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 16px rgba(0, 0, 0, .3);
  --shadow-lg: 0 2px 8px rgba(0, 0, 0, .4), 0 24px 56px -8px rgba(0, 0, 0, .6);
  --page-shadow: 0 0 0 1px rgba(255, 255, 255, .04), 0 18px 50px -12px rgba(0, 0, 0, .75);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  height: 100dvh;
  overflow: hidden;
  font: 13px/1.4 var(--ui);
  color: var(--ink);
  background: var(--chrome);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.topbar { grid-row: 1; }
.ribbon-tabs { grid-row: 2; }
.ribbon { grid-row: 3; }
.findbar { grid-row: 4; }
.workspace { grid-row: 5; }
.statusbar { grid-row: 6; }
button, input, select { font: inherit; color: inherit; }
button { cursor: default; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .f { fill: currentColor; stroke: none; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd {
  font: 500 11px/1 var(--ui); color: var(--ink-2);
  border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px;
  padding: 3px 5px; background: var(--card); min-width: 20px; display: inline-block; text-align: center;
}

/* ---------- Barra in alto ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px 8px;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 15px; letter-spacing: -.01em; flex: none; }
.brand img { display: block; width: 28px; height: 28px; filter: drop-shadow(0 1px 1px rgba(16, 24, 40, .12)); }
.quick { display: flex; gap: 2px; padding-left: 10px; border-left: 1px solid var(--line); flex: none; }
.qb {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border: 0; border-radius: 7px; background: transparent; color: var(--ink-2);
  transition: background-color .12s, color .12s;
}
.qb svg { width: 18px; height: 18px; }
.qb:hover { background: var(--hover); color: var(--ink); }
.qb:active { background: var(--press); }
.qb.on { background: var(--accent-soft); color: var(--accent); }

.doc-meta { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.title {
  min-width: 80px; width: 100%; max-width: 360px;
  border: 1px solid transparent; border-radius: 7px;
  padding: 5px 8px; background: transparent;
  font-size: 14px; font-weight: 600; letter-spacing: -.01em;
  text-overflow: ellipsis;
  transition: border-color .12s, background-color .12s;
}
.title:hover { border-color: var(--line-2); }
.title:focus { outline: none; border-color: var(--accent); background: var(--card); box-shadow: 0 0 0 3px var(--accent-soft); }
.save-state {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 12px; color: var(--ink-3); white-space: nowrap;
}
.save-state .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); transition: background-color .2s, box-shadow .2s; }
.save-state[data-state="pending"] .dot { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent); }
.save-state[data-state="error"] .dot { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }
.save-state[data-state="error"] { color: var(--danger); }

/* Ricerca comandi */
.cmd-search {
  position: relative; display: flex; align-items: center; gap: 8px;
  width: 260px; flex: 0 1 260px; min-width: 150px;
  height: 32px; padding: 0 8px 0 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 9px;
  box-shadow: var(--shadow-sm);
  color: var(--ink-3);
  transition: border-color .12s, box-shadow .12s, width .2s;
}
.cmd-search svg { width: 16px; height: 16px; }
.cmd-search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 0; color: var(--ink); font-size: 13px; }
.cmd-search input::placeholder { color: var(--ink-3); }
.cmd-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cmd-search:focus-within kbd { display: none; }
.cmd-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
  min-width: 300px;
  background: var(--pop); backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  padding: 6px; max-height: 360px; overflow: auto;
}
.cmd-results button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 7px; color: var(--ink);
}
.cmd-results button svg { width: 18px; height: 18px; color: var(--ink-2); }
.cmd-results button .cr-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-results button .cr-where { font-size: 11px; color: var(--ink-3); }
.cmd-results button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.cmd-results button[aria-selected="true"] svg, .cmd-results button[aria-selected="true"] .cr-where { color: inherit; opacity: .85; }
.cmd-results .cr-empty { padding: 10px; color: var(--ink-3); font-size: 12.5px; }

/* Pulsanti */
.file-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: var(--card); color: var(--ink);
  font-weight: 550; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background-color .12s, border-color .12s, color .12s, box-shadow .12s, transform .06s;
}
.btn svg { width: 17px; height: 17px; }
.btn svg.chev { width: 13px; height: 13px; margin-left: -3px; opacity: .6; }
.btn:hover { background: var(--chrome-2); }
.btn:active { transform: translateY(.5px); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn.ghost:hover { background: var(--hover); color: var(--ink); }
.btn.ghost[aria-expanded="true"] { background: var(--press); color: var(--ink); }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 100%);
  border-color: var(--accent-2); color: var(--accent-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 1px 2px rgba(20, 50, 140, .25), 0 4px 10px -4px rgba(36, 87, 214, .45);
}
.btn.primary:hover { background: var(--accent-2); }
.btn.primary:disabled { opacity: .7; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.icon { padding: 0; width: 28px; }
.btn.icon svg { width: 16px; height: 16px; }
.btn.danger { color: var(--danger); }
.btn.danger-text { color: var(--danger); }

/* ---------- Schede ---------- */
.ribbon-tabs {
  display: flex; align-items: flex-end; gap: 2px;
  padding: 0 14px;
  overflow-x: auto; scrollbar-width: none;
}
.ribbon-tabs::-webkit-scrollbar { display: none; }
.rtab {
  position: relative; border: 0; background: none;
  padding: 7px 12px 9px; border-radius: 7px 7px 0 0;
  color: var(--ink-2); font-weight: 520; white-space: nowrap;
  transition: color .12s, background-color .12s;
}
.rtab:hover { color: var(--ink); background: var(--hover); }
.rtab::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 3px;
  border-radius: 3px 3px 0 0; background: var(--accent);
  transform: scaleX(0); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
}
.rtab[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.rtab[aria-selected="true"]::after { transform: scaleX(1); }
body.ribbon-collapsed .rtab[aria-selected="true"]::after { transform: scaleX(0); }
.rtab.ctx { color: var(--ok); }
.rtab.ctx[aria-selected="true"] { color: var(--ok); }
.rtab.ctx::after { background: var(--ok); }
.ribbon-tabs .qb { margin-bottom: 4px; }
.ribbon-tabs .qb svg { transition: transform .2s; }
body.ribbon-collapsed #btnCollapse svg { transform: rotate(180deg); }

/* ---------- Barra multifunzione ---------- */
.ribbon {
  margin: 0 10px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin;
}
body.ribbon-collapsed .ribbon { display: none; }
.panel { display: flex; align-items: stretch; min-height: 104px; padding: 6px 4px 0; width: max-content; min-width: 100%; }
.panel[hidden] { display: none; }
@keyframes panel-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.panel { animation: panel-in .18s ease-out; }
.rgroup {
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 0 8px; position: relative;
}
.rgroup + .rgroup::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 10px; width: 1px; background: var(--line);
}
.rbody { display: flex; align-items: center; gap: 2px; flex: 1; }
.rlabel { text-align: center; font-size: 11px; color: var(--ink-3); padding: 3px 0 6px; white-space: nowrap; letter-spacing: .01em; }
.rows { flex-direction: column; justify-content: center; align-items: flex-start; gap: 5px; }
.row { display: flex; align-items: center; gap: 2px; }
.col { display: flex; flex-direction: column; gap: 1px; }
.vsep { width: 1px; height: 20px; background: var(--line); margin: 0 5px; flex: none; }

.tb {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  min-width: 30px; height: 30px; padding: 0 5px;
  border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--ink);
  transition: background-color .1s, color .1s, border-color .1s;
}
.tb svg { width: 19px; height: 19px; }
.tb svg.chev { width: 12px; height: 12px; opacity: .55; }
.tb:hover { background: var(--hover); }
.tb:active { background: var(--press); }
.tb.on, .tb[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.tb.wide { padding: 0 4px 0 6px; }
.lbl-btn { gap: 7px; padding: 0 10px 0 7px; font-size: 12.5px; }
.glyph { font: 600 15px/1 Georgia, "Times New Roman", serif; }
.glyph sup, .glyph sub { font: 600 9px var(--ui); }
.glyph.small-a { font-size: 12px; }
.glyph.b { font-weight: 800; font-family: var(--ui); font-size: 14px; }
.glyph.i { font-style: italic; font-weight: 500; font-size: 16px; }
.glyph.u { text-decoration: underline; text-underline-offset: 3px; font-family: var(--ui); font-size: 14px; }
.glyph.s { text-decoration: line-through; font-family: var(--ui); font-size: 13px; }
.glyph.pil { font-size: 16px; }
.tb.color { position: relative; flex-direction: column; gap: 0; padding: 2px 5px 3px; }
.tb.color svg { width: 17px; height: 17px; }
.swatch { display: block; width: 18px; height: 4px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.tb.color input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }

.big {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 5px;
  min-width: 62px; max-width: 92px; height: 72px; padding: 8px 6px 4px;
  border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--ink);
  font-size: 11.5px; line-height: 1.2; text-align: center;
  transition: background-color .1s, color .1s, border-color .1s;
}
.big > svg { width: 26px; height: 26px; stroke-width: 1.4; color: var(--accent); }
.big span { display: inline-flex; align-items: center; justify-content: center; flex-wrap: wrap; hyphens: manual; }
.big svg.chev.in { width: 11px; height: 11px; margin-left: 2px; opacity: .55; }
.big .big-glyph { font: 500 24px/26px Georgia, serif; height: 26px; color: var(--accent); }
.big:hover { background: var(--hover); }
.big:active { background: var(--press); }
.big.on, .big[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent-line); }

.sel {
  height: 30px; border: 1px solid var(--line-2); border-radius: 7px;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238790a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 6px center / 13px;
  padding: 0 24px 0 9px; appearance: none; -webkit-appearance: none;
  font-size: 13px;
  transition: border-color .12s, box-shadow .12s;
}
.sel:hover { border-color: var(--ink-3); }
.sel:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sel-font { width: 158px; }
.sel-size { width: 62px; margin-right: 4px; }

/* Galleria stili */
.styles {
  display: flex; gap: 4px; padding: 2px;
  max-width: 420px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: thin;
}
.style-tile {
  flex: none; width: 76px; height: 66px; scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--card); color: #141a26;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.style-tile .sample {
  display: grid; place-items: center; width: 64px; height: 32px; border-radius: 5px;
  background: #fff; color: #141a26; overflow: hidden; white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(16, 24, 40, .06);
}
.style-tile .name { font-size: 10.5px; color: var(--ink-2); }
.style-tile:hover { border-color: var(--line-2); box-shadow: var(--shadow); transform: translateY(-1px); }
.style-tile.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.style-tile.on .name { color: var(--accent); font-weight: 600; }
.s-p { font: 12px Georgia, serif; }
.s-h1 { font: 700 17px Georgia, serif; color: #17306b !important; }
.s-h2 { font: 700 14px Georgia, serif; color: #1f3f86 !important; }
.s-h3 { font: 700 12.5px Georgia, serif; color: #2a4a92 !important; }
.s-q { font: italic 12px Georgia, serif; color: #4b5468 !important; }
.s-em { font: italic 12px Georgia, serif; }

/* ---------- Menu a comparsa ---------- */
.popover {
  position: fixed; z-index: 40;
  background: var(--pop); backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: 6px;
  animation: pop-in .14s cubic-bezier(.2, .8, .2, 1);
  transform-origin: top left;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.menu { display: flex; flex-direction: column; min-width: 190px; }
.menu button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  border: 0; background: none; text-align: left; padding: 7px 10px 7px 28px; border-radius: 7px; position: relative; color: var(--ink);
}
.menu button small { color: var(--ink-3); font-size: 11.5px; }
.menu button:hover { background: var(--accent); color: var(--accent-ink); }
.menu button:hover small { color: inherit; opacity: .8; }
.menu button.on::before {
  content: ""; position: absolute; left: 10px; top: 50%; width: 9px; height: 5px; margin-top: -4px;
  border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg);
}
.menu.icons button { display: grid; grid-template-columns: 22px 1fr; column-gap: 10px; padding: 8px 12px 8px 10px; min-width: 270px; }
.menu.icons button svg { grid-row: span 2; align-self: center; width: 22px; height: 22px; color: var(--accent); }
.menu.icons button:hover svg { color: inherit; }
.grid { display: grid; grid-template-columns: repeat(8, 20px); gap: 3px; padding: 4px; }
.grid span { width: 20px; height: 20px; border: 1px solid var(--line-2); border-radius: 4px; background: var(--card); transition: background-color .06s, border-color .06s; }
.grid span.hot { background: var(--accent-soft); border-color: var(--accent); }
.grid-label { text-align: center; font-size: 12px; color: var(--ink-2); padding: 4px 0 2px; font-variant-numeric: tabular-nums; }
.symbols { display: grid; grid-template-columns: repeat(8, 34px); gap: 2px; }
.symbols button {
  width: 34px; height: 34px; border: 0; border-radius: 7px; background: none; font-size: 17px; color: var(--ink);
}
.symbols button:hover { background: var(--accent); color: var(--accent-ink); }

/* ---------- Trova e sostituisci ---------- */
.findbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin: 8px 10px 0; padding: 7px 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
  animation: panel-in .16s ease-out;
}
.findbar .field {
  display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 9px;
  border: 1px solid var(--line-2); border-radius: 8px; background: var(--chrome); color: var(--ink-3);
}
.findbar .field svg { width: 15px; height: 15px; }
.findbar .field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--card); }
.findbar input { border: 0; background: none; outline: none; width: 190px; color: var(--ink); padding: 0; }
.find-count { font-size: 12px; color: var(--ink-3); min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.findbar .btn.small svg { width: 15px; height: 15px; }
#findPrev, #findNext { padding: 0; width: 28px; }

/* ---------- Area di lavoro ---------- */
.workspace { display: flex; min-height: 0; margin-top: 8px; }
.navpane {
  flex: none; width: 250px; display: flex; flex-direction: column; min-height: 0;
  margin: 0 0 8px 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
  animation: nav-in .2s ease-out;
}
@keyframes nav-in { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
.navpane-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 6px 14px; font-weight: 650; }
.navlist { list-style: none; margin: 0; padding: 4px 6px 10px; overflow: auto; flex: 1; }
.navlist button {
  display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--ink-2);
  padding: 6px 8px; border-radius: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 2px solid transparent;
}
.navlist button:hover { background: var(--hover); color: var(--ink); }
.navlist button.current { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.navlist .lv1 button { font-weight: 600; color: var(--ink); }
.navlist .lv1 button.current { color: var(--accent); }
.navlist .lv2 button { padding-left: 20px; }
.navlist .lv3 button { padding-left: 32px; font-size: 12.5px; }
.navlist:empty { display: none; }
.navempty { margin: 4px 14px 14px; color: var(--ink-3); font-size: 12.5px; line-height: 1.5; }

.desk {
  flex: 1; min-width: 0; overflow: auto; padding: 24px 16px 72px;
  margin: 0 10px 0 10px; border-radius: var(--r-lg) var(--r-lg) 0 0;
  background:
    radial-gradient(1200px 600px at 50% -200px, color-mix(in srgb, var(--accent) 7%, transparent), transparent 70%),
    linear-gradient(180deg, var(--desk), var(--desk-2));
  scroll-behavior: smooth;
}
.page {
  --zoom: 1;
  --pw: 21cm; --ph: 29.7cm; --mt: 2.5cm; --ml: 2cm;
  position: relative;
  width: var(--pw);
  min-height: var(--ph);
  margin: 0 auto;
  background: #ffffff;
  border-radius: 2px;
  box-shadow: var(--page-shadow);
  padding: var(--mt) var(--ml);
  zoom: var(--zoom);
}
.page-probe { position: absolute; left: 0; top: 0; width: 1px; height: calc(var(--ph) - 2 * var(--mt)); visibility: hidden; pointer-events: none; }
.editor {
  min-height: calc(var(--ph) - 2 * var(--mt));
  outline: none;
  font-family: Georgia, serif;
  font-size: 12pt;
  line-height: 1.5;
  color: #141a26;
  overflow-wrap: break-word;
  caret-color: #2457d6;
  color-scheme: light;
}
.editor ::selection { background: rgba(36, 87, 214, .22); }
.editor:empty::before { content: "Inizia a scrivere…"; color: #9aa2b2; }
.editor p { margin: 0 0 .6em; }
.editor h1 { font-size: 22pt; font-weight: 700; margin: .4em 0 .4em; line-height: 1.2; color: #17306b; }
.editor h2 { font-size: 16pt; font-weight: 700; margin: .9em 0 .35em; line-height: 1.25; color: #1f3f86; }
.editor h3 { font-size: 13pt; font-weight: 700; margin: .8em 0 .3em; color: #2a4a92; }
.editor blockquote { margin: .6em 0; padding: .1em 0 .1em 1em; border-left: 3px solid #2457d6; color: #4b5468; font-style: italic; }
.editor blockquote[style] { font-style: normal; color: inherit; }
.editor ul, .editor ol { margin: 0 0 .6em; padding-left: 1.6em; }
.editor a { color: #2457d6; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.editor img { max-width: 100%; height: auto; cursor: pointer; }
.editor img.picked { outline: 2px solid #2457d6; outline-offset: 3px; border-radius: 1px; }
.editor table { border-collapse: collapse; width: 100%; margin: .4em 0 .8em; }
.editor td, .editor th { border: 1px solid #b6bfd0; padding: 4px 8px; vertical-align: top; min-width: 2em; }
.editor th { background: #eef2fb; font-weight: 700; text-align: left; }
.editor hr { border: 0; border-top: 1px solid #cfd5e1; margin: 1em 0; }
.editor hr.page-break { border-top: 1px dashed #aab3c5; margin: 1.6em calc(-1 * var(--ml)); position: relative; overflow: visible; }
.editor hr.page-break::after {
  content: "Interruzione di pagina"; position: absolute; left: 50%; top: -.8em; transform: translateX(-50%);
  background: #fff; color: #8790a3; font: 500 10.5px var(--ui); letter-spacing: .04em; padding: 0 10px;
}
.editor .toc { margin: .4em 0 1em; padding: .6em 0; border-top: 1px solid #cfd5e1; border-bottom: 1px solid #cfd5e1; }
/* Segni di paragrafo */
.editor.marks :is(p, h1, h2, h3, li, td, th)::after { content: "¶"; color: #8fb0e6; font: 400 .9em Georgia, serif; font-style: normal; margin-left: 2px; }
::highlight(word-find) { background-color: rgba(255, 200, 0, .38); }
::highlight(word-find-cur) { background-color: #ff9f1a; color: #141a26; }

/* ---------- Barra immagine ---------- */
.imgbar {
  position: fixed; z-index: 20; display: flex; align-items: center; gap: 3px;
  background: var(--pop); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 4px; box-shadow: var(--shadow-lg);
  animation: pop-in .14s ease-out;
}
.imgbar .btn { box-shadow: none; border-color: transparent; background: transparent; }
.imgbar .btn:hover { background: var(--hover); }
.imgbar .vsep { margin: 0 2px; }

/* ---------- Barra di stato ---------- */
.statusbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px; height: 30px; font-size: 12px; color: var(--ink-2);
  background: var(--chrome); border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.statusbar #stats { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.hint { color: var(--accent); font-weight: 550; white-space: nowrap; }
.lang { color: var(--ink-3); }
.zoom { display: flex; align-items: center; gap: 4px; }
.zoom .qb { width: 22px; height: 22px; }
.zoom .qb svg { width: 14px; height: 14px; }
.zoom input { width: 110px; accent-color: var(--accent); }
.zoom-out { border: 0; background: none; min-width: 44px; text-align: right; color: var(--ink-2); padding: 2px 4px; border-radius: 5px; }
.zoom-out:hover { background: var(--hover); color: var(--ink); }

/* ---------- Avvisi ---------- */
.toast {
  position: fixed; left: 50%; bottom: 52px; transform: translate(-50%, 16px) scale(.98);
  max-width: min(560px, calc(100vw - 32px));
  background: rgba(20, 24, 33, .94); color: #fff; padding: 10px 16px; border-radius: 10px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px -6px rgba(0, 0, 0, .4);
  font-size: 13px; opacity: 0; pointer-events: none; z-index: 60; text-align: center;
  transition: opacity .2s ease-out, transform .25s cubic-bezier(.2, .8, .2, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

body.painting .editor { cursor: copy; }

/* ---------- Finestre di dialogo ---------- */
.dlg {
  border: 1px solid var(--line); border-radius: 16px; padding: 0;
  background: var(--card); color: var(--ink);
  box-shadow: var(--shadow-lg);
  width: min(420px, calc(100vw - 32px));
}
.dlg.wide { width: min(720px, calc(100vw - 32px)); }
.dlg[open] { animation: dlg-in .2s cubic-bezier(.2, .8, .2, 1); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.dlg::backdrop { background: rgba(12, 16, 26, .32); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.dlg form { padding: 22px 22px 18px; }
.dlg h2 { margin: 0 0 16px; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.dlg-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.stats-grid { display: grid; grid-template-columns: 1fr auto; margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stats-grid dt, .stats-grid dd { margin: 0; padding: 9px 14px; border-top: 1px solid var(--line); }
.stats-grid dt:first-of-type, .stats-grid dd:first-of-type { border-top: 0; }
.stats-grid dt { color: var(--ink-2); }
.stats-grid dd { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.keys { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px 28px; }
.keys h3 { margin: 0 0 8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; }
.keys dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 0; align-items: center; }
.keys dt { display: flex; gap: 3px; align-items: center; white-space: nowrap; }
.keys dd { margin: 0; color: var(--ink-2); }
.fld { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 12.5px; color: var(--ink-2); font-weight: 550; }
.fld input {
  height: 36px; padding: 0 11px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--chrome);
  font-size: 14px; font-weight: 400; color: var(--ink);
}
.fld input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--card); }

/* ---------- Concentrazione ---------- */
.focus-exit {
  position: fixed; top: 14px; right: 16px; z-index: 30;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px 6px 9px;
  background: var(--pop); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  color: var(--ink-2); font-size: 12px; box-shadow: var(--shadow);
  opacity: .35; transition: opacity .2s;
}
.focus-exit svg { width: 14px; height: 14px; }
.focus-exit:hover { opacity: 1; color: var(--ink); }
body.focus .topbar, body.focus .ribbon-tabs, body.focus .ribbon, body.focus .statusbar, body.focus .navpane { display: none !important; }
body.focus .workspace { margin-top: 0; }
body.focus .desk { margin: 0; border-radius: 0; padding-top: 48px; }

/* ---------- Schermi piccoli ---------- */
@media (max-width: 1100px) {
  .file-actions .btn.ghost span, .file-actions .btn.ghost .chev { display: none; }
  .file-actions .btn.ghost { padding: 0 8px; }
  .cmd-search { flex-basis: 200px; width: 200px; }
  .cmd-search kbd { display: none; }
}
@media (max-width: 820px) {
  .save-state #saveText { display: none; }
  .cmd-search { display: none; }
  .navpane { position: absolute; z-index: 25; top: 0; bottom: 0; height: auto; }
  .workspace { position: relative; }
  .lang { display: none; }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand span { display: none; }
  .doc-meta { flex: 1 1 0; }
  .file-actions { margin-left: auto; }
  .btn.primary span { display: none; }
  .btn.primary { padding: 0 10px; }
  .zoom input { display: none; }
  .desk { padding: 12px 0 40px; margin: 0; border-radius: 0; }
  .ribbon { margin: 0 8px; }
  .page { width: calc(100% - 16px); min-height: 70vh; padding: 28px 20px; }
  .editor { min-height: 60vh; }
  .editor hr.page-break { margin-left: -20px; margin-right: -20px; }
  .findbar input { width: 130px; }
  .keys { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .desk { scroll-behavior: auto; }
}

/* ---------- Stampa / PDF ---------- */
@media print {
  body { display: block; height: auto; overflow: visible; background: #fff; }
  .topbar, .ribbon-tabs, .ribbon, .findbar, .statusbar, .imgbar, .toast, .popover, .navpane, .focus-exit, dialog { display: none !important; }
  .workspace { display: block; margin: 0; }
  .desk { padding: 0; margin: 0; overflow: visible; background: none; }
  .page { width: auto; min-height: 0; padding: 0; box-shadow: none; zoom: 1 !important; }
  .editor { min-height: 0; }
  .editor img.picked { outline: none; }
  .editor.marks :is(p, h1, h2, h3, li, td, th)::after { content: none; }
  .editor hr.page-break { border: 0; margin: 0; break-after: page; }
  .editor hr.page-break::after { content: none; }
}
