:root {
  --brand: #2563eb;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2330;
  --muted: #667085;
  --danger: #c6283a;
  --danger-bg: #fdecee;
  --ok: #16794a;
  --ok-bg: #e7f6ee;
  --warn: #a15c07;
  --warn-bg: #fff4e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #222833;
    --border: #2d3441;
    --text: #e7eaf0;
    --muted: #9aa3b2;
    --danger: #ff6b7d;
    --danger-bg: #3a1d23;
    --ok: #4ccf8b;
    --ok-bg: #173126;
    --warn: #f5b04c;
    --warn-bg: #3a2d16;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: Consolas, "Cascadia Mono", monospace; font-size: .9em; }
[hidden] { display: none !important; }

.container { max-width: 980px; margin: 0 auto; padding: 28px 16px 64px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Barre du haut */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 980px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.session { display: flex; align-items: center; gap: 12px; font-size: 14px; min-width: 0; }
.session .who { text-align: right; line-height: 1.25; min-width: 0; }
.session .who strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.session .who span { color: var(--muted); font-size: 12.5px; }

/* Boutons et champs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 8px; padding: 9px 16px;
  font: inherit; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff;
  transition: filter .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; filter: none; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 16px; }
.icon-btn {
  border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: 8px;
  padding: 6px 10px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
}
.icon-btn:hover { color: var(--danger); background: var(--danger-bg); }

input[type=text], input[type=email], input[type=search], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px;
}
input:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible, .list-card:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand);
}
textarea { min-height: 140px; resize: vertical; font-family: Consolas, "Cascadia Mono", monospace; font-size: 13.5px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Page de connexion / messages */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { max-width: 420px; width: 100%; padding: 40px 32px; text-align: center; margin: 8vh auto 0; }
.login .brand-mark { width: 52px; height: 52px; font-size: 24px; border-radius: 12px; margin: 0 auto 18px; }
.login h1 { font-size: 22px; margin: 0 0 6px; }
.login p { color: var(--muted); margin: 0 0 28px; }
.login .btn { width: 100%; }
.login .foot { margin-top: 22px; font-size: 13px; color: var(--muted); }
.message { max-width: 520px; padding: 32px; }
.message h1 { font-size: 20px; margin-top: 0; }
.tenant-id code { display: block; padding: 12px; background: var(--surface-2); border-radius: 8px; font-size: 15px; user-select: all; word-break: break-all; }

/* En-têtes de page */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; margin: 0; line-height: 1.2; }
.page-head .sub { color: var(--muted); margin-top: 4px; word-break: break-all; }
.back { display: inline-block; margin-bottom: 12px; font-size: 14px; font-weight: 600; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar input { min-width: 220px; }

/* Grille des listes */
.lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.list-card {
  display: block; padding: 16px 18px; color: var(--text); text-decoration: none;
  transition: border-color .15s, transform .15s;
}
.list-card:hover { border-color: var(--brand); text-decoration: none; transform: translateY(-1px); }
.list-card h3 { margin: 0 0 2px; font-size: 16px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.list-card .email { color: var(--muted); font-size: 13.5px; word-break: break-all; }
.list-card .desc { margin-top: 8px; font-size: 13.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-ext { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }

/* Panneau d'ajout */
.panel { padding: 18px; margin-bottom: 18px; }
.panel h2 { font-size: 16px; margin: 0 0 12px; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tab { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected=true] { color: var(--brand); border-bottom-color: var(--brand); }
.add-row { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 10px; align-items: end; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.bulk-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 12px; flex-wrap: wrap; }
.create-form { max-width: 640px; display: grid; gap: 16px; }
.create-form .hint { margin-top: 4px; }
.address { display: flex; align-items: center; gap: 6px; }
.address input { flex: 1.2; min-width: 0; }
.address .at { color: var(--muted); font-weight: 600; }
.address select { flex: 1; min-width: 0; }
select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; }
select:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: 14px; cursor: pointer; }
.check input { margin-top: 3px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.notice { padding: 12px 14px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: 14px; margin-bottom: 18px; }

.results { margin-top: 14px; border: 1px solid var(--border); border-radius: 8px; max-height: 260px; overflow: auto; }
.results div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 12px; font-size: 13.5px; border-bottom: 1px solid var(--border); }
.results div:last-child { border-bottom: 0; }
.results .s-added { color: var(--ok); }
.results .s-skipped { color: var(--muted); }
.results .s-error { color: var(--danger); }

/* Membres */
.members-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.members-head h2 { font-size: 16px; margin: 0; }
.members-head input { max-width: 280px; }
.member { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.member:last-child { border-bottom: 0; }
.avatar { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; background: var(--brand); }
.avatar.ext { background: var(--muted); }
.member .info { flex: 1; min-width: 0; }
.member .info strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.member .info span { color: var(--muted); font-size: 13.5px; word-break: break-all; }
.member .badge { flex: none; }

.empty { padding: 40px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 16px; }

/* Chargement */
.loading { display: grid; place-items: center; padding: 60px 0; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; border-color: rgba(255,255,255,.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Boîte de dialogue */
.dialog { border: 1px solid var(--border); border-radius: 12px; padding: 22px; max-width: 420px; width: calc(100% - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(15, 20, 30, .45); }
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog p { margin: 0 0 20px; color: var(--muted); word-break: break-word; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Notifications */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(440px, calc(100% - 32px)); }
.toast { padding: 11px 16px; border-radius: 8px; background: var(--text); color: var(--surface); font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: rise .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 640px) {
  .container { padding-top: 18px; }
  .add-row { grid-template-columns: 1fr; }
  .address { flex-wrap: wrap; }
  .address select { flex-basis: 100%; }
  .toolbar { width: 100%; }
  .toolbar input { min-width: 0; flex: 1; }
  .members-head input { max-width: none; }
  .session .who { display: none; }
  .member .badge { display: none; }
  .page-head h1 { font-size: 20px; }
}
.icon-btn .spinner { width: 14px; height: 14px; border-width: 2px; border-color: var(--border); border-top-color: var(--danger); }
