:root {
  /* LIGHT PET THEME (Warm, Friendly, Clean) */
  --bg-dark: #fffdf5; /* Warm off-white */
  --bg-card: #ffffff; /* Pure white for cards */
  --bg-hover: #fff3db; /* Light amber hover */
  
  --text-main: #332111; /* Pet-friendly deep brown/gray */
  --text-muted: #78716c; /* Warm gray */
  
  --primary: #f97316; /* Energetic Orange */
  --primary-hover: #ea580c; 
  
  --success: #10b981; /* Fresh Green */
  --success-hover: #059669;
  
  --danger: #ef4444; /* Clean Red */
  --danger-hover: #dc2626;
  
  --warning: #f59e0b; /* Amber */
  
  --border-color: #fceea7; /* Soft yellow/amber border */
  
  --font-family: 'Nunito', 'Inter', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font-family); background-color: var(--bg-dark); color: var(--text-main); height: 100vh; overflow: hidden; }

/* SPA Routing */
.view-section { display: none; }
.view-section.active { display: flex; flex-direction: column; width: 100%; height: 100vh; }
.view-section.app-container { flex-direction: row; }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fade-in 0.3s ease; }
.client-tab-content { display: none; }
.client-tab-content.active { display: block; flex: 1; overflow-y: auto; animation: fade-in 0.3s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Utilities */
.justify-center { justify-content: center; }
.align-center { align-items: center; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 0.5rem; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-muted { color: var(--text-muted); }
.error-text { color: var(--danger); font-size: 0.875rem; margin-top: 1rem; text-align: center; font-weight: 700; }
.w-100 { width: 100%; }

/* Login Form */
.login-container { flex: 1; display: flex; align-items: center; justify-content: center; background-image: radial-gradient(circle at top right, var(--bg-hover) 0%, var(--bg-dark) 100%); }
.login-box { background-color: var(--bg-card); padding: 2.5rem; border-radius: 1.5rem; width: 100%; max-width: 400px; border: 1px solid var(--border-color); box-shadow: 0 25px 40px -12px rgba(249, 115, 22, 0.15); }

/* Sidebar & Admin */
.sidebar { width: 260px; background-color: var(--bg-card); border-right: 1px solid var(--border-color); padding: 1.5rem; display: flex; flex-direction: column; box-shadow: 2px 0 10px rgba(0,0,0,0.02); z-index: 20;}
.brand { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 2.5rem; color: var(--text-main); }
.brand-icon { color: var(--primary); width: 32px; height: 32px; filter: drop-shadow(0 4px 6px rgba(249,115,22,0.3)); }
.nav-menu { display: flex; flex-direction: column; gap: 0.5rem; }
.nav-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; color: var(--text-muted); text-decoration: none; border-radius: 0.75rem; transition: all 0.2s; font-weight: 600; }
.nav-item:hover, .nav-item.active { background-color: var(--bg-hover); color: var(--text-main); }
.nav-item.active { background-color: rgba(249, 115, 22, 0.1); color: var(--primary); }

.main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; background-color: var(--bg-dark); }
.topbar { padding: 1.5rem 2rem; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); background-color: rgba(255, 253, 245, 0.9); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.topbar h2 { font-size: 1.75rem; font-weight: 800; color: var(--text-main); }
.user-profile { display: flex; align-items: center; gap: 1.25rem; font-weight: 600; }
.avatar { width: 40px; height: 40px; background-color: var(--bg-hover); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--primary); border: 2px solid var(--border-color); }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.5rem; padding: 2rem; }
.stat-card { background-color: var(--bg-card); padding: 1.75rem; border-radius: 1.25rem; border: 1px solid var(--border-color); display: flex; align-items: center; gap: 1.5rem; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }
.stat-icon { width: 64px; height: 64px; border-radius: 1.25rem; display: flex; align-items: center; justify-content: center; transform: rotate(-5deg); }
.stat-icon.clients { background-color: rgba(16, 185, 129, 0.15); color: var(--success); }
.stat-icon.points { background-color: rgba(249, 115, 22, 0.15); color: var(--primary); }
.stat-info p { color: var(--text-muted); font-size: 0.875rem; font-weight: 700; text-transform: uppercase; margin-bottom: 0.25rem; }
.stat-info h3 { font-size: 2.25rem; font-weight: 800; line-height: 1; }

/* Content Section & Table */
.content-section { padding: 0 2rem 2rem; flex: 1; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.section-header h3 { font-size: 1.5rem; font-weight: 800; }
.search-bar { background-color: var(--bg-card); border: 1px solid var(--border-color); border-radius: 0.75rem; padding: 0.75rem 1.25rem; display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.5rem; box-shadow: inset 0 2px 4px rgba(0,0,0,0.02); }
.search-bar input { background: transparent; border: none; color: var(--text-main); font-family: inherit; font-size: 0.875rem; width: 100%; outline: none; font-weight: 500;}
.table-container { background-color: var(--bg-card); border-radius: 1.25rem; border: 1px solid var(--border-color); overflow: hidden; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }
.clients-table { width: 100%; border-collapse: collapse; }
.clients-table th, .clients-table td { padding: 1.25rem 1.5rem; text-align: left; border-bottom: 1px solid var(--border-color); }
.clients-table th { color: var(--text-muted); font-size: 0.75rem; font-weight: 800; text-transform: uppercase; background-color: var(--bg-hover); letter-spacing: 0.05em; }
.clients-table tbody tr:hover { background-color: var(--bg-hover); }
.clickable-cell:hover { text-decoration: underline; color: var(--primary-hover); }
.badge-points { background-color: rgba(249, 115, 22, 0.1); color: var(--primary); padding: 0.35rem 0.85rem; border-radius: 999px; font-weight: 700; display: inline-block; font-size:0.875rem; border: 1px solid rgba(249, 115, 22, 0.2); }
.actions-cell { display: flex; gap: 0.5rem; }

/* Buttons */
.btn-primary { background-color: var(--primary); color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 0.75rem; font-weight: 700; font-size: 0.875rem; display: flex; align-items: center; justify-content: center; gap: 0.5rem; cursor: pointer; transition: 0.2s; font-family: inherit; box-shadow: 0 4px 6px -1px rgba(249,115,22,0.4); }
.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-1px); }
.btn-secondary { background-color: var(--bg-hover); color: var(--text-main); border: 2px solid transparent; padding: 0.75rem 1.5rem; border-radius: 0.75rem; font-weight: 700; font-size: 0.875rem; cursor: pointer; transition: 0.2s; }
.btn-secondary:hover { border-color: var(--border-color); }

.btn-icon { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: 0.5rem; border-radius: 0.5rem; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
.btn-icon:hover { background-color: var(--bg-hover); color: var(--text-main); }
.btn-icon.success { color: var(--success); }
.btn-icon.success:hover { background-color: rgba(16,185,129,0.1); }
.btn-icon.danger { color: var(--danger); }
.btn-icon.danger:hover { background-color: rgba(239,68,68,0.1); }
.btn-icon.primary { color: var(--primary); }
.btn-icon.primary:hover { background-color: rgba(249,115,22,0.1); }

/* Modals */
.modal { position: fixed; inset: 0; background-color: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 50; opacity: 0; pointer-events: none; transition: 0.2s; }
.modal.active { opacity: 1; pointer-events: auto; }
.modal-content { background-color: var(--bg-card); border: 1px solid var(--border-color); border-radius: 1.5rem; width: 100%; max-width: 420px; transform: translateY(20px) scale(0.95); transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); display: flex; flex-direction: column; max-height:90vh; }
.modal-content.large { max-width: 850px; }
.modal.active .modal-content { transform: translateY(0) scale(1); }
.modal-header { padding: 1.5rem 2rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-header h3 { font-size: 1.25rem; font-weight: 800; }
.modal-body { padding: 2rem; overflow-y: auto; }
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 700; color: var(--text-main); margin-bottom: 0.5rem; }
.form-group input { width: 100%; background-color: var(--bg-dark); border: 1px solid var(--border-color); color: var(--text-main); padding: 0.875rem 1.25rem; border-radius: 0.75rem; outline: none; font-family: inherit; font-weight: 500; font-size: 1rem; transition: border-color 0.2s; }
.form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(249,115,22,0.2); }

/* Client View Specifics */
.client-topbar { padding: 1.5rem 2%; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background-color: var(--bg-card); flex-shrink: 0; box-shadow: 0 2px 10px rgba(0,0,0,0.02);}
.client-nav { display: flex; background-color: var(--bg-card); border-bottom: 1px solid var(--border-color); flex-shrink: 0; overflow-x: auto; box-shadow: 0 4px 6px -4px rgba(0,0,0,0.05); }
.client-tab-btn { flex: 1; min-width: max-content; padding: 1.25rem 1rem; background: transparent; border: none; color: var(--text-muted); font-family: inherit; font-size: 0.875rem; font-weight: 700; cursor: pointer; border-bottom: 3px solid transparent; transition: 0.2s; display: flex; align-items: center; justify-content: center; gap: 0.5rem; outline: none;}
.client-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background-color: rgba(249, 115, 22, 0.05); }

.client-dashboard { padding: 2rem 1rem; display: flex; justify-content: center; align-items: flex-start; }
.loyalty-card { background: linear-gradient(135deg, var(--primary), var(--warning)); border-radius: 2rem; width: 100%; max-width: 480px; padding: 2.5rem; color: white; box-shadow: 0 25px 50px -12px rgba(249, 115, 22, 0.5); position: relative; overflow: hidden; border: 4px solid rgba(255,255,255,0.2); }
.loyalty-card::after { content: ''; position: absolute; top: -50px; right: -50px; width: 150px; height: 150px; background: rgba(255,255,255,0.1); border-radius: 50%; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3rem; position: relative; z-index: 2; }
.card-body p { opacity: 0.9; font-size: 1rem; margin-bottom: 0px; font-weight: 700; letter-spacing: 0.05em; }
.card-body h1 { font-size: 5rem; font-weight: 800; line-height: 1; margin-bottom: 2rem; position: relative; z-index: 2; text-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.card-footer { opacity: 0.9; font-size: 0.875rem; text-align: center; font-weight: 600; background: rgba(0,0,0,0.15); padding: 0.5rem; border-radius: 1rem; }

/* Rewards Grid */
.rewards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.5rem; }
.reward-card { background-color: var(--bg-card); border: 2px solid var(--border-color); border-radius: 1.25rem; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; position: relative; overflow: hidden; transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 4px 6px rgba(0,0,0,0.02);}
.reward-card:hover { transform: translateY(-4px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.05); }
.reward-card::before { content: ''; position: absolute; top: 0; left: 0; width: 6px; height: 100%; background-color: var(--primary); }
.reward-cost { font-weight: 800; color: var(--primary); font-size: 1.5rem; background: var(--bg-dark); align-self: flex-start; padding: 0.25rem 0.75rem; border-radius: 0.75rem; }
.reward-title { font-weight: 700; font-size: 1.125rem; color: var(--text-main); }
.reward-actions { margin-top: auto; display: flex; gap: 0.5rem; }

/* Coupons Wallet (I Miei Buoni) */
.coupons-list { display: flex; flex-direction: column; gap: 1.5rem; }
.coupon-ticket { background: var(--bg-card); border: 2px dashed var(--warning); border-radius: 1.25rem; padding: 2rem; display: flex; justify-content: space-between; align-items: center; position: relative; box-shadow: 0 4px 10px rgba(245, 158, 11, 0.1); }
.coupon-ticket::before, .coupon-ticket::after { content: ''; position: absolute; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; background-color: var(--bg-dark); border-radius: 50%; z-index: 1;}
.coupon-ticket::before { left: -15px; border-right: 2px dashed var(--warning); }
.coupon-ticket::after { right: -15px; border-left: 2px dashed var(--warning); }
.coupon-info h4 { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; color: var(--text-main); }
.coupon-info p { font-size: 0.875rem; font-weight: 600; color: var(--text-muted); }

/* History List */
.history-list { display: flex; flex-direction: column; gap: 1rem; }
.history-item { background: var(--bg-card); padding: 1.25rem 1.5rem; border-radius: 1rem; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--border-color); box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.history-item.admin-history { background: transparent; border: none; border-bottom: 1px solid var(--border-color); border-radius: 0; padding: 1rem 0; box-shadow: none; }
.history-item.admin-history:last-child { border-bottom: none; }
.hist-desc { font-weight: 700; font-size: 1rem; color: var(--text-main); margin-bottom: 0.25rem; }
.hist-date { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.hist-val { font-weight: 800; font-size: 1.25rem; }
.val-pos { color: var(--success); }
.val-neg { color: var(--danger); }

/* Notifications */
.notif-wrapper { position: relative; }
.notif-dot { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; background-color: var(--danger); border-radius: 50%; border: 2px solid var(--bg-card); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); } 70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }
.notif-dropdown { position: absolute; top: 100%; right: 0; margin-top: 0.5rem; width: 320px; background-color: var(--bg-card); border: 1px solid var(--border-color); border-radius: 1rem; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); z-index: 100; opacity: 0; pointer-events: none; transform: translateY(-10px); transition: 0.2s; }
.notif-dropdown.active { opacity: 1; pointer-events: auto; transform: translateY(0); }
.notif-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border-color); font-weight: 800; display: flex; justify-content: space-between; align-items: center; font-size: 1rem; background: var(--bg-hover); border-radius: 1rem 1rem 0 0; }
.notif-body { max-height: 350px; overflow-y: auto; display: flex; flex-direction: column; }
.notif-item { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border-color); font-size: 0.875rem; transition: background 0.2s; color: var(--text-main); font-weight: 500;}
.notif-item:hover { background-color: var(--bg-dark); }
.notif-item:last-child { border-bottom: none; }
.notif-item .n-date { font-size: 0.7rem; color: var(--text-muted); display: block; margin-top: 0.5rem; font-weight: 600;}

/* Profile Grid in Admin Modal */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.profile-col { padding: 0 2rem 2rem 0; max-height: 65vh; overflow-y: auto; }
.profile-col h4 { margin-bottom: 0.5rem; font-size: 1.25rem; font-weight: 800;}

/* Filters Row */
.filters-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.filter-select {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}
.filter-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(249,115,22,0.2); }

/* Form Select (inside modals) */
.form-select {
  width: 100%;
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.875rem 1.25rem;
  border-radius: 0.75rem;
  outline: none;
  font-family: inherit;
  font-weight: 600;
  font-size: 1rem;
  transition: border-color 0.2s;
  cursor: pointer;
}
.form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(249,115,22,0.2); }

/* Leaderboard */
.leaderboard-row {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(0,0,0,0.03);
  transition: transform 0.2s, box-shadow 0.2s;
}
.leaderboard-row:hover { transform: translateX(4px); box-shadow: 0 4px 8px rgba(0,0,0,0.06); }

/* Hide spin buttons on number inputs */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

/* ==========================================
 * MOBILE RESPONSIVENESS
 * ========================================== */
.mobile-only { display: none !important; }

@media (max-width: 768px) {
  .mobile-only { display: flex !important; margin-right: 0.5rem; }
  .view-section.app-container.active { flex-direction: column; display: flex; }
  
  /* Sidebar (Admin) Slide-out */
  .sidebar {
    position: fixed; top: 0; left: -280px; bottom: 0; width: 260px;
    background: var(--bg-card); z-index: 1000;
    flex-direction: column; align-items: stretch; gap: 1rem; padding: 1.5rem;
    transition: left 0.3s ease; border-right: none; box-shadow: 4px 0 15px rgba(0,0,0,0.1);
  }
  .sidebar.open { left: 0; }
  .brand { margin-bottom: 2rem; justify-content: flex-start; }
  .nav-menu { flex-direction: column; overflow-x: visible; padding-bottom: 0; justify-content: flex-start; }
  .nav-item { padding: 0.75rem 1rem; white-space: normal; font-size: 1rem; }
  
  /* Topbars */
  .topbar { padding: 1rem; flex-direction: row; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); }
  .client-topbar { padding: 1rem; flex-direction: row; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); }
  
  /* Client Nav Slide-out */
  .client-nav {
    position: fixed; top: 0; left: -280px; bottom: 0; width: 260px;
    background: var(--bg-card); z-index: 1000;
    flex-direction: column; align-items: stretch; padding: 2rem 1rem;
    transition: left 0.3s ease; box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    border-bottom: none;
  }
  .client-nav.open { left: 0; }
  .client-tab-btn { justify-content: flex-start; padding: 1rem; border-bottom: none; border-left: 3px solid transparent; text-align: left; font-size: 1rem;}
  .client-tab-btn.active { border-bottom-color: transparent; border-left-color: var(--primary); background-color: rgba(249, 115, 22, 0.05); }

  /* Notification Bell fix */
  .notif-wrapper { position: static; }
  .notif-dropdown {
    position: absolute; top: 70px; right: 1rem; left: 1rem;
    width: auto; max-width: none; max-height: 60vh;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  }
  
  /* Other tweaks */
  .stats-grid { grid-template-columns: 1fr; padding: 1rem; gap: 1rem; }
  .content-section { padding: 0 1rem 1rem; }
  .section-header { flex-direction: column; align-items: stretch; gap: 1rem; }
  .clients-table th, .clients-table td { padding: 0.75rem 1rem; font-size: 0.875rem; }
  .table-container { overflow-x: auto; }
  .actions-cell { flex-wrap: wrap; justify-content: flex-start; }
  
  .loyalty-card { padding: 1.5rem; max-width: 100%; }
  .card-body h1 { font-size: 3.5rem; margin-bottom: 1rem; }
  .profile-grid { grid-template-columns: 1fr; }
  .profile-col { padding: 0 0 1.5rem 0; max-height: none; }
  .modal-header h3 { font-size: 1.125rem; }
  .modal-content { max-height: 95vh; margin: 1rem; }
}
