:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #1b2433;
  --muted: #667085;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #e8efff;
  --danger: #dc2626;
  --sidebar: #14213d;
  --sidebar-text: #c9d3e6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);

  --b-gray-bg: #eef1f5; --b-gray: #475467;
  --b-blue-bg: #e6efff; --b-blue: #1d4ed8;
  --b-green-bg: #e3f6ea; --b-green: #15803d;
  --b-amber-bg: #fdf3dc; --b-amber: #a15c07;
  --b-orange-bg: #ffeadb; --b-orange: #c2410c;
  --b-red-bg: #fde4e4; --b-red: #b91c1c;
  --b-purple-bg: #f0e8fd; --b-purple: #7e22ce;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --surface: #171d2b; --surface-2: #1c2333; --border: #2a3346;
    --text: #e6eaf2; --muted: #98a2b3; --primary: #4f8bff; --primary-soft: #1d2b4a;
    --sidebar: #0b0f19; --shadow: 0 1px 2px rgba(0,0,0,.4);
    --b-gray-bg: #273041; --b-gray: #c2cad6;
    --b-blue-bg: #1c2d52; --b-blue: #93b4ff;
    --b-green-bg: #163a26; --b-green: #7ddc9d;
    --b-amber-bg: #3d2f12; --b-amber: #f3c46b;
    --b-orange-bg: #43260f; --b-orange: #fdac74;
    --b-red-bg: #451a1a; --b-red: #fca5a5;
    --b-purple-bg: #33204d; --b-purple: #d3b1fb;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 15px; }
.brand svg { color: #6ea0ff; }
#nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-text); font-size: 13.5px;
}
#nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
#nav a.active { background: rgba(110,160,255,.18); color: #fff; }
#nav .ico { width: 20px; text-align: center; }
#nav .sep { margin: 12px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .55; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-wrap: wrap; gap: 6px; }
.me { width: 100%; font-size: 12.5px; margin-bottom: 4px; }
.me strong { color: #fff; display: block; }
.sidebar .btn.ghost { color: var(--sidebar-text); border-color: rgba(255,255,255,.15); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.topbar-actions { position: relative; }
.view { padding: 22px 24px 60px; max-width: 1400px; width: 100%; }
.menu-btn { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-btn { display: inline-flex; }
  .view { padding: 16px; }
  .topbar { padding: 12px 16px; }
}

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; color: var(--text); cursor: pointer; padding: 6px; border-radius: 8px; font-size: 18px; position: relative; display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select, .toolbar input[type=month] { width: auto; }
.toolbar .spacer { flex: 1; }

/* ---------- Cards & tables ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card h2, .card h3 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 8px; border: 1px solid var(--border); }
.progress > div { height: 100%; background: var(--primary); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr.highlight { background: var(--primary-soft); }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 4px; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

.list-compact { list-style: none; margin: 0; padding: 0; }
.list-compact li { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.list-compact li:last-child { border-bottom: 0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--b-gray-bg); color: var(--b-gray); }
.badge.blue { background: var(--b-blue-bg); color: var(--b-blue); }
.badge.green { background: var(--b-green-bg); color: var(--b-green); }
.badge.amber { background: var(--b-amber-bg); color: var(--b-amber); }
.badge.orange { background: var(--b-orange-bg); color: var(--b-orange); }
.badge.red { background: var(--b-red-bg); color: var(--b-red); }
.badge.purple { background: var(--b-purple-bg); color: var(--b-purple); }

/* ---------- Detail (immeuble) ---------- */
.detail-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.detail-head h2 { margin: 0; font-size: 22px; }
.detail-head .spacer { flex: 1; }
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 20px; }
.dl div span { display: block; font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 20px 0 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center;
  color: var(--muted); margin-bottom: 14px; background: var(--surface);
}
.dropzone.over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dropzone .row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; margin-top: 10px; }
.dropzone select { width: auto; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 15, 30, .5); display: flex;
  align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal { width: 100%; max-width: 720px; background: var(--surface); border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.narrow { max-width: 440px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; font-weight: 700; font-size: 13px; margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--border); }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 10px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Notifications ---------- */
.badge-count { position: absolute; top: 0; right: 0; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 1px 5px; min-width: 17px; text-align: center; }
.notif-panel {
  position: absolute; right: 0; top: 42px; width: 380px; max-width: calc(100vw - 24px); max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.18); z-index: 30;
}
.notif-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.notif { display: block; padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
.notif:hover { background: var(--surface-2); text-decoration: none; }
.notif.unread { background: var(--primary-soft); }
.notif .t { font-weight: 600; font-size: 13px; }
.notif .m { font-size: 12.5px; color: var(--muted); }
.notif .d { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { margin: 0 0 4px; font-size: 22px; }
.auth form > div { margin-bottom: 14px; }
.auth .btn { width: 100%; justify-content: center; padding: 10px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1b2433; color: #fff;
  padding: 10px 18px; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 200; font-size: 13.5px;
}
.toast.error { background: var(--danger); }
a.card { color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--primary); text-decoration: none; }
