:root {
  --honey-50:  #fdf8ec;
  --honey-100: #f8ecd0;
  --honey-200: #f0d79a;
  --honey-400: #dca62f;
  --honey-600: #b57a12;
  --honey-700: #8d5d0c;

  --ink:       #2b2318;
  --ink-soft:  #6b5f4d;
  --line:      #e7ddc8;
  --surface:   #ffffff;
  --bg:        #faf6ee;

  --green:     #2e7d4f;
  --green-bg:  #e6f4ea;
  --amber:     #a96a00;
  --amber-bg:  #fdf1d8;
  --slate:     #5a6472;
  --slate-bg:  #eceef1;
  --paid:      #1f6f8b;
  --paid-bg:   #e2f0f5;
  --red:       #b3261e;

  --radius:    14px;
  --tabbar-h:  64px;
  --rail-w:    96px;
  --shadow:    0 1px 2px rgba(43,35,24,.06), 0 6px 20px rgba(43,35,24,.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }

.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.small { font-size: .8125rem; }
.grow  { flex: 1; }

.view.centered {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

/* ---------- Login ---------- */
.login-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  padding: 32px 24px;
}
.login-card .logo { font-size: 44px; line-height: 1; }
.login-card h1 { margin-top: 8px; }
.login-card p  { margin: 4px 0 20px; }
.login-card .field { text-align: left; }
.login-card .info, .login-card .error { text-align: left; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  font-size: .8125rem;
  color: var(--ink-soft);
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn-google svg { width: 18px; height: 18px; flex: none; }

.info {
  background: var(--honey-50);
  border: 1px solid var(--honey-200);
  color: var(--honey-700);
  font-size: .875rem;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0 0 12px;
}

/* ---------- Form ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field > span {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--ink-soft);
}
input[type=text], input[type=email], input[type=password],
input[type=date], input[type=search], input[type=number], select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--honey-400);
  box-shadow: 0 0 0 3px rgba(220,166,47,.2);
}

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { min-width: 160px; }

/* ---------- Bottoni ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary  { background: var(--honey-600); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--honey-700); }
.btn-outline  { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-outline:hover:not(:disabled) { border-color: var(--honey-400); }
.btn-ghost    { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { background: var(--honey-50); color: var(--ink); }
.btn-danger   { background: transparent; color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #fdecea; }
.btn-sm    { padding: 6px 10px; font-size: .8125rem; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 20px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; align-items: center; gap: 8px; }
.logo-sm { font-size: 22px; }
.topbar-user { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--honey-100);
  color: var(--honey-700);
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.page { display: flex; flex-direction: column; gap: 20px; }
.home-side, .home-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ---------- Griglia mieli ---------- */
.honey-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  margin: 4px 0 16px;
}
.honey-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--honey-50);
}
.honey-card.has-qty { border-color: var(--honey-400); background: var(--honey-100); }
.honey-card h3 { font-size: .95rem; margin-bottom: 10px; }

.qty-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}
.qty-label { font-size: .8125rem; color: var(--ink-soft); }
.qty-label .hint { font-style: normal; opacity: .7; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 30px;
  height: 30px;
  font-size: 18px;
  line-height: 1;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
}
.stepper button:hover { border-color: var(--honey-400); }
.stepper input {
  width: 48px;
  text-align: center;
  padding: 6px 4px;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.stock-need {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--honey-200);
  font-size: .8125rem;
  color: var(--ink-soft);
}
.stock-need.is-short { color: var(--amber); font-weight: 600; }
.stock-need.is-ok    { color: var(--green); font-weight: 600; }

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.total-box { display: flex; align-items: baseline; gap: 8px; }
.total-box strong { font-size: 1.4rem; color: var(--honey-700); }

/* ---------- Statistiche ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: .75rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font: inherit;
  font-size: .875rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: var(--honey-400); }
.chip.is-active { background: var(--honey-600); border-color: var(--honey-600); color: #fff; }
.search { max-width: 220px; }

/* ---------- Ordini ---------- */
.orders { display: flex; flex-direction: column; gap: 12px; }

.order {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.order.s-da_preparare { border-left-color: var(--amber); }
.order.s-pronto       { border-left-color: var(--green); }
.order.s-consegnato   { border-left-color: var(--slate); opacity: .75; }
.order.s-pagato       { border-left-color: var(--paid); opacity: .6; }

.order-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.order-name { font-size: 1.05rem; font-weight: 650; }
.order-meta { font-size: .8125rem; color: var(--ink-soft); }
.order-price { font-size: 1.15rem; font-weight: 700; color: var(--honey-700); white-space: nowrap; }

.status {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.status.s-da_preparare { background: var(--amber-bg); color: var(--amber); }
.status.s-pronto       { background: var(--green-bg); color: var(--green); }
.status.s-consegnato   { background: var(--slate-bg); color: var(--slate); }
.status.s-pagato       { background: var(--paid-bg);  color: var(--paid); }

.order-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.item-tag {
  font-size: .8125rem;
  background: var(--honey-50);
  border: 1px solid var(--honey-200);
  border-radius: 8px;
  padding: 4px 10px;
}
.item-tag b { font-weight: 650; }

.order-notes {
  font-size: .875rem;
  color: var(--ink-soft);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

.order-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 32px 0;
}

/* ---------- Varie ---------- */
.error {
  background: #fdecea;
  color: var(--red);
  font-size: .875rem;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0 0 12px;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--honey-200);
  border-top-color: var(--honey-600);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 100;
  background: var(--ink);
  color: #fff;
  font-size: .875rem;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.is-error { background: var(--red); }

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
                    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
  cursor: pointer;
}

.row > .field.narrow { min-width: 120px; flex: 0 1 140px; }

.section-label {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--honey-700);
  margin: 6px 0 8px;
}

/* ---------- Barra di navigazione ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  max-width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font: inherit;
  font-size: .75rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab svg {
  width: 24px;
  height: 24px;
  padding: 3px 16px;
  box-sizing: content-box;
  border-radius: 999px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: background .15s;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--honey-700); }
.tab.is-active svg { background: var(--honey-100); }

/* ---------- Kit nel form ordine ---------- */
.kit-builder {
  border: 1px dashed var(--honey-200);
  border-radius: 12px;
  padding: 14px;
  background: var(--honey-50);
  margin-bottom: 12px;
}
.kit-builder .field { margin-bottom: 8px; }
.kit-composition {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  column-gap: 20px;
}
.kit-builder-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--honey-200);
}
.kit-builder-actions { display: flex; align-items: center; gap: 8px; }
#kit-count { color: var(--ink-soft); }
#kit-count.is-ok { color: var(--green); font-weight: 600; }
.stepper button:disabled { opacity: .4; cursor: not-allowed; }

.kit-lines {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kit-line {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--honey-400);
  background: var(--honey-100);
  border-radius: 10px;
  padding: 8px 8px 8px 12px;
}
.kit-line-price { font-weight: 700; color: var(--honey-700); white-space: nowrap; }

.item-tag.kit-tag { background: #fff6e0; border-color: var(--honey-400); }

/* ---------- Catalogo ---------- */
.catalog-layout { display: grid; gap: 20px; }

.list { list-style: none; margin: 0 0 16px; padding: 0; }
.list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.list-row:first-child { border-top: 1px solid var(--line); }
.list-row.is-archived b { color: var(--ink-soft); text-decoration: line-through; }
.list-empty { padding: 8px 0; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }

.kit-form { border-top: 1px solid var(--line); padding-top: 16px; }
.kit-form .card-head { margin-bottom: 12px; }
.kit-form h3 { font-size: .95rem; }

.check-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.check-chip { position: relative; cursor: pointer; }
.check-chip input { position: absolute; opacity: 0; pointer-events: none; }
.check-chip span {
  display: inline-block;
  font-size: .875rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  transition: all .15s;
}
.check-chip span::before { content: "+ "; }
.check-chip:hover span { border-color: var(--honey-400); }
.check-chip input:checked + span {
  background: var(--honey-600);
  border-color: var(--honey-600);
  color: #fff;
}
.check-chip input:checked + span::before { content: "✓ "; }
.check-chip input:focus-visible + span { box-shadow: 0 0 0 3px rgba(220,166,47,.35); }

/* ---------- Nuovo ordine: pulsante e foglio (sotto i 1024px) ---------- */
.card-head-actions { display: flex; align-items: center; gap: 4px; }
.sheet-close { font-size: 1.1rem; line-height: 1; padding: 8px 12px; }

body.no-scroll { overflow: hidden; }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-weight: 650;
  color: #fff;
  background: var(--honey-600);
  border: 0;
  border-radius: 999px;
  padding: 14px 20px 14px 16px;
  box-shadow: 0 6px 20px rgba(141,93,12,.35), 0 2px 6px rgba(43,35,24,.15);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fab span { font-size: 1.4rem; line-height: 1; font-weight: 500; }
.fab:hover { background: var(--honey-700); }
.fab:active { transform: scale(.97); }

@media (max-width: 1023.98px) {
  /* Lo spazio in fondo evita che il pulsante copra l'ultimo ordine. */
  .is-admin .container { padding-bottom: calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom)); }

  .home-side {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: block;
    background: var(--surface);
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateY(100%);
    visibility: hidden;
    transition: transform .25s ease, visibility 0s linear .25s;
  }
  .home-side.is-open {
    transform: none;
    visibility: visible;
    transition: transform .25s ease;
  }

  .home-side .card {
    max-width: 720px;
    min-height: 100%;
    margin: 0 auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
  }
  .home-side #order-form { flex: 1; display: flex; flex-direction: column; }
  .home-side .form-footer { margin-top: auto; }

  /* Titolo e chiusura restano in alto, totale e salva in basso. */
  .home-side .card-head {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0 -16px 16px;
    padding: max(10px, env(safe-area-inset-top)) 8px 10px 16px;
    background: rgba(255,255,255,.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
  }
  .home-side .form-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 8px -16px 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.95);
    backdrop-filter: blur(8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .home-side, .home-side.is-open { transition: none; }
}

/* ---------- Telefono ---------- */
@media (max-width: 520px) {
  .container { padding: 16px; padding-bottom: calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom)); }
  .search { max-width: none; flex: 1; }
  .topbar { padding: 10px 16px; }
  .topbar h1 { font-size: 1.05rem; }
  .user-email { display: none; }
  .kit-builder-actions { width: 100%; }
  .kit-builder-actions .btn { margin-left: auto; }
}

/* ---------- Tablet: catalogo su due colonne ---------- */
@media (min-width: 760px) {
  .catalog-layout {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    align-items: start;
  }
}

/* ---------- Schermo grande: barra laterale e layout a colonne ---------- */
@media (min-width: 1024px) {
  #view-app { padding-left: var(--rail-w); }

  .tabbar {
    top: 0;
    right: auto;
    width: var(--rail-w);
    height: auto;
    flex-direction: column;
    justify-content: flex-start;
    gap: 6px;
    padding: 16px 0;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .tab { flex: 0 0 auto; padding: 10px 0; max-width: none; }

  /* Su schermo grande il form è sempre visibile: niente pulsante né ✕. */
  .fab, .sheet-close { display: none; }

  .topbar { padding-left: 28px; padding-right: 28px; }

  .container {
    max-width: 1480px;
    padding: 28px 32px 48px;
  }

  .toast { bottom: 28px; left: calc(50% + var(--rail-w) / 2); }

  /* Home admin: form a sinistra (fisso mentre scorri), ordini a destra */
  .is-admin .home-layout:not(.hidden) {
    display: grid;
    grid-template-columns: minmax(420px, 500px) minmax(0, 1fr);
    align-items: start;
    gap: 28px;
  }
  .home-side {
    position: sticky;
    top: 84px;
    max-height: calc(100dvh - 104px);
    overflow-y: auto;
    border-radius: var(--radius);
    scrollbar-width: thin;
  }

  .orders {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    align-items: start;
  }

  .stock-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

@media (min-width: 1600px) {
  .orders { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
}
