:root {
  color-scheme: light;
  --ink: #181715;
  --muted: #66625e;
  --line: #d4d0ca;
  --paper: #fffefa;
  --surface: #f8f7f4;
  --brand: #191917;
  --accent: #b8893f;
  --danger: #981820;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--surface); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  color: white;
  background: var(--brand);
  box-shadow: 0 4px 18px rgb(16 16 16 / 18%);
}
.brand, .header-actions, .toolbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand img { width: 98px; height: 47px; object-fit: contain; filter: brightness(0) invert(1); }
.brand div { display: grid; gap: 2px; }
.brand span, .sync-status { color: #cbc8c4; font-size: 12px; }
.button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 750;
}
.button.primary { color: white; background: var(--accent); }
.button.secondary { color: var(--ink); background: white; border-color: var(--line); }
.app-header .button.secondary { color: white; background: transparent; border-color: #ffffff45; }
.button.danger-text { color: var(--danger); background: transparent; }
.sync-status {
  padding: 6px 9px;
  border: 1px solid #ffffff35;
  border-radius: 99px;
}
.sync-status.online { color: white; border-color: #ffffff65; background: #ffffff12; }
.embedded-mode .app-header { display: none; }
.embedded-mode .app-shell { min-height: 100vh; }
.embedded-mode .archive { top: 0; height: 100vh; }
.app-shell { display: grid; grid-template-columns: 320px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.archive {
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--paper);
}
.archive-heading, .workspace-toolbar, .line-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.eyebrow, .section-kicker {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .1em;
  text-transform: uppercase;
}
h1, h2, h3 { margin: 0; }
h1 { font-size: 23px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
.counter { min-width: 32px; padding: 5px 9px; border-radius: 99px; text-align: center; background: #eeece7; font-weight: 850; }
.search { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; background: white; }
.quote-list { display: grid; gap: 8px; overflow-y: auto; padding-right: 3px; }
.quote-card {
  width: 100%;
  padding: 12px;
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  text-align: left;
  color: var(--ink);
  background: white;
}
.quote-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px #b8893f30; }
.quote-card span { color: var(--muted); font-size: 12px; }
.empty-state { padding: 22px 10px; text-align: center; color: var(--muted); font-size: 13px; }
.workspace { min-width: 0; padding: 22px; }
.workspace-toolbar {
  max-width: 1180px;
  margin: 0 auto 16px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  box-shadow: 0 8px 28px rgb(30 27 24 / 7%);
}
.quote-page {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 34px;
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 0 12px 36px rgb(30 27 24 / 8%);
}
.document-masthead {
  display: grid;
  grid-template-columns: 92px 1fr minmax(220px, auto);
  align-items: center;
  gap: 24px;
  padding: 18px 20px;
  color: white;
  background: var(--brand);
}
.document-masthead div { display: grid; gap: 4px; }
.document-logo img { width: 86px; height: auto; display: block; background: white; }
.document-masthead strong { font-size: 20px; }
.document-masthead span { color: #d9d6d0; font-size: 12px; }
.document-title { text-transform: uppercase; }
.document-company { text-align: right; }
label { display: grid; gap: 6px; font-size: 12px; font-weight: 760; letter-spacing: .025em; text-transform: uppercase; }
input, textarea, select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: white;
  letter-spacing: normal;
  text-transform: none;
}
textarea { resize: vertical; line-height: 1.4; }
.form-grid, .document-info, .parties, .signature-row, .totals { display: grid; gap: 14px; }
.form-grid.top { grid-template-columns: 1fr 1fr .7fr .7fr; }
.parties { grid-template-columns: 1fr; }
.signature-row, .totals { grid-template-columns: 1fr 1fr; }
.parties section { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.company-static strong { font-size: 18px; }
.company-static span:not(.section-kicker) { color: var(--muted); font-size: 13px; line-height: 1.35; }
.text-button { border: 0; color: var(--brand); background: transparent; font-size: 12px; font-weight: 850; }
.quote-table { display: grid; border: 1px solid var(--line); border-bottom: 0; background: white; }
.quote-table-head {
  display: grid;
  grid-template-columns: 38px minmax(240px, 1fr) 74px 74px 74px 74px 112px 104px 108px 34px;
  gap: 8px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.price-list-mode .quote-table-head {
  grid-template-columns: 42px minmax(260px, 1fr) 150px 34px;
}
.price-list-mode .quote-table-head span:nth-child(n+3):nth-child(-n+7),
.price-list-mode .quote-table-head span:nth-child(9) {
  display: none;
}
.price-list-mode .quote-table-head span:nth-child(8)::before { content: "Prezzo"; }
.price-list-mode .quote-table-head span:nth-child(8) { font-size: 0; }
.price-list-mode .quote-table-head span:nth-child(8)::before { font-size: 10px; }
.quote-line-list { display: grid; }
.output-empty-line { display: none !important; }
.quote-line {
  display: grid;
  grid-template-columns: 38px minmax(240px, 1fr) 74px 74px 74px 74px 112px 104px 108px 34px;
  gap: 8px;
  align-items: start;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}
.price-list-mode .quote-line {
  grid-template-columns: 42px minmax(260px, 1fr) 150px 34px;
}
.price-list-mode .quote-line [data-field="quantity"],
.price-list-mode .quote-line [data-field="thickness"],
.price-list-mode .quote-line [data-field="width"],
.price-list-mode .quote-line [data-field="length"],
.price-list-mode .quote-line [data-field="cubicMeters"],
.price-list-mode .quote-line [data-field="total"],
.price-list-mode .total-box {
  display: none;
}
.price-list-mode .totals { grid-template-columns: 1fr; }
.line-number { padding-top: 9px; font-size: 12px; font-weight: 850; }
.quote-line textarea { min-height: 78px; }
.remove-line { width: 32px; height: 32px; border: 0; border-radius: 6px; color: var(--danger); background: #fff0f1; font-size: 20px; }
.total-box {
  align-self: end;
  justify-self: end;
  min-width: 280px;
  padding: 18px;
  display: grid;
  gap: 8px;
  border: 1px solid var(--ink);
  background: white;
  text-align: right;
}
.total-box span { color: var(--muted); font-size: 11px; font-weight: 850; letter-spacing: .08em; }
.total-box strong { font-size: 26px; }
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  padding: 11px 15px;
  border-radius: 8px;
  color: white;
  background: var(--brand);
  opacity: 0;
  transform: translateY(8px);
  transition: .2s ease;
  pointer-events: none;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.auth-dialog { width: min(440px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 12px; color: var(--ink); background: white; }
.auth-dialog::backdrop { background: rgb(16 16 16 / 58%); }
.auth-dialog form { display: grid; gap: 16px; padding: 24px; }
.auth-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-close { border: 0; color: var(--muted); background: transparent; font-size: 28px; }
.auth-feedback { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }
.pdf-export-host { position: fixed; z-index: -1; top: 0; left: -10000px; width: 200mm; background: white; }
.pdf-static-field { min-height: 20px; padding: 4px; border: .5px solid var(--line); border-radius: 2px; background: #f8f7f4; white-space: pre-wrap; }
@media (max-width: 920px) {
  .app-shell { display: block; }
  .archive { position: static; height: auto; max-height: 320px; border-right: 0; border-bottom: 1px solid var(--line); }
  .form-grid.top, .parties, .signature-row, .totals { grid-template-columns: 1fr; }
  .quote-line, .quote-table-head { grid-template-columns: 32px minmax(190px, 1fr) 68px 68px 68px 68px 96px 88px 94px 34px; }
  .price-list-mode .quote-line, .price-list-mode .quote-table-head { grid-template-columns: 32px minmax(190px, 1fr) 120px 34px; }
}
@media (max-width: 640px) {
  body { padding-bottom: 128px; }
  .app-header { position: relative; display: grid; padding: 12px 14px; }
  .brand img { width: 76px; height: 36px; }
  .workspace { padding: 10px; }
  .workspace-toolbar {
    position: fixed;
    z-index: 30;
    right: 0;
    bottom: 0;
    left: 0;
    display: block;
    max-width: none;
    margin: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
  }
  .workspace-toolbar > div:first-child { display: none; }
  .toolbar-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .toolbar-actions .button { width: 100%; min-height: 44px; padding-inline: 8px; }
  .toolbar-actions .button.primary { grid-column: 1 / -1; order: -1; }
  .quote-page { padding: 15px; }
  .document-masthead { display: grid; padding: 14px; }
  .document-title { text-align: left; }
  .quote-table { gap: 12px; border: 0; background: transparent; }
  .quote-table-head { display: none; }
  .quote-line {
    grid-template-columns: 40px 1fr 38px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
  }
  .quote-line textarea { grid-column: 1 / -1; }
  .quote-line input { grid-column: 1 / -1; min-height: 44px; font-size: 16px; }
  .price-list-mode .quote-line { grid-template-columns: 40px 1fr 38px; }
  .price-list-mode .quote-line [data-field="unitPrice"] { grid-column: 1 / -1; }
  .remove-line { grid-column: 3; grid-row: 1; }
}
@page { size: A4 portrait; margin: 5mm; }
@media print {
  :root {
    --print-ink: #181715;
    --print-muted: #66625e;
    --print-line: #181715;
    --print-soft: #fbfaf6;
    --print-accent: #526a2f;
  }
  .no-print { display: none !important; }
  .print-hidden { display: none !important; }
  body { background: white; }
  .app-shell, .workspace { display: block; min-height: 0; padding: 0; }
  .quote-page {
    width: 100%;
    min-height: 0;
    padding: 5mm;
    gap: 4mm;
    border: 0;
    box-shadow: none;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--print-ink);
    background: white;
  }
  .document-masthead {
    display: grid;
    grid-template-columns: 26mm 1fr 58mm;
    align-items: start;
    padding: 0;
    color: var(--print-ink);
    background: white;
    border-bottom: 0;
  }
  .document-logo {
    align-content: start;
    padding-bottom: 2mm;
  }
  .document-logo img {
    width: 22mm;
    background: white;
  }
  .document-masthead strong {
    color: var(--print-ink);
    font-size: 16px;
    letter-spacing: .02em;
  }
  .document-masthead span {
    color: var(--print-muted);
    font-size: 8px;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  .document-title {
    min-width: 48mm;
    padding: 3mm 0 0;
    color: var(--print-accent);
    background: transparent;
    text-align: left;
  }
  .document-title strong {
    color: var(--print-accent);
    font-size: 16px;
  }
  .document-title span {
    color: var(--print-muted);
    font-size: 8px;
  }
  .document-company {
    justify-items: end;
    align-content: start;
    padding-bottom: 2mm;
    text-align: right;
  }
  .document-company strong {
    color: var(--print-accent);
    font-size: 13px;
    text-transform: uppercase;
  }
  .document-company span {
    display: block;
    color: var(--print-muted);
    font-size: 7.8px;
    letter-spacing: .04em;
    line-height: 1.35;
    text-transform: uppercase;
  }
  label {
    gap: 1mm;
    color: var(--print-muted);
    font-size: 6.8px;
    letter-spacing: .08em;
  }
  input, textarea, select, .pdf-static-field {
    min-height: 5mm;
    padding: 1mm 1.4mm;
    border: .5px solid var(--print-line);
    border-radius: 0;
    background: white;
    color: var(--print-ink);
    font-size: 8.2px;
    line-height: 1.18;
  }
  .document-info {
    grid-template-columns: minmax(0, 1fr) 48mm;
    align-items: start;
    gap: 8mm;
    margin-top: 2mm;
  }
  .form-grid.top {
    grid-template-columns: 1fr;
    gap: 3mm;
  }
  .document-type-field,
  .document-number-field {
    display: none;
  }
  .document-fields {
    align-items: start;
    padding-top: 6mm;
    padding-bottom: 0;
    border-bottom: 0;
  }
  .document-fields label {
    gap: 1mm;
    color: var(--print-muted);
    font-size: 7px;
  }
  .document-fields input,
  .document-fields select,
  .document-fields .pdf-static-field {
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--print-ink);
    font-size: 8.8px;
    font-weight: 700;
  }
  .parties {
    grid-template-columns: 1fr;
    gap: 2mm;
  }
  .parties section {
    gap: 1mm;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: white;
  }
  .customer-fields {
    grid-template-columns: 1fr;
    text-align: left;
  }
  .customer-fields .section-kicker,
  .customer-fields label:last-child { grid-column: 1 / -1; }
  .customer-fields label {
    justify-items: stretch;
  }
  .customer-fields input,
  .customer-fields .pdf-static-field {
    text-align: left;
  }
  .customer-fields input {
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--print-ink);
    font-size: 8.8px;
    font-weight: 700;
    line-height: 1.08;
  }
  .customer-fields .pdf-static-field {
    display: block;
    border: 0;
    padding: 0;
    min-height: 0;
    color: var(--print-ink);
    font-size: 8.8px;
    font-weight: 700;
    line-height: 1.08;
  }
  .customer-fields label {
    gap: 0;
    color: transparent;
    font-size: 0;
    letter-spacing: 0;
    line-height: 1.08;
    text-transform: none;
  }
  .section-kicker {
    padding-bottom: .8mm;
    color: var(--print-ink);
    border-bottom: .5px solid var(--print-line);
    font-size: 7px;
    letter-spacing: .12em;
  }
  .customer-fields .section-kicker {
    border-bottom: 0;
    padding-bottom: 0;
  }
  .quote-table {
    border: .6px solid var(--print-line);
    border-bottom: 0;
    background: white;
  }
  .quote-table-head, .quote-line {
    grid-template-columns: 8mm minmax(0, 1fr) 13mm 13mm 13mm 13mm 19mm 18mm 22mm;
    gap: 0;
    padding: 0;
  }
  .quote-table-head {
    align-items: center;
    min-height: 6mm;
    color: var(--print-ink);
    background: white;
    border-bottom: .6px solid var(--print-line);
    font-size: 6.8px;
    letter-spacing: .06em;
  }
  .quote-table-head span {
    padding: 0 1mm;
  }
  .price-list-mode .quote-table-head, .price-list-mode .quote-line { grid-template-columns: 9mm minmax(0, 1fr) 30mm; }
  .quote-line {
    align-items: stretch;
    border-bottom: .6px solid var(--print-line);
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .quote-line > * {
    border-right: .6px solid var(--print-line) !important;
  }
  .quote-line > *:last-child {
    border-right: 0 !important;
  }
  .quote-line .pdf-static-field {
    min-height: 7mm;
    padding: 1mm;
    border: 0;
    background: transparent;
  }
  .quote-line .pdf-static-field[data-name="description"] {
    min-height: 8mm;
  }
  .quote-line textarea { min-height: 8mm; }
  .line-number {
    display: grid;
    place-items: start center;
    padding: 1.5mm .7mm;
    font-size: 7px;
  }
  .totals {
    align-items: end;
    grid-template-columns: minmax(0, 1fr) 48mm;
    gap: 3mm;
  }
  .totals label {
    align-self: stretch;
  }
  .total-box {
    min-width: 0;
    width: 48mm;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: right;
  }
  .total-box span { color: var(--print-ink); font-size: 7.2px; }
  .total-box strong { color: var(--print-accent); font-size: 14px; }
  .signature-row {
    margin-top: 1mm;
    padding-top: 4mm;
    grid-template-columns: 1fr 1fr;
    gap: 8mm;
    border-top: .5px solid var(--print-line);
  }
  .signature-row .pdf-static-field {
    min-height: 8mm;
    border-width: 0 0 .5px;
  }
}
