/* Plateforme de gestion FPS Maroc */
:root {
  --navy-900: #161E55;
  --navy-700: #1E2A78;
  --navy-50: #EEF0FB;
  --blue: #3A5BD0;
  --bg: #F4F5F9;
  --card: #FFFFFF;
  --line: #E3E6EF;
  --line-soft: #EEF0F5;
  --ink: #141A33;
  --ink-2: #3D4452;
  --muted: #5A6178;
  --green: #1B6B34; --green-bg: #E6F4EA;
  --amber: #8A4B00; --amber-bg: #FFF4E5; --amber-line: #F1D3A8; --amber-soft: #FFF8EC; --amber-ink: #5C3300;
  --red: #B42318; --red-bg: #FDECEA; --red-line: #F3C9C4;
  --sky: #0B5394; --sky-bg: #E6F0FB;
  --purple: #4A2A8A; --purple-bg: #EDE7F6;
  --gray: #4B5563; --gray-bg: #F1F3F5;
  --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-h: 'Space Grotesk', 'Inter', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.45; }
a { color: var(--navy-700); }
a:hover { color: var(--navy-900); }
h1, h2, h3 { font-family: var(--font-h); margin: 0; line-height: 1.2; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ic { flex: none; }
.hidden { display: none !important; }

/* ---------- Structure ---------- */
.app { display: flex; flex-wrap: wrap; min-height: 100vh; }
.side { flex: 1 1 248px; max-width: 100%; background: var(--navy-900); color: #fff; padding: 22px 16px; display: flex; flex-direction: column; gap: 18px; }
.side-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; padding: 2px 6px; }
.brand:hover { color: #fff; }
.brand-mark { width: 44px; height: 44px; border-radius: 10px; background: #fff; color: var(--navy-700); display: flex; align-items: center; justify-content: center; font-family: var(--font-h); font-weight: 700; font-style: italic; font-size: 16px; flex: none; }
.brand-logo { background: #fff; border-radius: 10px; padding: 5px 7px; display: flex; align-items: center; justify-content: center; flex: none; height: 52px; }
.brand-logo img { height: 42px; width: auto; display: block; }
.brand-txt { display: flex; flex-direction: column; }
.brand-txt strong { font-family: var(--font-h); font-size: 17px; }
.brand-txt small { color: #A9B2DA; font-size: 12px; }
.side-toggle { display: none; background: transparent; border: 1px solid rgba(255,255,255,.25); color: #fff; width: 44px; height: 44px; border-radius: 10px; cursor: pointer; align-items: center; justify-content: center; }
.side-body { display: flex; flex-direction: column; gap: 18px; flex: 1; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group p { margin: 0 0 6px; padding: 0 12px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #8E98C6; }
.nav-group a, .nav-group .off { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: #C9D0EE; text-decoration: none; font-weight: 500; min-height: 44px; }
.nav-group a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-group a.on { background: #fff; color: var(--navy-900); font-weight: 600; }
.nav-group .off { color: #8E98C6; }
.side-user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; background: rgba(255,255,255,.06); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex: none; }
.who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.who a { color: #fff; font-weight: 600; text-decoration: none; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: #A9B2DA; font-size: 12px; }
.logout { color: #C9D0EE; display: flex; width: 36px; height: 36px; align-items: center; justify-content: center; border-radius: 8px; }
.logout:hover { color: #fff; background: rgba(255,255,255,.08); }
.main { flex: 999 1 560px; min-width: 0; padding: 26px 32px 48px; display: flex; flex-direction: column; gap: 20px; }
.main-public { min-height: 100vh; align-items: center; justify-content: center; }

@media (max-width: 860px) {
  .doc { padding: 22px 16px; }
  .side { flex-basis: 100%; padding: 12px 16px; gap: 12px; }
  .side-toggle { display: flex; }
  .side-body { display: none; }
  .side.open .side-body { display: flex; }
  .main { padding: 18px 16px 40px; }
  h1 { font-size: 24px; }
}

/* ---------- En-têtes et onglets ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; }
.page-title { display: flex; flex-direction: column; gap: 6px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.back { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; text-decoration: none; font-size: 14px; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs a { height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid #DDE1EC; background: #fff; color: var(--navy-700); font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; }
.tabs a.on { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }

/* ---------- Boutons et formulaires ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid #DDE1EC; background: #fff; color: var(--navy-700); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #B9C2E6; color: var(--navy-900); }
.btn-primary { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
.btn-primary:hover { background: var(--navy-900); color: #fff; }
.btn-danger { color: var(--red); border-color: var(--red-line); }
.btn-danger:hover { background: var(--red-bg); color: var(--red); }
.btn-amber { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-icon { min-height: 36px; width: 36px; padding: 0; }
.inline { display: inline; }
form.inline { display: inline-flex; }
label { font-size: 13px; font-weight: 600; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input[type=tel], select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #D5DAE6; border-radius: 9px; padding: 0 12px; min-height: 42px; width: 100%;
}
textarea { padding: 10px 12px; min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9DB0F0; outline-offset: 0; border-color: var(--blue); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--navy-700); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters label { min-width: 160px; }
.filters .grow { flex: 1 1 240px; }
.req::after { content: ' *'; color: var(--red); }

/* ---------- Cartes, KPI ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card.flush { padding: 0; gap: 0; overflow: hidden; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.card.flush .card-head { padding: 16px 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 16px; }
.split { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.split > .main-col { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.split > .side-col { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi-l { font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-v { font-family: var(--font-h); font-size: 25px; font-weight: 700; white-space: nowrap; }
.kpi-s { font-size: 13px; color: var(--muted); }
.kpi.navy { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
.kpi.navy .kpi-l, .kpi.navy .kpi-s { color: #C9D0EE; }
.kpi.red { border-color: var(--red-line); }
.kpi.red .kpi-l { color: var(--red); }
.kpi.amber { border-color: var(--amber-line); }
.kpi.amber .kpi-l { color: var(--amber); }
.kpi.internal { background: var(--amber-soft); border-color: var(--amber-line); }
.kpi.internal .kpi-l { color: var(--amber); }
.kpi.internal .kpi-s { color: var(--amber-ink); }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.kv > span:first-child { color: var(--muted); }
.kv.total { padding-top: 10px; border-top: 1px solid var(--line-soft); font-weight: 700; }
.kv.total > span:first-child { color: var(--ink); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-gray { background: var(--gray-bg); color: var(--gray); }
.b-navy { background: var(--navy-50); color: var(--navy-700); }
.b-blue { background: var(--sky-bg); color: var(--sky); }
.b-green { background: var(--green-bg); color: var(--green); }
.b-amber { background: var(--amber-bg); color: var(--amber); }
.b-red { background: var(--red-bg); color: var(--red); }
.b-purple { background: var(--purple-bg); color: var(--purple); }
.m-ok { color: var(--green); font-weight: 600; }
.m-low { color: var(--amber); font-weight: 600; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #F8F9FC; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tbody tr:hover td { background: #FAFBFE; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl .strong { font-weight: 600; }
.tbl .sub { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.tbl th.int, .tbl td.int { background: var(--amber-soft); }
.tbl th.int { color: var(--amber); background: var(--amber-bg); }
.tbl tfoot td { font-weight: 700; background: #F8F9FC; border-top: 1px solid var(--line); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* ---------- Messages ---------- */
.flash { padding: 12px 16px; border-radius: 10px; font-weight: 500; border: 1px solid; }
.flash-success { background: var(--green-bg); border-color: #B7DFC3; color: var(--green); }
.flash-error { background: var(--red-bg); border-color: var(--red-line); color: var(--red); }
.flash-info { background: var(--navy-50); border-color: #D5DBF3; color: var(--navy-700); }
.note { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--amber-bg); border: 1px solid var(--amber-line); color: var(--amber-ink); }
.note .ic { color: var(--amber); }

/* ---------- Pipeline ---------- */
.kanban-wrap { overflow-x: auto; padding-bottom: 6px; }
.kanban { display: grid; grid-template-columns: repeat(5, minmax(240px, 1fr)); gap: 14px; min-width: 1240px; }
.k-col { background: #ECEEF5; border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.k-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.k-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.k-card a.t { font-weight: 700; text-decoration: none; color: var(--ink); }
.k-card select { min-height: 34px; font-size: 12px; }

/* ---------- Progression ---------- */
.bar { height: 8px; border-radius: 999px; background: var(--line-soft); overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--blue); border-radius: 999px; }
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-row .bar { flex: 1; }

/* ---------- Fil de l'affaire ---------- */
.chain { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.chain li { display: flex; }
.chain .step { flex: 1; display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: #F8F9FC; color: var(--ink); text-decoration: none; }
.chain a.step:hover { border-color: #B9C2E6; }
.chain .step small { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.chain .step strong { font-size: 14px; }
.chain .step span { font-size: 12px; color: var(--muted); }
.chain .step.cur { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
.chain .step.cur small, .chain .step.cur span { color: #C9D0EE; }
.chain .step.todo { background: transparent; border-style: dashed; }

/* ---------- Éditeur de lignes ---------- */
.lines { width: 100%; border-collapse: collapse; font-size: 13px; }
.lines th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.lines th.int { color: var(--amber); background: var(--amber-bg); }
.lines th.num { text-align: right; }
.lines td { padding: 6px; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
.lines td.int { background: var(--amber-soft); }
.lines input, .lines select, .lines textarea { min-height: 38px; font-size: 13px; padding: 0 8px; }
.lines textarea { padding: 8px; min-height: 38px; height: 38px; }
.lines .c-des { min-width: 260px; width: 100%; }
.lines .c-n { width: 90px; text-align: right; }
.lines .c-u { width: 90px; }
.lines .c-t { width: 80px; }
.lines .c-tot { text-align: right; white-space: nowrap; padding-top: 16px; font-variant-numeric: tabular-nums; min-width: 110px; }
.lines .c-m { text-align: right; white-space: nowrap; padding-top: 16px; min-width: 110px; }
.totals-box { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 16px; }
.totals { width: 320px; max-width: 100%; display: flex; flex-direction: column; font-size: 14px; }
.totals > div { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); }
.totals > div.ttc { background: var(--navy-700); color: #fff; font-weight: 700; padding: 11px 14px; border-radius: 8px; border: 0; margin-top: 6px; }
.internal-box { width: 300px; max-width: 100%; display: flex; flex-direction: column; font-size: 14px; padding: 12px 14px; border-radius: 10px; background: var(--amber-soft); border: 1px dashed #E0B57A; }
.internal-box .h { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--amber); margin-bottom: 6px; }
.internal-box > div { display: flex; justify-content: space-between; padding: 5px 0; }
.mode-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: 12px; background: var(--amber-soft); border: 1px solid var(--amber-line); color: var(--amber-ink); font-size: 13px; }

/* ---------- Document (devis / facture) ---------- */
.doc { background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 24px rgba(22,30,85,.06); padding: 36px 32px; display: flex; flex-direction: column; gap: 24px; }
.doc-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 20px; }
.doc-co { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.doc-co .logo { height: 72px; max-width: 240px; width: auto; object-fit: contain; align-self: flex-start; margin-bottom: 6px; }
.doc-co .mark { font-family: var(--font-h); font-size: 34px; font-weight: 700; font-style: italic; color: var(--navy-700); line-height: 1; }
.doc-title { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; font-size: 13px; text-align: right; }
.doc-title .t { font-family: var(--font-h); font-size: 28px; font-weight: 700; letter-spacing: .06em; color: var(--navy-700); text-transform: uppercase; }
.doc-parties { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.doc-box { padding: 14px 16px; border-radius: 8px; background: var(--bg); display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.doc-box .h { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.doc-lines { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-lines th { background: var(--navy-700); color: #fff; text-align: left; font-weight: 600; font-size: 12px; padding: 9px 8px; white-space: nowrap; }
.doc-lines th.r { text-align: right; }
.doc-lines th.int { background: var(--amber); }
.doc-lines td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc-lines td.int { background: var(--amber-soft); }
.doc-lines .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-foot { padding-top: 14px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); text-align: center; line-height: 1.6; }
.pre { white-space: pre-line; }

/* ---------- Divers ---------- */
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line-soft); }
.list-row:first-of-type { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-row .t { font-weight: 600; }
.done .t { text-decoration: line-through; color: var(--muted); }
.chart { display: flex; gap: 6px; align-items: flex-end; height: 200px; padding-top: 10px; border-bottom: 1px solid #C9CFE0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.chart .b { width: 70%; max-width: 34px; background: var(--blue); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .b.pay { background: #D9822B; }
.chart .pair { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart .pair .b { width: 45%; }
.chart-labels { display: flex; gap: 6px; }
.chart-labels span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
details.add { border: 1px dashed #C9CFE0; border-radius: 10px; padding: 0; }
details.add > summary { cursor: pointer; padding: 12px 14px; font-weight: 600; color: var(--navy-700); list-style: none; display: flex; align-items: center; gap: 8px; min-height: 44px; }
details.add > summary::-webkit-details-marker { display: none; }
details.add[open] > summary { border-bottom: 1px dashed #C9CFE0; }
details.add > form { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.login-card { width: 400px; max-width: 100%; }
.pagination { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line-soft); }

/* Aperçu client : masque tout ce qui est interne */
.client-mode .int, .client-mode .internal-only { display: none !important; }

/* ---------- Impression ---------- */
@media print {
  body { background: #fff; font-size: 12px; }
  .side, .page-head, .no-print, .mode-bar, .tabs, .flash { display: none !important; }
  .main { padding: 0; }
  .doc { border: 0; box-shadow: none; padding: 0; }
  .doc .int, .doc .internal-only { display: none !important; }
  .doc-lines th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
