:root {
  --green: #0c3b2e;
  --green-soft: #145c45;
  --gold: #c6a15b;
  --gold-deep: #8c6a2f;
  --ink: #1c1915;
  --muted: #5e584e;
  --paper: #efe8dc;
  --sheet: #fffdf8;
  --line: #e4d9c6;
  --danger: #8f2d2d;
  --ok: #145c45;
  --shadow: 0 16px 40px rgba(28, 25, 21, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

a { color: var(--green); }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.side {
  background: var(--green);
  color: #f6f1e7;
  padding: 22px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
  padding: 0 8px;
  text-decoration: none;
  color: inherit;
}

.brand-mark, .brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--gold);
  color: var(--green);
  display: grid;
  place-items: center;
  font-family: Georgia, "Iowan Old Style", serif;
  font-weight: 700;
}
.brand-logo {
  object-fit: contain;
  background: white;
  display: block;
}

.brand small,
.nav-label,
.kicker {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
}

.brand strong { display: block; font-size: 14px; font-weight: 600; }
.brand em { display: block; font-style: normal; color: #d9c7a2; font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-label { color: #d9c7a2; padding: 0 12px 6px; }
.nav a {
  color: inherit;
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 10px;
}
.nav a:hover,
.nav a.on { background: rgba(198, 161, 91, 0.16); }
.nav a.on { box-shadow: inset 3px 0 0 var(--gold); }

.side-foot { margin-top: auto; padding: 8px 12px 0; color: #d9c7a2; font-size: 13px; }

.main { padding: 28px 32px 72px; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
}

.kicker { color: var(--gold-deep); margin: 0 0 4px; }
h1, h2, h3 { font-family: Georgia, "Iowan Old Style", serif; font-weight: 600; }
h1 { margin: 0; font-size: 34px; line-height: 1.1; }
h2 { margin: 0 0 12px; font-size: 22px; }

.top-actions, .inline-actions, .toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.pill, .badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: white;
}
.pill.warn { color: var(--danger); }
.badge-active { background: #e7f3ec; color: var(--ok); border-color: transparent; }
.badge-suspendue { background: #f8efd8; color: #7a5a12; border-color: transparent; }
.badge-annulee { background: #f8e8e8; color: var(--danger); border-color: transparent; }
.badge-muted { background: #f4efe4; color: var(--muted); border-color: transparent; }

.flash { margin: 0 0 14px; padding: 12px 14px; border-radius: 12px; }
.flash-ok { background: #e7f3ec; color: var(--ok); }
.flash-error { background: #f8e8e8; color: var(--danger); }

.stats, .split, .grid-2 { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(4, 1fr); margin-bottom: 14px; }
.split { grid-template-columns: 0.9fr 1.1fr; align-items: start; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.span-2 { grid-column: span 2; }

.card, .stat {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.card { padding: 18px 20px; }
.stat { padding: 16px 18px; }
.stat p, .stat span { margin: 0; color: var(--muted); }
.stat strong {
  display: block;
  margin: 6px 0 2px;
  font-family: Georgia, serif;
  font-size: 32px;
  font-weight: 600;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #f0e7d8; vertical-align: middle; }
th {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
td.num, .num { font-variant-numeric: tabular-nums; letter-spacing: 0.03em; }

.person {
  display: flex;
  gap: 10px;
  align-items: center;
  text-decoration: none;
  color: inherit;
}
.avatar, .thumb {
  object-fit: cover;
  background: #f4efe4;
  border: 1px solid var(--line);
}
.avatar { width: 74px; height: 92px; border-radius: 10px; }
.thumb, .initials {
  width: 36px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f4efe4;
  color: var(--green);
  font-family: Georgia, serif;
  border: 1px solid var(--line);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .search label { color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%;
  border: 1px solid #e0d5c3;
  background: white;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(198, 161, 91, 0.45);
  border-color: var(--gold);
}

.segment { display: flex; gap: 8px; }
.segment label {
  display: flex;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: white;
}

.help { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.empty { padding: 28px 8px; text-align: center; color: var(--muted); }
.filters { display: grid; grid-template-columns: 1.4fr repeat(3, 1fr) auto; gap: 10px; align-items: end; margin-bottom: 14px; }
.preview-box {
  background: #f4efe4;
  border-radius: 12px;
  padding: 12px 14px;
}
.preview-box strong { font-family: Georgia, serif; font-size: 20px; letter-spacing: 0.04em; }
.check { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.actions-tight { display: flex; gap: 8px; justify-content: flex-end; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--green);
  color: #fffdf8;
  text-decoration: none;
  border: 1px solid var(--green);
  font: inherit;
  cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--green); }
.btn.danger { background: transparent; color: var(--danger); border-color: #e7c7c7; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.licence-cell { display: inline-flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  color: var(--green);
  background: white;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { border-color: var(--gold); color: var(--green); }
.color-row { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px; }
.color-field { display: grid; gap: 6px; font-size: 14px; }
.color-field input[type="color"] {
  width: 72px;
  height: 40px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  cursor: pointer;
}
.stack { display: flex; flex-direction: column; gap: 14px; }
.identity-grid { display: grid; grid-template-columns: 90px 1fr; gap: 16px; align-items: center; }
.muted { color: var(--muted); }
dl.meta { display: grid; grid-template-columns: 160px 1fr; gap: 8px 12px; margin: 0; }
dl.meta dt { color: var(--muted); }

.desk {
  margin: 0;
  min-height: 100vh;
  background: #d9d2c4;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 40px;
}
.print-toolbar {
  width: 148mm;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}
.print-toolbar p { margin: 0; color: var(--muted); font-size: 13px; max-width: 78mm; }

.sheet {
  --green: var(--licence-vert, #0c3b2e);
  --gold: var(--licence-filet, #c6a15b);
  --gold-deep: color-mix(in srgb, var(--gold) 72%, #1c1915);
  width: 148mm;
  height: 210mm;
  background-color: var(--sheet);
  box-shadow: 0 18px 50px rgba(28, 25, 21, 0.18);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.sheet-has-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--fond) center / cover no-repeat;
  opacity: 0.42;
  pointer-events: none;
}
.sheet-has-bg .facts div,
.sheet-plain.sheet-has-bg .facts div {
  background: transparent;
  border: none;
}
.sheet-inner {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  margin: 4mm 6mm 5mm;
  border: 0.45mm solid var(--green);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet-has-bg .sheet-inner { border: none; }
.licence-banner,
.banner-meta,
.goldbar,
.sheet-head { position: relative; z-index: 1; }
.licence-banner {
  display: block;
  width: 100%;
  height: auto;
  background: transparent;
}
.banner-preview {
  display: block;
  width: 100%;
  max-width: 520px;
  height: auto;
  margin-top: 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.banner-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 2.2mm 4mm;
  background: var(--green);
  color: #f6f1e7;
  font-size: 9pt;
}
.banner-meta strong {
  color: var(--licence-numero, var(--gold));
  font-family: Georgia, serif;
  font-size: 12pt;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.licence-no {
  margin: 1.2mm 0 0;
  color: var(--licence-numero, var(--gold-deep));
  font-family: Georgia, serif;
  font-size: 13pt;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.sheet-plain .banner-meta {
  background: transparent;
  color: var(--green);
  border-bottom: 0.35mm solid var(--green);
}
.sheet-plain .banner-meta strong { color: var(--licence-numero, var(--green)); }
.sheet-head {
  display: grid;
  grid-template-columns: 18mm 1fr auto;
  gap: 4mm;
  align-items: center;
  background: var(--green);
  color: #f6f1e7;
  padding: 5mm 5mm 4mm;
}
.sigle {
  width: 16mm;
  height: 16mm;
  border-radius: 50%;
  background: var(--sheet);
  color: var(--green);
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-weight: 700;
  overflow: hidden;
}
.sigle img { width: 100%; height: 100%; object-fit: cover; }
.sheet-head .eyebrow { margin: 0; text-transform: uppercase; letter-spacing: 0.12em; font-size: 8pt; color: #e7d7b0; }
.sheet-head h1 { color: white; font-size: 16pt; margin: 1mm 0; }
.sheet-head .sub { margin: 0; font-size: 9pt; }
.head-num {
  margin: 0;
  color: var(--licence-numero, var(--gold));
  font-family: Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 11pt;
}
.goldbar { height: 1.7mm; background: var(--gold); }
.sheet-head.no-logo { grid-template-columns: 1fr auto; }
.sheet-plain .sheet-head {
  background: transparent;
  color: var(--green);
  border-bottom: 0.35mm solid var(--green);
}
.sheet-plain .sheet-head h1,
.sheet-plain .eyebrow { color: var(--green); }
.sheet-plain .head-num { color: var(--licence-numero, var(--green)); }
.sheet-plain .sub { color: var(--muted); }
.sheet-plain .sigle { box-shadow: inset 0 0 0 0.3mm var(--green); }
.sheet-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 4.5mm 4.5mm 3mm;
}
.identity-row {
  display: grid;
  grid-template-columns: 46mm 1fr;
  gap: 4.5mm;
  align-items: stretch;
}
.photo-col {
  height: 54mm;
  border-radius: 1.6mm;
  overflow: hidden;
  background: white;
  border: 0.25mm solid rgba(198, 161, 91, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-col img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}
.photo-col span {
  height: 100%;
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: 18pt;
  color: var(--green);
}
.sheet-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 3.2mm;
  padding-top: 1mm;
}
.sheet-copy h2 { margin: 0; font-size: 20pt; line-height: 1.08; }
.sheet-copy h2 span { font-weight: 500; }
.role {
  margin: 0;
  color: var(--gold-deep);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 9pt;
  font-weight: 700;
}
.org { margin: 0; color: var(--muted); font-size: 12pt; }
.beside-line { margin: 0; font-family: Georgia, serif; font-size: 11pt; }
.beside-line span {
  display: block;
  color: var(--gold-deep);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 7.5pt;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.facts {
  flex: 1;
  margin: 4mm 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 1fr;
  gap: 2.4mm;
  align-content: stretch;
}
.facts div {
  padding: 2.4mm 3mm;
  background: #f7f2e8;
  border-radius: 1.4mm;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.sheet-plain .facts div { background: transparent; border: 0.2mm solid #eadfcd; }
.facts dt {
  margin: 0;
  color: var(--gold-deep);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 7pt;
}
.facts dd { margin: 0.6mm 0 0; font-family: Georgia, serif; font-size: 11pt; }
.sheet-foot {
  margin-top: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 5mm;
}
.sign span, .mention { color: var(--muted); }
.sign { width: 62mm; }
.sign span { font-size: 8.5pt; }
.sign i { display: block; height: 5mm; border-bottom: 0.3mm solid var(--gold); }
.sign strong { display: block; margin-top: 1.5mm; font-size: 10pt; }
.signature-img, .signature-preview {
  display: block;
  height: 14mm;
  width: auto;
  max-width: 48mm;
  object-fit: contain;
}
.portrait {
  width: 42px;
  height: 54px;
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #f4efe4;
  color: var(--green);
  border: 1px solid var(--line);
  font-family: Georgia, serif;
}
.portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 18%;
  display: block;
}
.qr { width: 22mm; height: 22mm; }
.mention { margin: 3mm 6mm 4mm; text-align: center; font-size: 8pt; }
.fond-preview {
  display: block;
  width: 100%;
  max-width: 280px;
  height: 120px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-top: 8px;
}
.stamp {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform: rotate(-28deg);
  font-family: Georgia, serif;
  font-size: 28pt;
  letter-spacing: 0.18em;
  color: rgba(143, 45, 45, 0.28);
  pointer-events: none;
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; z-index: 3; gap: 10px; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav-label, .side-foot { display: none; }
  .nav a { white-space: nowrap; }
  .stats, .split, .grid-2, .filters { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: auto; }
  .main { padding: 18px 14px 48px; }
  h1 { font-size: 28px; }
}

@media (max-width: 640px) {
  .stats, .split, .grid-2, .filters, dl.meta, .identity-grid { grid-template-columns: 1fr; }
  .print-toolbar { width: min(148mm, 100%); }
}

.layout-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 14px;
}
.layout-board h3 { margin: 0 0 8px; font-size: 16px; }
.layout-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  min-height: 120px;
  border: 1px dashed #d9cbb4;
  border-radius: 12px;
  background: #faf7f1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.layout-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: grab;
}
.layout-list li strong { flex: 1; font-weight: 600; }
.drag { color: var(--gold-deep); }
.layout-moves { display: flex; gap: 4px; }
.layout-moves button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 4px 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.layout-list li.dragging { opacity: 0.45; }

.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 21, 0.46);
}
.modal-panel {
  position: relative;
  width: min(1040px, calc(100vw - 28px));
  height: calc(100vh - 28px);
  max-height: calc(100vh - 28px);
  display: flex;
  flex-direction: column;
  background: var(--sheet);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(28, 25, 21, 0.28);
}
.modal-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-bar h2 { margin: 0; font-size: 22px; }
.modal-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #d9d2c4;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
body.modal-open { overflow: hidden; }
.modal .sheet-stage {
  margin: 0 auto;
  overflow: hidden;
  flex: 0 0 auto;
}
.modal .sheet-fit {
  transform-origin: top left;
}
.modal .sheet { box-shadow: none; }

@media (max-width: 900px) {
  .layout-board { grid-template-columns: 1fr; }
  .modal-bar { flex-direction: column; align-items: stretch; }
}

@media print {
  body.desk, body.printing-modal { background: white; padding: 0; }
  .no-print { display: none !important; }
  .sheet { box-shadow: none; width: 148mm; height: 210mm; }
  body.printing-modal .shell,
  body.printing-modal .modal-backdrop { display: none !important; }
  body.printing-modal .modal {
    position: static;
    display: block;
    padding: 0;
    background: white;
  }
  body.printing-modal .modal-panel {
    max-height: none;
    width: auto;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }
  body.printing-modal .modal-body { overflow: visible; background: white; padding: 0; }
  body.printing-modal .sheet-stage,
  body.desk .sheet-stage {
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
  }
  body.printing-modal .sheet-fit,
  body.desk .sheet-fit {
    width: auto;
    height: auto;
    overflow: visible;
    margin: 0;
    transform: none !important;
  }
  body.printing-modal .sheet { transform: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A5 portrait; margin: 0; }
}
