:root {
  --bg-deep: #07111f;
  --bg-panel: #0d1c2e;
  --bg-elevated: #14263c;
  --stroke: rgba(180, 210, 235, 0.18);
  --text: #eef4fa;
  --text-muted: #9bb0c4;
  --accent: #f0a202;
  --accent-soft: rgba(240, 162, 2, 0.18);
  --cyan: #3db8d4;
  --danger-touch: #e07a3d;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font-display: "Rajdhani", sans-serif;
  --font-body: "IBM Plex Sans", sans-serif;
  --header-h: 72px;
  --filters-h: auto;
  --touch: 48px;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg-deep);
  color-scheme: dark;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  opacity: 0;
  transition: opacity 0.45s ease;
}

body.is-ready {
  opacity: 1;
}

.app {
  min-height: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(61, 184, 212, 0.16), transparent 55%),
    radial-gradient(900px 600px at 90% 0%, rgba(240, 162, 2, 0.1), transparent 50%),
    linear-gradient(180deg, #0a1728 0%, #07111f 45%, #050d18 100%);
}

.app::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(126, 182, 217, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126, 182, 217, 0.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
}

/* Header */
.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--stroke);
  backdrop-filter: blur(10px);
  background: rgba(7, 17, 31, 0.72);
  animation: slideDown 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.6rem, 2.4vw, 2.1rem);
  letter-spacing: 0.14em;
  line-height: 1;
  color: var(--text);
}

.brand span {
  color: var(--accent);
}

.project-title {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.search-wrap {
  position: relative;
  width: min(360px, 36vw);
}

.search-wrap input {
  width: 100%;
  height: var(--touch);
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: #14263c;
  color: #eef4fa;
  padding: 0 18px 0 44px;
  font-size: 1rem;
  outline: none;
  color-scheme: dark;
}

.search-wrap input::placeholder {
  color: #9bb0c4;
  opacity: 1;
}

.search-wrap input:focus {
  border-color: rgba(240, 162, 2, 0.65);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-wrap svg {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.65;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-elevated);
}

.lang-btn {
  min-width: 56px;
  height: var(--touch);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.lang-btn.is-active {
  background: var(--accent);
  color: #1a1200;
}

/* Filters */
.filters {
  position: relative;
  z-index: 4;
  padding: 12px 20px 16px;
  border-bottom: 1px solid var(--stroke);
  background: rgba(13, 28, 46, 0.78);
  animation: fadeUp 0.6s 0.08s both cubic-bezier(0.22, 1, 0.36, 1);
}

.filters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.filters-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field select {
  height: var(--touch);
  border-radius: 12px;
  border: 1px solid rgba(180, 210, 235, 0.35);
  background-color: #1a334d;
  color: #eef4fa;
  padding: 0 12px;
  font-size: 0.98rem;
  outline: none;
  color-scheme: dark;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239bb0c4' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.field select option,
.field select optgroup {
  background-color: #14263c;
  color: #eef4fa;
}

.field select:focus {
  border-color: rgba(61, 184, 212, 0.85);
  box-shadow: 0 0 0 3px rgba(61, 184, 212, 0.2);
}

.btn {
  height: var(--touch);
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.04em;
  padding: 0 16px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-accent {
  background: linear-gradient(135deg, #f0a202, #e07a3d);
  border-color: transparent;
  color: #1a1200;
}

.btn-ghost {
  background: transparent;
}

/* Stage: mapa + painel de contatos sempre visível */
.stage {
  position: relative;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  overflow: hidden;
}

.graph-shell {
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

#cy {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 2;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 1.15rem;
  background: rgba(7, 17, 31, 0.55);
  pointer-events: none;
}

.graph-empty:not([hidden]) {
  pointer-events: auto;
}

.btn-fit {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 3;
}

.legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(420px, calc(100% - 180px));
  justify-content: flex-end;
  pointer-events: none;
}

/* Painel de detalhes — coluna fixa à direita */
.side-panel {
  position: relative;
  z-index: 4;
  width: auto;
  height: 100%;
  min-height: 0;
  background: linear-gradient(180deg, #12263c 0%, #0b1830 100%);
  border-left: 1px solid var(--stroke);
  box-shadow: none;
  transform: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.side-panel.is-open {
  transform: none;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--stroke);
  flex-shrink: 0;
}

.panel-heading {
  min-width: 0;
  flex: 1;
}

.panel-kicker {
  margin: 0 0 4px;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 700;
}

.panel-head h2 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 1.55rem;
  line-height: 1.15;
  letter-spacing: 0.02em;
  color: #eef4fa;
}

.panel-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 28px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(61, 184, 212, 0.12);
  border: 1px solid rgba(61, 184, 212, 0.28);
  color: #c9e8f2;
  font-size: 0.8rem;
}

.icon-btn {
  width: var(--touch);
  height: var(--touch);
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  flex-shrink: 0;
}

.panel-body {
  overflow: auto;
  padding: 16px 20px 28px;
  flex: 1;
  min-height: 0;
}

.panel-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 48px 16px;
  font-size: 1.05rem;
  line-height: 1.45;
  border: 1px dashed rgba(180, 210, 235, 0.25);
  border-radius: var(--radius);
  background: rgba(7, 17, 31, 0.35);
}

.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.contact-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 14px;
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(7, 17, 31, 0.72);
  border: 1px solid var(--stroke);
  animation: fadeUp 0.35s ease both;
}

.contact-photo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: #1a334d;
  border: 2px solid rgba(240, 162, 2, 0.45);
}

.contact-name {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: 0.02em;
  color: #eef4fa;
}

.contact-tier,
.contact-ships,
.contact-vendor,
.muted {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.contact-phone {
  display: inline-block;
  margin: 4px 0 8px;
  color: var(--accent);
  font-weight: 600;
  font-size: 1.05rem;
  text-decoration: none;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(13, 28, 46, 0.88);
  border: 1px solid var(--stroke);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

@keyframes slideDown {
  from {
    transform: translateY(-12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fadeUp {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulseSoft {
  0%,
  100% {
    opacity: 0.75;
  }
  50% {
    opacity: 1;
  }
}

@keyframes ping {
  0% {
    box-shadow: 0 0 0 0 rgba(61, 184, 212, 0.55);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(61, 184, 212, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(61, 184, 212, 0);
  }
}

@media (max-width: 1100px) {
  .filters-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .search-wrap {
    width: min(280px, 30vw);
  }
}

@media (max-width: 780px) {
  .topbar {
    flex-wrap: wrap;
  }

  .search-wrap {
    order: 3;
    width: 100%;
  }

  .filters-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .legend {
    display: none;
  }

  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 1fr) minmax(280px, 45vh);
  }

  .side-panel {
    border-left: 0;
    border-top: 1px solid var(--stroke);
  }
}