/* ===== HappyFacture — thème corporate ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #16202e;
  --muted: #5f6b7a;
  --line: #e0e5ec;
  --accent: #2b5ca8;
  --accent-ink: #244d8c;
  --accent-soft: #e9eff8;
  --blue: #2b5ca8;
  --blue-soft: #e9eff8;
  --green: #1d7a4f;
  --green-soft: #e7f3ec;
  --amber: #a3630b;
  --amber-soft: #faf1e2;
  --red: #b3261e;
  --red-soft: #fbeae9;
  --sidebar: #101826;
  --sidebar-ink: #b9c2d0;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(13, 22, 38, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --card: #171e29;
    --ink: #e5eaf1;
    --muted: #94a0af;
    --line: #27303e;
    --accent: #6ea3e0;
    --accent-ink: #8ab4e8;
    --accent-soft: #1c2941;
    --blue: #6ea3e0;
    --blue-soft: #1c2941;
    --green: #52b788;
    --green-soft: #14281e;
    --amber: #d9a441;
    --amber-soft: #2b2210;
    --red: #e5736c;
    --red-soft: #331715;
    --sidebar: #0a0f18;
    --sidebar-ink: #9aa5b5;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg.icn { display: inline-block; vertical-align: -3px; flex-shrink: 0; }

#app { display: flex; min-height: 100vh; }

/* ----- Sidebar ----- */
.sidebar {
  width: 232px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.logo { font-size: 17px; color: #fff; padding: 2px 8px 18px; display: flex; align-items: center; gap: 10px; font-weight: 500; letter-spacing: -0.01em; }
.logo b { color: #7fa8dd; font-weight: 700; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin-top: 14px; }
.sidebar nav a {
  color: var(--sidebar-ink);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 13.5px;
  font-weight: 500;
}
.sidebar nav a .ico { display: inline-flex; opacity: 0.75; }
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar nav a.active .ico { opacity: 1; }
.sidebar-footer { margin-top: auto; font-size: 11.5px; color: #66707f; padding: 10px; }

/* ----- Recherche globale ----- */
.search-wrap { position: relative; padding: 0 2px; }
.search-wrap input {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 13px;
}
.search-wrap input::placeholder { color: #6f7a8a; }
#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow);
  z-index: 80;
  overflow: hidden;
}
#search-results:empty { display: none; }
.search-hit {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  background: none;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}
.search-hit .icn { color: var(--muted); }
.search-hit:hover, .search-hit:focus { background: var(--accent-soft); }
.search-hit .sub { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ----- Main ----- */
main { flex: 1; padding: 26px 32px; max-width: 1100px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; letter-spacing: -0.01em; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

/* ----- Cards / tables ----- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; overflow-x: auto; }
.card h3 { font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { font-size: 21px; font-weight: 700; margin-top: 6px; letter-spacing: -0.01em; }
.stat .value.accent { color: var(--accent); }
.stat .value.green { color: var(--green); }
.stat .value.amber { color: var(--amber); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 600; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 13.5px; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--accent-soft); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ----- Barre d'encaissement ----- */
.progress { height: 3px; background: var(--line); border-radius: 99px; margin-top: 5px; min-width: 60px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width 0.4s ease; }

/* ----- Badges ----- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 5px; font-size: 11.5px; font-weight: 600; white-space: nowrap; letter-spacing: 0.02em; }
.badge.brouillon { background: var(--line); color: var(--muted); }
.badge.envoyee { background: var(--blue-soft); color: var(--blue); }
.badge.payee, .badge.acceptee { background: var(--green-soft); color: var(--green); }
.badge.partielle { background: var(--amber-soft); color: var(--amber); }
.badge.refusee { background: var(--red-soft); color: var(--red); }
.badge.retard { background: var(--red-soft); color: var(--red); }

/* ----- Buttons ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  min-height: 37px;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 12.5px; min-height: 29px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ----- Forms ----- */
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field-error { border-color: var(--red) !important; outline: 2px solid var(--red-soft) !important; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
.checkbox-field { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 13.5px; }
.checkbox-field input { width: auto; }

/* ----- Logo entreprise ----- */
.logo-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-thumb { max-height: 52px; max-width: 160px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }

/* ----- Bandeau profil ----- */
.profile-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--accent);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.profile-banner .icn { color: var(--accent); }
.profile-banner .grow { flex: 1; min-width: 200px; }
.profile-banner b { display: block; margin-bottom: 2px; font-size: 14px; }
.profile-banner .small { color: var(--muted); }
.profile-progress { height: 5px; background: var(--line); border-radius: 99px; margin-top: 8px; overflow: hidden; max-width: 260px; }
.profile-progress i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* ----- Doc editor lines ----- */
.lines-table input, .lines-table select { padding: 6px 8px; font-size: 13px; }
.lines-table td { padding: 5px 5px; }
.totals-box { margin-left: auto; width: 300px; margin-top: 14px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 4px; font-size: 13.5px; }
.totals-box .row.total { border-top: 2px solid var(--ink); font-weight: 700; font-size: 16px; margin-top: 4px; }

.empty { text-align: center; color: var(--muted); padding: 42px 20px; }
.empty .big { margin-bottom: 12px; color: var(--muted); opacity: 0.6; }
.empty b { color: var(--ink); font-size: 15px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt { margin-top: 14px; }

/* ----- Bouton flottant « nouvelle facture » (mobile) ----- */
.fab-create {
  display: none;
  position: fixed;
  right: 18px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 65;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  font-weight: 400;
  line-height: 1;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 6px 20px rgba(13, 22, 38, 0.35);
  transition: transform 0.15s;
}
.fab-create:active { transform: scale(0.94); }

/* ----- Liste « À faire aujourd'hui » ----- */
.todo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.todo-row:last-child { border-bottom: none; }
.todo-row > span { flex: 1; }
.todo-row .icn { color: var(--amber); flex-shrink: 0; }

/* ----- Toasts ----- */
#toasts {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #101826;
  color: #fff;
  padding: 11px 18px;
  border-radius: 9px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
  max-width: 92vw;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); border-color: var(--red); }
.toast button {
  background: none;
  border: none;
  color: #8ab4e8;
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 2px;
  width: auto;
}
.toast.error button { color: #fff; text-decoration: underline; }

/* ----- Modal ----- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 20, 0.55);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  animation: slideUp 0.2s ease;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { font-size: 16px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } }

/* ----- Aperçu avant impression ----- */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 22, 0.88);
  z-index: 150;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.15s ease;
}
.preview-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--sidebar);
  color: #fff;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.preview-title { font-weight: 600; font-size: 14px; }
.preview-warn {
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.preview-scroll { flex: 1; overflow-y: auto; padding: 26px 16px; }
.preview-sheet {
  background: #fff;
  max-width: 780px;
  margin: 0 auto;
  border-radius: 4px;
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.45);
  padding: 30px 36px;
  animation: slideUp 0.2s ease;
}

/* ----- Confetti (formes sobres) ----- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden; }
.confetti span {
  position: absolute;
  top: -30px;
  width: 8px;
  height: 13px;
  border-radius: 2px;
  animation: fall 1.9s ease-in forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(340deg); opacity: 0.5; }
}

/* ===== Document imprimé — modèle premium ===== */
#print-area { display: none; }

@media print {
  #app, #toasts, #modal-root { display: none !important; }
  body { background: #fff; }
  #print-area { display: block; }
}

.print-doc { font-size: 12.5px; color: #1a2330; max-width: 720px; margin: 0 auto; padding: 10px 4px; line-height: 1.5; }
.print-doc .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 18px; border-bottom: 2.5px solid #1f3a5f; margin-bottom: 26px; }
.print-doc .brand-block { display: flex; align-items: flex-start; gap: 14px; }
.print-doc .brand-logo { max-height: 62px; max-width: 190px; object-fit: contain; }
.print-doc .brand { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.print-doc .brand-details { color: #55606e; margin-top: 6px; line-height: 1.55; font-size: 11.5px; }
.print-doc .doc-type { font-size: 11px; text-transform: uppercase; letter-spacing: 0.18em; color: #55606e; text-align: right; }
.print-doc .doc-number { font-size: 21px; font-weight: 700; text-align: right; margin-top: 2px; color: #1f3a5f; }
.print-doc .doc-meta { text-align: right; color: #55606e; margin-top: 8px; line-height: 1.65; font-size: 11.5px; }
.print-doc .parties { display: flex; justify-content: space-between; gap: 30px; margin-bottom: 26px; }
.print-doc .party h4 { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: #8a93a0; margin-bottom: 6px; font-weight: 700; }
.print-doc .party { line-height: 1.6; }
.print-doc table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.print-doc th {
  color: #1f3a5f;
  padding: 7px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  border-top: 1.5px solid #1f3a5f;
  border-bottom: 1px solid #1f3a5f;
  background: none;
  font-weight: 700;
}
.print-doc td { padding: 8px; border-bottom: 1px solid #e6e9ee; font-size: 12px; }
.print-doc .totals { margin-left: auto; width: 300px; margin-top: 14px; }
.print-doc .totals .row { display: flex; justify-content: space-between; padding: 4px 10px; font-variant-numeric: tabular-nums; }
.print-doc .totals .row.total { border-top: 1.5px solid #1a2330; font-weight: 700; font-size: 13.5px; margin-top: 3px; padding-top: 7px; }
.print-doc .totals .row.grand {
  background: #1f3a5f;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 9px 12px;
  border-radius: 4px;
  margin-top: 8px;
  border: none;
}
.print-doc .print-notes { margin-top: 20px; color: #48525f; font-size: 11.5px; }
.print-doc .sign-box {
  margin-top: 26px;
  border: 1px solid #cfd5dd;
  border-radius: 5px;
  padding: 12px 14px 58px;
  width: 300px;
  margin-left: auto;
  font-size: 11px;
  color: #55606e;
}
.print-doc .sign-box b { color: #1a2330; display: block; margin-bottom: 3px; font-size: 11.5px; }
.print-doc .print-footer { margin-top: 38px; padding-top: 12px; border-top: 1px solid #dfe3e9; font-size: 9.8px; color: #8a93a0; line-height: 1.6; text-align: center; }

/* ----- Responsive : barre d'onglets en bas sur mobile ----- */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 60;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
  }
  .logo { padding: 0; font-size: 16px; flex-shrink: 0; }
  .search-wrap { flex: 1; }
  .sidebar nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 70;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0;
    margin: 0;
    background: var(--sidebar);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .sidebar nav a {
    flex-direction: column;
    gap: 3px;
    padding: 6px 2px;
    font-size: 9.5px;
    text-align: center;
    min-height: 44px;
    justify-content: center;
  }
  .sidebar-footer { display: none; }
  main { padding: 16px 14px 96px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .totals-box { width: 100%; }
  #toasts { bottom: calc(78px + env(safe-area-inset-bottom)); }
  .preview-sheet { padding: 18px 16px; }
  .fab-create { display: flex; }
}
