/* REVENTE — CRM */
:root {
  --bg: #0e1116;
  --bg2: #151a22;
  --bg3: #1d242f;
  --border: #28303d;
  --text: #e8ecf2;
  --muted: #8b95a5;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, .14);
  --green: #34c98e;
  --green-soft: rgba(52, 201, 142, .13);
  --red: #ff5d6c;
  --red-soft: rgba(255, 93, 108, .12);
  --orange: #ffb054;
  --orange-soft: rgba(255, 176, 84, .13);
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 15px; -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea {
  font: inherit; font-size: 16px; /* ≥16px : évite le zoom auto d'iOS sur les champs */
  color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type="number"] { -moz-appearance: textfield; }
::placeholder { color: #5b6577; }

.app { display: flex; height: 100vh; }

/* ─── Sidebar ─── */
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 20px; }
.brand-icon { font-size: 24px; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand-user { font-size: 11px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.ws-switch { padding: 0 4px 12px; }
.ws-switch select {
  background: var(--bg3); border-color: var(--border); font-size: 13.5px; font-weight: 600;
  padding: 8px 10px; cursor: pointer;
}
.team-block { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.team-block-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; margin-bottom: 8px; flex-wrap: wrap; }
.auth-user { text-align: center; font-size: 17px !important; letter-spacing: normal !important; font-weight: 600 !important; margin-bottom: 10px; }
.nav-btn {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 10px;
  color: var(--muted); font-weight: 500; text-align: left; transition: all .15s;
}
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent); }
.nav-btn .ico { width: 20px; text-align: center; font-size: 16px; }
.nav-sale { background: var(--accent); color: #fff !important; margin: 8px 0; }
.nav-sale:hover { background: #3d7bf0; }
.nav-sale.active { background: var(--accent); color: #fff; }
.nav-spacer { flex: 1; }

/* ─── Contenu ─── */
.content { flex: 1; overflow-y: auto; padding: 28px 32px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 14px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 700; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ─── Boutons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 10px;
  background: var(--bg3); border: 1px solid var(--border); font-weight: 600; font-size: 14px;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #3d7bf0; }
.btn-green { background: var(--green); border-color: var(--green); color: #06281c; }
.btn-green:hover { filter: brightness(1.08); }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: var(--red-soft); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-big { padding: 15px 22px; font-size: 16px; border-radius: 12px; width: 100%; justify-content: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ─── Cartes stats ─── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 26px; font-weight: 750; margin-top: 7px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat-sub .pos { color: var(--green); font-weight: 600; }
.stat-card.hl { border-color: rgba(79,140,255,.4); background: linear-gradient(135deg, var(--bg2), rgba(79,140,255,.07)); }
.stat-card.net { border-color: rgba(52,201,142,.4); background: linear-gradient(135deg, var(--bg2), rgba(52,201,142,.07)); }
.stat-card.net .stat-value { color: var(--green); }
.stat-card.net .stat-value.neg { color: var(--red); }
.stat-sub .frais { color: var(--red); font-weight: 600; }

/* ─── Panneaux ─── */
.panel { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.panel-title { font-weight: 700; font-size: 15px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.two-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 980px) { .two-cols { grid-template-columns: 1fr; } }

/* ─── Graphique barres ─── */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 10px; }
.chart .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 5px; min-width: 0; }
.chart .bar { width: 100%; max-width: 26px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; transition: filter .15s; position: relative; }
.chart .bar.empty { background: var(--bg3); }
.chart .bar:hover { filter: brightness(1.25); }
.chart .bar-label { font-size: 9.5px; color: var(--muted); white-space: nowrap; }

/* ─── Listes / tableaux ─── */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 11px 10px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.row-click { cursor: pointer; }
tr.row-click:hover td { background: var(--bg3); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
th.num { text-align: right; }

/* ─── Produits (grille) ─── */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 13px; }
.product-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: all .15s; position: relative;
}
.product-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.product-card.out { opacity: .45; cursor: not-allowed; }
.product-photo {
  width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--bg3);
}
.product-photo-placeholder {
  width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 38px; background: var(--bg3); color: #47506080;
}
.product-info { padding: 11px 12px 13px; }
.product-name { font-weight: 650; font-size: 14px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.product-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; }
.product-price { font-weight: 700; color: var(--accent); font-size: 15px; }
.stock-badge { font-size: 12px; font-weight: 650; padding: 2.5px 8px; border-radius: 20px; background: var(--green-soft); color: var(--green); }
.stock-badge.low { background: var(--orange-soft); color: var(--orange); }
.stock-badge.zero { background: var(--red-soft); color: var(--red); }
.card-qty {
  position: absolute; top: 8px; right: 8px; background: var(--accent); color: #fff;
  min-width: 26px; height: 26px; border-radius: 20px; display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 13.5px; padding: 0 7px;
  box-shadow: 0 3px 10px rgba(0,0,0,.4);
}

/* ─── Panier de vente ─── */
.cart-line { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.cart-line:last-of-type { border-bottom: none; }
.cart-thumb { width: 42px; height: 42px; border-radius: 9px; object-fit: cover; background: var(--bg3); flex-shrink: 0; }
.cart-thumb-ph { width: 42px; height: 42px; border-radius: 9px; background: var(--bg3); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.cart-name { flex: 1; min-width: 0; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-name small { display: block; color: var(--muted); font-weight: 500; font-size: 11.5px; margin-top: 1px; }
.qty-ctl { display: flex; align-items: center; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.qty-ctl button { width: 27px; height: 27px; border-radius: 7px; font-size: 16px; font-weight: 700; color: var(--muted); }
.qty-ctl button:hover { background: var(--bg3); color: var(--text); }
.qty-ctl .q { min-width: 26px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.price-input { width: 76px !important; text-align: right; padding: 6px 8px !important; font-weight: 600; font-variant-numeric: tabular-nums; }
.price-input.discounted { border-color: var(--orange); color: var(--orange); }
.price-input.premium { border-color: var(--green); color: var(--green); }
.cart-total-row { display: flex; justify-content: space-between; padding: 8px 0 4px; font-size: 14px; color: var(--muted); }
.cart-total-row.grand { font-size: 19px; font-weight: 750; color: var(--text); border-top: 1px solid var(--border); padding-top: 13px; margin-top: 7px; }
.cart-total-row .pos { color: var(--green); }

/* ─── Recherche & filtres ─── */
.searchbar { position: relative; flex: 1; max-width: 380px; }
.searchbar input { padding-left: 38px; }
.searchbar::before { content: '⌕'; position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 18px; }
.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { padding: 7px 14px; border-radius: 20px; background: var(--bg2); border: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--muted); transition: all .12s; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ─── Modale ─── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 8, 12, .72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 18px;
  width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto; padding: 24px; box-shadow: var(--shadow);
}
.modal h2 { font-size: 18px; margin-bottom: 18px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.modal-actions .btn-danger { margin-right: auto; }

/* ─── Upload photo ─── */
.photo-drop {
  border: 2px dashed var(--accent); border-radius: 12px; padding: 20px 14px; text-align: center;
  cursor: pointer; color: var(--accent); font-size: 14px; font-weight: 600;
  background: var(--accent-soft); transition: all .15s; position: relative; overflow: hidden;
}
.photo-drop:has(img) { background: transparent; border-color: var(--border); padding: 10px; }
.photo-drop:hover { border-color: var(--accent); color: var(--accent); }
.photo-drop img { max-width: 100%; max-height: 140px; border-radius: 8px; display: block; margin: 0 auto; }
.photo-drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ─── Divers ─── */
.empty-state { text-align: center; color: var(--muted); padding: 44px 20px; }
.empty-state .big { font-size: 40px; margin-bottom: 12px; }
.margin-pos { color: var(--green); font-weight: 600; }
.margin-neg { color: var(--red); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--bg3); }
.pill-warn { background: var(--orange-soft); color: var(--orange); }
a.contact-pill { text-decoration: none; color: var(--text); transition: all .12s; display: inline-block; margin: 1px 0; }
a.contact-pill:hover { background: var(--accent-soft); color: var(--accent); }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 14px; cursor: pointer; user-select: none; }
.check-row input { width: auto; accent-color: var(--accent); transform: scale(1.15); }
.unpaid-panel { border-color: rgba(255,176,84,.45); }
.promo-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--green-soft); border: 1px solid rgba(52,201,142,.4);
  border-radius: 10px; padding: 10px 13px; font-size: 13.5px; margin-bottom: 14px;
}
.send-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.receipt-preview { width: 100%; border-radius: 14px; margin-top: 14px; border: 1px solid var(--border); }
.pill-restock { background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.insights-panel { border-color: rgba(79,140,255,.35); }
textarea { resize: vertical; min-height: 60px; line-height: 1.45; }
.low-stock-list .item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.low-stock-list .item:last-child { border-bottom: none; }

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 13px 22px; border-radius: 12px; font-weight: 600; z-index: 200;
  box-shadow: var(--shadow); animation: toastIn .25s ease;
}
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ─── Écran de verrouillage (PIN) ─── */
.auth-screen {
  position: fixed; inset: 0; background: var(--bg); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-box { width: 100%; max-width: 320px; text-align: center; }
.auth-logo { font-size: 54px; margin-bottom: 12px; }
.auth-box h1 { font-size: 22px; margin-bottom: 8px; }
.auth-box p { color: var(--muted); font-size: 14px; margin-bottom: 24px; line-height: 1.5; }
.auth-box input {
  text-align: center; font-size: 24px !important; letter-spacing: 10px;
  font-weight: 700; margin-bottom: 12px; padding: 14px;
}
.auth-err { color: var(--red); font-size: 13.5px; min-height: 20px; margin-bottom: 10px; font-weight: 600; }
.auth-switch { display: block; margin: 16px auto 0; color: var(--accent); font-size: 13.5px; font-weight: 600; }
.auth-switch:hover { text-decoration: underline; }
.invite-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  border-color: rgba(79,140,255,.45); background: linear-gradient(135deg, var(--bg2), rgba(79,140,255,.08));
}

/* ─── Responsive mobile ─── */
@media (max-width: 760px) {
  .app { flex-direction: column; height: 100dvh; }
  .content { padding: 16px 14px 100px; -webkit-overflow-scrolling: touch; }

  /* Navigation en barre du bas, façon application */
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; width: 100%;
    flex-direction: row; align-items: stretch; gap: 2px;
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
    overflow-x: auto; border-right: none; border-top: 1px solid var(--border);
    background: rgba(21, 26, 34, .96); backdrop-filter: blur(12px);
  }
  .brand, .nav-spacer { display: none; }
  .nav-btn {
    flex-direction: column; align-items: center; gap: 3px; flex-shrink: 0;
    padding: 8px 11px; font-size: 10.5px; border-radius: 12px;
  }
  .nav-btn .ico { font-size: 19px; width: auto; }
  .nav-sale { margin: 0; }

  .page-head { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 16px; }
  .page-title { font-size: 21px; }
  .searchbar { max-width: none; }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 21px; }

  .two-cols { grid-template-columns: 1fr; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .panel { padding: 14px; overflow-x: auto; }
  .panel table { min-width: 560px; }
  th, td { padding: 9px 8px; font-size: 13.5px; }
  .chart .bar-label { font-size: 8px; }

  /* Modales en feuille qui monte du bas */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    max-width: none; border-radius: 20px 20px 0 0; max-height: 92dvh;
    padding: 22px 18px calc(24px + env(safe-area-inset-bottom));
  }
  .btn { padding: 12px 16px; }
  .btn-sm { padding: 9px 13px; }

  /* Boutons des fiches : empilés en pleine largeur, action principale en premier */
  .modal-actions { flex-direction: column-reverse; gap: 9px; }
  .modal-actions .btn { width: 100%; justify-content: center; padding: 14px; font-size: 15px; }
  .modal-actions .btn-danger { margin-right: 0; }
  .send-actions .btn { flex: 1 1 45%; justify-content: center; padding: 13px 10px; }
  .form-grid-2 { grid-template-columns: 1fr; gap: 0; }
}
