:root {
  --bg: #f2f1ec;
  --card: #f8f7f2;
  --line: #ddd8cf;
  --ink: #161616;
  --muted: #3f3f3f;
  --accent: #ef6f3c;
  --green: #2f7d4d;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Neue Haas Grotesk Text Pro", "Avenir Next", "IBM Plex Sans", "Segoe UI", sans-serif;
  background: var(--bg);
}

.page {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 16px 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.back-link {
  display: inline-block;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}

.back-link:hover {
  color: var(--accent);
}

.hero h1 {
  margin: 6px 0 0;
  font-size: 1.62rem;
  letter-spacing: 0.01em;
}

.hero p {
  margin: 6px 0 0;
  color: var(--muted);
}

#stats {
  margin-top: 8px;
  font-size: 0.94rem;
  color: var(--muted);
}

.controls {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(120px, 1fr) minmax(140px, 1fr) minmax(160px, 1fr) minmax(120px, 1fr);
  gap: 10px;
  align-items: start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  position: relative;
}

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

.field-helper {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.35;
}

.field-helper.is-ok {
  color: #1f7a46;
}

.field-helper.is-warning {
  color: #915d14;
}

label {
  font-size: 0.84rem;
  color: #2f2f2f;
  font-weight: 700;
}

input,
select,
button {
  border: 1px solid #cbc4b7;
  border-radius: 10px;
  padding: 10px 11px;
  font-size: 0.95rem;
  color: var(--ink);
  background: #fdfcf9;
}

input:focus,
select:focus,
button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(239, 111, 60, 0.18);
}

.entity-input-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.ghost {
  background: transparent;
  color: #2c2c2c;
}

.ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.primary {
  background: #161616;
  color: #fff;
  border-color: #161616;
  min-width: 92px;
  font-weight: 700;
}

.primary:hover {
  background: #000;
  border-color: #000;
}

#searchBtn {
  width: auto;
}

#searchBtn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#clearAllBtn {
  min-width: 104px;
}

.controls-actions {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
}

.controls-actions #searchBtn {
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
}

.dropdown-toggle {
  background: #fdfcf9;
  text-align: left;
  width: 100%;
  padding-right: 34px;
  position: relative;
  background-image:
    linear-gradient(45deg, transparent 50%, #4f4f4f 50%),
    linear-gradient(135deg, #4f4f4f 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  background: #fdfcf9;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  z-index: 30;
}

.dropdown-menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 500;
}

.dropdown-menu label:hover {
  background: #f3efe6;
}

.dropdown-menu input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: #161616;
}

.dropdown-menu label:has(input:checked) {
  background: #f2ede2;
  border-color: #d7ccba;
}

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fdfcf9;
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: 250px;
  overflow: auto;
  z-index: 35;
}

.suggestion {
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid #e7e1d4;
}

.suggestion:hover {
  background: #f3efe6;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}

.active-filters-title {
  font-size: 0.82rem;
  color: #2f2f2f;
  font-weight: 700;
  margin-right: 4px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid #d8cebc;
  background: #f2ede2;
  border-radius: 999px;
  font-size: 0.82rem;
  color: #2f2f2f;
  padding: 4px 10px;
}

.filter-chip button {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  min-width: 0;
  color: #2f2f2f;
  font-size: 0.92rem;
  line-height: 1;
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tab {
  background: #f2ede2;
  border: 1px solid #d8cebc;
  font-weight: 700;
}

.tab.active {
  background: #fff;
  border-color: #161616;
}

#status {
  margin-left: auto;
  font-size: 0.92rem;
  color: #2f2f2f;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.legend-wrap {
  margin-bottom: 8px;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.legend-chip {
  display: inline-block;
  margin-right: 6px;
  margin-bottom: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f2ede2;
  border: 1px solid #d8cebc;
}

.legend-key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
  margin-bottom: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f5f1e8;
  border: 1px solid #ddd2bf;
  color: #2f2f2f;
  font-size: 0.82rem;
}

.legend-swatch {
  width: 14px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  border: 1px solid transparent;
}

.legend-own-yes {
  background: #e7f2e8;
  border-color: #87b88d;
}

.legend-own-no {
  background: #f7e8e8;
  border-color: #c89c9c;
}

.legend-context-owner {
  background: rgba(246, 235, 183, 0.62);
  border-color: #d1bb70;
}

.legend-context-board {
  background: rgba(244, 178, 209, 0.67);
  border-color: #cc76a5;
}

.graph-tools {
  display: flex;
  gap: 6px;
}

.graph-btn {
  background: #f2ede2;
  border: 1px solid #d8cebc;
  min-width: 48px;
  padding: 6px 10px;
  font-weight: 700;
}

.graph {
  border: 1px solid #d8d1c5;
  border-radius: 12px;
  overflow: hidden;
  min-height: calc(100vh - 350px);
  background: #f4f3ef;
  cursor: grab;
}

.graph-layout {
  position: relative;
  padding-left: 14px;
  padding-right: 14px;
}

.graph svg {
  display: block;
}

.graph [data-node],
.graph .graph-edge {
  transition: opacity 170ms ease, filter 170ms ease;
  cursor: pointer;
}

.graph [data-node].is-dim,
.graph .graph-edge.is-dim {
  opacity: 0.18;
}

.graph [data-node].filter-dim,
.graph .graph-edge.filter-dim {
  opacity: 0.24;
}

.graph [data-node].is-active {
  opacity: 1;
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.2));
}

.graph .graph-edge.is-active {
  opacity: 1;
}

.graph .graph-edge.is-active line,
.graph .graph-edge.is-active path {
  stroke: #2f6a93;
  stroke-width: 3.4;
}

.graph.dragging {
  cursor: grabbing;
}

.node-details {
  position: absolute;
  top: 10px;
  right: 10px;
  width: min(340px, calc(100% - 20px));
  max-height: calc(100% - 20px);
  overflow: auto;
  border: 1px solid #d8d1c5;
  border-radius: 10px;
  background: rgba(253, 252, 249, 0.97);
  padding: 10px;
  z-index: 12;
}

.node-details-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.node-details h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.node-meta {
  margin: 0 0 8px;
  font-size: 0.86rem;
  color: #3f3f3f;
}

.node-links {
  margin: 8px 0 0;
  padding-left: 16px;
}

.node-links li {
  margin-bottom: 5px;
  font-size: 0.85rem;
  color: #2c2c2c;
}

.graph-empty {
  margin-top: 8px;
  border: 1px dashed #c48b3c;
  border-radius: 10px;
  background: #fdf7ea;
  color: #6f4b1c;
  padding: 9px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.table-tools {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.table-tools input {
  width: min(420px, 100%);
}

.excel {
  background: var(--green);
  color: #fff;
  border: none;
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #d8d1c5;
  border-radius: 12px;
  background: #fbfaf6;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 780px;
}

th,
td {
  border-bottom: 1px solid #e0d9cd;
  text-align: left;
  padding: 9px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #ede9de;
  color: #161616;
  cursor: pointer;
  user-select: none;
}

th span {
  color: #6c6253;
}

tr:hover td {
  background: #f6f2e9;
}

.hidden {
  display: none !important;
}

.app-footer {
  margin-top: 4px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  text-align: center;
  color: #2a2a2a;
  font-size: 0.9rem;
}

@media (max-width: 980px) {
  .page {
    padding: 10px;
  }

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

  .controls-actions {
    grid-column: auto;
    grid-row: auto;
    flex-direction: column;
    align-items: stretch;
  }

  .controls-actions #searchBtn,
  #clearAllBtn {
    width: 100%;
  }

  .active-filters {
    gap: 6px;
  }

  .graph-empty {
    flex-direction: column;
    align-items: flex-start;
  }

  .node-details {
    position: static;
    width: 100%;
    max-height: none;
    margin-top: 8px;
  }

  .graph-layout {
    padding-left: 8px;
    padding-right: 8px;
  }

  #status {
    margin-left: 0;
  }

  .graph {
    min-height: 62vh;
  }
}
