/* Charte MT Prestige : bleu nuit, rouge, bleu roi, blanc. Police système (aucune ressource externe). */
:root {
  --navy: #0A2A66; --blue: #1F57C3; --red: #E3202B; --green: #1E8E5A; --amber: #B7791F;
  --bg: #F4F6FB; --card: #fff; --line: #DCE2EE; --text: #1B2433; --muted: #5E6B80;
  --radius: 10px; --shadow: 0 1px 3px rgba(10, 42, 102, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.45; background: var(--bg); }
a { color: var(--blue); }
h1 { font-size: 1.45rem; margin: 0; color: var(--navy); }
h2 { font-size: 1.15rem; color: var(--navy); }
h3 { font-size: 1rem; color: var(--navy); margin: 1rem 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-family: ui-monospace, Consolas, monospace; }
.danger { color: var(--red); } .ok { color: var(--green); } .pre { white-space: pre-line; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

/* Structure */
.shell { display: grid; grid-template-columns: 240px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: #fff; border-bottom: 3px solid; border-image: linear-gradient(90deg, var(--navy) 0 45%, var(--red) 45% 55%, var(--blue) 55%) 1; position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand img { height: 40px; display: block; }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; }
.sidenav { background: var(--navy); padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.sidenav a { color: #DCE6FA; text-decoration: none; padding: 10px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.sidenav a .ic { width: 20px; text-align: center; opacity: .85; }
.sidenav a:hover { background: rgba(255,255,255,.08); }
.sidenav a.active { background: #fff; color: var(--navy); font-weight: 600; box-shadow: inset 4px 0 0 var(--red); }
.content { padding: 20px; max-width: 1280px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-title { margin: 22px 0 10px; }

/* Synchronisation */
.syncbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pill { font-size: .8rem; padding: 3px 10px; border-radius: 999px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.pill-ok { background: #E3F5EC; color: var(--green); } .pill-warn { background: #FFF3DC; color: #8A5A00; }
.pill-info { background: #E6EEFC; color: var(--blue); } .pill-danger { background: #FDE6E7; color: var(--red); }

/* Composants */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--navy); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { border-color: var(--blue); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-primary:hover { background: var(--blue); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-ghost { background: transparent; color: var(--red); border-color: transparent; }
.btn-small { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn-block { width: 100%; margin-top: 8px; }
.icon-btn { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: var(--muted); padding: 6px; min-width: 36px; min-height: 36px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
.actions.left { justify-content: flex-start; margin: 0 0 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .row-between { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: #E3F5EC; color: var(--green); } .badge-info { background: #E6EEFC; color: var(--blue); }
.badge-warn { background: #FFF3DC; color: #8A5A00; } .badge-danger { background: #FDE6E7; color: var(--red); }
.badge-neutral { background: #EEF1F6; color: var(--muted); } .badge-pending { background: #FFF3DC; color: #8A5A00; }
.chip { display: inline-block; background: #EEF1F6; border-radius: 6px; padding: 2px 8px; margin: 0 6px 6px 0; font-size: .85rem; }
.alert { padding: 10px 14px; border-radius: 8px; margin: 10px 0; border-left: 4px solid; }
.alert-info { background: #E6EEFC; border-color: var(--blue); } .alert-warn { background: #FFF6E5; border-color: #E0A21B; }
.alert-danger { background: #FDECEC; border-color: var(--red); color: #8B1218; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-icon { font-size: 2rem; color: var(--line); } .empty h3 { color: var(--navy); }
.loading { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 60px 20px; color: var(--muted); }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--navy); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.kpi { background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--navy); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi > span { color: var(--muted); font-size: .85rem; } .kpi strong { font-size: 1.35rem; color: var(--navy); } .kpi small { color: var(--muted); font-size: .78rem; }
.kpi-blue { border-top-color: var(--blue); } .kpi-green { border-top-color: var(--green); } .kpi-red { border-top-color: var(--red); } .kpi-amber { border-top-color: #E0A21B; }
.mini { background: #F7F9FD; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; }
.mini > span { color: var(--muted); font-size: .8rem; }

/* Formulaires */
.form { display: flex; flex-direction: column; gap: 10px; } .narrow { max-width: 680px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-weight: 600; font-size: .9rem; color: var(--navy); } .req { color: var(--red); }
.field-hint { font-size: .8rem; color: var(--muted); } .field-error { font-size: .85rem; color: var(--red); }
input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid #C3CDE0; border-radius: 8px; background: #fff; color: var(--text); min-height: 40px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
input:disabled, select:disabled { background: #F1F3F8; color: var(--muted); }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .9rem; } .check input { width: auto; min-height: auto; margin-top: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0; }
.align-start { align-items: start; }
.fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; } legend { font-weight: 600; color: var(--navy); padding: 0 6px; }
.alloc-row { display: grid; grid-template-columns: 1fr 1fr 40px; gap: 8px; margin-bottom: 6px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: 3px; }
.filters label.check { flex-direction: row; align-items: center; }
.filters input, .filters select { width: auto; min-width: 150px; }
.search { min-width: 240px; }
.upload input { display: none; }
.upload.disabled { opacity: .5; pointer-events: none; } .file-picker { margin-top: 6px; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 9px 14px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tab.active { color: var(--navy); border-bottom-color: var(--red); }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.info-grid div { display: flex; flex-direction: column; }
.list { list-style: none; padding: 0; margin: 0; } .list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.secret { background: #F7F9FD; border: 1px dashed var(--blue); padding: 12px; border-radius: 8px; font-size: 1.05rem; }

/* Tableaux */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: #F2F5FB; color: var(--navy); font-size: .82rem; text-transform: uppercase; letter-spacing: .02em; }
.table tfoot th { background: #E8EEF9; text-transform: none; font-size: .9rem; }
.table .num { text-align: right; }
.table-compact th, .table-compact td { padding: 6px 8px; font-size: .88rem; }
tr.cancelled td { color: var(--muted); text-decoration: line-through; } tr.cancelled td .badge, tr.cancelled td .btn { text-decoration: none; }
tr.muted td { opacity: .6; }

/* Contrats */
.contract { border-left: 4px solid var(--line); } .contract-active { border-left-color: var(--blue); }
.contract-head { display: flex; justify-content: space-between; gap: 10px; cursor: pointer; flex-wrap: wrap; }
.contract-head .right { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-start; }
.contract-body { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }

/* Fenêtres et notifications */
.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; } .modal-body { padding: 16px 18px; }
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); border-left: 5px solid var(--green); }
.toast-warn { border-left-color: #E0A21B; } .toast-danger { border-left-color: var(--red); }

/* Connexion */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #fff 0 55%, #E6EEFC 55%); }
.login { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 10px; border-top: 5px solid var(--red); }
.login-logo { max-width: 260px; margin: 6px auto 0; display: block; } .login h1 { text-align: center; }
.relogin input { max-width: 240px; }

/* Reçus */
.receipt { background: #fff; max-width: 720px; margin: 0 auto; padding: 28px 32px; border: 1px solid var(--line); border-radius: 6px; position: relative; }
.rc-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.rc-logo { height: 70px; } .rc-title { text-align: right; } .rc-title h1 { font-size: 1.15rem; }
.rc-no { font-size: 1.05rem; margin-top: 4px; } .rc-prov { font-size: .75rem; color: var(--red); }
.rc-band { display: grid; grid-template-columns: 45fr 10fr 45fr; height: 5px; margin: 12px 0 6px; }
.rc-band span:nth-child(1) { background: var(--navy); } .rc-band span:nth-child(2) { background: var(--red); } .rc-band span:nth-child(3) { background: var(--blue); }
.rc-res { color: var(--muted); font-size: .85rem; margin: 0 0 14px; }
.rc-table { width: 100%; border-collapse: collapse; } .rc-table th, .rc-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rc-table th { width: 34%; color: var(--navy); font-weight: 600; background: #F7F9FD; }
.rc-amount .money { font-size: 1.3rem; font-weight: 700; color: var(--navy); }
.rc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 26px; }
.rc-sign div { border-top: 1px solid #999; padding-top: 6px; height: 70px; font-size: .85rem; color: var(--muted); }
.rc-foot { font-size: .8rem; color: var(--muted); margin-top: 14px; }
.rc-contact { text-align: center; font-size: .85rem; border-top: 1px solid var(--line); padding-top: 8px; color: var(--navy); }
.rc-contact strong { color: var(--red); }
.rc-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-12deg); border: 4px solid var(--red); color: var(--red); font-size: 1.6rem; font-weight: 800; padding: 6px 18px; opacity: .8; background: rgba(255,255,255,.85); text-align: center; max-width: 80%; }
.rc-actions { max-width: 720px; margin: 0 auto 12px; justify-content: space-between; }
.print-head { display: none; }

/* Trésorerie, personnel, contrat électronique */
.kpi-link { text-decoration: none; color: inherit; } .kpi-link:hover { border-color: var(--blue); }
.bills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.bill { display: flex; align-items: center; gap: 6px; font-size: .85rem; } .bill span { white-space: nowrap; min-width: 70px; } .bill input { min-width: 0; }
.staff-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.staff-card .big { font-size: 1.1rem; color: var(--navy); }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0; font-size: .9rem; } .dl dt { color: var(--muted); } .dl dd { margin: 0; }
.esign { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.contract-doc { max-width: 820px; line-height: 1.55; } .contract-doc p { text-align: justify; margin: 6px 0; }
.contract-doc h3 { margin-top: 16px; } .article h4 { margin: 14px 0 4px; color: var(--navy); font-size: .95rem; } .art-n { color: var(--red); }
.sig-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 24px; break-inside: avoid; }
.sig-box { border: 1px solid var(--line); border-radius: 8px; padding: 12px; min-height: 150px; display: flex; flex-direction: column; gap: 6px; }
.sig-role { font-weight: 700; color: var(--navy); } .sig-img { max-height: 90px; max-width: 100%; object-fit: contain; align-self: flex-start; }
.sig-meta { font-size: .8rem; color: var(--muted); } .sig-empty { color: var(--muted); font-style: italic; flex: 1; }
.sig-hash { font-size: .72rem; color: var(--muted); word-break: break-all; margin-top: 14px; }
.sig-pad { width: 100%; height: 190px; border: 2px dashed var(--blue); border-radius: 8px; background: #fff; touch-action: none; display: block; margin: 6px 0; cursor: crosshair; }
.signed-text { white-space: pre-wrap; font-size: .8rem; max-height: 50vh; overflow: auto; background: #F7F9FD; padding: 10px; border-radius: 8px; }
.doc-status { max-width: 820px; margin: 0 auto 10px; }

/* Mobile */
@media screen and (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .sidenav { display: none; position: fixed; top: 64px; left: 0; right: 0; z-index: 30; max-height: calc(100vh - 64px); overflow-y: auto; }
  .sidenav.open { display: flex; }
  .user .muted { display: none; }
  .content { padding: 12px; }
  .grid2, .grid3, .sig-grid { grid-template-columns: 1fr; }
  .bills { grid-template-columns: 1fr 1fr; }
  .search, .filters input, .filters select { min-width: 0; width: 100%; } .filters label { flex: 1 1 140px; }
  .brand img { height: 32px; }
  /* Tableaux transformés en fiches */
  .table-wrap { border: 0; background: transparent; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td, .table tfoot, .table tfoot tr, .table tfoot th { display: block; width: 100%; }
  .table tr { background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; padding: 6px 10px; }
  .table td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 10px; text-align: right; }
  .table td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: .82rem; text-align: left; }
  .table td.num { text-align: right; }
  .receipt { padding: 16px; } .rc-head { flex-direction: column; align-items: flex-start; } .rc-title { text-align: left; }
}

/* Impression (reçus et rapports) */
@media print {
  @page { size: A4; margin: 12mm; }
  body, :root { background: #fff; }
  .no-print, .topbar, .sidenav, .filters, .tabs, .toasts, .alert-warn, .page-head .actions { display: none !important; }
  .shell { display: block; } .content { padding: 0; max-width: none; }
  .receipt { border: 0; padding: 0; max-width: none; }
  .print-head { display: flex; gap: 16px; align-items: center; border-bottom: 3px solid var(--navy); margin-bottom: 12px; padding-bottom: 8px; }
  .print-head img { height: 50px; } .print-head h2, .print-head p { margin: 0; }
  .table-wrap { border: 0; } .table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rc-band, .rc-table th, .kpi { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .card { box-shadow: none; break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

/* Éditeur de texte de contrat */
.doc-editor textarea { width: 100%; font: inherit; line-height: 1.45; }
.doc-editor .field { display: block; margin-bottom: 12px; }
.de-row { display: flex; gap: 6px; align-items: flex-start; margin-bottom: 6px; }
.de-row textarea { flex: 1; }
.de-art { padding: 12px; }
.de-art-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.de-art-head .art-n { font-weight: 700; color: var(--blue); white-space: nowrap; }
.de-art-title { flex: 1; min-width: 160px; font-weight: 600; }
.de-tools { display: flex; gap: 4px; }
.de-add { margin-top: 8px; }
.de-actions { position: sticky; bottom: 0; background: var(--bg, #fff); padding: 10px 0; border-top: 1px solid var(--line); z-index: 2; }
.ph-help { padding: 10px; }
.ph-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 12px; margin-top: 6px; }
.ph-list code { background: #EEF1F6; padding: 1px 4px; border-radius: 4px; font-size: 12px; }
.tpl-part { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.modal .de-actions { background: #fff; }

/* Signature par défaut et cachet « mention authentique » */
.sig-visual { position: relative; min-height: 96px; display: flex; align-items: center; }
.stamp { width: 118px; height: 118px; transform: rotate(-9deg); opacity: .88; flex: none; }
.sig-visual .stamp { position: absolute; right: 4px; top: -14px; }
.sig-visual .stamp-img { width: auto; height: 110px; max-width: 140px; object-fit: contain; }
.stamp-preview { display: flex; justify-content: center; padding: 10px 0; }
.stamp-preview .stamp { width: 170px; height: 170px; }
.stamp-preview .stamp-img { height: 160px; width: auto; }
.sig-preview { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; border: 1px dashed var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: #fff; }
.span2 { grid-column: 1 / -1; }

/* Affichage adaptatif : l'application occupe toute la largeur de l'écran (ordinateur, tablette, téléphone)
   et la taille du texte suit la taille de l'écran. */
html { font-size: clamp(15px, 0.35vw + 11px, 19px); }
body { font-size: .95rem; }
.content { max-width: none; padding: clamp(12px, 1.6vw, 32px); min-width: 0; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(clamp(165px, 13vw, 260px), 1fr)); gap: clamp(10px, 1vw, 18px); }
.staff-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, clamp(280px, 22vw, 420px)), 1fr)); }
.brand img { height: clamp(32px, 2.6vw, 48px); }
@media screen and (min-width: 861px) {
  .shell { grid-template-columns: clamp(200px, 14vw, 280px) minmax(0, 1fr); }
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.nowrap { white-space: nowrap; }
.unit-photo { width: 100%; max-width: 320px; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 10px; border: 1px solid var(--line, #DCE2EE); }

/* Contrat : vue de la résidence en arrière-plan (bandeau estompé à l'écran, filigrane sur chaque page imprimée). */
.contract-doc { position: relative; isolation: isolate; }
.contract-doc > .contract-bg { position: absolute; top: 0; left: 0; width: 100%; height: auto; z-index: -1; pointer-events: none; user-select: none;
  -webkit-mask-image: linear-gradient(#000 45%, transparent 100%); mask-image: linear-gradient(#000 45%, transparent 100%); }
@media print {
  .contract-doc > .contract-bg { position: fixed; top: 50%; left: 0; width: 100%; transform: translateY(-50%); -webkit-mask-image: none; mask-image: none; }
}
