/* ============================================
   ShopLink - Design System Global
   frontend/src/styles/main.css
   ============================================ */

:root {
  /* Palette principale */
  --green-wa: #25D366;
  --green-dark: #128C7E;
  --green-light: #DCF8C6;
  --accent: #FF6B35;
  --accent-light: #FFF0EB;

  /* Neutres */
  --white: #FFFFFF;
  --gray-50: #F8FAFC;
  --gray-100: #F1F5F9;
  --gray-200: #E2E8F0;
  --gray-300: #CBD5E1;
  --gray-400: #94A3B8;
  --gray-500: #64748B;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1E293B;
  --gray-900: #0F172A;

  /* Sémantique */
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted: var(--gray-400);
  --border: var(--gray-200);
  --bg: var(--gray-50);
  --surface: var(--white);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  /* Transitions */
  --transition: all .2s ease;
  --transition-slow: all .4s ease;

  /* Viewport mobile fix (clavier virtuel, barres navigateur) */
  --vh: 1vh;
}

/* DARK THEME */
[data-theme="dark"] {
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --border: #334155;
  --bg: #0F172A;
  --surface: #1E293B;
}

/* RESET */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: calc(var(--vh, 1vh) * 100);
}
img { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; touch-action: manipulation; }
input, textarea, select {
  font: inherit;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .9rem;
  background: var(--surface);
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
  width: 100%;
  font-size: 16px; /* empêche le zoom automatique iOS au focus */
  max-width: 100%;
}
@media (min-width: 481px) {
  input, textarea, select { font-size: inherit; }
}
input:focus, textarea:focus, select:focus {
  border-color: var(--green-wa);
  box-shadow: 0 0 0 3px rgba(37,211,102,.15);
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .65rem 1.4rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: .95rem;
  transition: var(--transition);
  white-space: nowrap;
  min-height: 44px; /* zone tactile minimum recommandée mobile */
}
.btn-primary {
  background: var(--green-wa);
  color: #fff;
}
.btn-primary:hover { background: var(--green-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--green-wa);
  color: var(--green-wa);
}
.btn-outline:hover { background: var(--green-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #e55a27; transform: translateY(-1px); }
.btn-ghost { background: var(--gray-100); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--gray-200); }
.btn-sm { padding: .45rem 1rem; font-size: .85rem; min-height: 38px; }
.btn-lg { padding: .85rem 2rem; font-size: 1.05rem; border-radius: var(--radius-lg); min-height: 50px; }
.btn-icon { padding: .6rem; border-radius: var(--radius-sm); min-width: 40px; min-height: 40px; }

/* CARDS */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-body { padding: 1.5rem; }

/* BADGE */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .7rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-green { background: var(--green-light); color: var(--green-dark); }
.badge-accent { background: var(--accent-light); color: var(--accent); }
.badge-gray { background: var(--gray-100); color: var(--text-secondary); }

/* FORMS */
.form-group { display: flex; flex-direction: column; gap: .4rem; min-width: 0; }
.form-label { font-size: .875rem; font-weight: 600; color: var(--text-secondary); }
.form-error { font-size: .8rem; color: #EF4444; }

/* GRID */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

/* UTILS */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.text-center { text-align: center; }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-green { color: var(--green-wa); }
.text-accent { color: var(--accent); }
.w-full { width: 100%; }
.hidden { display: none !important; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.p-1 { padding: .5rem; } .p-2 { padding: 1rem; } .p-3 { padding: 1.5rem; }

/* TOAST */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  left: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1.2rem;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--green-wa);
  min-width: 280px;
  max-width: 400px;
  width: 100%;
  animation: slideIn .3s ease;
  pointer-events: auto;
}
.toast.error { border-color: #EF4444; }
.toast.warning { border-color: #F59E0B; }
@keyframes slideIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }

/* SKELETON */
.skeleton {
  background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* MODAL ─────────────────────────────────────────────────────────
   Corrigé : centré verticalement quand le contenu tient à l'écran,
   mais devient scrollable (haut ET bas accessibles) dès que le
   contenu ou le clavier virtuel dépasse la hauteur visible.
   ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  display: flex;
  align-items: flex-start;        /* permet au contenu de dépasser sans être coupé */
  justify-content: center;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  backdrop-filter: blur(4px);
  animation: fadeIn .2s ease;
  overflow-y: auto;               /* scroll de l'overlay si la modale est plus grande que l'écran */
  -webkit-overflow-scrolling: touch;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2rem;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: scaleIn .2s ease;
  margin: auto 0;                 /* centre verticalement quand petit, sinon laisse le scroll faire le travail */
  max-height: none;
  position: relative;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; gap: 1rem; }
.modal-title { font-size: 1.25rem; font-weight: 700; word-break: break-word; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }

/* SPINNER */
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--green-wa);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────────────────── RESPONSIVE GLOBAL ─────────────────────────── */

/* Tablettes (≤1024px) */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Tablettes / petits écrans (≤768px) */
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .hide-mobile { display: none !important; }
  .modal { padding: 1.5rem; border-radius: var(--radius-lg); }
  .toast-container { left: .75rem; right: .75rem; top: .75rem; align-items: stretch; }
  .toast { min-width: 0; max-width: none; }
}

/* Mobiles (≤480px) */
@media (max-width: 480px) {
  .btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }
  .modal-overlay { padding: .5rem; padding-top: max(.5rem, env(safe-area-inset-top)); padding-bottom: max(.5rem, env(safe-area-inset-bottom)); }
  .modal { padding: 1.25rem; border-radius: var(--radius-md); }
  .modal-title { font-size: 1.1rem; }
}

/* Très petits mobiles (≤360px) */
@media (max-width: 360px) {
  .modal { padding: 1rem; }
  .btn { font-size: .875rem; padding: .6rem 1rem; }
}

/* Mode paysage mobile : éviter que les modales soient écrasées en hauteur */
@media (max-height: 480px) and (orientation: landscape) {
  .modal-overlay { align-items: flex-start; padding-top: .5rem; padding-bottom: .5rem; }
  .modal { margin: 0 auto; }
}