/* Gestionale Falegnameria Amoruso — stile mobile-first */
:root {
  --legno: #8a7056;
  --legno-scuro: #5e4a37;
  --legno-chiaro: #b49a7c;
  --crema: #f7f3ee;
  --carta: #ffffff;
  --ink: #2c241c;
  --ink-2: #6b5f53;
  --linea: #e6ddd2;
  --ok: #2f7d4f;
  --ok-bg: #e5f3ea;
  --warn: #a5630c;
  --warn-bg: #fdf0dc;
  --err: #b3362c;
  --err-bg: #fbe7e5;
  --info: #2c5f8a;
  --info-bg: #e5eff8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 2px 8px rgba(60, 40, 20, .05);
  --side-w: 236px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--crema);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--crema); min-height: 100vh; -webkit-text-size-adjust: 100%; }
a { color: var(--legno-scuro); }
h1, h2, h3 { font-weight: 600; letter-spacing: .01em; margin: 0 0 .6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--ink-2); }
small { color: var(--ink-2); }
.ico { width: 20px; height: 20px; flex: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 40;
  background: var(--legno); color: #fff; display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform .22s ease;
}
.sidebar.open { transform: none; box-shadow: 4px 0 24px rgba(0,0,0,.25); }
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.1rem 1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.18); }
.brand-mark { font-size: 2.1rem; line-height: 1; font-weight: 300; border-right: 1px solid rgba(255,255,255,.6); padding-right: .6rem; }
.brand-txt { font-size: .74rem; letter-spacing: .14em; line-height: 1.35; }
.sidebar nav { flex: 1; overflow-y: auto; padding: .5rem 0; }
.sidebar nav a { display: flex; align-items: center; gap: .75rem; padding: .62rem 1.1rem; color: rgba(255,255,255,.9); text-decoration: none; font-size: .95rem; }
.sidebar nav a:hover { background: rgba(255,255,255,.1); }
.sidebar nav a.active { background: rgba(0,0,0,.18); color: #fff; box-shadow: inset 3px 0 0 #fff; }
.sidebar-foot { padding: .9rem 1.1rem 1.2rem; border-top: 1px solid rgba(255,255,255,.18); font-size: .85rem; }
.sidebar-foot a { color: #fff; }
.who { display: flex; flex-direction: column; margin-bottom: .35rem; }
.who small { color: rgba(255,255,255,.75); }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; display: none; }
.backdrop.show { display: block; }

/* ---------- Main ---------- */
.main { min-height: 100vh; padding-bottom: 76px; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--carta); border-bottom: 1px solid var(--linea);
  display: flex; align-items: center; gap: .6rem; padding: .55rem .9rem; min-height: 56px;
  padding-top: max(.55rem, env(safe-area-inset-top));
}
.topbar h1 { font-size: 1.12rem; margin: 0; flex: 1; color: var(--legno-scuro); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { background: none; border: 0; padding: .35rem; color: var(--legno-scuro); cursor: pointer; border-radius: 8px; }
.content { padding: .9rem; max-width: 1280px; margin: 0 auto; }

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--carta);
  border-top: 1px solid var(--linea); display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a, .bottomnav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .45rem 0 .5rem;
  color: var(--ink-2); text-decoration: none; font-size: .7rem; background: none; border: 0; font-family: inherit; cursor: pointer;
}
.bottomnav .ico { width: 22px; height: 22px; }
.bottomnav a.active { color: var(--legno-scuro); font-weight: 600; }

@media (min-width: 960px) {
  .sidebar { transform: none; }
  .main { margin-left: var(--side-w); padding-bottom: 0; }
  .bottomnav, .only-mobile, .backdrop { display: none !important; }
  .content { padding: 1.4rem 1.6rem; }
  .topbar { padding: .7rem 1.6rem; }
}

/* ---------- Componenti ---------- */
.card { background: var(--carta); border: 1px solid var(--linea); border-radius: var(--radius); padding: 1rem; margin-bottom: .9rem; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .6rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: .9rem; }
@media (min-width: 760px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
}
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: .9rem; }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(5, 1fr); } }
.kpi { background: var(--carta); border: 1px solid var(--linea); border-radius: var(--radius); padding: .8rem .9rem; text-decoration: none; color: inherit; box-shadow: var(--shadow); display: block; }
.kpi b { display: block; font-size: 1.55rem; font-weight: 600; color: var(--legno-scuro); line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .8rem; color: var(--ink-2); }
.kpi.alert b { color: var(--err); }

.btn {
  display: inline-flex; align-items: center; gap: .35rem; background: var(--legno); color: #fff; border: 1px solid var(--legno);
  padding: .5rem .9rem; border-radius: 8px; text-decoration: none; font: inherit; font-size: .9rem; cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--legno-scuro); border-color: var(--legno-scuro); }
.btn-light { background: var(--carta); color: var(--legno-scuro); border-color: var(--linea); }
.btn-light:hover { background: var(--crema); color: var(--legno-scuro); border-color: var(--legno-chiaro); }
.btn-danger { background: var(--carta); color: var(--err); border-color: #e7c2bd; }
.btn-danger:hover { background: var(--err-bg); color: var(--err); border-color: var(--err); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn .ico { width: 17px; height: 17px; }
.link-danger { background: none; border: 0; color: var(--err); cursor: pointer; padding: 0; font: inherit; font-size: .8rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; }

.flash { padding: .7rem .9rem; border-radius: 8px; margin-bottom: .8rem; font-size: .92rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-err { background: var(--err-bg); color: var(--err); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }

.badge { display: inline-block; padding: .15rem .5rem; border-radius: 99px; font-size: .74rem; font-weight: 600; background: #eee8e1; color: var(--ink-2); white-space: nowrap; }
.b-da_iniziare, .b-bozza, .b-da_fare { background: #eee8e1; color: #6b5f53; }
.b-in_produzione, .b-inviato, .b-in_corso, .b-aperta { background: var(--info-bg); color: var(--info); }
.b-in_montaggio, .b-alta, .b-in_scadenza { background: var(--warn-bg); color: var(--warn); }
.b-completato, .b-accettato, .b-fatto, .b-pagata, .b-entrata { background: var(--ok-bg); color: var(--ok); }
.b-sospeso, .b-annullato, .b-rifiutato { background: #f0eeee; color: #8a8380; text-decoration: line-through; }
.b-urgente, .b-scaduta { background: var(--err-bg); color: var(--err); }
.b-uscita { background: #efe7f6; color: #6b3f8f; }
.b-sopralluogo { background: #e8f0f7; color: #2c5f8a; }
.b-produzione { background: #f4ece1; color: #7a5a35; }
.b-montaggio { background: #fdf0dc; color: #a5630c; }
.b-consegna { background: #e5f3ea; color: #2f7d4f; }
.b-appuntamento { background: #efe7f6; color: #6b3f8f; }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; min-width: 0; }
.field label { font-size: .8rem; font-weight: 600; color: var(--ink-2); }
.field.check label { font-size: .92rem; font-weight: 400; color: var(--ink); display: flex; align-items: center; gap: .45rem; }
input, select, textarea {
  font: inherit; font-size: 16px; /* evita lo zoom su iPhone */
  padding: .55rem .65rem; border: 1px solid #d6cabb; border-radius: 8px; background: #fff; color: var(--ink); width: 100%; min-width: 0;
}
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--legno); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--legno-chiaro); outline-offset: 0; border-color: var(--legno); }
textarea { resize: vertical; }
.form-row { display: grid; gap: 0 .8rem; grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .form-row.c2 { grid-template-columns: 1fr 1fr; }
  .form-row.c3 { grid-template-columns: repeat(3, 1fr); }
  .form-row.c4 { grid-template-columns: repeat(4, 1fr); }
  .span2 { grid-column: span 2; }
  .span3 { grid-column: span 3; }
}
fieldset { border: 0; padding: 0; margin: 0; }
.form-foot { position: sticky; bottom: 64px; background: rgba(247,243,238,.95); backdrop-filter: blur(4px); padding: .7rem 0; display: flex; gap: .5rem; flex-wrap: wrap; z-index: 5; }
@media (min-width: 960px) { .form-foot { bottom: 0; } }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.filters input[type=search], .filters input[type=text] { flex: 1 1 220px; }
.filters select { flex: 0 1 200px; width: auto; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .8rem; }
.chip { padding: .35rem .75rem; border-radius: 99px; border: 1px solid var(--linea); background: var(--carta); text-decoration: none; color: var(--ink-2); font-size: .85rem; }
.chip.on { background: var(--legno); border-color: var(--legno); color: #fff; }

/* ---------- Tabelle: diventano schede su cellulare ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); font-weight: 600; padding: .55rem .6rem; border-bottom: 2px solid var(--linea); white-space: nowrap; }
table.t td { padding: .6rem; border-bottom: 1px solid var(--linea); vertical-align: top; }
table.t tr.clic { cursor: pointer; }
table.t tr.clic:hover td { background: #fbf8f4; }
table.t tfoot td { font-weight: 600; border-bottom: 0; }
@media (max-width: 759px) {
  table.rt thead { display: none; }
  table.rt, table.rt tbody, table.rt tr, table.rt td { display: block; width: 100%; }
  table.rt tr { background: var(--carta); border: 1px solid var(--linea); border-radius: var(--radius); margin-bottom: .55rem; padding: .45rem .7rem; box-shadow: var(--shadow); }
  table.rt td { border: 0; padding: .22rem 0; display: flex; justify-content: space-between; gap: .8rem; text-align: right; }
  table.rt td::before { content: attr(data-label); font-size: .78rem; color: var(--ink-2); text-align: left; flex: none; }
  table.rt td.main-cell { display: block; text-align: left; font-weight: 600; font-size: 1rem; padding-bottom: .3rem; }
  table.rt td.main-cell::before { content: none; }
  table.rt td:empty { display: none; }
  table.rt tfoot tr { background: none; box-shadow: none; border: 0; }
  .card > .table-wrap > table.rt tr { box-shadow: none; }
}

/* ---------- Dettagli ---------- */
dl.info { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; font-size: .93rem; }
dl.info dt { color: var(--ink-2); font-size: .82rem; padding-top: .1rem; }
dl.info dd { margin: 0; word-break: break-word; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-bottom: 1px solid var(--linea); display: flex; gap: .7rem; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list .when { min-width: 54px; font-size: .8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.list .grow { flex: 1; min-width: 0; }
.list a.title { font-weight: 600; text-decoration: none; color: var(--ink); }
.empty { text-align: center; padding: 1.5rem .5rem; color: var(--ink-2); }
.diario { list-style: none; margin: 0 0 .8rem; padding: 0; }
.diario li { border-left: 3px solid var(--legno-chiaro); padding: .3rem 0 .3rem .7rem; margin-bottom: .6rem; }
.diario small { display: block; }
.pre { white-space: pre-wrap; }

/* ---------- Righe editabili ---------- */
.righe { width: 100%; border-collapse: collapse; }
.righe th { font-size: .74rem; text-transform: uppercase; color: var(--ink-2); text-align: left; padding: .3rem; }
.righe td { padding: .25rem; vertical-align: top; }
.righe input, .righe textarea, .righe select { padding: .4rem .5rem; }
.righe .del { background: none; border: 0; color: var(--err); font-size: 1.3rem; cursor: pointer; padding: .3rem; }
@media (max-width: 759px) {
  .righe thead { display: none; }
  .righe, .righe tbody, .righe tr, .righe td { display: block; width: 100%; }
  .righe tr { border: 1px solid var(--linea); border-radius: 8px; padding: .4rem; margin-bottom: .5rem; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .3rem; position: relative; }
  .righe td { padding: 0; }
  .righe td.wide { grid-column: 1 / -1; }
  .righe td[data-label]::before { content: attr(data-label); display: block; font-size: .7rem; color: var(--ink-2); }
  .righe td.rm { position: absolute; top: -.2rem; right: 0; width: auto; }
}
.totali { margin-left: auto; max-width: 340px; font-size: .95rem; }
.totali div { display: flex; justify-content: space-between; padding: .25rem 0; }
.totali .tot { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--linea); margin-top: .3rem; padding-top: .45rem; }

/* ---------- Agenda ---------- */
.cal-nav { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem; flex-wrap: wrap; }
.cal-nav h2 { margin: 0; flex: 1; text-align: center; font-size: 1.05rem; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--linea); border-left: 1px solid var(--linea); background: var(--carta); border-radius: var(--radius); overflow: hidden; }
.cal .dow { font-size: .72rem; text-transform: uppercase; color: var(--ink-2); text-align: center; padding: .35rem 0; background: #faf6f1; border-right: 1px solid var(--linea); border-bottom: 1px solid var(--linea); }
.cal .day { min-height: 92px; border-right: 1px solid var(--linea); border-bottom: 1px solid var(--linea); padding: .25rem; font-size: .75rem; text-decoration: none; color: inherit; display: block; }
.cal .day.out { background: #faf8f5; color: #b5aba0; }
.cal .day.today .n { background: var(--legno); color: #fff; border-radius: 99px; padding: 0 .4rem; }
.cal .day .n { font-weight: 600; font-size: .8rem; display: inline-block; margin-bottom: .15rem; }
.cal .ev { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 4px; padding: 1px 4px; margin-bottom: 2px; font-size: .72rem; }
.cal .ev.fatto { opacity: .55; text-decoration: line-through; }
@media (max-width: 640px) {
  .cal .day { min-height: 54px; }
  .cal .ev { font-size: 0; height: 6px; padding: 0; margin: 2px 0 0; }
}
.giorno-h { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--legno-scuro); margin: 1rem 0 .4rem; display: flex; justify-content: space-between; align-items: center; }
.giorno-h.oggi { color: var(--err); }
.ev-card { background: var(--carta); border: 1px solid var(--linea); border-left: 4px solid var(--legno-chiaro); border-radius: 8px; padding: .55rem .7rem; margin-bottom: .45rem; display: flex; gap: .7rem; box-shadow: var(--shadow); }
.ev-card .ora { min-width: 46px; font-weight: 600; font-variant-numeric: tabular-nums; font-size: .9rem; }
.ev-card .grow { flex: 1; min-width: 0; }
.ev-card .grow a.title { font-weight: 600; color: var(--ink); text-decoration: none; }
.ev-card.t-sopralluogo { border-left-color: #2c5f8a; }
.ev-card.t-produzione { border-left-color: #8a6a3f; }
.ev-card.t-montaggio { border-left-color: #c47a12; }
.ev-card.t-consegna { border-left-color: #2f7d4f; }
.ev-card.t-appuntamento { border-left-color: #6b3f8f; }
.ev-card.s-fatto { opacity: .6; }
.ev-card.s-fatto .title { text-decoration: line-through; }
.ev-card.lavoro { border-left-style: dashed; }
.quick-done { margin-left: auto; }

/* ---------- Allegati ---------- */
.upload { margin-bottom: .7rem; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
.thumb { border: 1px solid var(--linea); border-radius: 8px; overflow: hidden; background: #faf7f3; display: flex; flex-direction: column; }
.thumb img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.thumb .doc { display: flex; align-items: center; justify-content: center; aspect-ratio: 4/3; font-size: 2.4rem; text-decoration: none; }
.thumb-meta { padding: .3rem .45rem 0; font-size: .75rem; display: flex; flex-direction: column; }
.thumb form { padding: 0 .45rem .35rem; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: var(--legno); }
.login-box { background: var(--carta); border-radius: 14px; padding: 1.8rem 1.5rem; width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-box .brand { color: var(--legno-scuro); border: 0; justify-content: center; padding: 0 0 1.2rem; }
.login-box .brand-mark { border-color: var(--legno-chiaro); }
.login-box .btn { width: 100%; justify-content: center; padding: .7rem; font-size: 1rem; }

/* ---------- Stampa ---------- */
@media print {
  .sidebar, .bottomnav, .topbar, .no-print, .form-foot, .backdrop { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; }
  body, :root { background: #fff; }
  .card { box-shadow: none; border: 0; padding: 0; }
}

/* ---------- Ritocchi cellulare ---------- */
@media (min-width: 420px) and (max-width: 639px) {
  .form-row.c4 { grid-template-columns: 1fr 1fr; }
  .form-row.c4 .span2 { grid-column: span 2; }
}
@media (max-width: 759px) {
  .righe.r2 tr { grid-template-columns: 1fr 1fr; }
  .cal .ev { height: 7px; border-radius: 3px; }
  .cal .ev.b-montaggio { background: #e3a23e; }
  .cal .ev.b-sopralluogo { background: #4f86b8; }
  .cal .ev.b-consegna { background: #49a06e; }
  .cal .ev.b-produzione { background: #a7814f; }
  .cal .ev.b-appuntamento { background: #8b62ad; }
  .cal .ev.b-altro { background: #a99d92; }
}
