/* ==========================================================================
   CRM FIH International — Feuille de style globale
   --------------------------------------------------------------------------
   1. Variables (design tokens)      5. Composants : cartes, KPI
   2. Base & typographie             6. Composants : tableaux
   3. Layout (sidebar + contenu)     7. Composants : formulaires, modale, toast
   4. Composants : boutons, badges   8. Responsive
   ========================================================================== */

@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");

/* 1. Variables ------------------------------------------------------------ */
:root {
  --c-primary: #c8102e;
  --c-primary-600: #a50d26;
  --c-primary-50: #fbe9ec;
  --c-primary-text: #9e0c22;
  --c-side: #e8f0f8;
  --c-side-border: #d0dcea;
  --c-side-text: #17191c;
  --c-side-muted: #4a5564;
  --c-accent: #b00e26;

  --c-bg: #f6f6f4;
  --c-surface: #ffffff;
  --c-border: #e4e4e0;
  --c-text: #17191c;
  --c-muted: #5c626b;

  --c-success: #17603d;  --c-success-bg: #e3f3ea;
  --c-warning: #8a5a10;  --c-warning-bg: #fdf3e1;
  --c-danger:  #9e0c22;  --c-danger-bg:  #fbe9ec;
  --c-info:    #1e4e8c;  --c-info-bg:    #e6eef9;
  --c-neutral: #3f454d;  --c-neutral-bg: #ededea;

  --sidebar-w: 248px;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: none;
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --font: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* 2. Base ----------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.85rem; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 1.1rem; font-weight: 700; }
h3 { font-size: .95rem; font-weight: 600; }
a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--c-muted); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.icon { width: 18px; height: 18px; flex: none; vertical-align: middle; }

[hidden] { display: none !important; }

/* 3. Layout --------------------------------------------------------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--c-side);
  color: var(--c-side-text);
  border-right: 1px solid var(--c-side-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__brand {
  display: flex; flex-direction: column; align-items: stretch; gap: 10px;
  padding: 16px 16px 14px;
  font-weight: 800; font-size: 1rem; color: var(--c-side-text); text-align: center;
  border-bottom: 1px solid var(--c-side-border);
}
/* Logo de la société : toujours sur fond blanc, pour rester lisible quelle que soit sa couleur */
.brand-logo {
  display: flex; align-items: center; justify-content: center;
  background: #fff; border-radius: 8px; padding: 8px 12px; min-height: 56px;
}
.brand-logo img { max-width: 100%; max-height: 60px; display: block; }
.brand-logo.is-text { color: var(--c-primary); font-size: 1.4rem; font-weight: 800; letter-spacing: .04em; }
.sidebar__nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar__nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--c-side-text); font-weight: 500;
}
.sidebar__nav a:hover { background: rgba(255,255,255,.6); text-decoration: none; color: var(--c-side-text); }
.sidebar__nav a.active { background: #fff; color: var(--c-primary-text); font-weight: 700; box-shadow: inset 3px 0 0 var(--c-primary); }
.sidebar__nav { overflow-y: auto; flex: 1; min-height: 0; }
.nav-group {
  margin: 12px 12px 4px; font-size: .68rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--c-side-muted);
}
.sidebar__nav .count {
  margin-left: auto; font-size: .75rem; color: var(--c-side-muted);
  padding: 1px 4px;
}
.sidebar__footer { border-top: 1px solid var(--c-side-border); padding: 14px 20px; font-size: .75rem; color: var(--c-side-muted); }
.sidebar__user { display: flex; flex-direction: column; margin-bottom: 8px; }
.sidebar__user strong { color: var(--c-side-text); font-size: .88rem; }
.sidebar__btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: 0; color: var(--c-side-text); font: inherit; font-size: .82rem;
  padding: 6px 8px; margin: 0 -8px; border-radius: var(--radius-sm); cursor: pointer;
}
.sidebar__btn:hover { background: rgba(255,255,255,.6); }
.sidebar__btn .icon { width: 15px; height: 15px; }

/* Page de connexion */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(400px, 100%); }
.login-card .brand { display: flex; flex-direction: column; align-items: center; gap: 12px; font-weight: 800; font-size: 1.2rem; color: var(--c-text); margin-bottom: 6px; text-align: center; }
.login-card .brand .brand-logo { padding: 0; min-height: 0; }
.login-card .brand .brand-logo img { max-height: 90px; }
.login-card #intro { text-align: center; }
.login-card form { display: grid; gap: 14px; margin-top: 18px; }
.login-card .btn { width: 100%; padding: 10px; }
.form-error { color: var(--c-danger); background: var(--c-danger-bg); padding: 8px 12px; border-radius: var(--radius-sm); font-size: .88rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: none; /* visible uniquement en mobile */
  align-items: center; gap: 12px;
  padding: 12px 16px; background: #17191c; color: #fff;
  position: sticky; top: 0; z-index: 30;
}
.topbar .burger { background: none; border: 0; color: #fff; cursor: pointer; padding: 4px; }
.content { padding: 28px 32px 48px; max-width: 1280px; width: 100%; }

.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-header p { margin: 4px 0 0; color: var(--c-muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--c-border);
}
.toolbar .search { flex: 1 1 240px; }

.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 24px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }

/* 4. Boutons & badges ----------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid #d5d5d0; background: var(--c-surface); color: var(--c-text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: #f3f3f0; border-color: #c4c4be; text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; font-weight: 700; }
.btn-primary:hover { background: var(--c-primary-600); border-color: var(--c-primary-600); }
.btn-danger { color: var(--c-danger); }
.btn-danger:hover { background: var(--c-danger-bg); border-color: #efc3ca; }
.btn-danger.solid { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: #ededea; border-color: transparent; }
.btn-sm { padding: 5px 9px; font-size: .82rem; }
.btn-icon { padding: 6px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 99px;
  font-size: .78rem; font-weight: 700; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-neutral { color: var(--c-neutral); background: var(--c-neutral-bg); }
.badge-info    { color: var(--c-info);    background: var(--c-info-bg); }
.badge-success { color: var(--c-success); background: var(--c-success-bg); }
.badge-danger  { color: var(--c-danger);  background: var(--c-danger-bg); }
.badge-warning { color: var(--c-warning); background: var(--c-warning-bg); }

/* Sélecteur de statut intégré au tableau */
.status-select {
  border: 1px solid transparent; border-radius: 99px;
  padding: 3px 8px; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.status-select:hover { border-color: var(--c-border); }

/* 5. Cartes & KPI --------------------------------------------------------- */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card__header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--c-border);
}
.card__body { padding: 18px; }
.card + .card { margin-top: 20px; }
.grid > .card { margin-top: 0; } /* pas de décalage dans les grilles */

.kpi { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.kpi__icon {
  width: 42px; height: 42px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  background: var(--c-primary-50); color: var(--c-primary-text);
}
.kpi__label { color: var(--c-muted); font-size: .8rem; }
.kpi__value { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.kpi__sub { font-size: .78rem; color: var(--c-muted); }

.module-link {
  display: flex; gap: 14px; align-items: flex-start; padding: 18px;
  color: inherit; transition: border-color .15s, transform .15s;
}
.module-link:hover { border-color: var(--c-accent); text-decoration: none; transform: translateY(-1px); }
.module-link p { margin: 4px 0 0; color: var(--c-muted); font-size: .85rem; }

.empty { padding: 36px 16px; text-align: center; color: var(--c-muted); }

/* Entités : même mise en page, repère de couleur distinct */
:root { --c-entite: var(--c-primary-text); --c-entite-bg: var(--c-primary-50); --c-entite-bar: var(--c-primary); }
body[data-entite="ip"] { --c-entite: #17191c; --c-entite-bg: #e2e3e1; --c-entite-bar: #17191c; }
.entite-tag {
  display: inline-flex; align-items: center; padding: 3px 12px; border-radius: 99px;
  font-size: .8rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
  color: var(--c-entite); background: var(--c-entite-bg);
}
.entite-tag.fih { --c-entite: var(--c-primary-text); --c-entite-bg: var(--c-primary-50); }
.entite-tag.ip  { --c-entite: #17191c; --c-entite-bg: #e2e3e1; }
.entite-tag.sm { padding: 1px 8px; font-size: .72rem; }
.page-header.entite { border-left: 5px solid var(--c-entite-bar); padding-left: 14px; }
.page-header.entite h1 { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.entite-switch { display: inline-flex; padding: 3px; border-radius: 10px; background: #ebebe7; }
.entite-switch a { padding: 7px 13px; border-radius: 8px; font-weight: 600; font-size: .85rem; color: #4a5058; }
.entite-switch a:hover { color: var(--c-text); text-decoration: none; }
.entite-switch a.on { background: #fff; color: var(--c-text); font-weight: 700; }
.code-affaire { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; letter-spacing: .02em; }
.toolbar .dates { display: flex; align-items: center; gap: 6px; color: var(--c-muted); font-size: .82rem; }
.toolbar .dates .input { width: auto; padding: 6px 8px; }

/* 6. Tableaux ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-size: .9rem;
}
table.data th, table.data td {
  padding: 12px 10px; text-align: left; border-bottom: 1px solid #ecece8;
  vertical-align: middle;
}
table.data th {
  background: transparent; color: var(--c-muted); font-weight: 700;
  font-size: .78rem;
  white-space: nowrap; user-select: none;
}
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--c-text); }
table.data th .sort-ind { opacity: .35; margin-left: 4px; }
table.data th.sorted .sort-ind { opacity: 1; color: var(--c-primary); }
table.data tbody tr:hover { background: #fafaf8; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.actions { text-align: right; white-space: nowrap; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* 7. Formulaires ---------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-weight: 600; font-size: .82rem; }
.field label .req { color: var(--c-danger); }
.input, select.input, textarea.input {
  width: 100%; padding: 8px 11px; font: inherit; color: var(--c-text);
  background: #fff; border: 1px solid #d5d5d0; border-radius: var(--radius-sm);
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: none; border-color: var(--c-accent); box-shadow: 0 0 0 3px rgba(200,16,46,.15); }
.input:invalid:not(:placeholder-shown) { border-color: var(--c-danger); }
.field .hint { font-size: .75rem; color: var(--c-muted); }

/* Lignes de devis */
.lines-table { width: 100%; border-collapse: collapse; }
.lines-table th { font-size: .75rem; color: var(--c-muted); text-align: left; padding: 6px 4px; }
.lines-table td { padding: 4px; }
.lines-table .col-qty { width: 90px; }
.lines-table .col-price { width: 130px; }
.lines-table .col-total { width: 120px; text-align: right; font-variant-numeric: tabular-nums; }
.lines-table .col-del { width: 40px; text-align: center; }
.totals {
  margin-top: 12px; margin-left: auto; width: min(320px, 100%);
  display: grid; grid-template-columns: 1fr auto; gap: 4px 16px;
  font-variant-numeric: tabular-nums;
}
.totals .grand { font-weight: 700; font-size: 1.05rem; border-top: 1px solid var(--c-border); padding-top: 6px; }

/* Modale */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 32, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; z-index: 100; overflow-y: auto;
  animation: fade .15s ease;
}
.modal {
  background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: min(620px, 100%); animation: pop .18s ease;
}
.modal.wide { width: min(880px, 100%); }
.modal__header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--c-border); }
.modal__body { padding: 20px; }
.modal__footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--c-border); background: #fafaf8; border-radius: 0 0 var(--radius) var(--radius); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

/* Toast */
.toast-zone { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: #17191c; color: #fff; padding: 10px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: .88rem; animation: pop .2s ease;
  border-left: 4px solid var(--c-accent);
}
.toast.success { border-left-color: #3ecf8e; }
.toast.error { border-left-color: #ff6b5b; }

/* Panneau de détail (fiche client) */
.detail-list { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; }
.detail-list dt { color: var(--c-muted); }
.detail-list dd { margin: 0; }
.section-title { margin: 22px 0 10px; display: flex; justify-content: space-between; align-items: center; }

/* 8. Responsive ----------------------------------------------------------- */
@media (max-width: 900px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; display: none; }
  .sidebar-overlay.show { display: block; }
  .content { padding: 20px 16px 40px; }
}

@media (max-width: 640px) {
  .grid-kpi { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px; gap: 10px; }
  .kpi__icon { display: none; }
  .kpi__value { font-size: 1.15rem; }
  .form-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .page-header { align-items: stretch; }

  /* Tableaux → cartes empilées */
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { padding: 10px 14px; border-bottom: 1px solid var(--c-border); }
  table.data td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.data td::before { content: attr(data-label); color: var(--c-muted); font-size: .8rem; text-align: left; }
  table.data td.actions { justify-content: flex-end; padding-top: 8px; }
  table.data td.actions::before { content: none; }

  .lines-table thead { display: none; }
  .lines-table tr { display: grid; grid-template-columns: 1fr 1fr 40px; gap: 6px; padding: 8px 0; border-bottom: 1px dashed var(--c-border); }
  .lines-table td:first-child { grid-column: 1 / -1; }
  .lines-table .col-total { display: none; }
  .detail-list { grid-template-columns: 1fr; }
  .detail-list dt { margin-top: 6px; }
}

@media print {
  .sidebar, .topbar, .page-actions, .toolbar, td.actions { display: none !important; }
  .content { padding: 0; }
}
.detail-list dd.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data th:first-child, table.data td:first-child { padding-left: 16px; }
table.data td.actions { padding-right: 12px; }
.cell-adresse { display: block; max-width: 230px; font-size: .85rem; }
@media (max-width: 640px) { .cell-adresse { max-width: none; } }
.cell-email { display: inline-block; max-width: 200px; overflow-wrap: anywhere; }
.cell-objet { display: block; max-width: 250px; }
@media (max-width: 640px) { .cell-objet { max-width: none; } }
/* Liens des tableaux : en noir (le rouge reste réservé aux actions principales) */
table.data td a:not(.btn) { color: var(--c-text); font-weight: 600; }
table.data td a:not(.btn):hover { color: var(--c-accent); }
/* Titres d'entité du menu : bandeau bleu marine, texte blanc */
.nav-group.is-entite {
  margin: 14px 0 6px; padding: 8px 12px; border-radius: 8px;
  background: #14274e; color: #fff; font-size: .72rem;
}
.nav-group.is-entite { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; }
.entite-logo { width: 44px; height: 30px; flex: none; object-fit: contain; background: #fff; border-radius: 7px; padding: 2px; }
/* En-tête : deux logos côte à côte, même hauteur */
.brand-logo { gap: 12px; }
.brand-logo img { height: 54px; width: auto; max-width: 48%; object-fit: contain; }
.brand-logo strong { color: var(--c-primary); font-size: 1.4rem; font-weight: 800; letter-spacing: .04em; }
.login-card .brand .brand-logo img { height: 84px; max-height: none; }
/* Messagerie */
.mail-list { display: flex; flex-direction: column; border: 1px solid var(--c-border); border-radius: var(--radius-sm); overflow: hidden; }
.mail-item { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 11px 14px; background: #fff; border: 0; border-bottom: 1px solid var(--c-border); font: inherit; color: inherit; cursor: pointer; }
.mail-item:last-child { border-bottom: 0; }
.mail-item:hover, .mail-item:focus-visible { background: #fafaf8; outline: none; box-shadow: inset 3px 0 0 var(--c-primary); }
.mail-item__top { display: flex; justify-content: space-between; gap: 12px; }
.mail-item__objet { font-weight: 600; }
.mail-item__resume { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-corps { margin-top: 12px; padding: 14px 16px; background: #fafaf8; border: 1px solid var(--c-border); border-radius: var(--radius-sm); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 55vh; overflow-y: auto; }
.mail-piece { display: flex; align-items: center; gap: 10px; font-weight: 500; padding: 10px 12px; border: 1px solid var(--c-border); border-radius: var(--radius-sm); background: #fafaf8; }
.mail-piece a { margin-left: auto; font-size: .85rem; }
.line-extra { display: flex; gap: 6px; margin-top: 4px; }
.line-extra .input { padding: 5px 9px; font-size: .82rem; }
.lines-table td { vertical-align: top; }
.lines-table .col-total { padding-top: 12px; }
