/* L'interfaccia intorno al foglio: archivio, barra, pannello. Il foglio vero sta in foglio.css. */
:root { --fondo: #e4e2db; --carta: #f7f6f2; --bordo: #dad8d0; --bordo2: #c9c7be; --ink: #1f1f1f; --tenue: #5a5a55; --verde: #3f5246; --rosso: #8c2f1b; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--fondo); color: var(--ink); font-family: "Instrument Sans", "Segoe UI", Arial, sans-serif; font-size: 15px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--verde); outline-offset: 2px; }
.serif { font-family: "Newsreader", Georgia, serif; font-weight: 400; }

.btn { height: 44px; padding: 0 16px; background: #fff; border: 1px solid var(--bordo2); border-radius: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--ink); }
.btn.pieno { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
.btn.verde { background: var(--verde); color: #fff; border-color: var(--verde); font-weight: 600; }
.btn.piccolo { height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.campo { display: block; font-size: 13px; color: var(--tenue); }
.campo input, .campo textarea { display: block; width: 100%; margin-top: 4px; padding: 0 12px; height: 44px; border: 1px solid var(--bordo2); border-radius: 6px; background: #fff; font-size: 15px; color: var(--ink); }
.campo textarea { height: auto; min-height: 190px; padding: 12px; line-height: 1.5; resize: vertical; }

.barra { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 28px; background: var(--carta); border-bottom: 1px solid var(--bordo); }
.barra .gruppo { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; min-width: 0; }

/* Entrata */
.entra { max-width: 420px; margin: 18vh auto 0; padding: 0 24px; }
.entra h1 { font-size: 34px; margin: 0 0 8px; }
.entra p { color: var(--tenue); margin: 0 0 16px; }

/* Archivio */
.archivio { max-width: 1040px; margin: 0 auto; padding: 28px 28px 80px; }
.cerca { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; background: #fff; border: 1px solid var(--bordo); border-radius: 6px; }
.cerca input { border: 0; outline: 0; width: 220px; background: transparent; }
.filtri { display: flex; flex-wrap: wrap; gap: 8px; }
.filtro { height: 40px; padding: 0 16px; border-radius: 20px; border: 1px solid var(--bordo2); background: transparent; }
.filtro[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.cliente { margin-top: 28px; }
.cliente h2 { margin: 0 0 10px; font-size: 24px; }
.tabella { background: #fff; border: 1px solid var(--bordo); border-radius: 8px; overflow: hidden; }
.progetto { padding: 10px 20px; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--verde); background: var(--carta); border-bottom: 1px solid var(--bordo); }
.riga { display: grid; grid-template-columns: minmax(0, 1fr) 132px 150px 120px 44px; align-items: center; gap: 12px; padding: 0 8px 0 20px; min-height: 58px; border-bottom: 1px solid var(--bordo); }
.riga:last-child { border-bottom: 0; }
.riga:hover { background: #fbfaf7; }
.riga .titolo { font-size: 17px; font-weight: 500; padding: 16px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.riga .quando { color: var(--tenue); }
.riga .importo { font-size: 17px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stato { height: 32px; padding: 0 10px; border-radius: 16px; border: 0; font-size: 13px; font-weight: 600; cursor: pointer; }
.stato.bozza { background: #e7e5de; color: #45453f; }
.stato.mandato { background: #f3e3c3; color: #6e4609; }
.stato.approvato { background: #dce6df; color: #2f4036; }
.icona { width: 40px; height: 40px; display: grid; place-items: center; background: transparent; border: 0; border-radius: 6px; color: var(--tenue); }
.icona:hover { background: #ebe9e2; color: var(--ink); }
.menu { position: absolute; z-index: 30; min-width: 170px; padding: 6px; background: #fff; border: 1px solid var(--bordo2); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); }
.menu button { display: block; width: 100%; height: 40px; padding: 0 12px; text-align: left; background: transparent; border: 0; border-radius: 4px; }
.menu button:hover { background: #f1efe9; }
.vuoto { margin-top: 48px; text-align: center; color: var(--tenue); }
.piede { margin-top: 28px; font-size: 14px; color: var(--tenue); }
.piede button { background: none; border: 0; padding: 0; text-decoration: underline; color: inherit; }

/* Editor */
.editor .nome { min-width: 0; }
.editor .nome small { display: block; font-size: 13px; color: var(--tenue); }
.editor .nome strong { display: block; font-size: 21px; line-height: 1.2; max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.salvato { font-size: 14px; color: var(--verde); min-width: 96px; }
.salvato.errore { color: var(--rosso); font-weight: 600; }
.segmenti { display: flex; background: #e7e5de; border-radius: 8px; padding: 3px; }
.segmenti button { height: 38px; padding: 0 14px; border: 0; border-radius: 6px; background: transparent; color: #45453f; }
.segmenti button[aria-pressed="true"] { background: #fff; color: var(--ink); font-weight: 600; }
.corpo { display: flex; align-items: flex-start; gap: 24px; padding: 20px 28px 80px; }
.tavolo { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.sopra { position: sticky; top: 69px; z-index: 10; background: var(--fondo); padding: 8px 0; margin: -8px 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; width: 100%; max-width: 210mm; font-size: 14px; color: #45453f; }
.misura { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--verde); }
.misura .tacca { width: 120px; height: 6px; background: #cfcdc5; border-radius: 3px; overflow: hidden; }
.misura .tacca i { display: block; height: 6px; background: var(--verde); }
.misura.oltre { color: var(--rosso); }
.misura.oltre .tacca { background: #e2b9ae; }
.misura.oltre .tacca i { background: var(--rosso); }
.oltre-avviso { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; width: 100%; max-width: 210mm; padding: 10px 14px; background: #f6e4de; border: 1px solid #d9a99b; border-radius: 8px; color: #5e1e10; }
.conflitto { background: #f3e3c3; border-color: #d9b877; color: #4d3206; }
.cornice { position: relative; width: max-content; transform-origin: top left; }
.cornice .foglio { border: 1px solid #cfcdc5; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06); position: relative; }
.fine-pagina { position: absolute; left: 0; right: 0; height: 0; border-top: 1px dashed #b9b7ae; pointer-events: none; }
.fine-pagina span { position: absolute; right: 8px; top: -17px; font-size: 11px; color: var(--tenue); }
.oltre .fine-pagina { border-top: 2px solid var(--rosso); }
.oltre .fine-pagina span { color: var(--rosso); font-weight: 600; }
.velo { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(246, 228, 222, 0.55); pointer-events: none; display: none; }
.oltre .velo { display: block; }

/* Testi che si scrivono sul foglio */
.foglio [data-c] { outline: 0; border-radius: 2px; cursor: text; }
.foglio [data-c]:hover { background: #f3f5f3; }
.foglio [data-c]:focus { background: #eef2ef; }
.foglio [data-c]:empty::before { content: attr(data-segna); color: #a9a9a2; }
.foglio td[data-c]:empty::before, .foglio span[data-c]:empty::before { content: attr(data-segna); }
.foglio li[data-c]:empty::after { content: "Scrivi la voce"; color: #a9a9a2; }
.foglio .data { cursor: pointer; border-radius: 2px; }
.foglio .data:hover { background: #f3f5f3; }
.foglio .blocco { position: relative; }
.foglio .blocco.scelto::after { content: ""; position: absolute; inset: -5px -9px; border: 1.5px solid var(--verde); border-radius: 3px; pointer-events: none; }
.foglio .b-totale.scelto::after { inset: -5px -9px -5px -3px; }
.foglio .b-separatore { cursor: pointer; }
.foglio .b-separatore::before { content: ""; position: absolute; inset: -7px 0; }
.attrezzi { position: absolute; z-index: 5; display: flex; flex-direction: column; gap: 4px; }
.attrezzi button { width: 34px; height: 34px; display: grid; place-items: center; background: #fff; border: 1px solid var(--bordo2); border-radius: 6px; color: var(--ink); }
.attrezzi button:hover { border-color: var(--ink); }
.attrezzi button.via { color: var(--rosso); }
.attrezzi button:disabled { opacity: 0.35; }
.sotto-blocco { position: absolute; z-index: 5; display: flex; flex-wrap: wrap; gap: 6px; }
.sotto-blocco button { height: 28px; padding: 0 10px; background: #fff; border: 1px dashed #8fa396; border-radius: 4px; color: var(--verde); font-size: 13px; }
.sotto-blocco button:hover { border-style: solid; }

.pannello { flex: 0 0 348px; position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-bottom: 8px; }
.scheda { background: var(--carta); border: 1px solid var(--bordo); border-radius: 8px; padding: 16px 18px; }
.scheda h2 { margin: 0 0 12px; font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--verde); }
.scheda .testa-scheda { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.scheda .testa-scheda h2 { margin: 0; }
.due { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.spunta { display: flex; align-items: center; gap: 10px; min-height: 40px; margin-top: 6px; font-size: 14px; }
.spunta input { width: 18px; height: 18px; accent-color: var(--verde); }
.nota { margin: 8px 0 0; font-size: 13px; color: var(--tenue); }

#avvisi { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.avviso { display: flex; align-items: center; gap: 14px; padding: 12px 16px; background: var(--ink); color: #fff; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); }
.avviso button { background: none; border: 0; color: #fff; text-decoration: underline; padding: 0; }
.avviso.brutto { background: var(--rosso); }

@media (max-width: 1180px) {
  .corpo { flex-direction: column; align-items: stretch; padding: 16px 12px 80px; }
  .pannello { position: static; flex: none; max-height: none; width: 100%; max-width: 210mm; margin: 0 auto; }
  .barra { padding: 10px 12px; }
  .editor .nome strong { max-width: 70vw; }
}
@media (max-width: 720px) {
  .barra { position: static; }
  .sopra { top: 0; }
  .archivio { padding: 16px 12px 80px; }
  .riga { grid-template-columns: minmax(0, 1fr) auto 44px; padding-left: 14px; }
  .riga .quando { display: none; }
  .riga .importo { grid-column: 1 / 2; grid-row: 2; text-align: left; padding-bottom: 12px; font-size: 15px; }
  .riga .titolo { padding-bottom: 2px; }
  .cerca input { width: 140px; }
}
@media print { .barra, .pannello, .sopra, .attrezzi, .sotto-blocco, #avvisi { display: none !important; } }
