@import url('https://fonts.googleapis.com/css2?family=Sora:wght@500;600;700;800&family=Source+Sans+3:wght@400;500;600;700&display=swap');

:root {
  --navy: #0d2a43;
  --navy-soft: #1d4f74;
  --cyan: #0b9aa7;
  --blue: #1d6db0;
  --line: #bdd6e7;
  --line-soft: #d4e4f0;
  --text: #2f536d;
  --bg: #edf4fb;
  --surface: rgba(255, 255, 255, 0.93);
  --radius-lg: 1rem;
  --radius-md: 0.72rem;
  --shadow: 0 20px 44px rgba(8, 38, 61, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 0% 0%, rgba(11, 154, 167, 0.16), transparent 30%),
    radial-gradient(circle at 100% 0%, rgba(29, 109, 176, 0.14), transparent 30%), var(--bg);
  color: var(--navy);
  font-family: 'Source Sans 3', sans-serif;
}

.tree-shell {
  width: min(1500px, calc(100% - 1.1rem));
  margin: 0.72rem auto 1.2rem;
  display: grid;
  gap: 0.8rem;
}

.panel,
.tree-head {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.tree-head {
  padding: 0.72rem 0.86rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: var(--navy);
  font-family: 'Sora', sans-serif;
  font-weight: 700;
}

.brand img {
  height: 2.36rem;
  width: auto;
}

.head-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: 0.84rem;
  padding: 0.48rem 0.72rem;
  cursor: pointer;
  text-decoration: none;
}

.btn-ghost {
  border-color: var(--line);
  background: #fff;
  color: var(--navy);
}

.intro-panel {
  padding: 0.82rem;
}

.intro-panel h1 {
  margin: 0;
  font-family: 'Sora', sans-serif;
  font-size: clamp(1.14rem, 2.1vw, 1.62rem);
  line-height: 1.2;
}

.intro-panel p {
  margin: 0.34rem 0 0;
  color: var(--text);
  max-width: 88ch;
}

.controls-panel {
  padding: 0.72rem;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(170px, 220px) minmax(190px, 240px) auto;
  gap: 0.58rem;
  align-items: end;
}

label {
  display: grid;
  gap: 0.24rem;
  color: var(--text);
  font-size: 0.79rem;
  font-weight: 700;
}

.search-field {
  min-width: 0;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  padding: 0.52rem 0.58rem;
  font: inherit;
  color: var(--navy);
  background: #fff;
}

input:focus,
select:focus {
  outline: 2px solid rgba(29, 109, 176, 0.25);
  outline-offset: 1px;
  border-color: #2f7bb4;
}

.control-actions {
  display: flex;
  gap: 0.42rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.control-actions .btn {
  padding: 0.44rem 0.66rem;
  font-size: 0.8rem;
}

.stats-row {
  padding: 0.58rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.stat-tile {
  border: 1px solid var(--line-soft);
  border-radius: 0.74rem;
  background: #f7fcff;
  padding: 0.5rem 0.56rem;
  display: grid;
  gap: 0.14rem;
}

.stat-tile strong {
  font-family: 'Sora', sans-serif;
  font-size: 1.06rem;
  line-height: 1;
}

.stat-tile span {
  color: #3f6683;
  font-size: 0.76rem;
  font-weight: 700;
}

.output-panel {
  padding: 0.72rem;
}

.tree-output {
  border: 1px solid var(--line-soft);
  border-radius: 0.82rem;
  background: #fff;
  padding: 0.72rem;
}

.tree-root,
.tree-root ul {
  list-style: none;
  margin: 0;
  padding-left: 1.2rem;
  position: relative;
}

.tree-root {
  padding-left: 0;
}

.tree-root ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0.46rem;
  width: 2px;
  height: 100%;
  background: #9fbfd6;
}

.tree-branch,
.tree-leaf {
  position: relative;
  padding-left: 1rem;
}

.tree-branch::before,
.tree-leaf::before {
  content: '';
  position: absolute;
  top: 1rem;
  left: 0.46rem;
  width: 0.72rem;
  height: 2px;
  background: #9fbfd6;
}

.tree-root > .tree-branch {
  padding-left: 0;
}

.tree-root > .tree-branch::before {
  display: none;
}

.tree-branch::after,
.tree-leaf::after {
  content: "";
  position: absolute;
  top: 0.94rem;
  left: 0.4rem;
  width: 0.2rem;
  height: 0.2rem;
  border-radius: 999px;
  background: #8aaec8;
}

.tree-root > .tree-branch::after {
  display: none;
}

.tree-node {
  margin: 0.34rem 0;
}

.tree-root > .tree-branch + .tree-branch {
  margin-top: 0.58rem;
  padding-top: 0.58rem;
  border-top: 1px dashed #c4d9ea;
}

.tree-root ul > .tree-branch + .tree-branch,
.tree-root ul > .tree-leaf + .tree-leaf {
  margin-top: 0.38rem;
  padding-top: 0.38rem;
  border-top: 1px solid #deebf5;
}

.tree-node[open] > ul {
  margin-top: 0.34rem;
  padding-top: 0.34rem;
  border-top: 1px dashed #c2d8e8;
  border-left: 2px solid #d3e4f0;
  margin-left: 0.2rem;
  padding-left: 1rem;
}

.tree-node > summary {
  cursor: pointer;
  list-style: none;
  position: relative;
  padding-right: 1.7rem;
}

.tree-node > summary::after {
  content: "+";
  position: absolute;
  right: 0.54rem;
  top: 0.7rem;
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  border: 1px solid #8fb2ca;
  background: #f6fbff;
  color: #2f5d80;
  font-weight: 800;
  font-size: 0.8rem;
  line-height: 0.94rem;
  text-align: center;
}

.tree-node[open] > summary::after {
  content: "−";
}

.tree-node > summary::-webkit-details-marker {
  display: none;
}

.node-card {
  border: 1px solid var(--line-soft);
  border-radius: 0.8rem;
  background: #f9fcff;
  padding: 0.56rem;
  display: grid;
  gap: 0.28rem;
}

.node-card h3,
.node-card h4 {
  margin: 0;
  font-family: 'Sora', sans-serif;
  font-size: 0.92rem;
  line-height: 1.25;
}

.node-card p {
  margin: 0;
  color: #315a77;
  font-size: 0.83rem;
}

.node-level-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.42rem;
  flex-wrap: wrap;
}

.level-pill {
  border-radius: 999px;
  padding: 0.12rem 0.48rem;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.level-affiliate {
  background: #e5f2ff;
  color: #1d4f74;
  border: 1px solid #9dc4df;
}

.level-organization {
  background: #e7f7f1;
  color: #1a6e5a;
  border: 1px solid #9fd6c5;
}

.level-provider {
  background: #fff3e3;
  color: #8a4b18;
  border: 1px solid #ecc796;
}

.node-meta {
  display: flex;
  gap: 0.34rem;
  flex-wrap: wrap;
}

.node-chip {
  border: 1px solid #8db8d4;
  border-radius: 999px;
  background: #edf7ff;
  color: #2a5a7c;
  font-size: 0.73rem;
  font-weight: 700;
  padding: 0.16rem 0.42rem;
}

.node-line {
  color: #466a84;
  font-size: 0.79rem;
  font-weight: 600;
}

.affiliate-card {
  border-left: 5px solid #2b7ab3;
  background: linear-gradient(180deg, #f4faff 0%, #f9fcff 100%);
}

.organization-card {
  border-left: 5px solid #2da487;
  background: linear-gradient(180deg, #f3fdf8 0%, #f9fffd 100%);
}

.provider-card {
  border-left: 5px solid #d99045;
  background: linear-gradient(180deg, #fffbf3 0%, #fffefb 100%);
}

.is-unlinked > summary .node-card,
.node-card.is-unlinked {
  border-color: #d5be96;
  background: #fff8ec;
}

.node-empty {
  margin: 0.3rem 0 0.1rem;
  color: #5a7f99;
  font-size: 0.8rem;
  font-style: italic;
}

.empty-state {
  padding: 1.1rem;
  text-align: center;
  color: #446987;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .control-grid {
    grid-template-columns: 1fr 220px 220px;
  }

  .control-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .tree-head {
    flex-direction: column;
    align-items: stretch;
  }

  .brand {
    justify-content: center;
  }

  .head-actions {
    justify-content: center;
  }

  .control-grid {
    grid-template-columns: 1fr;
  }

  .stats-row {
    grid-template-columns: 1fr;
  }

  .tree-output {
    padding: 0.52rem;
  }

  .tree-root,
  .tree-root ul {
    padding-left: 0.8rem;
  }

  .tree-branch,
  .tree-leaf {
    padding-left: 0.72rem;
  }
}
