/* ===== Charte INNOVEA GROUP ===== */
:root {
  --blue:        #15456F;   /* bleu principal */
  --blue-soft:   #EEF3F8;   /* fond bleu très clair */
  --blue-border: #C5D5E8;   /* bordures internes claires */
  --bordeaux:    #8C192D;   /* accent rouge/bordeaux */
  --ink:         #333333;   /* texte courant */
  --grey:        #666666;   /* texte secondaire */
  --paper:       #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #e9edf2;
  color: var(--ink);
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 13px;
  line-height: 1.35;
}

/* ===== Barre d'outils ===== */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--blue);
  color: #fff;
}
.toolbar-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.toolbar-title { font-weight: 600; letter-spacing: .3px; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  font: inherit;
  font-size: 13px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--bordeaux); color: #fff; }
.btn-primary:hover { opacity: .9; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); }
.btn-ghost:hover { background: rgba(255,255,255,.12); }

/* ===== Feuille A4 ===== */
.sheet {
  background: var(--paper);
  width: 210mm;
  min-height: 297mm;
  margin: 20px auto;
  padding: 16mm 14mm;
  box-shadow: 0 2px 14px rgba(0,0,0,.18);
}

/* ===== En-tête société ===== */
.doc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--blue);
  padding-bottom: 8px;
}
.brand-logo { height: 56px; width: auto; }
.brand-contact {
  text-align: right;
  font-size: 11px;
  color: var(--grey);
  line-height: 1.5;
}
.brand-contact strong { color: var(--blue); font-size: 12px; }

/* ===== Titre ===== */
.doc-title { margin: 14px 0 16px; }
.doc-title h1 {
  margin: 0;
  color: var(--blue);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .5px;
}
/* Sous-titre : champ libre, saisi par l'utilisateur (data-field="subtitle"). */
.subtitle {
  display: block;
  width: 100%;
  margin: 2px 0 0 -4px;   /* -4px compense le padding : aligné sur le H1 */
  padding: 2px 4px;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12px;
  color: var(--bordeaux);
}
.subtitle::placeholder { color: #c49aa3; }
.subtitle:hover { background: var(--blue-soft); }
.subtitle:focus { outline: 2px solid var(--blue-border); outline-offset: -2px; background: #fff; }

/* ===== Blocs COMMANDE / CLIENT ===== */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 6px;
}
.info-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--blue);
}
.info-table thead th {
  background: var(--blue);
  color: #fff;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 6px 10px;
}
.info-table td {
  border-bottom: 1px solid var(--blue-border);
  padding: 5px 10px;
  vertical-align: middle;
}
.info-table tr:last-child td { border-bottom: none; }
.info-table .label {
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
  width: 40%;
  white-space: nowrap;
}
.info-table .value { color: var(--ink); }

/* ===== Titres de section ===== */
.section-heading {
  color: var(--blue);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .5px;
  margin: 18px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--blue);
}

/* ===== Tableau des articles ===== */
.items-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--blue-border);
}
.items-table thead th {
  background: var(--blue);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  padding: 7px 6px;
  border: 1px solid var(--blue-border);
  text-align: center;
}
.items-table tbody td {
  border: 1px solid var(--blue-border);
  padding: 0;
  vertical-align: middle;
}
.items-table tbody tr:nth-child(even) td { background: var(--blue-soft); }
.items-table .cell-num {
  text-align: center;
  color: var(--ink);
  font-size: 12px;
  width: 36px;
}
.col-num   { width: 36px; }
.col-ref   { width: 18%; }
.col-qte   { width: 56px; }
.col-pu    { width: 16%; }
.col-total { width: 16%; }

.items-table .cell-total {
  text-align: right;
  padding: 6px 8px;
  color: var(--ink);
  font-size: 12px;
  white-space: nowrap;
}
.row-actions { width: 44px; text-align: center; white-space: nowrap; }

/* Inputs dans le tableau */
.items-table input {
  width: 100%;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  padding: 6px 8px;
}
.items-table input.num { text-align: right; }
.items-table input.center { text-align: center; }
.items-table input:focus { outline: 2px solid var(--blue-border); outline-offset: -2px; background: #fff; }

.btn-del,
.btn-add {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
}
.btn-del { color: var(--bordeaux); }
.btn-del:hover { opacity: .7; }

/* Bouton "+" : masqué partout, visible seulement sur la dernière ligne */
.btn-add {
  display: none;
  color: #fff;
  background: var(--blue);
  border-radius: 4px;
  font-weight: 700;
  width: 18px;
  height: 18px;
}
.btn-add:hover { background: #1d5a92; }
.items-table tr.is-last .btn-add { display: inline-block; }

/* ===== Bas de page : modalités + totaux ===== */
.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 0.85fr;
  gap: 18px;
  margin-top: 16px;
  align-items: start;
}
.pay-block .section-heading { margin-top: 0; }
.pay-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 6px 0;
}
.pay-label {
  display: inline-block;
  min-width: 70px;
  font-weight: 700;
  color: var(--blue);
}
.chk { display: inline-flex; align-items: center; gap: 5px; }
.pay-pct {
  width: 46px;
  border: none;
  border-bottom: 1px solid var(--blue-border);
  background: transparent;
  font: inherit;
  text-align: center;
  color: var(--ink);
}
.pay-pct:focus { outline: none; border-bottom-color: var(--blue); }

/* Totaux */
.totals-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--blue);
  margin-top: 28px;
}
.totals-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--blue-border);
}
.totals-table .t-label {
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
  white-space: nowrap;
}
.totals-table .t-value { text-align: right; white-space: nowrap; }
.totals-table .t-input input,
.tva-pct {
  border: none;
  border-bottom: 1px solid var(--blue-border);
  background: transparent;
  font: inherit;
  text-align: right;
  color: var(--ink);
  width: 90px;
}
.tva-pct { width: 34px; text-align: center; }
.totals-table .t-input input:focus,
.tva-pct:focus { outline: none; border-bottom-color: var(--blue); }
.totals-table .t-ttc td {
  background: var(--bordeaux);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  border-bottom: none;
}

/* ===== Signatures ===== */
.sign-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.sign-box {
  border: 1px solid var(--blue-border);
  border-radius: 4px;
  padding: 10px 12px 28px;
}
.sign-title {
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
  margin: -10px -12px 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--blue-border);
}
.sign-box p { margin: 8px 0; color: var(--ink); }
.sign-zone { margin-top: 22px; }

/* ===== Pied ===== */
.doc-footer {
  margin-top: 22px;
  padding-top: 8px;
  border-top: 1px solid var(--blue);
  text-align: center;
  font-size: 10px;
  color: var(--grey);
  line-height: 1.6;
}
.footer-line { color: var(--blue); }

/* ===== Mode du document : bon de commande ou facture proforma =====
   body.is-proforma est posé par app.js ; les éléments propres à chaque mode
   portent .only-bc / .only-pro. */
body:not(.is-proforma) .only-pro { display: none !important; }
body.is-proforma .only-bc { display: none !important; }

.proforma-note {
  margin: 14px 0 0;
  padding: 8px 12px;
  border-left: 3px solid var(--bordeaux);
  background: var(--blue-soft);
  font-size: 11px;
  color: var(--grey);
  line-height: 1.5;
}
.proforma-note strong { color: var(--bordeaux); }

/* Valeurs recopiées par app.js juste avant l'impression : invisibles à l'écran. */
.print-value { display: none; }

/* ===== Impression ===== */
@media print {
  @page { size: A4; margin: 12mm; }
  html, body { background: #fff; font-size: 11px; }
  .no-print { display: none !important; }
  .sheet {
    width: auto;
    min-height: auto;
    margin: 0;
    padding: 0;
    box-shadow: none;
  }
  .row-actions { display: none; }

  /* Les champs de saisie tronquent le texte trop long : on les remplace par
     leur valeur en texte (.print-value), qui passe à la ligne. */
  .sheet input:not([type="checkbox"]):not([type="radio"]) { display: none !important; }
  .print-value {
    display: inline;
    font: inherit;
    color: var(--ink);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
  .doc-title .print-value {
    display: block;
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--bordeaux);
  }
  .info-table .value .print-value { display: block; }
  .items-table .print-value {
    display: block;
    font-size: 11px;
    padding: 5px 8px;
  }
  .items-table .print-value.num { text-align: right; }
  .items-table .print-value.center { text-align: center; }
  /* le texte peut tenir sur plusieurs lignes : on aligne en haut */
  .items-table tbody td, .info-table td { vertical-align: top; }
  .items-table .cell-num, .items-table .cell-total { padding-top: 5px; }
  /* force le rendu des couleurs de fond */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .sign-box, .info-table, .items-table, .totals-table { break-inside: avoid; }
  .proforma-note { break-inside: avoid; }
}

/* ===== Responsive (mobile/tablette) ===== */
@media screen and (max-width: 820px) {
  .sheet {
    width: 100%;
    min-height: auto;
    margin: 0;
    padding: 16px;
    box-shadow: none;
  }
  body { font-size: 14px; }
  .info-grid,
  .bottom-grid,
  .sign-grid { grid-template-columns: 1fr; }
  .totals-table { margin-top: 8px; }
  .doc-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .brand-contact { text-align: left; }
  /* tableau articles défilable horizontalement */
  .items-table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ===== Page de connexion ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(140, 25, 45, .35), transparent 55%),
    linear-gradient(135deg, #16527f 0%, var(--blue) 45%, #0c2740 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
  padding: 38px 32px 26px;
  text-align: center;
  animation: login-rise .4s ease;
}
@keyframes login-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.login-logo-ring {
  width: 96px;
  height: 96px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--blue-soft);
  border: 3px solid var(--blue-border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.login-logo {
  width: 78px;
  height: 78px;
  object-fit: contain;
}
.login-title {
  margin: 0;
  font-size: 23px;
  color: var(--blue);
  letter-spacing: .3px;
}
.login-subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--grey);
}
.login-welcome {
  margin: 18px 0 22px;
  padding: 9px 12px;
  background: var(--blue-soft);
  border-radius: 9px;
  font-size: 12.5px;
  color: var(--blue);
}
.login-form { text-align: left; }
.login-field { display: block; margin-bottom: 15px; }
.login-field span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 5px;
}
.login-field input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 11px 12px;
  border: 1.5px solid var(--blue-border);
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-field input::placeholder { color: #9bb0c4; }
.login-field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(21, 69, 111, .15);
}
.login-pass-wrap { position: relative; }
.login-pass-wrap input { padding-right: 76px; }
.login-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.login-toggle:hover { background: var(--blue-soft); }
.login-error {
  margin: 0 0 12px;
  padding: 8px 10px;
  background: #fbe9ec;
  border-radius: 8px;
  font-size: 12px;
  color: var(--bordeaux);
  font-weight: 600;
}
.login-submit {
  width: 100%;
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  margin-top: 6px;
  border-radius: 9px;
  box-shadow: 0 6px 16px rgba(140, 25, 45, .3);
}
.login-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #eef1f4;
  font-size: 11px;
  color: var(--grey);
}

/* =====================================================================
   Archivage, comptes et états des documents (version 2 — base SQLite)
   ===================================================================== */

/* ===== Barre d'outils : partie gauche ===== */
.toolbar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar-actions .btn { text-decoration: none; display: inline-block; }
.user-chip {
  font-size: 12px;
  opacity: .85;
  padding: 0 4px;
  white-space: nowrap;
}
.user-chip::before { content: "👤 "; }

/* ===== Badges de statut ===== */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
}
.badge-brouillon { background: #fde9c8; color: #8a5a00; }
.badge-emis      { background: #d8f0dc; color: #1c6b34; }
.badge-annule    { background: #f6d9de; color: var(--bordeaux); }

/* ===== Indicateur d'enregistrement ===== */
.save-state { font-size: 11.5px; opacity: .9; }
.save-state.ok       { color: #b9f0c6; }
.save-state.en-cours { color: #ffe6b3; }
.save-state.erreur   { color: #ffc9d2; font-weight: 600; }

/* ===== Bandeau document verrouillé ===== */
.lock-banner {
  max-width: 800px;
  margin: 12px auto -8px;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--blue-soft);
  border-left: 4px solid var(--blue);
  font-size: 12.5px;
  color: var(--blue);
}
body.is-locked .lock-banner { border-left-color: var(--bordeaux); }

/* Document verrouillé : les champs deviennent du texte simple. */
body.is-locked .sheet input:disabled {
  background: transparent;
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
  opacity: 1;
  cursor: default;
}
body.is-locked .row-actions { visibility: hidden; }

.doc-numero { font-weight: 700; color: var(--blue); letter-spacing: .4px; }

/* ===== Filigrane des documents annulés ===== */
.sheet { position: relative; }
.watermark {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-24deg);
  font-size: 90px;
  font-weight: 800;
  letter-spacing: 8px;
  color: rgba(140, 25, 45, .13);
  pointer-events: none;
  user-select: none;
  z-index: 5;
}

/* ===== Journal du document ===== */
.journal-block {
  max-width: 800px;
  margin: 18px auto 40px;
  padding: 14px 18px;
  background: var(--paper);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.08);
}
.journal-block h2 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.journal-block ul { margin: 0; padding-left: 18px; font-size: 12px; color: var(--grey); }
.journal-block li { margin-bottom: 3px; }
.journal-block .j-date { color: var(--blue); font-variant-numeric: tabular-nums; }

/* ===== Pages liste (archives, comptes) ===== */
.page-liste { background: #eef1f5; }
.page-body { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

.bloc {
  background: var(--paper);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,.07);
}
.bloc h2 {
  margin: 0 0 14px;
  font-size: 15px;
  color: var(--blue);
  border-bottom: 2px solid var(--blue-soft);
  padding-bottom: 8px;
}
.bloc h3 { margin: 22px 0 10px; font-size: 13px; color: var(--bordeaux); }
.aide { font-size: 11.5px; color: var(--grey); margin: 10px 0 0; }

/* ===== Cartes de synthèse ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.card {
  background: var(--paper);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 2px 10px rgba(0,0,0,.07);
  border-left: 4px solid var(--blue);
}
.card-titre { font-size: 11.5px; color: var(--grey); text-transform: uppercase; letter-spacing: .4px; }
.card-valeur { font-size: 28px; font-weight: 700; color: var(--blue); line-height: 1.2; margin: 4px 0 2px; }
.card-detail { font-size: 12px; color: var(--bordeaux); font-variant-numeric: tabular-nums; }

/* ===== Filtres ===== */
.filtres {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filtres input, .filtres select {
  font: inherit;
  font-size: 13px;
  padding: 9px 11px;
  border: 1.5px solid var(--blue-border);
  border-radius: 9px;
  background: var(--paper);
  outline: none;
}
.filtres input[type="search"] { flex: 1 1 260px; }
.filtres input:focus, .filtres select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(21, 69, 111, .13);
}

/* ===== Tableau de liste ===== */
.table-wrap {
  background: var(--paper);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.07);
  overflow-x: auto;
}
.liste-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.liste-table th {
  background: var(--blue);
  color: #fff;
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  white-space: nowrap;
}
.liste-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #edf1f5;
  vertical-align: middle;
}
.liste-table tbody tr:hover { background: var(--blue-soft); }
.liste-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.liste-table .numero { font-weight: 700; color: var(--blue); white-space: nowrap; }
.liste-table .objet { font-size: 11px; color: var(--grey); }
.liste-table .col-actions { text-align: right; white-space: nowrap; }
.liste-table tr.ligne-annule td { opacity: .55; text-decoration: line-through; }
.liste-table tr.ligne-annule .badge { text-decoration: none; }
.liste-vide { padding: 26px; text-align: center; color: var(--grey); font-size: 13px; }
.liste-info { padding: 10px 12px; margin: 0; font-size: 11.5px; color: var(--grey); }

.btn-mini {
  font-size: 11.5px;
  padding: 5px 10px;
  margin-left: 6px;
  background: var(--blue-soft);
  color: var(--blue);
  border-color: var(--blue-border);
  text-decoration: none;
}
.btn-mini:hover { background: var(--blue-border); }
.btn-danger { background: #fbe9ec; color: var(--bordeaux); border-color: #f0ccd4; }
.btn-danger:hover { background: #f5d7dd; }

/* ===== Formulaires en ligne ===== */
.form-inline { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-inline label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--blue);
}
.form-inline input, .form-inline select {
  font: inherit;
  font-size: 13px;
  font-weight: 400;
  padding: 8px 10px;
  border: 1.5px solid var(--blue-border);
  border-radius: 8px;
  outline: none;
  min-width: 170px;
}
.form-inline input:focus, .form-inline select:focus { border-color: var(--blue); }

/* ===== Notification flottante ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: 90vw;
  padding: 12px 20px;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast-ok { background: #1c6b34; }
.toast-erreur { background: var(--bordeaux); }

/* ===== Impression : le filigrane reste, l'écran disparaît ===== */
@media print {
  .lock-banner, .journal-block, .toast { display: none !important; }
  .watermark { color: rgba(140, 25, 45, .16); }
}

/* ===== Responsive ===== */
@media screen and (max-width: 820px) {
  .toolbar-inner { flex-direction: column; align-items: stretch; }
  .toolbar-actions { justify-content: flex-start; }
  .form-inline { flex-direction: column; align-items: stretch; }
  .form-inline input, .form-inline select { min-width: 0; width: 100%; }
  .watermark { font-size: 54px; }
}
