:root {
  --bg: #1a1d23;
  --bg-soft: #232730;
  --panel: #2a2f3a;
  --border: #3a4150;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --accent: #ffb454;
  --accent-soft: #5e4220;
  --success: #6bc77d;
  --danger: #e26b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--bg-soft); padding: 1px 6px; border-radius: 4px; font-size: 0.95em; }

.topbar {
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.brand {
  color: var(--text);
  font-weight: 600;
  font-size: 1.1em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.brand .logo { font-size: 1.4em; }
.brand:hover { text-decoration: none; }

main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 24px;
}

.hero h1 { margin: 0 0 4px; font-size: 1.8em; }
.hero { margin-bottom: 24px; }
.muted { color: var(--muted); }
.small { font-size: 0.9em; }
.error { color: var(--danger); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}
.panel h2 { margin: 0 0 16px; font-size: 1.2em; }

.grid { display: grid; gap: 12px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .grid-3 { grid-template-columns: 1fr; } }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9em;
}
input, select, textarea, button {
  font: inherit;
  color: var(--text);
}
input, select, textarea {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover { background: var(--border); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1d23;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.1); }

.search-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
.search-list li { border-bottom: 1px solid var(--border); }
.search-list li:last-child { border-bottom: none; }
.search-list a {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: baseline;
  padding: 10px 4px;
  color: var(--text);
}
.search-list a:hover { background: var(--bg-soft); }
.search-list .rev { color: var(--muted); font-size: 0.9em; }

.status {
  font-size: 0.75em;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-soft);
  color: var(--muted);
}
.status-ready { background: rgba(107,199,125,0.15); color: var(--success); }
.status-researching { background: rgba(255,180,84,0.15); color: var(--accent); }
.status-failed { background: rgba(226,107,107,0.15); color: var(--danger); }

.variant-header {
  margin-bottom: 20px;
}
.variant-header .back {
  color: var(--muted);
  font-size: 0.9em;
}
.variant-header h1 { margin: 4px 0 2px; }
.variant-header .revision { color: var(--muted); margin: 0; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.schematic-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.schematic-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.schematic-list li:last-child { border-bottom: none; }

.bom-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
}
@media (max-width: 800px) { .bom-layout { grid-template-columns: 1fr; } }

.bom-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 500px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.bom-list li { border-bottom: 1px solid var(--border); }
.bom-list li:last-child { border-bottom: none; }
.bom-item {
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 8px 10px;
}
.bom-item:hover { background: var(--bg-soft); }
.bom-item .designator { color: var(--accent); font-weight: 600; }
.bom-item .part { color: var(--text); }
.bom-item .small { grid-column: 2; }

.bom-detail {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  min-height: 200px;
}
.bom-detail h3 { margin-top: 0; }
.bom-detail h4 { margin: 16px 0 6px; color: var(--muted); font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.05em; }
.bom-detail .pinout img {
  max-width: 100%;
  border-radius: 4px;
  background: #fff;
  padding: 8px;
}
.primary-link {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 6px;
  margin-top: 8px;
}
.primary-link:hover { text-decoration: none; background: var(--border); }

.chat-panel { margin-top: 20px; }
.chat-messages {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 12px;
}
.msg { margin-bottom: 12px; }
.msg-role {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 2px;
}
.msg-user .msg-role { color: var(--accent); }
.msg-body { white-space: pre-wrap; word-wrap: break-word; }

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}
.chat-form textarea { resize: vertical; min-height: 50px; }

.add-variant {
  margin-top: 8px;
  font-size: 0.9em;
}
.add-variant summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.add-variant .stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 16px 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
