/* =========================================================
   Geroimmo — feuille de style unique
   Palette : terre cuite (toits, action) + vert canard (finance)
   ========================================================= */

:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --surface-2: #faf7f2;
  --ink: #1d2528;
  --muted: #5f6b6b;
  --line: #e6ddd1;

  --primary: #c4572e;
  --primary-hover: #a9461f;
  --primary-ink: #ffffff;
  --primary-soft: #f7e4d9;

  --accent: #1f6f6b;
  --accent-soft: #d9eeec;

  --success: #1f7a4d;
  --success-soft: #dcf2e5;
  --warning: #9a5a06;
  --warning-soft: #fcefd6;
  --danger: #b42318;
  --danger-soft: #fde7e4;

  --chart-due: #e3d7c8;
  --chart-paid: var(--accent);

  --brand-bg: #1e2a2c;
  --brand-ink: #f6efe6;
  /* Couleurs de l'illustration (identiques en mode sombre) */
  --brand-terracotta: #d4623f;
  --scene-sky: #f6ddae;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(29, 37, 40, 0.05), 0 8px 24px rgba(29, 37, 40, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 248px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121719;
    --surface: #1a2124;
    --surface-2: #1f272a;
    --ink: #ebe8e3;
    --muted: #9ba7a6;
    --line: #2c373a;

    --primary: #e07a4f;
    --primary-hover: #ea8f68;
    --primary-ink: #1a1210;
    --primary-soft: #3a2419;

    --accent: #5db3ac;
    --accent-soft: #173331;

    --success: #5cc48f;
    --success-soft: #16301f;
    --warning: #e6a948;
    --warning-soft: #33280f;
    --danger: #f2796c;
    --danger-soft: #3a1a17;

    --chart-due: #34403f;

    --brand-bg: #0d1213;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0; }
img { display: block; }
[hidden] { display: none !important; }

a { color: var(--accent); }

.muted { color: var(--muted); }

:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: 12px; }

/* ---------- Marque ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}
.brand__name {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand__logo { height: 40px; width: auto; flex: none; }
.brand--light .brand__logo { height: 44px; }
/* « Gero » dans la couleur du texte (clair sur fond sombre), « immo » en terracotta */
.brand__name span { color: var(--primary); }
.brand--light { color: var(--brand-ink); }
.brand--light .brand__name span { color: var(--brand-terracotta); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn--primary { background: var(--primary); color: var(--primary-ink); }
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn--small { min-height: 32px; padding: 0 12px; font-size: 0.875rem; }
.btn--block { width: 100%; }

/* ---------- Formulaires ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 0.9rem; }
input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[aria-invalid="true"] { border-color: var(--danger); }

.password { position: relative; }
.password input { padding-right: 92px; }
.password__toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.password__toggle:hover { background: var(--surface-2); color: var(--ink); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field--full { grid-column: 1 / -1; }
fieldset.tenant-fields {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}
fieldset.tenant-fields legend { padding: 0 6px; font-weight: 700; }

/* ---------- Alertes, badges ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 0.92rem; }
.alert--error { background: var(--danger-soft); color: var(--danger); }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--neutral { background: var(--accent-soft); color: var(--accent); }

/* ---------- Carte ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.card__header h2 { font-size: 1.05rem; }

/* =========================================================
   Page de connexion
   ========================================================= */
.login { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }

/* Panneau gauche : texte dans un encart sombre, illustration du campement en bas.
   Le fond reprend la couleur du ciel de l'illustration pour un raccord invisible. */
.login__brand {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 40px 40px 0;
  color: var(--brand-ink);
  background: var(--scene-sky);
  overflow: hidden;
}
.login__intro {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 24px;
  max-width: 540px;
  padding: 32px;
  border-radius: 20px;
  background: rgba(31, 42, 68, 0.94);
  box-shadow: 0 20px 40px rgba(31, 42, 68, 0.25);
}
.login__scene {
  display: block;
  width: calc(100% + 80px);
  max-width: none;
  height: auto;
  max-height: 62vh;
  margin: auto -40px 0;
  padding-top: 24px;
  object-fit: cover;
  object-position: center bottom;
}
.login__pitch h1 { font-size: clamp(2rem, 4vw, 3.2rem); letter-spacing: -0.03em; margin-bottom: 16px; }
.login__pitch p { max-width: 34ch; font-size: 1.08rem; opacity: 0.88; }
.login__features { list-style: none; margin: 28px 0 0; padding: 0; display: grid; gap: 10px; }
.login__features li { display: flex; align-items: center; gap: 10px; }
.login__features li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--brand-terracotta);
  transform: rotate(45deg);
  flex: none;
}
.login__footnote { max-width: 42ch; font-size: 0.88rem; opacity: 0.7; }

.login__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 16px;
}
.login__form { width: 100%; max-width: 400px; display: grid; gap: 18px; padding: 32px; }
.login__form h2 { font-size: 1.5rem; }
.login__legal { font-size: 0.82rem; }

@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login__brand { min-height: 0; padding: 16px 16px 0; }
  .login__intro { gap: 16px; padding: 20px; border-radius: 16px; }
  .login__scene { width: calc(100% + 32px); max-height: 200px; margin: 0 -16px; padding-top: 12px; }
  .login__pitch h1 { font-size: 1.9rem; }
  .login__features, .login__footnote { display: none; }
  .login__form { padding: 24px 20px; }
}

/* =========================================================
   Application (tableau de bord)
   ========================================================= */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.nav { display: grid; gap: 4px; }
.nav__link {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}
.nav__link:hover { background: var(--surface-2); color: var(--ink); }
.nav__link.is-active { background: var(--primary-soft); color: var(--primary); }
.sidebar__foot { margin-top: auto; font-size: 0.8rem; color: var(--muted); }
.sidebar-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.4); }

.shell { margin-left: var(--sidebar-w); min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 32px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__menu { display: none; }
.topbar__heading { flex: 1; min-width: 0; }
.topbar__heading h1 { font-size: 1.35rem; }
.topbar__heading p { font-size: 0.88rem; }
.topbar__user { display: flex; align-items: center; gap: 12px; }
.topbar__identity { display: flex; flex-direction: column; line-height: 1.25; }
.topbar__identity span { font-size: 0.8rem; }
.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.content { display: grid; gap: 24px; padding: 28px 32px 48px; max-width: 1400px; }
.section-title { font-size: 1.05rem; margin-bottom: 14px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.kpi {
  display: grid;
  gap: 6px;
  align-content: start;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi__label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.kpi__value { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi__hint { color: var(--muted); font-size: 0.82rem; }
.kpi--alert .kpi__value { color: var(--danger); }
.meter { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.meter__fill { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 0.6s ease; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 24px; }

/* Graphique */
.legend { display: flex; gap: 16px; font-size: 0.82rem; color: var(--muted); }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__item::before { content: ""; width: 10px; height: 10px; border-radius: 3px; }
.legend__item--due::before { background: var(--chart-due); }
.legend__item--paid::before { background: var(--chart-paid); }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar--due { fill: var(--chart-due); }
.chart .bar--paid { fill: var(--chart-paid); }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }

/* Impayés */
.unpaid-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; max-height: 360px; overflow-y: auto; }
.unpaid-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.unpaid-item__title { font-weight: 700; }
.unpaid-item__meta { font-size: 0.82rem; color: var(--muted); }
.unpaid-item__amount { font-weight: 800; color: var(--danger); text-align: right; font-variant-numeric: tabular-nums; }
.unpaid-item__actions { grid-column: 2; justify-self: end; }
.empty { padding: 24px 12px; text-align: center; color: var(--muted); }

/* Tableau */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th {
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-title { font-weight: 700; }
.cell-sub { font-size: 0.82rem; color: var(--muted); }

/* SCI */
.sci-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.sci-card { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); display: grid; gap: 4px; }
.sci-card__name { font-weight: 800; }
.sci-card__stats { display: flex; justify-content: space-between; margin-top: 8px; font-size: 0.88rem; }

/* Dialogue */
.dialog {
  width: min(640px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
}
.dialog::backdrop { background: rgba(18, 23, 25, 0.55); }
.dialog__form { display: grid; gap: 18px; padding: 24px; }
.dialog__header, .dialog__footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog__footer { justify-content: flex-end; }

/* Notification */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* Squelette de chargement */
.content[aria-busy="true"] .kpi__value { color: transparent; background: var(--surface-2); border-radius: 6px; }

/* =========================================================
   Locataires (liste et formulaire)
   ========================================================= */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.nav__group {
  margin: 14px 12px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.alert--warning { background: var(--warning-soft); color: var(--warning); }
.alert--warning a { color: inherit; font-weight: 700; }

.breadcrumb { font-size: 0.82rem; color: var(--muted); }
.breadcrumb a { color: inherit; }

.content--narrow { max-width: 880px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar__search { width: 260px; min-height: 40px; padding: 8px 12px; }
.card__header h2 .badge { margin-left: 6px; vertical-align: middle; }

a.badge { text-decoration: none; }
a.badge:hover { filter: brightness(0.95); }
.table tr.is-new td { background: var(--accent-soft); }

.tenant-form { display: grid; gap: 20px; }
.form-section { display: grid; gap: 16px; }
.form-section__title { font-size: 1rem; }
.form-hint { font-size: 0.85rem; color: var(--muted); }
.req { color: var(--danger); }
.field--spacer { visibility: hidden; }
select[aria-invalid="true"] { border-color: var(--danger); }

.choice { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; border: 0; }
.choice legend { width: 100%; margin-bottom: 6px; padding: 0; font-weight: 600; font-size: 0.9rem; }
.choice__option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}
.choice__option input { width: auto; min-height: 0; accent-color: var(--primary); }
.choice__option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.choice__option:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }

.dropzone {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 28px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone.has-file { border-style: solid; border-color: var(--success); background: var(--success-soft); }
.dropzone.has-error { border-style: solid; border-color: var(--danger); background: var(--danger-soft); }
.dropzone:focus-within { outline: 3px solid var(--primary); outline-offset: 2px; }
.dropzone__input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone__title { font-weight: 700; word-break: break-all; }
.dropzone__hint { font-size: 0.85rem; color: var(--muted); }

.form-actions { display: flex; justify-content: flex-end; gap: 12px; }

/* ---------- Parcours de démarrage ---------- */
.onboarding { border-color: var(--primary); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.step {
  display: grid;
  grid-template-columns: auto 1fr;
  align-content: start;
  gap: 8px 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.step > .btn { grid-column: 1 / -1; justify-self: start; }
.step__marker {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--line);
  color: var(--muted);
  font-weight: 800;
}
.step__body { display: grid; gap: 2px; }
.step__title { font-weight: 700; }
.step__text { font-size: 0.85rem; color: var(--muted); }
.step--done .step__marker { background: var(--success); border-color: var(--success); color: #fff; }
.step--done .step__title { color: var(--success); }
.step--current { border-color: var(--primary); background: var(--primary-soft); }
.step--current .step__marker { border-color: var(--primary); color: var(--primary); }
.step--todo { opacity: 0.65; }

.cell-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ---------- Récapitulatif de location ---------- */
.lease-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  border-color: var(--accent);
  background: var(--accent-soft);
}
.lease-summary__label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--accent); }
.lease-summary__value { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.lease-summary__detail { color: var(--ink); max-width: 46ch; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.is-open { transform: none; }
  .shell { margin-left: 0; }
  .topbar { padding: 12px 16px; }
  .topbar__menu { display: inline-flex; }
  .topbar__identity { display: none; }
  .content { padding: 20px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .field--spacer { display: none; }
  .toolbar, .toolbar__search { width: 100%; }
}

@media (max-width: 520px) {
  .topbar__heading p { display: none; }
  .avatar { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .steps { grid-template-columns: 1fr; }
  .kpi__value { font-size: 1.35rem; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .toast { left: 16px; right: 16px; bottom: 16px; }
}

/* ---------- 404 ---------- */
.notfound-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.notfound { display: grid; justify-items: center; gap: 14px; text-align: center; max-width: 420px; padding: 40px 32px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
