:root{
  --border:#e7e7e7;
  --muted:#6b7280;
  --text:#111827;
  --bg:#ffffff;
  --panel:#fbfbfb;
  --success-bg:#ecfdf5;
  --success-border:#a7f3d0;
  --success-text:#065f46;
}

*{ box-sizing:border-box; }
html, body { height:100%; }

body{
  margin:0;
  font-family: Avenir, "Avenir Next", "Avenir Next LT Pro", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color:var(--text);
  background:var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Top app header */
.wex-header{
  position:sticky;
  top:0;
  z-index:50;
  background:#fff;
  border-bottom:1px solid var(--border);
  height:48px;
  display:flex;
  align-items:center;
}

.wex-header-inner{
  width:100%;
  padding:10px 24px;
  display:flex;
  justify-content:space-between;
  align-items:center;
}

.wex-brand{
  font-weight:800;
  font-size:18px;
  letter-spacing:-0.02em;
  color:#30534F;
  text-decoration:none;
}

.wex-nav{
  display:flex;
  gap:16px;
  font-size:14px;
}

.wex-nav a{
  color:var(--muted);
  text-decoration:none;
}

.wex-nav a:hover{
  color:var(--text);
}

.wex-nav a.active{
  color:var(--text);
  font-weight:600;
}

/* Main app layout */
#app{
  display:grid;
  grid-template-columns: 392px 1fr;
  height: calc(100vh - 48px);
}

#panel{
  padding:14px 14px 16px;
  border-right:1px solid var(--border);
  background:var(--panel);
  overflow:auto;
}

#graphWrap{
  position:relative;
  height:100%;
  width:100%;
}

#graph{
  position:absolute;
  inset:0;
  background:
    radial-gradient(circle at 1px 1px, #efefef 1px, transparent 0) 0 0 / 18px 18px;
}

#edgeConnectorLayer{
  position:absolute;
  inset:0;
  pointer-events:none;
  z-index:5;
}

/* Edge connector bubbles */
.edge-connector-badge{
  position:absolute;
  background:#ffffff;
  border:1px solid #d8dbe1;
  border-radius:999px;
  padding:4px 8px;
  font-size:11px;
  font-weight:700;
  color:#334155;
  white-space:nowrap;
  box-shadow:0 1px 2px rgba(0,0,0,0.04);
  transform-origin:center center;
}

.edge-connector-badge.selected{
  border-color:#111827;
}

/* Typography */
h2{
  margin:2px 0 10px;
  font-size:17px;
  letter-spacing:-0.015em;
  line-height:1.15;
}

.section-title{
  margin:0 0 8px;
  font-size:12px;
  letter-spacing:0.06em;
  text-transform:uppercase;
  color:#374151;
  font-weight:800;
}

.small{
  font-size:12px;
  color:var(--muted);
  line-height:1.35;
  margin:8px 0 10px;
}

.row{ margin:10px 0; }

label{
  display:block;
  font-size:12px;
  color:#111827;
  margin-bottom:6px;
  line-height:1.2;
}

input, textarea, select{
  width:100%;
  min-width:0;
  padding:8px 10px;
  border:1px solid #d8d8d8;
  border-radius:12px;
  background:#fff;
  outline:none;
  font-size:13px;
  line-height:1.25;
}

input:focus, textarea:focus, select:focus{
  border-color:#bdbdbd;
  box-shadow:0 0 0 4px rgba(0,0,0,0.04);
}

textarea{
  min-height:86px;
  resize:vertical;
}

.btnrow{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

button{
  padding:8px 11px;
  border:1px solid #d7d7d7;
  border-radius:12px;
  background:#fff;
  cursor:pointer;
  font-weight:800;
  font-size:12px;
  transition:background 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

button:hover{
  background:#f5f5f5;
  box-shadow:0 1px 0 rgba(0,0,0,0.03);
}

button:active{
  transform:translateY(1px);
  box-shadow:none;
}

button.danger{
  border-color:#ef4444;
  color:#ef4444;
  background:#fff;
}

button.danger:hover{
  background:#fff5f5;
}

hr{
  border:0;
  border-top:1px solid var(--border);
  margin:12px 0;
}

.hint{
  color:var(--muted);
  font-size:12px;
  padding:10px 10px;
  border:1px dashed #e2e2e2;
  border-radius:12px;
  background:#fff;
}

.hidden{ display:none; }

/* Selected summary */
.selected-summary{
  margin:0 0 12px;
  padding:10px 10px;
  background:#fff;
  border:1px solid #e6e8ec;
  border-radius:14px;
}

.selected-title{
  font-size:14px;
  font-weight:800;
  color:#111827;
  line-height:1.2;
}

.selected-meta{
  margin-top:4px;
  font-size:12px;
  color:#64748b;
  line-height:1.3;
}

.apply-status{
  margin-top:10px;
  padding:8px 10px;
  border:1px solid var(--success-border);
  border-radius:12px;
  background:var(--success-bg);
  color:var(--success-text);
  font-size:12px;
  font-weight:700;
}

/* Legend */
.legend{
  font-size:12px;
  margin:8px 0 12px;
}

.legend-row{
  display:flex;
  align-items:center;
  gap:8px;
  margin:4px 0;
  color:#334155;
}

.dot{
  width:14px;
  height:14px;
  border-radius:50%;
  display:inline-block;
}

.dot.person{
  background:#818cf8;
}

.dot.connector-node{
  width:14px;
  height:14px;
  background:#e5e7eb;
  border:1px solid #d1d5db;
  border-radius:4px;
  transform:rotate(45deg);
}

.line{
  width:26px;
  height:2px;
  display:inline-block;
  background:#d1d5db;
}

.line.dashed{
  background:none;
  border-top:2px dashed #d1d5db;
}

.edge-pill-swatch{
  display:inline-flex;
  align-items:center;
  padding:2px 8px;
  border-radius:999px;
  border:1px solid #d8dbe1;
  background:#fff;
  font-size:11px;
  font-weight:700;
  color:#334155;
}

/* Toggle alignment */
.row.toggle label{
  display:flex !important;
  align-items:center;
  gap:10px;
  margin-bottom:0;
}

.row.toggle input[type="checkbox"]{
  width:16px !important;
  height:16px !important;
  margin:0 !important;
  padding:0 !important;
  border-radius:4px;
  accent-color:#6366f1;
}

input[type="checkbox"]{
  width:16px !important;
  padding:0 !important;
  border:none !important;
  background:none !important;
  box-shadow:none !important;
}

/* Hover card */
.hover-card{
  position:absolute;
  z-index:20;
  min-width:220px;
  max-width:320px;
  padding:12px 14px;
  border:1px solid #e5e7eb;
  border-radius:14px;
  background:#ffffff;
  box-shadow:0 10px 24px rgba(0,0,0,0.10);
  pointer-events:none;
}

.hover-card.hidden{
  display:none;
}

.hover-title{
  font-size:14px;
  font-weight:800;
  color:#111827;
  margin-bottom:4px;
  line-height:1.2;
}

.hover-subtitle{
  font-size:12px;
  color:#6b7280;
  margin-bottom:10px;
}

.hover-section{
  margin-top:8px;
}

.hover-label{
  font-size:11px;
  font-weight:800;
  letter-spacing:.05em;
  text-transform:uppercase;
  color:#6b7280;
  margin-bottom:4px;
}

.hover-list{
  font-size:12px;
  color:#374151;
  line-height:1.45;
}

.hover-list div + div{
  margin-top:2px;
}

/* Rating stars */
.star-picker{
  display:flex;
  gap:6px;
  align-items:center;
  flex-wrap:wrap;
  min-width:0;
}

.rating-star{
  border:1px solid #d7d7d7;
  border-radius:10px;
  background:#fff;
  padding:3px 6px;
  font-size:12px;
  line-height:1;
  font-weight:900;
  cursor:pointer;
  flex:0 0 auto;
}

.rating-star.active{
  border-color:#6366f1;
  background:#eef2ff;
  color:#4338ca;
}

/* Shared editor rows */
.compact-row{
  border:1px solid #e5e7eb;
  background:#ffffff;
  border-radius:14px;
  padding:10px;
  overflow:hidden;
  box-shadow:0 1px 2px rgba(0,0,0,0.03);
  transition:box-shadow 120ms ease, border-color 120ms ease;
}

.compact-row:hover{
  border-color:#d1d5db;
  box-shadow:0 2px 6px rgba(0,0,0,0.04);
}

.compact-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
  align-items:center;
}

.compact-grid input{
  min-width:0;
  background:#fcfcfd;
}

.compact-grid .meta-row{
  grid-column: 1 / -1;
  display:block;
}

.compact-grid .meta-row input{
  width:120px;
}

.compact-grid .stars-row{
  grid-column: 1 / -1;
  display:flex;
  justify-content:flex-start;
}

.compact-grid .remove-row{
  grid-column: 1 / -1;
  display:flex;
  justify-content:flex-start;
  margin-top:2px;
}

.compact-remove{
  min-width:110px;
  align-self:flex-start;
  justify-self:start;
  white-space:nowrap;
}

/* Person books */
#bookList{
  display:flex;
  flex-direction:column;
  gap:10px;
}

/* Edge connector editor */
#edgeConnectorList{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.connector-row{
  border:1px solid #e4e6ea;
  background:#fff;
  border-radius:14px;
  padding:10px;
  box-shadow:0 1px 2px rgba(0,0,0,0.03);
}

.connector-row:hover{
  box-shadow:0 2px 6px rgba(0,0,0,0.04);
}

.connector-header{
  display:grid;
  grid-template-columns:1fr 120px;
  gap:8px;
  align-items:center;
}

.connector-books{
  margin-top:10px;
  display:flex;
  flex-direction:column;
  gap:8px;
}

.connector-books-title{
  font-size:11px;
  color:#475569;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:0.05em;
}

.connector-book-list{
  display:flex;
  flex-direction:column;
  gap:10px;
}

/* Responsive */
@media (max-width: 1400px){
  .compact-grid{
    grid-template-columns:1fr;
  }

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

  .connector-header{
    grid-template-columns:1fr;
  }
}

@media (max-width: 720px){
  .wex-header-inner{
    padding:10px 14px;
  }

  .wex-nav{
    gap:10px;
    font-size:13px;
  }

  #app{
    grid-template-columns:1fr;
    height:auto;
    min-height:calc(100vh - 48px);
  }

  #panel{
    border-right:none;
    border-bottom:1px solid var(--border);
  }

  #graphWrap{
    min-height:60vh;
  }
}