:root {
  --primary: #ff5c35;
  --primary-dark: #e6491f;
  --navy: #33475b;
  --navy-dark: #24344a;
  --bg: #f5f8fa;
  --card: #ffffff;
  --border: #e5e9ee;
  --text: #33475b;
  --text-light: #7c98b6;
  --success: #00a4bd;
  --success-bg: #eafaf3;
  --warn: #f5c26b;
  --danger: #e34c4c;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }

/* ---------- Login page ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--card);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(33,58,84,0.12);
  width: 360px;
}
.auth-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
  color: var(--navy-dark);
}
.auth-card p.sub { color: var(--text-light); margin: 0 0 24px; font-size: 13px; }
.tabs { display: flex; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; text-align: center; padding: 10px; cursor: pointer;
  color: var(--text-light); font-weight: 600; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--primary); border-color: var(--primary); }

label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: 12px; color: var(--navy); }
input, select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 14px; font-family: inherit; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; }

button, .btn {
  cursor: pointer; border: none; border-radius: 4px; font-weight: 600; font-size: 13px;
  padding: 9px 16px; font-family: inherit;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: white; color: var(--navy); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f0f3f6; }
.btn-danger { background: white; color: var(--danger); border: 1px solid var(--danger); }
.btn-block { width: 100%; margin-top: 18px; padding: 11px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.error-msg { background: #fdecea; color: var(--danger); padding: 8px 10px; border-radius: 4px; font-size: 13px; margin-top: 10px; }
.success-msg { background: var(--success-bg); color: #0a7a5c; padding: 8px 10px; border-radius: 4px; font-size: 13px; margin-top: 10px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--navy-dark); color: white; flex-shrink: 0;
  display: flex; flex-direction: column; padding: 20px 0;
}
.sidebar .logo { padding: 0 20px 20px; font-size: 18px; font-weight: 800; color: white; }
.sidebar .logo span { color: var(--primary); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 20px; color: #c6d3e2;
  cursor: pointer; font-weight: 500; border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: white; }
.nav-item.active { color: white; border-left-color: var(--primary); background: rgba(255,255,255,0.06); }
.nav-item .icon { width: 18px; text-align: center; }
.sidebar-footer { margin-top: 8px; padding: 14px 20px; border-top: 1px solid rgba(255,255,255,0.1); font-size: 12px; color: #93a6bc; }
.sidebar-footer strong { color: white; display: block; font-size: 13px; }
.sidebar-footer .logout-link { color: var(--primary); cursor: pointer; font-size: 12px; }

.main { flex: 1; min-width: 0; }
.topbar {
  background: white; border-bottom: 1px solid var(--border); padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar h2 { margin: 0; font-size: 20px; color: var(--navy-dark); }
.back-link { color: var(--navy-dark); font-weight: 700; font-size: 20px; text-decoration: none; }
.back-link:hover { color: var(--primary); }
.content { padding: 24px 28px; }

/* ---------- Cards / grid ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .label { color: var(--text-light); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 28px; font-weight: 700; color: var(--navy-dark); margin-top: 6px; }

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-header { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; color: var(--navy-dark); display: flex; justify-content: space-between; align-items: center; }
.panel-body { padding: 18px; }

.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; }
.toolbar input[type=text], .toolbar input[type=search] { max-width: 280px; }
.toolbar .spacer { flex: 1; }

.pagination { display: flex; gap: 12px; align-items: center; margin-top: 16px; }
.pagination .spacer { flex: 1; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; background: var(--card); }
table.panel-table { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th { text-align: left; background: #f8fafc; font-size: 11px; text-transform: uppercase; color: var(--text-light); padding: 10px 14px; border-bottom: 1px solid var(--border); }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: #f8fafc; cursor: pointer; }
td.actions-cell { white-space: nowrap; width: 1%; }
.icon-btn {
  background: none; border: none; cursor: pointer; padding: 4px 6px; font-size: 14px;
  border-radius: 4px; line-height: 1; color: var(--text-light);
}
.icon-btn:hover { background: #eef2f6; }
.icon-btn.icon-btn-danger:hover { background: #fdecea; color: var(--danger); }

/* ---------- Table : tri des colonnes (tous les utilisateurs) ---------- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th.sortable .sort-arrow { display: inline-block; margin-left: 4px; opacity: 0.35; }
th.sortable.sort-active .sort-arrow { opacity: 1; }

/* ---------- Personnalisation des colonnes (admin) ---------- */
.col-config-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.col-config-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--border); }
.col-config-row:last-child { border-bottom: none; }
.col-config-row.dragging { opacity: 0.4; background: #f8fafc; }
.col-drag-handle { cursor: grab; color: var(--text-light); font-size: 15px; }
.col-drag-handle:active { cursor: grabbing; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.badge-lead { background: #fdf1e0; color: #92661a; }
.badge-prospect { background: #e0eefd; color: #1a5f92; }
.badge-client { background: var(--success-bg); color: #0a7a5c; }
.badge-inactif { background: #ececec; color: #666; }
.badge-basse { background: #ececec; color: #666; }
.badge-normale { background: #e0eefd; color: #1a5f92; }
.badge-haute { background: #fdecea; color: var(--danger); }
.badge-non_envoye { background: #ececec; color: #666; }
.badge-envoye { background: #e0eefd; color: #1a5f92; }
.badge-valide { background: var(--success-bg); color: #0a7a5c; }
.badge-refuse { background: #fdecea; color: var(--danger); }

/* ---------- Contact detail: sidebar layout ---------- */
.contact-layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.contact-sidebar-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-align: center; }
.contact-avatar-lg {
  width: 64px; height: 64px; border-radius: 50%; background: var(--primary); color: white;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 22px; margin: 0 auto 12px;
  position: relative; overflow: hidden;
}
.contact-avatar-lg .company-logo-img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 10px;
}
.contact-avatar-lg #company-avatar-fallback {
  width: 100%; height: 100%; align-items: center; justify-content: center;
}
.contact-sidebar-card h2 { margin: 0 0 4px; font-size: 17px; color: var(--navy-dark); }
.contact-sidebar-card .contact-email { font-size: 13px; }
.quick-actions { display: flex; justify-content: space-between; gap: 4px; margin: 16px 0 4px; border-top: 1px solid var(--border); padding-top: 14px; }
.quick-action-btn {
  flex: 1; background: none; border: none; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 4px; color: var(--navy); font-size: 11px; padding: 6px 2px; border-radius: 6px;
}
.quick-action-btn:hover:not(:disabled) { background: #eef2f6; }
.quick-action-btn:disabled { color: var(--text-light); cursor: not-allowed; opacity: 0.5; }
.quick-action-btn .icon { font-size: 18px; }
.info-list { text-align: left; margin-top: 16px; border-top: 1px solid var(--border); padding-top: 10px; }
.info-list .info-row { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.info-list .info-row:last-child { border-bottom: none; }
.info-list .info-label { color: var(--text-light); font-size: 11px; text-transform: uppercase; margin-bottom: 2px; }
.pipeline-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .contact-layout { grid-template-columns: 1fr; } }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.kanban-col { background: #f0f3f6; border-radius: var(--radius); width: 250px; flex-shrink: 0; display: flex; flex-direction: column; max-height: calc(100vh - 220px); }
.kanban-col-header { padding: 12px 14px; font-weight: 700; font-size: 13px; color: var(--navy-dark); border-bottom: 2px solid var(--border); display: flex; justify-content: space-between; }
.kanban-col-header .total { font-weight: 600; color: var(--text-light); font-size: 12px; }
.kanban-cards { padding: 10px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.kanban-card { background: white; border-radius: 6px; padding: 10px 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.08); cursor: grab; border-left: 3px solid var(--primary); }
.kanban-card.dragging { opacity: 0.4; }
.kanban-card .title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.kanban-card .amount { color: #0a7a5c; font-weight: 700; font-size: 13px; }
.kanban-card .meta { color: var(--text-light); font-size: 11px; margin-top: 4px; }
.kanban-col.dragover { outline: 2px dashed var(--primary); outline-offset: -4px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(33,58,84,0.4); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.modal { background: white; border-radius: var(--radius); width: 460px; max-width: 92vw; max-height: 88vh; overflow-y: auto; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-header .close { cursor: pointer; color: var(--text-light); font-size: 20px; line-height: 1; }
.modal-body { padding: 18px 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Timeline ---------- */
.timeline-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-icon {
  width: 26px; height: 26px; border-radius: 50%; background: #eef2f6; color: var(--navy);
  display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0;
}
.timeline-content .text { font-size: 13px; }
.timeline-content .meta { color: var(--text-light); font-size: 11px; margin-top: 2px; }
.timeline-action-btn { margin-left: auto; align-self: center; flex-shrink: 0; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }
.muted { color: var(--text-light); }
.mt-16 { margin-top: 16px; }
.flex { display: flex; align-items: center; gap: 8px; }
.link-btn { background: none; border: none; color: var(--primary); font-weight: 600; cursor: pointer; padding: 0; font-size: 13px; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag-pill { background: #eef2f6; color: var(--navy); padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: white; display:flex; align-items:center; justify-content:center; font-weight:700; font-size: 13px; }
