/* =========================================================
   Menu del giorno – stile interfaccia + foglio di stampa
   ========================================================= */

:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --ink: #2a2622;
  --muted: #6d655c;
  --line: #ddd5ca;
  --accent: #7a2e1d;        /* bordeaux */
  --accent-ink: #ffffff;
  --accent-soft: #f6ebe7;
  --primary: #2f4a3a;       /* verde bottiglia */
  --primary-ink: #ffffff;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4d00;
  --info-bg: #e8f0f6;
  --info-ink: #24445e;
  --danger: #a32020;
  --radius: 12px;
  --tap: 48px;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --menu-font: "Cormorant Garamond", "Cormorant", Garamond, "Times New Roman", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 17px;
  line-height: 1.4;
}

button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- Barra superiore ---------- */
.topbar {
  position: static;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.app-title {
  margin: 0;
  font-family: var(--menu-font);
  font-size: 28px;
  font-weight: 600;
  color: var(--accent);
}
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.save-status { margin: 0; font-size: 14px; color: var(--muted); min-width: 8em; text-align: right; }
.save-status.is-error { color: var(--danger); }

/* ---------- Pulsanti ---------- */
.btn {
  min-height: var(--tap);
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { background: #f8f6f2; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: #263d30; }
.btn-accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-accent:hover:not(:disabled) { background: #652517; }
.btn-danger-outline { color: var(--danger); border-color: #e3c4c4; }
.btn-small { min-height: 44px; padding: 6px 14px; font-size: 15px; }
.btn-icon { min-width: var(--tap); padding: 6px 10px; font-size: 18px; }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after {
  content: "";
  position: absolute; inset: 0; margin: auto;
  width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.btn:not(.btn-accent):not(.btn-primary).is-busy::after { border-color: #ccc; border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.link-btn {
  border: 0; background: none; padding: 4px 6px; margin-left: 4px;
  color: var(--primary); font-weight: 600; font-size: 14px; cursor: pointer;
  min-height: 32px;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding: 16px;
  max-width: 1700px;
  margin: 0 auto;
}
@media (min-width: 1150px) {
  .layout { grid-template-columns: minmax(520px, 1fr) minmax(420px, 46%); align-items: start; }
  .topbar { position: sticky; top: 0; }
  .preview-pane { position: sticky; top: 92px; max-height: calc(100vh - 108px); overflow: auto; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.card-title {
  margin: 0 0 12px;
  font-family: var(--menu-font);
  font-size: 26px;
  font-weight: 600;
  color: var(--accent);
}
.card-title small { font-family: var(--ui-font); font-size: 15px; font-weight: 400; color: var(--muted); margin-left: 6px; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 12px 16px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.label { font-size: 15px; font-weight: 600; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.label small { font-weight: 400; }

input[type="text"], input[type="date"], textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid #cfc6ba;
  border-radius: 8px;
  background: #fff;
  font-size: 17px;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, textarea:focus, .btn:focus-visible, .seg button:focus-visible {
  outline: 3px solid rgba(122, 46, 29, .35);
  outline-offset: 1px;
  border-color: var(--accent);
}
.field-en input, .field-en textarea { background: #fbfaf7; font-style: italic; }
input.is-invalid { border-color: var(--danger); background: #fff6f6; }
.hint { font-size: 13px; color: var(--danger); min-height: 0; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
}

/* ---------- Sezioni e voci ---------- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.section-head .card-title { margin: 0; }
.section-count { font-size: 14px; color: var(--muted); }

.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  background: #fdfcfa;
}
.item-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.item-num {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700;
}
.item-bar .spacer { flex: 1; }
.item-grid { display: grid; grid-template-columns: 1fr; gap: 10px 14px; }
@media (min-width: 640px) {
  .item-grid { grid-template-columns: 1fr 150px; }
  .item-grid .span-2 { grid-column: 1 / -1; }
}
.item-en {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: grid; grid-template-columns: 1fr; gap: 10px 14px;
}
@media (min-width: 640px) { .item-en { grid-template-columns: 1fr 1fr; } }
.price-input { display: flex; align-items: center; gap: 6px; }
.date-input { display: flex; align-items: center; gap: 8px; }
.date-input input { flex: 1; min-width: 0; }
.date-input .btn { flex: none; }
.price-input span { font-weight: 600; color: var(--muted); }
.price-input input { text-align: right; }

.section-actions { display: flex; justify-content: flex-start; }

/* Modalità prezzo per sezione */
.price-mode {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 20px;
  margin-bottom: 14px; padding: 10px 12px;
  background: #faf7f2; border: 1px solid var(--line); border-radius: 10px;
}
.price-mode .sec-price { width: 180px; }
.price-mode-section .item-price { display: none; }
@media (min-width: 640px) {
  .price-mode-section .item-grid { grid-template-columns: 1fr; }
}

/* ---------- Avvisi ---------- */
.notice { margin: 0 16px 0; padding: 10px 14px; border-radius: 10px; font-size: 15px; }
.preview-pane .notice { margin: 0 0 10px; }
.notice-warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid #f0d98c; }
.notice-info { background: var(--info-bg); color: var(--info-ink); border: 1px solid #c8d9e8; }
body > .notice { margin-top: 12px; }

/* ---------- Anteprima ---------- */
.preview-controls { display: flex; flex-wrap: wrap; gap: 12px 20px; margin-bottom: 12px; }
.seg-group { display: flex; flex-direction: column; gap: 4px; }
.seg { display: inline-flex; border: 1px solid #cfc6ba; border-radius: 10px; overflow: hidden; background: #fff; }
.seg button {
  min-height: var(--tap); min-width: 64px; padding: 6px 16px;
  border: 0; border-right: 1px solid #e4ddd3; background: none; cursor: pointer; font-weight: 600;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-checked="true"] { background: var(--primary); color: #fff; }

.preview-wrap {
  background: #d9d3ca;
  border-radius: var(--radius);
  padding: 16px;
  overflow: hidden;
}
.sheet-holder { margin: 0 auto; position: relative; }
.sheet-stack {
  --fs: 1;                     /* fattore carattere (adattamento) */
  --sp: 1;                     /* fattore spaziature (adattamento) */
  --base: 12pt;
  position: absolute; top: 0; left: 0;
  display: flex; flex-direction: column; gap: 10mm;
  transform-origin: top left;
}

/* ---------- Il foglio ---------- */
.sheet {
  /* dimensioni impostate da JS in mm */
  flex: none;
  background: #fff;
  color: #1d1a17;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.sheet-inner { width: 100%; height: 100%; overflow: hidden; }

.m-content {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  font-family: var(--menu-font);
  font-size: calc(var(--base) * var(--fs));
  line-height: 1.22;
  font-variant-numeric: lining-nums;
}

.m-head { text-align: center; }
.m-rest {
  font-size: 1.05em;
  font-weight: 600;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: #6b2a1b;
}
.m-title {
  margin: calc(.25em * var(--sp)) 0 0;
  font-size: 2.3em;
  font-weight: 500;
  line-height: 1.05;
}
.m-date { margin-top: calc(.35em * var(--sp)); font-style: italic; font-size: 1.02em; color: #4a443d; }
.m-rule {
  width: 34%; margin: calc(.9em * var(--sp)) auto calc(.2em * var(--sp));
  border: 0; border-top: .6pt solid #9c8f80;
}

.m-body { flex: 1; display: flex; flex-direction: column; justify-content: center; }

/* Colonne: in A4 a sinistra antipasti e primi, a destra secondi e dolci */
.m-cols { display: flex; align-items: flex-start; }
.m-col { flex: 1 1 0; min-width: 0; }
.m-cols-2 .m-col:first-child { padding-right: 1.2em; }
.m-cols-2 .m-col + .m-col { padding-left: 1.2em; border-left: .5pt solid #cfc4b6; align-self: stretch; }
.m-col > .m-sec:first-child { margin-top: calc(.6em * var(--sp)); }

.m-sec { margin-top: calc(1.25em * var(--sp)); break-inside: avoid; }
.m-sec-title {
  display: flex; align-items: center; gap: .8em;
  margin: 0 0 calc(.55em * var(--sp));
  font-size: 1.3em;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
  text-align: center;
  color: #6b2a1b;
}
.m-sec-title::before, .m-sec-title::after { content: ""; flex: 1; border-top: .5pt solid #b8ab9b; }
.m-sec-title .m-sec-label { display: flex; flex-direction: column; align-items: center; }
.m-sec-main { white-space: nowrap; }
/* Prezzo unico della categoria, accanto al titolo */
.m-sec-price {
  margin-left: .6em; padding-left: .6em;
  border-left: .5pt solid #b8ab9b;
  font-size: .85em; letter-spacing: .04em; font-weight: 600;
  color: #1d1a17;
}

.m-item { margin-bottom: calc(.62em * var(--sp)); break-inside: avoid; }
.m-item:last-child { margin-bottom: 0; }
.m-line { display: flex; align-items: baseline; gap: .35em; }
.m-name { font-size: 1.12em; font-weight: 600; }
.m-lead { flex: 1; min-width: 1.5em; border-bottom: 1pt dotted #9c8f80; transform: translateY(-.25em); }
.m-price { font-size: 1.08em; font-weight: 600; white-space: nowrap; }
.m-desc { font-size: .93em; color: #3a3530; margin-top: .05em; }
.m-desc { font-style: italic; }

.m-foot {
  margin-top: calc(1.2em * var(--sp));
  padding-top: calc(.5em * var(--sp));
  border-top: .5pt solid #b8ab9b;
  text-align: center;
  font-size: .82em;
  font-style: italic;
  color: #4a443d;
  white-space: pre-line;
}
.m-empty { text-align: center; font-style: italic; color: #9b9187; margin-top: 3em; }

/* ---------- Toast e finestra di dialogo ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 50;
  max-width: min(92vw, 560px);
  padding: 14px 20px;
  border-radius: 12px;
  background: #2a2622; color: #fff;
  font-size: 16px;
  box-shadow: 0 8px 28px rgba(0,0,0,.25);
}
.toast.is-error { background: var(--danger); }

.dialog {
  border: 0; border-radius: 16px; padding: 24px;
  width: min(92vw, 520px);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.dialog::backdrop { background: rgba(30, 25, 20, .45); }
.dialog-title { margin: 0 0 8px; font-size: 22px; }
.dialog-msg { margin: 0 0 20px; white-space: pre-line; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }

/* ---------- Telefono ---------- */
@media (max-width: 560px) {
  body { font-size: 16px; }
  .topbar-actions .btn { flex: 1 1 45%; }
  .layout { padding: 12px; }
  .preview-wrap { padding: 8px; }
}

/* =========================================================
   STAMPA: solo il foglio
   ========================================================= */
@media print {
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  .topbar, .editor, .preview-controls, .notice, .toast, .dialog { display: none !important; }
  .layout, .preview-pane, .preview-wrap, .sheet-holder {
    display: block !important;
    position: static !important;
    margin: 0 !important; padding: 0 !important;
    width: auto !important; height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    background: none !important; border: 0 !important; border-radius: 0 !important;
    box-shadow: none !important;
  }
  .sheet-stack {
    position: static !important;
    display: block !important;
    transform: none !important;
  }
  .sheet {
    position: relative !important;
    box-shadow: none !important;
    margin: 0 !important;
    page-break-after: always;
    break-after: page;
    page-break-inside: avoid;
    break-inside: avoid;
    overflow: hidden;
  }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
}
