/* ============ MonkoTrack — feuille de style ============ */

:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #101828;
  --muted: #667085;
  --border: #e4e7ec;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff4ff;
  --danger: #dc2626;
  --danger-text: #dc2626;
  --success: #16a34a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px -12px rgba(16, 24, 40, .12);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --card: #161b22;
    --text: #e6edf3;
    --muted: #8b949e;
    --border: #2d333b;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-soft: #14233f;
    --danger-text: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
  }
}

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

/* L'attribut hidden doit gagner même sur les éléments avec display défini (modale, toast). */
[hidden] { display: none !important; }

html { color-scheme: light dark; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

.container { max-width: 1040px; margin: 0 auto; padding: 0 20px; width: 100%; }

.muted { color: var(--muted); }
.center { text-align: center; }
.mono { font-family: "Cascadia Code", Consolas, monospace; letter-spacing: .04em; }

/* ---------- En-tête ---------- */

.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 62px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.brand b { color: var(--accent); }

.brand-logo { font-size: 1.5rem; }

.main-nav { display: flex; gap: 6px; }

.main-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  transition: background .15s, color .15s;
}

.main-nav a:hover { color: var(--text); background: var(--bg); }

.main-nav a.active { color: var(--accent); background: var(--accent-soft); }

/* Bouton « Déconnexion » de l'admin (formulaire POST) : même apparence que les liens du menu. */
.logout-form { display: inline; margin: 0; }

.nav-logout {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: var(--muted);
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  transition: background .15s, color .15s;
}

.nav-logout:hover { color: var(--text); background: var(--bg); }

.header-right { display: flex; align-items: center; gap: 12px; }

.lang-select {
  font-family: inherit;
  font-size: .9rem;
  font-weight: 500;
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

.lang-select:hover { border-color: var(--accent); }

/* ---------- Héros / recherche ---------- */

.hero {
  padding: 64px 0 48px;
  text-align: center;
  background:
    radial-gradient(600px 220px at 30% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent),
    radial-gradient(600px 220px at 70% 0%, color-mix(in srgb, var(--accent) 7%, transparent), transparent);
}

.hero h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); margin-bottom: 10px; }

.hero-sub { color: var(--muted); margin-bottom: 28px; }

.track-form {
  display: flex;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}

.track-form input {
  flex: 1;
  padding: 14px 18px;
  font-size: 1.05rem;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .05em;
  min-width: 0;
}

.track-form input::placeholder { text-transform: none; letter-spacing: normal; color: var(--muted); }

.track-form input:focus,
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font-size: .95rem;
  font-weight: 600;
  font-family: inherit;
  border: 1.5px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }

.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn.big { padding: 14px 26px; font-size: 1.05rem; border-radius: 12px; }
.btn.small { padding: 7px 12px; font-size: .85rem; }

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--muted);
  transition: background .15s, color .15s;
  line-height: 1;
}

.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.icon-btn.small { font-size: .8rem; padding: 4px 6px; }

/* ---------- Cartes ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 32px;
}

.not-found, .empty-state { text-align: center; padding: 48px 28px; }

.nf-icon { font-size: 2.6rem; margin-bottom: 12px; }

.not-found h2 { margin-bottom: 8px; }
.not-found p { color: var(--muted); }

.empty-state p { color: var(--muted); margin-bottom: 18px; }

/* ---------- Résultat de suivi ---------- */

.result-card { animation: fadeUp .3s ease; }

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

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.result-label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; }

.result-id { font-family: "Cascadia Code", Consolas, monospace; letter-spacing: .05em; font-size: 1.5rem; }

.result-head-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.alert {
  background: color-mix(in srgb, #f59e0b 14%, transparent);
  border: 1px solid color-mix(in srgb, #f59e0b 40%, transparent);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 20px;
}

.alert.danger {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border-color: color-mix(in srgb, var(--danger) 55%, transparent);
}

.alert.success {
  background: color-mix(in srgb, var(--success) 12%, transparent);
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
}

/* ---------- Badges de statut ---------- */

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge.big { padding: 7px 16px; font-size: .95rem; }

.status-created   { background: color-mix(in srgb, #6b7280 16%, transparent); color: #6b7280; }
.status-preparing { background: color-mix(in srgb, #d97706 16%, transparent); color: #b45309; }
.status-shipped   { background: color-mix(in srgb, #6366f1 16%, transparent); color: #4f46e5; }
.status-transit   { background: color-mix(in srgb, #3b82f6 16%, transparent); color: #2563eb; }
.status-delivery  { background: color-mix(in srgb, #8b5cf6 16%, transparent); color: #7c3aed; }
.status-delivered { background: color-mix(in srgb, #22c55e 16%, transparent); color: #15803d; }
.status-problem   { background: color-mix(in srgb, #ef4444 16%, transparent); color: #dc2626; }
.status-customs   { background: #dc2626; color: #fff; }

@media (prefers-color-scheme: dark) {
  .status-created   { color: #9ca3af; }
  .status-preparing { color: #fbbf24; }
  .status-shipped   { color: #a5b4fc; }
  .status-transit   { color: #93c5fd; }
  .status-delivery  { color: #c4b5fd; }
  .status-delivered { color: #86efac; }
  .status-problem   { color: #fca5a5; }
}

.service-standard { background: color-mix(in srgb, #6b7280 12%, transparent); color: #6b7280; }
.service-express  { background: color-mix(in srgb, #f97316 16%, transparent); color: #c2410c; }

@media (prefers-color-scheme: dark) {
  .service-standard { color: #9ca3af; }
  .service-express  { color: #fdba74; }
}

/* ---------- Étapes de progression ---------- */

.steps {
  display: flex;
  margin: 28px 0 32px;
}

.step { flex: 1; text-align: center; position: relative; }

.step::before {
  content: "";
  position: absolute;
  top: 15px;
  left: -50%;
  width: 100%;
  height: 3px;
  background: var(--border);
}

.step:first-child::before { display: none; }

.step.done::before, .step.current::before { background: var(--accent); }

.step-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--card);
  border: 3px solid var(--border);
  margin: 0 auto 8px;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
}

.step.done .step-dot { background: var(--accent); border-color: var(--accent); }

.step.current .step-dot {
  border-color: var(--accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 20%, transparent);
}

.step-label { font-size: .78rem; color: var(--muted); padding: 0 4px; }

.step.done .step-label, .step.current .step-label { color: var(--text); font-weight: 600; }

/* Étape « saisie douane » : toujours en rouge. */
.step.alert-step .step-dot { border-color: var(--danger); }
.step.alert-step .step-label { color: var(--danger-text); font-weight: 600; }
.step.alert-step.done::before, .step.alert-step.current::before { background: var(--danger); }
.step.alert-step.done .step-dot { background: var(--danger); border-color: var(--danger); }
.step.alert-step.current .step-dot {
  background: var(--danger);
  border-color: var(--danger);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--danger) 25%, transparent);
}

/* ---------- Détails ---------- */

.details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}

.detail {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail span { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.section-title { margin-bottom: 18px; font-size: 1.15rem; }

/* ---------- Chronologie ---------- */

.timeline { position: relative; padding-left: 30px; }

.timeline::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--border);
}

.tl-item { position: relative; padding-bottom: 22px; }

.tl-item:last-child { padding-bottom: 0; }

.tl-dot {
  position: absolute;
  left: -28px;
  top: 5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--card);
  border: 3px solid var(--muted);
}

.tl-item.latest .tl-dot {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}

.tl-item.problem .tl-dot { border-color: var(--danger); }

.tl-item.latest.problem .tl-dot {
  background: var(--danger);
  border-color: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 20%, transparent);
}

.tl-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }

.tl-date { color: var(--muted); font-size: .88rem; }

.tl-desc { font-size: .95rem; }

.tl-loc { color: var(--muted); font-size: .88rem; }

/* ---------- Pied de page ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
}

.site-footer a { color: var(--muted); }

/* ---------- Notifications ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 22px;
  border-radius: 999px;
  font-size: .92rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: fadeUp .25s ease;
}

/* ---------- Panel d'administration ---------- */

.admin-main { padding-top: 36px; }

.admin-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.admin-title-row h1 { font-size: 1.6rem; }
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-tile.warn .stat-value { color: var(--danger); }

.stat-value { font-size: 1.7rem; font-weight: 700; }

.stat-label { color: var(--muted); font-size: .88rem; }

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.toolbar input[type="search"] {
  flex: 1;
  min-width: 220px;
  max-width: 420px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
}

.toolbar-actions { display: flex; gap: 8px; }

.table-wrap { overflow-x: auto; }

.ship-table { width: 100%; border-collapse: collapse; font-size: .93rem; }

.ship-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.ship-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.ship-table tbody tr:last-child td { border-bottom: none; }

.ship-table tbody tr:hover td { background: color-mix(in srgb, var(--accent) 4%, transparent); }

.td-id { font-weight: 600; }

.td-date { color: var(--muted); white-space: nowrap; }

.td-actions, .th-actions { text-align: right; white-space: nowrap; }

.status-select {
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  max-width: 190px;
}

.status-select.status-delivered { border-color: color-mix(in srgb, var(--success) 50%, transparent); }
.status-select.status-problem   { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.status-select.status-customs   { border-color: var(--danger); color: var(--danger-text); }

/* La liste déroulante ouverte garde des couleurs normales, quelle que soit la couleur du statut affiché. */
.status-select option { color: var(--text); background: var(--card); }

/* ---------- Fenêtre modale ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 12, 20, .55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px 16px;
  z-index: 100;
  overflow-y: auto;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 640px;
  animation: fadeUp .22s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.2rem; }

.modal-body { padding: 22px 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

.field input, .field textarea, .field select {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  resize: vertical;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

.id-row { display: flex; gap: 8px; }

.id-row input {
  flex: 1;
  font-family: "Cascadia Code", Consolas, monospace;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}

.id-row input[readonly] { opacity: .7; }

.events-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 8px;
}

.events-section legend {
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0 8px;
}

.events-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.event-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .88rem;
}

.ev-info { flex: 1; color: var(--muted); min-width: 0; }

.event-add-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.event-add-grid #ev-location { grid-column: 1 / -1; }

.event-add-grid select, .event-add-grid input {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  min-width: 0;
}

/* ---------- Connexion à l'admin ---------- */

.login-card {
  max-width: 380px;
  margin: 64px auto 32px;
  padding: 32px 28px;
}

.login-card h1 { font-size: 1.4rem; text-align: center; margin-bottom: 22px; }

.login-card label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

/* 1rem minimum : sous iOS, un champ plus petit fait zoomer la page à la saisie. */
.login-card input[type="password"] {
  display: block;
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

.login-card .btn { display: flex; width: 100%; margin-top: 18px; padding: 12px 18px; font-size: 1rem; }

.login-error {
  color: var(--danger-text);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 18px 0;
  font-size: .9rem;
}

.login-card > :last-child, .login-card form > :last-child { margin-bottom: 0; }

/* ---------- Adaptation mobile ---------- */

@media (max-width: 640px) {
  .track-form { flex-direction: column; }
  .step-label { display: none; }
  .card { padding: 20px 16px; }
  .field-grid, .event-add-grid { grid-template-columns: 1fr; }
  .header-inner { height: auto; padding: 10px 20px; flex-wrap: wrap; gap: 8px; }
  .header-right { gap: 8px; flex-wrap: wrap; }
  .main-nav a, .nav-logout { padding: 8px 10px; }
  .hero { padding: 40px 0 32px; }
  .login-card { margin-top: 32px; padding: 24px 20px; }
}
