/* Grafica ripresa da syscoit.solutions: giallo #FACC33, testo #1A202C, font Raleway */

@font-face { font-family: Raleway; font-weight: 400; font-style: normal; font-display: swap; src: url('fonts/Raleway-Regular.ttf') format('truetype'); }
@font-face { font-family: Raleway; font-weight: 500; font-style: normal; font-display: swap; src: url('fonts/Raleway-Medium.ttf') format('truetype'); }
@font-face { font-family: Raleway; font-weight: 600; font-style: normal; font-display: swap; src: url('fonts/Raleway-SemiBold.ttf') format('truetype'); }
@font-face { font-family: Raleway; font-weight: 700; font-style: normal; font-display: swap; src: url('fonts/Raleway-Bold.ttf') format('truetype'); }

:root {
  --brand: #facc33;          /* giallo Sysco */
  --brand-hover: #f2bd0d;
  --brand-soft: #fef6d8;
  --ink: #1a202c;            /* testo principale e pulsanti */
  --ink-2: #2d3748;
  --muted: #718096;
  --bg: #f7fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e0;
  --danger: #c53030;
  --ok-bg: #dcfae6;   --ok-text: #067647;
  --warn-bg: #fef0c7; --warn-text: #93370d;
  --info-bg: #edf2f7; --info-text: #2d3748;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(26, 32, 44, .06), 0 4px 14px rgba(26, 32, 44, .05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 500 16px/1.5 Raleway, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: lining-nums; /* Raleway usa numeri "da testo" di default */
  font-feature-settings: "lnum" 1;
}
a { color: var(--ink); text-decoration-color: var(--brand); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--ink); }
h1, h2 { font-weight: 700; letter-spacing: -.01em; color: var(--ink); }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }

/* --- Barra superiore --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(26, 32, 44, .02);
  display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem;
  padding: .45rem 1rem;
}
.topbar .brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none; margin-right: auto; font-weight: 700; }
.topbar .brand img { height: 46px; width: auto; display: block; }
.topbar .brand span { font-size: .95rem; color: var(--ink-2); border-left: 2px solid var(--brand); padding-left: .6rem; line-height: 1.2; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem; }
.topbar nav a, .topbar nav .link {
  color: var(--ink-2); text-decoration: none; padding: .4rem .8rem; border-radius: 999px;
  font-size: .95rem; font-weight: 600;
}
.topbar nav a:hover, .topbar nav .link:hover { background: var(--bg); color: var(--ink); }
.topbar nav a.active { background: var(--brand); color: var(--ink); }

.container { max-width: 1000px; margin: 0 auto; padding: 1.2rem 16px 3rem; }

/* --- Elementi comuni --- */
.card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: .8rem;
  color: inherit; text-decoration: none; box-shadow: var(--shadow);
}
a.card { transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--brand); transform: translateY(-1px); }
.cards { list-style: none; margin: 0; padding: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; }
.pre { white-space: pre-wrap; margin: 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .6rem; }
.page-head h1 { margin: .4rem 0; }
.inline { display: inline; margin: 0; }
.customer { font-size: 1.1rem; font-weight: 700; margin: .2rem 0; }

.flash { background: var(--brand-soft); color: var(--ink); border-left: 4px solid var(--brand); padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 600; }
.alert { background: #fff5f5; color: var(--danger); border-left: 4px solid var(--danger); padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.alert ul { margin: 0; padding-left: 1.2rem; }

.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: .18rem .65rem; border-radius: 999px; background: var(--info-bg); color: var(--info-text); }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.info { background: var(--ink); color: #fff; }

/* --- Pulsanti (a pillola, come sul sito) --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 44px; padding: .5rem 1.25rem; border-radius: 999px;
  border: 2px solid var(--ink); background: transparent; color: var(--ink);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--ink); color: #fff; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--ink); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--ink); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.small { min-height: 36px; padding: .3rem 1rem; font-size: .875rem; }
.btn.block { width: 100%; }
.btn-icon { border: 0; background: none; color: var(--muted); font-size: 1.1rem; padding: .4rem .6rem; cursor: pointer; border-radius: 999px; }
.btn-icon:hover { color: var(--danger); background: #fff5f5; }
.link { background: none; border: 0; font: inherit; cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .8rem 0; }
.actions.sticky { position: sticky; top: 62px; z-index: 5; background: var(--bg); padding: .5rem 0; }

/* --- Form --- */
.form fieldset { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1rem; box-shadow: var(--shadow); }
.form legend { font-weight: 700; padding: .15rem .7rem; background: var(--brand); border-radius: 999px; font-size: .9rem; }
.form label { display: block; font-size: .9rem; font-weight: 700; margin-bottom: .8rem; color: var(--ink-2); }
.form label.check, label.check { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem;
  font: inherit; font-weight: 500; font-size: 16px; /* evita lo zoom automatico su iPhone */
  padding: .6rem .8rem; min-height: 44px;
  border: 1px solid var(--border-strong); border-radius: 10px; background: #fff; color: var(--ink);
}
input[type=checkbox] { width: 1.2rem; height: 1.2rem; min-height: 0; margin: 0; display: inline-block; accent-color: var(--ink); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--brand); }
.btn:focus-visible, a:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 .8rem; }
.grid.three { grid-template-columns: 90px 1fr 70px; }
#customer-filter { margin-bottom: .5rem; }

.filters { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input[type=search] { flex: 1 1 200px; margin: 0; border-radius: 999px; padding-left: 1.1rem; }
.filters select { width: auto; margin: 0; }
.filters.wrap { align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.filters.wrap label { font-size: .85rem; font-weight: 700; flex: 1 1 140px; min-width: 0; color: var(--ink-2); }
/* the select fills its column instead of growing to the longest customer name */
.filters.wrap select { width: 100%; max-width: 100%; text-overflow: ellipsis; }

/* --- Materiali --- */
.materials { width: 100%; border-collapse: collapse; margin-bottom: .6rem; }
.materials th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 700; padding: 0 .2rem; }
.materials td { padding: .2rem; vertical-align: middle; }
.materials input { margin: 0; }
.materials td:nth-child(2) { width: 5rem; }
.materials td:nth-child(3) { width: 4.5rem; }
.materials td:nth-child(4) { width: 2.5rem; }

/* --- Dettaglio --- */
.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.2rem; margin: 0; }
.details dt { color: var(--muted); font-weight: 600; }
.details dd { margin: 0; font-weight: 600; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .78rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr:hover { background: var(--bg); }
.table .num { text-align: right; white-space: nowrap; }
.table .desc { min-width: 220px; white-space: pre-wrap; }
.table-scroll { overflow-x: auto; }
.compact { margin: .6rem 0 0; padding-left: 1.2rem; }
.signature { max-width: 100%; max-height: 160px; border-bottom: 2px solid var(--brand); display: block; margin-bottom: .5rem; }

/* --- Firma --- */
.sig-wrap { position: relative; border: 2px dashed var(--border-strong); border-radius: var(--radius); background: #fff; }
.sig-wrap.signed { border-color: var(--brand); border-style: solid; }
#sig-canvas { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.sig-hint { position: absolute; left: 1rem; bottom: .6rem; color: #a0aec0; pointer-events: none; font-size: .9rem; }
.sig-wrap.signed .sig-hint { display: none; }

/* --- Riepilogo --- */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-bottom: 1rem; }
.totals div { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--brand); border-radius: var(--radius); padding: .7rem 1rem; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.totals span { font-size: .85rem; font-weight: 600; }
.totals strong { font-size: 1.5rem; font-weight: 700; }

/* --- Login --- */
.login-page { min-height: calc(100vh - 4.5rem); display: grid; place-items: center; padding: 1rem 0; }
.login-box { width: 100%; max-width: 380px; padding: 1.8rem 1.5rem; text-align: center; border-top: 5px solid var(--brand); }
.login-box .logo { width: 170px; height: auto; margin: 0 auto .4rem; display: block; }
.login-box h1 { font-size: 1.2rem; margin: .2rem 0 1.2rem; color: var(--ink-2); }
.login-box .form { text-align: left; }

/* --- Elementi per il telefono (nascosti sul PC) --- */
.tabbar, .mobile-user { display: none; }
.chips { display: flex; gap: .4rem; margin: -.4rem 0 1rem; overflow-x: auto; }
.chip {
  flex: 0 0 auto; padding: .4rem 1rem; border-radius: 999px; min-height: 38px; display: inline-flex; align-items: center;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink-2);
  font-weight: 700; font-size: .9rem; text-decoration: none;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.add-link { display: inline-block; margin-top: .5rem; font-weight: 700; }

/* Sezioni richiudibili del modulo (Materiali, Note) */
.fold { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: .2rem 1.1rem; margin: 0 0 1rem; box-shadow: var(--shadow); }
.fold summary { cursor: pointer; font-weight: 700; padding: .7rem 0; list-style: none; display: flex; align-items: center; gap: .4rem; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::before { content: '+'; display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 999px; background: var(--brand); font-weight: 700; }
.fold[open] summary::before { content: '–'; }
.fold[open] { padding-bottom: 1rem; }
.fold textarea { margin-top: 0; }

.sign-summary .details { margin-bottom: .7rem; }
.secondary-actions { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.menu-list .card { display: flex; flex-direction: column; gap: .1rem; }
.sig-clear {
  position: absolute; top: .5rem; right: .5rem; border: 1px solid var(--border-strong); background: #fff;
  color: var(--ink-2); font: inherit; font-weight: 700; font-size: .85rem; padding: .3rem .8rem; border-radius: 999px; cursor: pointer;
}

/* Versione del programma, in basso a destra */
.app-version {
  position: fixed; right: .6rem; bottom: calc(.4rem + env(safe-area-inset-bottom)); z-index: 5;
  font-size: .8rem; font-weight: 700; color: var(--ink-2); background: var(--surface); border: 1px solid var(--border);
  padding: .1rem .5rem; border-radius: 999px; box-shadow: 0 1px 4px rgba(26, 32, 44, .08); pointer-events: none; user-select: none;
}

/* --- Telefono --- */
@media (max-width: 700px) {
  :root { --tabbar-h: 62px; }
  body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  /* sopra la barra dei pulsanti in basso */
  body.has-tabbar .app-version { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + .2rem); }
  .hide-mobile { display: none !important; }

  .topbar { padding: .35rem 16px; padding-top: calc(.35rem + env(safe-area-inset-top)); flex-wrap: nowrap; }
  .topbar .brand img { height: 36px; }
  .topbar .brand span { display: none; }
  .desktop-nav { display: none !important; }
  .mobile-user { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }

  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -2px 10px rgba(26, 32, 44, .05);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 700;
    -webkit-tap-highlight-color: transparent;
  }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar a.active { color: var(--ink); }
  .tabbar a.active svg { stroke: var(--ink); }
  .tabbar a.active span { box-shadow: inset 0 -3px 0 var(--brand); }
  .tabbar .tab-new svg { width: 40px; height: 40px; padding: 8px; border-radius: 999px; background: var(--brand); color: var(--ink); stroke-width: 2.6; margin-top: -6px; }
  .tabbar .tab-new.active span { box-shadow: none; }

  .container { padding: .8rem 16px 1.5rem; }
  h1 { font-size: 1.35rem; }
  .page-head { margin-bottom: .3rem; }
  .card { padding: .85rem 1rem; }

  .filters input[type=search] { flex-basis: 100%; }

  /* Modulo */
  .form fieldset { padding: .8rem .9rem .2rem; }
  .fold { padding: .1rem .9rem; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 .6rem; }
  .grid.three { grid-template-columns: 5.5rem minmax(0, 1fr) 4rem; }
  input[type=date], input[type=time] { -webkit-appearance: none; appearance: none; min-width: 0; text-align: left; }

  /* Materiali: una scheda per riga (descrizione sopra, quantità e unità sotto) */
  .materials thead { display: none; }
  .materials, .materials tbody { display: block; }
  .materials tr { display: grid; grid-template-columns: minmax(0, 1fr) 5rem 2.6rem; gap: .35rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
  .materials td { display: block; padding: 0; width: auto !important; }
  .materials td:first-child { grid-column: 1 / -1; }
  .materials td:last-child { display: flex; align-items: center; justify-content: center; }

  /* Pulsanti di salvataggio sempre a portata di pollice */
  .savebar {
    position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 10;
    margin: 0 -16px; padding: .6rem 16px; background: var(--bg); border-top: 1px solid var(--border);
    flex-wrap: nowrap;
  }
  .savebar .btn { flex: 1 1 0; padding-left: .6rem; padding-right: .6rem; }
  .savebar .btn.primary { flex-grow: 1.6; }

  .actions .btn, .actions form.inline { flex: 1 1 auto; }
  .actions form.inline .btn { width: 100%; }
  .main-actions .btn.wide { flex-basis: 100%; min-height: 52px; font-size: 1.05rem; }
  .secondary-actions { justify-content: center; }

  .details { gap: .2rem .9rem; }

  /* Firma */
  .sign-summary { font-size: .92rem; }
  #sig-canvas { height: clamp(200px, 42vh, 320px); }
  .sign-actions { flex-direction: column; }
  .sign-actions .btn { width: 100%; min-height: 52px; }

  .actions.sticky { top: 50px; }
  .totals { grid-template-columns: 1fr; }
  .totals strong { font-size: 1.2rem; }
}
