/* ============================================================
   GESTLOC — Interface principale
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-width: 230px;
  --topbar-height: 52px;
  --color-sidebar-bg: #12172E;
  --sidebar-bg: #12172E;
  --color-sidebar-text: rgba(255,255,255,0.6);
  --color-sidebar-active: rgba(255,255,255,0.1);
  --color-sidebar-accent: #7F77DD;
  --color-purple: #7F77DD;
  --color-teal: #1D9E75;
  --color-amber: #EF9F27;
  --color-red: #E24B4A;
  --color-coral: #D85A30;
  --accent: #7F77DD;
  --accent-light: #EEEDFE;
  --border: 0.5px solid #f0f0ec;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 20px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  font-size: 14px;
  background: #f5f5f0;
  color: #1a1a1a;
  height: 100vh;
  overflow: hidden;
}

/* ---- LAYOUT ---- */
.app-layout, .layout {
  display: flex;
  height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 0.5px solid rgba(255,255,255,0.08);
  margin-bottom: 0.5rem;
}

.sidebar-logo .logo-title {
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo .logo-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  margin-top: 3px;
  padding-left: 26px;
}

.nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.25);
  padding: 0.75rem 1.25rem 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 1.25rem;
  font-size: 13px;
  color: var(--color-sidebar-text);
  cursor: pointer;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.12s;
}

.nav-item:hover {
  color: #fff;
  background: rgba(255,255,255,0.06);
}

.nav-item.active {
  color: #fff;
  background: var(--color-sidebar-active);
  border-left-color: var(--color-sidebar-accent);
}

.nav-item i { font-size: 16px; }

/* ---- MAIN ---- */
.main-area, .main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 0.5px solid #e5e5e0;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 15px;
  font-weight: 500;
  color: #1a1a1a;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ---- CONTENT ---- */
.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.5rem;
}

/* ---- CARDS ---- */
.card {
  background: #fff;
  border: 0.5px solid #e5e5e0;
  border-radius: 12px;
  padding: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 13px;
  font-weight: 500;
  color: #1a1a1a;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.card-link {
  font-size: 12px;
  font-weight: 400;
  color: #888;
  text-decoration: none;
}

.card-link:hover { color: var(--color-purple); }

/* ---- MÉTRIQUES ---- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 1.25rem;
}

.metric-card, .metric {
  background: #fff;
  border: 0.5px solid #e5e5e0;
  border-radius: 10px;
  padding: 1rem 1.25rem;
}

.metric-label {
  font-size: 12px;
  color: #888;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.metric-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.metric-value {
  font-size: 26px;
  font-weight: 500;
  color: #1a1a1a;
  line-height: 1.1;
}

.metric-accent .metric-value { color: var(--color-purple); }

.metric-sub {
  font-size: 12px;
  color: #aaa;
  margin-top: 4px;
}

.metric-sub.alert { color: #A32D2D; }

/* ---- GRILLES ---- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

/* ---- BADGES / PILLS ---- */
.pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.pill-green  { background: #EAF3DE; color: #3B6D11; }
.pill-red    { background: #FCEBEB; color: #A32D2D; }
.pill-amber  { background: #FAEEDA; color: #854F0B; }
.pill-gray   { background: #F1EFE8; color: #5F5E5A; }
.pill-purple { background: #EEEDFE; color: #534AB7; }
.pill-blue   { background: #E6F1FB; color: #185FA5; }
.pill-orange { background: #FAEEDA; color: #854F0B; }

/* ---- ALERTES SYSTÈME ---- */
.badge-alert {
  background: #F0997B;
  color: #4A1B0C;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-weight: 500;
}

/* ---- ROWS LISTE ---- */
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 0.5px solid #f0f0ec;
}

.list-row:last-child { border-bottom: none; padding-bottom: 0; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}

.av-purple { background: #EEEDFE; color: #534AB7; }
.av-teal   { background: #E1F5EE; color: #0F6E56; }
.av-blue   { background: #E6F1FB; color: #185FA5; }
.av-coral  { background: #FAECE7; color: #993C1D; }
.av-amber  { background: #FAEEDA; color: #854F0B; }
.av-green  { background: #EAF3DE; color: #3B6D11; }
.av-red    { background: #FCEBEB; color: #A32D2D; }

.list-info { flex: 1; min-width: 0; }
.list-name { font-size: 13px; font-weight: 500; color: #1a1a1a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub  { font-size: 11px; color: #aaa; margin-top: 1px; }
.list-right { text-align: right; flex-shrink: 0; }
.list-amount { font-size: 13px; font-weight: 500; color: #1a1a1a; }

/* ---- ALERTES ROWS ---- */
.alert-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 0.5px solid #f0f0ec;
}

.alert-row:last-child { border-bottom: none; }

.alert-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.ai-red    { background: #FCEBEB; color: #A32D2D; }
.ai-amber  { background: #FAEEDA; color: #854F0B; }
.ai-blue   { background: #E6F1FB; color: #185FA5; }
.ai-purple { background: #EEEDFE; color: #534AB7; }
.ai-green  { background: #EAF3DE; color: #3B6D11; }

.alert-title {
  font-size: 13px;
  font-weight: 500;
  color: #1a1a1a;
}

.alert-sub {
  font-size: 11px;
  color: #aaa;
  margin-top: 1px;
}

/* ---- BARRES PROGRESSION ---- */
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.bar-row:last-child { margin-bottom: 0; }
.bar-label { font-size: 12px; color: #888; width: 120px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar-track {
  flex: 1;
  height: 8px;
  background: #f0f0ec;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }
.bar-val  { font-size: 12px; font-weight: 500; color: #1a1a1a; width: 45px; text-align: right; flex-shrink: 0; }

.bar-fill-purple { background: var(--color-purple); }
.bar-fill-amber  { background: var(--color-amber); }
.bar-fill-red    { background: var(--color-red); }

/* ---- TABLES ---- */
.table-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 460px;            /* ~10 lignes ; ajuster si besoin (~46px/ligne) */
}
.table-wrapper thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;             /* fond des .card */
}

/* ---- TABLEAUX : hauteur adaptative (volet C, 15/07) ----
   Remplace le plafond fixe de .table-wrapper par la hauteur de fenêtre
   disponible. --table-fill-offset (posé inline par page) = tout ce qui
   occupe la fenêtre au-dessus du tableau (topbar + filtres + marges) ;
   valeur par défaut prudente si non fournie. Le sticky thead de
   .table-wrapper reste actif. N'affecte que les pages qui ajoutent
   cette classe — .table-wrapper seul (banque, lots, impot, régul.
   charges, contrat_detail) est inchangé.
   Symétrie haut/bas (16/07) : les offsets par page (mesurés par lecture
   de code au volet C, pas de rendu navigateur) réservaient trop d'espace
   résiduel en bas par rapport à la marge haute réelle (padding .content
   = 1.5rem/24px). --table-fill-bottom-fix retranche un correctif unique
   (calibré sur la marge la plus courte des 5 pages, /contrats, pour ne
   jamais risquer un dépassement bas de page) à tous les offsets — valeur
   partagée unique, aucun fork par page. Résiduel bas encore > marge
   haute sur les pages à en-tête plus chargé (récapitulatif quittances,
   onglets+recherche contrats/factures) : cf. rapport. */
.table-fill {
  --table-fill-bottom-fix: 45px;
  max-height: calc(100vh - var(--table-fill-offset, 260px) + var(--table-fill-bottom-fix));
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  font-weight: 500;
  color: #888;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 12px 10px;
  border-bottom: 0.5px solid #e5e5e0;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 0.5px solid #f5f5f0;
  color: #1a1a1a;
}

/* Cellules numériques : montant et « € » solidaires, jamais de retour à la ligne */
.num { text-align: right; white-space: nowrap; }
thead th.num { text-align: right; }

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafafa; }
tbody tr.clickable-row { cursor: pointer; }
tbody tr.clickable-row:hover td { background: #f0effe; }

/* Fonds colorés par statut */
tr.row-preavis  td { background: #FFF8F0; }
tr.row-resilie  td { background: #FEF5F5; }
tr.row-clos     td { background: #F8F8F8; }
tr.row-contentieux td { background: #FEF5F5; }
tr.row-preavis.clickable-row:hover td,
tr.row-resilie.clickable-row:hover td,
tr.row-clos.clickable-row:hover td,
tr.row-contentieux.clickable-row:hover td { filter: brightness(0.97); }

/* ---- BOUTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 0.5px solid #e0e0da;
  background: #fff;
  color: #1a1a1a;
  text-decoration: none;
  transition: all 0.12s;
  white-space: nowrap;
}

.btn:hover { background: #f5f5f0; }

.btn-primary {
  background: var(--color-purple);
  color: #fff;
  border-color: var(--color-purple);
}

.btn-primary:hover { background: #6d65c9; border-color: #6d65c9; }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-gray {
  background: #f5f5f0;
  border-color: #e0e0da;
  color: #555;
}

.btn-gray:hover { background: #eeeee9; }

.btn-danger {
  background: #FCEBEB;
  border-color: #f0c0c0;
  color: #A32D2D;
}

.btn-danger:hover { background: #f8d8d8; }

.btn-orange {
  background: #FAEEDA;
  border-color: #e0c898;
  color: #854F0B;
}

.btn-orange:hover { background: #f5e4c5; }

/* ---- FORMULAIRES ---- */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 0.5px solid #e0e0da;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  color: #1a1a1a;
  background: #fff;
  outline: none;
  transition: border-color 0.12s;
}

/* Barres de filtres /banque — largeur au contenu, tout sur une ligne */
form[action="/banque"] select,
form[action="/banque"] input[type="text"] {
  width: auto;
  flex: 0 0 auto;
  min-width: 120px;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus, textarea:focus {
  border-color: var(--color-purple);
}

textarea { resize: vertical; min-height: 80px; }

.label {
  font-size: 12px;
  color: #888;
  margin-bottom: 4px;
  display: block;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ---- PANNEAUX INLINE (remplacent les modales) ---- */
.detail-row > td,
.action-row > td {
  padding: 0 !important;
  border-bottom: 2px solid var(--color-purple) !important;
}

.inline-panel {
  padding: 1.25rem 1.5rem;
  background: #f9f9f7;
  border-left: 3px solid var(--color-purple);
}

.panel-tabs {
  display: flex;
  gap: 0;
  border-bottom: 0.5px solid #e5e5e0;
  margin: -1.25rem -1.5rem 1.25rem;
  padding: 0 1.5rem;
  background: #fff;
}

.panel-tab {
  font-size: 12px;
  padding: 10px 14px;
  cursor: pointer;
  color: #888;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -0.5px;
  transition: color 0.12s, border-color 0.12s;
}

.panel-tab.active {
  color: var(--color-purple);
  border-bottom-color: var(--color-purple);
  font-weight: 500;
}

.panel-tab-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 0.5px solid #e0e0da;
}

/* Panneau fixe en haut (variante — cf. P5 factures) */
/* Panneau fixe sous la topbar, s'ouvrant par le haut.
   translateY(calc(-100% - topbar-height)) garantit que le bas du panneau
   fermé arrive à y=0 (bord viewport), donc entièrement caché derrière la topbar.
   Avec translateY(-100%) seul le bas était à y=52px, faisant apparaître les
   champs de la bottom-panel-body à nu au-dessus du contenu (bug P5). */
.top-panel {
  position: fixed;
  top: var(--topbar-height);
  left: var(--sidebar-width);
  right: 0;
  background: #fff;
  border-bottom: 1px solid #e5e5e0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.10);
  z-index: 100;
  transform: translateY(calc(-100% - var(--topbar-height)));
  transition: transform 0.22s ease;
}
.top-panel.open { transform: translateY(0); }

/* Panneau fixe en bas (formulaire création) */
.bottom-panel {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  background: #fff;
  border-top: 1px solid #e5e5e0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.10);
  z-index: 100;
  transform: translateY(100%);
  transition: transform 0.22s ease;
}

.bottom-panel.open { transform: translateY(0); }

.bottom-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 1.5rem;
  border-bottom: 0.5px solid #f0f0ec;
  background: #fff;
}

.bottom-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
}

.bottom-panel-body {
  padding: 1rem 1.5rem 1.25rem;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.bottom-panel-body .field { min-width: 150px; flex: 1; }

/* Formulaire inline ajout locataire (contrat_nouveau) */
.ajout-loc-panel {
  background: #f5f5f0;
  border-radius: var(--radius-sm);
  border: 0.5px solid #e0e0da;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

/* ---- ACCORDÉON QUITTANCES ---- */
.groupe {
  border: 0.5px solid #e5e5e0;
  border-radius: var(--radius);
  background: #fff;
  margin-bottom: 8px;
  overflow: hidden;
}

.groupe-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 1rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.groupe-header:hover { background: #fafafa; }

.groupe-nom {
  font-size: 13px;
  font-weight: 500;
  color: #1a1a1a;
  flex: 1;
}

.groupe-toggle {
  font-size: 14px;
  color: #aaa;
  transition: transform 0.2s;
}

.groupe.open .groupe-toggle { transform: rotate(180deg); }

.quittance-list {
  display: none;
  border-top: 0.5px solid #f5f5f0;
}

.groupe.open .quittance-list { display: block; }

/* ---- TAB BAR (filtres) ---- */
.tab-bar {
  display: flex;
  border-bottom: 0.5px solid #e5e5e0;
  background: #fff;
  border-radius: 12px 12px 0 0;
  padding: 0 1.25rem;
}

.tab-btn {
  padding: 10px 14px;
  font-size: 13px;
  color: #888;
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -0.5px;
  transition: all 0.12s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-btn.active {
  color: var(--color-purple);
  border-bottom-color: var(--color-purple);
}

.tab-count {
  font-size: 11px;
  background: #f0f0ec;
  color: #888;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
}

.tab-btn.active .tab-count {
  background: var(--accent-light);
  color: var(--color-purple);
}

/* ---- SECTION HEADERS ---- */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  margin-top: 1.25rem;
}

.section-header:first-child { margin-top: 0; }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
}

/* ---- SEARCH BAR ---- */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrap i {
  position: absolute;
  left: 9px;
  color: #bbb;
  font-size: 15px;
  pointer-events: none;
}

.search-input {
  width: 220px;
  padding: 6px 10px 6px 30px;
  border: 0.5px solid #e0e0da;
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: #fff;
  outline: none;
  transition: border-color 0.12s, width 0.2s;
}

.search-input:focus {
  border-color: var(--color-purple);
  width: 260px;
}

/* ---- TAGS LOCATAIRES ---- */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
  padding: 4px 8px;
  border: 0.5px solid #e0e0da;
  border-radius: var(--radius-sm);
  background: #fff;
  align-items: center;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
}

.tag-referent    { background: #EAF3DE; color: #3B6D11; }
.tag-colocataire { background: #EEEDFE; color: #534AB7; }

.tag-remove {
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  opacity: 0.6;
  background: none;
  border: none;
  color: inherit;
}

.tag-remove:hover { opacity: 1; }

/* ---- TOAST ---- */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1a1a1a;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  opacity: 1;
  transition: opacity 0.4s;
  max-width: 300px;
  pointer-events: auto;
}

.toast.toast-ok     { background: #2D5A1B; }
.toast.toast-error  { background: #6B1919; }
.toast.toast-warn   { background: #7A4A00; }
.toast.fade-out     { opacity: 0; }

/* ---- FACTURE ROWS ---- */
.facture-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 0.5px solid #f0f0ec;
}

.facture-row:last-child { border-bottom: none; }

.facture-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.fi-elec  { background: #FAEEDA; color: #854F0B; }
.fi-eau   { background: #E6F1FB; color: #185FA5; }
.fi-gaz   { background: #FCEBEB; color: #A32D2D; }
.fi-autre { background: #F1EFE8; color: #5F5E5A; }

/* ---- BANDEAU TOTAL ---- */
.bandeau {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f5f5f0;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 12px;
  color: #888;
  margin: 0 -1.25rem -1.25rem;
}

.bandeau strong { color: #1a1a1a; }

/* ---- DEUX COLONNES FORM ---- */
.form-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.form-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---- CALCUL AFFICHÉ ---- */
.calcul-box {
  background: #f5f5f0;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  color: #555;
}

.calcul-box .calcul-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-purple);
}

/* ---- UTILITAIRES ---- */
.text-muted   { color: #aaa; }
.text-red     { color: #A32D2D; }
.text-green   { color: #3B6D11; }
.text-amber   { color: #854F0B; }
.text-purple  { color: #534AB7; }
.text-right   { text-align: right; }
.text-bold    { font-weight: 600; }
.text-sm      { font-size: 12px; }
.mt-1  { margin-top: 1rem; }
.mb-1  { margin-bottom: 1rem; }
.mt-sm { margin-top: 0.5rem; }
.gap-1 { gap: 1rem; }
.gap-8 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.flex-1 { flex: 1; }

/* ============================================================
   FICHE VPS 2 — MODE LECTURE SEULE
   Actif via l'attribut data-lecture-seule posé sur <body> par base.html,
   lui-même alimenté par request.state.ecriture_interdite (middleware).
   Aucune règle ci-dessous ne s'applique quand l'attribut est absent :
   c'est la condition de neutralité du test T-OFF.
   ============================================================ */

/* Masquage des commandes d'écriture explicitement annotées. L'annotation des
   73 templates est une passe cosmétique ultérieure : la sécurité ne repose pas
   dessus (403 serveur + enveloppe fetch), seulement le confort visuel. */
body[data-lecture-seule] [data-ecriture] { display: none !important; }

/* Bandeau d'information, pas d'obstruction. Zéro modale. */
.bandeau-lecture-seule {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  z-index: 40;
  padding: 5px 14px;
  font-size: 11.5px;
  color: #6a6a66;
  background: #f3f1e9;
  border-top: 0.5px solid #e2e0d6;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Avis temporaire émis par l'enveloppe fetch quand une écriture est interceptée. */
.avis-lecture-seule {
  position: fixed;
  bottom: 34px;
  right: 18px;
  z-index: 60;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  background: #12172E;
  color: #fff;
  font-size: 12.5px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.avis-lecture-seule.visible { opacity: 1; transform: translateY(0); }

/* ============================================================================
   FICHE 5 — CONSULTATION SUR SMARTPHONE
   ----------------------------------------------------------------------------
   INVARIANT : au-dessus de 768px, rien ne change. Tout ce qui suit est soit
   enfermé dans une media query, soit inerte au-dessus du seuil (une classe que
   personne ne porte, un bouton en display:none). C'est l'écran de travail
   quotidien de Steph : la neutralité desktop n'est pas négociable.
   ============================================================================ */

/* Bouton burger : présent dans le HTML en permanence, invisible au-dessus du
   seuil. Règle hors media query, mais sans effet visible sur desktop. */
.burger {
  display: none;
  background: none;
  border: none;
  padding: 8px;
  margin-right: 4px;
  cursor: pointer;
  color: #1a1a1a;
  font-size: 22px;
  line-height: 1;
}

/* Voile derrière la sidebar ouverte. Idem : inerte tant que .ouvert est absent. */
.voile-menu {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.35);
}
.voile-menu.ouvert { display: block; }

/* Conteneur de défilement posé PAR JAVASCRIPT autour des tableaux qui n'en ont
   pas déjà un (voir base.html). Au-dessus du seuil il ne fait rien : pas de
   largeur imposée, pas de débordement — donc aucun effet sur le rendu desktop. */
.tableau-defilant { width: 100%; }

/* Classe d'effacement par priorité, posée à l'étage 2 sur les colonnes
   secondaires. Sans media query elle ne masque rien. */
.masquable-mobile { }

@media (max-width: 768px) {

  /* ---- Mise en page : la sidebar sort du flux ---- */
  .app-layout, .layout { display: block; height: auto; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: 82vw;
    max-width: 300px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 2px 0 18px rgba(0, 0, 0, .3);
  }
  .sidebar.ouvert { transform: translateX(0); }

  .main-area, .main { height: 100vh; overflow: hidden; }

  /* ---- Topbar compacte ---- */
  .burger { display: block; }
  .topbar { padding: 0 .75rem; gap: .5rem; }
  .topbar-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }
  .topbar-right { flex-shrink: 0; }

  /* ---- Contenu ---- */
  /* overflow-x: hidden est LE point de la fiche : la PAGE ne doit jamais partir
     en travers. Le défilement latéral appartient aux tableaux, pas au document. */
  .content { padding: .75rem; overflow-x: hidden; }
  body { font-size: 15px; }          /* lecture confortable sans zoomer */

  /* ---- Tableaux : le défilement reste DANS le tableau ---- */
  .table-wrapper, .tableau-defilant {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;   /* inertie tactile iOS */
    max-width: 100%;
  }
  .table-wrapper { max-height: none; }   /* l'écran est déjà court, pas de double cadre */
  /* Ombre au bord droit : signale qu'il reste du contenu à faire défiler. */
  .table-wrapper, .tableau-defilant {
    background-image: linear-gradient(to left, rgba(0,0,0,.10), rgba(0,0,0,0) 22px);
    background-position: right center;
    background-repeat: no-repeat;
    background-size: 22px 100%;
    background-attachment: local;
  }
  table { font-size: 13.5px; }
  th, td { padding: 8px 10px; white-space: nowrap; }

  /* ---- Effacement des colonnes secondaires (étage 2) ---- */
  .masquable-mobile { display: none !important; }

  /* ---- Confort tactile : 44px, seuil d'Apple comme de Google ---- */
  .nav-item { min-height: 44px; display: flex; align-items: center; }
  .btn, .btn-sm, button, select { min-height: 44px; }
  .btn-sm { padding: .5rem .75rem; font-size: 13.5px; }
  .list-row { min-height: 52px; padding-top: 10px; padding-bottom: 10px; }
  a, .card-link { touch-action: manipulation; }

  /* ---- Formulaires pleine largeur, 16px pour empêcher le zoom auto d'iOS ---- */
  input, select, textarea { width: 100%; font-size: 16px; min-height: 44px; }
  .field-row { flex-direction: column; gap: .5rem; }
  .field { width: 100%; flex: 1 1 auto !important; }

  /* ---- Blocs en une colonne ---- */
  .metric-card { width: 100%; }
  .bottom-panel, .inline-panel, .top-panel { width: 100%; left: 0; right: 0; }

  /* ---- Bandeau lecture seule : une barre fine, pas un pavé ---- */
  .bandeau-lecture-seule {
    left: 0;
    font-size: 11px;
    padding: 4px 10px;
  }
  .avis-lecture-seule { right: 10px; left: 10px; bottom: 30px; }

  /* ---- Survols sans équivalent tactile : neutralisés ---- */
  .btn:hover, .nav-item:hover, .list-row:hover { filter: none; }
}

/* Terminaux tactiles : un :hover y « colle » après le tap. On ne le déclenche
   que sur les périphériques qui savent réellement survoler. */
@media (hover: none) {
  .btn:hover, .nav-item:hover, .list-row:hover, .card-link:hover { filter: none; }
}

/* ----------------------------------------------------------------------------
   FICHE 5 — ÉTAGE 2 : effacement des colonnes secondaires, par famille de liste.
   Ciblage par IDENTIFIANT DE TABLEAU, jamais par page : `contrats.py` rend trois
   gabarits sous le même `active`, et viser la page masquerait des colonnes sur la
   fiche contrat. L'identifiant ne désigne qu'un tableau, il ne peut pas déraper.
   Les colonnes effacées restent atteignables : le tableau défile latéralement.
   ---------------------------------------------------------------------------- */
@media (max-width: 768px) {

  /* Banque — remboursements : on garde Date, Locataire, Montant, Nature. */
  #tbl-remboursements th:nth-child(5), #tbl-remboursements td:nth-child(5),
  #tbl-remboursements th:nth-child(6), #tbl-remboursements td:nth-child(6) { display: none; }

  /* Banque — paiements : on garde Date, Locataire, Période, Total.
     Le détail (Loyer / Charges / Dépôt) reste accessible par défilement. */
  #tbl-paiements th:nth-child(4), #tbl-paiements td:nth-child(4),
  #tbl-paiements th:nth-child(5), #tbl-paiements td:nth-child(5),
  #tbl-paiements th:nth-child(6), #tbl-paiements td:nth-child(6),
  #tbl-paiements th:nth-child(8), #tbl-paiements td:nth-child(8) { display: none; }

  /* Quittances — on garde Contrat, Période, Loyer appelé, Reçu, Statut. */
  #tbl-quittances th:nth-child(4), #tbl-quittances td:nth-child(4) { display: none; }

  /* Factures — on garde Fournisseur, Date, Montant, Statut. */
  #tbl-factures th:nth-child(4), #tbl-factures td:nth-child(4) { display: none; }

  /* Contrats — on garde Contrat, Loyer, Statut, Indicateur. */
  #tbl-contrats th:nth-child(3), #tbl-contrats td:nth-child(3),
  #tbl-contrats th:nth-child(4), #tbl-contrats td:nth-child(4) { display: none; }

  /* Lots — on garde Lot, Surnom, Immeuble, Contrat. */
  #tbl-lots th:nth-child(4), #tbl-lots td:nth-child(4),
  #tbl-lots th:nth-child(5), #tbl-lots td:nth-child(5) { display: none; }

  /* Locataires — on garde l'avatar, Nom, Contrat(s), Statut. */
  #table-locataires th:nth-child(3), #table-locataires td:nth-child(3),
  #table-locataires th:nth-child(4), #table-locataires td:nth-child(4) { display: none; }
}
