:root {
  --primary: #5B4FE8;
  --primary-dark: #3B2FB0;
  --accent: #FF8A3D;
  --bg: #f2f6fa;
  --card-bg: #ffffff;
  --text: #101820;
  --text-muted: #6b7684;
  --border: #e3e8ee;
  --success: #16a34a;
  --danger: #e2483d;
  --radius: 20px;
  --shadow: 0 10px 30px rgba(10, 40, 70, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app-shell { min-height: 100vh; }

.screen {
  display: none;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  background: var(--card-bg);
  animation: fadeIn 0.25s ease;
}
.screen.active { display: flex; }

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

@media (min-width: 640px) {
  body { background: #e6edf3; }
  .app-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 64px 24px;
  }
  .screen.active {
    max-width: 420px;
    width: 100%;
    min-height: 740px;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(10, 40, 70, 0.16);
    overflow: hidden;
  }
}

.header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 18px 20px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.header .logo { height: 30px; display: block; }
.header.with-back { padding-top: 14px; }

.back-btn {
  background: rgba(255,255,255,0.18);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-btn:active { background: rgba(255,255,255,0.32); }

.header-title { font-size: 17px; font-weight: 700; }
.header-icons { margin-left: auto; display: flex; gap: 14px; font-size: 18px; }
.icon-inert { opacity: 0.85; cursor: default; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.content::-webkit-scrollbar { width: 0; }

/* ---------- Login ---------- */
.login-screen {
  background: linear-gradient(160deg, var(--primary), var(--primary-dark));
}
.login-screen .content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 40px 24px;
  color: #fff;
}
.login-logo-big { height: 46px; margin-bottom: 10px; }
.login-title { font-size: 20px; font-weight: 800; }
.login-sub { color: rgba(255,255,255,0.85); font-size: 14px; margin-top: -8px; }

.phone-field {
  width: 100%;
  text-align: left;
}
.phone-field label {
  display: block;
  font-size: 12.5px;
  color: rgba(255,255,255,0.85);
  margin-bottom: 6px;
  font-weight: 600;
}
.phone-input-wrap {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.14);
  border: 1.5px solid rgba(255,255,255,0.35);
  border-radius: 14px;
  overflow: hidden;
}
.phone-input-wrap span {
  padding: 13px 10px 13px 14px;
  font-weight: 700;
  color: #fff;
}
.phone-input-wrap input {
  flex: 1;
  padding: 13px 14px 13px 4px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 15px;
  outline: none;
}
.phone-input-wrap input::placeholder { color: rgba(255,255,255,0.6); }

.pin-dots-row {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin: 6px 0 4px;
}
.pin-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.7);
  background: transparent;
  transition: background 0.15s ease;
}
.pin-dot.filled { background: #fff; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 280px;
  margin: 10px auto 0;
}
.key-btn {
  padding: 16px 0;
  border-radius: 16px;
  border: none;
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}
.key-btn:active { background: rgba(255,255,255,0.3); }
.key-btn.key-empty { background: transparent; cursor: default; }
.key-btn.key-empty:active { background: transparent; }

.keypad.on-light .key-btn {
  background: #f4f6f9;
  color: var(--text);
}
.keypad.on-light .key-btn:active { background: #e6eaf0; }

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: transform 0.05s ease, opacity 0.15s ease;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-light { background: rgba(255,255,255,0.16); color: #fff; }
.btn-secondary { background: #eef3f8; color: var(--text); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-link { background: none; border: none; color: var(--primary); font-weight: 700; cursor: pointer; padding: 0; font-family: inherit; }

.field { width: 100%; text-align: left; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.field input, .field select {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  font-size: 15px;
  background: #fafbfc;
  outline: none;
  font-family: inherit;
}
.field input:focus, .field select:focus { border-color: var(--primary); background: #fff; }

/* ---------- Accueil ---------- */
.greeting { font-size: 13.5px; opacity: 0.9; }
.greeting-name { font-size: 18px; font-weight: 700; margin-top: 2px; }

.home-hero {
  background: linear-gradient(160deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 14px 20px 40px;
  text-align: center;
}
.home-hero-top { display: flex; justify-content: flex-start; font-size: 19px; }
.balance-hero { font-size: 32px; font-weight: 800; margin: 18px 0 4px; }
.holder-hero { font-size: 12.5px; opacity: 0.85; margin-bottom: 18px; }

.qr-hero {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.14);
  background-image: radial-gradient(rgba(255,255,255,0.4) 1.5px, transparent 1.5px);
  background-size: 14px 14px;
  border-radius: 22px;
  padding: 18px 22px 16px;
  position: relative;
  cursor: pointer;
}
.qr-hero-box {
  width: 132px;
  height: 132px;
  background: #fff;
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}
.qr-hero-box svg { width: 100%; height: 100%; display: block; }
.qr-hero-scan {
  font-size: 12.5px;
  font-weight: 700;
  background: rgba(255,255,255,0.92);
  color: var(--primary-dark);
  padding: 4px 14px;
  border-radius: 20px;
}
.qr-hero-badge {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
  padding: 6px;
  object-fit: contain;
}

.home-actions-card {
  background: var(--card-bg);
  margin: -26px 16px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  padding: 16px 4px;
  position: relative;
  z-index: 1;
}
.home-action { flex: 1; text-align: center; cursor: pointer; }
.home-action.disabled { opacity: 0.4; cursor: default; }
.home-action-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  margin: 0 auto 6px;
  color: #fff;
}
.home-action-icon.send { background: #3E7BFA; }
.home-action-icon.payments { background: #FF8A3D; }
.home-action-icon.airtime { background: #22C1E8; }
.home-action-label { font-size: 11.5px; font-weight: 700; }
.home-action .home-action-label { color: #3E7BFA; }
.home-action:has(.payments) .home-action-label { color: #FF8A3D; }
.home-action:has(.airtime) .home-action-label { color: #22C1E8; }
.home-action.disabled .home-action-label { opacity: 0.55; }

.section-title { font-size: 14px; font-weight: 700; margin: 4px 0 10px; color: var(--text); }

.tx-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.tx-item:last-child { border-bottom: none; }
.tx-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: #eaf6fd;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.tx-info { flex: 1; min-width: 0; }
.tx-name { font-size: 14px; font-weight: 600; }
.tx-date { font-size: 12px; color: var(--text-muted); }
.tx-amount { font-size: 14px; font-weight: 700; white-space: nowrap; }
.tx-amount.neg { color: var(--danger); }
.tx-amount.pos { color: var(--success); }

/* ---------- Choix du mode d'envoi ---------- */
.mode-tabs {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 18px;
}
.mode-tab {
  flex: 1;
  padding: 12px;
  text-align: center;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  background: #fff;
  color: var(--text);
}
.mode-tab.active { background: var(--primary); color: #fff; }

/* ---------- Contacts ---------- */
.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.contact-item.selected { border-color: var(--primary); background: #eaf6fd; }
.contact-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 14.5px; font-weight: 700; }
.contact-phone { font-size: 12.5px; color: var(--text-muted); }

.add-contact-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border: 1.5px dashed var(--primary);
  border-radius: 14px;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  background: #f2faff;
  margin-bottom: 6px;
}

/* ---------- QR ---------- */
.qr-viewfinder {
  width: 220px;
  height: 220px;
  margin: 20px auto;
  border-radius: 20px;
  background: #0e2230;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#qrVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.qr-frame {
  width: 160px;
  height: 160px;
  border: 3px solid var(--accent);
  border-radius: 16px;
  position: relative;
  z-index: 1;
}
.qr-scanline {
  position: absolute;
  left: 6px; right: 6px;
  height: 3px;
  background: var(--accent);
  top: 0;
  animation: scan 1.6s ease-in-out infinite;
  border-radius: 2px;
}
@keyframes scan {
  0% { top: 6px; }
  50% { top: 150px; }
  100% { top: 6px; }
}
.qr-hint { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 4px; }

/* ---------- Recevoir (mon QR code) ---------- */
.qr-display {
  display: flex;
  justify-content: center;
  margin: 14px 0 10px;
}
.my-qr-code {
  background: #ffffff;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0,0,0,0.06);
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.my-qr-code svg { width: 100%; height: 100%; }
.receive-identity { text-align: center; }
.receive-name { font-weight: 700; font-size: 17px; }
.receive-phone { color: var(--text-muted); font-size: 14px; margin-top: 2px; }
.receive-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.receive-actions .btn { flex: 1; }

/* ---------- Montant ---------- */
.amount-display { text-align: center; padding: 20px 0 6px; }
.amount-input {
  font-size: 40px;
  font-weight: 800;
  border: none;
  background: none;
  text-align: center;
  width: 100%;
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.amount-currency { font-size: 15px; color: var(--text-muted); font-weight: 700; }

.info-banner {
  background: #eaf6fd;
  border: 1px solid #bfe6fa;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: #0c5a80;
  margin-bottom: 14px;
  display: flex;
  gap: 8px;
}
.info-banner.warn {
  background: #fff7e6;
  border-color: #ffe1a8;
  color: #8a5a00;
}

/* ---------- Récap ---------- */
.recap-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  gap: 12px;
}
.recap-row:last-child { border-bottom: none; }
.recap-label { color: var(--text-muted); }
.recap-value { font-weight: 700; text-align: right; }
.recap-total {
  margin-top: 10px;
  padding-top: 14px;
  border-top: 2px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 800;
}

/* ---------- PIN de confirmation ---------- */
.pin-screen .content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* ---------- Chargement ---------- */
.loading-screen .content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
}
.spinner {
  width: 50px; height: 50px;
  border: 5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Succès ---------- */
.success-screen .content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 28px;
}
.success-check {
  width: 82px; height: 82px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 40px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 18px;
  animation: pop 0.35s ease;
}
@keyframes pop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}
.success-title { font-size: 19px; font-weight: 800; margin-bottom: 4px; }
.success-sub { font-size: 13.5px; color: var(--text-muted); margin-bottom: 20px; }
.receipt-card {
  width: 100%;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  text-align: left;
  margin-bottom: 20px;
}
.success-actions { width: 100%; display: flex; flex-direction: column; gap: 10px; }

.hint { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 6px; }

/* ---------- Notifications (remplacent les alert() natives) ---------- */
.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: #101820;
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: var(--success); }

/* ---------- Page Admin ---------- */
.admin-wrap { max-width: 560px; margin: 0 auto; padding: 24px 20px 60px; }
.admin-header { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.admin-header a { color: var(--primary); text-decoration: none; font-weight: 700; font-size: 14px; }
.admin-title { font-size: 20px; font-weight: 800; margin: 0; }
.admin-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.admin-card h2 { font-size: 15px; margin: 0 0 14px; }
.color-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.color-field label { display: block; font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.color-field input[type="color"] {
  width: 100%; height: 42px; border: 1.5px solid var(--border); border-radius: 10px; padding: 2px; background: #fff; cursor: pointer;
}
.preset-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.preset-btn {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px;
  border: 1.5px solid var(--border); background: #fafbfc; font-size: 12.5px; font-weight: 600; cursor: pointer; color: var(--text);
}
.preset-btn:hover { border-color: var(--primary); }
.preset-swatch { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.logo-preview-box {
  display: flex; align-items: center; gap: 16px; padding: 14px; border: 1.5px dashed var(--border); border-radius: 12px; margin-bottom: 14px;
}
.logo-preview-box img { max-height: 40px; max-width: 140px; background: #10202c; padding: 6px 10px; border-radius: 8px; }
.save-bar { position: sticky; bottom: 0; background: var(--bg); padding: 14px 0 0; display: flex; gap: 10px; }
.save-msg { text-align: center; font-size: 13px; color: var(--success); font-weight: 700; margin-top: 10px; display: none; }
.disclaimer {
  font-size: 11.5px; color: var(--text-muted); background: #fff7e6; border: 1px solid #ffe1a8; border-radius: 10px; padding: 10px 12px; margin-top: 12px;
}
