/* ---------- Design tokens ---------- */
:root {
  --color-paper: #f2eedf;
  --color-paper-raised: #fbf9f1;
  --color-ink: #26261f;
  --color-ink-soft: #5c5a4d;
  --color-green: #355e3b;
  --color-green-dark: #24422a;
  --color-red: #a6402f;
  --color-gold: #c79a3d;
  --color-line: #d8d0ba;

  --font-display: "Fraunces", "Georgia", serif;
  --font-body: "Work Sans", system-ui, -apple-system, sans-serif;

  --radius: 8px;
  --shadow-card: 0 2px 10px rgba(38, 38, 31, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background-color: var(--color-paper);
  background-image: radial-gradient(
    circle at 1px 1px,
    rgba(38, 38, 31, 0.05) 1px,
    transparent 0
  );
  background-size: 22px 22px;
  color: var(--color-ink);
  font-family: var(--font-body);
  line-height: 1.4;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ---------- Header ---------- */

.page-header {
  text-align: center;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--color-green);
  position: relative;
}

.top-reset {
  position: absolute;
  right: 0;
  top: 0;
  background: none;
  border: 1px solid var(--color-line);
  color: var(--color-ink-soft);
  font-family: var(--font-body);
  font-size: 0.75rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
}

.top-reset:hover {
  border-color: var(--color-red);
  color: var(--color-red);
}

.menu-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.9rem, 6vw, 2.6rem);
  margin: 0.25rem 0 0.15rem;
  letter-spacing: 0.01em;
}

.menu-subtitle {
  font-size: 0.9rem;
  color: var(--color-ink-soft);
  margin: 0 0 0.75rem;
}

.header-note {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--color-ink-soft);
  max-width: 46ch;
  margin: 0 auto;
}

/* ---------- Guest info card ---------- */

.guest-card {
  background: var(--color-paper-raised);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1rem;
  margin-bottom: 2rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.85rem;
}

.avviso {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: red;
}

.avviso--spacer {
  visibility: hidden;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-ink-soft);
  font-weight: 600;
}

.field input {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--color-line);
  border-radius: 6px;
  background: #fff;
  color: var(--color-ink);
  width: 100%;
}

.field input:focus {
  outline: 2px solid var(--color-green);
  outline-offset: 1px;
}

.field input:disabled {
  background: var(--color-line);
  color: var(--color-ink-soft);
  cursor: not-allowed;
}

.field-row {
  display: flex;
  gap: 0.75rem;
}

.field-row .field {
  flex: 1;
  min-width: 0;
}

.checkbox-field {
  margin-top: 0.85rem;
  margin-bottom: 0.85rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-ink);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-left: 1px;
  accent-color: var(--color-green);
  cursor: pointer;
}

/* ---------- Menu sections ---------- */

.menu-section {
  margin-bottom: 1.75rem;
}

.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-green-dark);
  border-bottom: 1px solid var(--color-line);
  padding-bottom: 0.4rem;
  margin: 0 0 0.5rem;
}

.section-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-red);
  display: inline-block;
  flex-shrink: 0;
}

.item-list {
  display: flex;
  flex-direction: column;
}

.item-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px dashed var(--color-line);
}

/* Applied only when the row has a second line (static menu note, or an
   order note/chip once qty > 0): keeps qty/price pinned to the name's
   baseline instead of shifting with the row's growing height. */
.item-row.item-row--top {
  align-items: start;
}

.item-row:last-child {
  border-bottom: none;
}

.qty-input-wrap {
  display: flex;
}

.qty-input {
  width: 56px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  text-align: center;
  padding: 0.4rem 0.2rem;
  border: 1px solid var(--color-line);
  border-radius: 6px;
  background: var(--color-paper-raised);
  color: var(--color-ink);
}

.qty-input:focus {
  outline: 2px solid var(--color-green);
  outline-offset: 1px;
  background: #fff;
}

/* Chrome/Safari hide the spin buttons until hover by default; force them
   to stay visible at all times, matching the previous behavior. */
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
  opacity: 1;
}

.item-name {
  font-size: 0.96rem;
  font-weight: 500;
}

.item-note {
  font-size: 0.76rem;
  color: var(--color-ink-soft);
  font-style: italic;
}

.item-note-row {
  margin-top: 0.1rem;
  font-size: 0.76rem;
  color: var(--color-ink-soft);
}

.note-chip-wrap.hidden {
  display: none;
}

.note-chip {
  font-style: normal;
  font-weight: 600;
  font-size: 0.76rem;
  font-family: var(--font-body);
  color: var(--color-green);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline dashed;
  text-underline-offset: 2px;
}

.note-chip:hover {
  color: var(--color-green-dark);
}

/* Note input / entered-note row, inside item-info: spans the
   name+note column width, not the quantity and price columns. */
.item-note-editor {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.3rem;
}

.item-note-editor.hidden {
  display: none;
}

.note-value {
  font-size: 0.85rem;
  font-style: italic;
  color: var(--color-ink-soft);
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.note-value:hover {
  color: var(--color-ink);
}

.note-remove {
  border: none;
  background: none;
  color: var(--color-red);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0 0.2rem;
}

.note-input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--color-line);
  border-radius: 6px;
  background: #fff;
  color: var(--color-ink);
}

.note-input:focus {
  outline: 2px solid var(--color-green);
  outline-offset: 1px;
}

.note-input-counter {
  font-size: 0.7rem;
  color: var(--color-ink-soft);
  white-space: nowrap;
}

.item-price {
  font-family: var(--font-body);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-red);
  white-space: nowrap;
  text-align: right;
}

/* ---------- Allergen tags & tooltip ---------- */

.allergen-tags {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

/* Only when the item is actually ordered does the badge get the
   colored-pill treatment; vertical-align on <button> elements is
   inconsistent across browsers, so a relative-position nudge is used
   instead — only needed once the badge has real height/padding. */
.allergen-tags--active {
  position: relative;
  top: -1px;
}

.allergen-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  padding: 0;
  color: var(--color-ink-soft);
  font-family: var(--font-body);
  font-style: normal;
  font-weight: 600;
  font-size: 0.76rem;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.allergen-tag:hover,
.allergen-tag:focus-visible {
  color: var(--color-red);
  outline: none;
}

/* Comma-like separator in the muted state, since the tags aren't
   visually self-delimiting circles yet. */
.allergen-tags:not(.allergen-tags--active) .allergen-tag:not(:last-child)::after {
  content: ",";
  text-decoration: none;
}

.allergen-tags--active .allergen-tag {
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--color-gold);
  color: #fff;
  font-weight: 700;
  font-size: 0.65rem;
  line-height: 1;
  text-decoration: none;
}

.allergen-tags--active .allergen-tag:hover,
.allergen-tags--active .allergen-tag:focus-visible {
  background: var(--color-red);
  color: #fff;
}

.allergen-tooltip {
  position: fixed;
  max-width: 260px;
  background: var(--color-ink);
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-style: normal;
  line-height: 1.35;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  z-index: 1500;
  pointer-events: none;
}

.allergen-tooltip.hidden {
  display: none;
}

/* ---------- Allergens legend ---------- */

.allergens-legend {
  margin-top: 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-line);
}

.allergens-legend-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-green-dark);
  margin: 0 0 0.85rem;
  text-align: center;
}

.allergens-legend-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  /* 14 allergens over 2 columns = 7 rows; column flow fills each
     column top-to-bottom before moving to the next, matching the
     reference table (1-7 left column, 8-14 right column). */
  grid-template-rows: repeat(7, auto);
  grid-auto-flow: column;
  gap: 0.75rem 1.5rem;
}

.legend-item {
  font-size: 0.78rem;
  color: var(--color-ink-soft);
  line-height: 1.35;
}

.legend-item strong {
  display: block;
  color: var(--color-ink);
  margin-bottom: 0.1rem;
}

/* ---------- Total & footer ---------- */

.total-card {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--color-green-dark);
  color: var(--color-paper-raised);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
}

.total-label {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
}

.total-amount {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
}

.footer-note {
  font-size: 0.9rem;
  font-weight: 800;  
  color: var(--color-ink-soft);
  text-align: center;
  max-width: 50ch;
  margin: 0 auto 1.5rem;
}

.actions-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-primary {
  background: var(--color-green);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-green-dark);
}

.btn-secondary {
  background: transparent;
  border-color: var(--color-line);
  color: var(--color-ink-soft);
}

.btn-secondary:hover {
  border-color: var(--color-red);
  color: var(--color-red);
}

.btn-danger {
  background: var(--color-red);
  color: #fff;
}

.btn-danger:hover {
  background: #832f21;
}

/* ---------- Modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(38, 38, 31, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--color-paper-raised);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.modal-content h3 {
  font-family: var(--font-display);
  margin: 0 0 0.5rem;
}

.modal-content p {
  font-size: 0.9rem;
  color: var(--color-ink-soft);
  margin: 0 0 1.25rem;
}

#qrcode {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
  min-height: 240px;
  align-items: center;
}

.framed-qr-canvas {
  max-width: 100%;
  height: auto;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

/* ---------- Responsive ---------- */

/* Wider, dedicated breakpoint: stacks tavolo/coperti before there's too
   little room for "NON COSTITUISCE PRENOTAZIONE*" to fit on one line
   next to the label (estimated from the label's font metrics — nudge
   this value up/down if it still wraps on some device). */
@media (max-width: 600px) {
  .field-row {
    flex-direction: column;
    gap: 0.85rem;
  }

  .avviso--spacer {
    display: none;
  }
}

@media (max-width: 480px) {
  .allergens-legend-grid {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-flow: row;
  }

  .item-row {
    grid-template-columns: 48px 1fr auto;
    gap: 0.5rem;
  }

  .qty-input {
    width: 48px;
  }

  .top-reset {
    position: static;
    display: inline-block;
    margin-top: 0.75rem;
  }
}

.hidden {
  display: none !important;
}
