/* ══ Gestion SCI — thème clair/sombre ══ */
:root, [data-theme="light"] {
  --bg: #F6F2EC; --card: #FFFFFF; --card2: #FBF8F4; --text: #263326; --muted: #6E7562;
  --accent: #2D5016; --accent2: #3D6B20; --accent-soft: #E7EFDD; --border: #E6DED3;
  --danger: #C62828; --danger-soft: #FCE8E6; --warn: #B7791F; --warn-soft: #FDF3DC;
  --ok: #2E7D32; --ok-soft: #E3F1E4; --info: #2B6CB0; --info-soft: #E5EEF8;
  --shadow: 0 1px 2px rgba(40,50,30,.06), 0 4px 14px rgba(40,50,30,.05);
}
[data-theme="dark"] {
  --bg: #161A15; --card: #222821; --card2: #1C211B; --text: #E9E4DB; --muted: #A2A894;
  --accent: #8BC34A; --accent2: #9CCC65; --accent-soft: #2C3A22; --border: #353C33;
  --danger: #EF5350; --danger-soft: #3B2222; --warn: #F6C04E; --warn-soft: #3A321D;
  --ok: #81C784; --ok-soft: #22341F; --info: #64B5F6; --info-soft: #1E2C3A;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; font-size: 14px; }
a { color: var(--accent); }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { background: var(--card); border-radius: 18px; padding: 32px 24px; width: 100%; max-width: 360px;
  box-shadow: var(--shadow); text-align: center; }
.login-box h1 { margin: 8px 0 4px; font-size: 22px; }
.login-logo { width: 64px; height: 64px; border-radius: 16px; }
.login-box input { margin-bottom: 10px; }

/* ── Layout ── */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--card); border-right: 1px solid var(--border); padding: 18px 12px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 8px 18px; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
#side-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text);
  text-decoration: none; margin-bottom: 2px; }
#side-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#side-nav a .badge { margin-left: auto; }
.side-logout { margin-top: auto; }
main { flex: 1; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); display: flex; align-items: center; gap: 8px;
  padding: 14px 20px 10px; padding-top: max(14px, env(safe-area-inset-top)); }
.topbar h1 { font-size: 21px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; }
.page { padding: 4px 20px 100px; max-width: 1100px; }
.bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar { padding: 12px 16px 8px; padding-top: max(12px, env(safe-area-inset-top)); }
  .page { padding: 2px 16px 96px; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--card);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { flex: 1; text-align: center; padding: 8px 2px 7px; color: var(--muted); text-decoration: none;
    font-size: 11px; position: relative; }
  .bottom-nav a .ico { display: block; font-size: 21px; line-height: 1.1; }
  .bottom-nav a.active { color: var(--accent); font-weight: 600; }
  .bottom-nav .badge { position: absolute; top: 3px; left: 54%; }
}

/* ── Composants ── */
.card { background: var(--card); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow);
  border: 1px solid var(--border); margin-bottom: 10px; }
.card.clickable { cursor: pointer; }
.card.clickable:active { transform: scale(.995); }
.grid { display: grid; gap: 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 6px; }
.kpi { background: var(--card); border-radius: 14px; padding: 12px 14px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.kpi .lab { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kpi .val { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--muted); }
.kpi.alert .val { color: var(--danger); }
.kpi.good .val { color: var(--ok); }
.progress { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 4px; }

.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 99px; font-size: 12.5px;
  font-weight: 600; white-space: nowrap; }
.pill.paye { background: var(--ok-soft); color: var(--ok); }
.pill.attendu { background: var(--info-soft); color: var(--info); }
.pill.retard { background: var(--danger-soft); color: var(--danger); }
.pill.partiel { background: var(--warn-soft); color: var(--warn); }
.pill.annule, .pill.gris { background: var(--card2); color: var(--muted); border: 1px solid var(--border); }
.badge { background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 6px; font-weight: 700; }

.btn { border: 1px solid var(--border); background: var(--card); color: var(--text); border-radius: 10px;
  padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; min-height: 40px; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="dark"] .btn-primary { color: #142010; }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 5px 10px; min-height: 34px; font-size: 13.5px; border-radius: 9px; }
.btn-block { width: 100%; }
.icon-btn { border: none; background: transparent; color: var(--text); font-size: 26px; width: 40px; height: 40px;
  border-radius: 10px; cursor: pointer; line-height: 1; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

input, select, textarea { width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card2); color: var(--text); min-height: 42px; }
textarea { min-height: 200px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.f { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }

.month-nav { display: flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 3px; margin-bottom: 12px; width: fit-content; }
.month-nav button { border: none; background: transparent; font-size: 20px; width: 38px; height: 34px; cursor: pointer;
  color: var(--text); border-radius: 8px; }
.month-nav span { min-width: 130px; text-align: center; font-weight: 600; text-transform: capitalize; }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.tabs button { border: 1px solid var(--border); background: var(--card); color: var(--text); padding: 7px 13px; border-radius: 99px;
  font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item > .grow { flex: 1; min-width: 0; }
html, body { overflow-x: hidden; }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 700;
  background: var(--accent-soft); color: var(--accent); flex-shrink: 0; font-size: 15px; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.pos { color: var(--ok); }
.amount.neg { color: var(--text); }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.t td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t td.r, table.t th.r { text-align: right; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* grille des loyers */
.grille { border-collapse: separate; border-spacing: 3px; font-size: 12.5px; }
.grille th { font-weight: 600; color: var(--muted); padding: 2px 4px; text-transform: capitalize; }
.grille td.nom { white-space: nowrap; padding-right: 8px; font-weight: 600; font-size: 13.5px; position: sticky; left: 0;
  background: var(--bg); z-index: 1; }
.grille td.c { width: 46px; height: 34px; border-radius: 7px; text-align: center; cursor: pointer; font-weight: 700; }
.c.paye { background: var(--ok-soft); color: var(--ok); }
.c.attendu { background: var(--info-soft); color: var(--info); }
.c.retard { background: var(--danger-soft); color: var(--danger); }
.c.partiel { background: var(--warn-soft); color: var(--warn); }
.c.annule { background: var(--card2); color: var(--muted); }
.c.vide { background: transparent; cursor: default; }

.alert-box { border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; font-size: 14px; display: flex; gap: 8px; }
.alert-box.warn { background: var(--warn-soft); color: var(--warn); }
.alert-box.info { background: var(--info-soft); color: var(--info); }
.alert-box.danger { background: var(--danger-soft); color: var(--danger); }
.alert-box.ok { background: var(--ok-soft); color: var(--ok); }

.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; }
.bars .b div { width: 100%; max-width: 26px; border-radius: 5px 5px 0 0; }
.bars .b small { font-size: 10.5px; color: var(--muted); }
.bar-in { background: var(--accent); }
.bar-out { background: #C9B79C; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.dropzone { border: 2px dashed var(--border); border-radius: 14px; padding: 22px; text-align: center; color: var(--muted);
  cursor: pointer; background: var(--card2); }
.dropzone.over { border-color: var(--accent); color: var(--accent); }

/* ── Modales ── */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 12, .45); z-index: 100; display: flex;
  align-items: flex-end; justify-content: center; animation: fade .15s; }
.modal { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .close { float: right; }
@media (min-width: 700px) { .overlay { align-items: center; } .modal { border-radius: 18px; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 86px; z-index: 200; display: flex;
  flex-direction: column; gap: 6px; width: min(92vw, 420px); }
.toast { background: #263326; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow);
  animation: up .2s; }
.toast.error { background: var(--danger); }
.kpi.warn .val { color: var(--warn); }
