:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #eeece5;
  --ink: #202124;
  --muted: #65686f;
  --line: #d9d5c9;
  --primary: #2563eb;
  --secondary: #16825d;
  --both: #7c3aed;
  --watchlist: #737373;
  --danger: #c2410c;
  --gold: #b7791f;
  --shadow: 0 18px 42px rgba(49, 45, 37, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.locked .app-shell {
  display: none;
}

body:not(.locked) .auth-screen {
  display: none;
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  display: grid;
  gap: 16px;
  width: min(100%, 380px);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  font-size: 28px;
}

.auth-card label {
  color: var(--muted);
  font-size: 12px;
}

.auth-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.auth-card input:focus {
  border-color: #111827;
}

.auth-card button {
  min-height: 42px;
  color: #fff;
  background: #111827;
  border: 1px solid #111827;
  border-radius: 8px;
  font-weight: 700;
}

.auth-error {
  min-height: 20px;
  color: #b91c1c;
  font-size: 13px;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 360px;
  min-height: 100vh;
}

.sidebar,
.detail-panel {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: #fbfaf7;
  border-color: var(--line);
}

.sidebar {
  padding: 24px 18px;
  border-right: 1px solid var(--line);
}

.detail-panel {
  padding: 24px;
  border-left: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  background: #111827;
  border-radius: 8px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
}

.eyebrow {
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.nav-tabs {
  display: grid;
  gap: 6px;
  margin-bottom: 26px;
}

.nav-tab {
  width: 100%;
  padding: 10px 12px;
  color: var(--muted);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
}

.nav-tab.active,
.nav-tab:hover {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.filter-block {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.filter-block label,
.filter-block span {
  color: var(--muted);
  font-size: 12px;
}

input[type="search"] {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

input[type="search"]:focus {
  border-color: #9ca3af;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.segmented button {
  min-height: 34px;
  padding: 7px 8px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented button.active {
  color: #fff;
  background: #111827;
  border-color: #111827;
}

.legend {
  display: grid;
  gap: 10px;
  padding: 14px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 999px;
}

.primary {
  background: var(--primary);
}

.secondary {
  background: var(--secondary);
}

.both {
  background: var(--both);
}

.watchlist {
  background: var(--watchlist);
}

.main {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.topbar h2 {
  font-size: 30px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stat {
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.stack-map {
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
}

.layer-band {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 16px;
  min-height: 116px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.layer-title h3 {
  margin-bottom: 7px;
  font-size: 18px;
}

.layer-title p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.node-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px;
}

.node-pill {
  min-height: 38px;
  padding: 9px 11px;
  color: var(--ink);
  background: #f9fafb;
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.node-pill:hover,
.node-pill.active {
  background: #fff;
  box-shadow: var(--shadow);
}

.node-pill.high-risk {
  border-top-color: var(--danger);
  border-right-color: var(--danger);
  border-bottom-color: var(--danger);
}

.node-pill.important {
  outline: 2px solid rgba(183, 121, 31, 0.28);
}

.node-pill[data-market="Primary"] {
  border-left-color: var(--primary);
}

.node-pill[data-market="Secondary"] {
  border-left-color: var(--secondary);
}

.node-pill[data-market="Both"] {
  border-left-color: var(--both);
}

.node-pill[data-market="Watchlist"] {
  border-left-color: var(--watchlist);
}

.node-name {
  display: block;
  font-size: 14px;
  font-weight: 650;
}

.node-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.detail-card {
  display: grid;
  gap: 18px;
}

.detail-head {
  display: grid;
  gap: 8px;
}

.detail-head h3 {
  font-size: 24px;
}

.badge-row,
.mapping-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.badge {
  padding: 5px 7px;
  color: #374151;
  background: var(--surface-2);
  border-radius: 7px;
  font-size: 12px;
}

.section-block {
  display: grid;
  gap: 8px;
}

.explainer-box {
  display: grid;
  gap: 8px;
  padding: 13px;
  background: #f8f7f2;
  border: 1px solid var(--line);
  border-left: 5px solid #111827;
  border-radius: 8px;
}

.explainer-box h4 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.explainer-box p {
  color: #30343a;
  font-size: 14px;
  line-height: 1.58;
}

.section-block h4 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.section-block p,
.section-block li {
  color: #3f4248;
  font-size: 14px;
  line-height: 1.55;
}

.section-block ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

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

.mapping-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.mapping-card span {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th,
td {
  padding: 13px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f8f7f2;
  font-size: 12px;
  font-weight: 700;
}

td {
  font-size: 13px;
  line-height: 1.5;
}

tr:last-child td {
  border-bottom: 0;
}

.table-node {
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 700;
  text-align: left;
}

.company-list {
  display: grid;
  gap: 6px;
}

.company-item {
  padding: 7px 8px;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.company-item strong {
  display: block;
}

.company-item span {
  color: var(--muted);
  font-size: 12px;
}

.graph-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
}

.graph-canvas {
  position: relative;
  min-height: 620px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.graph-line {
  position: absolute;
  z-index: 1;
  height: 3px;
  background: #c6c1b6;
  transform-origin: left center;
}

.graph-line::after {
  position: absolute;
  top: 50%;
  right: -1px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid currentColor;
  content: "";
  transform: translateY(-50%);
}

.graph-line.rel-constrained {
  height: 0;
  border-top: 3px dashed #dc2626;
  background: transparent;
  color: #dc2626;
}

.graph-line.rel-enables {
  background: #16a34a;
  color: #16a34a;
}

.graph-line.rel-complements {
  height: 4px;
  background: #2563eb;
  color: #2563eb;
}

.graph-line.rel-captures {
  background: #b7791f;
  color: #b7791f;
}

.graph-line.rel-competes {
  height: 0;
  border-top: 3px dotted #7c2d12;
  background: transparent;
  color: #7c2d12;
}

.graph-edge-label {
  position: absolute;
  z-index: 3;
  max-width: 92px;
  padding: 4px 6px;
  color: #374151;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 6px 14px rgba(37, 36, 31, 0.08);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.graph-edge-label.rel-enables,
.connection-card.rel-enables .relation-chip {
  color: #166534;
  border-color: rgba(22, 163, 74, 0.32);
  background: #ecfdf3;
}

.graph-edge-label.rel-constrained,
.connection-card.rel-constrained .relation-chip {
  color: #991b1b;
  border-color: rgba(220, 38, 38, 0.32);
  background: #fef2f2;
}

.graph-edge-label.rel-complements,
.connection-card.rel-complements .relation-chip {
  color: #1d4ed8;
  border-color: rgba(37, 99, 235, 0.32);
  background: #eff6ff;
}

.graph-edge-label.rel-captures,
.connection-card.rel-captures .relation-chip {
  color: #92400e;
  border-color: rgba(183, 121, 31, 0.32);
  background: #fffbeb;
}

.graph-edge-label.rel-competes,
.connection-card.rel-competes .relation-chip {
  color: #7c2d12;
  border-color: rgba(124, 45, 18, 0.32);
  background: #fff7ed;
}

.graph-legend {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: calc(100% - 24px);
}

.graph-legend span {
  padding: 5px 7px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.graph-legend .rel-enables {
  color: #166534;
  border-color: rgba(22, 163, 74, 0.32);
}

.graph-legend .rel-constrained {
  color: #991b1b;
  border-color: rgba(220, 38, 38, 0.32);
}

.graph-legend .rel-complements {
  color: #1d4ed8;
  border-color: rgba(37, 99, 235, 0.32);
}

.graph-legend .rel-captures {
  color: #92400e;
  border-color: rgba(183, 121, 31, 0.32);
}

.graph-legend .rel-competes {
  color: #7c2d12;
  border-color: rgba(124, 45, 18, 0.32);
}

.graph-node {
  position: absolute;
  z-index: 4;
  width: 132px;
  min-height: 54px;
  padding: 9px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--watchlist);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(37, 36, 31, 0.08);
  font-size: 12px;
  font-weight: 700;
}

.graph-node small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-weight: 500;
}

.connection-list {
  display: grid;
  align-content: start;
  gap: 10px;
}

.connection-card {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.connection-card.rel-enables {
  border-left: 5px solid #16a34a;
}

.connection-card.rel-constrained {
  border-left: 5px solid #dc2626;
}

.connection-card.rel-complements {
  border-left: 5px solid #2563eb;
}

.connection-card.rel-captures {
  border-left: 5px solid #b7791f;
}

.connection-card.rel-competes {
  border-left: 5px solid #7c2d12;
}

.relation-chip {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.connection-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.connection-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.opportunity-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.opportunity-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.opportunity-card h3 {
  font-size: 22px;
}

.editor-layout {
  display: grid;
  gap: 16px;
}

.editor-card {
  display: grid;
  gap: 16px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.editor-head h3 {
  font-size: 20px;
}

.editor-form {
  display: grid;
  gap: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.editor-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.editor-form input,
.editor-form select,
.editor-form textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.editor-form textarea {
  min-height: 82px;
  resize: vertical;
}

.editor-form input:focus,
.editor-form select:focus,
.editor-form textarea:focus {
  border-color: #111827;
}

.editor-form button,
.data-actions button,
.file-button {
  justify-self: start;
  min-height: 38px;
  padding: 9px 12px;
  color: #fff;
  background: #111827;
  border: 1px solid #111827;
  border-radius: 8px;
  font-weight: 700;
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.file-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.danger-button {
  background: #b91c1c !important;
  border-color: #b91c1c !important;
}

.form-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.saved-list {
  display: grid;
  gap: 8px;
}

.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.saved-item span {
  color: var(--muted);
}

.empty-state {
  display: grid;
  align-content: center;
  min-height: 240px;
  color: var(--muted);
}

.empty-state h3 {
  color: var(--ink);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .detail-panel {
    position: static;
    grid-column: 1 / -1;
    height: auto;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .main {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .stats {
    justify-content: flex-start;
  }

  .layer-band,
  .graph-layout,
  .opportunity-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .graph-canvas {
    min-height: 760px;
  }
}
