:root {
  --ground: #F6F5F1;
  --surface: #FFFFFF;
  --ink: #14201B;
  --ink-2: #3B4641;
  --muted: #55615B;
  --line: #E2E4DF;
  --line-2: #EEF0EC;
  --dark: #12201B;
  --accent: #0F6B4F;
  --accent-ink: #0B5A41;
  --accent-soft: #E3F1EA;
  --warn: #8A3B08;
  --warn-soft: #FBE9DC;
  --warn-line: #E3B48F;
  --idle: #3D4450;
  --idle-soft: #ECEDEF;
  --info: #1D4ED8;
  --info-soft: #E5EDFD;
  --r: 12px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--accent-ink); }
a:hover { color: #073D2C; }
h1, h2 { margin: 0; letter-spacing: -0.015em; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 800; }
p { margin: 0; }
code { background: var(--line-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* En-tête */
.topbar { background: var(--dark); color: #E8EEEA; position: sticky; top: 0; z-index: 10; padding-top: env(safe-area-inset-top); }
.topbar-in { max-width: 1180px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: #FFFFFF; text-decoration: none; min-width: 0; }
.brand:hover { color: #FFFFFF; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #FFFFFF; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 16px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 17px; font-weight: 800; }
.brand-text small { font-size: 12px; color: #A9B8B0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout { margin: 0; }
.tabs { max-width: 1180px; margin: 0 auto; padding: 0 12px; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { color: #C9D5CE; text-decoration: none; padding: 12px 12px 13px; font-weight: 700; font-size: 14px; white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a:hover { color: #FFFFFF; }
.tabs a.on { color: #FFFFFF; border-bottom-color: #4FBF95; }
.actas { background: var(--info-soft); color: #1E3A8A; }
.actas { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 16px; padding: 8px 16px; font-size: 14px; }
.actas form { margin: 0; }

/* Mise en page */
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-head form { margin: 0; }
.eyebrow { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.eyebrow a { text-decoration: none; }
.eyebrow.light { color: #A9B8B0; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav h1 { min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 20px; align-items: start; }
.grid-2-in { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.narrow { max-width: 480px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card.empty { display: flex; flex-direction: column; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Chiffres */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.kpi-value.warn { color: var(--warn); }
.kpi-note { font-size: 13px; color: var(--muted); }
@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 18px; }
}
.bar { height: 8px; background: #ECEDEA; border-radius: 99px; overflow: hidden; }
.bar div { height: 8px; background: var(--accent); }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid #C9CEC8; background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 700; font-size: 14px; text-decoration: none; cursor: pointer;
  list-style: none; user-select: none;
}
.btn:hover { border-color: #9AA39E; color: var(--ink); }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid #4FBF95; outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #FFFFFF; }
.btn-warn { color: var(--warn); border-color: var(--warn-line); }
.btn-warn:hover { color: var(--warn); border-color: var(--warn); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--line-2); border-color: transparent; }
.btn-ghost-dark { background: transparent; border-color: rgba(255, 255, 255, 0.25); color: #FFFFFF; }
.btn-ghost-dark:hover { border-color: rgba(255, 255, 255, 0.6); color: #FFFFFF; }
.btn-small { min-height: 40px; padding: 8px 12px; font-size: 13px; }
.btn-icon { width: 40px; min-height: 40px; padding: 0; font-size: 22px; line-height: 1; }
.btn-block { width: 100%; }
summary.btn::-webkit-details-marker { display: none; }

/* Filtres */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; min-height: 40px; padding: 8px 14px; border-radius: 99px; border: 1px solid #D5D8D3; background: var(--surface); color: #2A3330; text-decoration: none; font-weight: 700; font-size: 13px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.chip:hover { border-color: var(--accent); }
.chip.on:hover { color: #FFFFFF; }

/* Listes */
.rows { list-style: none; margin: 0; padding: 0; }
.row { border-top: 1px solid var(--line-2); padding: 14px 0; display: flex; flex-direction: column; gap: 10px; }
.row:first-child { border-top: none; }
.rows.compact .row { padding: 10px 0; }
.row-main { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 8px 16px; align-items: center; }
.row-link { color: inherit; text-decoration: none; border-radius: 8px; }
.row-link:hover { color: inherit; background: #FAFAF8; }
.row-who, .row-money { display: flex; flex-direction: column; min-width: 0; }
.row-who strong, .row-money strong { font-size: 15px; }
.row-who .muted, .row-money .muted { font-size: 13px; }
.row-status { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; }
.row-actions form { margin: 0; }
.chev { font-size: 24px; color: #9AA39E; }
@media (max-width: 560px) {
  .row-main { grid-template-columns: minmax(0, 1fr) auto; }
  .row-money { grid-column: 1; grid-row: 2; }
  .row-status { grid-column: 2; grid-row: 1 / span 2; }
}

.pill { display: inline-block; padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.pill-paid { background: var(--accent-soft); color: var(--accent-ink); }
.pill-late { background: var(--warn-soft); color: var(--warn); }
.pill-due { background: var(--idle-soft); color: var(--idle); }
.pill-partial { background: var(--info-soft); color: #1E3A8A; }

details.pay, details.more { position: relative; }
details.pay[open] { flex-basis: 100%; order: 10; }
details.pay[open] > summary { display: none; }
.pay-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 12px; align-items: end; background: #FAFAF8; border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.more-menu { position: absolute; right: 0; top: 44px; z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 8px 24px rgba(18, 32, 27, 0.12); min-width: 200px; }

/* Formulaires */
.field { display: flex; flex-direction: column; gap: 6px; border: none; padding: 0; margin: 0; min-width: 0; }
.field label, .field > span, .field legend, .field summary { font-size: 13px; font-weight: 700; color: var(--ink-2); padding: 0; }
.field summary { cursor: pointer; }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #C9CEC8; border-radius: 10px;
  background: #FFFFFF; color: var(--ink); font: inherit; font-size: 16px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 500; }
.check input { width: 20px; height: 20px; margin-top: 1px; flex: none; accent-color: var(--accent); }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.checks .ok { color: var(--accent-ink); }
.checks .ko { color: var(--warn); font-weight: 700; }
.copy { display: flex; gap: 8px; }
.copy input { font-size: 13px; }

.flash { border-radius: 12px; padding: 12px 14px; font-weight: 600; font-size: 14px; }
.flash-ok { background: var(--accent-soft); color: var(--accent-ink); }
.flash-error { background: var(--warn-soft); color: var(--warn); }

/* Connexion */
.login-body { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; }
.login { width: 100%; max-width: 420px; padding: 48px 16px; display: flex; flex-direction: column; gap: 20px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.login-brand p { color: var(--muted); }
.login-card { display: flex; flex-direction: column; gap: 14px; }

/* Espace locataire */
.tenant-head { background: var(--dark); color: #FFFFFF; padding: calc(28px + env(safe-area-inset-top)) 16px 56px; }
.tenant-head-in { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 4px; }
.tenant-head p { color: #C9D5CE; }
.tenant { max-width: 560px; margin: -36px auto 0; padding: 0 16px 48px; display: flex; flex-direction: column; gap: 16px; }
.due-card { display: flex; flex-direction: column; gap: 8px; box-shadow: 0 8px 24px rgba(18, 32, 27, 0.08); }
.due-card.ok .big-amount { color: var(--accent-ink); }
.big-amount { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.due-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-top: 1px solid var(--line-2); padding-top: 8px; font-size: 14px; }
.pay-info { background: #FAFAF8; border: 1px solid var(--line); border-radius: 12px; padding: 14px; font-weight: 600; }

/* Documents */
.doc-body { background: #E9EAE6; }
.doc-tools { max-width: 800px; margin: 0 auto; padding: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.doc { max-width: 800px; margin: 0 auto 40px; background: #FFFFFF; padding: clamp(20px, 5vw, 48px); border-radius: 6px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08); display: flex; flex-direction: column; gap: 22px; font-size: 14px; }
.doc-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; border-bottom: 2px solid var(--ink); padding-bottom: 16px; }
.doc-head > div { display: flex; flex-direction: column; gap: 2px; }
.doc-agency { font-size: 18px; }
.doc-title { text-align: right; }
.doc-title h1 { font-size: 22px; text-transform: uppercase; letter-spacing: 0.04em; }
.doc-parties { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 14px; }
.doc-parties > div { display: flex; flex-direction: column; gap: 2px; }
.doc-label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th, .doc-table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.doc-table th { font-size: 12px; color: var(--muted); }
.doc-table .num { text-align: right; white-space: nowrap; }
.doc-table .total td { font-weight: 800; border-bottom: 2px solid var(--ink); }
.doc-box { background: #FAFAF8; border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.doc-text { font-size: 15px; line-height: 1.6; }
.doc-small { font-size: 12px; color: var(--muted); }
.doc-sign { text-align: right; font-weight: 700; }
.doc-foot { font-size: 11px; color: var(--muted); text-align: center; border-top: 1px solid var(--line); padding-top: 10px; }
@media (max-width: 560px) { .doc-title { text-align: left; } .doc-table { font-size: 13px; } }

@media print {
  @page { size: A4; margin: 14mm; }
  body, .doc-body { background: #FFFFFF; }
  .no-print { display: none !important; }
  .doc { box-shadow: none; margin: 0; padding: 0; max-width: none; }
}
