/* ===== Global CRM — design system ===== */
:root {
  --accent: #e02b20;
  --accent-dark: #b81f16;
  --sidebar-bg: #17171f;
  --sidebar-text: #a3a3b2;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1c1c24;
  --muted: #6b7280;
  --border: #e6e6ea;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 20, 30, .07), 0 4px 14px rgba(20, 20, 30, .05);
  --green: #16a34a; --red: #dc2626; --orange: #ea580c;
  --blue: #2563eb; --purple: #7c3aed; --gray: #6b7280;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }

/* ---- Sidebar ---- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 232px; background: var(--sidebar-bg);
  display: flex; flex-direction: column; z-index: 50; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 16px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 1.15rem;
}
.brand-name { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; }
.brand-name em { font-style: normal; color: var(--accent); }
.sidebar nav { flex: 1; padding: 6px 10px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; margin: 2px 0;
  border-radius: 8px; color: var(--sidebar-text); font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { color: #fff; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.logout { color: var(--sidebar-text); font-size: .82rem; }
.burger {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 60;
  background: var(--sidebar-bg); color: #fff; border: 0; border-radius: 8px;
  width: 40px; height: 40px; font-size: 1.1rem; cursor: pointer;
}

/* ---- Contenu ---- */
.content { margin-left: 232px; padding: 26px 30px 60px; min-height: 100vh; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); font-size: .9rem; }

/* ---- Cartes ---- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card h2 { display: flex; align-items: center; justify-content: space-between; }
.grid { display: grid; gap: 16px; }
/* Les cellules de grille doivent pouvoir rétrécir sous la largeur de leur contenu
   (tableaux larges) pour que .table-wrap défile au lieu de faire déborder la page. */
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 1.55rem; font-weight: 750; margin-top: 2px; }
.stat .hint { color: var(--muted); font-size: .82rem; }
.stat.alert .value { color: var(--red); }
.stat.good .value { color: var(--green); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-gray   { background: #f1f1f4; color: #52525e; }
.badge-blue   { background: #e3edff; color: #1d4ed8; }
.badge-green  { background: #e2f7e9; color: #15803d; }
.badge-red    { background: #fde8e8; color: #b91c1c; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-purple { background: #f0e9fe; color: #6d28d9; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

/* ---- Boutons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 15px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-weight: 600; font-size: .88rem; cursor: pointer; text-decoration: none !important;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #fafafc; border-color: #d4d4dc; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { color: var(--red); }
.btn-sm { padding: 4px 10px; font-size: .8rem; border-radius: 7px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Formulaires ---- */
label { display: block; font-weight: 600; font-size: .84rem; margin-bottom: 4px; color: #3f3f49; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=url], input[type=tel], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px;
  font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(224,43,32,.25); border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { margin-bottom: 2px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; align-items: center; }
.help { color: var(--muted); font-size: .8rem; margin-top: 3px; }

/* ---- Flash ---- */
.flash { padding: 11px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; }
.flash-success { background: #e2f7e9; color: #15803d; }
.flash-error { background: #fde8e8; color: #b91c1c; }
.flash-info { background: #e3edff; color: #1d4ed8; }

/* ---- Kanban ---- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 14px; align-items: flex-start; }
.kanban-col { min-width: 250px; width: 250px; background: #ededf1; border-radius: var(--radius); padding: 10px; flex-shrink: 0; }
.kanban-col h3 { margin: 2px 4px 10px; font-size: .84rem; display: flex; justify-content: space-between; align-items: center; }
.kanban-col .col-total { color: var(--muted); font-weight: 600; font-size: .78rem; }
.kanban-col.dragover { outline: 2px dashed var(--accent); outline-offset: -2px; }
.kanban-card {
  background: #fff; border-radius: 10px; box-shadow: var(--shadow); padding: 10px 12px;
  margin-bottom: 8px; cursor: grab; border-left: 3px solid transparent;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card .kc-title { font-weight: 650; margin-bottom: 2px; }
.kanban-card .kc-meta { color: var(--muted); font-size: .8rem; }
.kanban-card .kc-amount { font-weight: 700; font-size: .88rem; margin-top: 4px; }
.kanban-card.overdue { border-left-color: var(--red); }

/* ---- Timeline activités ---- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 22px; border-left: 2px solid var(--border); position: relative; margin-left: 8px; }
.timeline li::before {
  content: ''; position: absolute; left: -6px; top: 16px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent);
}
.timeline .t-head { font-size: .8rem; color: var(--muted); }
.timeline .t-body { margin-top: 2px; white-space: pre-wrap; }

/* ---- Divers ---- */
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.empty .big { font-size: 2rem; margin-bottom: 6px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters .field { min-width: 150px; margin: 0; }
.pagination { display: flex; gap: 6px; margin-top: 14px; }
.pagination a, .pagination span { padding: 5px 11px; border-radius: 7px; border: 1px solid var(--border); background: #fff; }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }
.text-muted { color: var(--muted); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 14px; }
.avatar {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: #ededf1; color: #52525e; font-weight: 700; font-size: .82rem; flex-shrink: 0;
}

/* ---- Login ---- */
.login-page { display: grid; place-items: center; min-height: 100vh; background: var(--sidebar-bg); }
.login-box { width: min(380px, 92vw); background: #fff; border-radius: 16px; padding: 34px 32px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-box .brand { padding: 0 0 18px; }
.login-box .brand-name { color: var(--text); font-size: 1.3rem; }

/* ---- Responsive ---- */
@media (max-width: 920px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; width: 250px; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .burger { display: block; }
  .content { margin-left: 0; padding: 64px 14px 40px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  body { font-size: 15px; }
}
@media print {
  .sidebar, .burger, .btn, .filters { display: none !important; }
  .content { margin: 0; padding: 0; }
  .card { box-shadow: none; border: 1px solid var(--border); }
}

/* ===== Calculateur de marges — éditeur de lignes ===== */
.pill-group { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.pill { padding: 6px 14px; border-radius: 99px; border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-weight: 600; font-size: .84rem; text-decoration: none !important; }
.pill:hover { background: #fafafc; border-color: #d4d4dc; }
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

table.lines-table th, table.lines-table td { padding: 6px 8px; }
table.lines-table td input[type=text], table.lines-table td input[type=number] {
  padding: 6px 8px; font-size: .88rem;
}
table.lines-table td.num-cell input[type=number] { text-align: right; }
table.lines-table col.col-label { width: 26%; }
table.lines-table col.col-supplier { width: 18%; }
table.lines-table col.col-cost, table.lines-table col.col-price { width: 13%; }
table.lines-table col.col-margin, table.lines-table col.col-marginpct { width: 11%; }
table.lines-table col.col-paid { width: 6%; }
table.lines-table col.col-remove { width: 4%; }
.margin-cell { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.margin-cell.negative { color: var(--red); }
.margin-cell.positive { color: var(--green); }
tfoot.lines-totals td { border-top: 2px solid var(--border); border-bottom: 0; font-weight: 700; background: #fafafc; }
tfoot.lines-totals td.num-cell, tfoot.lines-totals td.margin-cell { text-align: right; }
.paid-check { display: flex; justify-content: center; align-items: center; }
.paid-check input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; }
.line-remove-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px 6px; border-radius: 6px; }
.line-remove-btn:hover { background: #fde8e8; color: var(--red); }
.text-negative { color: var(--red); }
.text-positive { color: var(--green); }

@media print {
  input, select, textarea { border: none !important; background: transparent !important; }
  .line-remove-btn, #add-line { display: none !important; }
}

