/* ===================================================================
   Fideluxe — tema greige + oro antico
   Mobile-first, con piccoli tocchi di raffinatezza.
   =================================================================== */

:root {
  /* Palette */
  --bg:           #EDE7DD;   /* greige chiaro */
  --bg-soft:      #F5F0E6;
  --bg-deep:      #DCD3C4;
  --ink:          #2B2620;   /* testo profondo */
  --ink-soft:     #5A5146;
  --line:         #CFC3AE;
  --gold:         #B08D57;   /* oro antico */
  --gold-deep:    #8C6E3F;
  --gold-soft:    #D4BB8E;
  --white:        #FFFBF4;
  --danger:       #B3523E;

  /* Radii & shadow */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-xl: 28px;
  --shadow-sm: 0 1px 2px rgba(43, 38, 32, 0.06), 0 2px 8px rgba(43, 38, 32, 0.04);
  --shadow-md: 0 4px 16px rgba(43, 38, 32, 0.10);
  --shadow-lg: 0 16px 40px rgba(43, 38, 32, 0.18);

  /* Font */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-serif: "Didot", "Bodoni 72", "Playfair Display", Georgia, serif;

  /* Spacing scale */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px; line-height: 1.4;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

body {
  background-image:
    radial-gradient(ellipse at top, rgba(176,141,87,0.08), transparent 60%),
    radial-gradient(ellipse at bottom, rgba(176,141,87,0.05), transparent 60%);
}

h1, h2, h3 { font-family: var(--font-serif); font-weight: 500; letter-spacing: 0.01em; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea {
  font-family: inherit; font-size: 16px; color: var(--ink);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  width: 100%;
  transition: border-color .18s, box-shadow .18s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(176,141,87,0.18);
}

/* =========== BRAND =========== */
.brand { text-align: center; margin-bottom: var(--s-6); }
.brand__mark {
  display: inline-grid; place-items: center;
  width: 72px; height: 72px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--gold) 0%, var(--gold-deep) 100%);
  color: var(--white);
  font-family: var(--font-serif); font-size: 34px;
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.3);
  margin-bottom: var(--s-3);
}
.brand__mark--sm { width: 34px; height: 34px; font-size: 18px; margin: 0; }
.brand__name {
  margin: 0;
  font-size: 34px; letter-spacing: 0.04em;
  color: var(--ink);
}
.brand__tag { color: var(--ink-soft); margin: var(--s-2) 0 0; font-size: 14px; letter-spacing: 0.02em; }

/* =========== SCREENS =========== */
.screen {
  min-height: 100dvh;
  padding: max(env(safe-area-inset-top), 16px) var(--s-4) max(env(safe-area-inset-bottom), 20px);
  animation: fadeIn .28s ease both;
}
.screen--center {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding-top: 10vh;
}

@keyframes fadeIn { from {opacity: 0; transform: translateY(6px);} to {opacity: 1; transform: none;} }

/* =========== CARD GENERIC =========== */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}
.card--glass {
  background: rgba(255, 251, 244, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: var(--s-4);
}

/* =========== FIELDS / FORMS =========== */
.field { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.field__label {
  font-size: 12px; font-weight: 500; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.field__row { display: flex; gap: var(--s-2); margin-top: var(--s-2); }
.field__row > * { flex: 1; }
.field--check { flex-direction: row; align-items: center; gap: var(--s-3); }
.field--check input { width: auto; }
.radio-group { display: flex; gap: var(--s-4); margin: var(--s-3) 0; }
.radio-group label { display: flex; align-items: center; gap: var(--s-2); font-size: 14px; }
.radio-group input { width: auto; }

/* =========== BUTTONS =========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-size: 15px; font-weight: 500; letter-spacing: 0.02em;
  transition: transform .12s ease, box-shadow .18s, background .18s;
  min-height: 44px;
}
.btn:active { transform: scale(0.97); }
.btn--primary {
  background: linear-gradient(145deg, var(--gold) 0%, var(--gold-deep) 100%);
  color: var(--white);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.25);
}
.btn--primary:hover { box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.25); }
.btn--ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn--ghost:hover { background: var(--bg-soft); }
.btn--danger {
  background: transparent; color: var(--danger); border: 1px solid var(--danger);
}
.btn--danger:hover { background: rgba(179,82,62,0.08); }
.btn--block { width: 100%; margin-bottom: var(--s-4); }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  color: var(--ink);
  transition: background .18s;
}
.icon-btn:hover, .icon-btn:active { background: rgba(176,141,87,0.12); color: var(--gold-deep); }

.hint { font-size: 13px; color: var(--ink-soft); margin: 0; }
.hint--error { color: var(--danger); }

/* =========== TOP BAR =========== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-2) 0 var(--s-4);
}
.topbar__left { display: flex; align-items: center; gap: var(--s-3); }
.topbar__right { display: flex; gap: var(--s-1); }
.topbar__title {
  font-family: var(--font-serif); font-size: 22px; letter-spacing: 0.04em;
}

/* =========== SEARCH =========== */
.search {
  display: flex; gap: var(--s-2); margin-bottom: var(--s-3);
  position: sticky; top: 0; z-index: 5;
  padding: var(--s-2) 0;
  background: linear-gradient(var(--bg) 80%, transparent);
}
.search input { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 14px; border-radius: 100px;
  background: var(--white); border: 1px solid var(--line);
  color: var(--ink-soft); font-size: 13px; font-weight: 500;
  transition: all .18s;
  white-space: nowrap;
}
.chip--fav[aria-pressed="true"] {
  background: linear-gradient(145deg, var(--gold) 0%, var(--gold-deep) 100%);
  color: var(--white); border-color: transparent;
}

/* =========== CATEGORIES BAR =========== */
.categories-bar {
  display: flex; gap: var(--s-2); margin-bottom: var(--s-4);
  overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: none;
}
.categories-bar::-webkit-scrollbar { display: none; }
.cat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 100px;
  background: var(--white); border: 1px solid var(--line);
  font-size: 13px; color: var(--ink-soft); font-weight: 500;
  white-space: nowrap; cursor: pointer;
  transition: all .18s;
}
.cat-chip__dot { width: 8px; height: 8px; border-radius: 50%; }
.cat-chip.active {
  background: var(--ink); color: var(--white); border-color: transparent;
}

/* =========== CARDS LIST =========== */
.cards-list {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-3);
  padding-bottom: var(--s-10);
}
@media (min-width: 640px) {
  .cards-list { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 960px) {
  .cards-list { grid-template-columns: repeat(4, 1fr); gap: var(--s-4); }
}

.card-tile {
  position: relative;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  min-height: 130px;
  display: flex; flex-direction: column; justify-content: space-between;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s, border-color .18s;
  overflow: hidden;
}
.card-tile::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--tile-color, var(--gold));
  opacity: 0.85;
}
.card-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--gold-soft); }
.card-tile:active { transform: translateY(0) scale(0.98); }

.card-tile__logo {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--bg-soft);
  display: grid; place-items: center;
  overflow: hidden;
  font-family: var(--font-serif); font-size: 20px; color: var(--gold-deep);
  border: 1px solid var(--line);
}
.card-tile__logo img { width: 100%; height: 100%; object-fit: cover; }
.card-tile__name {
  font-family: var(--font-serif); font-size: 16px; line-height: 1.2;
  margin-top: var(--s-2);
  color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-tile__cat {
  font-size: 11px; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-top: 4px;
}
.card-tile__fav {
  position: absolute; top: 10px; right: 10px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(255,251,244,0.9);
  color: var(--ink-soft);
}
.card-tile__fav.active { color: var(--gold-deep); }

/* =========== EMPTY =========== */
.empty { text-align: center; padding: var(--s-10) var(--s-4); color: var(--ink-soft); }
.empty__icon { font-size: 40px; color: var(--gold); margin-bottom: var(--s-3); }
.empty__text { margin: 0 0 var(--s-2); font-family: var(--font-serif); font-size: 18px; color: var(--ink); }
.empty__sub { margin: 0; font-size: 13px; }

/* =========== MODAL =========== */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
}
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(43, 38, 32, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn .2s ease both;
}
.modal__sheet {
  position: relative;
  width: 100%; max-width: 560px;
  max-height: 92dvh; overflow-y: auto;
  background: var(--bg-soft);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--s-6) var(--s-5) calc(var(--s-6) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  animation: slideUp .28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.modal__sheet--sm { max-width: 400px; }
@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal__sheet { border-radius: var(--r-xl); max-height: 88dvh; }
}
@keyframes slideUp { from {transform: translateY(30px); opacity: 0;} to {transform: none; opacity: 1;} }

.modal--full { align-items: stretch; }
.modal--full .cassa,
.modal--full .scanner {
  position: relative;
  width: 100%; height: 100dvh;
  background: var(--ink);
  color: var(--white);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--s-6);
  animation: fadeIn .25s ease both;
}

.modal__close {
  position: absolute; top: var(--s-3); right: var(--s-3);
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-deep); color: var(--ink);
  font-size: 22px; line-height: 1;
  z-index: 2;
}
.modal__title {
  margin: 0 0 var(--s-4); font-size: 22px;
}
.modal__actions {
  display: flex; gap: var(--s-3); justify-content: flex-end;
  margin-top: var(--s-5);
}

/* =========== DETAIL =========== */
.detail__head {
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--s-3);
  align-items: center;
  margin-bottom: var(--s-5);
}
.detail__logo {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--white); border: 1px solid var(--line);
  display: grid; place-items: center; overflow: hidden;
  font-family: var(--font-serif); font-size: 26px; color: var(--gold-deep);
}
.detail__logo img { width: 100%; height: 100%; object-fit: cover; }
.detail__title h2 { margin: 0; font-size: 22px; }
.cat-pill {
  display: inline-block; margin-top: 4px;
  padding: 3px 10px; border-radius: 100px;
  font-size: 11px; color: var(--white);
  background: var(--gold);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.fav-btn { color: var(--ink-soft); transition: color .18s, transform .18s; }
.fav-btn[aria-pressed="true"] { color: var(--gold-deep); }
.fav-btn[aria-pressed="true"] svg { fill: currentColor; }
.fav-btn:active { transform: scale(0.9); }

.detail__barcode {
  background: var(--white);
  border-radius: var(--r-md);
  padding: var(--s-4);
  display: grid; place-items: center;
  margin-bottom: var(--s-3);
  min-height: 120px;
}
.detail__barcode svg, .detail__barcode canvas, .detail__barcode img { max-width: 100%; height: auto; }
.detail__number {
  font-family: "SF Mono", "Menlo", monospace;
  text-align: center;
  font-size: 18px; letter-spacing: 0.1em;
  color: var(--ink);
  margin: 0 0 var(--s-4);
}
.detail__note {
  background: var(--bg-deep);
  padding: var(--s-3);
  border-radius: var(--r-sm);
  font-size: 14px; color: var(--ink);
  white-space: pre-wrap;
  margin: 0 0 var(--s-2);
}
.detail__note:empty { display: none; }
.detail__date { font-size: 12px; color: var(--ink-soft); text-align: center; margin: 0; }

/* =========== CASSA =========== */
.cassa { }
.cassa h2 {
  font-size: 26px; margin: 0 0 var(--s-6);
  color: var(--gold-soft); letter-spacing: 0.04em;
}
.cassa__barcode {
  background: var(--white);
  padding: var(--s-5);
  border-radius: var(--r-lg);
  display: grid; place-items: center;
  margin-bottom: var(--s-4);
  max-width: 90%;
}
.cassa__barcode svg, .cassa__barcode canvas, .cassa__barcode img {
  max-width: 100%; height: auto;
}
.cassa__number {
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 22px; letter-spacing: 0.15em;
  color: var(--gold-soft);
  margin: 0 0 var(--s-6);
}
.cassa__hint { font-size: 13px; color: rgba(255,255,255,0.4); }
.cassa__close, .scanner__close {
  background: rgba(255,255,255,0.1); color: var(--white);
}

/* =========== SCANNER =========== */
.scanner__box {
  width: 90%; max-width: 400px; height: 300px;
  border: 2px solid var(--gold);
  border-radius: var(--r-md);
  overflow: hidden;
  background: #000;
}
.scanner__hint { margin-top: var(--s-4); color: rgba(255,255,255,0.7); }

/* =========== PREVIEWS =========== */
.barcode-preview {
  margin-top: var(--s-3);
  background: var(--white);
  padding: var(--s-3);
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  min-height: 60px;
}
.barcode-preview:empty { display: none; }
.barcode-preview svg, .barcode-preview canvas, .barcode-preview img { max-width: 100%; height: auto; }

.logo-preview { margin-top: var(--s-3); }
.logo-preview img {
  width: 64px; height: 64px; border-radius: 50%;
  object-fit: cover; border: 1px solid var(--line);
}
.logo-preview:empty { display: none; }

/* =========== ADMIN =========== */
.tabs {
  display: flex; gap: var(--s-1);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s-5);
  overflow-x: auto;
}
.tab {
  padding: var(--s-3) var(--s-4);
  color: var(--ink-soft);
  font-size: 14px; font-weight: 500;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all .18s;
}
.tab.active { color: var(--gold-deep); border-bottom-color: var(--gold); }

.admin-list { display: flex; flex-direction: column; gap: var(--s-2); }
.admin-item {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  transition: all .18s;
}
.admin-item:hover { border-color: var(--gold-soft); }
.admin-item__info { display: flex; align-items: center; gap: var(--s-3); min-width: 0; flex: 1; }
.admin-item__swatch { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }
.admin-item__name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-item__sub { font-size: 12px; color: var(--ink-soft); }
.admin-item__actions { display: flex; gap: var(--s-2); flex-shrink: 0; }
.admin-item__actions button {
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  font-size: 16px;
  background: var(--bg-soft);
}
.admin-item__actions button:hover { background: var(--bg-deep); }
.admin-item__actions button.danger:hover { background: rgba(179,82,62,0.12); color: var(--danger); }

.inline-form {
  display: flex; gap: var(--s-2); align-items: center;
  margin-bottom: var(--s-4); flex-wrap: wrap;
}
.inline-form input[type="text"] { flex: 1; min-width: 150px; }
.inline-form input[type="color"] { width: 48px; height: 44px; padding: 4px; }

/* =========== TOAST =========== */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--white);
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 14px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: toastIn .25s ease both;
  max-width: 90%;
}
.toast--error { background: var(--danger); }
@keyframes toastIn { from {opacity: 0; transform: translate(-50%, 10px);} to {opacity: 1; transform: translate(-50%, 0);} }

/* =========== HELPERS =========== */
[hidden] { display: none !important; }
