/* Stampa documenti — stile Panta Rei (stessa palette dell'app del menu).
   Mobile-first: si usa quasi sempre dal telefono. */

@font-face {
  font-family: 'Montserrat';
  src: url('../assets/fonts/Montserrat.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --brand: #00b7cd;
  --brand-strong: #0a95a8;
  --brand-100: #bde9ef;
  --brand-50: #e2f5f8;

  --n0: #ffffff;
  --n25: #f8f5ef;
  --n50: #f1ece2;
  --n100: #e7e0d3;
  --n200: #d8cfbe;
  --n400: #948a78;
  --n500: #6a6154;
  --n600: #4a4438;
  --n900: #141414;

  --verde: #4f8a2a;
  --verde-bg: #eaf1de;
  --giallo: #9a6a12;
  --giallo-bg: #fbf0da;
  --rosso: #b8382c;
  --rosso-bg: #fae3e0;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-full: 999px;
  --shadow-card: 0 1px 2px rgba(20, 20, 20, 0.04), 0 6px 20px rgba(20, 20, 20, 0.05);
  --shadow-pop: 0 18px 50px rgba(20, 20, 20, 0.16);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--n25);
  color: var(--n900);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* ===== Pulsanti ===== */
.btn {
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--tap);
  padding: 0 1.25rem;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.1s var(--ease), opacity 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--brand-strong); color: var(--n0); }
.btn-primary:hover:not(:disabled) { background: #087f8f; }
.btn-ghost { background: transparent; border-color: var(--n200); }
.btn-ghost:hover:not(:disabled) { background: var(--n50); }
.btn-sm { min-height: 36px; padding: 0 0.9rem; font-size: 0.85rem; }
.btn-full { width: 100%; }

/* ===== Card ===== */
.card {
  background: var(--n0);
  border: 1px solid var(--n100);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.25rem;
}
.card-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 1rem; }

/* ===== Login ===== */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.5rem 1rem;
}
.brand-logo { height: 40px; width: auto; display: block; }
.brand-logo-lg { height: 72px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 1rem; }
.login-card h1 { font-size: 1.5rem; }
.subtitle { color: var(--n500); margin-top: -0.75rem; }
.login-footer { color: var(--n400); font-size: 0.8rem; }

.field { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.9rem; }
.field input {
  width: 100%;
  /* 16px: sotto questa misura iPhone fa zoom sul campo */
  font-size: 16px;
  min-height: var(--tap);
  padding: 0 0.9rem;
  border: 1px solid var(--n200);
  border-radius: var(--radius-sm);
  background: var(--n0);
  font-size: 1rem;
  font-weight: 500;
}
.field input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-50); }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 5.5rem; }
.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  min-height: 36px;
  padding: 0 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--n50);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.form-error { background: var(--rosso-bg); color: var(--rosso); border-radius: var(--radius-sm); padding: 0.6rem 0.8rem; font-size: 0.9rem; }

/* ===== App ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  padding-top: max(0.6rem, env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--n100);
}
.header-brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.header-brand .brand-logo { height: 32px; }
.header-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.user-badge { font-size: 0.8rem; color: var(--n500); max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem calc(2rem + var(--safe-bottom));
  display: grid;
  gap: 1rem;
}

/* Stato stampanti: una riga per stampante, colore = stato */
.printers { display: grid; gap: 0.5rem; }
.printer-status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "icon title pill" "icon text text";
  align-items: center;
  column-gap: 0.75rem;
  row-gap: 0.15rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--n100);
  border-radius: var(--radius-md);
  background: var(--n0);
  box-shadow: var(--shadow-card);
}
.printer-icon { grid-area: icon; align-self: start; position: relative; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--n50); color: var(--n500); }
.printer-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.printer-icon .dot { position: absolute; right: -3px; top: -3px; width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--n0); background: var(--n400); }
.printer-lines { display: contents; }
.printer-title { grid-area: title; font-size: 0.95rem; line-height: 1.3; }
.printer-text { grid-area: text; font-size: 0.8rem; color: var(--n500); line-height: 1.35; }
.printer-pill { grid-area: pill; justify-self: end; padding: 0.25rem 0.65rem; border-radius: var(--radius-full); font-size: 0.75rem; font-weight: 700; white-space: nowrap; background: var(--n50); color: var(--n600); }

.printer-status.is-on .printer-icon { background: var(--verde-bg); color: var(--verde); }
.printer-status.is-on .dot { background: var(--verde); animation: pulse 2.4s var(--ease) infinite; }
.printer-status.is-on .printer-pill { background: var(--verde-bg); color: var(--verde); }
.printer-status.is-warn { border-color: #f0d49c; }
.printer-status.is-warn .printer-icon, .printer-status.is-warn .printer-pill { background: var(--giallo-bg); color: var(--giallo); }
.printer-status.is-warn .dot { background: #e7a93a; }
.printer-status.is-off { border-color: #f0bdb6; }
.printer-status.is-off .printer-icon, .printer-status.is-off .printer-pill { background: var(--rosso-bg); color: var(--rosso); }
.printer-status.is-off .dot { background: var(--rosso); }
.printer-status.is-pc-off .dot { background: var(--n400); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(79, 138, 42, 0.45); } 50% { box-shadow: 0 0 0 5px rgba(79, 138, 42, 0); } }

/* Scelta della stampante (solo se sono piu' d'una) */
.printer-choice { border: none; margin-bottom: 1rem; }
.printer-choice legend { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.4rem; }
.printer-options { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.printer-option { position: relative; flex: 1 1 140px; }
.printer-option input { position: absolute; opacity: 0; inset: 0; }
.printer-option span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: var(--tap); padding: 0.4rem 0.8rem;
  border: 2px solid var(--n200); border-radius: var(--radius-md);
  font-weight: 600; font-size: 0.9rem; cursor: pointer;
}
.printer-option input:checked + span { border-color: var(--brand-strong); background: var(--brand-50); color: var(--brand-strong); }
.printer-option input:focus-visible + span { outline: 3px solid var(--brand); outline-offset: 2px; }

/* Area di caricamento */
.drop-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 1.75rem 1rem;
  border: 2px dashed var(--brand-100);
  border-radius: var(--radius-md);
  background: var(--brand-50);
  color: var(--brand-strong);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.drop-zone:hover, .drop-zone.is-over { border-color: var(--brand); background: #d3f0f5; }
.drop-zone:focus-within { outline: 3px solid var(--brand); outline-offset: 2px; }
.drop-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-zone svg { width: 36px; height: 36px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.drop-zone strong { font-size: 1.05rem; }
.drop-hint { color: var(--n500); font-size: 0.85rem; }

.pickers { display: grid; gap: 0.6rem; }
/* La fotocamera ha senso solo su telefono/tablet (dito, non mouse) */
.camera-btn { display: none; }
@media (pointer: coarse) {
  .camera-btn {
    position: relative;
    display: flex; align-items: center; justify-content: center; gap: 0.6rem;
    min-height: 52px;
    border: 1px solid var(--brand-100); border-radius: var(--radius-md);
    background: var(--n0); color: var(--brand-strong);
    font-weight: 700;
  }
  .camera-btn input { position: absolute; inset: 0; opacity: 0; }
  .camera-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .drop-zone { padding: 1.4rem 1rem; }
}

/* Elenchi */
.file-list, .job-list { list-style: none; display: grid; gap: 0.5rem; }
.file-list:not(:empty) { margin-top: 1rem; }

.file-item, .job-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--n100);
  border-radius: var(--radius-md);
  background: var(--n0);
}
.file-item.has-error { border-color: var(--rosso); background: var(--rosso-bg); }
.file-info { display: grid; gap: 0.15rem; min-width: 0; }
.file-name {
  font-weight: 600; font-size: 0.92rem; line-height: 1.3;
  overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.file-meta { font-size: 0.8rem; color: var(--n500); }
.has-error .file-meta { color: var(--rosso); font-weight: 600; }

.progress { display: block; height: 4px; margin-top: 0.3rem; border-radius: var(--radius-full); background: var(--n100); overflow: hidden; }
.progress-bar { display: block; width: 0; height: 100%; background: var(--brand); transition: width 0.2s linear; }

.copies { display: flex; align-items: center; border: 1px solid var(--n200); border-radius: var(--radius-full); overflow: hidden; }
.step { width: 44px; height: 44px; touch-action: manipulation; border: none; background: var(--n50); font-size: 1.2rem; font-weight: 600; cursor: pointer; }
.step:hover:not(:disabled) { background: var(--n100); }
.copies-input { width: 46px; height: 44px; font-size: 1rem; border: none; text-align: center; font-weight: 700; -moz-appearance: textfield; appearance: textfield; }
.copies-input::-webkit-outer-spin-button, .copies-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.remove { width: 44px; height: 44px; touch-action: manipulation; border: none; border-radius: 50%; background: transparent; font-size: 1.4rem; line-height: 1; color: var(--n500); cursor: pointer; }
.remove:hover:not(:disabled) { background: var(--n50); color: var(--rosso); }

.print-bar { margin-top: 1rem; }
.btn-print { min-height: 56px; font-size: 1.05rem; }
/* Sul telefono, con file in lista, il pulsante resta a portata di pollice */
@media (max-width: 639px) {
  .has-pending .print-bar {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 1rem -1.25rem -1.25rem;
    padding: 0.75rem 1.25rem calc(0.75rem + var(--safe-bottom));
    background: linear-gradient(to top, var(--n0) 75%, rgba(255, 255, 255, 0));
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }
  .has-pending .toast { bottom: calc(6.75rem + var(--safe-bottom)); }
}

.job-item { grid-template-columns: minmax(0, 1fr) auto; }
.job-item .cancel:not([hidden]) { grid-column: 1 / -1; justify-self: end; }
.badge { padding: 0.25rem 0.65rem; border-radius: var(--radius-full); font-size: 0.75rem; font-weight: 700; white-space: nowrap; background: var(--n50); color: var(--n600); }
.badge[data-status="pending"] { background: var(--giallo-bg); color: var(--giallo); }
.badge[data-status="printing"] { background: var(--brand-50); color: var(--brand-strong); }
.badge[data-status="done"] { background: var(--verde-bg); color: var(--verde); }
.badge[data-status="failed"], .badge[data-status="expired"] { background: var(--rosso-bg); color: var(--rosso); }
.empty { color: var(--n400); font-size: 0.9rem; }

/* Messaggi */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 20;
  width: min(92vw, 480px);
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  font-weight: 600;
  font-size: 0.92rem;
  animation: toast-in 0.25s var(--ease);
}
.toast.success { background: var(--n900); color: var(--n0); }
.toast.error { background: var(--rosso); color: var(--n0); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (min-width: 640px) {
  .card { padding: 1.5rem; }
  .job-item { grid-template-columns: minmax(0, 1fr) auto auto; }
  .job-item .cancel:not([hidden]) { grid-column: auto; }
}

@media (max-width: 380px) {
  .header-title { display: none; }
  .file-item { grid-template-columns: minmax(0, 1fr) auto; }
  .file-item .copies { grid-row: 2; grid-column: 1; justify-self: start; }
  .file-item .remove { grid-row: 1; grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
