/* =====================================================================
   Preventivatore — design system
   Dark base, glass panels, accent ambra/arancio (macchine movimento terra)
   ===================================================================== */

@font-face { font-family: 'Inter'; font-weight: 400; font-display: swap; src: url('../fonts/inter-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 500; font-display: swap; src: url('../fonts/inter-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 600; font-display: swap; src: url('../fonts/inter-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 700; font-display: swap; src: url('../fonts/inter-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Outfit'; font-weight: 600; font-display: swap; src: url('../fonts/outfit-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Outfit'; font-weight: 700; font-display: swap; src: url('../fonts/outfit-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Outfit'; font-weight: 800; font-display: swap; src: url('../fonts/outfit-latin-800-normal.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-weight: 400; font-display: swap; src: url('../fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-weight: 500; font-display: swap; src: url('../fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2'); }

:root {
  --bg: #090c13;
  --bg-2: #0e1320;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-2: rgba(255, 255, 255, 0.08);
  --surface-3: rgba(255, 255, 255, 0.12);
  --surface-solid: #141a28;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e9ecf3;
  --text-2: #b7bdcc;
  --muted: #8790a5;
  --accent: #f5a524;
  --accent-2: #ff6a2b;
  --accent-soft: rgba(245, 165, 36, 0.14);
  --accent-glow: rgba(245, 165, 36, 0.32);
  --blue: #5b8cff;
  --blue-soft: rgba(91, 140, 255, 0.14);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --grad-accent: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  --grad-blue: linear-gradient(135deg, #5b8cff 0%, #8b5cff 100%);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  --shadow-accent: 0 8px 24px -8px var(--accent-glow);
  --font-display: 'Outfit', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sidebar-w: 248px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --inset: rgba(0, 0, 0, 0.22);
  --inset-soft: rgba(0, 0, 0, 0.12);
  --inset-strong: rgba(0, 0, 0, 0.3);
  --chrome: rgba(9, 12, 19, 0.55);
  --chrome-strong: rgba(9, 12, 19, 0.8);
  --backdrop: rgba(3, 5, 10, 0.65);
  --info-text: #a9c1ff;
  --mesh-1: rgba(245, 165, 36, 0.13);
  --mesh-2: rgba(91, 140, 255, 0.14);
  --mesh-3: rgba(255, 106, 43, 0.08);
  color-scheme: dark;
}

/* Tema chiaro: stessi componenti, palette luminosa (scelta salvata sul dispositivo, vedi assets/js/theme.js) */
:root[data-theme="light"] {
  --bg: #f3f5f9;
  --bg-2: #ffffff;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-2: rgba(15, 23, 42, 0.05);
  --surface-3: rgba(15, 23, 42, 0.09);
  --surface-solid: #ffffff;
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.17);
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --accent: #d97706;
  --accent-2: #ea580c;
  --accent-soft: rgba(217, 119, 6, 0.11);
  --accent-glow: rgba(234, 88, 12, 0.24);
  --blue: #2563eb;
  --blue-soft: rgba(37, 99, 235, 0.1);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.1);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.08);
  --warn: #b45309;
  --grad-accent: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  --grad-blue: linear-gradient(135deg, #3b6ef6 0%, #7c4dff 100%);
  --shadow: 0 10px 30px -14px rgba(15, 23, 42, 0.2);
  --inset: rgba(15, 23, 42, 0.035);
  --inset-soft: rgba(15, 23, 42, 0.025);
  --inset-strong: #ffffff;
  --chrome: rgba(255, 255, 255, 0.72);
  --chrome-strong: rgba(255, 255, 255, 0.86);
  --backdrop: rgba(15, 23, 42, 0.35);
  --info-text: #1d4ed8;
  --mesh-1: rgba(245, 158, 11, 0.14);
  --mesh-2: rgba(59, 110, 246, 0.1);
  --mesh-3: rgba(234, 88, 12, 0.06);
  color-scheme: light;
}
:root[data-theme="light"] .pp-final input,
:root[data-theme="light"] .pt-final input { background: #fffaf0; }
:root[data-theme="light"] .badge.warn { background: rgba(180, 83, 9, 0.1); }

/* selettore tema */
.theme-switch { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--inset); border: 1px solid var(--border); }
.theme-switch button { width: 30px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; transition: background .2s ease, color .2s ease, transform .2s ease; }
.theme-switch button:hover { color: var(--text); transform: scale(1.05); }
.theme-switch button.on { background: var(--surface-solid); color: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 600px at 12% -10%, var(--mesh-1), transparent 60%),
    radial-gradient(800px 600px at 105% 10%, var(--mesh-2), transparent 60%),
    radial-gradient(700px 500px at 50% 110%, var(--mesh-3), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -0.02em; margin: 0; line-height: 1.2; }
h1 { font-weight: 800; font-size: 28px; }
h2 { font-weight: 700; font-size: 20px; }
h3 { font-weight: 700; font-size: 16px; }
a { color: var(--accent); text-decoration: none; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.ico { flex: none; display: inline-block; vertical-align: middle; }
::selection { background: var(--accent-soft); }

/* ---------------------------------------------------------------- animazioni */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--accent-glow); } 100% { box-shadow: 0 0 0 10px transparent; } }
@keyframes flash { 0% { color: var(--accent); } 100% { color: inherit; } }
.anim-in { animation: fadeInUp .3s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms); }
.spin { animation: spin 1s linear infinite; }
.flash { animation: flash .6s ease; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------------------------------------------------------- superfici */
.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}
.card { padding: 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { display: flex; align-items: center; gap: 10px; }
.card-head .ico-bubble { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }

/* ---------------------------------------------------------------- pulsanti */
.btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: 600 14px/1 var(--font-body);
  cursor: pointer;
  white-space: nowrap;
  transition: transform .2s ease, filter .2s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:hover { transform: scale(1.02); filter: brightness(1.05); background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: scale(.98); }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--grad-accent); border-color: transparent; color: #1a1205; box-shadow: var(--shadow-accent); }
.btn-primary:hover { background: var(--grad-accent); box-shadow: 0 10px 30px -8px var(--accent-glow); }
.btn-blue { background: var(--grad-blue); border-color: transparent; color: #fff; box-shadow: 0 8px 24px -8px rgba(91, 140, 255, .45); }
.btn-blue:hover { background: var(--grad-blue); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: rgba(248, 113, 113, .35); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text-2);
  cursor: pointer; transition: all .2s ease; -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); transform: scale(1.05); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }

/* ---------------------------------------------------------------- form */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.field small { color: var(--muted); font-size: 12px; }
input, select, textarea {
  width: 100%;
  font: 400 16px/1.4 var(--font-body); /* 16px evita lo zoom automatico su iOS */
  color: var(--text);
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
  -webkit-appearance: none; appearance: none;
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--inset-strong); box-shadow: 0 0 0 3px var(--accent-soft); }
input[readonly] { color: var(--muted); }
textarea { resize: vertical; min-height: 80px; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238790a5' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px;
}
select option { background: var(--surface-solid); color: var(--text); }
input[type="color"] { padding: 4px; height: 42px; cursor: pointer; }
input[type="checkbox"] {
  width: 20px; height: 20px; padding: 0; border-radius: 6px; flex: none; cursor: pointer;
  display: inline-grid; place-items: center; background: var(--inset);
}
input[type="checkbox"]:checked { background: var(--grad-accent); border-color: transparent; }
input[type="checkbox"]:checked::after { content: ''; width: 10px; height: 6px; border: 2.5px solid #1a1205; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.input-money { font-family: var(--font-mono); text-align: right; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-all { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 14px; }
.input-icon { position: relative; }
.input-icon .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon input { padding-left: 40px; }

/* segmented */
.seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--inset); border: 1px solid var(--border); border-radius: 12px; }
.seg button { position: relative; border: 0; background: transparent; color: var(--muted); font: 600 13px var(--font-body); height: 32px; padding: 0 14px; border-radius: 8px; cursor: pointer; transition: color .2s ease; }
.seg button:hover { color: var(--text); }
.seg button.on { color: #1a1205; background: var(--grad-accent); box-shadow: var(--shadow-accent); }

/* ---------------------------------------------------------------- badge */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.acquisto { background: var(--accent-soft); color: var(--accent); }
.badge.noleggio { background: var(--blue-soft); color: var(--blue); }
.badge.bozza { background: var(--surface-2); color: var(--text-2); }
.badge.inviato { background: var(--blue-soft); color: var(--blue); }
.badge.accettato { background: var(--success-soft); color: var(--success); }
.badge.rifiutato { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: rgba(251, 191, 36, .14); color: var(--warn); }
.badge.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-discount { display: inline-flex; align-items: center; justify-content: center; min-width: 74px; height: 30px; padding: 0 10px; border-radius: 8px; font: 600 14px var(--font-mono); background: var(--accent-soft); color: var(--accent); }
.chip-discount.neg { background: var(--danger-soft); color: var(--danger); }
.chip-discount.none { background: var(--surface-2); color: var(--muted); }

/* ---------------------------------------------------------------- layout app */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  padding: 20px 14px;
  border-right: 1px solid var(--border);
  background: var(--chrome);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--grad-accent); color: #1a1205; font: 800 18px var(--font-display); box-shadow: var(--shadow-accent); flex: none; overflow: hidden; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.brand-name { font: 700 15px/1.2 var(--font-display); letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.nav-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding: 14px 10px 6px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px;
  height: 40px; padding: 0 12px; border-radius: 10px;
  color: var(--text-2); font-weight: 500; font-size: 14px;
  transition: background .2s ease, color .2s ease, transform .2s ease;
}
.nav-item:hover { background: var(--surface); color: var(--text); transform: translateX(2px); }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-item.active::before { content: ''; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--grad-accent); }
.nav-item.active .ico { color: var(--accent); }
.sidebar .new-btns { display: grid; gap: 8px; padding: 6px 4px 8px; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--grad-blue); font: 700 13px var(--font-display); color: #fff; flex: none; }

.main { min-width: 0; padding: 28px 32px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: 10px; flex-wrap: wrap; }

.topbar, .tabbar { display: none; }

/* ---------------------------------------------------------------- statistiche */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { padding: 18px 20px; position: relative; overflow: hidden; transition: transform .2s ease, filter .2s ease; }
.stat:hover { transform: scale(1.02); filter: brightness(1.05); }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font: 800 28px/1.2 var(--font-display); letter-spacing: -0.02em; margin-top: 6px; }
.stat .ico-bg { position: absolute; right: -6px; bottom: -10px; opacity: .08; }
.stat.accent .v { background: var(--grad-accent); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------------------------------------------------------------- tabelle */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
table.data th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--bg-2); z-index: 1; }
table.data td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr { transition: background .2s ease, transform .2s ease; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr:hover { background: var(--surface); transform: translateX(2px); }
table.data td.num, table.data th.num { text-align: right; font-family: var(--font-mono); white-space: nowrap; }
table.data .group-row td { background: rgba(245, 165, 36, .06); font: 700 12px var(--font-display); letter-spacing: .06em; text-transform: uppercase; color: var(--accent); padding: 8px 12px; }
table.data .group-row:hover { transform: none; }
table.data tr.inactive td { opacity: .45; }
.cell-actions { display: flex; gap: 4px; justify-content: flex-end; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.list-cards { display: none; }
.q-card { display: block; padding: 16px; color: inherit; transition: transform .2s ease, filter .2s ease; }
.q-card:hover { transform: scale(1.02); filter: brightness(1.05); }
.q-card + .q-card { margin-top: 10px; }
.q-card .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.q-card .cust { font: 700 16px var(--font-display); margin: 8px 0 2px; }
.q-card .bottom { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 10px; }
.q-card .amount { font: 700 18px var(--font-mono); }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .ico { color: var(--accent); opacity: .7; margin-bottom: 10px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .input-icon { flex: 1; min-width: 220px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 18px; padding-bottom: 2px; }

/* ---------------------------------------------------------------- editor preventivo */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 22px; align-items: start; }
.editor-head { position: sticky; top: 0; z-index: 20; margin: -28px -32px 22px; padding: 14px 32px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; background: var(--chrome-strong); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.editor-head .q-num { font: 600 18px var(--font-mono); letter-spacing: -0.01em; }
.editor-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.save-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); min-width: 110px; }
.save-state.ok { color: var(--success); }
.save-state.err { color: var(--danger); }
.save-state.dirty { color: var(--warn); }

.cust-search { position: relative; }
.dropdown {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30;
  background: var(--surface-solid); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow);
  max-height: 320px; overflow-y: auto; padding: 6px; animation: scaleIn .15s var(--ease);
}
.dropdown button { display: block; width: 100%; text-align: left; border: 0; background: transparent; color: var(--text); padding: 10px 12px; border-radius: 8px; cursor: pointer; font: inherit; transition: background .15s ease, transform .15s ease; }
.dropdown button:hover, .dropdown button.hl { background: var(--surface-2); transform: translateX(2px); }
.dropdown .sub { font-size: 12px; color: var(--muted); }

.lines { display: flex; flex-direction: column; gap: 14px; }
.line { padding: 18px; position: relative; transition: border-color .2s ease; }
.line:hover { border-color: var(--border-strong); }
.line-head { display: flex; align-items: flex-start; gap: 12px; }
.line-idx { width: 30px; height: 30px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; font: 600 12px var(--font-mono); color: var(--muted); flex: none; }
.line-title { font: 700 20px/1.2 var(--font-display); letter-spacing: -0.02em; }
.line-title.mono { font-family: var(--font-mono); font-weight: 600; font-size: 18px; }
.line-cat { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.line-desc { margin-top: 10px; }
.line-desc textarea { min-height: 60px; font-size: 14px; color: var(--text-2); }
.line-tools { display: flex; gap: 2px; margin-left: auto; }

.opts-box { margin-top: 14px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.opts-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 10px 14px; background: var(--inset); flex-wrap: wrap; }
.opts-head .label { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.opt { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--border); cursor: pointer; transition: background .15s ease, transform .15s ease; }
.opt:hover { background: var(--surface); transform: translateX(2px); }
.opt.on { background: rgba(245, 165, 36, .06); }
.opt .name { font-size: 14px; font-weight: 500; }
.opt .name .grp { font: 500 11px var(--font-mono); color: var(--muted); margin-left: 6px; }
.opt .price { font: 500 13px var(--font-mono); color: var(--text-2); white-space: nowrap; }
.opt .qty-mini { display: flex; align-items: center; gap: 2px; }
.opt-group-title { padding: 8px 14px; font: 700 11px var(--font-mono); letter-spacing: .06em; color: var(--accent); background: var(--inset-soft); border-top: 1px solid var(--border); }
.opt-custom { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); }

.qty { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--inset); }
.qty button { width: 34px; height: 38px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; display: grid; place-items: center; transition: background .15s ease; }
.qty button:hover { background: var(--surface-2); color: var(--text); }
.qty input { width: 54px; height: 38px; border: 0; border-radius: 0; text-align: center; padding: 0 4px; background: transparent; font-family: var(--font-mono); }
.qty input:focus { box-shadow: none; }
.qty.sm button { width: 28px; height: 30px; }
.qty.sm input { width: 40px; height: 30px; font-size: 14px; }

.price-panel {
  margin-top: 14px; display: grid; gap: 14px; align-items: end;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) auto minmax(0, 1fr);
  padding: 14px; border-radius: 12px; background: var(--inset); border: 1px solid var(--border);
}
.price-panel.rental { grid-template-columns: minmax(0, 1.4fr) minmax(0, .8fr) minmax(0, 1fr) minmax(0, 1.25fr) auto; }
.pp-k { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.pp-list { font: 500 17px var(--font-mono); color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(248,113,113,.7); text-decoration-thickness: 2px; white-space: nowrap; height: 44px; display: flex; align-items: center; }
.pp-list.nostrike { text-decoration: none; }
.pp-final input { height: 44px; font: 600 18px var(--font-mono); text-align: right; border-color: rgba(245,165,36,.45); background: rgba(245,165,36,.07); }
.pp-final input:focus { box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-accent); }
.pp-total { font: 700 19px var(--font-mono); white-space: nowrap; height: 44px; display: flex; align-items: center; justify-content: flex-end; }
.pp-disc { height: 44px; display: flex; align-items: center; }
.pp-hint { grid-column: 1 / -1; display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: -4px; }
.pp-hint button { border: 0; background: none; color: var(--accent); font: 600 12px var(--font-body); cursor: pointer; padding: 0; }
.pp-hint .warn { color: var(--warn); display: inline-flex; gap: 6px; align-items: center; }
.pp-hint .bad { color: var(--danger); display: inline-flex; gap: 6px; align-items: center; }
/* tabella prezzi della macchina configurata: una riga per prodotto, ognuno con il proprio sconto */
.ptable { margin-top: 14px; border-radius: 12px; background: var(--inset); border: 1px solid var(--border); overflow: hidden; }
.pt-row { display: grid; grid-template-columns: minmax(0, 1.3fr) 96px minmax(100px, 1fr) minmax(112px, 1fr) 70px minmax(108px, 1fr); gap: 10px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--border); transition: background .15s ease; }
.pt-row:hover { background: var(--surface); }
.pt-row.pt-head { border-top: 0; padding-top: 10px; padding-bottom: 6px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.pt-row.pt-head:hover { background: transparent; }
.pt-row.pt-head span:nth-child(n+3) { text-align: right; }
.pt-name { font-size: 14px; font-weight: 500; }
.pt-row.base .pt-name { font-weight: 700; font-family: var(--font-display); font-size: 15px; }
.pt-listcell { text-align: right; }
.pt-list { font: 500 13px var(--font-mono); color: var(--muted); white-space: nowrap; text-decoration: line-through; text-decoration-color: rgba(248,113,113,.7); text-decoration-thickness: 2px; }
.pt-list.nostrike { text-decoration: none; }
.pt-final input { height: 38px; font: 600 14px var(--font-mono); text-align: right; border-color: rgba(245,165,36,.45); background: rgba(245,165,36,.07); padding: 6px 10px; }
.pt-disc { text-align: right; }
.pt-disc .chip-discount { min-width: 0; height: 26px; padding: 0 7px; font-size: 12px; }
.pt-tot { font: 600 14px var(--font-mono); text-align: right; white-space: nowrap; }
.pt-foot { display: flex; align-items: flex-end; gap: 14px; padding: 12px 14px; border-top: 1px solid var(--border-strong); background: var(--inset-soft); flex-wrap: wrap; }
.ptable .pp-hint { padding: 0 14px 12px; margin-top: 0; }

.line-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-top: 14px; align-items: end; }

.add-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.add-bar .btn { border-style: dashed; }

.summary { position: sticky; top: 90px; padding: 20px; }
.summary h3 { margin-bottom: 14px; }
.sum-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; font-size: 14px; }
.sum-row .v { font-family: var(--font-mono); white-space: nowrap; }
.sum-row.list .v { text-decoration: line-through; color: var(--muted); }
.sum-row.save .v { color: var(--accent); }
.sum-row.sep { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; }
.sum-total { margin-top: 12px; padding: 16px; border-radius: 14px; background: var(--grad-accent); color: #1a1205; box-shadow: var(--shadow-accent); }
.sum-total .k { font: 700 12px var(--font-body); text-transform: uppercase; letter-spacing: .08em; opacity: .75; }
.sum-total .v { font: 800 28px/1.2 var(--font-display); letter-spacing: -0.02em; }
.summary .actions { display: grid; gap: 8px; margin-top: 16px; }
.mobile-sum { display: none; }

/* ---------------------------------------------------------------- modal / toast */
.modal-back { position: fixed; inset: 0; z-index: 100; background: var(--backdrop); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fadeIn .2s ease; }
.modal { width: 100%; max-width: 640px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--surface-solid); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: 0 30px 80px -20px rgba(0,0,0,.8); animation: scaleIn .22s var(--ease); }
.modal.wide { max-width: 980px; }
.modal.full { max-width: 1100px; height: calc(100vh - 40px); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; font-size: 18px; }
.modal-body { padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.modal-body.flush { padding: 0; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pdf-viewer { min-height: 100%; background: #3a3f4b; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.pdf-viewer .loader { min-height: 60vh; color: #e9ecf3; }
.pdf-viewer iframe { flex: 1; min-height: 70vh; width: 100%; }
.pdf-page { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pdf-page canvas { display: block; background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.45); border-radius: 2px; }
.pdf-page-label { font-size: 11px; color: #c9ced9; letter-spacing: .04em; }
.modal iframe { width: 100%; height: 100%; border: 0; background: #e9ecf1; display: block; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

.pick-list { display: flex; flex-direction: column; }
.pick-group { padding: 10px 20px 6px; font: 700 11px var(--font-display); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); position: sticky; top: 0; background: var(--surface-solid); z-index: 1; }
.pick { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 20px; border: 0; border-top: 1px solid var(--border); background: transparent; color: var(--text); text-align: left; cursor: pointer; font: inherit; transition: background .15s ease, transform .15s ease; }
.pick:hover { background: var(--surface); transform: translateX(2px); }
.pick .t { font: 600 15px var(--font-mono); }
.pick .d { font-size: 13px; color: var(--muted); }
.pick .p { text-align: right; font: 500 14px var(--font-mono); white-space: nowrap; }
.pick .p small { display: block; color: var(--muted); font-size: 11px; font-family: var(--font-body); }

.toasts { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 420px; padding: 12px 16px; border-radius: 12px; background: var(--surface-solid); border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-size: 14px; animation: fadeInUp .3s var(--ease); }
.toast.ok .ico { color: var(--success); }
.toast.err .ico { color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(10px); transition: all .3s ease; }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin: 12px 0; border: 1px solid; }
.alert.ok { background: var(--success-soft); color: var(--success); border-color: rgba(52,211,153,.3); }
.alert.ko { background: var(--danger-soft); color: var(--danger); border-color: rgba(248,113,113,.3); }
.alert.info { background: var(--blue-soft); color: var(--info-text); border-color: rgba(91,140,255,.3); }
.check-list { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 8px; font-size: 14px; }
.check-list li { display: flex; align-items: center; gap: 10px; }
.check-list li::before { content: ''; width: 18px; height: 18px; border-radius: 50%; flex: none; }
.check-list li.ok::before { background: var(--success-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2334d399' stroke-width='3'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center no-repeat; }
.check-list li.ko::before { background: var(--danger-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23f87171' stroke-width='3'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E") center no-repeat; }

/* ---------------------------------------------------------------- invio email */
.attach { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font: 500 13px var(--font-mono); }
.mail-history { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); display: grid; gap: 8px; }
.mh-row { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text-2); }
.mh-row .ico { color: var(--blue); margin-top: 3px; }

/* ---------------------------------------------------------------- credito sviluppatore */
.credit { margin: 22px 0 0; text-align: center; font-size: 11px; letter-spacing: .04em; color: var(--muted); opacity: .75; }
.sidebar-credit { margin: 10px 4px 0; text-align: left; font-size: 10.5px; line-height: 1.4; }

/* ---------------------------------------------------------------- login */
.auth-body { display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 420px; padding: 32px; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.auth-brand h1 { font-size: 24px; }
.auth-brand p { margin: 2px 0 0; }
.auth-card form { display: grid; gap: 14px; }

.logo-box { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo-preview { width: 180px; height: 80px; border-radius: 12px; background: #fff; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--border); }
.logo-preview img { max-width: 90%; max-height: 90%; }
.logo-preview.empty { background: var(--inset); color: var(--muted); font-size: 12px; }

.loader { display: grid; place-items: center; min-height: 50vh; color: var(--muted); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1280px) {
  .editor { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 1100px) {
  :root { --sidebar-w: 76px; }
  .sidebar { padding: 16px 10px; align-items: center; }
  .brand { padding: 4px 0 14px; }
  .brand-text, .nav-item span, .nav-label, .sidebar .new-btns .btn span, .user-chip .who, .sidebar-credit, .sidebar .theme-switch { display: none; }
  .nav-item { width: 48px; justify-content: center; padding: 0; }
  .nav-item.active::before { left: -10px; }
  .sidebar .new-btns { padding: 6px 0; }
  .sidebar .new-btns .btn { width: 48px; padding: 0; }
  .main { padding: 24px 22px 60px; }
  .editor-head { margin: -24px -22px 18px; padding: 12px 22px; }
  .editor { grid-template-columns: minmax(0, 1fr); }
  .summary { display: none; }
  .mobile-sum {
    display: flex; position: sticky; bottom: 12px; z-index: 25; margin-top: 18px;
    align-items: center; gap: 12px; padding: 12px 14px 12px 18px;
  }
  .mobile-sum .tot { font: 800 22px/1.1 var(--font-display); }
  .mobile-sum .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hide-md { display: none; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .app { display: block; }
  .sidebar { display: none; }
  .topbar {
    display: flex; position: sticky; top: 0; z-index: 40; align-items: center; gap: 10px;
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
    background: var(--chrome-strong); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
  }
  .topbar .t { font: 700 17px var(--font-display); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 6px 6px calc(6px + var(--safe-bottom));
    background: var(--chrome-strong); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 10.5px; color: var(--muted); border-radius: 10px; transition: color .2s ease, transform .2s ease; }
  .tabbar a.active { color: var(--accent); }
  .tabbar a:active { transform: scale(.94); }
  .tabbar .plus { width: 46px; height: 46px; margin-top: -18px; border-radius: 16px; display: grid; place-items: center; background: var(--grad-accent); color: #1a1205; box-shadow: var(--shadow-accent); }
  .main { padding: 16px 16px calc(96px + var(--safe-bottom)); }
  .page-head { margin-bottom: 16px; }
  .page-head h1 { font-size: 24px; }
  h1 { font-size: 24px; }
  .card { padding: 16px; }
  .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid.keep-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2, .span-3 { grid-column: auto; }
  .form-grid.keep-2 .span-2 { grid-column: span 2; }
  .stats { gap: 10px; }
  .stat { padding: 14px; }
  .stat .v { font-size: 22px; }
  .table-desktop { display: none; }
  .list-cards { display: block; }
  .editor-head { margin: -16px -16px 16px; padding: 10px 16px; top: calc(env(safe-area-inset-top, 0px) + 57px); }
  .editor-head .q-num { font-size: 15px; }
  .editor-head .actions .btn span { display: none; }
  .editor-head .actions .btn { width: 40px; padding: 0; }
  .save-state { min-width: 0; }
  .save-state span { display: none; }
  .line { padding: 14px; }
  .line-title { font-size: 18px; }
  .price-panel, .price-panel.rental { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pp-final { grid-column: span 2; order: -1; }
  .price-panel.rental .pp-final { order: 0; }
  .pp-total { justify-content: flex-start; }
  .opt { grid-template-columns: 24px minmax(0, 1fr) auto; }
  .opt .qty-mini { grid-column: 2 / -1; justify-self: start; }
  .opt-custom { grid-template-columns: minmax(0, 1fr) 120px auto; }
  .mobile-sum { bottom: calc(76px + var(--safe-bottom)); }
  .pt-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; padding: 12px 14px; }
  .pt-row.pt-head { display: none; }
  .pt-name { grid-column: 1 / -1; }
  .pt-row > [data-label]::before { content: attr(data-label); display: block; font: 600 10px var(--font-body); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; text-decoration: none; }
  .pt-listcell, .pt-disc, .pt-tot { text-align: left; }
  .modal-back { padding: 0; align-items: flex-end; }
  .modal, .modal.full { max-height: calc(100vh - 30px); border-radius: 20px 20px 0 0; padding-bottom: var(--safe-bottom); }
  .modal.full { height: calc(100vh - 30px); }
  .toasts { left: 16px; right: 16px; bottom: calc(86px + var(--safe-bottom)); }
  .modal-foot [data-info], .modal-foot .btn-ghost[data-close] { display: none; }
  .pdf-viewer { padding: 10px 8px; }
  .toast { max-width: none; }
}
