:root {
  color-scheme: dark;
  --bg: #071015;
  --panel: rgba(12, 24, 30, 0.92);
  --panel-strong: #0d1a21;
  --line: rgba(162, 196, 205, 0.14);
  --muted: #81949c;
  --text: #edf5f4;
  --accent: #ffbd69;
  --accent-2: #ff875e;
  --cyan: #54d6d0;
  --blue: #3b91ad;
  --violet: #9b88e8;
  --family: #ff7d86;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 254px minmax(420px, 1fr) 310px;
  grid-template-rows: 78px minmax(0, 1fr);
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 48% 42%, rgba(37, 110, 120, 0.11), transparent 34%),
    linear-gradient(145deg, #071116, #061015 60%, #09141a);
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 21, 0.82);
  backdrop-filter: blur(18px);
  z-index: 4;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  position: relative;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 189, 105, 0.55);
  border-radius: 50%;
  box-shadow: inset 0 0 15px rgba(255, 189, 105, 0.08);
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(255, 189, 105, 0.75);
}

.brand-mark::before {
  width: 7px;
  height: 7px;
  left: 6px;
  top: 13px;
}

.brand-mark::after {
  width: 5px;
  height: 5px;
  right: 6px;
  top: 8px;
}

.brand h1 {
  margin: 1px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 25px;
  font-weight: 500;
  letter-spacing: -0.5px;
}

.brand h1 span {
  color: var(--accent);
  font-style: italic;
}

.embed-brand,
.embed-action {
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.75px;
}

.snapshot {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #9aabb1;
  font-size: 12px;
}

.snapshot label {
  font-weight: 650;
}

.snapshot select {
  min-width: 156px;
  padding: 7px 30px 7px 10px;
  border: 1px solid rgba(104, 214, 176, 0.22);
  border-radius: 8px;
  color: #d8e4e5;
  background: #0b171d;
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
}

.snapshot select:focus-visible {
  outline: 2px solid rgba(104, 214, 176, 0.55);
  outline-offset: 2px;
}

.snapshot select:disabled {
  cursor: wait;
  opacity: 0.7;
}

.pulse {
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #68d6b0;
  box-shadow: 0 0 0 4px rgba(104, 214, 176, 0.1), 0 0 12px rgba(104, 214, 176, 0.4);
}

.controls-panel,
.detail-panel {
  min-height: 0;
  background: var(--panel);
  backdrop-filter: blur(20px);
  z-index: 3;
  overflow-y: auto;
}

.controls-panel {
  grid-column: 1;
  grid-row: 2;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
}

.panel-intro {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-intro > p:not(.eyebrow) {
  margin: 7px 0 0;
  color: #9badb3;
  font-size: 12px;
  line-height: 1.5;
}

.panel-intro .release-note {
  margin-top: 10px;
  color: #6f858d;
  font-size: 10px;
  line-height: 1.45;
}

.field-label {
  display: block;
  margin: 18px 0 8px;
  color: #84969d;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.35px;
  text-transform: uppercase;
}

.split-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.search-wrap {
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 15px;
  transform: translateY(-50%);
  fill: none;
  stroke: #71858d;
  stroke-width: 1.8;
}

input,
select {
  width: 100%;
  height: 39px;
  border: 1px solid rgba(148, 182, 191, 0.17);
  border-radius: 8px;
  outline: none;
  background: rgba(5, 13, 17, 0.6);
  color: #dce7e8;
  font-size: 11px;
  transition: border 140ms ease, box-shadow 140ms ease;
}

input {
  padding: 0 11px 0 34px;
}

select {
  padding: 0 10px;
}

input:focus,
select:focus {
  border-color: rgba(255, 189, 105, 0.5);
  box-shadow: 0 0 0 3px rgba(255, 189, 105, 0.07);
}

.text-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 10px;
}

.toggle {
  display: grid;
  grid-template-columns: 28px 1fr 19px;
  align-items: center;
  width: 100%;
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid rgba(148, 182, 191, 0.08);
  background: transparent;
  text-align: left;
  cursor: pointer;
  opacity: 0.48;
  transition: opacity 150ms ease;
}

.toggle.active {
  opacity: 1;
}

.toggle strong,
.toggle small {
  display: block;
}

.toggle strong {
  font-size: 11px;
  font-weight: 650;
}

.toggle small {
  margin-top: 2px;
  color: #74878e;
  font-size: 9px;
}

.switch-dot {
  position: relative;
  width: 18px;
  height: 10px;
  border-radius: 10px;
  background: #314149;
}

.switch-dot::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #71858d;
  transition: transform 150ms ease, background 150ms ease;
}

.toggle.active .switch-dot {
  background: rgba(255, 189, 105, 0.25);
}

.toggle.active .switch-dot::after {
  transform: translateX(8px);
  background: var(--accent);
}

.line-sample {
  display: block;
  width: 20px;
  height: 2px;
}

.line-sample.ownership {
  background: var(--accent);
  box-shadow: 8px 0 0 -1px var(--accent);
}

.line-sample.family {
  background: repeating-linear-gradient(90deg, var(--family) 0 4px, transparent 4px 7px);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid rgba(148, 182, 191, 0.14);
  border-radius: 8px;
  background: rgba(5, 13, 17, 0.5);
}

.segmented button {
  height: 29px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #71858d;
  cursor: pointer;
  font-size: 10px;
}

.segmented button.active {
  background: rgba(255, 189, 105, 0.13);
  color: var(--accent);
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px 8px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: #93a5ab;
  font-size: 9px;
}

.legend > div {
  display: flex;
  align-items: center;
  gap: 7px;
}

.legend-node {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-node.person { background: var(--accent); }
.legend-node.family-node { background: var(--accent-2); }
.legend-node.holding { background: var(--violet); }
.legend-node.company { background: var(--cyan); }

.hint {
  margin: 19px 0 0;
  color: #5e727a;
  font-size: 9px;
  line-height: 1.55;
}

.data-notice {
  margin: 9px 0 0;
  color: #63777e;
  font-size: 9px;
  line-height: 1.45;
}

.graph-stage {
  position: relative;
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(116, 153, 163, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(116, 153, 163, 0.035) 1px, transparent 1px);
  background-size: 42px 42px;
}

#graph {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#graph.dragging {
  cursor: grabbing;
}

.graph-stats,
.value-scale {
  position: absolute;
  bottom: 17px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 16, 21, 0.72);
  backdrop-filter: blur(12px);
  color: #7f949b;
  font-size: 9px;
}

.graph-stats {
  left: 17px;
}

.graph-stats strong {
  color: #d7e3e4;
  font-weight: 650;
}

.value-scale {
  right: 17px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: right;
}

.value-scale span {
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 1px;
}

.value-scale strong {
  color: #d5e0e1;
  font-size: 9px;
  font-weight: 600;
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(6, 15, 20, 0.9);
  transition: opacity 350ms ease, visibility 350ms ease;
}

.loading.hidden {
  display: none;
  opacity: 0;
  visibility: hidden;
}

.loading span {
  width: 33px;
  height: 33px;
  border: 1px solid rgba(255, 189, 105, 0.16);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.loading p {
  color: #84979e;
  font-size: 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.detail-panel {
  grid-column: 3;
  grid-row: 2;
  padding: 22px 21px 28px;
  border-left: 1px solid var(--line);
}

.detail-close {
  display: none;
}

.empty-detail {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.empty-detail h2 {
  margin: 7px 0 5px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 500;
}

.empty-detail > p:last-child {
  max-width: 190px;
  margin: 0;
  color: #748890;
  font-size: 10px;
  line-height: 1.5;
}

.empty-orbit {
  position: relative;
  width: 56px;
  height: 56px;
  margin-bottom: 17px;
  border: 1px solid rgba(124, 160, 170, 0.18);
  border-radius: 50%;
}

.empty-orbit::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(124, 160, 170, 0.12);
  border-radius: 50%;
}

.empty-orbit i {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(255, 189, 105, 0.5);
}

.detail-head {
  position: relative;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.detail-logo {
  position: absolute;
  top: -2px;
  right: 0;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.detail-logo img {
  width: 27px;
  height: 27px;
  object-fit: contain;
}

.detail-logo span {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  background: var(--logo-bg);
  color: #fff;
  font-size: 10px;
  font-weight: 850;
}

.detail-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8ba0a7;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.detail-kicker span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.detail-head h2 {
  margin: 10px 0 7px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 27px;
  font-weight: 500;
  line-height: 1.07;
}

.location-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 9px;
  color: #a9b9bd;
  font-size: 9px;
  font-weight: 650;
}

.location-pill span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #62d6bd;
  box-shadow: 0 0 8px rgba(98, 214, 189, 0.5);
}

.detail-head p {
  margin: 0;
  color: #94a7ad;
  font-size: 11px;
  line-height: 1.55;
}

.value-card {
  margin: 15px 0 18px;
  padding: 13px 14px;
  border: 1px solid rgba(255, 189, 105, 0.18);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(255, 189, 105, 0.08), rgba(84, 214, 208, 0.03));
}

.value-card span,
.value-card small {
  display: block;
}

.value-card span {
  color: #87999f;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}

.value-card strong {
  display: block;
  margin: 3px 0;
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 25px;
  font-weight: 500;
}

.value-card small {
  color: #74878e;
  font-size: 9px;
  line-height: 1.4;
}

.detail-section {
  margin-top: 18px;
}

.detail-section h3 {
  margin: 0 0 9px;
  color: #7f939a;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 1.25px;
  text-transform: uppercase;
}

.relation-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 8px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(148, 182, 191, 0.09);
}

.relation-card strong {
  font-size: 10px;
  font-weight: 600;
}

.relation-card .percentage {
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
}

.relation-card small {
  grid-column: 1 / -1;
  color: #6f838b;
  font-size: 8.5px;
  line-height: 1.4;
}

.relation-source {
  grid-column: 1 / -1;
  width: max-content;
  color: #7faea8;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-decoration: none;
}

.relation-source:hover {
  color: var(--accent);
}

.source-link {
  display: block;
  padding: 10px 11px;
  border: 1px solid rgba(148, 182, 191, 0.13);
  border-radius: 8px;
  color: #b5c5c9;
  text-decoration: none;
  transition: border 140ms ease, color 140ms ease, background 140ms ease;
}

.source-link:hover {
  border-color: rgba(255, 189, 105, 0.35);
  background: rgba(255, 189, 105, 0.05);
  color: var(--accent);
}

.source-link strong,
.source-link small {
  display: block;
}

.source-link strong {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.35;
}

.source-link small {
  margin-top: 3px;
  color: #697d84;
  font-size: 8px;
}

@media (max-width: 1020px) {
  .app-shell {
    grid-template-columns: 220px minmax(400px, 1fr) 275px;
  }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .app-shell {
    grid-template-columns: 210px minmax(520px, 1fr);
    grid-template-rows: 72px 680px;
    min-width: 730px;
    min-height: 752px;
  }
  .detail-panel { display: none; }
  .topbar { grid-column: 1 / 3; }
}

/* Modalità compatta per iframe: attivata con ?embed=1. */
html.embed-mode,
html.embed-mode body {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

html.embed-mode .app-shell {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 56px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

html.embed-mode .topbar {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  padding: 0 12px;
}

html.embed-mode .brand {
  min-width: 0;
  gap: 9px;
}

html.embed-mode .brand-mark {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
}

html.embed-mode .brand-mark::before {
  left: 5px;
  top: 10px;
}

html.embed-mode .brand-mark::after {
  right: 4px;
  top: 6px;
}

html.embed-mode .brand-copy {
  display: none;
}

html.embed-mode .embed-brand {
  display: block;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.embed-mode .embed-brand span {
  color: var(--accent);
  font-style: italic;
}

html.embed-mode .topbar-actions {
  flex: 0 0 auto;
  gap: 7px;
}

html.embed-mode .embed-action {
  display: inline-flex;
  height: 32px;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid rgba(148, 182, 191, 0.17);
  border-radius: 7px;
  background: rgba(5, 13, 17, 0.58);
  color: #c6d4d6;
  font-size: 10px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

html.embed-mode .embed-action:hover,
html.embed-mode.controls-open #embed-controls-button {
  border-color: rgba(255, 189, 105, 0.42);
  color: var(--accent);
}

html.embed-mode .snapshot {
  gap: 5px;
}

html.embed-mode .snapshot .pulse,
html.embed-mode .snapshot label {
  display: none;
}

html.embed-mode .snapshot select {
  min-width: 148px;
  height: 32px;
  padding-top: 0;
  padding-bottom: 0;
}

html.embed-mode .graph-stage {
  grid-column: 1;
  grid-row: 2;
}

html.embed-mode .controls-panel {
  position: absolute;
  top: 56px;
  bottom: 0;
  left: 0;
  display: block;
  width: min(270px, calc(100% - 28px));
  padding-top: 18px;
  border-right-color: rgba(255, 189, 105, 0.18);
  box-shadow: 22px 0 60px rgba(0, 0, 0, 0.42);
  transform: translateX(calc(-100% - 24px));
  transition: transform 180ms ease;
  z-index: 8;
}

html.embed-mode.controls-open .controls-panel {
  transform: translateX(0);
}

html.embed-mode .detail-panel {
  position: absolute;
  top: 68px;
  right: 12px;
  bottom: 12px;
  display: block;
  width: min(310px, calc(100% - 24px));
  max-height: calc(100% - 80px);
  padding-top: 46px;
  border: 1px solid rgba(148, 182, 191, 0.18);
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateX(calc(100% + 28px));
  transition: opacity 170ms ease, transform 190ms ease;
  z-index: 7;
}

html.embed-mode.has-selection .detail-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

html.embed-mode .detail-close {
  position: absolute;
  top: 11px;
  right: 12px;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid rgba(148, 182, 191, 0.16);
  border-radius: 50%;
  background: rgba(5, 13, 17, 0.62);
  color: #aebdc0;
  cursor: pointer;
}

html.embed-mode .detail-close:hover {
  border-color: rgba(255, 189, 105, 0.4);
  color: var(--accent);
}

@media (max-width: 680px) {
  html.embed-mode .embed-brand {
    font-size: 15px;
  }

  html.embed-mode .snapshot select {
    min-width: 126px;
    width: 126px;
  }

  html.embed-mode .embed-open span {
    display: none;
  }

  html.embed-mode .detail-panel {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-height: 58%;
    transform: translateY(calc(100% + 24px));
  }

  html.embed-mode.has-selection .detail-panel {
    transform: translateY(0);
  }
}

@media (max-width: 500px) {
  html.embed-mode .embed-brand span {
    display: none;
  }

  html.embed-mode .snapshot {
    display: none;
  }

  html.embed-mode .graph-stats {
    bottom: 11px;
    left: 11px;
  }

  html.embed-mode .value-scale {
    right: 11px;
    bottom: 11px;
  }
}
