:root {
  /* Palette derivee du logo Toit et Moi (violet + gris) */
  --bg: #f5f3f8;
  --surface: #ffffff;
  --border: #e7e3ee;
  --text: #2b2533;
  --muted: #7b7488;
  --primary: #6e4c84;
  --primary-dark: #563a69;
  --primary-light: #8a66a3;
  --primary-soft: #f1ebf7;
  --grey-accent: #b7babe;
  --grey-soft: #eef0f2;
  --success: #2f9e6f;
  --success-soft: #e6f6ef;
  --danger: #d6336c;
  --danger-soft: #fde8ef;
  --warn: #b07d00;
  --edit-soft: #fbf3df;
  --shadow: 0 1px 3px rgba(43, 37, 51, .08), 0 1px 2px rgba(43, 37, 51, .06);
  --shadow-lg: 0 14px 34px rgba(86, 58, 105, .20);
  --radius: 14px;
  --grad: linear-gradient(135deg, #6e4c84 0%, #9466b3 100%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

::selection { background: var(--primary-soft); }

/* ---------------- Login ---------------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grad);
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.login-wrap::before,
.login-wrap::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
}
.login-wrap::before { width: 420px; height: 420px; top: -160px; right: -120px; }
.login-wrap::after  { width: 320px; height: 320px; bottom: -140px; left: -100px; }
.login-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 38px 34px 34px;
  animation: rise .5s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.login-logo { display: block; height: 120px; margin: 0 auto 14px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.login-card .sub { color: var(--muted); margin: 0 0 26px; font-size: 13px; text-align: center; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 13px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; outline: none; background: #fcfbfe;
  transition: border .15s, box-shadow .15s, background .15s;
}
.field input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px var(--primary-soft); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid transparent; border-radius: 10px; padding: 10px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer; background: #fff; color: var(--text);
  transition: transform .08s ease, background .15s, box-shadow .15s, opacity .15s; white-space: nowrap;
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(110, 76, 132, .28); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; box-shadow: 0 6px 16px rgba(47, 158, 111, .25); }
.btn-success:hover { filter: brightness(.96); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary-light); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }
.btn-block { width: 100%; padding: 12px; }

.alert { padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; display: none; }
.alert.show { display: block; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }

/* ---------------- App layout ---------------- */
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 14px;
  position: sticky; top: 0; z-index: 30; box-shadow: 0 1px 0 rgba(43,37,51,.02);
}
.topbar .logo-img { height: 40px; width: auto; display: block; }
.topbar .title { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.topbar .title small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--muted); font-size: 13px; }
.topbar .user b { color: var(--text); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--grad); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}

.container { padding: 16px 20px 24px; }

/* ----- Panneau d'information repliable ----- */
.info-panel { margin-bottom: 14px; }
.panel-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; user-select: none;
}
.panel-head .ph-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.panel-head .ph-line { flex: 1; height: 1px; background: var(--border); }
.collapse-btn {
  border: 1px solid var(--border); background: #fff; color: var(--primary); width: 26px; height: 26px;
  border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  transition: transform .25s ease, background .15s;
}
.collapse-btn:hover { background: var(--primary-soft); }
.info-panel.collapsed .collapse-btn { transform: rotate(-90deg); }

.info-grid {
  display: flex; flex-wrap: wrap; gap: 14px;
  overflow: hidden; transition: max-height .3s ease, opacity .25s ease, margin .3s ease;
  max-height: 360px; opacity: 1;
}
.info-panel.collapsed .info-grid { max-height: 0; opacity: 0; margin: 0; }

.info-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 17px; box-shadow: var(--shadow); flex: 1; min-width: 185px;
  position: relative; overflow: hidden;
}
.info-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--grad);
}
.info-card .label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.info-card .value { font-size: 21px; font-weight: 700; margin-top: 5px; color: var(--text); }
.info-card .value small { font-size: 13px; font-weight: 500; color: var(--muted); }

.insee-card { display: flex; flex-direction: column; gap: 10px; min-width: 270px; }
.insee-card::before { background: var(--grey-accent); }
.insee-status { font-size: 12px; color: var(--muted); min-height: 16px; display: flex; align-items: center; gap: 8px; }
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--primary-soft); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.toolbar .search { position: relative; }
.toolbar .search input {
  padding: 10px 12px 10px 34px; border: 1px solid var(--border); border-radius: 10px;
  min-width: 250px; outline: none; background: #fcfbfe; transition: border .15s, box-shadow .15s, background .15s;
}
.toolbar .search input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px var(--primary-soft); }
.toolbar .search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.toolbar .spacer { flex: 1; }
.pending-pill {
  display: none; align-items: center; gap: 6px; background: var(--edit-soft); color: var(--warn);
  border: 1px solid #efddb0; padding: 7px 13px; border-radius: 20px; font-size: 13px; font-weight: 600;
}
.pending-pill.show { display: inline-flex; }
.pending-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* dropdown colonnes */
.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 320px; max-height: 440px; overflow-y: auto; padding: 8px;
}
.dropdown-menu.show { display: block; animation: rise .18s ease; }
.dropdown-menu .dd-actions { display: flex; gap: 10px; padding: 6px 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dropdown-menu .dd-actions a { font-size: 12px; color: var(--primary); cursor: pointer; font-weight: 600; }
.dropdown-menu .dd-actions a:hover { text-decoration: underline; }
.col-item { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 8px; cursor: pointer; }
.col-item:hover { background: var(--primary-soft); }
.col-item input { width: 15px; height: 15px; accent-color: var(--primary); }
.col-item .lock { margin-left: auto; font-size: 10px; color: var(--primary); background: var(--primary-soft); padding: 2px 7px; border-radius: 10px; font-weight: 600; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

/* errors banner */
.errors-box { display: none; margin-bottom: 14px; }
.errors-box.show { display: block; }
.errors-box .alert-danger { display: block; }
.errors-box ul { margin: 8px 0 0; padding-left: 18px; }
.errors-box li { margin: 2px 0; }

/* ----- Onglets par Type Local ----- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  padding: 9px 16px; border: 1px solid var(--border); border-bottom: none; background: #f1ebf8;
  border-radius: 12px 12px 0 0; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; transition: background .15s, color .15s; position: relative; top: 1px;
}
.tab:hover { color: var(--primary); background: #ece3f5; }
.tab.active { background: #fff; color: var(--primary); box-shadow: inset 0 -3px 0 var(--primary); }
.tab .cnt { background: var(--primary-soft); color: var(--primary); border-radius: 10px; padding: 1px 8px; font-size: 11px; font-weight: 700; }
.tab.active .cnt { background: var(--primary); color: #fff; }
.tabs:not(:empty) + .table-wrap { border-top-left-radius: 0; }

/* ----- Tabulator : en-tetes violets ----- */
.tabulator { border: none; font-size: 13px; background: #fff; }
.tabulator .tabulator-header { background: var(--primary); border: none; color: #fff; }
.tabulator .tabulator-header .tabulator-col { background: var(--primary); border-right: 1px solid rgba(255, 255, 255, .14); }
.tabulator .tabulator-header .tabulator-col-title { font-weight: 600; color: #fff; }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable:hover { background: var(--primary-dark) !important; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-sorter { color: rgba(255, 255, 255, .85); }
.tabulator .tabulator-header .tabulator-header-filter { padding: 2px 3px; }

/* bouton entonnoir dans la ligne de filtre */
.hf-btn {
  width: 100%; border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .14); color: #fff;
  border-radius: 7px; height: 26px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px;
  font-size: 11px; transition: background .15s;
}
.hf-btn:hover { background: rgba(255, 255, 255, .3); }
.hf-btn.active { background: #fff; color: var(--primary); border-color: #fff; font-weight: 700; }
.hf-btn svg { width: 12px; height: 12px; }

.tabulator-row.tabulator-row-even { background: #fcfafe; }
.tabulator-row:hover { background: var(--primary-soft) !important; }
.tabulator .tabulator-cell { border-right: 1px solid #f0ecf5; }

/* cellules editables : violet clair filigrane */
.tabulator .tabulator-cell.editable-cell {
  background-color: #f6f0fb; cursor: text;
  background-image: repeating-linear-gradient(45deg, rgba(110, 76, 132, .07) 0, rgba(110, 76, 132, .07) 1px, transparent 1px, transparent 7px);
}
.tabulator .tabulator-cell.editable-cell:hover { background-color: #efe5f8; }
.tabulator .tabulator-cell.cell-modified { background: #e1cff5 !important; background-image: none; box-shadow: inset 0 0 0 2px var(--primary-light); }
.tabulator .tabulator-cell.cell-error { background: var(--danger-soft) !important; background-image: none; box-shadow: inset 0 0 0 2px var(--danger); }
.tabulator .tabulator-footer { background: #faf8fc; border-top: 1px solid var(--border); }
.tabulator .tabulator-footer .tabulator-page.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.null-val { color: #b9b3c4; font-style: italic; }
.muted-count { color: var(--muted); font-size: 13px; }
.last-update { font-size: 11px; color: var(--muted); border-top: 1px dashed var(--border); padding-top: 8px; line-height: 1.5; }
.last-update b { color: var(--text); }

/* ----- Popups de filtre ----- */
.filter-pop {
  position: absolute; z-index: 1000; background: #fff; border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg); padding: 14px; width: 290px; font-size: 13px;
  animation: rise .15s ease;
}
.filter-pop .fp-title { font-weight: 700; margin-bottom: 12px; color: var(--text); }
.filter-pop .fp-title .fp-sub { font-weight: 500; color: var(--muted); font-size: 11px; display: block; }
.filter-pop .fp-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.filter-pop .fp-row label { width: 46px; color: var(--muted); font-size: 12px; }
.filter-pop input[type=number], .filter-pop input[type=date], .filter-pop input[type=text] {
  flex: 1; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; outline: none; min-width: 0; font-size: 13px;
}
.filter-pop input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.filter-pop .fp-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }
.filter-pop .fp-actions .btn { padding: 7px 12px; font-size: 13px; }

.fp-slider { position: relative; height: 30px; margin: 6px 4px 14px; }
.fp-slider .track { position: absolute; left: 0; right: 0; top: 13px; height: 5px; background: var(--grey-soft); border-radius: 3px; }
.fp-slider .track .fill { position: absolute; height: 100%; background: var(--primary); border-radius: 3px; }
.fp-slider input[type=range] {
  position: absolute; left: 0; right: 0; top: 6px; width: 100%; margin: 0; height: 18px;
  -webkit-appearance: none; appearance: none; background: transparent; pointer-events: none;
}
.fp-slider input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; width: 18px; height: 18px; border-radius: 50%;
  background: var(--primary); cursor: pointer; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.fp-slider input[type=range]::-moz-range-thumb {
  pointer-events: auto; width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); cursor: pointer; border: 3px solid #fff;
}
.fp-checklist { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px; margin-bottom: 4px; }
.fp-check { display: flex; align-items: center; gap: 8px; padding: 5px 7px; border-radius: 6px; cursor: pointer; }
.fp-check:hover { background: var(--primary-soft); }
.fp-check input { accent-color: var(--primary); width: 15px; height: 15px; }
.fp-check span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fp-listactions { display: flex; gap: 10px; margin-bottom: 8px; }
.fp-listactions a { font-size: 12px; color: var(--primary); cursor: pointer; font-weight: 600; }
.fp-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.fp-tab { flex: 1; text-align: center; padding: 7px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 12px; color: var(--muted); font-weight: 600; }
.fp-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.fp-pane { display: none; }
.fp-pane.active { display: block; }

/* ----- Administration des utilisateurs ----- */
.admin-wrap { max-width: 1100px; margin: 0 auto; }
.admin-grid { display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .admin-grid { grid-template-columns: 1fr; } }
.admin-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; }
.admin-card h2 { margin: 0 0 16px; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.admin-card .pill { background: var(--primary-soft); color: var(--primary); border-radius: 12px; padding: 1px 10px; font-size: 12px; font-weight: 700; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin: 4px 0 16px; cursor: pointer; }
.chk input { accent-color: var(--primary); width: 16px; height: 16px; }
.user-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.user-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 2px solid var(--border); }
.user-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.user-table tr:hover td { background: var(--primary-soft); }
.role { font-size: 11px; padding: 2px 9px; border-radius: 10px; background: var(--grey-soft); color: var(--muted); font-weight: 600; }
.role-admin { background: var(--primary-soft); color: var(--primary); }
.me-tag { font-size: 10px; background: var(--primary); color: #fff; border-radius: 8px; padding: 1px 6px; margin-left: 4px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.95); box-shadow: var(--shadow); }
.btn-danger:disabled { opacity: .4; }
.select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fcfbfe; font-size: 14px; outline: none; }
.select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 16px; line-height: 1.5; }
.role-select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; background: #fff; cursor: pointer; }
.role-select.is-admin { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-light); font-weight: 600; }
.role-select:disabled { opacity: .6; cursor: not-allowed; }
