/* ============================================================
   OPUS MENU — Design System
   Variables CSS + Reset + Utilities + Toast + Piano Lock
   ============================================================ */

/* ─── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ─── CSS Variables ─────────────────────────────────────────── */
:root {
  /* Colori brand */
  --color-bg:           #FAFAF8;
  --color-surface:      #FFFFFF;
  --color-surface-2:    #F4F4F2;
  --color-dark:         #1C1C1E;
  --color-dark-2:       #2C2C2E;
  --color-dark-3:       #3A3A3C;

  --color-accent:       #C8432A;
  --color-accent-hover: #B53A22;
  --color-accent-light: #FBE9E6;
  --color-gold:         #D4A843;
  --color-gold-light:   #FBF4E3;

  --color-text:         #1C1C1E;
  --color-text-2:       #48484A;
  --color-text-muted:   #8E8E93;
  --color-text-inverse: #FFFFFF;

  --color-border:       #E5E5EA;
  --color-border-dark:  #C7C7CC;

  --color-success:      #34C759;
  --color-success-bg:   #E8F8ED;
  --color-warning:      #FF9500;
  --color-warning-bg:   #FFF3E0;
  --color-error:        #FF3B30;
  --color-error-bg:     #FFE5E4;
  --color-info:         #007AFF;
  --color-info-bg:      #E5F1FF;

  /* Sidebar dashboard */
  --sidebar-bg:         #1C1C1E;
  --sidebar-text:       rgba(255,255,255,0.75);
  --sidebar-active-bg:  rgba(200,67,42,0.15);
  --sidebar-active-text:#FFFFFF;
  --sidebar-width:      260px;

  /* Tipografia */
  --font:               'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-size-xs:       0.75rem;
  --font-size-sm:       0.875rem;
  --font-size-base:     1rem;
  --font-size-md:       1.125rem;
  --font-size-lg:       1.25rem;
  --font-size-xl:       1.5rem;
  --font-size-2xl:      2rem;
  --font-size-3xl:      2.5rem;

  /* Spazi */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* Border radius */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --radius-full: 9999px;

  /* Ombre */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);
  --shadow-xl:  0 16px 48px rgba(0,0,0,0.16);

  /* Transizioni */
  --transition: 200ms ease;
  --transition-slow: 350ms ease;
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Reset mobile (iOS + Android) ──────────────────────────── */
/* Rimuove il flash blu al tap su Android */
a, button, [role="button"], input, select, textarea {
  -webkit-tap-highlight-color: transparent;
}
/* Elimina delay 300ms su Android e vecchi browser mobile */
a, button, [role="button"] {
  touch-action: manipulation;
}
/* Input: font 16px evita auto-zoom su iOS e Android Chrome */
input, select, textarea {
  font-size: 16px;
}
/* Scrolling fluido su iOS e Android */
html {
  -webkit-overflow-scrolling: touch;
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background-color: var(--color-bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; font-size: inherit; }
ul, ol { list-style: none; }
h1, h2, h3, h4, h5, h6 { line-height: 1.3; font-weight: 700; }

/* ─── Typography Utilities ──────────────────────────────────── */
.text-xs     { font-size: var(--font-size-xs); }
.text-sm     { font-size: var(--font-size-sm); }
.text-base   { font-size: var(--font-size-base); }
.text-md     { font-size: var(--font-size-md); }
.text-lg     { font-size: var(--font-size-lg); }
.text-xl     { font-size: var(--font-size-xl); }
.text-2xl    { font-size: var(--font-size-2xl); }
.text-3xl    { font-size: var(--font-size-3xl); }
.text-muted  { color: var(--color-text-muted); }
.text-accent { color: var(--color-accent); }
.text-gold   { color: var(--color-gold); }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-semi   { font-weight: 600; }
.font-bold   { font-weight: 700; }

/* ─── Layout Utilities ──────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.hidden { display: none !important; }
.w-full { width: 100%; }
.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-6  { margin-bottom: var(--space-6); }

/* ─── Card ──────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  padding: var(--space-6);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}

.card-title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text);
}

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
  cursor: pointer;
  border: 2px solid transparent;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.btn-primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { border-color: var(--color-accent); color: var(--color-accent); }

.btn-dark {
  background: var(--color-dark);
  color: #fff;
  border-color: var(--color-dark);
}
.btn-dark:hover { background: var(--color-dark-2); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-2);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }

.btn-danger {
  background: var(--color-error);
  color: #fff;
  border-color: var(--color-error);
}
.btn-danger:hover { opacity: 0.88; }

.btn-gold {
  background: var(--color-gold);
  color: #fff;
  border-color: var(--color-gold);
}
.btn-gold:hover { opacity: 0.9; }

.btn-sm {
  padding: 0.375rem var(--space-3);
  font-size: var(--font-size-xs);
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 0.875rem var(--space-8);
  font-size: var(--font-size-base);
  border-radius: var(--radius-md);
}

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  aspect-ratio: 1;
}

/* ─── Form Controls ─────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-2);
}

.form-label .required { color: var(--color-error); margin-left: 2px; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.625rem var(--space-4);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(200,67,42,0.12);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--color-text-muted); }

.form-textarea {
  resize: vertical;
  min-height: 90px;
}

.form-hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.form-error {
  font-size: var(--font-size-xs);
  color: var(--color-error);
}

/* Toggle Switch */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.toggle {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-border-dark);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider { background: var(--color-accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ─── Badge ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge-accent      { background: var(--color-accent-light); color: var(--color-accent); }
.badge-gold        { background: var(--color-gold-light); color: #8B6914; }
.badge-success     { background: var(--color-success-bg); color: #1a8c38; }
.badge-warning     { background: var(--color-warning-bg); color: #8B5000; }
.badge-error       { background: var(--color-error-bg); color: #B71C1C; }
.badge-dark        { background: var(--color-dark); color: #fff; }
.badge-neutral     { background: var(--color-surface-2); color: var(--color-text-2); }

/* Plan badges */
.badge-plan-base        { background: var(--color-surface-2); color: var(--color-text-2); }
.badge-plan-ristoratore { background: var(--color-accent-light); color: var(--color-accent); }
.badge-plan-chef        { background: var(--color-gold-light); color: #7a5b10; }

/* ─── Divider ───────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-6) 0;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-5) 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}
.divider-text::before, .divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

/* ─── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-8);
  transform: translateY(16px);
  transition: transform var(--transition);
}

.modal-overlay.active .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.modal-title { font-size: var(--font-size-lg); font-weight: 700; }

.modal-close {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--color-surface-2);
  cursor: pointer;
  font-size: var(--font-size-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}
.modal-close:hover { background: var(--color-border); }

.modal-footer {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border);
}

/* ─── Toast ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--color-dark);
  color: #fff;
  font-size: var(--font-size-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  min-width: 260px;
  max-width: 360px;
  transform: translateX(110%);
  transition: transform var(--transition-slow);
  pointer-events: auto;
}

.toast-show { transform: translateX(0); }

.toast-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.toast-success .toast-icon { background: var(--color-success); }
.toast-error   .toast-icon { background: var(--color-error); }
.toast-warning .toast-icon { background: var(--color-warning); color: var(--color-dark); }
.toast-info    .toast-icon { background: var(--color-info); }

/* ─── Plan Lock ──────────────────────────────────────────────── */
.plan-locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.plan-locked::after {
  content: '🔒';
  margin-left: auto;
  font-size: 0.7rem;
  flex-shrink: 0;
}

/* ─── Page Header ────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
}

.page-title {
  font-size: var(--font-size-2xl);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.page-subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* ─── Empty State ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-6);
  color: var(--color-text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
}

.empty-state-title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text-2);
  margin-bottom: var(--space-2);
}

.empty-state-text {
  font-size: var(--font-size-sm);
  max-width: 320px;
  margin: 0 auto var(--space-6);
}

/* ─── Skeleton Loader ────────────────────────────────────────── */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.skeleton {
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.4s ease infinite;
}

/* ─── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ─── Upgrade Banner ─────────────────────────────────────────── */
.upgrade-banner {
  background: linear-gradient(135deg, var(--color-dark) 0%, var(--color-dark-2) 100%);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  color: #fff;
  margin-bottom: var(--space-6);
}

.upgrade-banner-text h3 { font-size: var(--font-size-base); font-weight: 700; }
.upgrade-banner-text p  { font-size: var(--font-size-sm); opacity: 0.7; margin-top: 2px; }

/* ─── Responsive ─────────────────────────────────────────────── */
/* Tablet (≤1024px) */
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile (≤768px) */
@media (max-width: 768px) {
  .container { padding: 0 var(--space-4); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: stretch; gap: var(--space-3); }
  .page-header .btn { width: 100%; justify-content: center; }
  .modal { padding: var(--space-5); border-radius: var(--radius-lg); }
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; }
  #toast-container {
    left: var(--space-4);
    right: var(--space-4);
    bottom: max(var(--space-4), env(safe-area-inset-bottom, var(--space-4)));
  }
  .toast { min-width: unset; max-width: 100%; }
  .upgrade-banner { flex-direction: column; align-items: flex-start; }
  .upgrade-banner .btn { width: 100%; }
}

/* Piccoli schermi (≤480px) */
@media (max-width: 480px) {
  .page-title { font-size: var(--font-size-xl); }
}
