/* Parcella · interfaccia (shell).
   Approssimazione web del linguaggio iOS corrente: il vetro (backdrop-filter) è riservato alla chrome
   flottante (barra in alto, tab bar, menu, toast); i contenuti stanno su superfici raggruppate opache.
   Non è il materiale Liquid Glass di Apple, che esiste solo sulle piattaforme Apple. */

:root {
  color-scheme: light dark;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-doc: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;

  --bg: #f2f2f7;
  --card: #ffffff;
  --card-hover: #f7f7fa;
  --label: #0f0f12;
  --label-2: rgba(60, 60, 67, .64);
  --label-3: rgba(60, 60, 67, .40);
  --sep: rgba(60, 60, 67, .14);
  --fill: rgba(120, 120, 128, .14);
  --fill-2: rgba(120, 120, 128, .08);
  --fill-3: rgba(120, 120, 128, .22);
  --tint: #007aff;
  --tint-strong: #0066d6;
  --tint-soft: rgba(0, 122, 255, .12);
  --on-tint: #ffffff;
  --red: #e0352b;
  --orange: #b86a00;
  --orange-soft: rgba(255, 149, 0, .13);
  --green: #1f8a3b;
  --green-soft: rgba(52, 199, 89, .16);
  --paper-shadow: 0 30px 60px -24px rgba(20, 30, 55, .38), 0 2px 6px rgba(20, 30, 55, .08), 0 0 0 1px rgba(20, 30, 55, .05);

  --glass-bg: rgba(255, 255, 255, .62);
  --glass-border: rgba(255, 255, 255, .80);
  --glass-hi: rgba(255, 255, 255, .95);
  --glass-shadow: 0 12px 32px -12px rgba(25, 35, 60, .28), 0 1px 2px rgba(0, 0, 0, .06);
  --glass-thumb: rgba(255, 255, 255, .78);
  --glass-thumb-hi: rgba(255, 255, 255, 1);
  --thumb: #ffffff;
  --thumb-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 1px 1px rgba(0, 0, 0, .06);

  --r-xl: 26px;
  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 9px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-ios: cubic-bezier(.32, .72, 0, 1);
  --topbar-h: 56px;
  --top-offset: calc(12px + var(--topbar-h) + 24px);
  --fs: 15px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-hover: #232326;
    --label: #f5f5f7;
    --label-2: rgba(235, 235, 245, .62);
    --label-3: rgba(235, 235, 245, .36);
    --sep: rgba(84, 84, 88, .55);
    --fill: rgba(120, 120, 128, .26);
    --fill-2: rgba(120, 120, 128, .14);
    --fill-3: rgba(120, 120, 128, .36);
    --tint: #0a84ff;
    --tint-strong: #3395ff;
    --tint-soft: rgba(10, 132, 255, .22);
    --red: #ff453a;
    --orange: #ffb340;
    --orange-soft: rgba(255, 159, 10, .18);
    --green: #30d158;
    --green-soft: rgba(48, 209, 88, .2);
    --paper-shadow: 0 40px 80px -30px rgba(0, 0, 0, .9), 0 2px 8px rgba(0, 0, 0, .5);
    --glass-bg: rgba(28, 28, 32, .62);
    --glass-border: rgba(255, 255, 255, .12);
    --glass-hi: rgba(255, 255, 255, .18);
    --glass-shadow: 0 16px 40px -12px rgba(0, 0, 0, .7), 0 1px 2px rgba(0, 0, 0, .4);
    --glass-thumb: rgba(255, 255, 255, .14);
    --glass-thumb-hi: rgba(255, 255, 255, .22);
    --thumb: #636366;
    --thumb-shadow: 0 3px 8px rgba(0, 0, 0, .45);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: rgba(120, 120, 128, .4) transparent; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs);
  line-height: 1.4;
  letter-spacing: -0.006em;
  color: var(--label);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  font-optical-sizing: auto;
  accent-color: var(--tint);
  caret-color: var(--tint);
}
::selection { background: var(--tint-soft); }
:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; border-radius: 6px; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; margin: 0; -webkit-tap-highlight-color: transparent; }
input, textarea, select { background: transparent; border: 0; padding: 0; margin: 0; min-width: 0; }
input:focus, textarea:focus, select:focus { outline: none; }
[hidden] { display: none !important; }
svg.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- sfondo e vetro ---------- */
.wash {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(55% 45% at 10% 6%, rgba(110, 150, 220, .24), transparent 70%),
    radial-gradient(45% 40% at 94% 10%, rgba(240, 200, 170, .24), transparent 70%),
    radial-gradient(60% 55% at 55% 108%, rgba(140, 180, 230, .18), transparent 70%),
    var(--bg);
}
@media (prefers-color-scheme: dark) {
  .wash {
    background:
      radial-gradient(55% 45% at 10% 6%, rgba(60, 95, 175, .36), transparent 70%),
      radial-gradient(45% 40% at 94% 10%, rgba(130, 75, 60, .30), transparent 70%),
      radial-gradient(60% 55% at 55% 108%, rgba(40, 70, 130, .32), transparent 70%),
      var(--bg);
  }
}
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--glass-hi), var(--glass-shadow);
}
@media (prefers-reduced-transparency: reduce) {
  .glass { background: var(--card); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

/* ---------- barra in alto ---------- */
.topbar {
  position: fixed; top: 12px; left: 16px; right: 16px; z-index: 50;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.cluster { display: flex; align-items: center; gap: 4px; height: var(--topbar-h); padding: 6px; border-radius: 999px; }
.cluster-nav { padding-left: 20px; gap: 14px; }
.wordmark { font-family: var(--font-doc); font-size: 21px; font-weight: 500; letter-spacing: -0.012em; color: var(--label); padding-right: 2px; line-height: 1; }

/* ---------- controllo segmentato ---------- */
.seg {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  align-items: stretch; padding: 3px; border-radius: 11px; background: var(--fill); isolation: isolate;
  max-width: 100%;
}
.seg > button {
  position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 4px 12px; border-radius: 8px; min-height: 28px;
  font-size: 13px; font-weight: 500; line-height: 1.3; color: var(--label-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
  transition: color 180ms ease, opacity 120ms ease;
}
.seg > button:active { opacity: .7; }
.seg > button[aria-checked="true"], .seg > button[aria-selected="true"] { color: var(--label); font-weight: 600; }
.seg-thumb {
  position: absolute; z-index: 0; top: 0; left: 0; width: 0; height: 0; border-radius: 8px;
  background: var(--thumb); box-shadow: var(--thumb-shadow);
  transition: transform 280ms var(--ease-ios), width 280ms var(--ease-ios), height 280ms var(--ease-ios);
  will-change: transform;
}
.seg.no-anim .seg-thumb { transition: none; }
.seg-glass { background: transparent; padding: 0; gap: 2px; height: 44px; border-radius: 999px; }
.seg-glass > button { padding: 0 18px; font-size: 14px; border-radius: 999px; }
.seg-glass .seg-thumb { border-radius: 999px; background: var(--glass-thumb); box-shadow: inset 0 1px 0 var(--glass-thumb-hi), 0 2px 8px rgba(20, 30, 60, .12); }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); flex: none; }
.swatch-navy { background: #1f3a5f; }
.swatch-bordeaux { background: #6b1f2a; }
.swatch-grafite { background: #2b2d31; }

/* ---------- pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; letter-spacing: -0.006em; color: var(--label); white-space: nowrap;
  transition: transform 140ms var(--ease-out), background-color 160ms ease, color 160ms ease, opacity 160ms ease;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-glass { background: transparent; }
.btn-icon { width: 40px; padding: 0; }
.btn-primary { background: var(--tint); color: var(--on-tint); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22); }
.btn-tint { background: var(--tint-soft); color: var(--tint); height: 34px; font-size: 13px; padding: 0 14px; }
.btn-quiet { background: var(--fill); height: 34px; font-size: 13px; padding: 0 14px; }
@media (hover: hover) and (pointer: fine) {
  .btn-glass:hover { background: var(--fill); }
  .btn-primary:hover { background: var(--tint-strong); }
  .btn-quiet:hover { background: var(--fill-3); }
  .btn-tint:hover { background: color-mix(in srgb, var(--tint) 20%, transparent); }
}
.destructive, .destructive-text { color: var(--red) !important; }
.tinted { color: var(--tint); }
.tinted-text { color: var(--tint); font-weight: 500; }

/* ---------- menu (popover) ---------- */
.menu {
  position: fixed; inset: auto; margin: 0; padding: 6px; min-width: 264px; max-width: calc(100vw - 24px);
  border-radius: 18px; color: var(--label); transform-origin: top right;
  opacity: 1; transform: none;
  transition: opacity 180ms var(--ease-out), transform 200ms var(--ease-out), overlay 200ms allow-discrete, display 200ms allow-discrete;
}
.menu:not(:popover-open) { opacity: 0; transform: scale(.96) translateY(-4px); }
@starting-style { .menu:popover-open { opacity: 0; transform: scale(.96) translateY(-4px); } }
.menu::backdrop { background: transparent; }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 12px;
  font-size: 14px; font-weight: 500; text-align: left; color: var(--label);
}
.menu button .ico { width: 18px; height: 18px; color: var(--label-2); }
.menu button.destructive .ico { color: var(--red); }
.menu button:hover, .menu button:focus-visible { background: var(--fill); outline: none; }
.menu button:active { background: var(--fill-3); }
.menu hr { border: 0; border-top: 1px solid var(--sep); margin: 6px 8px; }
.menu .menu-title { padding: 8px 12px 4px; font-size: 12px; font-weight: 600; color: var(--label-2); }
.menu .menu-hint { padding: 4px 12px 8px; font-size: 12px; color: var(--label-2); }

/* ---------- layout ---------- */
.main {
  display: grid; grid-template-columns: minmax(400px, 500px) minmax(0, 1fr); gap: 32px;
  padding: var(--top-offset) 24px 48px; max-width: 1560px; margin: 0 auto;
}
.pane-editor { min-width: 0; }
.pane-head { padding: 8px 16px 12px; }
.title { margin: 0; font-size: 30px; line-height: 1.15; font-weight: 700; letter-spacing: -0.026em; text-wrap: balance; }
.subtitle { margin: 6px 0 0; color: var(--label-2); font-size: 14px; }
.group { margin-top: 26px; }
.group-title { margin: 0 16px 8px; font-size: 13px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--label-2); }
.group-foot { margin: 8px 16px 0; font-size: 13px; line-height: 1.4; color: var(--label-2); }
.card { background: var(--card); border-radius: var(--r-lg); overflow: clip; }

/* ---------- righe di lista ---------- */
.row {
  position: relative; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  min-height: 46px; padding: 8px 16px;
}
.card > .row:not(:first-child)::before, .card > .riga:not(:first-child)::before {
  content: ""; position: absolute; left: 16px; right: 0; top: 0; height: 1px; background: var(--sep);
}
.card > .row-indent::before { left: 32px; }
.row-label { font-size: var(--fs); color: var(--label); flex: none; }
.row-text { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.row-text .row-label { white-space: normal; }
.row-sub { font-size: 12.5px; line-height: 1.3; color: var(--label-2); }
.row > input, .row > .select, .row > .row-value, .row > textarea { flex: 1; min-width: 0; text-align: right; }
.row > input, .row-value input { padding: 4px 0; text-align: right; color: var(--label); width: 100%; }
.row input::placeholder, .row textarea::placeholder { color: var(--label-3); }
/* data: il campo nativo resta sopra, trasparente, e apre il selettore del sistema; sotto si legge la data in italiano */
.date { position: relative; display: inline-flex; align-items: center; flex: none; margin-left: auto; min-height: 30px; padding: 4px 10px; border-radius: 8px; background: var(--fill-2); color: var(--label); font-variant-numeric: tabular-nums; }
.date input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.date-text { pointer-events: none; white-space: nowrap; }
.date-text.placeholder { color: var(--label-3); }
.date:focus-within { outline: 2px solid var(--tint); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) { .date:hover { background: var(--fill); } }
.row-stack { flex-direction: column; align-items: stretch; gap: 3px; padding-top: 10px; padding-bottom: 10px; }
.row-stack .row-label { font-size: 13px; color: var(--label-2); }
.row-stack input, .row-stack textarea { text-align: left; padding: 2px 0; width: 100%; }
textarea { resize: none; width: 100%; line-height: 1.4; field-sizing: content; min-height: 1.4em; }
.row-indent { padding-left: 32px; }
.row-cols { gap: 14px; align-items: stretch; padding-top: 10px; padding-bottom: 10px; flex-wrap: nowrap; }
.col { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.col .row-label { font-size: 13px; color: var(--label-2); }
.col input { text-align: left; padding: 2px 0; width: 100%; }
.col-cap { width: 72px; flex: none; }
.col-prov { width: 54px; flex: none; }
.grow { flex: 1; min-width: 0; }
.row-button { width: 100%; text-align: left; color: var(--label); transition: background-color 120ms ease; }
.card > .row-button:first-child { border-radius: var(--r-lg) var(--r-lg) 0 0; }
.card > .row-button:last-child { border-radius: 0 0 var(--r-lg) var(--r-lg); }
@media (hover: hover) and (pointer: fine) { .row-button:hover { background: var(--card-hover); } }
.row-button:active { background: var(--fill-2); }
.row-detail { color: var(--label-2); font-size: 14px; }
.chev { color: var(--label-3); width: 18px; height: 18px; }
.row-actions { gap: 2px; padding: 4px 8px; }
.row-actions .row-button { width: auto; padding: 8px 10px; border-radius: 10px; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.affixed { display: flex; align-items: baseline; justify-content: flex-end; gap: 2px; }
.affixed input { width: auto; flex: 0 1 auto; min-width: 2ch; }
.affix { color: var(--label-2); }
.affix:empty { display: none; }
.int, .money, .num, .tnum { font-variant-numeric: tabular-nums; }
.hint { flex-basis: 100%; font-size: 12px; line-height: 1.3; color: var(--red); margin-top: -4px; padding-bottom: 2px; }

.select { position: relative; display: inline-flex; align-items: center; justify-content: flex-end; flex: 1; min-width: 0; }
.select select {
  appearance: none; -webkit-appearance: none; padding: 4px 22px 4px 0; text-align: right; text-align-last: right;
  color: var(--label); max-width: 100%; cursor: pointer;
}
.select .ico { position: absolute; right: 0; width: 16px; height: 16px; color: var(--label-3); pointer-events: none; }

/* ---------- interruttore ---------- */
.switch {
  position: relative; flex: none; width: 46px; height: 28px; border-radius: 14px; background: var(--fill-3);
  transition: background-color 240ms var(--ease-ios);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 12px; background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .16), 0 1px 1px rgba(0, 0, 0, .06);
  transition: transform 240ms var(--ease-ios), width 160ms var(--ease-ios);
}
.switch[aria-checked="true"] { background: var(--tint); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch:active::after { width: 28px; }
.switch[aria-checked="true"]:active::after { transform: translateX(14px); }

/* ---------- prestazioni ---------- */
.riga { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: end; padding: 12px 16px; }
.riga textarea { grid-column: 1 / -1; padding-right: 36px; font-size: var(--fs); }
.riga-nums { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--label-2); font-size: 13px; }
.riga-nums input, .riga-nums .select select {
  background: var(--fill-2); border-radius: 8px; padding: 4px 8px; color: var(--label); font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.riga-nums input { text-align: right; width: 5.5ch; }
.riga-nums input.price { width: 11ch; }
.riga-nums .select { flex: none; }
.riga-nums .select select { padding-right: 22px; text-align: left; text-align-last: left; }
.riga-nums .select .ico { right: 5px; }
.riga-nums .x { padding: 0 2px; }
.riga-tot { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; white-space: nowrap; }
.riga-del {
  position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border-radius: 50%; color: var(--label-3);
  display: inline-flex; align-items: center; justify-content: center; transition: background-color 120ms ease, color 120ms ease;
}
.riga-del .ico { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) { .riga-del:hover { background: var(--fill); color: var(--red); } }

/* ---------- riepilogo ---------- */
.card-summary { padding: 6px 0 4px; }
.sum-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 16px; font-size: 14px; color: var(--label-2); }
.sum-row b { color: var(--label); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum-row.total { color: var(--label); font-weight: 600; margin-top: 4px; padding-top: 10px; position: relative; }
.sum-row.total::before { content: ""; position: absolute; left: 16px; right: 16px; top: 0; height: 1px; background: var(--sep); }
.sum-row.total b { font-weight: 600; }
.sum-row.netto { color: var(--label); font-weight: 600; font-size: 15px; padding: 10px 16px 12px; align-items: baseline; }
.sum-row.netto b { font-weight: 700; font-size: 22px; letter-spacing: -0.02em; }
.avvisi { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.avvisi li {
  display: flex; gap: 8px; align-items: flex-start; padding: 9px 12px; border-radius: 12px;
  background: var(--orange-soft); color: var(--label); font-size: 13px; line-height: 1.35;
}
.avvisi .ico { width: 16px; height: 16px; color: var(--orange); margin-top: 1px; }

/* ---------- avviso ---------- */
.notice { display: flex; gap: 12px; padding: 14px 16px; margin: 4px 0 8px; align-items: flex-start; font-size: 14px; line-height: 1.45; }
.notice .ico { color: var(--tint); width: 22px; height: 22px; margin-top: 1px; }
.notice-body { min-width: 0; }
.notice-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- anteprima ---------- */
/* il pannello è alto quanto la finestra: il foglio viene ridotto (js fitPreview) finché pagina intera e pillola entrano senza scorrere */
.pane-preview {
  position: sticky; top: var(--top-offset); height: calc(100dvh - var(--top-offset) - 24px); overflow: auto;
  display: flex; flex-direction: column; align-items: center; padding: 8px 8px 12px; scrollbar-width: thin;
}
.sheet-wrap { zoom: var(--sheet-zoom, 1); }
.pane-preview .sheet { cursor: zoom-in; }
.pane-preview[data-zoom="larghezza"] .sheet { cursor: zoom-out; }
.preview-tools { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin-top: 16px; flex: none; }
.theme-pill, .zoom-pill { padding: 4px; border-radius: 999px; height: 44px; flex: none; }
.zoom-pill > button { border-radius: 999px; padding: 0 14px; font-size: 13px; min-height: 34px; }
.zoom-pill .seg-thumb { border-radius: 999px; background: var(--glass-thumb); box-shadow: inset 0 1px 0 var(--glass-thumb-hi), 0 2px 8px rgba(20, 30, 60, .12); }
.theme-pill > button { border-radius: 999px; padding: 0 14px; font-size: 13px; min-height: 34px; }
.theme-pill .seg-thumb { border-radius: 999px; background: var(--glass-thumb); box-shadow: inset 0 1px 0 var(--glass-thumb-hi), 0 2px 8px rgba(20, 30, 60, .12); }

/* ---------- archivio ---------- */
.filters { display: flex; gap: 10px; align-items: center; padding: 0 0 4px; flex-wrap: wrap; }
.search { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 200px; height: 36px; padding: 0 12px; border-radius: 999px; background: var(--fill); color: var(--label-2); }
.search .ico { width: 16px; height: 16px; }
.search input { flex: 1; color: var(--label); }
.search input::placeholder { color: var(--label-3); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.arch-year { margin-top: 22px; }
.arch-year-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0 16px 8px; }
.arch-year-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.arch-year-head span { font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; text-align: right; }
.arch-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 10px 16px; width: 100%; text-align: left; color: var(--label); position: relative; }
.card > .arch-row:not(:first-child)::before { content: ""; position: absolute; left: 16px; right: 0; top: 0; height: 1px; background: var(--sep); }
.arch-row .n { font-weight: 600; min-width: 0; }
.arch-row .c { color: var(--label-2); font-size: 13.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arch-row .amt { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; white-space: nowrap; }
.arch-row .d { color: var(--label-2); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: .01em; vertical-align: 1px; margin-left: 6px; }
.pill-bozza { background: var(--fill); color: var(--label-2); }
.pill-emessa { background: var(--tint-soft); color: var(--tint); }
.pill-pagata { background: var(--green-soft); color: var(--green); }
.empty { padding: 36px 24px; text-align: center; color: var(--label-2); font-size: 14px; line-height: 1.45; }
.empty .ico { width: 34px; height: 34px; color: var(--label-3); margin-bottom: 8px; stroke-width: 1.4; }
.empty h3 { margin: 0 0 4px; font-size: 17px; color: var(--label); font-weight: 600; }
.empty p { margin: 0 auto; max-width: 34ch; }
.empty .btn { margin-top: 14px; }

/* ---------- logo ---------- */
.logo-value { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
#logo-preview { height: 30px; max-width: 120px; object-fit: contain; border-radius: 4px; }

/* ---------- finestre ---------- */
dialog {
  border: 0; padding: 0; background: var(--bg); color: var(--label); border-radius: var(--r-xl);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45), 0 0 0 1px var(--sep);
  opacity: 1; transform: none; filter: none;
  transition: opacity 240ms var(--ease-out), transform 320ms var(--ease-out), filter 240ms var(--ease-out), overlay 320ms allow-discrete, display 320ms allow-discrete;
}
dialog:not([open]) { opacity: 0; transform: translateY(16px) scale(.98); }
@starting-style { dialog[open] { opacity: 0; transform: translateY(16px) scale(.98); filter: blur(8px); } }
dialog::backdrop {
  background: rgba(0, 0, 0, .28); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  transition: background-color 240ms ease, -webkit-backdrop-filter 240ms ease, backdrop-filter 240ms ease, overlay 320ms allow-discrete, display 320ms allow-discrete;
}
dialog:not([open])::backdrop { background: rgba(0, 0, 0, 0); -webkit-backdrop-filter: blur(0); backdrop-filter: blur(0); }
@starting-style { dialog[open]::backdrop { background: rgba(0, 0, 0, 0); -webkit-backdrop-filter: blur(0); backdrop-filter: blur(0); } }
.sheet-dialog { width: min(560px, calc(100vw - 32px)); max-height: min(80dvh, 720px); padding: 8px 16px 20px; margin: auto; flex-direction: column; gap: 12px; }
.sheet-dialog[open] { display: flex; }
.grabber { display: none; width: 36px; height: 5px; border-radius: 3px; background: var(--fill-3); margin: 4px auto 0; flex: none; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 0 2px; touch-action: none; }
.dlg-head h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.btn-close { width: 32px; height: 32px; border-radius: 50%; background: var(--fill); color: var(--label-2); display: inline-flex; align-items: center; justify-content: center; transition: transform 120ms var(--ease-out); }
.btn-close .ico { width: 16px; height: 16px; stroke-width: 2.25; }
.btn-close:active { transform: scale(.92); }
#rubrica-list { overflow: auto; flex: 1; min-height: 60px; }
.rub-row { display: flex; align-items: center; position: relative; }
.card > .rub-row:not(:first-child)::before { content: ""; position: absolute; left: 16px; right: 0; top: 0; height: 1px; background: var(--sep); }
.rub-main { flex: 1; min-width: 0; display: grid; gap: 1px; padding: 10px 16px; text-align: left; color: var(--label); }
.rub-main .n { font-weight: 600; }
.rub-main .c { color: var(--label-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rub-del { flex: none; width: 32px; height: 32px; margin-right: 10px; border-radius: 50%; color: var(--label-3); display: inline-flex; align-items: center; justify-content: center; }
.rub-del .ico { width: 16px; height: 16px; }
#rubrica-list .empty { padding: 20px 16px; }
@media (hover: hover) and (pointer: fine) { .rub-del:hover { background: var(--fill); color: var(--red); } .rub-main:hover { background: var(--card-hover); } }
/* riferimenti normativi */
.linklike { color: var(--tint); font-weight: 500; text-align: left; }
.linklike:hover { text-decoration: underline; text-underline-offset: 2px; }
.sheet-dialog-wide { width: min(640px, calc(100vw - 32px)); max-height: min(86dvh, 820px); }
.dlg-intro { margin: 0; font-size: 14px; line-height: 1.45; color: var(--label-2); }
.refs-list { overflow: auto; flex: 1; min-height: 80px; display: grid; gap: 10px; padding-bottom: 4px; }
.ref { background: var(--card); border-radius: var(--r-lg); padding: 14px 16px 12px; }
.ref h3 { margin: 0 0 2px; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.ref-cit { margin: 0; font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.ref-desc { margin: 8px 0 0; font-size: 14px; line-height: 1.45; }
.ref-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ref-links a { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; background: var(--tint-soft); color: var(--tint); font-size: 13px; font-weight: 500; text-decoration: none; transition: background-color 160ms ease, transform 140ms var(--ease-out); }
.ref-links a:hover { background: color-mix(in srgb, var(--tint) 20%, transparent); }
.ref-links a:active { transform: scale(.97); }
.ref-links a .ico { width: 14px; height: 14px; }
.ref-links .ente { flex-basis: 100%; font-size: 12px; color: var(--label-3); margin-top: 2px; }

.alert-dialog { width: min(340px, calc(100vw - 48px)); padding: 20px 20px 16px; text-align: center; margin: auto; }
.alert-dialog h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.alert-dialog p { margin: 0 0 18px; color: var(--label-2); font-size: 14px; line-height: 1.45; }
.alert-actions { display: flex; gap: 8px; justify-content: center; }
.alert-actions .btn { flex: 1; height: 40px; font-size: 14px; }
.alert-actions .btn-primary.destructive { background: var(--red); color: #fff !important; }

/* ---------- toast ---------- */
.toast {
  position: fixed; top: calc(12px + var(--topbar-h) + 12px); left: 50%; z-index: 60;
  display: flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 500; color: var(--label); max-width: calc(100vw - 32px);
  opacity: 1; transform: translateX(-50%);
  transition: opacity 220ms var(--ease-out), transform 280ms var(--ease-out), display 280ms allow-discrete;
}
.toast .ico { width: 18px; height: 18px; color: var(--green); }
.toast.warn .ico { color: var(--orange); }
.toast[hidden] { display: none; opacity: 0; transform: translateX(-50%) translateY(-8px) scale(.96); }
@starting-style { .toast:not([hidden]) { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(.96); } }

/* ---------- tab bar (schermi stretti) ---------- */
.tabbar { display: none; }

/* ---------- movimento ridotto ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
  dialog, .menu, .toast { transform: none !important; filter: none !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .main { grid-template-columns: minmax(380px, 440px) minmax(0, 1fr); gap: 24px; }
}
@media (max-width: 899px) {
  :root { --fs: 16px; --top-offset: calc(12px + var(--topbar-h) + 16px); }
  .topbar { left: 12px; right: 12px; }
  .cluster-nav .seg { display: none; }
  .cluster-nav { padding-right: 18px; }
  .cluster-actions .btn span { display: none; }
  .cluster-actions .btn { width: 44px; padding: 0; }
  /* minmax(0, 1fr): con "1fr" il minimo automatico lascerebbe al foglio non ancora ridotto (794px) allargare la colonna */
  .main { grid-template-columns: minmax(0, 1fr); gap: 0; padding: var(--top-offset) 12px 120px; }
  .pane-preview { min-width: 0; }
  .main:not([data-view="anteprima"]) .pane-preview { display: none; }
  .main[data-view="anteprima"] .pane-editor { display: none !important; }
  .pane-preview { position: static; height: auto; overflow: visible; padding: 0 0 8px; }
  .preview-tools { margin: 16px auto 0; }
  .zoom-pill { display: none; }
  .pane-preview .sheet { cursor: default; }
  .grabber { display: block; }
  .sheet-dialog.dragging { transition: none; }
  .title { font-size: 28px; }
  .row-cols { flex-wrap: wrap; }
  .tabbar {
    position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
    display: flex; gap: 2px; padding: 6px; border-radius: 999px;
  }
  .tabbar button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; width: 72px; padding: 6px 0 5px; border-radius: 999px;
    font-size: 11px; font-weight: 600; letter-spacing: 0; color: var(--label-2);
    transition: color 160ms ease, background-color 160ms ease, transform 120ms var(--ease-out);
  }
  .tabbar button:active { transform: scale(.94); }
  .tabbar button .ico { width: 22px; height: 22px; }
  .tabbar button[aria-current="page"] { color: var(--tint); background: var(--glass-thumb); box-shadow: inset 0 1px 0 var(--glass-thumb-hi), 0 2px 8px rgba(20, 30, 60, .1); }
  .menu { right: 12px; }
}
@media (max-width: 420px) {
  .tabbar button { width: 64px; }
  .seg > button { padding: 4px 8px; font-size: 12.5px; }
  .cluster-nav { padding-left: 16px; }
}
