/* ============================================
   Jardi Inventaire — Styles Mobile-First
   ============================================ */

:root {
  --green: #28a745;
  --green-light: #d4edda;
  --green-dark: #1e7e34;
  --red: #dc3545;
  --red-light: #f8d7da;
  --orange: #fd7e14;
  --orange-light: #fff3cd;
  --blue: #007bff;
  --blue-dark: #0056b3;
  --gray-100: #f8f9fa;
  --gray-200: #e9ecef;
  --gray-300: #dee2e6;
  --gray-400: #ced4da;
  --gray-500: #adb5bd;
  --gray-600: #6c757d;
  --gray-700: #495057;
  --gray-800: #343a40;
  --gray-900: #212529;
  --white: #ffffff;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 12px;
  --transition: 0.2s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  min-height: 100dvh;
  line-height: 1.5;
}

/* ---- Utilities ---- */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

.text-center { text-align: center; }
.text-muted { color: var(--gray-600); }
.text-small { font-size: 0.85rem; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.hidden { display: none !important; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  width: 100%;
  min-height: 50px;
  text-decoration: none;
  color: var(--white);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--blue);
}
.btn-primary:hover { background: var(--blue-dark); }

.btn-success {
  background: var(--green);
}
.btn-success:hover { background: var(--green-dark); }

.btn-danger {
  background: var(--red);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover {
  background: var(--gray-200);
}

.btn-secondary {
  background: var(--gray-600);
}

.btn-sm {
  padding: 10px 16px;
  font-size: 0.9rem;
  min-height: 42px;
  width: auto;
}

/* ---- Form elements ---- */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--gray-700);
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--white);
  transition: border-color var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--blue);
}

input[type="number"] {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  padding: 18px 16px;
}

/* Large recomptage input */
.input-recomptage {
  font-size: 2rem;
  padding: 20px;
  border: 3px solid var(--blue);
  border-radius: var(--radius);
  text-align: center;
  font-weight: 700;
}

.input-recomptage:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(40, 167, 69, 0.15);
}

/* ---- Cards ---- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

/* ---- LOGIN PAGE ---- */
.login-wrapper {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 0.9rem;
  color: var(--gray-600);
  margin-bottom: 24px;
}

.login-error {
  background: var(--red-light);
  color: var(--red);
  padding: 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}

/* ---- HEADER BAR ---- */
.header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.header-back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

/* ---- KPI CARDS ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}

.kpi-card.full-width {
  grid-column: 1 / -1;
}

.kpi-value {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.2;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--gray-600);
  margin-top: 4px;
}

.kpi-green .kpi-value { color: var(--green); }
.kpi-orange .kpi-value { color: var(--orange); }
.kpi-blue .kpi-value { color: var(--blue); }

/* ---- Progress bar ---- */
.progress-bar {
  width: 100%;
  height: 12px;
  background: var(--gray-200);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), #20c997);
  border-radius: 6px;
  transition: width 0.5s ease;
}

/* ---- Support table (dashboard) ---- */
.support-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.support-table th {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 2px solid var(--gray-300);
  color: var(--gray-600);
  font-weight: 600;
}

.support-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--gray-200);
}

.support-table .done-cell {
  color: var(--green);
  font-weight: 600;
}

/* ---- Session config ---- */
.filter-section {
  margin-bottom: 20px;
}

.filter-section h3 {
  font-size: 1rem;
  margin-bottom: 10px;
}

.checkbox-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  padding: 8px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
}

.checkbox-item:last-child {
  border-bottom: none;
}

.checkbox-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}

.toggle-switch {
  position: relative;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--gray-300);
  border-radius: 28px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  bottom: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--blue);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

.preview-count {
  background: var(--gray-100);
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  margin: 16px 0;
}

.preview-count span {
  color: var(--blue);
  font-size: 1.4rem;
}

/* ---- SESSION PAGE — Product card ---- */
.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
}

.session-counter {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--blue);
  background: rgba(0, 123, 255, 0.1);
  padding: 4px 12px;
  border-radius: 20px;
}

.product-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 16px;
  padding: 20px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.product-designation {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 8px;
}

.product-fournisseur {
  font-size: 0.9rem;
  color: var(--gray-600);
  margin-bottom: 4px;
}

.product-ean {
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  background: var(--gray-100);
  padding: 6px 10px;
  border-radius: 6px;
  display: inline-block;
  margin: 8px 0;
}

.stock-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 16px 0;
}

.stock-cell {
  text-align: center;
  padding: 12px 8px;
  border-radius: 8px;
  background: var(--gray-100);
}

.stock-cell-label {
  font-size: 0.75rem;
  color: var(--gray-600);
  text-transform: uppercase;
  font-weight: 600;
}

.stock-cell-value {
  font-size: 1.5rem;
  font-weight: 800;
  margin-top: 4px;
}

.ecart-negatif {
  background: var(--red-light);
}
.ecart-negatif .stock-cell-value {
  color: var(--red);
}

.ecart-positif {
  background: var(--orange-light);
}
.ecart-positif .stock-cell-value {
  color: var(--orange);
}

.product-meta {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--gray-200);
}

.recomptage-section {
  margin: 20px 16px;
}

.recomptage-label {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--gray-600);
  text-align: center;
  margin-bottom: 10px;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  margin: 16px;
  padding-bottom: 24px;
}

/* ---- Session finished ---- */
.session-finished {
  text-align: center;
  padding: 40px 20px;
}

.session-finished-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.session-finished h2 {
  font-size: 1.4rem;
  margin-bottom: 8px;
}

.session-finished p {
  color: var(--gray-600);
  margin-bottom: 24px;
}

/* ---- Import section ---- */
.import-zone {
  border: 2px dashed var(--gray-400);
  border-radius: var(--radius);
  padding: 30px 20px;
  text-align: center;
  margin-bottom: 16px;
}

.import-zone p {
  color: var(--gray-600);
  margin-bottom: 12px;
}

/* ---- Export buttons ---- */
.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ---- Loading/spinner ---- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid var(--gray-300);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

/* ---- Toast notifications ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-800);
  color: var(--white);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 1000;
  animation: toastIn 0.3s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- Desktop overrides ---- */
@media (min-width: 768px) {
  .container {
    max-width: 700px;
    padding: 24px;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .btn {
    width: auto;
    min-width: 200px;
  }

  .action-buttons {
    max-width: 500px;
    margin: 20px auto;
  }

  .product-card {
    max-width: 600px;
    margin: 20px auto;
  }

  .recomptage-section {
    max-width: 400px;
    margin: 20px auto;
  }
}
