/* ============================================
   SUIVI-COLIS - Styles globaux
   Esthétique : minimal/éditorial, fond crème, accent vert forêt
   Fonts : Poppins (tout le projet)
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
  /* Palette */
  --bg:           #FAFAF7;
  --bg-card:     #FFFFFF;
  --bg-subtle:    #F2F1EC;
  --ink:          #0F0F0F;
  --ink-soft:     #404040;
  --muted:        #737065;
  --line:         #E5E3DC;
  --accent:       #1B4332;
  --accent-soft:  #D4E5DA;
  --error:        #B91C1C;
  --warning:      #C2410C;
  --success:      #166534;

  /* Typo — tout en Poppins */
  --font-display: 'Poppins', system-ui, sans-serif;
  --font-body:    'Poppins', system-ui, sans-serif;
  --font-mono:    'Poppins', system-ui, sans-serif;

  /* Layout */
  --radius:       4px;
  --radius-lg:    8px;
  --max-w:        680px;
  --max-w-wide:   980px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ============================================
   HEADER (branding shop)
   ============================================ */
.site-header {
  padding: 24px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

/* Option "logo centré" (réglable par boutique dans l'admin) */
.site-header.logo-centered {
  justify-content: center;
}

.site-header .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
}

.site-header .brand img {
  height: 28px;
  width: auto;
}

.site-header .brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}

/* ============================================
   MAIN
   ============================================ */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ============================================
   LANDING - Hero
   ============================================ */
.hero {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 32px;
  position: relative;
  overflow: hidden;
}

/* Décor : ligne en pointillés évoquant un trajet */
.hero::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -100px;
  right: -100px;
  height: 1px;
  background-image: linear-gradient(to right, var(--line) 50%, transparent 50%);
  background-size: 12px 1px;
  z-index: 0;
  opacity: 0.6;
}

.hero-inner {
  max-width: var(--max-w);
  width: 100%;
  text-align: center;
  position: relative;
  z-index: 1;
  background: var(--bg);
  padding: 32px 0;
}

.hero h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(36px, 6vw, 56px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 16px;
}

.hero h1 em {
  font-style: italic;
  color: var(--accent);
  font-weight: 700;
}

.hero .subtitle {
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 40px;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

/* Form */
.track-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 460px;
  margin: 0 auto;
}

.track-form .input-wrap {
  position: relative;
}

.track-form input[type="text"] {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 15px;
  letter-spacing: 0.02em;
  padding: 18px 20px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  border-radius: var(--radius);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
  text-align: center;
}

.track-form input[type="text"]::placeholder {
  color: #B5B2A8;
  font-family: var(--font-mono);
}

.track-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.track-form button {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 15px;
  padding: 16px 32px;
  background: var(--ink);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  letter-spacing: 0.01em;
}

.track-form button:hover {
  background: var(--accent);
}

.track-form button:active {
  transform: translateY(1px);
}

.track-form button:disabled {
  background: var(--muted);
  cursor: not-allowed;
}

/* Reassurance */
.reassure {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 48px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.reassure span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.reassure svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ============================================
   TRACKING PAGE - Résultats
   ============================================ */
.track-page {
  flex: 1;
  padding: 48px 32px 80px;
}

.track-inner {
  max-width: 960px;
  margin: 0 auto;
  animation: fadeUp 0.4s ease-out;
}

/* Mise en page 2 colonnes : à gauche le suivi + étapes, à droite destination + carte */
.track-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 0 40px;
  grid-template-areas:
    "header side"
    "timeline side";
  align-items: start;
}
.track-grid .track-header { grid-area: header; }
.track-grid .track-tl { grid-area: timeline; min-width: 0; }
.track-grid .track-side {
  grid-area: side;
  min-width: 0;
  position: sticky;
  top: 24px;
}
.track-grid .track-side .meta-strip { grid-template-columns: 1fr; margin-bottom: 20px; }
.track-grid .track-side .destination-map { margin-bottom: 0; }
.track-grid.no-side {
  grid-template-columns: 1fr;
  grid-template-areas: "header" "timeline";
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.track-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 32px;
  transition: color 0.15s;
}

.track-back:hover { color: var(--ink); }

.track-header {
  margin-bottom: 40px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--line);
}

.track-header .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 8px;
}

.track-header .number {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 24px;
  word-break: break-all;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.status-badge.delivered    { background: #DCFCE7; color: var(--success); }
.status-badge.in_transit   { background: var(--accent-soft); color: var(--accent); }
.status-badge.out_for_delivery { background: #FEF3C7; color: var(--warning); }
.status-badge.exception, .status-badge.undelivered, .status-badge.expired { background: #FEE2E2; color: var(--error); }
.status-badge.info_received, .status-badge.pending { background: var(--bg-subtle); color: var(--ink-soft); }
.status-badge.not_found { background: #FEE2E2; color: var(--error); }

.status-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Destination + EDD strip */
.meta-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 40px;
}

@media (max-width: 480px) {
  .meta-strip { grid-template-columns: 1fr; }
}

.meta-item {
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.meta-item .meta-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 4px;
}

.meta-item .meta-value {
  font-size: 14px;
  color: var(--ink);
  font-weight: 600;
}

/* Map destination */
.destination-map {
  width: 100%;
  height: 280px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  margin-bottom: 40px;
  overflow: hidden;
  background: var(--bg-subtle);
}

.destination-map iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* Timeline */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: var(--line);
}

.timeline-event {
  position: relative;
  padding: 0 0 28px 0;
}

.timeline-event::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 6px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--line);
}

.timeline-event:first-child::before {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.timeline-event .event-time {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

.timeline-event .event-desc {
  font-size: 15px;
  color: var(--ink);
  line-height: 1.4;
  margin-bottom: 2px;
  font-weight: 600;
}

.timeline-event .event-location {
  font-size: 13px;
  color: var(--muted);
}

/* Empty / Error states */
.state {
  text-align: center;
  padding: 80px 24px;
  max-width: 460px;
  margin: 0 auto;
}

.state h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  margin-bottom: 12px;
  color: var(--ink);
}

.state p {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 24px;
}

.state .btn-secondary {
  display: inline-block;
  padding: 12px 24px;
  background: var(--ink);
  color: var(--bg);
  text-decoration: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
}

/* Loader */
.loader {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 80px 0;
  gap: 6px;
}

.loader .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.loader .dot:nth-child(2) { animation-delay: 0.15s; }
.loader .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 60%, 100% { transform: scale(0.6); opacity: 0.4; }
  30%           { transform: scale(1);   opacity: 1; }
}

/* ============================================
   FOOTER
   ============================================ */
.site-footer {
  padding: 24px 32px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

/* ============================================
   ADMIN
   ============================================ */
.admin-page {
  padding: 40px 32px;
  max-width: var(--max-w-wide);
  margin: 0 auto;
}

.admin-page h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  margin-bottom: 32px;
}

.admin-section {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}

.admin-section h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  margin-bottom: 16px;
  color: var(--ink);
}

.admin-section label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  margin-top: 16px;
  font-weight: 500;
}

.admin-section input,
.admin-section textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg);
}

.admin-section textarea {
  font-family: var(--font-mono);
  font-size: 13px;
  resize: vertical;
  min-height: 100px;
}

.admin-section input:focus,
.admin-section textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.admin-section button {
  margin-top: 20px;
  padding: 10px 24px;
  background: var(--ink);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.admin-section button:hover { background: var(--accent); }

/* Interface de remplacement (mot original -> remplacé par) */
.rules-list { margin-top: 4px; }

.rule-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.rule-row input {
  flex: 1;
  width: auto;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--bg);
}

.rule-row input:focus { outline: none; border-color: var(--accent); }

.rule-arrow { color: var(--muted); flex: none; }

.admin-section button.rule-del {
  flex: none;
  margin-top: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  background: var(--bg-subtle);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 14px;
}
.admin-section button.rule-del:hover { background: #FEE2E2; color: var(--error); }

.admin-section button.btn-add-rule {
  margin-top: 8px;
  background: var(--bg-subtle);
  color: var(--ink);
  border: 1px dashed var(--line);
  font-size: 13px;
  padding: 8px 16px;
}
.admin-section button.btn-add-rule:hover { background: var(--accent-soft); color: var(--accent); }

/* Boîte d'accès gérant */
.creds-box {
  margin-top: 4px;
  padding: 12px 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
}
.creds-box strong { font-family: var(--font-mono); font-weight: 600; }

/* Case "appliquer à toutes les boutiques" */
.apply-all-wrap {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin-top: 20px !important;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--ink) !important;
}
.apply-all-wrap input { width: auto !important; }

/* Champ logo (téléversement + aperçu) */
.logo-field { margin-top: 4px; }
.logo-preview {
  max-height: 64px;
  max-width: 180px;
  display: block;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  background: var(--bg);
  object-fit: contain;
}
.logo-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.admin-section .logo-upload-btn {
  display: inline-block;
  cursor: pointer;
  margin: 0;
  padding: 9px 14px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
}
.admin-section .logo-url-input {
  width: auto;
  flex: 1;
  min-width: 150px;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg);
}
.admin-section button.logo-clear {
  margin: 0;
  padding: 8px 12px;
  background: var(--bg-subtle);
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 500;
  font-size: 13px;
}
.admin-section button.logo-clear:hover { background: #FEE2E2; color: var(--error); }

/* Options d'affichage du logo (admin) */
.logo-options {
  margin: 8px 0 4px;
  padding: 14px 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.logo-options label.opt-check {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  margin-top: 10px;
}
.logo-options input[type="checkbox"] { width: auto !important; margin: 0; }
.logo-options input[type="range"] { width: 100%; margin: 4px 0 6px; }
.logo-options .range-val { color: var(--accent); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 1000;
  animation: fadeUp 0.3s ease-out;
}

/* ============================================
   POPUP (modale accès gérant)
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 2000;
  animation: fadeUp 0.2s ease-out;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--ink);
}

.modal-sub { color: var(--muted); font-size: 14px; margin-bottom: 16px; }

.modal-creds {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
}

.cred-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 14px;
}
.cred-line span { color: var(--muted); flex: none; }
.cred-line strong {
  font-family: var(--font-mono);
  font-weight: 600;
  word-break: break-all;
  text-align: right;
}

.modal-actions { display: flex; gap: 10px; }
.modal-actions button {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
}
.modal-copy { background: var(--accent); color: #fff; }
.modal-copy:hover { filter: brightness(1.1); }
.modal-close { background: var(--bg-subtle); color: var(--ink); border: 1px solid var(--line) !important; }
.modal-close:hover { background: var(--line); }

/* ============================================
   RESPONSIVE / MOBILE
   ============================================ */
@media (max-width: 600px) {
  .site-header { padding: 16px 20px; }
  .site-footer { padding: 20px; }
  .hero { padding: 48px 20px; }
  .track-page { padding: 32px 18px 60px; }
  .reassure { flex-direction: column; align-items: center; gap: 12px; }
  .admin-page { padding: 24px 16px; }
  .admin-section { padding: 18px 16px; }
  .track-form button { width: 100%; }
  .modal { padding: 22px 18px; }
}

@media (max-width: 520px) {
  /* Champs de remplacement empilés sur petit écran */
  .rule-row { flex-wrap: wrap; }
  .rule-row .rule-from,
  .rule-row .rule-to { flex: 1 1 100%; }
  .rule-arrow { display: none; }
  .rule-row .rule-del { margin-left: auto; }
  /* Accès dans le popup : libellé au-dessus de la valeur */
  .cred-line { flex-direction: column; gap: 2px; }
  .cred-line strong { text-align: left; }
}

/* Tablette / mobile : la page de suivi repasse en 1 colonne (numéro -> carte -> étapes) */
@media (max-width: 768px) {
  .track-inner { max-width: var(--max-w); }
  .track-grid {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "side" "timeline";
    gap: 0;
  }
  .track-grid .track-side { position: static; margin-bottom: 8px; }
  .track-grid .track-header { margin-bottom: 24px; padding-bottom: 20px; }
}
