/* Excel — aspetto
   Superfici calme e calde, un solo accento smeraldo, profondità leggera.
   Tutti i colori sono variabili: chiaro qui sotto, scuro più avanti. */

/* ---------- Colori: chiaro ---------- */
:root {
  --accent: #0e7a4a;
  --accent-hi: #0b6a40;
  --accent-ink: #ffffff;
  --accent-soft: rgba(14, 122, 74, .11);
  --accent-ring: rgba(14, 122, 74, .28);
  --canvas: #f3f4f1;
  --bar: #f3f4f1;
  --surface: #ffffff;
  --ribbon: #ffffff;
  --hover: rgba(20, 30, 24, .06);
  --press: rgba(20, 30, 24, .1);
  --line: #e2e5e0;
  --line-strong: #cfd4cc;
  --ink: #15191a;
  --ink-2: #5d6661;
  --ink-3: #8a928d;
  --field: #ffffff;
  --pop: rgba(255, 255, 255, .92);
  --danger: #b3261e;
  --err: #c0362c;
  --shadow-sm: 0 1px 2px rgba(16, 24, 20, .06), 0 1px 1px rgba(16, 24, 20, .04);
  --shadow: 0 12px 32px -8px rgba(16, 32, 22, .22), 0 2px 6px rgba(16, 32, 22, .08);
  --cell-bg: #ffffff;
  --cell-ink: #15191a;
  --grid-line: #e9ebe7;
  --head-bg: #f7f8f6;
  --head-ink: #7a837e;
  --head-on: #e3f1e8;
  --sel-fill: rgba(14, 122, 74, .08);
  --ref: #2f6fde;
  --toast: rgba(22, 26, 24, .92);
  --toast-ink: #f4f6f3;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r-sm: 7px;
  --r: 10px;
  --r-lg: 14px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

/* ---------- Colori: scuro ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #34c47c; --accent-hi: #4fd391; --accent-ink: #062014; --accent-soft: rgba(52, 196, 124, .15); --accent-ring: rgba(52, 196, 124, .35);
    --canvas: #111312; --bar: #111312; --surface: #1a1c1b; --ribbon: #1a1c1b;
    --hover: rgba(255, 255, 255, .07); --press: rgba(255, 255, 255, .11);
    --line: #2a2d2b; --line-strong: #3a3e3b; --ink: #ecefec; --ink-2: #a3aaa5; --ink-3: #737a75; --field: #222524;
    --pop: rgba(32, 35, 33, .94); --danger: #ff8a80; --err: #ff7b72;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 16px 40px -8px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .4);
    --cell-bg: #161817; --cell-ink: #e6e9e6; --grid-line: #252826; --head-bg: #1c1f1d; --head-ink: #858c87; --head-on: #18392a;
    --sel-fill: rgba(52, 196, 124, .12); --ref: #6ea4ff; --toast: rgba(236, 239, 236, .95); --toast-ink: #121413;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #34c47c; --accent-hi: #4fd391; --accent-ink: #062014; --accent-soft: rgba(52, 196, 124, .15); --accent-ring: rgba(52, 196, 124, .35);
  --canvas: #111312; --bar: #111312; --surface: #1a1c1b; --ribbon: #1a1c1b;
  --hover: rgba(255, 255, 255, .07); --press: rgba(255, 255, 255, .11);
  --line: #2a2d2b; --line-strong: #3a3e3b; --ink: #ecefec; --ink-2: #a3aaa5; --ink-3: #737a75; --field: #222524;
  --pop: rgba(32, 35, 33, .94); --danger: #ff8a80; --err: #ff7b72;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 16px 40px -8px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .4);
  --cell-bg: #161817; --cell-ink: #e6e9e6; --grid-line: #252826; --head-bg: #1c1f1d; --head-ink: #858c87; --head-on: #18392a;
  --sel-fill: rgba(52, 196, 124, .12); --ref: #6ea4ff; --toast: rgba(236, 239, 236, .95); --toast-ink: #121413;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--ui); font-size: 14px; color: var(--ink); background: var(--canvas);
  display: grid; grid-template-rows: auto auto auto auto auto 1fr auto;
  height: 100dvh; overflow: hidden;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; }
::selection { background: var(--accent-ring); }

/* ---------- Barra superiore ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px 6px; background: var(--bar); }
.brand { display: flex; align-items: center; gap: 9px; flex: none; }
.brand-mark { width: 30px; height: 30px; display: block; filter: drop-shadow(0 1px 1.5px rgba(8, 60, 36, .3)); }
.brand-name { font: 650 16px/1 var(--display); letter-spacing: -.015em; color: var(--ink); }
.quick { display: flex; gap: 2px; padding-left: 10px; border-left: 1px solid var(--line); }
.qb { width: 30px; height: 30px; border: 0; border-radius: var(--r-sm); background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); transition: background .12s, color .12s; }
.qb:hover { background: var(--hover); color: var(--ink); }
.qb:active { background: var(--press); }
.qb svg { width: 18px; height: 18px; }
.doc-meta { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.title {
  font: 600 14.5px var(--ui); color: var(--ink); border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; padding: 5px 8px; min-width: 0; width: 100%; max-width: 360px; text-overflow: ellipsis;
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.title:hover { border-color: var(--line-strong); }
.title:focus { outline: none; border-color: var(--accent); background: var(--field); box-shadow: 0 0 0 3px var(--accent-ring); }
.save-state { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: 12px; white-space: nowrap; }
.save-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .7; }
.file-actions { display: flex; gap: 4px; align-items: center; }
.btn {
  font: 500 13px var(--ui); border: 1px solid var(--line); background: var(--field); color: var(--ink);
  border-radius: var(--r-sm); padding: 6px 12px; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .12s var(--ease);
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(.5px); }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff), var(--accent));
  border-color: color-mix(in srgb, var(--accent) 80%, #000); color: var(--accent-ink);
  box-shadow: 0 1px 2px rgba(8, 60, 36, .25), inset 0 1px 0 rgba(255, 255, 255, .18); padding: 6px 14px;
}
.btn.primary:hover { background: var(--accent-hi); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--hover); color: var(--ink); }
.btn.small { padding: 4px 10px; font-size: 12px; }
:is(.btn, .tb, .big, .qb, .rtab, .sel, .menu button, .sheet-tab, .add-sheet):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Schede e nastro ---------- */
.ribbon-tabs { display: flex; gap: 2px; padding: 2px 14px 6px; background: var(--bar); overflow-x: auto; scrollbar-width: none; }
.rtab {
  position: relative; border: 0; background: transparent; cursor: pointer; padding: 6px 13px; border-radius: 999px;
  font-size: 13.5px; font-weight: 500; color: var(--ink-2); white-space: nowrap; transition: background .15s, color .15s;
}
.rtab:hover { color: var(--ink); background: var(--hover); }
.rtab[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.ribbon {
  background: var(--ribbon); margin: 0 10px; border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); overflow-x: auto; scrollbar-width: thin;
}
.panel { display: flex; align-items: stretch; min-height: 88px; padding: 6px 6px; width: max-content; min-width: 100%; animation: panel-in .18s var(--ease); }
.panel[hidden] { display: none; }
@keyframes panel-in { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: none; } }
.rgroup { display: flex; align-items: center; gap: 4px; padding: 0 12px; position: relative; }
.rgroup + .rgroup::before { content: ""; position: absolute; left: 0; top: 14%; bottom: 14%; width: 1px; background: var(--line); }
.col { display: flex; flex-direction: column; gap: 2px; }
.rows { display: grid; grid-template-rows: 1fr 1fr; gap: 6px; align-content: center; }
.row { display: flex; align-items: center; gap: 2px; }
.vsep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.tb {
  position: relative; height: 32px; min-width: 32px; padding: 0 6px; flex: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 1px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink); cursor: pointer;
  transition: background .12s, color .12s;
}
.tb:hover, .big:hover { background: var(--hover); }
.tb:active, .big:active { background: var(--press); }
.tb.on, .big.on { background: var(--accent-soft); color: var(--accent); }
.tb.wide { padding: 0 3px 0 6px; }
.tb.lbl-btn { gap: 6px; padding: 0 10px 0 6px; font-size: 13px; justify-content: flex-start; }
.tb svg { stroke-width: 1.5; }
.chev { width: 13px; height: 13px; stroke-width: 2; opacity: .6; }
.chev.in { width: 11px; height: 11px; vertical-align: -1px; }
.glyph { font: 400 18px/1 var(--ui); }
.glyph.small { font-size: 12.5px; font-weight: 600; letter-spacing: -.02em; }
.glyph.b { font-weight: 700; }
.glyph.i { font-style: italic; font-family: "New York", Georgia, serif; }
.glyph.u { text-decoration: underline; text-underline-offset: 3px; }
.glyph.s { text-decoration: line-through; font-size: 16px; }
.tb.color svg { margin-top: -5px; }
.tb .swatch { position: absolute; left: 7px; width: 18px; bottom: 5px; height: 4px; border-radius: 2px; box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .15); }
.tb.color input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.big {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-width: 64px; height: 74px; padding: 4px 8px; border: 0; border-radius: var(--r); background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 500; line-height: 1.15; text-align: center; white-space: nowrap; color: var(--ink);
  transition: background .12s, color .12s;
}
.big > svg { width: 28px; height: 28px; stroke-width: 1.35; color: var(--accent); }
.big.on > svg { color: inherit; }
.big .big-glyph { font: italic 400 26px/28px "New York", Georgia, serif; height: 28px; color: var(--accent); }
.sel {
  font: 13px var(--ui); color: var(--ink); height: 30px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--field); padding: 0 6px; cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.sel:hover { border-color: var(--line-strong); }
.sel:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.sel-size { width: 64px; }
.sel-fmt { width: 150px; }

/* ---------- Menu a comparsa ---------- */
.popover {
  position: fixed; z-index: 40; background: var(--pop); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 6px;
  -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4);
  animation: pop-in .14s var(--ease); transform-origin: top left;
}
.popover[hidden] { display: none; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-3px) scale(.985); } to { opacity: 1; transform: none; } }
.menu { padding: 5px; min-width: 200px; display: flex; flex-direction: column; gap: 1px; }
.menu button {
  text-align: left; border: 0; background: transparent; border-radius: var(--r-sm); padding: 7px 10px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 14px; font-size: 13px;
}
.menu button:hover { background: var(--accent-soft); color: var(--accent); }
.menu small { color: var(--ink-3); font-size: 11.5px; }
.menu button:hover small { color: inherit; opacity: .8; }
.fn-menu { width: 360px; max-height: 440px; }
.fn-search {
  font: 13px var(--ui); color: var(--ink); height: 34px; margin: 2px 2px 6px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--field);
}
.fn-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.fn-list { overflow: auto; max-height: 370px; }
.fn-list button { flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; }
.fn-list b { font-weight: 600; font-family: var(--mono); font-size: 12.5px; }
.fn-list small { white-space: normal; }

/* ---------- Barra della formula ---------- */
.formulabar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bar); }
.namebox, .formula {
  font: 13px var(--mono); color: var(--ink); height: 32px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--field); padding: 0 10px; box-shadow: var(--shadow-sm); transition: border-color .12s, box-shadow .12s;
}
.namebox { width: 92px; text-align: center; font-weight: 600; }
.formula { flex: 1; min-width: 0; padding-left: 38px; }
.namebox:focus, .formula:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.fx {
  position: relative; z-index: 1; margin-right: -38px; width: 30px; text-align: center;
  font: italic 600 14px "New York", Georgia, serif; color: var(--accent); pointer-events: none;
}

.findbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 0 10px 8px; background: var(--bar); }
.findbar[hidden] { display: none; }
.findbar input {
  font: 13px var(--ui); color: var(--ink); height: 30px; padding: 0 10px; width: 190px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--field);
}
.findbar input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.find-count { color: var(--ink-2); font-size: 12px; min-width: 70px; }

/* ---------- Suggerimenti delle funzioni ---------- */
.ac {
  position: fixed; z-index: 45; width: 380px; max-width: calc(100vw - 16px);
  background: var(--pop); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
  -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4);
  animation: pop-in .12s var(--ease); font-size: 13px;
}
.ac[hidden] { display: none; }
.ac-head { display: flex; justify-content: space-between; padding: 8px 12px 6px; font-size: 11px; font-weight: 600; letter-spacing: .02em; color: var(--ink-3); }
.ac-items { max-height: 264px; overflow-y: auto; padding: 0 5px 5px; scrollbar-width: thin; }
.ac-item { display: grid; grid-template-columns: 24px auto 1fr; align-items: center; gap: 9px; padding: 6px 8px; border-radius: var(--r-sm); cursor: pointer; }
.ac-item[aria-selected="true"] { background: var(--accent-soft); }
.ac-ic {
  width: 24px; height: 20px; display: grid; place-items: center; border-radius: 5px;
  font: italic 600 11px "New York", Georgia, serif; color: var(--accent); background: var(--accent-soft);
}
.ac-item[aria-selected="true"] .ac-ic { background: var(--accent); color: var(--accent-ink); }
.ac-name { font: 500 12.5px var(--mono); color: var(--ink-2); white-space: nowrap; }
.ac-name b { font-weight: 700; color: var(--ink); }
.ac-item[aria-selected="true"] .ac-name { color: var(--ink); }
.ac-item[aria-selected="true"] .ac-name b { color: var(--accent); }
.ac-desc { color: var(--ink-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.ac-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px;
  border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 60%, transparent); font-size: 11.5px; color: var(--ink-3);
}
.ac-foot code { font: 12px var(--mono); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-foot span { white-space: nowrap; }
kbd {
  font: 600 10.5px var(--ui); padding: 1px 5px; border-radius: 4px; color: var(--ink-2);
  background: var(--field); border: 1px solid var(--line-strong); border-bottom-width: 2px;
}
.fn-tip {
  position: fixed; z-index: 44; padding: 6px 10px; border-radius: var(--r-sm); max-width: calc(100vw - 16px);
  background: var(--toast); color: var(--toast-ink); font: 12px var(--mono); white-space: nowrap; box-shadow: var(--shadow);
  animation: pop-in .12s var(--ease); pointer-events: none;
}
.fn-tip[hidden] { display: none; }
.fn-tip b { font-weight: 700; }
.fn-tip em { font-style: normal; font-weight: 700; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; text-decoration-color: var(--accent); }

/* ---------- Griglia ---------- */
.sheet-wrap {
  position: relative; overflow: auto; outline: none; background: var(--cell-bg);
  margin: 0 10px; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-sm); scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
.grid {
  --zoom: 1;
  border-collapse: separate; border-spacing: 0; table-layout: fixed;
  font: 11pt var(--ui); color: var(--cell-ink); zoom: var(--zoom);
  font-variant-numeric: tabular-nums;
  user-select: none; -webkit-user-select: none;
}
.grid th, .grid td {
  height: 24px; padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: clip;
  border-right: 1px solid var(--grid-line); border-bottom: 1px solid var(--grid-line);
  background: transparent; line-height: 23px; vertical-align: bottom;
}
.grid td.ovf { overflow: visible; }
.grid.nogrid td { border-right-color: transparent; border-bottom-color: transparent; }
.grid thead th {
  position: sticky; top: 0; z-index: 3; background: var(--head-bg); color: var(--head-ink);
  font: 500 11.5px var(--ui); letter-spacing: .02em; text-align: center; vertical-align: middle; cursor: default;
  border-bottom: 1px solid var(--line);
}
.grid thead th .rs { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.grid thead th .rs:hover { background: linear-gradient(90deg, transparent 3px, var(--accent) 3px, var(--accent) 4px, transparent 4px); }
.grid tbody th {
  position: sticky; left: 0; z-index: 2; background: var(--head-bg); color: var(--head-ink);
  font: 500 11.5px var(--ui); text-align: center; vertical-align: middle; width: 46px; min-width: 46px; cursor: default;
  border-right: 1px solid var(--line);
}
.grid thead th.corner { left: 0; z-index: 4; }
.grid th.on { background: var(--head-on); color: var(--accent); font-weight: 650; }
.grid thead th.on { box-shadow: inset 0 -2px 0 var(--accent); }
.grid tbody th.on { box-shadow: inset -2px 0 0 var(--accent); }
.grid td.num { text-align: right; }
.grid td.ctr { text-align: center; }
.grid td.err { color: var(--err); text-align: center; font-weight: 500; }
.grid td.wrap { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.3; padding-top: 2px; padding-bottom: 2px; }
.grid td.formula-view { font-family: var(--mono); font-size: 10pt; text-align: left; color: var(--ink-2); }
.grid.freeze-row tbody tr:first-child td, .grid.freeze-row tbody tr:first-child th { position: sticky; top: 25px; z-index: 2; background-color: var(--cell-bg); }
.grid.freeze-row tbody tr:first-child th { z-index: 3; }
.grid.freeze-row tbody tr:first-child td { box-shadow: 0 1px 0 var(--line-strong); }
.grid.freeze-col tbody td:nth-child(2) { position: sticky; left: 46px; z-index: 1; background-color: var(--cell-bg); box-shadow: 1px 0 0 var(--line-strong); }
.grid.freeze-row tbody tr:first-child th { background-color: var(--head-bg); }
.grid.freeze-row.freeze-col tbody tr:first-child td:nth-child(2) { z-index: 3; }

.sel-box {
  position: absolute; pointer-events: none; z-index: 5; border-radius: 2px;
  border: 2px solid var(--accent); background: var(--sel-fill);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.sel-box.single { background: transparent; }
.sel-box.copying { border-style: dashed; animation: march 1s linear infinite; }
@keyframes march { 50% { border-color: color-mix(in srgb, var(--accent) 45%, transparent); } }
.fill-handle {
  position: absolute; z-index: 6; width: 9px; height: 9px; background: var(--accent); border-radius: 2px;
  border: 2px solid var(--cell-bg); cursor: crosshair; box-shadow: 0 0 0 .5px var(--accent);
}
.fill-preview { position: absolute; z-index: 5; pointer-events: none; border: 1.5px dashed var(--ink-2); border-radius: 2px; }
.cell-editor {
  position: absolute; z-index: 7; margin: 0; resize: none; overflow: hidden;
  font: 11pt var(--ui); color: var(--cell-ink); background: var(--cell-bg);
  border: 2px solid var(--accent); border-radius: 3px; padding: 1px 5px; outline: none; line-height: 21px;
  box-shadow: 0 0 0 4px var(--accent-soft), 0 8px 24px -6px rgba(0, 0, 0, .25);
  font-variant-numeric: tabular-nums;
}
.ref-hint { position: absolute; z-index: 4; pointer-events: none; border: 2px dashed var(--ref); border-radius: 2px; background: color-mix(in srgb, var(--ref) 8%, transparent); }

/* ---------- Barra dei fogli ---------- */
.sheetbar {
  display: flex; align-items: center; gap: 6px; padding: 0 12px 0 14px; height: 40px; margin: 0 10px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 0 0 var(--r-lg) var(--r-lg);
  box-shadow: var(--shadow-sm); font-size: 12.5px;
}
.sheet-tabs { display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none; align-items: center; height: 100%; }
.sheet-tab {
  border: 0; background: transparent; padding: 5px 13px; border-radius: 999px; cursor: pointer;
  color: var(--ink-2); white-space: nowrap; font-weight: 500; transition: background .12s, color .12s;
}
.sheet-tab:hover { background: var(--hover); color: var(--ink); }
.sheet-tab.on { color: var(--accent); font-weight: 600; background: var(--accent-soft); }
.add-sheet {
  border: 0; background: transparent; width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  font-size: 17px; line-height: 1; color: var(--ink-2); transition: background .12s, color .12s;
}
.add-sheet:hover { background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }
.sel-stats { color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.zoom { display: flex; align-items: center; gap: 8px; color: var(--ink-2); padding-left: 12px; border-left: 1px solid var(--line); height: 22px; }
.zoom input { width: 110px; accent-color: var(--accent); }
.zoom output { min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

.ctx-menu { position: fixed; z-index: 50; }

.toast {
  position: fixed; left: 50%; bottom: 64px; transform: translate(-50%, 14px) scale(.98);
  background: var(--toast); color: var(--toast-ink); padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 500; opacity: 0; pointer-events: none; z-index: 60; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  transition: opacity .2s var(--ease), transform .2s var(--ease); max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.print-area { display: none; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px 4px; }
  .brand-name { display: none; }
  .doc-meta { flex: 1 1 0; }
  .file-actions { width: 100%; overflow-x: auto; }
  .save-state, .zoom, .sel-stats { display: none; }
  .ribbon-tabs { padding: 2px 8px 6px; }
  .ribbon, .sheet-wrap { margin-left: 6px; margin-right: 6px; }
  .sheetbar { margin: 0 6px 6px; }
  .panel { min-height: 82px; }
  .ac { width: calc(100vw - 16px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Stampa / PDF: solo l'area usata ---------- */
@page { size: A4; margin: 1.5cm; }
@media print {
  body { display: block; height: auto; overflow: visible; background: #fff; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block; }
  .print-area table { border-collapse: collapse; font: 10pt -apple-system, "Segoe UI", sans-serif; color: #000; }
  .print-area td { padding: 2px 6px; border: 1px solid #ccc; white-space: nowrap; }
  .print-area td.num { text-align: right; }
}
