/* preventivoveloce — mobile first */
:root {
  --ink: #1c2b36;
  --ink-soft: #51626f;
  --paper: #f6f7f4;
  --card: #ffffff;
  --accent: #0e7c66;      /* verde bottega: azioni e conferme */
  --accent-dark: #0a5c4c;
  --amber: #e8a33d;       /* bozze */
  --danger: #c0392b;
  --line: #e2e6e3;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(28,43,54,.08), 0 4px 14px rgba(28,43,54,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, .tile-label, .page-title, .logo-sm, .brand h1 {
  font-family: "Archivo", sans-serif;
}
.hidden { display: none !important; }
.view { max-width: 640px; margin: 0 auto; padding: 0 14px 90px; }

/* ---- auth ---- */
.auth-wrap { padding-top: 12vh; max-width: 400px; margin: 0 auto; }
.brand { text-align: center; margin-bottom: 28px; }
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto 10px;
  background: var(--ink); color: var(--paper);
  font-family: "Archivo"; font-weight: 800; font-size: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 18px; border-bottom: 4px solid var(--accent);
}
.brand h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.tagline { color: var(--ink-soft); margin: 6px 0 0; font-size: 14px; }

.tabs { display: flex; gap: 6px; background: #eceee9; padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tabs.sub { margin: 14px 0; }
.tab {
  flex: 1; border: 0; background: transparent; padding: 10px;
  border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--ink-soft);
}
.tab.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.auth-form, .card label { display: block; }
.auth-form label, .card label {
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
  margin-bottom: 12px;
}
input, select, textarea {
  display: block; width: 100%; margin-top: 5px;
  padding: 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font-family: inherit;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tile:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.btn {
  display: inline-block; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  padding: 12px 16px; border-radius: 11px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  font-family: inherit;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; }
.btn.primary:active { background: var(--accent-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f1d2cd; }
.link { background: none; border: 0; color: var(--accent); font-size: 14px; margin-top: 12px; width: 100%; text-align: center; text-decoration: underline; cursor: pointer; }

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 2px; position: sticky; top: 0; z-index: 5;
  background: var(--paper);
}
.logo-sm { font-weight: 800; font-size: 20px; flex: 1; }
.page-title { font-weight: 700; font-size: 18px; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
  font-size: 19px; cursor: pointer; color: var(--ink);
}
.icon-btn.active { background: var(--ink); color: #fff; }

/* ---- home tiles (elemento firma) ---- */
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.tile {
  position: relative; text-align: left;
  background: var(--card); border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius); padding: 18px 14px;
  min-height: 128px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
  box-shadow: var(--shadow); font-family: inherit;
}
.tile[data-key="archivio"] { border-left-color: var(--amber); }
.tile[data-key="rubrica"] { border-left-color: #3d6fb4; }
.tile[data-key="impostazioni"] { border-left-color: var(--ink-soft); }
.tile-icon { font-size: 26px; }
.tile-label { font-size: 18px; font-weight: 800; }
.tile-sub { font-size: 12.5px; color: var(--ink-soft); }
.reorder-ctrl {
  position: absolute; top: 8px; right: 8px; display: flex; gap: 4px;
}
.reorder-ctrl b {
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  background: var(--ink); color: #fff; border-radius: 8px; font-size: 12px;
}
.reorder-hint { text-align: center; color: var(--ink-soft); font-size: 13px; }
.tile.shake { animation: wob 0.35s ease-in-out infinite alternate; }
@keyframes wob { from { transform: rotate(-0.6deg); } to { transform: rotate(0.6deg); } }
@media (prefers-reduced-motion: reduce) { .tile.shake { animation: none; } }

/* ---- cards ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 14px 0;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 800; }

.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.row-btns .btn { flex: 1; }
.check { display: flex !important; align-items: center; gap: 8px; margin: 12px 0; }
.check input { width: auto; margin: 0; }

.logo-row { display: flex; align-items: center; gap: 14px; }
#logo-preview { max-width: 110px; max-height: 70px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }

.add-item { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; margin: 14px 0; }
.add-item input { margin-top: 0; }
.add-item .btn { grid-column: 1 / -1; }

.search { margin: 10px 0; }

/* ---- liste ---- */
.item-list { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  background: var(--card); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 12px; display: flex; align-items: center; gap: 10px;
}
.item-main { flex: 1; min-width: 0; }
.item-code { font-size: 12px; font-weight: 700; color: var(--accent); }
.item-desc { font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.item-price { font-weight: 700; white-space: nowrap; }
.mini-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  width: 34px; height: 34px; font-size: 15px; cursor: pointer; flex-shrink: 0;
}
.mini-btn.del { color: var(--danger); }

.search-results { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.sr-row {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer;
  font-family: inherit; text-align: left; font-size: 14px; width: 100%;
}
.sr-add { margin-left: auto; color: var(--accent); font-weight: 800; font-size: 20px; }

/* ---- righe preventivo ---- */
.riga {
  border: 1px solid var(--line); border-radius: 11px; padding: 10px; margin-bottom: 8px; background: #fff;
}
.riga-top { display: flex; align-items: baseline; gap: 8px; }
.riga-tot { margin-left: auto; font-weight: 800; }
.riga-ctrl { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 8px; margin-top: 8px; align-items: end; }
.riga-ctrl label { font-size: 11px; margin: 0; }
.riga-ctrl input { padding: 8px; margin-top: 3px; }
.empty { color: var(--ink-soft); font-size: 14px; text-align: center; padding: 10px 0; }

.tot-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-top: 1px dashed var(--line); font-size: 15px; }
.tot-row.grand { font-size: 18px; border-top: 2px solid var(--ink); }
.iva-inline { display: inline-block; width: 62px; padding: 5px 7px; margin: 0 3px; }

.bottom-actions { position: sticky; bottom: 12px; }
.bottom-actions .btn { box-shadow: var(--shadow); }
.sticky-save { position: sticky; bottom: 12px; width: 100%; box-shadow: var(--shadow); }

/* ---- pdf ---- */
.pdf-frame { width: 100%; height: 46vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

/* ---- archivio ---- */
.badge { font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 20px; }
.badge.inviato { background: #e2f2ec; color: var(--accent-dark); }
.badge.bozza { background: #faf0dc; color: #9a6a17; }
.arch-meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

/* ---- cliente box ---- */
.cliente-box { margin-top: 10px; font-size: 14px; color: var(--ink-soft); background: var(--paper); padding: 10px 12px; border-radius: 10px; }
.cliente-box b { color: var(--ink); }

/* ---- toast / loader ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 24px; background: var(--ink); color: #fff;
  padding: 12px 20px; border-radius: 12px; font-size: 14px; z-index: 50;
  max-width: 90%; text-align: center;
}
.toast.err { background: var(--danger); }
.loader {
  position: fixed; inset: 0; background: rgba(246,247,244,.65);
  display: flex; align-items: center; justify-content: center; z-index: 60;
}
.spin {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: rot 0.8s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

@media (min-width: 480px) {
  .add-item { grid-template-columns: 1fr 2fr 1fr auto; }
  .add-item .btn { grid-column: auto; }
}

/* ---- aggiunte v2 ---- */
.hint { font-size: 12.5px; color: var(--ink-soft); margin: -6px 0 12px; line-height: 1.45; }
.check.terms { font-weight: 400; font-size: 13px; }
.check.terms a { color: var(--accent); }
.page-footer { text-align: center; font-size: 12px; color: var(--ink-soft); padding: 26px 0 10px; }
.page-footer a { color: var(--ink-soft); }
.vp-text { font-size: 15px; line-height: 1.5; color: var(--ink); }

.home-brand {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin: 4px 0 12px;
  box-shadow: var(--shadow);
}
.home-brand img { max-height: 48px; max-width: 120px; border-radius: 6px; }
.home-brand-txt { display: flex; flex-direction: column; min-width: 0; }
.home-brand-txt b { font-family: "Archivo"; font-size: 16px; }
.home-brand-txt span { font-size: 12px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; }

.palette { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; padding: 0;
}
.swatch.sel { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.custom-color { display: flex !important; align-items: center; gap: 10px; }
.custom-color input { width: 56px; height: 40px; padding: 2px; margin: 0; }

.toast.ok { background: var(--accent); }

.table-wrap { overflow-x: auto; }
.adm-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.adm-table th, .adm-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.adm-table th { font-size: 12px; color: var(--ink-soft); }
.adm-table td:nth-child(3), .adm-table td:nth-child(4),
.adm-table th:nth-child(3), .adm-table th:nth-child(4) { text-align: right; }

/* ---- aggiunte v3 ---- */
.fb-tab {
  position: fixed; right: 0; top: 46%;
  transform: rotate(180deg); writing-mode: vertical-rl;
  background: var(--ink); color: #fff; border: 0;
  padding: 14px 9px; font-size: 13px; font-weight: 700;
  font-family: "Archivo", sans-serif; letter-spacing: 0.06em;
  border-radius: 0 10px 10px 0; cursor: pointer; z-index: 20;
  box-shadow: var(--shadow);
}
.fb-overlay {
  position: fixed; inset: 0; background: rgba(28,43,54,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 40;
}
.fb-panel {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 18px 16px 26px;
  animation: fbup 0.25s ease-out;
}
@keyframes fbup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .fb-panel { animation: none; } }
.fb-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.fb-head h2 { margin: 0; font-size: 17px; }
.fb-item-txt { font-size: 14px; white-space: pre-wrap; }
@media (min-width: 640px) {
  .fb-overlay { align-items: center; }
  .fb-panel { border-radius: 18px; }
}

.adm-actions { white-space: nowrap; }
.adm-actions .mini-btn { margin-left: 4px; }

/* ---- wizard onboarding ---- */
.wz-progress { display: flex; gap: 8px; justify-content: center; padding: 18px 0 6px; }
.wz-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); transition: all 0.2s; }
.wz-dot.on { background: var(--accent); transform: scale(1.25); }
.wz-hero { text-align: center; padding: 9vh 10px 20px; }
.wz-hero .brand-mark { margin-bottom: 16px; }
.wz-hero h1 { font-size: 26px; margin: 0 0 12px; }
.wz-hero p { color: var(--ink-soft); font-size: 16px; line-height: 1.55; }
.wz-nav { position: sticky; bottom: 12px; margin-top: 14px; }
.wz-nav .btn { box-shadow: var(--shadow); }
.wz-count { font-size: 14px; color: var(--ink-soft); text-align: center; margin: 10px 0 0; }

/* ---- nuovo cliente inline ---- */
.cliente-row { display: flex; gap: 8px; align-items: stretch; }
.cliente-row select { flex: 1; margin-top: 0; }
.btn.new-client { white-space: nowrap; border-color: var(--accent); color: var(--accent); font-size: 14px; }
.nc-form { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }

/* ---- coriandoli ---- */
.confetti-overlay { position: fixed; inset: 0; background: rgba(246,247,244,.92); z-index: 45;
  display: flex; align-items: center; justify-content: center; }
#confetti-box { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece {
  position: absolute; top: -14px; width: 10px; height: 14px; border-radius: 2px;
  animation: cfall linear forwards;
}
@keyframes cfall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0.85; }
}
@media (prefers-reduced-motion: reduce) { .confetti-piece { display: none; } }
.confetti-card { text-align: center; max-width: 420px; padding: 20px; position: relative; }
.confetti-check {
  width: 74px; height: 74px; margin: 0 auto 14px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 38px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.confetti-card h1 { font-size: 26px; margin: 0 0 10px; }
.confetti-card p { color: var(--ink-soft); margin-bottom: 20px; }

/* etichette tile su due righe */
.tile-label { font-size: 16px; line-height: 1.2; }

/* ---- v8: editor logo, selezione listino, wizard list ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(28,43,54,.5);
  display: flex; align-items: center; justify-content: center; z-index: 46; padding: 14px; }
.modal-panel { background: var(--card); border-radius: 16px; padding: 16px;
  width: 100%; max-width: 520px; max-height: 92vh; display: flex; flex-direction: column; gap: 10px; }
.crop-viewport { position: relative; width: 100%; aspect-ratio: 5 / 3; overflow: hidden;
  border-radius: 10px; background: repeating-conic-gradient(#eceee9 0% 25%, #fff 0% 50%) 50% / 20px 20px;
  border: 1px solid var(--line); touch-action: none; cursor: grab; }
.crop-viewport:active { cursor: grabbing; }
#crop-img { position: absolute; top: 0; left: 0; transform-origin: top left;
  user-select: none; pointer-events: none; max-width: none; }
.zoom-row { display: flex !important; align-items: center; gap: 12px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.zoom-row input { flex: 1; margin: 0; padding: 0; accent-color: var(--accent); }
.search-row { display: flex; gap: 8px; align-items: center; }
.search-row .search { flex: 1; margin: 10px 0; }
.icon-btn.lens { font-size: 17px; flex-shrink: 0; }
.pick-list { overflow-y: auto; flex: 1; min-height: 180px; max-height: 52vh;
  display: flex; flex-direction: column; gap: 6px; }
.pick-row { display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-size: 14px; }
.pick-row input { width: 18px; height: 18px; margin: 0; flex-shrink: 0; accent-color: var(--accent); }
.pick-row .item-main { flex: 1; min-width: 0; }

/* ---- v10: rifiniture mobile ---- */
.auth-form .btn.primary { margin-top: 18px; }
.fb-tab { top: auto; bottom: 92px; border-radius: 10px 0 0 10px; transform: none;
  writing-mode: vertical-rl; }
.modal-overlay { overscroll-behavior: contain; }
