/* ============================================================
   CRM Pro-Active — Thème Terracotta
   ============================================================ */
:root {
  --bg: #faf4ee;
  --bg-2: #f4e9df;
  --surface: #ffffff;
  --surface-soft: #fbf6f1;
  --line: #ecddd0;
  --terra: #c66a45;
  --terra-deep: #a4502f;
  --terra-soft: #e7a982;
  --terra-tint: #f7e7dc;
  --clay: #d98b5f;
  --sage: #7c8a5a;
  --espresso: #3a2a22;
  --ink: #5a463c;
  --muted: #9a8678;
  --green: #4f8a5b;
  --green-bg: #e6f1e7;
  --amber: #c98a2e;
  --amber-bg: #f7ecd6;
  --grey: #8a8178;
  --grey-bg: #ece7e1;
  --rust: #b14a39;
  --rust-bg: #f6e0db;
  --shadow-sm: 0 1px 2px rgba(58, 42, 34, .06), 0 2px 6px rgba(58, 42, 34, .05);
  --shadow-md: 0 6px 20px rgba(58, 42, 34, .10);
  --shadow-lg: 0 24px 60px rgba(58, 42, 34, .22);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 9px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--espresso);
  background:
    radial-gradient(1200px 600px at 100% -10%, #f6e3d4 0%, rgba(246,227,212,0) 55%),
    radial-gradient(900px 500px at -10% 110%, #f1e6dc 0%, rgba(241,230,220,0) 50%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#root { min-height: 100vh; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------------- Layout ---------------- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: linear-gradient(180deg, #ffffff 0%, #fdf7f1 100%);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px 20px;
}
.brand .logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(140deg, var(--terra) 0%, var(--terra-deep) 100%);
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 18px;
  box-shadow: var(--shadow-sm);
}
.brand .name { font-weight: 800; font-size: 16px; letter-spacing: -.2px; }
.brand .sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px; border-radius: var(--radius-sm);
  color: var(--ink); font-weight: 600; font-size: 14px;
  border: 1px solid transparent;
  transition: all .18s ease;
  background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--terra-tint); color: var(--terra-deep); }
.nav-item.active {
  background: linear-gradient(140deg, var(--terra) 0%, var(--terra-deep) 100%);
  color: #fff; box-shadow: var(--shadow-sm);
}
.nav-item .ico { width: 18px; height: 18px; display: inline-flex; }
.sidebar-foot { margin-top: auto; font-size: 11px; color: var(--muted); padding: 10px 8px; line-height: 1.5; }
.mode-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; padding: 5px 10px; border-radius: 999px;
  background: var(--terra-tint); color: var(--terra-deep); margin-bottom: 8px;
}
.mode-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--terra); }
.mode-pill.cloud { background: var(--green-bg); color: var(--green); }
.mode-pill.cloud .dot { background: var(--green); }

.main { padding: 30px 36px 60px; max-width: 1180px; width: 100%; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 26px; }
.topbar h1 { font-size: 26px; font-weight: 800; letter-spacing: -.5px; margin: 0; }
.topbar .subtitle { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--espresso);
  padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 700; font-size: 13.5px;
  transition: all .16s ease; box-shadow: var(--shadow-sm);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: linear-gradient(140deg, var(--terra) 0%, var(--terra-deep) 100%);
  color: #fff; border-color: transparent;
}
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--terra-tint); }
.btn.danger { color: var(--rust); border-color: var(--rust-bg); background: var(--rust-bg); box-shadow: none; }
.btn.danger:hover { background: #f0cfc8; }
.btn.sm { padding: 7px 12px; font-size: 12.5px; }

/* ---------------- Stat cards ---------------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 18px 16px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
  animation: rise .5s ease both;
}
.stat::after {
  content: ""; position: absolute; right: -20px; top: -20px; width: 90px; height: 90px;
  border-radius: 50%; background: var(--terra-tint); opacity: .55;
}
.stat .k { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; position: relative; }
.stat .v { font-size: 30px; font-weight: 800; margin-top: 8px; letter-spacing: -1px; position: relative; }
.stat .chip { position: relative; margin-top: 8px; font-size: 12px; font-weight: 700; }
.stat .ic {
  position: absolute; top: 16px; right: 16px; width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; background: var(--terra); color: #fff; box-shadow: var(--shadow-sm);
}
.stat.green .ic { background: var(--green); } .stat.green::after { background: var(--green-bg); }
.stat.amber .ic { background: var(--amber); } .stat.amber::after { background: var(--amber-bg); }
.stat.sage  .ic { background: var(--sage); }

/* ---------------- Toolbar ---------------- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search {
  flex: 1; min-width: 220px; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 14px; box-shadow: var(--shadow-sm); transition: border .16s;
}
.search:focus-within { border-color: var(--terra-soft); box-shadow: 0 0 0 4px var(--terra-tint); }
.search input { border: none; outline: none; flex: 1; font-size: 14px; background: transparent; color: var(--espresso); }
.search input::placeholder { color: var(--muted); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 13px; font-weight: 700; color: var(--ink); transition: all .15s; box-shadow: var(--shadow-sm);
}
.filter-chip:hover { border-color: var(--terra-soft); }
.filter-chip.active { background: var(--espresso); color: #fff; border-color: var(--espresso); }

/* ---------------- Table / cards ---------------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
table.clients { width: 100%; border-collapse: collapse; }
table.clients thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 800; padding: 14px 18px; background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
}
table.clients tbody tr {
  border-bottom: 1px solid var(--line); cursor: pointer; transition: background .14s;
  animation: fadeIn .3s ease both;
}
table.clients tbody tr:last-child { border-bottom: none; }
table.clients tbody tr:hover { background: var(--terra-tint); }
table.clients td { padding: 14px 18px; font-size: 14px; vertical-align: middle; }
.cell-name { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center;
  font-weight: 800; font-size: 14px; color: #fff;
  background: linear-gradient(140deg, var(--clay), var(--terra-deep));
}
.cell-name .nm { font-weight: 700; }
.cell-name .ad { font-size: 12px; color: var(--muted); margin-top: 1px; }
.tel { color: var(--ink); font-variant-numeric: tabular-nums; }

/* status badge */
.badge { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.badge.rdv   { background: var(--green-bg); color: var(--green); } .badge.rdv .dot { background: var(--green); }
.badge.rappel{ background: var(--amber-bg); color: var(--amber); } .badge.rappel .dot { background: var(--amber); }
.badge.norep { background: var(--grey-bg); color: var(--grey); } .badge.norep .dot { background: var(--grey); }
.badge.mort  { background: var(--rust-bg); color: var(--rust); } .badge.mort .dot { background: var(--rust); }

/* mini pipeline in row */
.pipe-mini { display: flex; align-items: center; gap: 4px; }
.pipe-mini .seg { width: 22px; height: 6px; border-radius: 4px; background: var(--line); transition: background .2s; }
.pipe-mini .seg.on { background: linear-gradient(90deg, var(--clay), var(--terra-deep)); }
.pipe-mini .lbl { font-size: 11px; color: var(--muted); margin-left: 8px; font-weight: 700; }

.empty { padding: 70px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 16px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }

/* ---------------- Modal ---------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(46, 31, 24, .42);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px;
  z-index: 50; overflow-y: auto; animation: fadeIn .2s ease;
}
.modal {
  background: var(--surface); width: 100%; max-width: 760px; border-radius: 22px;
  box-shadow: var(--shadow-lg); overflow: hidden; animation: pop .28s cubic-bezier(.2,.9,.3,1.1) both;
}
.modal-head {
  padding: 22px 26px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: linear-gradient(135deg, var(--terra) 0%, var(--terra-deep) 100%); color: #fff;
}
.modal-head .h-left { display: flex; align-items: center; gap: 14px; }
.modal-head .h-avatar { width: 46px; height: 46px; border-radius: 13px; background: rgba(255,255,255,.2); display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 800; }
.modal-head .h-sub { font-size: 12.5px; opacity: .85; margin-top: 2px; }
.x-btn { background: rgba(255,255,255,.18); border: none; color: #fff; width: 36px; height: 36px; border-radius: 10px; font-size: 18px; display: grid; place-items: center; transition: background .15s; }
.x-btn:hover { background: rgba(255,255,255,.32); }

.modal-body { padding: 24px 26px; max-height: 62vh; overflow-y: auto; }
.section-title { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--terra-deep); margin: 4px 0 14px; display: flex; align-items: center; gap: 8px; }
.section-title::before { content: ""; width: 18px; height: 3px; border-radius: 3px; background: var(--terra-soft); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--ink); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 10px 12px;
  font-size: 14px; color: var(--espresso); background: var(--surface-soft); transition: all .15s; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--terra-soft); background: #fff; box-shadow: 0 0 0 4px var(--terra-tint);
}
.field textarea { resize: vertical; min-height: 78px; }

/* status selector */
.status-row { display: flex; gap: 10px; flex-wrap: wrap; }
.status-opt {
  flex: 1; min-width: 130px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; background: var(--surface-soft); display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 13.5px; transition: all .16s; color: var(--ink);
}
.status-opt .dot { width: 10px; height: 10px; border-radius: 50%; }
.status-opt:hover { border-color: var(--terra-soft); }
.status-opt.sel { background: #fff; box-shadow: var(--shadow-md); transform: translateY(-1px); }
.status-opt.sel.rdv { border-color: var(--green); }
.status-opt.sel.rappel { border-color: var(--amber); }
.status-opt.sel.norep { border-color: var(--grey); }
.status-opt.sel.mort { border-color: var(--rust); }

/* pipeline stepper */
.pipeline { margin-top: 6px; }
.pipeline.locked { opacity: .45; pointer-events: none; filter: grayscale(.3); }
.steps { display: flex; align-items: flex-start; gap: 0; position: relative; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 9px; position: relative; text-align: center; }
.step .bar { position: absolute; top: 18px; left: -50%; width: 100%; height: 3px; background: var(--line); z-index: 0; transition: background .3s; }
.step:first-child .bar { display: none; }
.step.done .bar, .step.current .bar { background: linear-gradient(90deg, var(--clay), var(--terra-deep)); }
.step .knob {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; z-index: 1;
  background: var(--surface); border: 2px solid var(--line); color: var(--muted); font-weight: 800; font-size: 14px;
  transition: all .22s ease;
}
.step:hover .knob { border-color: var(--terra-soft); }
.step.done .knob { background: var(--green); border-color: var(--green); color: #fff; }
.step.current .knob { background: linear-gradient(140deg, var(--terra), var(--terra-deep)); border-color: var(--terra-deep); color: #fff; box-shadow: 0 0 0 5px var(--terra-tint); transform: scale(1.08); }
.step .stp-lbl { font-size: 11px; font-weight: 700; color: var(--ink); max-width: 84px; line-height: 1.25; }
.step.current .stp-lbl { color: var(--terra-deep); }

.modal-foot {
  padding: 16px 26px; border-top: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; gap: 12px; background: var(--surface-soft);
}
.foot-right { display: flex; gap: 10px; }

/* ---------------- Toast ---------------- */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast {
  background: var(--espresso); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 700; font-size: 13.5px;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; animation: toastIn .3s ease both;
}
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.toast.warn .dot { background: var(--amber); }

/* mobile bottom nav */
.mobile-nav { display: none; }

/* ---------------- Animations ---------------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.loading-screen { min-height: 100vh; display: grid; place-items: center; }
.loading-screen .big-spin { width: 42px; height: 42px; border: 4px solid var(--terra-tint); border-top-color: var(--terra); border-radius: 50%; animation: spin .8s linear infinite; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 20px 16px 96px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .topbar h1 { font-size: 22px; }
  .grid2 { grid-template-columns: 1fr; }
  .table-wrap { border: none; background: transparent; box-shadow: none; }
  table.clients thead { display: none; }
  table.clients, table.clients tbody, table.clients tr, table.clients td { display: block; width: 100%; }
  table.clients tbody tr {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    margin-bottom: 12px; padding: 6px 4px; box-shadow: var(--shadow-sm);
  }
  table.clients td { padding: 8px 16px; border: none; }
  table.clients td::before { content: attr(data-label); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 800; margin-bottom: 2px; }
  table.clients td.cell-name-td::before { display: none; }
  .steps { overflow-x: auto; padding-bottom: 8px; }
  .step { min-width: 78px; }
  .modal-body { max-height: 70vh; }
  .modal-head { padding: 18px 18px; }
  .modal-body { padding: 18px; }
  .modal-foot { padding: 14px 18px; flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; justify-content: center; }
  .foot-right { width: 100%; }
  .foot-right .btn { flex: 1; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: rgba(255,255,255,.92); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); justify-content: space-around;
  }
  .mobile-nav button { background: none; border: none; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700; color: var(--muted); padding: 4px 14px; border-radius: 12px; }
  .mobile-nav button.active { color: var(--terra-deep); background: var(--terra-tint); }
  .fab {
    position: fixed; right: 18px; bottom: 78px; z-index: 45; width: 56px; height: 56px; border-radius: 18px;
    background: linear-gradient(140deg, var(--terra), var(--terra-deep)); color: #fff; border: none;
    box-shadow: var(--shadow-lg); font-size: 26px; display: grid; place-items: center;
  }
}
@media (min-width: 901px) { .fab { display: none; } }

@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .v { font-size: 24px; }
}
