:root {
  --accent: #3f9d7e;
  --accent-dark: #2f7d63;
  --bg: #f4f6f7;
  --card: #ffffff;
  --border: #e3e6e8;
  --text: #2b3440;
  --muted: #8a949e;
  --label: #6b7682;
  --danger: #d9534f;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.03);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

/* ---------- Header ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  background: var(--text); color: #fff; font-weight: 700; font-size: 12px;
  padding: 6px 9px; border-radius: 7px; letter-spacing: .5px;
}
.brand h1 { font-size: 19px; margin: 0; font-weight: 700; }
.topbar-actions { display: flex; gap: 10px; }

/* ---------- Layout ---------- */
.container { max-width: 820px; margin: 28px auto; padding: 0 20px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 22px;
}
.card-title {
  text-transform: uppercase;
  letter-spacing: .8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 18px;
  display: flex; align-items: center; justify-content: space-between;
}

/* ---------- Form ---------- */
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; margin-bottom: 14px; flex: 1; min-width: 140px; }
label { font-size: 12px; color: var(--label); margin-bottom: 5px; font-weight: 600; }
input, select, textarea {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63,157,126,.12);
}
input::placeholder { color: #b7bfc7; }
.checkbox-row { display: flex; align-items: center; gap: 9px; margin-top: 6px; }
.checkbox-row input { width: 16px; height: 16px; }
.checkbox-row label { margin: 0; font-weight: 500; color: var(--text); }

/* info box emetteur */
.info-box {
  background: #eef6f2;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 13px 15px;
  font-size: 13px;
  color: #3d4a44;
}
.info-box b { color: var(--text); }
.info-box .muted { color: var(--muted); }

/* ---------- Buttons ---------- */
button, .btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--border);
  background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: 8px; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
button:hover { background: #f7f8f9; }
.btn-primary, button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover, button.primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--danger); border-color: #ecc; }
.btn-danger:hover { background: #fbecec; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; padding: 15px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-link { background: none; border: none; color: var(--accent); padding: 4px; cursor: pointer; font-weight: 600; }

/* ---------- Lines table ---------- */
.lines-head, .line {
  display: grid;
  grid-template-columns: 1fr 56px 96px 76px 110px 28px;
  gap: 8px; align-items: center;
}
.line .l-vat { padding: 9px 6px; }
.totals-box { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.totals-box .trow { display: flex; gap: 18px; min-width: 260px; justify-content: space-between; font-size: 14px; }
.totals-box .trow .lbl { color: var(--label); }
.totals-box .trow.ttc { font-size: 20px; font-weight: 700; margin-top: 6px; padding-top: 8px;
  border-top: 1px solid var(--border); min-width: 260px; }
.totals-box .trow.ttc .val { color: var(--accent); }
.lines-head { font-size: 12px; color: var(--label); font-weight: 600; margin-bottom: 8px; }
.line { margin-bottom: 10px; }
.line .line-total {
  background: #f1f3f4; border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; text-align: right; color: var(--muted);
}
.line .remove { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0; }
.line .remove:hover { color: var(--danger); background: none; }
.add-line {
  width: 100%; text-align: left; color: var(--label);
  border: 1px dashed var(--border); background: #fafbfb; margin-top: 4px;
}
.add-line:hover { border-color: var(--accent); color: var(--accent); }
.total-row { text-align: right; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.total-row .total-amount { font-size: 22px; font-weight: 700; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,28,36,.45);
  display: none; align-items: flex-start; justify-content: center; z-index: 50;
  overflow-y: auto; padding: 40px 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); width: 100%; max-width: 640px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2); padding: 24px;
}
.modal h2 { margin: 0 0 18px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item .meta { color: var(--muted); font-size: 12px; }
.list-item .acts { display: flex; gap: 8px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 34px; width: 100%; max-width: 380px; }
.auth-card .brand { justify-content: center; margin-bottom: 22px; }
.auth-card h2 { text-align: center; margin: 0 0 18px; font-size: 18px; }
.auth-switch { text-align: center; margin-top: 16px; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 12px 20px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 100;
}
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }
.empty { color: var(--muted); text-align: center; padding: 20px; font-style: italic; }

/* ---------- Badges / tags rôle ---------- */
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; line-height: 1;
  padding: 4px 9px; border-radius: 999px; letter-spacing: .3px; text-transform: uppercase;
  vertical-align: middle;
}
.badge-superadmin { background: #e9d5ff; color: #6b21a8; }
.badge-admin { background: #d6e4f0; color: #1f4e79; }
.badge-off { background: #f1d4d4; color: #b3261e; }
.badge-warn { background: #fbe8c8; color: #92500a; }
.badge-neutral { background: #e7eaec; color: #51606e; }

/* ---------- Journal / logs ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin-bottom: 0; }
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th { text-align: left; color: var(--label); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; border-bottom: 2px solid var(--border); }
.log-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.log-table tr:hover td { background: #f7f8f9; }
.log-when { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.log-actor { font-weight: 600; }
.log-ip { color: var(--muted); font-size: 11px; }
.modal.wide { max-width: 860px; }
.log-action {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px;
  background: #eef2f4; color: #455563;
}
.log-action.create { background: #d9efe4; color: #1f7a52; }
.log-action.update { background: #dbe7f5; color: #1f4e79; }
.log-action.delete { background: #f6dada; color: #b3261e; }
.log-action.auth { background: #efe6fa; color: #6b21a8; }
