:root {
  --navy: #0b2545; --teal: #13807a; --orange: #e07a1f; --green: #1e9e57; --gold: #f2c14e; --red: #c0392b;
  --bg: #f4f6f9; --card: #ffffff; --text: #1f2933; --muted: #5b6b7f; --line: #dde3ea; --chip: #eef2f6;
  --radius: 12px; --shadow: 0 1px 2px rgba(11, 37, 69, .06), 0 4px 16px rgba(11, 37, 69, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
h1 { font-size: 24px; margin: 0 0 4px; color: var(--navy); }
h2 { font-size: 17px; margin: 0 0 12px; color: var(--navy); }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; color: var(--navy); line-height: 1.1; }
.brand small { color: var(--muted); }
.logo { width: 36px; height: 36px; border-radius: 9px; background: var(--navy); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 14px; }

.btn { border: 1px solid transparent; border-radius: 9px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover { background: #12346a; }
.btn.ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--navy); }
.btn.orange { background: var(--orange); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.link { background: none; color: var(--muted); padding: 6px 0; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, textarea, select { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--text); }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(19, 128, 122, .35); border-color: var(--teal); }
label { display: block; font-weight: 600; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
label input, label textarea, label select { margin-top: 6px; font-weight: 400; }
textarea { resize: vertical; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--navy), #13807a); }
.login-card { background: #fff; border-radius: 16px; padding: 28px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 22px; }
.login-card .btn { width: 100%; justify-content: center; }

.top { position: sticky; top: 0; z-index: 10; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 10px 24px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a { padding: 8px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; }
.tabs a.on { background: var(--chip); color: var(--navy); }
main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }

.offer h3 { margin: 0 0 6px; color: var(--navy); font-size: 16px; }
.offer pre { white-space: pre-wrap; font: inherit; font-size: 13px; color: var(--muted); max-height: 140px; overflow: hidden; margin: 0 0 14px; mask-image: linear-gradient(#000 70%, transparent); }
.stats { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.stats b { color: var(--navy); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 16px; }
.kpi small { color: var(--muted); font-weight: 600; font-size: 12px; }
.kpi div { font-size: 26px; font-weight: 700; color: var(--navy); }

.toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.filters, .chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--muted); }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.notice { background: #e8f6f4; border: 1px solid #bfe4df; color: #0d5c57; padding: 10px 14px; border-radius: 9px; }

.lead { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; border-left: 5px solid var(--line); }
.lead.pA { border-left-color: var(--green); } .lead.pB { border-left-color: var(--gold); } .lead.pC { border-left-color: #9aa5b1; }
.lead-head { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 14px 18px; cursor: pointer; }
.lead-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lead-title strong { color: var(--navy); font-size: 16px; }
.prio { font-size: 12px; font-weight: 700; border-radius: 6px; padding: 2px 7px; color: #fff; background: #9aa5b1; }
.prio.A { background: var(--green); } .prio.B { background: var(--gold); color: #1f2933; }
.tag { font-size: 12px; border-radius: 6px; padding: 2px 8px; background: var(--chip); color: var(--muted); }
.tag.st-approuve { background: #e3effd; color: #174ea6; } .tag.st-envoye { background: #e3f6ea; color: #0b6b36; }
.tag.st-repondu, .tag.st-gagne { background: #fff3d6; color: #7a5300; } .tag.st-ecarte { background: #fbe3e1; color: #8a1c1c; }
.lead-why { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.lead-meta { font-size: 13px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.lead-meta a { color: var(--teal); }
.lead-body { border-top: 1px solid var(--line); padding: 16px 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.lead-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; justify-content: flex-end; }
.err { color: var(--red); font-size: 13px; }

.run { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; margin-bottom: 10px; }
.run-top { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.run pre { white-space: pre-wrap; font: inherit; font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; background: #9aa5b1; }
.dot.running { background: var(--orange); animation: pulse 1.2s infinite; } .dot.done { background: var(--green); } .dot.error { background: var(--red); }
@keyframes pulse { 50% { opacity: .3; } }

dialog { border: 0; border-radius: 16px; padding: 24px; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(11, 37, 69, .45); }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; padding: 10px 16px; }
  .tabs { order: 3; width: 100%; flex-basis: 100%; }
  main { padding: 16px; }
  .lead-body { grid-template-columns: 1fr; }
  .lead-head { grid-template-columns: 1fr; }
  .lead-actions { justify-content: flex-start; }
}

.translation { background: #f1f8f7; border: 1px solid #cfe7e3; border-radius: 9px; padding: 10px 12px; white-space: pre-wrap; font-size: 14px; margin-top: 10px; }
.thread { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 14px; }
.thread h3 { margin: 0 0 10px; font-size: 15px; color: var(--navy); }
.msg { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; }
.msg.mine { background: #f7f9fc; }
.msg.theirs { border-left: 4px solid var(--teal); }
.msg-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.msg-head strong { color: var(--navy); }
.msg pre { white-space: pre-wrap; font: inherit; font-size: 14px; margin: 8px 0 0; }
.inbox { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 16px; align-items: start; }
.inbox-item { background: #fff; border-radius: 10px; box-shadow: var(--shadow); padding: 10px 14px; margin-bottom: 8px; cursor: pointer; border-left: 4px solid transparent; }
.inbox-item.on { border-left-color: var(--navy); }
.inbox-item.unread .ii-subject { font-weight: 700; }
.ii-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.ii-top strong { color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ii-subject { margin: 2px 0; font-size: 14px; }
.ii-snippet { font-size: 13px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
#inbox-thread { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto; }
@media (max-width: 760px) {
  .inbox { grid-template-columns: 1fr; }
  #inbox-thread { position: static; max-height: none; }
}

.client-card { cursor: pointer; display: flex; flex-direction: column; gap: 8px; border-top: 4px solid var(--line); transition: transform .1s; }
.client-card:hover { transform: translateY(-1px); }
.client-card.replied { border-top-color: var(--orange); }
.client-card.won { border-top-color: var(--green); }
.client-card.sent { border-top-color: #4a7bd0; }
.cc-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.cc-top strong { color: var(--navy); font-size: 16px; }
.cc-offer { font-size: 13px; border-top: 1px dashed var(--line); padding-top: 8px; }
.cc-offer b { color: var(--navy); }
.cc-line { color: var(--muted); font-size: 13px; }
dialog.wide { width: min(900px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
.timeline { border-left: 2px solid var(--line); margin: 10px 0 18px 6px; padding-left: 16px; }
.tl-offer { margin: 18px 0 6px; color: var(--navy); }
