/* ════════════════════════════════════════════════════════════
   CSS GLOBAL — Nas-Sarra Immobilier
   ════════════════════════════════════════════════════════════ */

/* ── Variables & Reset ─────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --gold:#C8A96E; --gold-light:#F5EDD8; --gold-dark:#9B7A3D;
  --navy:#0D1B2A; --navy-mid:#1A2E44; --navy-light:#243B55;
  --cream:#FAF7F2; --cream-dark:#F0EAE0;
  --white:#FFFFFF;
  --text:#1A1A1A; --text-sec:#5A5A5A; --text-hint:#9A9A9A;
  --green:#2D7D46; --green-light:#E8F5EC;
  --red:#C0392B;   --red-light:#FDECEB;
  --border:#E2D9CC;
  --shadow:0 2px 16px rgba(13,27,42,.08);
  --shadow-lg:0 8px 40px rgba(13,27,42,.14);
  --radius:10px; --radius-lg:16px; --radius-xl:24px;
  --sidebar-w:260px;
  --topbar-h:60px;
  --transition:.22s cubic-bezier(.4,0,.2,1);
}
html { scroll-behavior: smooth; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout principal ──────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.content { flex: 1; overflow-y: auto; padding: 1.75rem; overscroll-behavior: contain; }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition), width var(--transition);
  z-index: 200;
}
.sidebar-brand { padding: 1.5rem 3rem 1.25rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,.08); position: relative; }
.brand-logo { display: flex; align-items: center; gap: 10px; }
.brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: var(--navy);
  font-family: 'Playfair Display', serif;
  flex-shrink: 0;
}
.brand-name { font-family: 'Playfair Display', serif; font-size: 15px; font-weight: 700; color: var(--white); line-height: 1.2; }
.brand-sub { font-size: 9px; color: var(--gold); letter-spacing: 1.5px; text-transform: uppercase; margin-top: 2px; }

.sidebar-user {
  padding: .85rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}
.user-av {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--navy); flex-shrink: 0;
}
.user-name { font-size: 12.5px; font-weight: 600; color: var(--white); }
.user-role { font-size: 10px; color: var(--gold); margin-top: 1px; }

.nav-section { padding: .6rem 0; }
.nav-label { font-size: 9px; text-transform: uppercase; letter-spacing: 1.2px; color: rgba(255,255,255,.3); padding: .4rem 1.25rem .2rem; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: .6rem 1.25rem;
  cursor: pointer; font-size: 12.5px;
  color: rgba(255,255,255,.65);
  border-left: 2px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  position: relative; user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.92); }
.nav-item.active { background: rgba(200,169,110,.13); border-left-color: var(--gold); color: var(--gold); font-weight: 600; }
.nav-item .nav-badge { margin-left: auto; background: var(--gold); color: var(--navy); font-size: 9px; font-weight: 700; padding: 1px 6px; border-radius: 10px; }
.nav-icon { width: 15px; height: 15px; flex-shrink: 0; opacity: .8; }

.sidebar-footer { margin-top: auto; padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer-text { font-size: 10px; color: rgba(255,255,255,.28); text-align: center; line-height: 1.7; }


/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 1.75rem;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
  position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.page-title { font-family: 'Playfair Display', serif; font-size: 17px; font-weight: 600; color: var(--navy); }
.page-crumb { font-size: 11px; color: var(--text-sec); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }


/* Topbar buttons */
.tb-btn {
  padding: 6px 13px; border-radius: 8px; font-size: 12px; font-weight: 500;
  cursor: pointer; border: 1px solid var(--border);
  background: transparent; color: var(--text);
  font-family: 'DM Sans', sans-serif;
  transition: background var(--transition), color var(--transition);
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; flex-shrink: 0;
}
.tb-btn:hover { background: var(--cream-dark); }
.tb-btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.tb-btn.primary:hover { background: var(--navy-mid); }
.tb-btn.gold { background: var(--gold); border-color: var(--gold); color: var(--navy); font-weight: 600; }
.tb-btn.gold:hover { background: var(--gold-dark); border-color: var(--gold-dark); }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  margin-bottom: 1.1rem;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; flex-wrap: wrap; gap: .5rem; }
.card-title { font-family: 'Playfair Display', serif; font-size: 15px; font-weight: 600; color: var(--navy); }
.card-sub { font-size: 11.5px; color: var(--text-sec); margin-top: 2px; }

/* Grilles */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; }
.grid4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; }

/* ── Stat cards ────────────────────────────────────────────── */
.stat-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.1rem 1.25rem;
  position: relative; overflow: hidden;
}
.stat-card::after { content: ''; position: absolute; top: 0; left: 0; width: 3px; height: 100%; background: var(--gold); }
.stat-label { font-size: 10.5px; color: var(--text-sec); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 4px; }
.stat-value { font-family: 'Playfair Display', serif; font-size: 24px; font-weight: 600; color: var(--navy); }
.stat-sub { font-size: 10px; color: var(--text-hint); margin-top: 3px; }
.stat-up { color: var(--green); }
.stat-down { color: var(--red); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  padding: 9px 18px; border-radius: 8px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid;
  display: inline-flex; align-items: center; gap: 7px;
  font-family: 'DM Sans', sans-serif;
  transition: all var(--transition);
  white-space: nowrap; background: #fff;
}
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-mid); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--cream-dark); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--navy); font-weight: 600; }
.btn-gold:hover { background: var(--gold-dark); border-color: var(--gold-dark); color: #fff; }
.btn-green { background: var(--green-light); border-color: #A8D8B9; color: var(--green); }
.btn-danger { background: var(--red-light); border-color: #F5B8B4; color: var(--red); }
.btn-sm { padding: 5px 11px; font-size: 11.5px; }
.btn-xs { padding: 3px 8px; font-size: 10.5px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Pills ─────────────────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 10px; font-weight: 600; padding: 3px 9px; border-radius: 20px; }
.pill-green  { background: var(--green-light); color: var(--green); }
.pill-amber  { background: #FEF3E2; color: #B07D1B; }
.pill-red    { background: var(--red-light); color: var(--red); }
.pill-blue   { background: #EBF3FD; color: #1A5FAF; }
.pill-gold   { background: var(--gold-light); color: var(--gold-dark); }
.pill-gray   { background: #F0EDE8; color: var(--text-sec); }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: .85rem; }
.form-label { font-size: 11px; font-weight: 600; color: var(--text-sec); margin-bottom: 5px; display: block; text-transform: uppercase; letter-spacing: .4px; }
.req { color: var(--gold-dark); }
input, select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; background: var(--white); color: var(--text);
  outline: none; transition: border-color var(--transition), box-shadow var(--transition);
  font-family: 'DM Sans', sans-serif;
  min-height: 40px; /* touch target */
}
input:focus, select:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200,169,110,.15);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
textarea { resize: vertical; min-height: 75px; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239A9A9A' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px;
}

/* ── Tableau responsive ────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 500px; }
th { background: var(--cream); color: var(--text-sec); font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--cream); }

/* ── Historique items ──────────────────────────────────────── */
.hist-item {
  display: flex; align-items: center; gap: 12px;
  padding: .8rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--white);
  margin-bottom: .5rem; cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.hist-item:hover { border-color: var(--gold); box-shadow: 0 3px 14px rgba(200,169,110,.14); transform: translateY(-1px); }
.hist-num { font-family: monospace; font-size: 11px; font-weight: 600; color: var(--navy); min-width: 110px; }
.hist-client { flex: 1; font-size: 12.5px; font-weight: 500; min-width: 0; }
.hist-montant { font-size: 13px; font-weight: 600; color: var(--navy); min-width: 110px; text-align: right; }
.hist-date { font-size: 10.5px; color: var(--text-hint); min-width: 80px; text-align: right; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast {
  background: var(--navy); color: #fff;
  padding: .7rem 1.1rem; border-radius: var(--radius);
  font-size: 12.5px; display: flex; align-items: center; gap: 8px;
  min-width: 240px; max-width: 320px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .28s cubic-bezier(.16,1,.3,1);
  border-left: 3px solid var(--gold);
}
.toast-success { border-left-color: var(--green); }
.toast-danger  { border-left-color: var(--red); }
@keyframes toastIn { from { transform: translateX(100%) scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--text-hint); }
.empty-icon  { font-size: 48px; margin-bottom: .75rem; }
.empty-title { font-size: 15px; font-weight: 600; color: var(--text-sec); margin-bottom: .4rem; }
.empty-text  { font-size: 12.5px; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-bg {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(13,27,42,.5);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(3px);
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ════════════════════════════════════════════════════════════
   ANIMATIONS GLOBALES
   ════════════════════════════════════════════════════════════ */

/* Éléments animables — état initial */
[data-anim] {
  opacity: 0;
  transition: opacity .5s cubic-bezier(.4,0,.2,1), transform .5s cubic-bezier(.4,0,.2,1);
}
[data-anim="fade-up"]    { transform: translateY(22px); }
[data-anim="fade-down"]  { transform: translateY(-16px); }
[data-anim="fade-left"]  { transform: translateX(22px); }
[data-anim="fade-right"] { transform: translateX(-22px); }
[data-anim="scale-in"]   { transform: scale(.94); }

/* État visible (ajouté par JS via IntersectionObserver) */
[data-anim].anim-in {
  opacity: 1;
  transform: none;
}

/* Délais de stagger */
[data-delay="1"] { transition-delay: .06s; }
[data-delay="2"] { transition-delay: .12s; }
[data-delay="3"] { transition-delay: .18s; }
[data-delay="4"] { transition-delay: .24s; }
[data-delay="5"] { transition-delay: .30s; }
[data-delay="6"] { transition-delay: .36s; }

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--cream-dark) 25%, var(--cream) 50%, var(--cream-dark) 75%);
  background-size: 200% 100%;
  animation: skeleton-wave 1.4s linear infinite;
  border-radius: var(--radius);
  min-height: 14px;
}
@keyframes skeleton-wave {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* Ripple sur boutons */
.btn, .nav-item, .tb-btn, .hist-item {
  position: relative;
  overflow: hidden;
}
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(200,169,110,.25);
  transform: scale(0);
  animation: ripple-anim .5s linear;
  pointer-events: none;
}
@keyframes ripple-anim {
  to { transform: scale(4); opacity: 0; }
}

/* ── Transition de page ─────────────────────────────────────
   L'animation est sur .main directement (pas via JS)
   fill-mode:both = commence à opacity:0 AVANT le premier frame
   → aucun flash au chargement                              */
.main {
  animation: pageIn 0.38s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: none; }
}
/* Sortie (ajoutée par JS avant navigation) */
.main.page-out {
  animation: pageOut 0.18s ease forwards;
}
@keyframes pageOut {
  to { opacity: 0; transform: translateY(-10px); }
}

/* ════════════════════════════════════════════════════════════
   HAMBURGER (toujours défini, visible selon écran)
   ════════════════════════════════════════════════════════════ */
#menuToggle {
  display: flex;            /* toujours flex */
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 6px;
  margin-right: 4px;
  flex-shrink: 0;
}
#menuToggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--navy);
  border-radius: 2px;
}

/* Overlay (caché par défaut) */
#navOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 490;
}

/* ════════════════════════════════════════════════════════════
   DESKTOP (> 1024px) — sidebar toujours visible, hamburger caché
   ════════════════════════════════════════════════════════════ */
@media (min-width: 1025px) {
  #menuToggle { display: none; }
  .grid3 { grid-template-columns: repeat(3, 1fr); }
  .grid4 { grid-template-columns: repeat(4, 1fr); }
}

/* ════════════════════════════════════════════════════════════
   TABLETTE & MOBILE (≤ 1024px) — sidebar en drawer
   ════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {

  /* Sidebar cachée par défaut — overlay fixe quand ouverte */
  .sidebar {
    display: none;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 270px;
    z-index: 500;
    box-shadow: 4px 0 30px rgba(0,0,0,.35);
  }
  .sidebar.nav-open   { display: flex; }
  #navOverlay.nav-open { display: block; }

  /* Main pleine largeur */
  .main { width: 100%; }

  /* Grilles */
  .grid4 { grid-template-columns: repeat(2, 1fr); }
  .grid3 { grid-template-columns: repeat(2, 1fr); }
}

/* ════════════════════════════════════════════════════════════
   MOBILE (≤ 768px)
   ════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .topbar { padding: 0 1rem; }
  .page-crumb { display: none; }
  .content { padding: 1rem; }

  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }

  .hist-item   { flex-wrap: wrap; gap: 8px; }
  .hist-num    { min-width: unset; }
  .hist-client { width: 100%; }
  .hist-montant, .hist-date { min-width: unset; }

  .toast-container { left: 10px; right: 10px; bottom: 10px; }
  .toast { min-width: unset; width: 100%; }
}

/* ════════════════════════════════════════════════════════════
   TRÈS PETIT (≤ 480px)
   ════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  body { font-size: 13px; }
  .stat-value { font-size: 20px; }
  .page-title { font-size: 15px; }
  .content { padding: .75rem; }
  .card { padding: 1rem; }
}
