@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #14181c;
  --panel: #1b2126;
  --panel-raised: #212830;
  --border: #2c363d;
  --text: #e7ecee;
  --text-muted: #8b98a3;
  --accent: #c89b3c;
  --accent-dim: #6b5726;
  --warn: #d97b3f;
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
}

/* ---------- Header ---------- */

.page-header {
  border-bottom: 1px solid var(--border);
  padding: 2rem 1.5rem 1.75rem;
}

.header-inner {
  max-width: 1080px;
  margin: 0 auto;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  display: inline-block;
  margin-bottom: 1rem;
}

.back-link:hover { color: var(--text); }

.page-header h1 {
  margin: 0 0 0.5rem;
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ---------- Shared panel box ---------- */

.panel-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.75rem;
}

.box-title {
  margin: 0 0 1.25rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

/* ---------- Decode panel ---------- */

.decode-row {
  display: flex;
  gap: 0.6rem;
}

#pinInput {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: normal;
}

#pinInput::placeholder {
  color: var(--text-muted);
}

#pinInput:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#decodeBtn {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: var(--accent);
  color: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.6rem 1.1rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: none;
}

#decodeBtn:hover {
  background: #dcae52;
  border-color: #dcae52;
}

#decodeBtn:active {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
}

#decodeBtn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#decode-note {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
}

#decode-note.error { color: var(--warn); }
#decode-note.success { color: var(--accent); }
#decode-note:empty { display: none; }

/* ---------- Layout ---------- */

.builder-layout {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Its own grid, separate from the accessories panel below - a single row, so the result
   panel's sticky containing block is exactly this row's height (the "build a new part
   number" box). Nesting it this way (rather than a shared grid with grid-row: span) is
   what makes the sticky panel release right at this box's bottom instead of riding along
   through the accessories panel below it. */
.builder-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem 2.5rem;
  align-items: start;
}

/* Grid items default to min-width: auto, which floors each 1fr track at its content's
   min-content width. Without this, a wide unbreakable string (e.g. the decode input's
   placeholder) stops the track from shrinking to fit, and the whole page gains
   horizontal scroll on narrow viewports. */
.left-column,
.builder-result {
  min-width: 0;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Same width as .builder-top's left column (1fr of a 1fr 1fr grid with a 2.5rem gap),
   without putting it back in that grid - doing that would widen its sticky containing
   block again (see the comment on .builder-top above). */
.accessories-panel {
  max-width: calc((100% - 2.5rem) / 2);
}

@media (max-width: 800px) {
  .accessories-panel {
    max-width: none;
  }

  .builder-top {
    grid-template-columns: 1fr;
  }
}

/* ---------- Form ---------- */

.field-group {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.field-group:last-child { border-bottom: none; padding-bottom: 0.25rem; }
.field-group:first-child { padding-top: 0.25rem; }

.field-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text);
}

select {
  width: 100%;
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                     linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

select:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.6;
}

select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-note {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--warn);
}

.field-note:empty { display: none; }

.field-hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- Insert arrangement picker button ---------- */

.arrangement-picker-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.arrangement-picker-btn::after {
  content: '';
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
  transform: rotate(45deg) translateY(-2px);
}

.arrangement-picker-btn:hover {
  border-color: var(--accent-dim);
}

.arrangement-picker-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.arrangement-diagram-id {
  margin: 0.75rem 0 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.arrangement-diagram-id:empty { display: none; }

.arrangement-diagram {
  margin-top: 0.75rem;
  display: flex;
  justify-content: center;
}

/* Up to 300px wide (shrinks with the column on narrow screens). A PNG, not an SVG - see
   generate_diagrams.py's module docstring for why (contact coordinates as scrapeable
   markup vs. pixels), rendered at 640px so it stays sharp on retina screens too. */
.arrangement-diagram img {
  width: 100%;
  max-width: 300px;
  height: auto;
  aspect-ratio: 1 / 1;
}

.arrangement-diagram:empty { display: none; }

.arrangement-legend {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.arrangement-legend:empty { display: none; }

.arrangement-legend li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-swatch {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.legend-swatch circle {
  fill: var(--accent);
  stroke: var(--bg);
  stroke-width: 0.75;
}

.legend-swatch circle.ring { fill: none; }

.keyway-diagram {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.keyway-diagram svg {
  width: 150px;
  height: 150px;
}

.keyway-diagram-caption {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.keyway-diagram:empty { display: none; }

/* ---------- Result panel ---------- */

.builder-result {
  position: sticky;
  top: 1.5rem;
}

/* Not sticky once the layout stacks, or it would slide over the accessories panel below it. */
@media (max-width: 800px) {
  .builder-result { position: static; }
}

.pin-display {
  border: 1px solid var(--accent-dim);
  border-radius: 4px;
  padding: 1.25rem 1rem;
  text-align: center;
  margin-bottom: 1.5rem;
  background: linear-gradient(180deg, rgba(200, 155, 60, 0.06), transparent);
}

.pin-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.pin-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
  word-break: break-all;
}

.pin-value.complete {
  color: var(--accent);
}

.pin-value.incomplete {
  color: var(--text-muted);
  font-weight: 400;
}

.pin-breakdown {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.pin-breakdown td {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.pin-breakdown tr:last-child td { border-bottom: none; }

.pin-breakdown td:first-child {
  color: var(--text-muted);
  padding-right: 1rem;
  white-space: nowrap;
  width: 40%;
}

.pin-breakdown td:nth-child(2) {
  font-family: var(--font-mono);
  color: var(--text);
  padding-right: 0.75rem;
  overflow-wrap: break-word;
}

.pin-breakdown td:last-child {
  color: var(--text-muted);
}

/* ---------- Contacts ---------- */

.contacts-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.contacts-section[hidden] { display: none; }

.contacts-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.contacts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.contacts-table th {
  text-align: left;
  font-weight: 500;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 0.75rem 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.contacts-table td {
  padding: 0.45rem 0.75rem 0.45rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text-muted);
}

.contacts-table tr:last-child td { border-bottom: none; }

.contacts-table td:first-child,
.contacts-table td:nth-child(2) {
  font-family: var(--font-mono);
  color: var(--text);
  white-space: nowrap;
}

.contacts-note {
  margin: 0.6rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.contacts-note:empty { display: none; }

/* ---------- Backshell orientation ---------- */

.orientation-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.orientation-section[hidden] { display: none; }

.orientation-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

/* Site-theme line art (grey lines, accent dimension), no background rect of its own -
   sits on the page background like the keyway and arrangement diagrams. */
.orientation-img {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

.orientation-note {
  margin: 0.6rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Mating connectors ---------- */

.mating-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.mating-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin-bottom: 0.9rem;
}

.plating-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.plating-check input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.mating-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  /* Scroll still works (wheel/touch/keyboard) - just no visible track, so it can't overlap
     the right-justified descriptor text. */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* legacy Edge */
}

.mating-list::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Chromium Edge */
}

.mating-list li {
  font-size: 0.85rem;
  color: var(--text);
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  cursor: pointer;
}

.mating-list li:hover {
  color: var(--accent);
}

.mating-list li:last-child { border-bottom: none; }

.mating-list .mating-pin {
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.mating-list .review-flag {
  color: var(--warn);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* Brief "shell style, contact type" descriptor, right-justified. min-width: 0 lets it
   shrink below its content's natural width, which flex children default out of - without
   it, a long descriptor would push the list wider instead of eliding. */
.mating-list .mating-descriptor {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.mating-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.mating-empty:empty { display: none; }

.disclaimer {
  margin: 1.5rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---------- Accessories panel ---------- */

.accessory-context {
  margin: 0 0 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

select optgroup {
  font-style: normal;
  font-weight: 600;
  color: var(--text-muted);
}

select option {
  font-weight: 400;
  color: var(--text);
}

select option:disabled {
  color: var(--text-muted);
}

/* One subsection per accessory type (Backshells, Shrink Boots, ...). */
.accessory-section {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.accessory-subtitle {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.accessory-unavailable {
  margin: 0.5rem 0 0;
  padding: 0 0 0 1.1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.accessory-unavailable li + li { margin-top: 0.3rem; }

/* The field selects follow the "Accessory type" group, so they keep the normal top padding. */
.accessory-fields .field-group:first-child { padding-top: 1rem; }

.accessory-result {
  margin-top: 1.25rem;
}

.accessory-result[hidden] { display: none; }

.accessory-pin-display {
  margin-bottom: 1rem;
}

.accessory-info {
  width: 100%;
  margin-top: 1rem;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.accessory-info td {
  padding: 0.35rem 0;
  border-top: 1px solid var(--border);
  vertical-align: top;
}

.accessory-info td:first-child {
  color: var(--text-muted);
  padding-right: 1rem;
  width: 55%;
}

.accessory-info td:last-child {
  font-family: var(--font-mono);
  color: var(--text);
}

.accessory-info:empty,
.accessory-info tbody:empty { display: none; }

.accessory-notes {
  margin: 1rem 0 0;
  padding: 0 0 0 1.1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.accessory-notes:empty { display: none; }

.accessory-notes li + li { margin-top: 0.3rem; }

.accessory-notes li.warn {
  color: var(--warn);
  list-style: none;
  margin-left: -1.1rem;
}

.accessory-source {
  margin: 1rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---------- Insert arrangement picker overlay ---------- */

.arrangement-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.arrangement-modal[hidden] { display: none; }

.arrangement-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 13, 16, 0.7);
}

.arrangement-modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.arrangement-modal-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.arrangement-modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  flex: 1;
}

.arrangement-modal-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.arrangement-modal-filter label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.arrangement-modal-filter select {
  width: auto;
  min-width: 9rem;
  padding: 0.4rem 1.6rem 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.arrangement-modal-close {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.arrangement-modal-close:hover {
  color: var(--text);
  background: var(--panel-raised);
}

.arrangement-modal-body {
  overflow-y: auto;
  padding: 1.5rem;
}

.arrangement-modal-loading {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 2rem 0;
}

.arrangement-modal-section + .arrangement-modal-section {
  margin-top: 1.75rem;
}

.arrangement-modal-section-title {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.arrangement-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}

.arrangement-card {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 0.5rem 0.6rem;
  cursor: pointer;
  color: var(--text);
  text-align: center;
}

.arrangement-card:hover {
  border-color: var(--accent-dim);
}

.arrangement-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.arrangement-card.selected {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(200, 155, 60, 0.12), var(--panel-raised));
}

.arrangement-card-diagram {
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.arrangement-card-diagram img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
/* Thumbnail PNGs are rendered without labels (see generate_diagrams.py's render_png
   show_labels arg) - they'd be unreadable at this size and turn dense layouts into grey
   speckle; the main diagram shows them. */

.arrangement-card-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.arrangement-card-no {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
}

.arrangement-card-contacts {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.arrangement-card-sizes {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.arrangement-card-flag {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.arrangement-card-flag.warn {
  color: var(--warn);
}

/* Shell style picker: wide isometric images, labeled by style only. */
.arrangement-modal-grid.shell-style-grid {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.shell-style-card-img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: contain;
  border-radius: 4px;
}

.arrangement-card:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.arrangement-card:disabled:hover {
  border-color: var(--border);
}

.shell-style-card-name {
  font-size: 0.85rem;
  font-weight: 600;
}

@media (max-width: 600px) {
  .arrangement-modal-header {
    flex-wrap: wrap;
  }

  .arrangement-modal-grid.shell-style-grid {
    grid-template-columns: 1fr;
  }

  .arrangement-modal-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}
