/* ===========================================================================
   Fatturazione Estera — interfaccia
   Impianto ispirato alle Human Interface Guidelines: tipografia di sistema,
   superfici traslucide, angoli morbidi, colori semantici Apple.
   Nessun framework, nessun font remoto: tutto locale e in un file solo.
   =========================================================================== */

:root {
  /* Grigi sistema (light) */
  --bg:            #f5f5f7;
  --surface:       #ffffff;
  --surface-2:     #fbfbfd;
  --separator:     rgba(60, 60, 67, .12);
  --separator-2:   rgba(60, 60, 67, .06);

  --label:         #1d1d1f;
  --label-2:       rgba(60, 60, 67, .68);
  --label-3:       rgba(60, 60, 67, .42);

  /* Colori semantici */
  --blue:   #0071e3;  --blue-bg:   rgba(0, 113, 227, .10);
  --green:  #1d8a4c;  --green-bg:  rgba(52, 199, 89, .14);
  --orange: #a05a00;  --orange-bg: rgba(255, 149, 0, .16);
  --red:    #c9251c;  --red-bg:    rgba(255, 59, 48, .12);
  --gray-bg:rgba(120, 120, 128, .12);

  --shadow-sm: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
  --shadow-md: 0 4px 16px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.10), 0 2px 8px rgba(0,0,0,.04);

  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-pill: 980px;
  --ease: cubic-bezier(.4, 0, .22, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #000000;
    --surface:     #1c1c1e;
    --surface-2:   #2c2c2e;
    --separator:   rgba(84, 84, 88, .48);
    --separator-2: rgba(84, 84, 88, .28);

    --label:       #f5f5f7;
    --label-2:     rgba(235, 235, 245, .60);
    --label-3:     rgba(235, 235, 245, .35);

    --blue:   #0a84ff;  --blue-bg:   rgba(10, 132, 255, .18);
    --green:  #30d158;  --green-bg:  rgba(48, 209, 88, .18);
    --orange: #ff9f0a;  --orange-bg: rgba(255, 159, 10, .18);
    --red:    #ff453a;  --red-bg:    rgba(255, 69, 58, .18);
    --gray-bg:rgba(120, 120, 128, .24);

    --shadow-sm: none;
    --shadow-md: 0 4px 16px rgba(0,0,0,.5);
    --shadow-lg: 0 16px 48px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.47;
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Larghezza piena: su un monitor grande non ha senso incolonnare tutto al
   centro lasciando i lati vuoti. Il respiro lo danno i margini, che crescono
   con la finestra invece di essere fissi. Solo i blocchi di prosa restano
   stretti, perche' li' una riga lunghissima e' davvero illeggibile. */
.wrap { width: 100%; margin: 0; padding: 0 clamp(18px, 2.6vw, 56px); }
main.wrap { padding-top: 32px; padding-bottom: 90px; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ------------------------------------------------------------ intestazione */

.top {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator-2);
}
.top .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; min-height: 52px;
}
.brand {
  font-size: 16px; font-weight: 600; letter-spacing: -.02em;
  color: var(--label); white-space: nowrap;
}
.brand:hover { text-decoration: none; opacity: .7; }

nav { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
nav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--r-pill);
  font-size: 13.5px; font-weight: 500; color: var(--label-2);
  transition: background .18s var(--ease), color .18s var(--ease);
}
nav a:hover { background: var(--gray-bg); color: var(--label); text-decoration: none; }
nav a.on { background: var(--blue-bg); color: var(--blue); font-weight: 600; }
nav a.quiet { color: var(--label-3); }

/* -------------------------------------------------------------- tipografia */

h1 {
  font-size: 30px; font-weight: 700; letter-spacing: -.028em;
  line-height: 1.15; margin: 0 0 22px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
h2 {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--label-3); margin: 0 0 14px;
}
.lead { color: var(--label-2); font-size: 15px; margin: -12px 0 24px; max-width: 68ch; }

.muted { color: var(--label-2); }
.small { font-size: 12.5px; }
.mono {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 12px; word-break: break-all;
}
.num { font-variant-numeric: tabular-nums; }
.bad { color: var(--red); }
.run { color: var(--orange); font-weight: 500; }

/* ------------------------------------------------------------ riepilogo */

/* I riquadri si allargano fino a un limite e poi si fermano, allineati a
   sinistra: stirarli per tutta la larghezza di un monitor da 32" li
   renderebbe sei rettangoli vuoti con un numero perso in mezzo. */
.tiles {
  display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 24px;
}
.tile {
  position: relative; display: block; padding: 18px 18px 16px;
  flex: 1 1 150px; max-width: 240px;
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); color: var(--label);
  border: 1px solid transparent;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease),
              border-color .2s var(--ease);
}
.tile:hover {
  text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-md);
}
.tile.on { border-color: var(--blue); box-shadow: var(--shadow-md); }
.tile .n {
  display: block; font-size: 34px; font-weight: 600; letter-spacing: -.03em;
  line-height: 1.05; font-variant-numeric: tabular-nums;
}
.tile .l {
  display: block; margin-top: 4px; font-size: 13px; color: var(--label-2);
  font-weight: 450;
}
.tile.s-ready  .n { color: var(--green); }
.tile.s-review .n { color: var(--orange); }
.tile.s-error  .n { color: var(--red); }

/* Si stringe sul proprio contenuto invece di diventare una fascia vuota
   larga quanto lo schermo. */
.runline {
  display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap;
  color: var(--label-2); font-size: 13.5px; margin: 0 0 22px;
  padding: 10px 16px; background: var(--surface); border-radius: var(--r-pill);
  box-shadow: var(--shadow-sm);
}

/* ---------------------------------------------------------------- controlli */

input, select, button, textarea {
  font: inherit; letter-spacing: inherit; color: var(--label);
}
input, select {
  padding: 8px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--separator); background: var(--surface);
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
input { min-width: 230px; }
input:focus, select:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3.5px var(--blue-bg);
}
input::placeholder { color: var(--label-3); }

button {
  cursor: pointer; padding: 8px 18px; border-radius: var(--r-pill);
  border: 1px solid var(--separator); background: var(--surface);
  font-size: 14px; font-weight: 500;
  transition: background .16s var(--ease), transform .12s var(--ease),
              opacity .16s var(--ease);
}
button:hover { background: var(--surface-2); }
button:active { transform: scale(.97); }
button.primary {
  background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600;
}
button.primary:hover { background: var(--blue); opacity: .88; }
button.ghost { background: transparent; border-color: transparent; color: var(--label-2); }
button.ghost:hover { background: var(--gray-bg); }
button.danger { color: var(--red); }

.filters { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.count { margin: 0 0 12px; font-size: 13px; color: var(--label-2); }

/* ------------------------------------------------------------------ tabella */

.grid {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.grid th {
  text-align: left; padding: 12px 16px;
  font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--label-3);
  background: var(--surface-2); border-bottom: 1px solid var(--separator-2);
  white-space: nowrap;
}
.grid td {
  padding: 13px 16px; border-bottom: 1px solid var(--separator-2);
  vertical-align: middle;
}
.grid tbody tr:last-child td { border-bottom: 0; }

/* Su uno schermo largo la risposta non e' allargare le colonne fino a
   lasciare voragini, ma mostrare PIU' dati. Queste compaiono solo quando
   c'e' davvero spazio, e sotto quella soglia spariscono senza rompere nulla. */
.wide-only { display: none; }
@media (min-width: 1500px) {
  .wide-only { display: table-cell; }
}
.grid.docs th, .grid.docs td { white-space: nowrap; }
.grid.docs .col-forn { white-space: normal; min-width: 220px; }
.grid tbody tr { cursor: pointer; transition: background .14s var(--ease); }
.grid tbody tr:hover { background: var(--surface-2); }
.grid tbody tr.done { cursor: default; }
.grid tbody tr.done td { opacity: .45; }
.r { text-align: right; font-variant-numeric: tabular-nums; }
.pad { padding: 44px 16px !important; text-align: center; color: var(--label-2); }

/* ------------------------------------------------------------------ badge */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: 11.5px; font-weight: 600; letter-spacing: -.005em;
  background: var(--gray-bg); color: var(--label-2); white-space: nowrap;
}
.badge.s-ready, .badge.s-sent, .badge.ok { background: var(--green-bg); color: var(--green); }
.badge.s-review { background: var(--orange-bg); color: var(--orange); }
.badge.s-error  { background: var(--red-bg);    color: var(--red); }
.badge.s-pending{ background: var(--blue-bg);   color: var(--blue); }

/* ------------------------------------------------------------------ schede */

.card {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: 22px; margin-bottom: 16px;
}
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 16px; }

/* Dettaglio documento: su schermo largo i dati stanno a sinistra e il PDF
   a destra, affiancati e visibili insieme. Sotto i 1180px tornano in colonna. */
.doc-layout { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
@media (min-width: 1180px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr) minmax(460px, 46%); }
  .doc-layout .cols { grid-template-columns: 1fr; }
  .doc-side { position: sticky; top: 74px; }
  .doc-side .pdf { height: calc(100vh - 108px); }
}
@media (min-width: 1700px) {
  .doc-layout .cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

dl { display: grid; grid-template-columns: minmax(118px, auto) 1fr; gap: 11px 20px; margin: 0; }
dt { color: var(--label-2); font-size: 13.5px; }
dd { margin: 0; font-weight: 450; }

.alert, .note {
  padding: 13px 16px; border-radius: var(--r-md); font-size: 14px;
  margin: 0 0 18px;
}
.alert { background: var(--red-bg);    color: var(--red); }
.note  { background: var(--orange-bg); color: var(--orange); }

.actions { display: flex; gap: 10px; margin: 20px 0; flex-wrap: wrap; }

details.card summary {
  cursor: pointer; color: var(--label-2); font-size: 13.5px; font-weight: 500;
  list-style: none;
}
details.card summary::-webkit-details-marker { display: none; }
details.card summary::before { content: "▸ "; color: var(--label-3); }
details.card[open] summary::before { content: "▾ "; }
pre { overflow-x: auto; white-space: pre-wrap; margin: 14px 0 0; color: var(--label-2); }

.pdf {
  width: 100%; height: 800px; border: 1px solid var(--separator);
  border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm);
}

/* ------------------------------------------------------- barra del worker */

.barra-worker {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  flex-wrap: wrap; margin: 0 0 22px; padding: 12px 16px 12px 20px;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.barra-worker.attiva { box-shadow: 0 0 0 1.5px var(--blue), var(--shadow-sm); }
.barra-worker form { margin: 0; }
.barra-worker b { font-weight: 600; }

.spinner {
  display: inline-block; width: 13px; height: 13px; margin-right: 7px;
  vertical-align: -1px; border-radius: 50%;
  border: 2px solid var(--blue-bg); border-top-color: var(--blue);
  animation: gira .8s linear infinite;
}
@keyframes gira { to { transform: rotate(360deg); } }

/* ------------------------------------------------- revisione e anteprima */

.esito-ok {
  padding: 13px 16px; border-radius: var(--r-md); font-size: 14px; margin: 0 0 18px;
  background: var(--green-bg); color: var(--green); font-weight: 500;
}

td.azioni, th.azioni { white-space: nowrap; text-align: right; }
.riga-azioni { display: flex; gap: 7px; justify-content: flex-end; margin: 0; }
.riga-azioni button { padding: 6px 14px; font-size: 13px; }
.riga-azioni button:disabled { opacity: .5; cursor: progress; }

a.peek {
  font-weight: 500; white-space: nowrap;
  border-bottom: 1px dashed currentColor;
}
a.peek::before { content: "📄 "; }

/* L'anteprima galleggia sopra tutto e resta abbastanza grande da leggere
   davvero gli importi: un francobollo non servirebbe a niente. */
#peek {
  position: fixed; z-index: 200; width: min(560px, 46vw); height: min(720px, 78vh);
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); border: 1px solid var(--separator);
  overflow: hidden; display: flex; flex-direction: column;
}
#peek[hidden] { display: none; }
#peek .peek-testa {
  padding: 9px 14px; font-size: 12.5px; font-weight: 600; color: var(--label-2);
  background: var(--surface-2); border-bottom: 1px solid var(--separator-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#peek iframe { flex: 1; width: 100%; border: 0; background: var(--surface-2); }

@media (max-width: 900px) {
  #peek { display: none !important; }   /* senza mouse non ha senso */
}

/* ---------------------------------------------------------------- paginazione */

.pager { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 18px; }
.pager a {
  min-width: 34px; text-align: center; padding: 6px 11px;
  border-radius: var(--r-sm); background: var(--surface);
  color: var(--label-2); font-size: 13.5px; box-shadow: var(--shadow-sm);
}
.pager a:hover { text-decoration: none; background: var(--surface-2); }
.pager a.on { background: var(--blue); color: #fff; font-weight: 600; }

/* --------------------------------------------------------------------- login */

.login {
  max-width: 372px; margin: 8vh auto 0; padding: 34px 32px 30px;
  border-radius: 22px; box-shadow: var(--shadow-lg);
}
.login h1 { justify-content: center; font-size: 25px; margin-bottom: 24px; }
.login label {
  display: block; margin-bottom: 15px;
  font-size: 12.5px; font-weight: 500; color: var(--label-2);
}
.login input { width: 100%; min-width: 0; margin-top: 6px; padding: 11px 13px; }
.login button {
  width: 100%; margin-top: 8px; padding: 11px;
  background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600;
}
.login .alert { text-align: center; }

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  h1 { font-size: 25px; }
  .grid th:nth-child(4), .grid td:nth-child(4) { display: none; }
  dl { grid-template-columns: 1fr; gap: 3px 0; }
  dt { margin-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .tile:hover { transform: none; }
}

/* Collegamenti alle fatture da scaricare (pagina Da verificare) */
.link-fattura {
  display: inline-block; margin-top: 5px; padding: 3px 10px;
  background: var(--blue-bg); border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 500;
}
.link-fattura:hover { text-decoration: none; filter: brightness(.95); }
.link-fattura::before { content: "↗ "; }
.link-fattura .small { margin-left: 5px; }

/* ------------------------------------------------- invio automatico */

.auto-send {
  margin: 0 0 16px; padding: 14px 18px;
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); border: 1.5px solid transparent;
}
.auto-send.on { border-color: var(--green); }
.auto-send-form { display: flex; align-items: center; gap: 14px; margin: 0; flex-wrap: wrap; }
.auto-send-testo { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 2px; }
.auto-send-nota {
  margin: 10px 0 0; padding: 9px 13px; border-radius: var(--r-md);
  background: var(--orange-bg); color: var(--orange); font-size: 13px;
}
.auto-send code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }

/* Interruttore in stile iOS: solo decorativo, il comando è il pulsante. */
.switch {
  position: relative; display: inline-block; width: 46px; height: 28px;
  background: var(--gray-bg); border-radius: 999px; flex: none;
  transition: background .22s var(--ease);
}
.switch.on { background: var(--green); }
.switch span {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .22s var(--ease);
}
.switch.on span { transform: translateX(18px); }

/* ------------------------------------------- finestre SweetAlert2
   Ritocchi per allinearle al resto: angoli morbidi, tipografia di sistema,
   pulsanti a pillola e tema scuro, che la libreria non ha. */

.swal2-popup {
  border-radius: 20px !important;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif !important;
  padding: 26px 24px 22px !important;
  box-shadow: var(--shadow-lg) !important;
  background: var(--surface) !important;
  color: var(--label) !important;
}
.swal2-title { font-size: 20px !important; font-weight: 650 !important; letter-spacing: -.02em !important; color: var(--label) !important; }
.swal2-html-container { font-size: 14.5px !important; color: var(--label-2) !important; line-height: 1.5 !important; }
.swal2-actions { gap: 9px !important; margin-top: 20px !important; }
.swal2-styled {
  border-radius: 980px !important; padding: 9px 22px !important;
  font-size: 14.5px !important; font-weight: 600 !important;
  box-shadow: none !important; transition: opacity .15s;
}
.swal2-styled:focus { box-shadow: 0 0 0 3.5px var(--blue-bg) !important; }
.swal2-confirm { background: var(--blue) !important; }
.swal2-cancel  { background: var(--gray-bg) !important; color: var(--label) !important; }
.swal2-styled:hover { opacity: .88; }
.swal2-icon { margin: 4px auto 18px !important; }

/* avvisi in alto a destra */
.swal2-toast {
  border-radius: 14px !important; box-shadow: var(--shadow-lg) !important;
  background: var(--surface) !important; padding: 12px 16px !important;
}
.swal2-toast .swal2-title { font-size: 14.5px !important; font-weight: 550 !important; }
.swal2-timer-progress-bar { background: var(--blue) !important; }

@media (prefers-color-scheme: dark) {
  .swal2-container .swal2-popup { background: var(--surface-2) !important; }
  .swal2-html-container, .swal2-title { color: var(--label) !important; }
}

/* riga che sta sparendo dopo un'azione */
.grid tbody tr[style*="opacity: 0"] { pointer-events: none; }

/* ------------------------------------------------- selezione multipla */

th.c-spunta, td.c-spunta { width: 42px; padding-right: 0 !important; text-align: center; }
.c-spunta input[type="checkbox"] {
  width: 17px; height: 17px; min-width: 0; margin: 0; padding: 0;
  accent-color: var(--blue); cursor: pointer; vertical-align: middle;
}
.grid tbody tr.scelta { background: var(--blue-bg); }
.grid tbody tr.scelta:hover { background: var(--blue-bg); }

/* Compare in basso solo quando c'è una selezione: finché non serve non
   occupa spazio e non distrae. */
.barra-selezione {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 120; display: flex; align-items: center; gap: 18px;
  padding: 11px 12px 11px 22px; border-radius: 980px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: var(--shadow-lg); border: 1px solid var(--separator);
  animation: sale .22s var(--ease);
}
.barra-selezione[hidden] { display: none; }
@keyframes sale { from { opacity: 0; transform: translate(-50%, 14px); } }
.barra-selezione .conta { font-size: 14px; color: var(--label-2); white-space: nowrap; }
.barra-selezione .conta b { color: var(--label); font-size: 15px; }
.barra-selezione-azioni { display: flex; gap: 8px; }
.barra-selezione button { padding: 7px 16px; font-size: 13.5px; }
.barra-selezione button.danger {
  background: var(--red-bg); border-color: transparent; color: var(--red); font-weight: 600;
}
.barra-selezione button.danger:hover { filter: brightness(.96); }

@media (max-width: 640px) {
  .barra-selezione { left: 12px; right: 12px; transform: none; border-radius: var(--r-lg); }
  @keyframes sale { from { opacity: 0; transform: translateY(14px); } }
}

/* ------------------------------------------------- caricamento manuale */

.zona-rilascio {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 44px 24px; text-align: center; cursor: pointer;
  border: 2px dashed var(--separator); border-radius: var(--r-lg);
  background: var(--surface-2);
  transition: border-color .18s var(--ease), background .18s var(--ease);
}
.zona-rilascio:hover, .zona-rilascio.sopra { border-color: var(--blue); background: var(--blue-bg); }
.zona-rilascio b { font-size: 16px; }
.zona-icona { font-size: 34px; line-height: 1; }
#elenco-file { margin-top: 6px; color: var(--blue); word-break: break-all; max-width: 90%; }
