/* Forza [hidden] ad avere precedenza su qualsiasi display CSS */
[hidden] { display: none !important; }

/* ============================================================
   ROOT VARIABLES
   ============================================================ */
:root {
  --red: #AE1F24;
  --red-dark: #8c181c;
  --yellow: #F8D131;
  --dark: #1a1a1a;
  --gray: #555;
  --gray-light: #888;
  --border: #e5e5e5;
  --bg: #fafaf8;
  --white: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.12);
  --transition: 0.18s ease;
  --font-title: 'Lily Script One', cursive;
  --font-body: 'DM Sans', system-ui, sans-serif;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--dark);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ============================================================
   PUBLIC FRONTEND — HEADER
   ============================================================ */
.site-header {
  background: var(--red);
  color: var(--white);
  padding: 2rem 1rem 1.5rem;
  text-align: center;
}

.header-inner { max-width: 900px; margin: 0 auto; }

.site-title {
  font-family: var(--font-title);
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.site-subtitle {
  font-size: 0.95rem;
  font-weight: 400;
  opacity: 0.88;
  margin-top: 0.3rem;
  letter-spacing: 0.04em;
}

/* ============================================================
   PUBLIC FRONTEND — CATEGORY NAV
   ============================================================ */
.category-nav {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.category-nav::-webkit-scrollbar { display: none; }

.nav-pills {
  display: flex;
  gap: 0.5rem;
  min-width: max-content;
}

.pill {
  background: var(--yellow);
  color: var(--dark);
  border: none;
  border-radius: 999px;
  padding: 0.45rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), transform var(--transition);
  line-height: 1;
}
.pill:hover { transform: translateY(-1px); }
.pill.active {
  background: var(--red);
  color: var(--white);
}

/* ============================================================
   PUBLIC FRONTEND — MAIN
   ============================================================ */
.menu-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

/* ============================================================
   PUBLIC FRONTEND — SECTION
   ============================================================ */
.menu-section { margin-bottom: 3.5rem; }

.section-title {
  font-family: var(--font-title);
  font-size: 1.85rem;
  color: var(--red);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 2px solid var(--yellow);
  padding-bottom: 0.5rem;
}

/* ============================================================
   PUBLIC FRONTEND — ITEMS GRID
   ============================================================ */
.items-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

/* ============================================================
   PUBLIC FRONTEND — ITEM CARD
   ============================================================ */
.item-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transition), transform var(--transition);
}
.item-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.item-card.unavailable { opacity: 0.5; pointer-events: none; }

.item-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.item-body {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.item-name {
  font-family: var(--font-title);
  font-size: 1.15rem;
  color: var(--dark);
  line-height: 1.25;
}

.item-desc {
  font-size: 0.85rem;
  color: var(--gray);
  flex: 1;
  line-height: 1.45;
}

.item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
  gap: 0.5rem;
}

.item-price {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--red);
  font-variant-numeric: tabular-nums;
}

.badge-unavailable {
  font-size: 0.72rem;
  font-weight: 500;
  background: #f0f0f0;
  color: #666;
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  letter-spacing: 0.02em;
}

/* ============================================================
   PUBLIC FRONTEND — FOOTER
   ============================================================ */
.site-footer {
  background: var(--red);
  color: var(--white);
  text-align: center;
  padding: 1.25rem 1rem;
  font-size: 0.875rem;
  letter-spacing: 0.03em;
}

/* ============================================================
   LOADING STATE
   ============================================================ */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem 1rem;
  color: var(--gray-light);
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   RESPONSIVE — PUBLIC
   ============================================================ */
@media (min-width: 640px) {
  .items-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1024px) {
  .items-grid { grid-template-columns: 1fr 1fr 1fr; }
  .category-nav { position: sticky; top: 0; z-index: 100; }
}

/* ============================================================
   SHARED BUTTON COMPONENT
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1.5px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition), opacity var(--transition);
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--red); color: var(--white); border-color: var(--red); }
.btn-primary:hover:not(:disabled) { background: var(--red-dark); border-color: var(--red-dark); }

.btn-outline { background: transparent; color: var(--red); border-color: var(--red); }
.btn-outline:hover:not(:disabled) { background: var(--red); color: var(--white); }

.btn-ghost { background: transparent; color: var(--gray); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: #f5f5f5; }

.btn-danger { background: #dc2626; color: var(--white); border-color: #dc2626; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-full { width: 100%; }
.btn-sm { padding: 0.35rem 0.85rem; font-size: 0.82rem; }

/* ============================================================
   ADMIN — BODY
   ============================================================ */
.admin-body { background: #f5f5f5; min-height: 100vh; }

/* ============================================================
   ADMIN — LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: #f5f5f5;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo { margin-bottom: 1rem; display: flex; justify-content: center; }
.login-title { font-size: 1.4rem; font-weight: 700; color: var(--dark); }
.login-sub { font-size: 0.875rem; color: var(--gray-light); margin-top: 0.25rem; margin-bottom: 1.75rem; }

.login-error {
  font-size: 0.83rem;
  color: #dc2626;
  margin-top: 0.75rem;
  min-height: 1.2em;
}

/* ============================================================
   ADMIN — HEADER
   ============================================================ */
.admin-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 200;
}
.admin-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.admin-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--dark);
}
.admin-header-actions { display: flex; gap: 0.5rem; }

/* ============================================================
   ADMIN — LAYOUT
   ============================================================ */
.admin-layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 57px);
}

/* ============================================================
   ADMIN — SIDEBAR
   ============================================================ */
.admin-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-light);
  margin-bottom: 0.5rem;
}

.cat-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.cat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.cat-item:hover { background: #f7f7f7; }
.cat-item.active { background: #fff3f3; }

.cat-btn {
  flex: 1;
  text-align: left;
  padding: 0.55rem 0.65rem;
  background: transparent;
  border: none;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--dark);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.cat-item.active .cat-btn { color: var(--red); }

.cat-actions {
  display: flex;
  gap: 0.15rem;
  opacity: 0;
  transition: opacity var(--transition);
  padding-right: 0.4rem;
}
.cat-item:hover .cat-actions { opacity: 1; }

.cat-action-btn {
  background: transparent;
  border: none;
  padding: 0.3rem;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--gray-light);
  cursor: pointer;
  line-height: 1;
}
.cat-action-btn:hover { background: var(--border); color: var(--dark); }
.cat-action-btn.danger:hover { background: #fee2e2; color: #dc2626; }

/* ============================================================
   ADMIN — CONTENT
   ============================================================ */
.admin-content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.content-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--dark);
}

/* ============================================================
   ADMIN — ITEMS GRID
   ============================================================ */
.items-admin-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .items-admin-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1024px) {
  .items-admin-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* ============================================================
   ADMIN — ITEM CARD
   ============================================================ */
.admin-item-card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.admin-item-card:hover { border-color: #ccc; box-shadow: var(--shadow); }
.admin-item-card.unavailable { opacity: 0.6; }

.admin-item-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 0.25rem;
}

.admin-item-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--dark);
  line-height: 1.3;
}
.admin-item-desc {
  font-size: 0.8rem;
  color: var(--gray);
  line-height: 1.4;
  flex: 1;
}
.admin-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.admin-item-price {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--red);
}

.avail-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--gray);
}

.admin-item-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.admin-item-actions .btn { flex: 1; }

/* ============================================================
   FORM FIELDS
   ============================================================ */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.field-group label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--dark);
}
.req { color: var(--red); }

.field-group input,
.field-group textarea,
.field-group select {
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--dark);
  background: var(--white);
  transition: border-color var(--transition);
  width: 100%;
}
.field-group input:focus,
.field-group textarea:focus {
  outline: none;
  border-color: var(--red);
}
.field-group textarea { resize: vertical; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.field-check { justify-content: flex-end; }

.login-form,
.modal-form { display: flex; flex-direction: column; gap: 1rem; }

/* ============================================================
   SWITCH TOGGLE
   ============================================================ */
.switch-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--dark);
  cursor: pointer;
  height: 100%;
  padding-top: 0.35rem;
}

.switch { position: relative; display: inline-flex; align-items: center; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-track {
  display: block;
  width: 40px;
  height: 22px;
  background: #d1d5db;
  border-radius: 999px;
  position: relative;
  transition: background var(--transition);
  cursor: pointer;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform var(--transition);
}
.switch input:checked + .switch-track { background: #22c55e; }
.switch input:checked + .switch-track::after { transform: translateX(18px); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card-sm { max-width: 380px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 0;
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  color: var(--gray-light);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 4px;
  line-height: 1;
}
.modal-close:hover { background: #f5f5f5; color: var(--dark); }

.modal-form { padding: 1.25rem 1.5rem; }

.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  background: var(--dark);
  color: var(--white);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.25s ease, toastOut 0.3s ease 2.7s forwards;
  max-width: 320px;
}
.toast.success { background: #16a34a; }
.toast.error { background: #dc2626; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-light);
  font-size: 0.9rem;
}

/* ============================================================
   RESPONSIVE — ADMIN
   ============================================================ */
@media (max-width: 639px) {
  .admin-layout { flex-direction: column; }
  .admin-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .cat-list { flex-direction: row; flex-wrap: wrap; gap: 0.4rem; }
  .cat-item { border-radius: 999px; }
  .cat-btn { padding: 0.35rem 0.85rem; border-radius: 999px; font-size: 0.82rem; }
  .cat-actions { display: none; }
}
