*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:    #1a56a0;
  --blue-lt: #e8f0fb;
  --green:   #1a7a4a;
  --red:     #b91c1c;
  --gray:    #6b7280;
  --border:  #d1d5db;
  --bg:      #f9fafb;
  --card:    #ffffff;
  --text:    #111827;
  --text-sm: #374151;
  --radius:  8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: var(--blue);
  color: #fff;
  padding: 1rem 1.5rem;
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: .9rem;
}

.header-logo {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  opacity: .95;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -.01em;
}

header p {
  font-size: 0.82rem;
  opacity: .80;
  margin-top: .2rem;
}

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ─── Input card ─────────────────────────────────────────────── */

.input-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.input-card h2 {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-sm);
  margin-bottom: .6rem;
}

.input-card .hint {
  font-size: .78rem;
  color: var(--gray);
  margin-bottom: .75rem;
  line-height: 1.5;
}

.input-card .hint code {
  background: #f3f4f6;
  border-radius: 3px;
  padding: 0 3px;
  font-size: .77rem;
}

textarea {
  width: 100%;
  min-height: 130px;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  font-family: "SF Mono", "Consolas", monospace;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
  line-height: 1.5;
}
textarea:focus { border-color: var(--blue); }

/* ─── Textarea wrapper (for autocomplete positioning) ────────── */

.textarea-wrapper {
  position: relative;
}

/* ─── Autocomplete dropdown ──────────────────────────────────── */

#ac-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.10);
  z-index: 100;
  max-height: 280px;
  overflow-y: auto;
}

.ac-item {
  display: grid;
  grid-template-columns: minmax(80px, auto) 1fr auto;
  align-items: center;
  gap: .5rem;
  padding: .42rem .7rem;
  cursor: pointer;
  font-size: .8rem;
  border-bottom: 1px solid #f3f4f6;
  transition: background .1s;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.ac-active { background: var(--blue-lt); }

.ac-input {
  font-family: "SF Mono", "Consolas", monospace;
  font-size: .8rem;
  color: var(--blue);
  white-space: nowrap;
}
.ac-input b { color: var(--text); font-weight: 700; }

.ac-desc {
  color: var(--gray);
  font-size: .75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-badge {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .1rem .35rem;
  border-radius: 3px;
  white-space: nowrap;
}
.ac-motor   { background: #eff6ff; color: #1d4ed8; }
.ac-sensory { background: #f0fdf4; color: #15803d; }
.ac-deficit { background: #fef2f2; color: #b91c1c; }
.ac-intact  { background: #f0fdf4; color: #15803d; }

.btn-row {
  display: flex;
  gap: .6rem;
  margin-top: .75rem;
  align-items: center;
}

button {
  padding: .5rem 1.15rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  transition: background .15s, opacity .15s;
}

#btn-submit {
  background: var(--blue);
  color: #fff;
}
#btn-submit:hover { background: #1248a0; }

#btn-clear {
  background: #f3f4f6;
  color: var(--text-sm);
}
#btn-clear:hover { background: #e5e7eb; }

/* ─── Parsed findings chips ─────────────────────────────────── */

#parsed-section { margin-bottom: 1.25rem; }

.section-title {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray);
  margin-bottom: .5rem;
}

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 500;
}

.chip-deficit {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
}

.chip-intact {
  background: #f0fdf4;
  color: var(--green);
  border: 1px solid #bbf7d0;
}

.chip-unmatched {
  background: #fffbeb;
  color: #92400e;
  border: 1px dashed #fcd34d;
}

.chip-icon { font-size: .7rem; }

/* ─── Results ────────────────────────────────────────────────── */

#results-section { margin-top: .25rem; }

.result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: .75rem;
  position: relative;
}

.result-card.top-result {
  border-color: var(--blue);
  border-width: 2px;
}

.result-header {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  margin-bottom: .55rem;
}

.confidence-bar-wrap {
  flex-shrink: 0;
  width: 44px;
  text-align: center;
}

.confidence-pct {
  font-size: .72rem;
  font-weight: 700;
  color: var(--blue);
}

.confidence-bar {
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  margin-top: 3px;
}

.confidence-bar-fill {
  height: 4px;
  border-radius: 2px;
  background: var(--blue);
  transition: width .4s ease;
}

.result-meta { flex: 1; }

.result-site {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.result-level {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  padding: .1rem .4rem;
  border-radius: 4px;
  background: var(--blue-lt);
  color: var(--blue);
  margin-top: .25rem;
}

.result-details {
  font-size: .8rem;
  line-height: 1.55;
  color: var(--text-sm);
}

.detail-row { margin-top: .3rem; }

.detail-label {
  font-weight: 600;
  margin-right: .25rem;
}

.detail-label.ok    { color: var(--green); }
.detail-label.bad   { color: var(--red);   }
.detail-label.miss  { color: var(--gray);  }

.result-note {
  margin-top: .5rem;
  font-size: .75rem;
  color: var(--gray);
  font-style: italic;
}

.badge-top {
  position: absolute;
  top: .7rem;
  right: .8rem;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--blue);
  background: var(--blue-lt);
  padding: .15rem .4rem;
  border-radius: 4px;
}

/* ─── Empty / error states ───────────────────────────────────── */

.info-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  color: var(--gray);
  font-size: .88rem;
}

.info-box strong { display: block; margin-bottom: .3rem; color: var(--text-sm); }

/* ─── Plexus diagram ─────────────────────────────────────────── */

#plexus-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem .75rem .5rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

#plexus-container .section-title { margin-bottom: .5rem; }

.plexus-col-label {
  font-size: 9px;
  fill: #9ca3af;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.plexus-edge {
  stroke: #d1d5db;
  stroke-width: 1.5;
  transition: stroke .2s, stroke-width .2s;
}
/* Edge between two upstream/best nodes — darker grey */
.plexus-edge.phl-edge-up  { stroke: #64748b; stroke-width: 2; }
/* Edge involving an impaired (deficit) node — red */
.plexus-edge.phl-edge-def { stroke: #dc2626; stroke-width: 2; }

.plexus-node rect {
  fill: #f9fafb;
  stroke: #9ca3af;
  stroke-width: 1.2;
  transition: fill .2s, stroke .2s, stroke-width .2s;
}
.plexus-node-label {
  font-size: 8.5px;
  fill: #374151;
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Best fit lesion site — solid red */
.plexus-node.phl-best rect {
  fill: #fee2e2;
  stroke: #dc2626;
  stroke-width: 2.5;
}
.plexus-node.phl-best .plexus-node-label { fill: #991b1b; font-weight: 700; }

/* Impaired downstream terminal nerves — red dashed */
.plexus-node.phl-deficit rect {
  fill: #fef2f2;
  stroke: #dc2626;
  stroke-width: 1.8;
  stroke-dasharray: 4 2;
}
.plexus-node.phl-deficit .plexus-node-label { fill: #dc2626; }

/* Upstream ancestors of lesion site — highlighted grey */
.plexus-node.phl-upstream rect {
  fill: #f1f5f9;
  stroke: #64748b;
  stroke-width: 1.8;
}
.plexus-node.phl-upstream .plexus-node-label { fill: #1e293b; font-weight: 600; }

/* ─── Footer ─────────────────────────────────────────────────── */

footer {
  padding: .85rem 1.5rem .7rem;
  font-size: .74rem;
  color: var(--gray);
  border-top: 1px solid var(--border);
  background: var(--card);
}

.footer-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .65rem;
}

.footer-linkedin {
  display: inline-flex;
  align-items: center;
  color: #0a66c2;
  transition: opacity .15s;
  flex-shrink: 0;
}
.footer-linkedin:hover { opacity: .75; }
.footer-linkedin svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.footer-disclaimer {
  text-align: center;
  margin-top: .4rem;
  font-size: .7rem;
  color: #9ca3af;
}

/* ─── Responsive ─────────────────────────────────────────────── */

@media (max-width: 520px) {
  header h1 { font-size: 1.1rem; }
  .result-site { font-size: .92rem; }
}
