/* ========================================
   NUSSALA PWA - STYLES MOBILES
   Optimisations pour application mobile
   ======================================== */

/* === VARIABLES MOBILE === */
:root {
  --mobile-header-height: 56px;
  --mobile-bottom-nav-height: 60px;
  --mobile-padding: 16px;
  --mobile-touch-target: 44px;
  --pwa-primary: #0d6efd;
  --pwa-secondary: #6c757d;
  --pwa-success: #198754;
  --pwa-danger: #dc3545;
  --pwa-safe-area-top: env(safe-area-inset-top, 0px);
  --pwa-safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* === RESET & BASE MOBILE === */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Permettre la sélection de texte pour certains éléments */
p, span, a, h1, h2, h3, h4, h5, h6, li, td, th, input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
  overflow-x: hidden;
  width: 100vw;
  max-width: 100%;
}

/* Désactiver le zoom sur input pour iOS */
@media screen and (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="number"],
  input[type="search"],
  textarea,
  select {
    font-size: 16px !important; /* Évite le zoom auto sur iOS */
  }
}

/* === HEADER MOBILE PWA === */
.pwa-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--mobile-header-height) + var(--pwa-safe-area-top));
  background: linear-gradient(135deg, var(--pwa-primary) 0%, #0b5ed7 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  padding-top: var(--pwa-safe-area-top);
  display: flex;
  align-items: center;
  padding-left: var(--mobile-padding);
  padding-right: var(--mobile-padding);
}

.pwa-header-title {
  flex: 1;
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.pwa-header-icon {
  width: var(--mobile-touch-target);
  height: var(--mobile-touch-target);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.pwa-header-icon:active {
  background-color: rgba(255, 255, 255, 0.2);
}

/* === CONTENU PRINCIPAL === */
.pwa-content {
  margin-top: calc(var(--mobile-header-height) + var(--pwa-safe-area-top));
  margin-bottom: calc(var(--mobile-bottom-nav-height) + var(--pwa-safe-area-bottom));
  min-height: calc(100vh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - var(--pwa-safe-area-top) - var(--pwa-safe-area-bottom));
  padding: var(--mobile-padding);
}

/* === NAVIGATION BOTTOM === */
.pwa-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--mobile-bottom-nav-height) + var(--pwa-safe-area-bottom));
  background: white;
  border-top: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: 8px;
  padding-bottom: calc(8px + var(--pwa-safe-area-bottom));
  z-index: 1000;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

.pwa-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--pwa-secondary);
  transition: color 0.2s;
  min-height: var(--mobile-touch-target);
  position: relative;
}

.pwa-nav-item.active {
  color: var(--pwa-primary);
}

.pwa-nav-item:active {
  background-color: rgba(0, 0, 0, 0.05);
  border-radius: 8px;
}

.pwa-nav-icon {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.pwa-nav-label {
  font-size: 0.75rem;
  font-weight: 500;
}

.pwa-nav-badge {
  position: absolute;
  top: 0;
  right: 25%;
  background: var(--pwa-danger);
  color: white;
  border-radius: 10px;
  padding: 2px 6px;
  font-size: 0.65rem;
  font-weight: 600;
}

/* === CARDS MOBILES === */
.pwa-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: var(--mobile-padding);
  margin-bottom: var(--mobile-padding);
  transition: transform 0.2s, box-shadow 0.2s;
}

.pwa-card:active {
  transform: scale(0.98);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* === BOUTONS MOBILES === */
.pwa-btn {
  min-height: var(--mobile-touch-target);
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.pwa-btn-primary {
  background: var(--pwa-primary);
  color: white;
}

.pwa-btn-primary:active {
  background: #0b5ed7;
  transform: scale(0.98);
}

.pwa-btn-outline {
  background: transparent;
  border: 2px solid var(--pwa-primary);
  color: var(--pwa-primary);
}

.pwa-btn-outline:active {
  background: rgba(13, 110, 253, 0.1);
}

/* === LISTE PRODUITS MOBILE === */
.pwa-product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: var(--mobile-padding);
}

.pwa-product-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s;
}

.pwa-product-card:active {
  transform: scale(0.95);
}

.pwa-product-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #f0f0f0;
}

.pwa-product-info {
  padding: 12px;
}

.pwa-product-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.pwa-product-price {
  font-size: 1.1rem;
  color: var(--pwa-primary);
  font-weight: 700;
}

/* === FORMULAIRES MOBILES === */
.pwa-form-group {
  margin-bottom: 16px;
}

.pwa-form-label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
}

.pwa-form-control {
  width: 100%;
  min-height: var(--mobile-touch-target);
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.2s;
}

.pwa-form-control:focus {
  outline: none;
  border-color: var(--pwa-primary);
}

/* === SEARCH BAR MOBILE === */
.pwa-search-bar {
  position: sticky;
  top: calc(var(--mobile-header-height) + var(--pwa-safe-area-top));
  background: white;
  padding: 12px var(--mobile-padding);
  border-bottom: 1px solid #e0e0e0;
  z-index: 100;
}

.pwa-search-input {
  width: 100%;
  min-height: var(--mobile-touch-target);
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 24px;
  font-size: 16px;
  background: #f8f9fa;
}

.pwa-search-input:focus {
  outline: none;
  border-color: var(--pwa-primary);
  background: white;
}

/* === PULL TO REFRESH === */
.pwa-pull-refresh {
  position: fixed;
  top: calc(var(--mobile-header-height) + var(--pwa-safe-area-top));
  left: 50%;
  transform: translateX(-50%) scale(0);
  background: white;
  padding: 12px 24px;
  border-radius: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 999;
  transition: transform 0.3s;
}

.pwa-pull-refresh.active {
  transform: translateX(-50%) scale(1);
}

/* === LOADING SPINNER === */
.pwa-spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 4px solid rgba(13, 110, 253, 0.2);
  border-top-color: var(--pwa-primary);
  border-radius: 50%;
  animation: pwa-spin 1s linear infinite;
}

@keyframes pwa-spin {
  to { transform: rotate(360deg); }
}

/* === MODAL MOBILE === */
.pwa-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 2000;
  animation: pwa-fade-in 0.3s;
}

.pwa-modal-content {
  background: white;
  width: 100%;
  border-radius: 20px 20px 0 0;
  padding: var(--mobile-padding);
  padding-bottom: calc(var(--mobile-padding) + var(--pwa-safe-area-bottom));
  max-height: 80vh;
  overflow-y: auto;
  animation: pwa-slide-up 0.3s;
}

@keyframes pwa-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pwa-slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* === TOAST NOTIFICATIONS === */
.pwa-toast {
  position: fixed;
  bottom: calc(var(--mobile-bottom-nav-height) + var(--pwa-safe-area-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 3000;
  animation: pwa-toast-in 0.3s;
}

@keyframes pwa-toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* === RESPONSIVE === */
@media (max-width: 576px) {
  .pwa-product-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 768px) {
  .pwa-bottom-nav {
    display: none;
  }
  
  .pwa-content {
    margin-bottom: 0;
  }
}

/* === INSTALLATION PROMPT === */
.pwa-install-prompt {
  position: fixed;
  bottom: calc(var(--mobile-bottom-nav-height) + var(--pwa-safe-area-bottom) + 16px);
  left: var(--mobile-padding);
  right: var(--mobile-padding);
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 2500;
  display: flex;
  align-items: center;
  gap: 12px;
  animation: pwa-slide-up 0.3s;
}

.pwa-install-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  overflow: hidden;
}

.pwa-install-text {
  flex: 1;
}

.pwa-install-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.pwa-install-subtitle {
  font-size: 0.85rem;
  color: #666;
}

.pwa-install-close {
  padding: 8px;
  cursor: pointer;
  color: #999;
}

/* === OFFLINE INDICATOR === */
.pwa-offline-banner {
  position: fixed;
  top: calc(var(--mobile-header-height) + var(--pwa-safe-area-top));
  left: 0;
  right: 0;
  background: #ff9800;
  color: white;
  padding: 8px;
  text-align: center;
  font-weight: 600;
  z-index: 999;
  animation: pwa-slide-down 0.3s;
}

@keyframes pwa-slide-down {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

/* === DARK MODE (optionnel) === */
@media (prefers-color-scheme: dark) {
  :root {
    --pwa-primary: #4d9fff;
  }
  
  body {
    background: #121212;
    color: #e0e0e0;
  }
  
  .pwa-card,
  .pwa-product-card,
  .pwa-bottom-nav,
  .pwa-modal-content {
    background: #1e1e1e;
  }
  
  .pwa-form-control,
  .pwa-search-input {
    background: #2a2a2a;
    border-color: #444;
    color: #e0e0e0;
  }
}
