/* ==========================================================================
   NextGen Pulse — Charte graphique officielle « Pulse »
   Source unique de vérité : ce bloc de tokens. Aucun hex en dehors de :root.
   ========================================================================== */
:root {
  /* Primaire — Pulse Orange */
  --pulse-50: #FCF3EE;
  --pulse-100: #F7E0D4;
  --pulse-200: #F2C0A6;
  --pulse-300: #EE996D;
  --pulse-400: #EC7131;
  --pulse-500: #CD4E0C;
  --pulse-600: #C54807;
  --pulse-700: #A33B06;
  --pulse-800: #802F04;
  --pulse-900: #5E2203;

  /* Accents */
  --accent-teal: #25749D;
  --accent-teal-light: #419AC8;
  --accent-terracotta: #C12B25;
  --accent-amber: #D9AE26;

  /* Neutres chauds */
  --bg-warm: #FAF7F2;
  --neutral-light: #F2EFEE;
  --neutral-mid: #6E625B;  /* texte secondaire — AA 5.9:1 sur blanc */
  --ink-dark: #382B24;
  --ink-darker: #231A15;

  /* Sémantiques (statuts) — texte sur fonds dédiés uniquement */
  --success: #2E7D4F;
  --success-text: #256B43;   /* AA 5.35:1 sur --success-bg */
  --warning: #C99400;        /* jamais en texte sur fond clair */
  --warning-text: #8A6400;   /* AA 4.53:1 sur --warning-bg */
  --warning-deep: #7A5800;  /* fonds de flash — AA 6.9:1 avec blanc */
  --danger: #B3261E;
  --info: #2D7FA9;

  /* Fonds pâles sémantiques (tint des couleurs de statut) */
  --success-bg: #D8F0DF;
  --info-bg: #E3F0F7;
  --danger-bg: #F6D9D7;
  --warning-bg: #F7EBCB;
  --danger-bg-soft: #FAEFED;

  /* Alias sémantiques (usage interne uniquement — référencent les tokens) */
  --text: var(--ink-dark);
  --text-muted: var(--neutral-mid);
  --bg: var(--bg-warm);
  --border: #E5DED8; /* neutre chaud dérivé, séparateurs discrets */
  --card-bg: #FFFFFF;
  --white: #FFFFFF;
  --primary: var(--pulse-600);  /* AA 4.88:1 avec blanc */
  --primary-hover: var(--pulse-400);
  --primary-active: var(--pulse-600);
  --focus: var(--accent-teal);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ===== Login ===== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--pulse-700) 0%, var(--pulse-900) 100%);
}
.login-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 40px rgba(35, 26, 21, 0.25);
  text-align: center;
}
.login-logo { width: 220px; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.4rem; margin: 0 0 1.5rem; color: var(--pulse-700); }
.login-card label { display: block; text-align: left; margin: 0.75rem 0 0.25rem; font-weight: 600; font-size: 0.9rem; }
.login-card input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
.login-card input:focus { outline: 2px solid var(--focus); border-color: var(--focus); }

/* ===== App shell ===== */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: linear-gradient(180deg, var(--pulse-700) 0%, var(--pulse-900) 100%);
  color: var(--white);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
}
.sidebar-logo { width: 100%; margin-bottom: 1.5rem; filter: drop-shadow(0 1px 2px rgba(94, 34, 3, 0.35)); }
.sidebar nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav-item { color: var(--white); text-decoration: none; padding: 0.55rem 0.75rem; border-radius: 6px; }
.nav-item:hover { background: var(--pulse-600); color: var(--white); }
.nav-item.active { background: var(--pulse-600); color: var(--white); box-shadow: inset 3px 0 0 var(--pulse-300); }
.sidebar-footer { margin-top: auto; font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.5rem; }
.content { flex: 1; padding: 2rem 3rem; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
h1 { color: var(--ink-darker); margin-top: 0; }
h2 { color: var(--pulse-700); }

/* ===== Boutons ===== */
.btn-primary, .btn-ghost, .btn-danger-link, .btn-secondary {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn-primary { background: var(--primary); color: var(--white); font-weight: 600; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { background: var(--primary-active); }
.btn-secondary { background: var(--card-bg); color: var(--accent-teal); border: 1px solid var(--accent-teal); padding: 0.45rem 0.9rem; border-radius: 4px; font-weight: 600; font-size: 0.9rem; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-danger-link { background: none; color: var(--danger); padding: 0.25rem 0; }
.login-card .btn-primary { width: 100%; margin-top: 1.5rem; }

/* ===== Tables ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.data-table th, .data-table td { padding: 0.65rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--pulse-50); color: var(--pulse-800); }
.mono { font-family: monospace; font-size: 0.8rem; max-width: 380px; overflow-wrap: anywhere; }
.actions a, .actions button { margin-right: 0.75rem; color: var(--accent-teal); }
.inline-form { display: inline; }

/* ===== Formulaires ===== */
.form-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 760px;
  margin-bottom: 2rem;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.25rem; }
.form-grid input, .form-grid select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
.form-grid input:focus, .form-grid select:focus { outline: 2px solid var(--focus); border-color: var(--focus); }
.form-grid small { color: var(--text-muted); }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 600; }
.form-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ===== Flashes ===== */
.flashes { position: fixed; top: 1rem; right: 1rem; z-index: 100; max-width: 380px; }
.flash { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 0.5rem; color: var(--white); box-shadow: 0 4px 12px rgba(35, 26, 21, 0.15); }
.flash-success { background: var(--success); }
.flash-danger { background: var(--danger); }
.flash-warning { background: var(--warning-deep); }
.flash-info { background: var(--info); }

/* ===== Modules métier ===== */
.span-2 { grid-column: span 2; }
.search-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; max-width: 480px; }
.search-bar input { flex: 1; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; }
.search-bar input:focus { outline: 2px solid var(--focus); border-color: var(--focus); }
.header-actions { display: flex; gap: 0.75rem; align-items: center; }
.thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); }

/* Statuts — couleurs sémantiques réservées aux statuts */
.status { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 12px; font-size: 0.8rem; font-weight: 600; }
.status-new { background: var(--pulse-100); color: var(--pulse-800); }
.status-progress { background: var(--info-bg); color: var(--accent-teal); }
.status-sent { background: var(--neutral-light); color: var(--ink-dark); }
.status-validated { background: var(--success-bg); color: var(--success-text); }
.status-refused { background: var(--danger-bg); color: var(--danger); }
.status-today { background: var(--warning-bg); color: var(--warning-text); }
tr.overdue td { background: var(--danger-bg-soft); }

/* ===== Constructeur de lignes ===== */
.lines-table textarea, .lines-table input, .lines-table select { width: 100%; padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; font: inherit; }
.line-kind { font-size: 0.75rem; font-weight: 700; color: var(--pulse-600); }
.line-actions { margin: 0.75rem 0; display: flex; gap: 0.5rem; }
.totals-preview { font-size: 1.05rem; margin: 0.75rem 0; color: var(--pulse-800); }
.section-row td { background: var(--pulse-50); font-size: 1.05rem; }
.note-row td { color: var(--text-muted); }

/* ===== Totaux ===== */
.totals-block { margin: 1.25rem 0; max-width: 380px; margin-left: auto; }
.totals-row { display: flex; justify-content: space-between; padding: 0.4rem 0; font-size: 1.05rem; }
.total-ttc { font-size: 1.25rem; color: var(--pulse-700); border-top: 2px solid var(--pulse-500); }
.margin-block { background: var(--card-bg); border: 1px dashed var(--border); padding: 1rem; border-radius: 8px; margin-top: 1.5rem; max-width: 560px; margin-left: auto; }

/* ===== Autocomplete ===== */
.autocomplete-results { position: relative; }
.autocomplete-item { padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-top: none; background: var(--card-bg); cursor: pointer; }
.autocomplete-item:hover { background: var(--pulse-50); }
.client-selected { color: var(--success); font-weight: 600; margin-top: 0.4rem; }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; background: rgba(35, 26, 21, 0.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-content { background: var(--card-bg); border-radius: 10px; padding: 1.5rem; width: 100%; max-width: 520px; max-height: 80vh; overflow: auto; }
#product-search { width: 100%; padding: 0.5rem; margin: 0.5rem 0; border: 1px solid var(--border); border-radius: 6px; }

/* ===== Stats & graphiques ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 1.1rem; }
.stat-label { color: var(--text-muted); font-size: 0.85rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--pulse-700); margin-top: 0.3rem; }
.stat-sub { font-size: 0.8rem; color: var(--text-muted); }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding: 1rem; background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 2rem; overflow-x: auto; }
.chart-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 28px; }
.chart-col.narrow { min-width: 12px; }
.chart-bar { width: 100%; min-height: 2px; background: var(--pulse-500); border-radius: 3px 3px 0 0; }
.chart-bar:nth-child(even) { background: var(--accent-teal); }
.chart-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ===== Lien de validation & signature ===== */
.link-box input { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; background: var(--pulse-50); }
.public-wrapper { min-height: 100vh; background: linear-gradient(135deg, var(--pulse-700) 0%, var(--pulse-900) 100%); padding: 2rem 1rem; }
.public-card { background: var(--card-bg); max-width: 860px; margin: 0 auto; border-radius: 12px; padding: 2rem; box-shadow: 0 10px 40px rgba(35, 26, 21, 0.25); }
.public-logo { width: 220px; margin-bottom: 1rem; }
.public-meta { color: var(--text-muted); }
.signature-box { margin-top: 2rem; border: 2px solid var(--pulse-500); border-radius: 10px; padding: 1.5rem; }
.signature-box label { display: block; font-weight: 600; margin-bottom: 0.4rem; }
.signature-box input { width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 1rem; }
.validated-box { margin-top: 2rem; background: var(--success-bg); color: var(--success-text); padding: 1rem 1.5rem; border-radius: 10px; font-weight: 600; }
.refused-box { margin-top: 2rem; background: var(--danger-bg); color: var(--danger); padding: 1rem 1.5rem; border-radius: 10px; font-weight: 600; }
.refuse-form { margin-top: 0.75rem; }
.status-line { margin: 0.5rem 0; }

/* Bannière brouillon facture */
.draft-banner { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--accent-amber); border-radius: 8px; padding: 0.75rem 1.25rem; font-weight: 700; margin-bottom: 1rem; }

/* ===== Style constructeur (devis/factures) ===== */
.odoo-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; gap: 1rem; flex-wrap: wrap; }
.mb0 { margin-bottom: 0; }
.odoo-form { background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px; padding: 1.25rem; }
.odoo-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.odoo-field label { display: block; font-weight: 600; color: var(--text-muted); font-size: 0.8rem; margin-bottom: 0.3rem; }
.odoo-field input, .odoo-field select {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
  background: var(--card-bg);
}
.odoo-field input:focus, .odoo-field select:focus { outline: 2px solid var(--focus); border-color: var(--focus); }
.field-static { padding: 0.45rem 0; font-weight: 600; }

/* Tableau de lignes */
.odoo-lines { width: 100%; border-collapse: collapse; }
.odoo-lines thead th {
  background: var(--neutral-light);
  color: var(--ink-dark);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.odoo-lines thead th.col-qty, .odoo-lines thead th.col-price, .odoo-lines thead th.col-tax,
.odoo-lines thead th.col-disc, .odoo-lines thead th.col-amount { text-align: right; }
.odoo-lines tbody tr { border-bottom: 1px solid var(--neutral-light); }
.odoo-lines tbody tr:hover { background: var(--bg-warm); }
.odoo-lines td { padding: 0.4rem 0.6rem; vertical-align: top; }
.odoo-lines textarea, .odoo-lines input, .odoo-lines select {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-size: 0.92rem;
  background: transparent;
  resize: vertical;
}
.odoo-lines textarea:hover, .odoo-lines input:hover, .odoo-lines select:hover { border-color: var(--border); }
.odoo-lines textarea:focus, .odoo-lines input:focus, .odoo-lines select:focus {
  outline: none;
  border-color: var(--focus);
  background: var(--card-bg);
}
.col-desc { width: 44%; }
.col-qty, .col-disc { width: 8%; }
.col-price { width: 11%; }
.col-tax { width: 8%; }
.col-amount { width: 11%; text-align: right; }
.col-del { width: 5%; text-align: right; white-space: nowrap; }
.cell-amount { font-weight: 600; text-align: right; }
.section-row td { background: var(--pulse-50); }
.section-row .section-title { font-weight: 700; font-size: 1rem; background: transparent !important; border: 1px dashed transparent !important; }
.section-row .section-title:hover, .section-row .section-title:focus { border-color: var(--pulse-200) !important; }
.note-row .note-text { font-style: italic; color: var(--text-muted); }

/* Boutons-liens */
.odoo-add-line { margin: 0.6rem 0 1rem; display: flex; gap: 1.25rem; flex-wrap: wrap; }
.link-btn { background: none; border: none; color: var(--accent-teal); font-weight: 600; cursor: pointer; padding: 0.25rem 0; font-size: 0.92rem; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.link-btn.sm { padding: 0.1rem 0.25rem; font-size: 0.85rem; color: var(--neutral-mid); }
.link-btn.sm.danger { color: var(--danger); }

/* Totaux */
.odoo-totals { margin-left: auto; max-width: 320px; border-top: 1px solid var(--border); }
.tot-row { display: flex; justify-content: space-between; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--neutral-light); }
.tot-row.total { font-weight: 700; font-size: 1.15rem; color: var(--pulse-700); border-top: 2px solid var(--pulse-500); border-bottom: none; }

.multiline { white-space: pre-wrap; }

/* ===== Tuiles d'accueil ===== */
.home-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.25rem; margin: 1.5rem 0; }
.home-tile { display: block; border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; background: var(--card-bg); text-decoration: none; color: inherit; }
.home-tile:hover { border-color: var(--pulse-500); box-shadow: 0 2px 8px rgba(205, 78, 12, 0.12); }
.home-tile h2 { margin: 0 0 .5rem; font-size: 1.05rem; color: var(--pulse-700); }
.home-tile p { margin: 0 0 .75rem; font-size: .9rem; color: var(--text-muted); }
.home-tile-count { font-size: .85rem; color: var(--text-muted); }

/* ===== Accueil : objectif mensuel ===== */
.home-intro { margin-bottom: 0.75rem; }
.target-progress { margin: 0 0 2rem; max-width: 760px; }
.target-progress-label { display: flex; justify-content: space-between; font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.target-progress-bar { height: 14px; background: var(--neutral-light); border-radius: 7px; overflow: hidden; }
.target-progress-fill { height: 100%; background: var(--pulse-500); border-radius: 7px; transition: width 0.3s; }
.target-progress-fill.over { background: var(--success); }
.target-achieved { margin-top: 0.5rem; font-weight: 700; color: var(--success-text); }
.target-form { max-width: 560px; }
.target-form h2 { margin-top: 0; }

/* ===== Rapprochement bancaire ===== */
.bank-table td { padding: 0.4rem 0.6rem; vertical-align: middle; }
.bank-label { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.suggested td { background: var(--pulse-50); }
.badge-count { display: inline-block; min-width: 26px; padding: 0.1rem 0.5rem; border-radius: 10px; font-size: 0.8rem; font-weight: 700; background: var(--pulse-500); color: var(--white); text-align: center; }
.badge-count.muted { background: var(--neutral-light); color: var(--ink-dark); }
.bank-bulk { margin-top: 0.75rem; justify-content: flex-start; align-items: center; }
.file-input-inline { font-size: 0.85rem; max-width: 340px; }
.ta-r { text-align: right; }
.ta-c { text-align: center; }
.invoice-lookup { position: relative; }
.invoice-search { width: 100%; padding: 0.3rem 0.45rem; font-size: 0.85rem; font-family: monospace; }
.invoice-dropdown { display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 60;
                    background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px;
                    box-shadow: 0 4px 14px rgba(35,26,21,.15); max-height: 240px; overflow-y: auto; }
.invoice-option { padding: 0.4rem 0.6rem; cursor: pointer; font-size: 0.85rem; }
.invoice-option:hover, .invoice-option.active { background: var(--pulse-50); }
.invoice-option .stat-sub { float: right; }
.invoice-cell { min-width: 240px; }
.empty-state { padding: 2rem; text-align: center; color: var(--text-muted); background: var(--card-bg); border: 1px dashed var(--border); border-radius: 8px; }
