:root {
  --bg: #faf8f5;
  --card: #ffffff;
  --card-hover: #fdf6ef;
  --line: #e8e0d6;
  --ink: #2c2418;
  --muted: #8c7e6f;
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-light: #fff3ec;
  --green: #15803d;
  --red: #b91c1c;
  --shadow-sm: 0 1px 4px rgba(120,90,50,.07);
  --shadow-md: 0 4px 14px rgba(120,90,50,.1);
  --shadow-lg: 0 8px 28px rgba(120,90,50,.14);
  --input-bg: #fff;
  --badge-hausse: #d97706;
  --badge-reapp: #7c3aed;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: .15s ease;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: #1d4ed8; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: 56px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 100;
}
.brand { font-weight: 800; font-size: 17px; letter-spacing: -.3px; white-space: nowrap; }
.mainnav { display: flex; gap: 4px; }
.mainnav a {
  padding: 7px 14px; border-radius: var(--radius-sm); color: var(--muted);
  font-weight: 500; font-size: 13px; transition: all var(--transition);
}
.mainnav a:hover { background: var(--card-hover); color: var(--ink); text-decoration: none; }
.mainnav a.active { background: var(--accent); color: #fff; }
.toggle-photos {
  background: none; border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 15px; padding: 6px 10px; line-height: 1;
  transition: all var(--transition);
}
.toggle-photos:hover { background: var(--card-hover); }
.no-photos .toggle-photos { opacity: .35; }
.topbar .user { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.topbar .user a { color: var(--muted); }
.topbar .user a:hover { color: var(--accent); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }

/* ---- KPIs ---- */
.kpis { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.kpi {
  background: var(--card); border-radius: var(--radius);
  padding: 16px 20px; min-width: 140px; flex: 1;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.kpi:hover { box-shadow: var(--shadow-md); }
.kpi .v { display: block; font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .3px; margin-top: 2px; }

/* ---- Layout (filters + results) ---- */
.layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
.filters {
  position: sticky; top: 72px;
  background: var(--card); border-radius: var(--radius);
  padding: 16px; max-height: calc(100vh - 90px); overflow-y: auto;
  box-shadow: var(--shadow-sm);
}
.filter-toggle {
  display: none; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; margin-bottom: 12px; width: 100%;
  box-shadow: var(--shadow-sm); transition: all var(--transition);
}
.filter-toggle:hover { box-shadow: var(--shadow-md); }
.filter-toggle .arrow { transition: transform var(--transition); font-size: 12px; margin-left: auto; }
.filter-toggle.open .arrow { transform: rotate(180deg); }

.filters fieldset { border: none; border-top: 1px solid var(--line); margin: 0; padding: 14px 0 6px; }
.filters fieldset:first-child { border-top: none; padding-top: 0; }
.filters legend {
  font-weight: 700; font-size: 11px; text-transform: uppercase;
  color: var(--muted); padding: 0; letter-spacing: .5px;
}
.filters .row { display: flex; gap: 6px; }
.filters input[type=text], .filters input[type=number], .filters select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13px; margin-top: 6px; background: var(--input-bg);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.filters input:focus, .filters select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.filters .row input { margin-top: 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; }
.checks label { font-size: 13px; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.dpe-checks .dpe-check input { display: none; }
.dpe-check .dot {
  display: inline-block; width: 28px; height: 26px; line-height: 26px; text-align: center;
  border-radius: var(--radius-sm); font-weight: 700; color: #000; opacity: .3;
  cursor: pointer; font-size: 12px; transition: all var(--transition);
}
.dpe-check .dot:hover { opacity: .6; }
.dpe-check input:checked + .dot { opacity: 1; outline: 2px solid var(--ink); outline-offset: 1px; }
label.inline { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; }
label.inline select { width: auto; margin-top: 0; }
.filter-actions { margin-top: 14px; }
.reset {
  font-size: 13px; color: var(--muted); transition: color var(--transition);
}
.reset:hover { color: var(--red); }

/* ---- Results table ---- */
.result-head { margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.grid {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.grid th, .grid td {
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: top;
}
.grid th {
  background: var(--card-hover); font-size: 11px; text-transform: uppercase;
  color: var(--muted); font-weight: 700; letter-spacing: .4px;
}
.grid tr:last-child td { border-bottom: none; }
.grid tbody tr { transition: background var(--transition); }
.grid tbody tr:hover { background: var(--card-hover); }
.bien-row { display: flex; gap: 12px; align-items: start; }
.thumb { width: 80px; height: 60px; object-fit: cover; border-radius: var(--radius-sm); flex-shrink: 0; }
.grid .bien a { font-weight: 600; }
.grid .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.grid .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.prix strong { font-size: 15px; }
.prix .old { color: var(--muted); font-size: 12px; }
.ecart { font-size: 12px; }
.pos { color: var(--green); font-weight: 700; }
.neg { color: var(--red); font-weight: 700; }
.pos-bad { color: var(--red); }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* ---- Mobile cards (annonces table replacement) ---- */
.mobile-cards { display: none; }
.mobile-card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow-sm); transition: box-shadow var(--transition);
}
.mobile-card:hover { box-shadow: var(--shadow-md); }
.mobile-card-top { display: flex; gap: 12px; }
.mobile-card-top .thumb { width: 90px; height: 68px; }
.mobile-card-info { flex: 1; min-width: 0; }
.mobile-card-info a { font-weight: 600; font-size: 14px; display: block; }
.mobile-card-info .meta { margin-top: 3px; }
.mobile-card-nums {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 13px;
}
.mobile-card-nums .label { color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 600; }
.mobile-card-actions {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
}

/* ---- Badges ---- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 700; color: #fff; margin-left: 4px;
  letter-spacing: .2px;
}
.badge.i-surv { background: #6b7280; }
.badge.i-int { background: var(--badge-hausse); }
.badge.i-vis { background: var(--red); }
.badge.loue { background: var(--accent); }
.feat { color: var(--muted); font-size: 11px; white-space: nowrap; }
.dpe {
  display: inline-block; min-width: 28px; text-align: center;
  padding: 6px 10px; border-radius: var(--radius-sm);
  font-weight: 800; color: #000; font-size: 13px;
}

/* ---- Edit actions ---- */
.actions { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.star {
  background: none; border: none; cursor: pointer; font-size: 20px;
  color: #d1d5db; line-height: 1; padding: 4px;
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--transition);
}
.star:hover { transform: scale(1.15); }
.star.on { color: var(--badge-hausse); }
.interet-select {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13px; min-height: 36px;
}
.visite-group { display: flex; flex-direction: column; align-items: start; gap: 2px; }
.visite-label { font-size: 10px; color: var(--muted); text-transform: uppercase; line-height: 1; font-weight: 600; }
.visite-row { display: flex; align-items: center; gap: 2px; }
.visite {
  width: 130px; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 13px; min-height: 36px;
}
.visite-clear {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 18px; line-height: 1; padding: 4px 6px;
  min-width: 32px; min-height: 36px;
  display: flex; align-items: center; justify-content: center;
}
.visite-clear:hover { color: var(--red); }
.notes-box summary {
  cursor: pointer; list-style: none; font-size: 18px;
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
}
.notes-box[open] { position: relative; }
.notes-box form {
  position: absolute; z-index: 5; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; width: 260px;
  box-shadow: var(--shadow-lg);
}
.notes-box textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; padding: 8px;
}
.notes-box button { margin-top: 8px; }

button[type=submit], .login-card button {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 8px 16px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all var(--transition);
}
button[type=submit]:hover, .login-card button:hover {
  background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm);
}

/* ---- Cards (classement) ---- */
.section-title { font-size: 17px; font-weight: 700; margin: 4px 0 16px; }
.cards { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: grid; gap: 14px; align-items: center;
  grid-template-columns: 90px 2.4fr 1.3fr 1.2fr 1fr auto 1.4fr;
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow-sm); transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-thumb { width: 90px; height: 65px; object-fit: cover; border-radius: var(--radius-sm); display: block; }
.no-photo { background: var(--line); border-radius: var(--radius-sm); }
.card-title a { font-weight: 600; }
.card .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.card-prix strong { font-size: 15px; }
.card-prix .old { color: var(--muted); font-size: 12px; display: block; }
.card-cf div, .card-score div { font-size: 13px; }
.card-actions { display: flex; justify-content: flex-end; }

/* ---- Photo hover preview ---- */
.thumb-wrap { position: relative; flex-shrink: 0; }
.thumb-preview {
  display: none; position: absolute; z-index: 20;
  left: calc(100% + 8px); top: 50%; transform: translateY(-50%);
  width: 320px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}
.thumb-wrap:hover .thumb-preview { display: block; }

/* ---- Toggle photos off ---- */
.no-photos .thumb-wrap, .no-photos .card-thumb.no-photo, .no-photos .mobile-card-top > .thumb { display: none; }
.no-photos .card { grid-template-columns: 2.4fr 1.3fr 1.2fr 1fr auto 1.4fr; }

/* ---- Notifications ---- */
.notif-banner {
  background: var(--accent-light); border-bottom: 1px solid var(--line);
  padding: 10px 20px; font-size: 13px;
}
.notif-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
.notif-header strong { font-size: 14px; }
.notif-dismiss-all {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 12px; padding: 4px 8px; font-weight: 600;
  border-radius: 4px; transition: background var(--transition);
}
.notif-dismiss-all:hover { background: var(--accent-light); }
.notif-line {
  display: flex; align-items: center; gap: 10px; padding: 5px 0;
}
.notif-type {
  display: inline-block; padding: 3px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 700; color: #fff;
  min-width: 90px; text-align: center; flex-shrink: 0;
}
.notif-nouvelle { background: var(--accent); }
.notif-baisse { background: var(--green); }
.notif-hausse { background: var(--badge-hausse); }
.notif-retiree { background: var(--muted); }
.notif-reapparition { background: var(--badge-reapp); }
.notif-text { flex: 1; min-width: 0; }
.notif-text a { font-weight: 600; }
.notif-detail { color: var(--muted); }
.notif-date { color: var(--muted); font-size: 11px; flex-shrink: 0; }
.notif-x {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 20px; line-height: 1; padding: 4px 8px; flex-shrink: 0;
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; transition: all var(--transition);
}
.notif-x:hover { color: var(--ink); background: var(--card-hover); }


/* ---- Login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card); border-radius: 12px;
  padding: 32px 28px; width: 340px;
  box-shadow: var(--shadow-lg);
}
.login-card h1 { font-size: 20px; font-weight: 800; margin: 0 0 20px; text-align: center; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; font-weight: 500; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 14px; margin-top: 4px; transition: border-color var(--transition), box-shadow var(--transition);
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.login-card button { width: 100%; margin-top: 8px; padding: 11px; font-size: 14px; }
.login-card .err { color: var(--red); font-size: 13px; margin: 0 0 14px; font-weight: 500; }

/* ==============================
   RESPONSIVE
   ============================== */

@media (max-width: 900px) {
  main { padding: 16px 12px 60px; }

  /* Topbar compact */
  .topbar { padding: 0 12px; gap: 8px; height: 50px; }
  .brand { font-size: 15px; }
  .mainnav a { padding: 6px 10px; font-size: 12px; }
  .topbar .user { font-size: 12px; }
  .topbar .user .uname { display: none; }

  /* KPIs horizontal scroll */
  .kpis { flex-wrap: nowrap; overflow-x: auto; gap: 8px; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .kpi { min-width: 120px; flex: none; padding: 12px 14px; }
  .kpi .v { font-size: 20px; }

  /* Filters drawer */
  .filter-toggle { display: flex; }
  .layout { grid-template-columns: 1fr; }
  .filters {
    position: static; max-height: none;
    display: none;
  }
  .filters.open { display: block; }

  /* Hide desktop table, show mobile cards */
  .grid { display: none; }
  .mobile-cards { display: flex; flex-direction: column; gap: 10px; }

  /* Classement cards stack */
  .card {
    grid-template-columns: 1fr;
    gap: 10px; padding: 14px;
  }
  .card-thumb { width: 100%; height: 160px; }
  .no-photos .card { grid-template-columns: 1fr; }
  .card-actions { justify-content: flex-start; }
  .card-actions .actions { flex-wrap: wrap; }

  /* Notifications compact */
  .notif-line { flex-wrap: wrap; gap: 6px; }
  .notif-type { min-width: 80px; font-size: 10px; }
  .notif-date { width: 100%; }

  /* Notes popup full width */
  .notes-box form { width: calc(100vw - 48px); max-width: 300px; right: 0; }

  /* Photo preview off on mobile */
  .thumb-wrap:hover .thumb-preview { display: none; }
}

@media (max-width: 480px) {
  .topbar { height: 46px; }
  .brand { font-size: 14px; }
  .topbar .user a { font-size: 11px; }

  .kpi { min-width: 100px; padding: 10px 12px; }
  .kpi .v { font-size: 18px; }
  .kpi .l { font-size: 11px; }

  .mobile-card-top .thumb { width: 70px; height: 54px; }
  .mobile-card-nums { grid-template-columns: 1fr 1fr; gap: 4px 10px; }

  .card-thumb { height: 120px; }

  .login-card { width: calc(100vw - 32px); padding: 24px 20px; }
}
