/* Mastrone · segnaletica di cantiere: neutri grigio-verde, giallo cantiere come unico accento */
:root {
  --bg: #f3f4f2; --surface: #ffffff; --surface-2: #f8f9f7; --ink: #1d2320; --muted: #5f6964; --line: #d9ddd9;
  --accent: #e3a600; --accent-ink: #1d2320; --accent-soft: #fbefc8;
  --good: #2f7d4f; --warn: #a86400; --bad: #b3362b; --festivo: #eceeeb;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816; --surface: #1d2220; --surface-2: #232927; --ink: #e8ebe9; --muted: #9aa49f; --line: #333b37;
    --accent: #f0b81e; --accent-ink: #141816; --accent-soft: #3a3115;
    --good: #5cbf83; --warn: #e3a24a; --bad: #ec7468; --festivo: #262c29; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--body); }
[hidden] { display: none !important; }
a { color: inherit; }
.wrap { max-width: 1480px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
main.wrap { padding-block: 16px 48px; display: grid; gap: 16px; outline: none; }

/* testata */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-inner { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-block: 10px 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.mark { width: 36px; height: 36px; flex: none; display: block; }
.brand h1 { font: 700 26px/1 var(--display); letter-spacing: .02em; margin: 0; }
.brand small { color: var(--muted); font-size: 12px; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding-bottom: 0; }
.tabs a { text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; padding: 10px 12px; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* blocchi */
h2 { font: 700 23px/1.1 var(--display); letter-spacing: .02em; margin: 0; text-wrap: balance; }
h3 { font: 700 18px/1.2 var(--display); letter-spacing: .02em; margin: 0; }
.sub { color: var(--muted); font-size: 13px; margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; display: grid; gap: 12px; align-content: start; }
.testa { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; }
.grid2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1.2fr .8fr; } .grid2.pari { grid-template-columns: 1fr 1fr; } }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kpi b { display: block; font: 700 30px/1.1 var(--display); font-variant-numeric: tabular-nums; }
.kpi span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.kpi.attenzione b { color: var(--warn); }
.riga { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-block: 9px; border-top: 1px solid var(--line); }
.riga:first-child { border-top: 0; }
.riga .chi { min-width: 0; }
.riga .chi strong { display: block; font-weight: 600; }
.riga .chi em { font-style: normal; color: var(--muted); font-size: 13px; }
.vuoto { color: var(--muted); font-size: 14px; padding: 8px 0; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; border: 1px solid currentColor; }
.pill.good { color: var(--good); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); } .pill.muted { color: var(--muted); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.azioni { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* moduli */
label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 4px; }
input, select, textarea { font: 15px var(--body); padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); width: 100%; min-width: 0; }
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; }
.campi { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.campo-check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.btn { font: 600 14px var(--body); border-radius: 8px; padding: 9px 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.errore { color: var(--bad); font-size: 14px; margin: 0; }

/* tabelle */
.tab-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
td.dx, th.dx { text-align: right; }
tr.cliccabile { cursor: pointer; }
tr.cliccabile:hover td { background: var(--surface-2); }
tr.spento td { color: var(--muted); }

/* griglia settimanale */
.settimana td.cella { min-width: 92px; cursor: pointer; font-size: 13px; }
.settimana td.cella:hover { background: var(--accent-soft); }
.settimana .festivo { background: var(--festivo); }
.settimana .oggi { box-shadow: inset 0 -3px 0 var(--accent); }
.voce { display: block; line-height: 1.3; }
.voce b { font-family: var(--mono); font-weight: 500; }
.voce.da_confermare b { color: var(--warn); }
.voce.assenza { color: var(--bad); }

/* messaggi */
.chat { display: grid; gap: 8px; }
.bolla { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; }
.bolla .meta { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.bolla .testo { white-space: pre-wrap; }
.bolla .risposta { white-space: pre-wrap; font-size: 14px; border-left: 3px solid var(--good); padding-left: 10px; color: var(--ink); }
.filtri { display: flex; gap: 6px; flex-wrap: wrap; }
.filtri button { font: 600 13px var(--body); border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.filtri button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.barra { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; min-width: 80px; }
.barra i { display: block; height: 100%; background: var(--accent); }
pre.report { white-space: pre-wrap; font: 14px/1.5 var(--mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 0; }
.avviso { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: min(380px, 100%); display: grid; gap: 10px; }
.login-box .btn { justify-content: center; margin-top: 6px; }

/* finestra modale e avvisi */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--ink); width: min(560px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
#modale-form { padding: 20px; display: grid; gap: 14px; }
#toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }
#toast.errore { background: var(--bad); color: #fff; }
@media (prefers-reduced-motion: no-preference) { .barra i { transition: width .4s ease; } }

/* scelta dei prezzi: prezzario regionale o ditta */
.scelta-listino { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; display: grid; gap: 8px; margin: 0; }
.scelta-listino legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
.scelta-listino .campo-check { align-items: flex-start; }
.scelta-listino input { margin-top: 4px; }
.interruttore { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.interruttore .sub:last-child { flex: 1 1 240px; }

/* lettura delle misure dai disegni e modello del preventivo */
.caricamento { border: 2px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; display: grid; gap: 8px; justify-items: center; background: var(--surface-2); }
.caricamento.sopra { border-color: var(--accent); background: var(--accent-soft); }
.proposta-amb { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 8px; }
.proposta-amb .campi { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.anteprima-modello { width: 100%; max-width: 360px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.riconosciuti { display: grid; gap: 4px; font-size: 13px; }
.riconosciuti span { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dotted var(--line); padding-block: 3px; }
.riconosciuti em { text-align: right; overflow-wrap: anywhere; } .riconosciuti code { font: 12px var(--mono); }
.assistita { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }

/* rapportino, documenti, cartello e PSC */
.titoletto { font: 600 12px/1.3 var(--body); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 14px 0 4px; }
.titoletto:first-child { margin-top: 4px; }
.titoletto .sub { text-transform: none; letter-spacing: 0; font-weight: 400; }
.aggiungi-nota { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; margin-top: 8px; }
.aggiungi-nota select { width: auto; }
@media (max-width: 520px) { .aggiungi-nota { grid-template-columns: 1fr; } }
.galleria { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.galleria figure { margin: 0; position: relative; display: grid; gap: 4px; }
.galleria img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; background: var(--surface-2); }
.galleria figcaption { font-size: 12.5px; line-height: 1.3; }
.galleria figcaption span { display: block; color: var(--muted); }
.galleria figure .btn { position: absolute; top: 6px; right: 6px; background: var(--surface); padding: 2px 8px; }
.aggiungi-foto { border: 2px dashed var(--line); border-radius: 8px; aspect-ratio: 4 / 3; display: grid; place-items: center; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; margin: 0; }
.aggiungi-foto:hover { border-color: var(--accent); color: var(--ink); }
.galleria.scelta label { display: grid; gap: 4px; font-weight: 400; font-size: 12.5px; position: relative; cursor: pointer; }
.galleria.scelta input { position: absolute; top: 8px; left: 8px; width: 20px; height: 20px; }
.galleria.scelta label:has(input:checked) img { outline: 3px solid var(--accent); outline-offset: -3px; }
.riga.doc .chi { overflow-wrap: anywhere; }
.nome-doc { font-weight: 600; text-decoration: none; display: inline-flex; gap: 8px; align-items: baseline; }
.nome-doc:hover { text-decoration: underline; }
.tipo-doc { font: 500 10.5px var(--mono); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; color: var(--muted); flex: none; }
.qr-check { font-size: 13px; white-space: nowrap; margin: 0; }
.colonna-destra { display: grid; gap: 14px; align-content: start; }
.caricamento .campi { text-align: left; width: 100%; }
.caricamento > div { text-align: left; }
.qr-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 10px; background: var(--surface-2); }
.qr-box .titoletto { margin: 0; }
.url-qr { font: 13px var(--mono); overflow-wrap: anywhere; }
dialog.ampio { width: min(980px, calc(100% - 24px)); }
.psc-fasi input:not([type="checkbox"]), .psc-costi input { padding: 6px 8px; font-size: 14px; }
.psc-fasi td, .psc-costi td { padding: 5px 6px; }
.psc-fasi .nome-fase { white-space: normal; min-width: 180px; font-size: 14px; }
.psc-costi td:nth-child(2) { min-width: 260px; }
input.corto { width: 76px; }
.spost { white-space: nowrap; }
.spost .btn { padding: 3px 8px; }
.riga .chi em { display: block; }
.mancanti-doc { margin-top: 12px; line-height: 1.6; }

/* editor del preventivo: la tabella delle voci prende quasi tutta la larghezza */
.editor-grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 1100px) { .editor-grid { grid-template-columns: minmax(0, 1fr) 320px; } }
table.righe-prev td.descr { white-space: normal; min-width: 220px; }
table.righe-prev td, table.righe-prev th { padding: 7px 8px; }
.col-x { width: 34px; padding-right: 0 !important; }
/* eliminazione: piccola X rossa */
.x-rossa { border: 1px solid transparent; background: none; color: var(--bad); font: 700 15px/1 var(--body); width: 28px; height: 28px; border-radius: 6px; cursor: pointer; display: inline-grid; place-items: center; padding: 0; }
.x-rossa:hover { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.x-rossa.sicuro { background: var(--bad); color: #fff; width: auto; padding: 0 8px; font-size: 12px; }
td.col-azione { width: 40px; text-align: right; }

.brand h1 .scritta { display: block; height: 22px; width: auto; }
.login-box .brand h1 .scritta { height: 26px; }
.caselle-permessi { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 6px 16px; }
.campo-check input { flex: none; }

/* conferma ore */
.avviso.ok { background: color-mix(in srgb, var(--good) 14%, transparent); }
.proposta-ore table td { vertical-align: middle; }
.proposta-ore select { min-width: 150px; }
.proposta-ore .ore-input { width: 76px; text-align: right; }
.aggiungi-operaio { margin-top: 12px; max-width: 320px; }
.btn.grande { width: 100%; margin-top: 16px; padding-block: 14px; font-size: 16px; }
@media (max-width: 560px) {
  .proposta-ore table, .proposta-ore tbody { display: block; }
  .proposta-ore thead { display: none; }
  .proposta-ore tr { display: grid; grid-template-columns: 1fr 84px; gap: 6px 10px; padding-block: 10px; border-top: 1px solid var(--line); }
  .proposta-ore tr:first-child { border-top: 0; }
  .proposta-ore td { display: block; padding: 0; border: 0; }
  .proposta-ore td:first-child { grid-column: 1 / -1; }
  .proposta-ore td:last-child { grid-column: 1 / -1; text-align: left; }
  .proposta-ore td:last-child button[hidden] { display: none; }
  .proposta-ore select { min-width: 0; width: 100%; }
}

/* logo dell'impresa */
.logo-impresa { height: 36px; max-width: 140px; object-fit: contain; display: block; }
.logo-impresa[hidden] { display: none; }
.logo-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; }
.logo-box img { max-height: 56px; max-width: 200px; object-fit: contain; background: #fff; border-radius: 6px; padding: 4px; }
@media (max-width: 560px) {
  .logo-impresa { height: 28px; max-width: 96px; }
  .user:has(.logo-impresa:not([hidden])) #nome-utente { display: none; }
}
tr.cliccabile { cursor: pointer; } tr.cliccabile:hover td, tr.scelta td { background: var(--accent-soft); }
