:root {
  --bg: #F0F0F3;
  --card: #FFFFFF;
  --border: #E7E7EC;
  --text: #1F2024;
  --sub: #8A8A93;
  --accent: #D7F547;
  --accent-text: #1F2024;
  --primary: #1F2024;
  --primary-hover: #37383D;
  --chip: #F1F1F4;
  --danger: #C4453B;
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Century Gothic", "Segoe UI", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.app { display: flex; height: 100vh; }

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 220px;
  flex: none;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { font-weight: 700; font-size: 17px; padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}
.nav-item:hover { background: var(--chip); }
.nav-item.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }

/* ---------------- Main / Topbar ---------------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px 10px;
}
.topbar h1 { margin: 0; font-size: 20px; }
.muted { color: var(--sub); }
.small { font-size: 12px; }
.target-picker { display: flex; align-items: center; gap: 8px; }
.target-picker select { min-width: 260px; }

.content { flex: 1; overflow: auto; padding: 10px 28px 28px; }

/* ---------------- Cards / layout ---------------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px;
  margin-bottom: 16px;
}
.toolbar-card { padding: 14px 18px; }
.table-card { padding: 0; overflow-x: auto; }
.table-card .table { min-width: 520px; }

.page { display: none; }
.page.active { display: block; }

.split { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.split-main { flex: 2 1 420px; min-width: 0; }
.split-side { flex: 1 1 260px; min-width: 240px; display: flex; flex-direction: column; gap: 10px; }

/* ---------------- Inputs / buttons ---------------- */
.input, select, .textarea {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--chip);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  outline: none;
}
.textarea { width: 100%; resize: vertical; }
.select-sm { max-width: 220px; }
.filters-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters-row .input:first-child { flex: 1; min-width: 160px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--sub); margin-bottom: 10px; }
label .input, label select, label .textarea { color: var(--text); font-size: 13px; }

.btn {
  font-family: inherit;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: var(--chip); color: var(--text); }
.btn.ghost:hover { background: #e2e2e6; }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn.full { width: 100%; margin-top: 4px; }
.btn.danger { background: #FBEAE8; color: var(--danger); }
.icon-btn {
  border: none; background: var(--chip); border-radius: 999px;
  width: 30px; height: 30px; cursor: pointer; font-size: 13px;
}
.icon-btn:hover { background: #e2e2e6; }

/* ---------------- Table ---------------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--sub); padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #FAFAFC; }
.pv2-base-row td { background: #F0F1F5; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--chip); font-size: 11px; }
.badge.warn { background: #FFF6D8; color: #8A6D00; }
.badge.bad { background: #FBEAE8; color: var(--danger); }
.badge.ok { background: #EAF7DC; color: #4C7A1F; }
.qty-input { width: 48px; text-align: center; }

/* ---------------- Grid (bibliothèque) ---------------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.product-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.product-thumb {
  position: relative;
  height: 120px; background: var(--chip); display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: var(--sub); overflow: hidden;
}
.new-badge { position: absolute; top: 8px; left: 8px; }
.product-select-check {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  width: 18px; height: 18px; cursor: pointer;
}
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-body { padding: 12px 14px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.product-title { font-weight: 600; font-size: 13px; }
.product-meta { font-size: 11px; color: var(--sub); }
.product-actions { display: flex; gap: 6px; padding: 0 14px 12px; }

/* ---------------- Cart ---------------- */
.cart-list { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow: auto; }
#cart-list { max-height: none; overflow: visible; }
.cart-item {
  display: flex; align-items: center; gap: 8px; background: var(--chip);
  border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12px;
}
.cart-item .name { flex: 1; }
.cart-thumb-click { cursor: pointer; line-height: 0; }
.cart-suggestion {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 6px 10px;
  margin: 2px 0 2px 20px; font-size: 12px;
}
.row-clickable { cursor: pointer; }
.row-clickable:hover { background: var(--chip); }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3);
  align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal { width: 700px; max-width: 92vw; max-height: 86vh; overflow: auto; }
.modal.modal-lg { width: 960px; max-height: 90vh; }
.selection-bar:not([hidden]) { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#pf-lines-table input { min-width: 0; width: 100%; }
#pf-lines-table td, #pf-lines-table th { padding: 6px 8px; }
#pf-lines-table td:last-child { white-space: nowrap; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--primary); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Outils page ---------------- */
.outil-card h3 { margin-top: 0; }

/* ---------------- Suggestions (liste + popup de liaison) ---------------- */
.sg-link-count { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.6); color: #fff; padding: 2px 8px; border-radius: 20px; font-size: 11px; }
.sg-compat-ok { color: #3fb950; cursor: default; }
.sg-compat-bad { color: var(--danger); cursor: pointer; }
.sg-compat-reasons { margin: 4px 0 0; padding-left: 18px; }
.sg-direction-choice { display: flex; gap: 14px; margin: 8px 0 10px; font-size: 12px; }
.sg-direction-choice label { display: flex; align-items: center; gap: 5px; cursor: pointer; }

/* ---------------- Responsive (fenêtre réduite) ---------------- */
@media (max-width: 900px) {
  .sidebar { width: 64px; padding: 16px 8px; }
  .brand { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-item span { display: none; }
  .content { padding: 10px 14px 20px; }
  .topbar { padding: 14px 14px 10px; flex-wrap: wrap; gap: 10px; }
  .target-picker select { min-width: 160px; }
  .modal { width: 94vw; }
}

@media (max-width: 600px) {
  .content { padding: 8px 10px 16px; }
  .card { padding: 12px; margin-bottom: 12px; }
  .toolbar-card { padding: 10px 12px; }
  .topbar h1 { font-size: 17px; }
  .topbar p { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .filters-row .input:first-child { min-width: 0; width: 100%; }
  .split { flex-direction: column; }
  .split-main, .split-side { flex-basis: auto; min-width: 0; width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
}

/* ---------------- Import v2 : comparaison importé / BDD ---------------- */
.iv2-photos { display: flex; gap: 10px; margin: 10px 0; }
.iv2-photo-box {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  flex: 1; padding: 6px; border: 1px solid var(--border); border-radius: 8px;
  min-height: 90px; justify-content: center;
}
.iv2-photo-box img { max-width: 100%; max-height: 80px; object-fit: contain; }
.iv2-final-cell { font-weight: 600; }

/* ---------------- Popup détail produit panier ---------------- */
.cim-columns { display: flex; gap: 20px; align-items: flex-start; }
.cim-photo { flex: 0 0 200px; }
.cim-photo img { width: 100%; border-radius: var(--radius-sm); object-fit: cover; background: var(--chip); }
.cim-photo .placeholder { width: 100%; height: 200px; border-radius: var(--radius-sm); background: var(--chip); display: flex; align-items: center; justify-content: center; font-size: 40px; color: var(--sub); }
.cim-info { flex: 1; min-width: 0; }
.cim-suggestions { flex: 1; min-width: 0; }

/* ---------------- Sites par marque (page Prix) ---------------- */
.prix-site-row {
  background: var(--chip); border-radius: var(--radius-sm); padding: 8px 10px;
  margin-bottom: 6px;
}
.prix-site-row .name { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.prix-site-url-input { display: block; width: 100%; font-family: "Consolas", monospace; font-size: 12.5px; }
.prix-maj-warn { color: #8A6D00; font-weight: 600; }
.prix-maj-old { color: var(--danger); font-weight: 600; }

/* ---------------- Évolution des prix (popups graphique) ---------------- */
.pev-svg { width: 100%; height: auto; overflow: visible; }
.pev-grid { stroke: var(--border); stroke-width: 1; }
.pev-zero { stroke: var(--sub); stroke-width: 1; stroke-dasharray: 3 3; }
.pev-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pev-axis-label { font-size: 10px; fill: var(--sub); }
.pev-point-label { font-size: 11px; font-weight: 600; fill: var(--text); }
.mev-rows { display: flex; flex-direction: column; gap: 8px; }
.mev-row { display: flex; align-items: center; gap: 10px; }
.mev-marque { flex: 0 0 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mev-bar-track { flex: 1; height: 14px; background: var(--chip); border-radius: 7px; overflow: hidden; }
.mev-bar { display: block; height: 100%; border-radius: 7px; transition: width .15s; }
.mev-value { flex: 0 0 70px; text-align: right; font-weight: 600; }


/* ---------------- Mode serveur : connexion, comptes, agent PC ---------------- */
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar-foot[hidden] { display: none; }
.user-line { font-size: 13px; padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-actions { display: flex; flex-direction: column; gap: 6px; }
.user-actions .btn { width: 100%; }
.user-actions .btn[hidden] { display: none; }
.agent-chip {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 1px solid var(--border); background: var(--chip); border-radius: 999px;
  padding: 7px 12px; font: inherit; font-size: 12px; cursor: pointer; color: var(--text);
}
.agent-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--sub); flex: none; }
.agent-chip.on .agent-dot { background: #3fb950; }
.agent-chip.off .agent-dot { background: var(--danger); }
.agent-chip.busy .agent-dot { background: #d9a400; }

.auth-overlay {
  position: fixed; inset: 0; z-index: 1000; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.auth-overlay[hidden] { display: none; }
.auth-card { width: 360px; max-width: 100%; display: flex; flex-direction: column; gap: 10px; padding: 24px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--sub); }
.auth-card label[hidden] { display: none; }
.auth-error { margin: 0; color: var(--danger); font-size: 13px; }
.auth-error[hidden] { display: none; }

.section-title { margin: 16px 0 6px; font-size: 14px; }
.account-agent-status { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--chip); font-size: 13px; margin-bottom: 10px; }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.account-actions a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.account-steps { margin: 10px 0 0; padding-left: 18px; }
.account-pw { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; }
@media (max-width: 800px) { .account-pw { grid-template-columns: 1fr; } }

.users-create { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 8px; align-items: center; margin-bottom: 12px; }
.check-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.users-list { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow: auto; }
.user-row {
  display: grid; grid-template-columns: 1.2fr auto 1fr auto; gap: 10px; align-items: center;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.user-row.disabled { opacity: .55; }
.user-row .u-name { font-weight: 600; }
.user-row .u-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.user-row .u-pw { grid-column: 1 / -1; display: none; gap: 8px; }
.user-row .u-pw.open { display: flex; }

.users-create label.check-inline { flex-direction: row !important; align-items: center; }


/* ---------------- Historique des modifications d'un produit ---------------- */
.hist-list { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow: auto; }
.hist-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; }
.hist-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; margin-bottom: 6px; flex-wrap: wrap; }
.hist-user { font-weight: 700; }
.hist-action { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--chip); margin-left: 6px; }
.hist-date { font-size: 12px; color: var(--sub); }
.hist-change { font-size: 13px; padding: 2px 0; }
.hist-label { color: var(--sub); }
.hist-old { text-decoration: line-through; color: var(--sub); }
.hist-new { font-weight: 600; }
.hist-empty { font-style: italic; color: var(--sub); text-decoration: none; }


/* ---------------- Verrou partage d'écran ---------------- */
body.locked > *:not(#lock-overlay) { display: none !important; }
.lock-overlay {
  position: fixed; inset: 0; z-index: 100000; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; padding: 24px;
}
.lock-overlay[hidden] { display: none; }
.lock-text {
  color: #ff2a2a; font-weight: 800; text-align: center; letter-spacing: .04em;
  font-size: clamp(28px, 6vw, 72px); line-height: 1.1;
}
.lock-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.lock-actions[hidden] { display: none; }
.lock-btn {
  background: #1a1a1a; color: #bbb; border: 1px solid #333; border-radius: 999px; padding: 10px 20px;
  font: inherit; font-size: 14px; cursor: pointer; text-decoration: none;
}
.lock-btn:hover { color: #fff; border-color: #666; }
