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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  background: #f5f4f0;
  color: #1a1a1a;
  min-height: 100vh;
}

/* ── Layout ── */
header {
  background: #1a1a1a;
  color: #fff;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  height: 52px;
}
header h1 { font-size: 1rem; font-weight: 500; letter-spacing: 0.05em; opacity: 0.9; }
nav { display: flex; gap: 0.25rem; margin-left: auto; }
nav a, nav button {
  background: none; border: none; color: #aaa;
  padding: 0.4rem 0.85rem; border-radius: 6px;
  cursor: pointer; font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}
nav a:hover, nav button:hover { background: #333; color: #fff; }
nav a.active { background: #333; color: #fff; }

main { max-width: 1680px; margin: 2rem auto; padding: 0 1.5rem; }

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid #e5e3dc;
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}
.card h2 { font-size: 1rem; font-weight: 500; margin-bottom: 1rem; color: #444; }

details.card summary {
  list-style: none;
}

details.card summary::-webkit-details-marker {
  display: none;
}

/* ── Search bar ── */
.search-row {
  display: flex; gap: 0.75rem; margin-bottom: 1.5rem;
}
.search-row input {
  flex: 1; padding: 0.6rem 1rem;
  border: 1px solid #ddd; border-radius: 8px;
  font-size: 0.95rem; outline: none;
  transition: border-color 0.15s;
}
.search-row input:focus { border-color: #888; }

/* ── Buttons ── */
.btn {
  padding: 0.55rem 1.1rem; border-radius: 8px;
  border: none; cursor: pointer; font-size: 0.875rem;
  font-weight: 500; transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: #1a1a1a; color: #fff; }
.btn-secondary { background: #eee; color: #333; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-danger { background: #fee2e2; color: #b91c1c; }

/* ── Table ── */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; padding: 0.5rem 0.75rem; color: #888; font-weight: 500;
     font-size: 0.8rem; border-bottom: 1px solid #eee; }
td { padding: 0.6rem 0.75rem; border-bottom: 1px solid #f0ede6; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #faf9f6; }
.clickable { cursor: pointer; }
.clickable:hover td { background: #f0ede6; }

/* ── Forms ── */
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
}
.form-grid.single { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field.span2 { grid-column: span 2; }
label { font-size: 0.8rem; color: #666; font-weight: 500; }
input, select, textarea {
  padding: 0.55rem 0.8rem;
  border: 1px solid #ddd; border-radius: 7px;
  font-size: 0.9rem; font-family: inherit;
  outline: none; transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: #888; }
textarea { resize: vertical; min-height: 80px; }

/* ── Detail view ── */
.detail-header {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 1rem;
  margin-bottom: 1.5rem;
}
.detail-header h2 { font-size: 1.4rem; font-weight: 600; }
.detail-header .meta { color: #888; font-size: 0.875rem; margin-top: 0.25rem; }
.section { margin-bottom: 1.5rem; }
.section h3 {
  font-size: 0.8rem; font-weight: 600; color: #888;
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 0.75rem; padding-bottom: 0.5rem;
  border-bottom: 1px solid #eee;
}

.tag {
  display: inline-block; padding: 0.2rem 0.6rem;
  background: #f0ede6; border-radius: 4px;
  font-size: 0.8rem; color: #555; margin: 0.15rem;
}

.relation-row {
  display: flex; align-items: center;
  padding: 0.5rem 0; border-bottom: 1px solid #f5f4f0;
  gap: 0.75rem;
}
.relation-row:last-child { border-bottom: none; }
.relation-type {
  font-size: 0.75rem; color: #888; background: #f5f4f0;
  padding: 0.2rem 0.5rem; border-radius: 4px; min-width: 80px;
  text-align: center;
}
.relation-name { font-weight: 500; cursor: pointer; }
.relation-name:hover { text-decoration: underline; }

/* ── Toggle switch ── */
.toggle-switch-wrap {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.85rem; color: #555; font-weight: 500;
  cursor: pointer; user-select: none; white-space: nowrap;
}
.toggle-switch { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #ddd; border-radius: 999px; transition: 0.15s;
}
.toggle-slider::before {
  content: ""; position: absolute; height: 16px; width: 16px;
  left: 2px; bottom: 2px; background: #fff; border-radius: 50%;
  transition: 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider { background: #1a1a1a; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Misc ── */
.empty { color: #aaa; font-size: 0.875rem; padding: 1rem 0; }
.back-btn { color: #888; cursor: pointer; font-size: 0.875rem; margin-bottom: 1rem;
            display: inline-flex; align-items: center; gap: 0.4rem; }
.back-btn:hover { color: #333; }
#toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: #1a1a1a; color: #fff;
  padding: 0.75rem 1.25rem; border-radius: 8px;
  font-size: 0.875rem; opacity: 0;
  transition: opacity 0.3s; pointer-events: none;
}
#toast.show { opacity: 1; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff; border-radius: 12px;
  padding: 1.75rem; width: 520px; max-width: 95vw;
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { font-size: 1rem; margin-bottom: 1.25rem; }
.modal-footer { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.25rem; }
.hidden { display: none !important; }

/* ── Navigation & links ── */
nav a { text-decoration: none; }
a.link, .link { color: inherit; font-weight: 500; text-decoration: none; cursor: pointer; }
a.link:hover, .link:hover { text-decoration: underline; }
a.ext { font-size: 0.85rem; color: #555; }
.muted { color: #999; font-size: 0.8rem; }
.badge { display: inline-block; padding: 0.1rem 0.45rem; border-radius: 4px; font-size: 0.7rem;
         background: #fef3c7; color: #92400e; vertical-align: middle; margin-left: 0.4rem; }
a.tag { text-decoration: none; }
a.tag:hover { background: #e5e1d6; }
.tag .x { cursor: pointer; margin-left: 0.3rem; color: #b91c1c; }
.btn { text-decoration: none; display: inline-block; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn { background: none; border: none; cursor: pointer; color: #aaa; font-size: 0.85rem; padding: 0.15rem 0.35rem; border-radius: 4px; }
.icon-btn:hover { color: #333; background: #f0ede6; }
.icon-btn.danger:hover { color: #b91c1c; background: #fee2e2; }

/* ── Cards ── */
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.card-head h2 { margin: 0; }
.card-head .count { color: #aaa; font-weight: 400; font-size: 0.85rem; margin-left: 0.35rem; }

/* ── Detail page layout ── */
.page-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 1000px) { .page-grid { grid-template-columns: minmax(0, 1fr); } }
.person-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.person-head h2 { font-size: 1.5rem; font-weight: 600; margin: 0; color: #1a1a1a; }
.person-head .meta { color: #777; font-size: 0.9rem; margin-top: 0.3rem; }
.person-head .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.ext-links { display: flex; gap: 1rem; margin-top: 0.6rem; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 0.4rem 0.75rem; font-size: 0.875rem; }
.kv dt { color: #999; }
.kv dd { margin: 0; }

/* ── Relationships ── */
.rel-group { margin-bottom: 1rem; }
.rel-group:last-child { margin-bottom: 0; }
.rel-group h3 { font-size: 0.72rem; font-weight: 600; color: #999; text-transform: uppercase;
                letter-spacing: 0.08em; margin-bottom: 0.25rem; }
.rel-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.3rem 0; border-bottom: 1px solid #f5f4f0; font-size: 0.9rem; }
.rel-row:last-child { border-bottom: none; }
.rel-row .kind { color: #888; font-size: 0.78rem; min-width: 70px; }
.rel-row .tools { margin-left: auto; display: flex; gap: 0.15rem; opacity: 0; transition: opacity 0.1s; }
.rel-row:hover .tools, tr:hover .tools { opacity: 1; }
.tools { display: flex; gap: 0.15rem; }
td .tools { opacity: 0; transition: opacity 0.1s; justify-content: flex-end; }

/* ── Ego network on the person page ── */
.ego { height: 360px; position: relative; border-radius: 8px; background: #fcfbf8; overflow: hidden; }
.ego .empty { padding: 1rem; }

/* ── Lists ── */
.list-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 0.75rem; color: #999; font-size: 0.85rem; }
.pager { display: flex; gap: 0.4rem; }

/* ── Search pickers ── */
.picker { position: relative; }
.picker-results { position: absolute; left: 0; right: 0; top: 100%; z-index: 300; background: #fff;
                  border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
                  margin-top: 4px; max-height: 260px; overflow-y: auto; }
.picker-results:empty { display: none; }
.search-result { padding: 0.4rem 0.6rem; cursor: pointer; border-radius: 6px; font-size: 0.875rem; }
.search-result:hover, .search-result.active { background: #f5f4f0; }
.picker-current { font-size: 0.8rem; color: #555; margin-top: 0.3rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.4rem; }

/* ── Timeline / network page ── */
.graph-tabs { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-box { max-height: 120px; overflow-y: auto; border: 1px solid #ddd; border-radius: 7px;
              padding: 0.4rem 0.6rem; display: flex; flex-direction: column; gap: 0.3rem; min-width: 160px; }
.filter-box label, .role-box label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem;
              font-weight: 400; cursor: pointer; white-space: nowrap; color: #555; }
.role-box { max-height: 180px; overflow-y: auto; border: 1px solid #ddd; border-radius: 7px;
            padding: 0.5rem 0.6rem; min-width: 220px; }
.role-box .group > label { font-weight: 600; color: #444; }
.role-box .members { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.2rem 0 0.5rem 1.2rem; }
.focus-chip { display: inline-flex; align-items: center; gap: 0.4rem; background: #1a1a1a; color: #fff;
              border-radius: 999px; padding: 0.25rem 0.4rem 0.25rem 0.75rem; font-size: 0.8rem; }
.focus-chip a { color: #fff; }
.focus-chip button { background: #444; color: #fff; border: none; border-radius: 999px; width: 20px; height: 20px; cursor: pointer; }
#graph-canvas { background: #fff; border: 1px solid #e5e3dc; border-radius: 10px; padding: 1rem; overflow: auto; position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 0.75rem; font-size: 0.78rem; color: #666; }
.legend span { display: flex; align-items: center; gap: 0.35rem; }
.tooltip { position: fixed; background: #1a1a1a; color: #fff; padding: 0.4rem 0.75rem; border-radius: 6px;
           font-size: 0.8rem; pointer-events: none; z-index: 200; opacity: 0; transition: opacity 0.15s; white-space: nowrap; }
details.filters > summary { cursor: pointer; font-size: 0.875rem; color: #555; font-weight: 500; list-style: revert; }
details.filters > summary .count { color: #999; font-weight: 400; margin-left: 0.3rem; }
.wrap { overflow-wrap: anywhere; }
.rel-row > .tools:last-child { margin-left: auto; }

/* Visitors (not logged in as admin) see no edit controls. */
body.readonly .admin, body.readonly .tools, body.readonly .tag .x { display: none !important; }
