/*
 * Build Mode styles
 *
 * All CSS rules specific to the molecule builder UI.  Loaded only on
 * pages that include the build mode (viewer.html / index.html).
 */

/* --- Element Picker (common row) --- */

.build-element-common {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.build-el-btn {
  position: relative;
  min-width: 36px;
  height: 34px;
  padding: 2px 5px 2px 12px;
  font-size: 12px;
  font-weight: 600;
  border: 1.5px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    background 0.15s;
  text-align: center;
  line-height: 28px;
}
.build-el-btn::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--el-color, #ccc);
}
.build-el-btn:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}
.build-el-btn.build-el-active {
  border-color: #0f172a;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.15);
  background: #f1f5f9;
  color: #0f172a;
}
.build-el-btn-sm {
  min-width: 28px;
  height: 26px;
  font-size: 10px;
  line-height: 20px;
  padding: 1px 3px 1px 10px;
  border-radius: 5px;
}
.build-el-btn-sm::before {
  width: 4px;
  height: 4px;
  left: 2px;
}

/* --- Full periodic table grid --- */
.build-pt-toggle-row {
  margin-top: 6px;
}
.build-pt-toggle {
  background: none;
  border: none;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 0;
}
.build-pt-toggle:hover {
  color: var(--text-primary);
}
.build-pt-full {
  margin-top: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.build-pt-grid {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  gap: 2px;
  min-width: 260px;
}

/* --- Tool mode toggle (Add / Select) --- */
.build-tool-toggle-wrap {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}
.build-tool-toggle-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px solid #cbd5e1;
  background: #fff;
  color: #475569;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    color 0.15s;
  text-align: center;
  white-space: nowrap;
}
.build-tool-toggle-btn:hover {
  border-color: #94a3b8;
  color: #0f172a;
}
.build-tool-toggle-active {
  border-color: #0f172a !important;
  background: #0f172a !important;
  color: #fff !important;
}

/* --- Geometry slider --- */
.build-adjust-slider {
  flex: 1;
  height: 4px;
  cursor: pointer;
  accent-color: #0f172a;
  min-width: 0;
}

/* --- Toolbar --- */
.build-toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}
.build-tool-btn {
  border: 1px solid #111827;
  background: #111827;
  color: #fff;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  flex: 1 1 0;
}
.build-tool-btn:hover {
  background: #000;
}
.build-tool-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.build-optimize-btn {
  width: 100%;
  padding: 8px 16px;
  font-size: 14px;
  letter-spacing: 0.02em;
}

/* --- Geometry adjustment --- */
.build-adjust-section {
  margin-top: 4px;
}
.build-adjust-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}
.build-adjust-input {
  width: 90px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  background: #fff;
  color: #111;
}
.build-adjust-input:focus {
  outline: none;
  border-color: #000;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

/* --- Fragment Library --- */
.build-frag-smiles {
  display: flex;
  gap: 6px;
  align-items: center;
}
.build-frag-smiles-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: "SF Mono", "Monaco", "Cascadia Code", "Roboto Mono", monospace;
  background: #fff;
  color: #111;
}
.build-frag-smiles-input:focus {
  outline: none;
  border-color: #000;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}
.build-frag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 6px;
  max-height: calc(var(--vh, 1vh) * 50);
  overflow-y: auto;
  padding-right: 2px;
}
.build-frag-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-surface);
  cursor: pointer;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
  text-align: center;
}
.build-frag-custom-card {
  margin-top: 8px;
}
.build-frag-card:hover {
  border-color: #000;
  box-shadow: var(--shadow-card);
}
.build-frag-card:disabled {
  opacity: 0.5;
  cursor: wait;
}
.build-frag-card-active {
  border-color: #000;
  box-shadow: 0 0 0 2px #000;
  background: rgba(0, 0, 0, 0.08);
}
.build-frag-preview {
  width: 64px;
  height: 64px;
  border-radius: 4px;
  object-fit: contain;
  background: transparent;
}
.build-frag-custom-preview {
  margin-top: 4px;
}
.build-frag-preview-loading {
  background: var(--bg-muted, #f1f5f9);
  animation: buildFragPulse 1.5s ease-in-out infinite;
}
@keyframes buildFragPulse {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.8;
  }
}
.build-frag-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}
.build-frag-icon {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.build-frag-name {
  font-size: 9px;
  color: var(--text-muted);
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* --- Build mode hint & adjust checkbox --- */
.build-adjust-checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-secondary, #64748b);
  cursor: pointer;
}
.build-adjust-cb {
  width: 14px;
  height: 14px;
  cursor: pointer;
}
.build-hint {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
}

/* --- Mobile adjustments for build mode --- */
@media (max-width: 1023px) {
  .build-pt-grid {
    min-width: 200px;
    gap: 1px;
  }
  .build-el-btn-sm {
    min-width: 22px;
    height: 22px;
    font-size: 8px;
    line-height: 18px;
    padding: 0 2px 0 8px;
  }
  .build-el-btn-sm::before {
    width: 3px;
    height: 3px;
  }
  .build-frag-grid {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  }
  .build-toolbar {
    gap: 4px;
  }
  .build-tool-btn {
    padding: 4px 8px;
    font-size: 11px;
  }
}
