:root {
  /* Palette Symbiel : sombre premium + accent violet→turquoise, or (gold) en highlight */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar: #0c0e18;
  --sidebar-hover: #1a1f33;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-soft: #64748b;
  --primary: #5b7cfa;
  --primary-dark: #4361ee;
  --accent: #2fd4d0;
  --violet: #a984ff;
  --gold: #f5c56b;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 700; }
.logo {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--violet), var(--accent)); color: #fff; font-size: 18px;
}
.brand-name { letter-spacing: -.3px; }
.brand-crm { color: var(--accent); font-weight: 800; }

/* ---------- Auth ---------- */
.auth-screen {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 70% -10%, #a984ff2e, transparent), radial-gradient(900px 500px at 10% 110%, #2fd4d022, transparent), var(--bg);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px;
  padding: 32px; box-shadow: var(--shadow-lg);
}
.auth-card .brand { justify-content: center; }
.auth-tagline { text-align: center; color: var(--text-soft); margin: 6px 0 24px; font-size: 14px; }
.auth-card h2 { font-size: 18px; margin-bottom: 16px; }
.auth-card label { display: block; font-size: 13px; font-weight: 600; color: var(--text-soft); margin-bottom: 12px; }
.auth-card input {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; color: var(--text);
}
.auth-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px #2563eb22; }
.auth-switch { text-align: center; font-size: 13px; color: var(--text-soft); margin-top: 16px; }
.auth-error { color: var(--red); font-size: 13px; text-align: center; margin-top: 12px; min-height: 18px; }

.btn-primary {
  width: 100%; padding: 11px; background: var(--primary); color: #fff; border: none;
  border-radius: 8px; font-size: 14px; font-weight: 600; transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.topbar-actions .btn-primary { width: auto; padding: 9px 16px; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: #cbd5e1; display: flex; flex-direction: column;
  padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { color: #fff; font-size: 18px; padding: 0 6px 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 8px;
  color: #cbd5e1; font-size: 14px; font-weight: 500; transition: background .12s, color .12s;
}
.nav-item .ic { width: 18px; text-align: center; opacity: .8; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.active .ic { opacity: 1; }
.sidebar-foot { border-top: 1px solid #ffffff1a; padding-top: 14px; }
.tenant-name { font-size: 12px; color: #94a3b8; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; padding: 0 6px 8px; }
.user-row { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.user-name { font-size: 14px; color: #fff; font-weight: 500; }
.logout { color: #94a3b8; font-size: 18px; }
.logout:hover { color: #fff; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 18px 28px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.search { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; width: 240px; }
.search:focus { outline: none; border-color: var(--primary); }
.view-root { padding: 28px; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.kpi .label { font-size: 13px; color: var(--text-soft); font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 800; margin-top: 6px; letter-spacing: -.5px; }
.kpi .sub { font-size: 12px; color: var(--text-soft); margin-top: 4px; }
.kpi.accent { border-top: 3px solid var(--primary); }
.kpi.green .value { color: var(--green); }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 24px;
}
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.panel-body { padding: 8px 20px 16px; }

/* ---------- Funnel bars ---------- */
.funnel-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.funnel-label { width: 130px; font-size: 13px; color: var(--text-soft); font-weight: 600; flex-shrink: 0; }
.funnel-track { flex: 1; background: #eef2f7; border-radius: 6px; height: 26px; position: relative; overflow: hidden; }
.funnel-fill { height: 100%; background: linear-gradient(90deg, var(--violet), var(--accent)); border-radius: 6px; min-width: 2px; transition: width .4s; }
.funnel-meta { width: 150px; text-align: right; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.funnel-meta .cnt { color: var(--text-soft); font-weight: 500; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-soft); padding: 12px 16px; border-bottom: 1px solid var(--border); background: #f8fafc; }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: #f8fafc; }
.cell-strong { font-weight: 600; }
.cell-soft { color: var(--text-soft); }
.empty { padding: 48px; text-align: center; color: var(--text-soft); }
.empty .big { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }

/* ---------- Notifications ---------- */
.notif-wrap { position: relative; }
.bell-btn { position: relative; background: none; border: 1px solid var(--border); border-radius: 8px; width: 38px; height: 38px; font-size: 17px; display: grid; place-items: center; }
.bell-btn:hover { background: #f8fafc; }
.bell-badge { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
.notif-panel { position: absolute; top: 46px; right: 0; width: 320px; max-height: 420px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 40; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px; }
.notif-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: #eff4ff; }
.notif-item.unread:hover { background: #e4edff; }
.notif-ic { font-size: 16px; flex-shrink: 0; }
.notif-title { font-size: 13px; font-weight: 500; line-height: 1.4; }
.notif-time { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.notif-empty { padding: 32px; text-align: center; color: var(--text-soft); font-size: 13px; }

/* ---------- List toolbar ---------- */
.list-toolbar { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 14px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.stage-nouveau { background: #e0e7ff; color: #3730a3; }
.badge.stage-qualifie { background: #cffafe; color: #155e75; }
.badge.stage-visite { background: #fef3c7; color: #92400e; }
.badge.stage-devis { background: #ffedd5; color: #9a3412; }
.badge.stage-negociation { background: #fae8ff; color: #86198f; }
.badge.stage-gagne { background: #dcfce7; color: #166534; }
.badge.stage-perdu { background: #fee2e2; color: #991b1b; }
.badge.type { background: #f1f5f9; color: #475569; }
.badge.qs-brouillon { background: #f1f5f9; color: #475569; }
.badge.qs-envoye { background: #dbeafe; color: #1e40af; }
.badge.qs-accepte { background: #dcfce7; color: #166534; }
.badge.qs-refuse { background: #fee2e2; color: #991b1b; }
.badge.cs-actif { background: #dcfce7; color: #166534; }
.badge.cs-en_attente { background: #fef3c7; color: #92400e; }
.badge.cs-expire { background: #fee2e2; color: #991b1b; }
.badge.cs-resilie { background: #f1f5f9; color: #475569; }
.badge.warn-badge { background: #fef3c7; color: #92400e; }
.kpi.warn { border-top: 3px solid var(--amber); }
.kpi.warn .value { color: var(--amber); }

/* ---------- Pipeline kanban ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; }
.kanban-col { flex: 0 0 250px; background: #eef2f7; border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 180px); }
.kanban-col.drop-hover { outline: 2px dashed var(--primary); outline-offset: -2px; }
.kanban-col-head { padding: 12px 14px; font-size: 13px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; }
.kanban-col-head .sum { font-size: 12px; color: var(--text-soft); font-weight: 600; }
.kanban-cards { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; flex: 1; }
.deal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 12px;
  box-shadow: var(--shadow); cursor: grab; transition: box-shadow .12s, transform .05s;
}
.deal-card:hover { box-shadow: var(--shadow-lg); }
.deal-card.dragging { opacity: .5; }
.deal-card .dc-title { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.deal-card .dc-company { font-size: 12px; color: var(--text-soft); margin-bottom: 8px; }
.deal-card .dc-foot { display: flex; justify-content: space-between; align-items: center; }
.deal-card .dc-amount { font-weight: 700; font-size: 14px; }
.col-nouveau .kanban-col-head { color: #3730a3; }
.col-qualifie .kanban-col-head { color: #155e75; }
.col-visite .kanban-col-head { color: #92400e; }
.col-devis .kanban-col-head { color: #9a3412; }
.col-negociation .kanban-col-head { color: #86198f; }
.col-gagne .kanban-col-head { color: #166534; }
.col-perdu .kanban-col-head { color: #991b1b; }

/* ---------- Detail / fiche 360 ---------- */
.detail-grid { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.detail-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.detail-title { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.detail-sub { color: var(--text-soft); font-size: 14px; margin-bottom: 16px; }
.field-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.field-row:last-child { border-bottom: none; }
.field-row .k { color: var(--text-soft); }
.field-row .v { font-weight: 600; text-align: right; }
.detail-actions { display: flex; gap: 8px; margin-top: 16px; }
.btn-sm { padding: 7px 12px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--text); }
.btn-sm:hover { background: #f8fafc; }
.btn-sm.danger { color: var(--red); border-color: #fecaca; }
.btn-sm.primary { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Timeline ---------- */
.timeline { position: relative; }
.tl-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.tl-icon { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; background: #f1f5f9; font-size: 14px; }
.tl-body { flex: 1; min-width: 0; }
.tl-subject { font-weight: 600; font-size: 14px; }
.tl-meta { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.tl-note { font-size: 13px; color: #334155; margin-top: 4px; white-space: pre-wrap; }
.tl-check { flex-shrink: 0; }
.tl-check input { width: 17px; height: 17px; cursor: pointer; }
.tl-done .tl-subject { text-decoration: line-through; color: var(--text-soft); }

.section-h { font-size: 15px; font-weight: 700; margin: 4px 0 12px; display: flex; justify-content: space-between; align-items: center; }
.link-btn { background: none; border: none; color: var(--primary); font-size: 13px; font-weight: 600; }

/* chip list */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip { padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--text-soft); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-close { border: none; background: none; font-size: 18px; color: var(--text-soft); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; color: var(--text); background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px #2563eb22; }
.field textarea { resize: vertical; min-height: 70px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--sidebar); color: #fff; padding: 12px 20px; border-radius: 9px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); z-index: 200; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; flex-direction: row; padding: 8px; z-index: 50; }
  .sidebar-brand, .sidebar-foot { display: none; }
  .sidebar nav { flex-direction: row; justify-content: space-around; }
  .nav-item span:not(.ic) { display: none; }
  .main { padding-bottom: 60px; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .view-root { padding: 16px; }
}
