*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f7f6f3;
  --bg2: #ffffff;
  --border: rgba(0,0,0,0.12);
  --border2: rgba(0,0,0,0.22);
  --text: #1a1a18;
  --text2: #5f5e5a;
  --text3: #9c9a92;
  --radius: 12px;
  --radius-sm: 8px;
  --purple: #534AB7;
  --purple-bg: #EEEDFE;
  --teal: #0F6E56;
  --teal-bg: #E1F5EE;
  --coral: #993C1D;
  --coral-bg: #FAECE7;
  --gray: #888780;
  --gray-bg: #F1EFE8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1a;
    --bg2: #252523;
    --border: rgba(255,255,255,0.1);
    --border2: rgba(255,255,255,0.2);
    --text: #e8e6de;
    --text2: #9c9a92;
    --text3: #5f5e5a;
    --purple-bg: #26215C;
    --teal-bg: #04342C;
    --coral-bg: #4A1B0C;
    --gray-bg: #2C2C2A;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── NAV ── */
nav {
  background: var(--bg2);
  border-bottom: 0.5px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-logo { font-size: 16px; font-weight: 500; }
.nav-logo span { color: var(--purple); }
.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
}
.avatar-sm {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
}

.page { display: none; }
.page.active { display: block; }


.auth-wrap {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}
.auth-card {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 40px;
  width: 100%;
  max-width: 420px;
}
.auth-card h1 { font-size: 22px; font-weight: 500; margin-bottom: 6px; }
.auth-card .sub { font-size: 14px; color: var(--text2); margin-bottom: 28px; line-height: 1.5; }


.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 5px; }
.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
.field input:focus,
.field textarea:focus { border-color: var(--purple); }
.field textarea { resize: vertical; min-height: 72px; }
select option { background: var(--bg2); }


.avatar-upload {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px dashed var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 0 auto 20px;
  font-size: 24px;
  color: var(--text3);
  position: relative;
  overflow: hidden;
  transition: border-color .15s;
}
.avatar-upload:hover { border-color: var(--purple); }
.avatar-upload img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.avatar-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }


.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border2);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  transition: background .15s;
  width: 100%;
  margin-top: 4px;
}
.btn:hover { background: var(--bg2); }
.btn-primary {
  background: var(--purple);
  color: #fff;
  border-color: var(--purple);
}
.btn-primary:hover { opacity: .9; background: var(--purple); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin-top: 0; }


.msg {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: 10px;
  display: none;
}
.msg.ok  { background: var(--teal-bg);  color: var(--teal); }
.msg.err { background: var(--coral-bg); color: var(--coral); }


.invite-banner {
  background: var(--teal-bg);
  border: 0.5px solid var(--teal);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 24px;
  font-size: 13px;
  color: var(--teal);
}
.invite-banner strong { font-weight: 500; }


.map-layout {
  display: flex;
  height: calc(100vh - 56px);
}
#map-container {
  flex: 1;
  position: relative;
  background: var(--bg);
  overflow: hidden;
  cursor: grab;
}
#map-container:active { cursor: grabbing; }
#edge-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}


.node {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: grab;
  user-select: none;
  z-index: 2;
  transform: translate(-50%, -50%);
  transition: filter .15s;
}
.node:active { cursor: grabbing; z-index: 10; }
.node.dimmed { opacity: .3; }
.node.selected .avatar-ring {
  box-shadow: 0 0 0 3px var(--purple);
  transform: scale(1.12);
}
.avatar-ring {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2.5px solid var(--border2);
  overflow: hidden;
  background: var(--bg2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 500;
  transition: transform .15s, box-shadow .15s;
}
.avatar-ring img { width: 100%; height: 100%; object-fit: cover; }
.node-label {
  font-size: 11px;
  font-weight: 500;
  background: var(--bg2);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 999px;
  border: 0.5px solid var(--border);
  white-space: nowrap;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}


.side-panel {
  width: 300px;
  background: var(--bg2);
  border-left: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.panel-section {
  padding: 16px 18px;
  border-bottom: 0.5px solid var(--border);
}
.panel-section h3 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}


.person-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
}
.person-row:last-child { border-bottom: none; }
.person-row:hover .person-name { color: var(--purple); }
.person-name { font-size: 13px; font-weight: 500; }
.person-sub  { font-size: 11px; color: var(--text3); margin-top: 1px; }


.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  margin: 2px;
}
.chip-famille { background: var(--purple-bg); color: var(--purple); }
.chip-amis    { background: var(--teal-bg);   color: var(--teal); }
.chip-travail { background: var(--coral-bg);  color: var(--coral); }
.chip-autre   { background: var(--gray-bg);   color: var(--gray); }


.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 18px;
  border-bottom: 0.5px solid var(--border);
}
.leg { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text2); }
.leg-dot { width: 8px; height: 8px; border-radius: 50%; }


#tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg2);
  border: 0.5px solid var(--border2);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12px;
  display: none;
  z-index: 50;
  max-width: 180px;
  line-height: 1.5;
}


.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: 100%;
  max-width: 400px;
  border: 0.5px solid var(--border);
}
.modal h2  { font-size: 18px; font-weight: 500; margin-bottom: 6px; }
.modal .sub { font-size: 13px; color: var(--text2); margin-bottom: 20px; }
.invite-link-box {
  background: var(--bg);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--purple);
  word-break: break-all;
  margin-bottom: 12px;
  font-family: monospace;
}


.empty { text-align: center; padding: 24px 16px; color: var(--text3); font-size: 13px; }