:root {
  --paper: #edf2fb;
  --ink: #1f2c44;
  --muted: #4c5f7a;
  --line: #a9b9d2;
  --card: #f8fbff;
  --accent: #0b57a4;
  --accent-soft: #deebff;
  --danger: #9e1230;
  --danger-soft: #fde7ec;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, #f6f9ff 0%, #e8effc 100%);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Verdana, sans-serif;
}

.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.2rem 3rem;
  position: relative;
}

.bg-shape {
  display: none;
}

.bg-shape-1 {
  width: 340px;
  height: 340px;
  background: rgba(13, 95, 88, 0.18);
  top: -110px;
  left: -90px;
  animation: driftA 14s ease-in-out infinite;
}

.bg-shape-2 {
  width: 300px;
  height: 300px;
  background: rgba(182, 17, 42, 0.12);
  right: -100px;
  bottom: -60px;
  animation: driftB 16s ease-in-out infinite;
}

.hero .kicker {
  display: inline-block;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.76rem;
  margin: 0 0 0.6rem;
  padding: 0.22rem 0.5rem;
  border: 1px solid #b4c7e3;
  border-radius: 2px;
  background: #eef5ff;
}

.hero h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  margin: 0;
  line-height: 1.15;
  color: #1c355e;
}

.hero .subtitle {
  margin: 0.8rem 0 0;
  color: var(--muted);
}

.mono {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.95em;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-top: 1.4rem;
}

.legend {
  color: var(--muted);
  font-size: 0.9rem;
}

button {
  border: 1px solid #8ea6cc;
  background: linear-gradient(180deg, #ffffff 0%, #dfe9fa 100%);
  color: #1b2e4f;
  font-family: inherit;
  font-weight: 600;
  padding: 0.52rem 0.9rem;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 #ffffff;
  transition: background 120ms ease, box-shadow 120ms ease;
}

button:hover {
  background: linear-gradient(180deg, #ffffff 0%, #d4e3fb 100%);
  box-shadow: inset 0 1px 0 #ffffff, 0 0 0 1px #9ab1d5;
}

.status {
  color: var(--muted);
  margin-left: 0.25rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 1.1rem;
}

.stats article {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.9rem;
}

.stats h2 {
  margin: 0;
  font-size: 1.35rem;
}

.stats p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.tree-panel {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8fbff;
  padding: 1rem;
  box-shadow: inset 0 0 0 1px #e6eefb;
}

.tree-root {
  font-family: "Segoe UI", Tahoma, Verdana, sans-serif;
  font-size: 0.92rem;
  line-height: 1.5;
}

.tree-node {
  margin-left: calc(var(--depth, 0) * 0.9rem);
  padding-left: 0.35rem;
  position: relative;
}

.tree-node::before {
  content: "";
  position: absolute;
  left: -0.3rem;
  top: 0.95rem;
  width: 0.3rem;
  border-top: 1px solid #a6b5cc;
}

.tree-node.with-children {
  padding-left: 0.1rem;
}

.tree-node.with-children > details {
  border-left: 1px dotted #b0bfd8;
  margin-left: 0.2rem;
  padding-left: 0.3rem;
}

.tree-node.with-children > details > :not(summary) {
  margin-left: 0.35rem;
}

.group-node {
  margin: 0.7rem 0 1.3rem;
}

.role-node {
  margin: 0.8rem 0 1.15rem;
}

.role-node.role-has-privileged > details {
  border-left: 2px solid #c43a53;
  background: #fff4f6;
  border-radius: 2px;
}

.role-node.role-has-privileged > details > summary {
  background: #ffe8ed;
  border: 1px solid #efbcc7;
  border-radius: 2px;
}

.role-node.role-has-privileged > details > summary .node-label {
  color: #8f0d28;
  font-weight: 700;
}

.role-flag {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.1rem 0.35rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8f0d28;
  background: #ffdfe6;
  border: 1px solid #efbcc7;
  border-radius: 2px;
}

.path-node {
  margin: 0.3rem 0 0.55rem;
}

.path-node.path-has-privileged > details {
  border-left: 2px solid #c43a53;
  background: #fff5f8;
  border-radius: 2px;
}

.path-node.path-has-privileged > details > summary {
  background: #ffe8ed;
  border: 1px solid #efbcc7;
  border-radius: 2px;
}

.path-node.path-has-privileged > details > summary .node-label,
.permission-node.path-has-privileged > .node-label {
  color: #8f0d28;
  font-weight: 700;
}

.permission-node {
  margin: 0.4rem 0 0.7rem;
}

.tree-node details {
  margin: 0.12rem 0;
}

.tree-node summary {
  list-style: none;
  cursor: pointer;
  display: inline-block;
  padding: 0.05rem 0.2rem;
}

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

.tree-node summary::before {
  content: "+";
  color: #243b61;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.9rem;
  height: 0.9rem;
  margin-right: 0.28rem;
  text-align: center;
  border: 1px solid #8fa6c8;
  background: #ffffff;
  font-size: 0.72rem;
  line-height: 1;
  transform: translateY(-0.01rem);
  transition: color 120ms ease;
}

details[open] > summary::before {
  content: "-";
}

.node-label {
  color: #1f3254;
}

.permission-content {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 0.45rem;
  row-gap: 0.18rem;
}

.action {
  color: #1a3f71;
  font-family: Consolas, "Courier New", monospace;
}

.permission-node .node-label {
  color: #24548f;
}

.permission-node.privileged .node-label {
  color: var(--danger);
  font-weight: 700;
}

.meta {
  margin-left: 0.32rem;
  color: var(--muted);
  font-family: "Segoe UI", Tahoma, Verdana, sans-serif;
  font-size: 0.85rem;
}

.privileged .meta {
  color: #8a1325;
}

.badge {
  margin-left: 0.35rem;
  border-radius: 2px;
  font-size: 0.68rem;
  font-family: "Segoe UI", Tahoma, Verdana, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.4rem;
  border: 1px solid transparent;
}

.badge.normal {
  color: #1f446f;
  background: var(--accent-soft);
  border-color: #b6cae8;
}

.badge.privileged {
  color: #8d1629;
  background: var(--danger-soft);
  border-color: #f7bfca;
}

.badge.privileged::after {
  content: " icon";
}

.error {
  color: var(--danger);
  font-family: "Segoe UI", Tahoma, Verdana, sans-serif;
  background: #fff0f2;
  border: 1px solid #f8cad3;
  border-radius: 3px;
  padding: 0.7rem;
}

@media (max-width: 760px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .tree-root {
    font-size: 0.82rem;
  }
}
